BlueGit

ict rusty-teams

fix(notify): show reactor names in channels instead of "Unknown"

Graph sends no display name with channel reactions, and the activity feed
only looked names up among the members of that one conversation, which a
channel does not have. Names now come from the members of all chats and
from message senders in the cache (95 of 96 channel reactors resolve on my
cache). Activity entries already saved as "Unknown" resolve when shown.
Reaction chips in the channel view use the same lookup.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

metis Daniel Däschle · pushed by metis

Authored 2026-10-08 · 7 weeks ago

Hash
5548c7cc126a88b470972b0ad38e11a07dac1d99
Parent
dd09cfbe
11 files changed +227 −54
crates/app/src/activity/feed.rs +32 −7
@@ -1,11 +1,11 @@
1 use std::collections::BTreeSet;
1 use std::collections::{BTreeSet, HashMap};
2 2
3 3 use chrono::{DateTime, Duration, FixedOffset, NaiveDate, Utc};
4 4 use serde::{Deserialize, Serialize};
5 5 use store::ActivityRecord;
6 6
7 7 use crate::notify::Incoming;
8 use crate::reaction_model::tooltip_text;
8 use crate::reaction_model::{UNKNOWN_REACTOR, tooltip_text};
9 9
10 10 pub const RETENTION_DAYS: i64 = 14;
11 11
@@ -112,6 +112,24 @@ pub struct Actor {
112 112 pub name: String,
113 113 }
114 114
115 impl Actor {
116 pub fn is_unresolved(&self) -> bool {
117 self.user_id.is_some() && (self.name.is_empty() || self.name == UNKNOWN_REACTOR)
118 }
119
120 pub fn display_name<'a>(&'a self, resolved: &'a HashMap<String, String>) -> &'a str {
121 if self.is_unresolved()
122 && let Some(name) = self
123 .user_id
124 .as_ref()
125 .and_then(|user_id| resolved.get(user_id))
126 {
127 return name;
128 }
129 &self.name
130 }
131 }
132
115 133 #[derive(Debug, Clone, PartialEq)]
116 134 pub struct Entry {
117 135 pub id: i64,
@@ -127,15 +145,22 @@ pub struct Entry {
127 145 }
128 146
129 147 impl Entry {
130 pub fn names(&self) -> String {
148 pub fn names(&self, resolved: &HashMap<String, String>) -> String {
131 149 let names: Vec<&str> = self
132 150 .actors
133 151 .iter()
134 .map(|actor| actor.name.as_str())
152 .map(|actor| actor.display_name(resolved))
135 153 .collect();
136 154 tooltip_text(&names)
137 155 }
138 156
157 pub fn unresolved_user_ids(&self) -> impl Iterator<Item = &String> {
158 self.actors
159 .iter()
160 .filter(|actor| actor.is_unresolved())
161 .filter_map(|actor| actor.user_id.as_ref())
162 }
163
139 164 pub fn latest_actor(&self) -> Option<&Actor> {
140 165 self.actors.last()
141 166 }
@@ -569,7 +594,7 @@ mod tests {
569 594 record(&mut feed, &incoming("chat", "m3", "Anna", 3));
570 595 let entries = all(&feed);
571 596 let entry = entries[0];
572 assert_eq!(entry.names(), "Ben and Anna");
597 assert_eq!(entry.names(&HashMap::new()), "Ben and Anna");
573 598 assert_eq!(entry.latest_actor().unwrap().name, "Anna");
574 599 }
575 600
@@ -644,7 +669,7 @@ mod tests {
644 669 );
645 670 let entries = all(&feed);
646 671 assert_eq!(entries.len(), 1);
647 assert_eq!(entries[0].names(), "Anna and Ben");
672 assert_eq!(entries[0].names(&HashMap::new()), "Anna and Ben");
648 673 assert_eq!(entries[0].glyphs, vec!["A", "B"]);
649 674 assert_eq!(entries[0].count, 2);
650 675 assert_eq!(entries[0].updated_at, at(9, 5));
@@ -687,7 +712,7 @@ mod tests {
687 712 assert!(all(&feed).is_empty());
688 713 react(&mut feed, &[sighting("Cleo", "C", Some(at(9, 0)))]);
689 714 react(&mut feed, &[sighting("Dan", "D", None)]);
690 assert_eq!(all(&feed)[0].names(), "Cleo and Dan");
715 assert_eq!(all(&feed)[0].names(&HashMap::new()), "Cleo and Dan");
691 716 }
692 717
693 718 #[test]
@@ -1,11 +1,11 @@
1use std::collections::BTreeSet;
1use std::collections::{BTreeSet, HashMap};
2
2
3use chrono::{DateTime, Duration, FixedOffset, NaiveDate, Utc};
3use chrono::{DateTime, Duration, FixedOffset, NaiveDate, Utc};
4use serde::{Deserialize, Serialize};
4use serde::{Deserialize, Serialize};
5use store::ActivityRecord;
5use store::ActivityRecord;
6
6
7use crate::notify::Incoming;
7use crate::notify::Incoming;
8use crate::reaction_model::tooltip_text;
8use crate::reaction_model::{UNKNOWN_REACTOR, tooltip_text};
9
9
10pub const RETENTION_DAYS: i64 = 14;
10pub const RETENTION_DAYS: i64 = 14;
11
11
@@ -112,6 +112,24 @@ pub struct Actor {
112 pub name: String,
112 pub name: String,
113}
113}
114
114
115impl Actor {
116 pub fn is_unresolved(&self) -> bool {
117 self.user_id.is_some() && (self.name.is_empty() || self.name == UNKNOWN_REACTOR)
118 }
119
120 pub fn display_name<'a>(&'a self, resolved: &'a HashMap<String, String>) -> &'a str {
121 if self.is_unresolved()
122 && let Some(name) = self
123 .user_id
124 .as_ref()
125 .and_then(|user_id| resolved.get(user_id))
126 {
127 return name;
128 }
129 &self.name
130 }
131}
132
115#[derive(Debug, Clone, PartialEq)]
133#[derive(Debug, Clone, PartialEq)]
116pub struct Entry {
134pub struct Entry {
117 pub id: i64,
135 pub id: i64,
@@ -127,15 +145,22 @@ pub struct Entry {
127}
145}
128
146
129impl Entry {
147impl Entry {
130 pub fn names(&self) -> String {
148 pub fn names(&self, resolved: &HashMap<String, String>) -> String {
131 let names: Vec<&str> = self
149 let names: Vec<&str> = self
132 .actors
150 .actors
133 .iter()
151 .iter()
134 .map(|actor| actor.name.as_str())
152 .map(|actor| actor.display_name(resolved))
135 .collect();
153 .collect();
136 tooltip_text(&names)
154 tooltip_text(&names)
137 }
155 }
138
156
157 pub fn unresolved_user_ids(&self) -> impl Iterator<Item = &String> {
158 self.actors
159 .iter()
160 .filter(|actor| actor.is_unresolved())
161 .filter_map(|actor| actor.user_id.as_ref())
162 }
163
139 pub fn latest_actor(&self) -> Option<&Actor> {
164 pub fn latest_actor(&self) -> Option<&Actor> {
140 self.actors.last()
165 self.actors.last()
141 }
166 }
@@ -569,7 +594,7 @@ mod tests {
569 record(&mut feed, &incoming("chat", "m3", "Anna", 3));
594 record(&mut feed, &incoming("chat", "m3", "Anna", 3));
570 let entries = all(&feed);
595 let entries = all(&feed);
571 let entry = entries[0];
596 let entry = entries[0];
572 assert_eq!(entry.names(), "Ben and Anna");
597 assert_eq!(entry.names(&HashMap::new()), "Ben and Anna");
573 assert_eq!(entry.latest_actor().unwrap().name, "Anna");
598 assert_eq!(entry.latest_actor().unwrap().name, "Anna");
574 }
599 }
575
600
@@ -644,7 +669,7 @@ mod tests {
644 );
669 );
645 let entries = all(&feed);
670 let entries = all(&feed);
646 assert_eq!(entries.len(), 1);
671 assert_eq!(entries.len(), 1);
647 assert_eq!(entries[0].names(), "Anna and Ben");
672 assert_eq!(entries[0].names(&HashMap::new()), "Anna and Ben");
648 assert_eq!(entries[0].glyphs, vec!["A", "B"]);
673 assert_eq!(entries[0].glyphs, vec!["A", "B"]);
649 assert_eq!(entries[0].count, 2);
674 assert_eq!(entries[0].count, 2);
650 assert_eq!(entries[0].updated_at, at(9, 5));
675 assert_eq!(entries[0].updated_at, at(9, 5));
@@ -687,7 +712,7 @@ mod tests {
687 assert!(all(&feed).is_empty());
712 assert!(all(&feed).is_empty());
688 react(&mut feed, &[sighting("Cleo", "C", Some(at(9, 0)))]);
713 react(&mut feed, &[sighting("Cleo", "C", Some(at(9, 0)))]);
689 react(&mut feed, &[sighting("Dan", "D", None)]);
714 react(&mut feed, &[sighting("Dan", "D", None)]);
690 assert_eq!(all(&feed)[0].names(), "Cleo and Dan");
715 assert_eq!(all(&feed)[0].names(&HashMap::new()), "Cleo and Dan");
691 }
716 }
692
717
693 #[test]
718 #[test]
crates/app/src/activity/reactions.rs +17 −0
@@ -41,6 +41,8 @@ mod tests {
41 41 use chrono::{TimeZone, Utc};
42 42
43 43 use super::*;
44 use crate::app_state::{AppState, Mode};
45 use crate::people::resolve_names;
44 46
45 47 fn record(message_id: &str, sender: &str, reactions_json: &str) -> MessageRecord {
46 48 MessageRecord {
@@ -81,4 +83,19 @@ mod tests {
81 83 let found = reacted_messages(&[record("mine", "me", reaction)], "me", |_| None);
82 84 assert_eq!(found[0].sightings[0].name, UNKNOWN_REACTOR);
83 85 }
86
87 #[test]
88 fn channel_reactor_is_named_from_another_message_sender() {
89 let reaction = r#"[{"reaction_type":"like","user_id":"u5"}]"#;
90 let mut other = record("other", "u5", "[]");
91 other.sender_name = Some("Cleo".into());
92 let records = vec![record("mine", "me", reaction), other];
93 let store = std::sync::Arc::new(store::Store::open_in_memory().unwrap());
94 store.upsert_messages(&records).unwrap();
95 let state = AppState::new(store, Mode::default());
96 let names = resolve_names(&state, &["u5".to_owned(), "u6".to_owned()]);
97 let found = reacted_messages(&records, "me", |user_id| names.get(user_id).cloned());
98 assert_eq!(found[0].sightings[0].name, "Cleo");
99 assert!(!names.contains_key("u6"));
100 }
84 101 }
@@ -41,6 +41,8 @@ mod tests {
41 use chrono::{TimeZone, Utc};
41 use chrono::{TimeZone, Utc};
42
42
43 use super::*;
43 use super::*;
44 use crate::app_state::{AppState, Mode};
45 use crate::people::resolve_names;
44
46
45 fn record(message_id: &str, sender: &str, reactions_json: &str) -> MessageRecord {
47 fn record(message_id: &str, sender: &str, reactions_json: &str) -> MessageRecord {
46 MessageRecord {
48 MessageRecord {
@@ -81,4 +83,19 @@ mod tests {
81 let found = reacted_messages(&[record("mine", "me", reaction)], "me", |_| None);
83 let found = reacted_messages(&[record("mine", "me", reaction)], "me", |_| None);
82 assert_eq!(found[0].sightings[0].name, UNKNOWN_REACTOR);
84 assert_eq!(found[0].sightings[0].name, UNKNOWN_REACTOR);
83 }
85 }
86
87 #[test]
88 fn channel_reactor_is_named_from_another_message_sender() {
89 let reaction = r#"[{"reaction_type":"like","user_id":"u5"}]"#;
90 let mut other = record("other", "u5", "[]");
91 other.sender_name = Some("Cleo".into());
92 let records = vec![record("mine", "me", reaction), other];
93 let store = std::sync::Arc::new(store::Store::open_in_memory().unwrap());
94 store.upsert_messages(&records).unwrap();
95 let state = AppState::new(store, Mode::default());
96 let names = resolve_names(&state, &["u5".to_owned(), "u6".to_owned()]);
97 let found = reacted_messages(&records, "me", |user_id| names.get(user_id).cloned());
98 assert_eq!(found[0].sightings[0].name, "Cleo");
99 assert!(!names.contains_key("u6"));
100 }
84}
101}
crates/app/src/activity/service.rs +8 −12
@@ -9,6 +9,7 @@ use super::reactions::reacted_messages;
9 9 use crate::app_state::{AppEvent, AppState};
10 10 use crate::demo;
11 11 use crate::notify::{IncomingTracker, channel_alerts};
12 use crate::people::resolve_names;
12 13
13 14 const WATERMARK_KEY: &str = "activity_watermark";
14 15 const RECENT_WINDOW: usize = 20;
@@ -204,17 +205,12 @@ fn reacted_in(state: &AppState, conversation_id: &str, my_user_id: &str) -> Vec<
204 205 let Ok(records) = state.store.messages(conversation_id, None, RECENT_WINDOW) else {
205 206 return Vec::new();
206 207 };
207 let members = state
208 .sidebar
209 .chats
208 let reactor_ids: Vec<String> = records
210 209 .iter()
211 .find(|chat| chat.id == conversation_id)
212 .map(|chat| chat.members.as_slice())
213 .unwrap_or_default();
214 reacted_messages(&records, my_user_id, |user_id| {
215 members
216 .iter()
217 .find(|member| member.user_id.as_deref() == Some(user_id))
218 .map(|member| member.display_name.clone())
219 })
210 .flat_map(teams_core::reactions)
211 .filter(|reaction| reaction.user_name.is_none())
212 .filter_map(|reaction| reaction.user_id)
213 .collect();
214 let names = resolve_names(state, &reactor_ids);
215 reacted_messages(&records, my_user_id, |user_id| names.get(user_id).cloned())
220 216 }
@@ -9,6 +9,7 @@ use super::reactions::reacted_messages;
9use crate::app_state::{AppEvent, AppState};
9use crate::app_state::{AppEvent, AppState};
10use crate::demo;
10use crate::demo;
11use crate::notify::{IncomingTracker, channel_alerts};
11use crate::notify::{IncomingTracker, channel_alerts};
12use crate::people::resolve_names;
12
13
13const WATERMARK_KEY: &str = "activity_watermark";
14const WATERMARK_KEY: &str = "activity_watermark";
14const RECENT_WINDOW: usize = 20;
15const RECENT_WINDOW: usize = 20;
@@ -204,17 +205,12 @@ fn reacted_in(state: &AppState, conversation_id: &str, my_user_id: &str) -> Vec<
204 let Ok(records) = state.store.messages(conversation_id, None, RECENT_WINDOW) else {
205 let Ok(records) = state.store.messages(conversation_id, None, RECENT_WINDOW) else {
205 return Vec::new();
206 return Vec::new();
206 };
207 };
207 let members = state
208 let reactor_ids: Vec<String> = records
208 .sidebar
209 .chats
210 .iter()
209 .iter()
211 .find(|chat| chat.id == conversation_id)
210 .flat_map(teams_core::reactions)
212 .map(|chat| chat.members.as_slice())
211 .filter(|reaction| reaction.user_name.is_none())
213 .unwrap_or_default();
212 .filter_map(|reaction| reaction.user_id)
214 reacted_messages(&records, my_user_id, |user_id| {
213 .collect();
215 members
214 let names = resolve_names(state, &reactor_ids);
216 .iter()
215 reacted_messages(&records, my_user_id, |user_id| names.get(user_id).cloned())
217 .find(|member| member.user_id.as_deref() == Some(user_id))
218 .map(|member| member.display_name.clone())
219 })
220}
216}
crates/app/src/main.rs +1 −0
@@ -22,6 +22,7 @@ mod frame_log;
22 22 mod fuzzy;
23 23 mod notice;
24 24 mod notify;
25 mod people;
25 26 mod reaction_model;
26 27 mod read_state;
27 28 mod render;
@@ -22,6 +22,7 @@ mod frame_log;
22mod fuzzy;
22mod fuzzy;
23mod notice;
23mod notice;
24mod notify;
24mod notify;
25mod people;
25mod reaction_model;
26mod reaction_model;
26mod read_state;
27mod read_state;
27mod render;
28mod render;
crates/app/src/people.rs added +38 −0
@@ -0,0 +1,38 @@
1 use std::collections::HashMap;
2
3 use crate::app_state::AppState;
4
5 pub fn local_names(state: &AppState) -> HashMap<String, String> {
6 let mut names: HashMap<String, String> = HashMap::new();
7 let known_people = state
8 .directory
9 .me
10 .iter()
11 .map(|me| (me.user_id.clone(), me.display_name.clone()))
12 .chain(
13 state
14 .sidebar
15 .chats
16 .iter()
17 .flat_map(|chat| chat.members.iter())
18 .filter_map(|member| Some((member.user_id.clone()?, member.display_name.clone()))),
19 );
20 for (user_id, name) in known_people {
21 names.entry(user_id).or_insert(name);
22 }
23 names
24 }
25
26 pub fn resolve_names(state: &AppState, user_ids: &[String]) -> HashMap<String, String> {
27 let mut names = local_names(state);
28 names.retain(|user_id, _| user_ids.contains(user_id));
29 let missing: Vec<String> = user_ids
30 .iter()
31 .filter(|user_id| !names.contains_key(*user_id))
32 .cloned()
33 .collect();
34 if let Ok(stored) = state.store.display_names(&missing) {
35 names.extend(stored);
36 }
37 names
38 }
@@ -0,0 +1,38 @@
1use std::collections::HashMap;
2
3use crate::app_state::AppState;
4
5pub fn local_names(state: &AppState) -> HashMap<String, String> {
6 let mut names: HashMap<String, String> = HashMap::new();
7 let known_people = state
8 .directory
9 .me
10 .iter()
11 .map(|me| (me.user_id.clone(), me.display_name.clone()))
12 .chain(
13 state
14 .sidebar
15 .chats
16 .iter()
17 .flat_map(|chat| chat.members.iter())
18 .filter_map(|member| Some((member.user_id.clone()?, member.display_name.clone()))),
19 );
20 for (user_id, name) in known_people {
21 names.entry(user_id).or_insert(name);
22 }
23 names
24}
25
26pub fn resolve_names(state: &AppState, user_ids: &[String]) -> HashMap<String, String> {
27 let mut names = local_names(state);
28 names.retain(|user_id, _| user_ids.contains(user_id));
29 let missing: Vec<String> = user_ids
30 .iter()
31 .filter(|user_id| !names.contains_key(*user_id))
32 .cloned()
33 .collect();
34 if let Ok(stored) = state.store.display_names(&missing) {
35 names.extend(stored);
36 }
37 names
38}
crates/app/src/views/activity_panel.rs +49 −11
@@ -1,3 +1,5 @@
1 use std::collections::{HashMap, HashSet};
2
1 3 use chrono::{DateTime, Local, NaiveDate, Offset};
2 4 use gpui_kit::assets::IconName;
3 5 use gpui_kit::component::{h_flex, tooltip::Tooltip, v_flex};
@@ -12,6 +14,7 @@ use crate::activity::{ActivityCenter, Entry, Filter, Kind};
12 14 use crate::app_state::{AppState, chat_title};
13 15 use crate::data::is_one_on_one;
14 16 use crate::format;
17 use crate::people::resolve_names;
15 18 use crate::theme;
16 19
17 20 const PANEL_WIDTH: f32 = 420.;
@@ -38,6 +41,8 @@ pub struct ActivityPanel {
38 41 filter: Filter,
39 42 focus_handle: FocusHandle,
40 43 scroll: ScrollHandle,
44 resolved_names: HashMap<String, String>,
45 looked_up: HashSet<String>,
41 46 _observations: [Subscription; 2],
42 47 }
43 48
@@ -70,6 +75,8 @@ impl ActivityPanel {
70 75 filter,
71 76 focus_handle,
72 77 scroll: ScrollHandle::new(),
78 resolved_names: HashMap::new(),
79 looked_up: HashSet::new(),
73 80 _observations: observations,
74 81 }
75 82 }
@@ -192,12 +199,13 @@ impl ActivityPanel {
192 199 ) -> AnyElement {
193 200 let activity = self.activity.clone();
194 201 let id = entry.id;
202 let resolved_names = &self.resolved_names;
195 203 let unread = !entry.read;
196 204 let actor = entry.latest_actor();
197 205 let avatar = person_avatar(
198 206 directory,
199 207 actor.and_then(|actor| actor.user_id.as_deref()),
200 actor.map_or("", |actor| actor.name.as_str()),
208 actor.map_or("", |actor| actor.display_name(resolved_names)),
201 209 AVATAR_SIZE,
202 210 );
203 211 let group = SharedString::from(format!("activity-row-group-{id}"));
@@ -239,7 +247,7 @@ impl ActivityPanel {
239 247 } else {
240 248 theme::text_soft()
241 249 })
242 .child(headline(entry, sidebar)),
250 .child(headline(entry, sidebar, resolved_names)),
243 251 )
244 252 .child(
245 253 div()
@@ -339,8 +347,8 @@ fn kind_marker(entry: &Entry) -> Div {
339 347 }
340 348 }
341 349
342 fn headline(entry: &Entry, sidebar: &Sidebar) -> String {
343 let names = entry.names();
350 fn headline(entry: &Entry, sidebar: &Sidebar, resolved_names: &HashMap<String, String>) -> String {
351 let names = entry.names(resolved_names);
344 352 let verb = match entry.kind {
345 353 Kind::Messages => names,
346 354 Kind::Mention => format!("{names} mentioned you"),
@@ -394,12 +402,24 @@ impl Render for ActivityPanel {
394 402 let app = self.app.clone();
395 403 let activity = self.activity.clone();
396 404 let state = app.read(cx);
397 let mut rows: Vec<AnyElement> = Vec::new();
398 for section in activity
405 let sections = activity
399 406 .read(cx)
400 407 .feed()
401 .sections(self.filter, today, offset)
402 {
408 .sections(self.filter, today, offset);
409 let unresolved: Vec<String> = sections
410 .iter()
411 .flat_map(|section| section.entries.iter())
412 .flat_map(|entry| entry.unresolved_user_ids())
413 .filter(|user_id| !self.looked_up.contains(*user_id))
414 .cloned()
415 .collect();
416 if !unresolved.is_empty() {
417 self.looked_up.extend(unresolved.iter().cloned());
418 self.resolved_names
419 .extend(resolve_names(state, &unresolved));
420 }
421 let mut rows: Vec<AnyElement> = Vec::new();
422 for section in sections {
403 423 rows.push(date_header(section.bucket.label()));
404 424 for entry in section.entries {
405 425 rows.push(self.row(
@@ -470,6 +490,8 @@ impl Render for ActivityPanel {
470 490
471 491 #[cfg(test)]
472 492 mod tests {
493 use std::collections::HashMap;
494
473 495 use chrono::{TimeZone, Utc};
474 496 use store::{ChatRecord, Sidebar};
475 497
@@ -512,14 +534,30 @@ mod tests {
512 534 }],
513 535 teams: Vec::new(),
514 536 };
515 assert_eq!(headline(&entry(Kind::Messages, 1), &sidebar), "Anna");
516 537 assert_eq!(
517 headline(&entry(Kind::Reaction, 1), &sidebar),
538 headline(&entry(Kind::Messages, 1), &sidebar, &HashMap::new()),
539 "Anna"
540 );
541 assert_eq!(
542 headline(&entry(Kind::Reaction, 1), &sidebar, &HashMap::new()),
518 543 "Anna reacted"
519 544 );
520 545 assert_eq!(
521 headline(&entry(Kind::Mention, 1), &sidebar),
546 headline(&entry(Kind::Mention, 1), &sidebar, &HashMap::new()),
522 547 "Anna mentioned you"
523 548 );
524 549 }
550
551 #[test]
552 fn headline_resolves_a_persisted_unknown_actor() {
553 let mut stale = entry(Kind::Reaction, 1);
554 stale.actors[0].name = "Unknown".into();
555 let sidebar = Sidebar::default();
556 let resolved = HashMap::from([("u1".to_owned(), "Anna".to_owned())]);
557 assert_eq!(headline(&stale, &sidebar, &resolved), "Anna reacted");
558 assert_eq!(
559 headline(&stale, &sidebar, &HashMap::new()),
560 "Unknown reacted"
561 );
562 }
525 563 }
@@ -1,3 +1,5 @@
1use std::collections::{HashMap, HashSet};
2
1use chrono::{DateTime, Local, NaiveDate, Offset};
3use chrono::{DateTime, Local, NaiveDate, Offset};
2use gpui_kit::assets::IconName;
4use gpui_kit::assets::IconName;
3use gpui_kit::component::{h_flex, tooltip::Tooltip, v_flex};
5use gpui_kit::component::{h_flex, tooltip::Tooltip, v_flex};
@@ -12,6 +14,7 @@ use crate::activity::{ActivityCenter, Entry, Filter, Kind};
12use crate::app_state::{AppState, chat_title};
14use crate::app_state::{AppState, chat_title};
13use crate::data::is_one_on_one;
15use crate::data::is_one_on_one;
14use crate::format;
16use crate::format;
17use crate::people::resolve_names;
15use crate::theme;
18use crate::theme;
16
19
17const PANEL_WIDTH: f32 = 420.;
20const PANEL_WIDTH: f32 = 420.;
@@ -38,6 +41,8 @@ pub struct ActivityPanel {
38 filter: Filter,
41 filter: Filter,
39 focus_handle: FocusHandle,
42 focus_handle: FocusHandle,
40 scroll: ScrollHandle,
43 scroll: ScrollHandle,
44 resolved_names: HashMap<String, String>,
45 looked_up: HashSet<String>,
41 _observations: [Subscription; 2],
46 _observations: [Subscription; 2],
42}
47}
43
48
@@ -70,6 +75,8 @@ impl ActivityPanel {
70 filter,
75 filter,
71 focus_handle,
76 focus_handle,
72 scroll: ScrollHandle::new(),
77 scroll: ScrollHandle::new(),
78 resolved_names: HashMap::new(),
79 looked_up: HashSet::new(),
73 _observations: observations,
80 _observations: observations,
74 }
81 }
75 }
82 }
@@ -192,12 +199,13 @@ impl ActivityPanel {
192 ) -> AnyElement {
199 ) -> AnyElement {
193 let activity = self.activity.clone();
200 let activity = self.activity.clone();
194 let id = entry.id;
201 let id = entry.id;
202 let resolved_names = &self.resolved_names;
195 let unread = !entry.read;
203 let unread = !entry.read;
196 let actor = entry.latest_actor();
204 let actor = entry.latest_actor();
197 let avatar = person_avatar(
205 let avatar = person_avatar(
198 directory,
206 directory,
199 actor.and_then(|actor| actor.user_id.as_deref()),
207 actor.and_then(|actor| actor.user_id.as_deref()),
200 actor.map_or("", |actor| actor.name.as_str()),
208 actor.map_or("", |actor| actor.display_name(resolved_names)),
201 AVATAR_SIZE,
209 AVATAR_SIZE,
202 );
210 );
203 let group = SharedString::from(format!("activity-row-group-{id}"));
211 let group = SharedString::from(format!("activity-row-group-{id}"));
@@ -239,7 +247,7 @@ impl ActivityPanel {
239 } else {
247 } else {
240 theme::text_soft()
248 theme::text_soft()
241 })
249 })
242 .child(headline(entry, sidebar)),
250 .child(headline(entry, sidebar, resolved_names)),
243 )
251 )
244 .child(
252 .child(
245 div()
253 div()
@@ -339,8 +347,8 @@ fn kind_marker(entry: &Entry) -> Div {
339 }
347 }
340}
348}
341
349
342fn headline(entry: &Entry, sidebar: &Sidebar) -> String {
350fn headline(entry: &Entry, sidebar: &Sidebar, resolved_names: &HashMap<String, String>) -> String {
343 let names = entry.names();
351 let names = entry.names(resolved_names);
344 let verb = match entry.kind {
352 let verb = match entry.kind {
345 Kind::Messages => names,
353 Kind::Messages => names,
346 Kind::Mention => format!("{names} mentioned you"),
354 Kind::Mention => format!("{names} mentioned you"),
@@ -394,12 +402,24 @@ impl Render for ActivityPanel {
394 let app = self.app.clone();
402 let app = self.app.clone();
395 let activity = self.activity.clone();
403 let activity = self.activity.clone();
396 let state = app.read(cx);
404 let state = app.read(cx);
397 let mut rows: Vec<AnyElement> = Vec::new();
405 let sections = activity
398 for section in activity
399 .read(cx)
406 .read(cx)
400 .feed()
407 .feed()
401 .sections(self.filter, today, offset)
408 .sections(self.filter, today, offset);
402 {
409 let unresolved: Vec<String> = sections
410 .iter()
411 .flat_map(|section| section.entries.iter())
412 .flat_map(|entry| entry.unresolved_user_ids())
413 .filter(|user_id| !self.looked_up.contains(*user_id))
414 .cloned()
415 .collect();
416 if !unresolved.is_empty() {
417 self.looked_up.extend(unresolved.iter().cloned());
418 self.resolved_names
419 .extend(resolve_names(state, &unresolved));
420 }
421 let mut rows: Vec<AnyElement> = Vec::new();
422 for section in sections {
403 rows.push(date_header(section.bucket.label()));
423 rows.push(date_header(section.bucket.label()));
404 for entry in section.entries {
424 for entry in section.entries {
405 rows.push(self.row(
425 rows.push(self.row(
@@ -470,6 +490,8 @@ impl Render for ActivityPanel {
470
490
471#[cfg(test)]
491#[cfg(test)]
472mod tests {
492mod tests {
493 use std::collections::HashMap;
494
473 use chrono::{TimeZone, Utc};
495 use chrono::{TimeZone, Utc};
474 use store::{ChatRecord, Sidebar};
496 use store::{ChatRecord, Sidebar};
475
497
@@ -512,14 +534,30 @@ mod tests {
512 }],
534 }],
513 teams: Vec::new(),
535 teams: Vec::new(),
514 };
536 };
515 assert_eq!(headline(&entry(Kind::Messages, 1), &sidebar), "Anna");
516 assert_eq!(
537 assert_eq!(
517 headline(&entry(Kind::Reaction, 1), &sidebar),
538 headline(&entry(Kind::Messages, 1), &sidebar, &HashMap::new()),
539 "Anna"
540 );
541 assert_eq!(
542 headline(&entry(Kind::Reaction, 1), &sidebar, &HashMap::new()),
518 "Anna reacted"
543 "Anna reacted"
519 );
544 );
520 assert_eq!(
545 assert_eq!(
521 headline(&entry(Kind::Mention, 1), &sidebar),
546 headline(&entry(Kind::Mention, 1), &sidebar, &HashMap::new()),
522 "Anna mentioned you"
547 "Anna mentioned you"
523 );
548 );
524 }
549 }
550
551 #[test]
552 fn headline_resolves_a_persisted_unknown_actor() {
553 let mut stale = entry(Kind::Reaction, 1);
554 stale.actors[0].name = "Unknown".into();
555 let sidebar = Sidebar::default();
556 let resolved = HashMap::from([("u1".to_owned(), "Anna".to_owned())]);
557 assert_eq!(headline(&stale, &sidebar, &resolved), "Anna reacted");
558 assert_eq!(
559 headline(&stale, &sidebar, &HashMap::new()),
560 "Unknown reacted"
561 );
562 }
525}
563}
crates/app/src/views/conversation.rs +14 −20
@@ -34,6 +34,7 @@ use crate::data::{is_one_on_one, others};
34 34 use crate::downloads::{self, ClickAction, DownloadKey, Downloads, PartFile, RevealTarget};
35 35 use crate::emoji;
36 36 use crate::notice::short_error;
37 use crate::people::{local_names, resolve_names};
37 38 use crate::reaction_model::UNKNOWN_REACTOR;
38 39 use crate::read_state::{ReadTrigger, plan_read};
39 40 use crate::render::layout_blocks;
@@ -849,24 +850,7 @@ impl ConversationView {
849 850 fn row_context(&self, cx: &App) -> RowContext {
850 851 let now = Local::now();
851 852 let app = self.app.read(cx);
852 let mut names: HashMap<String, String> = HashMap::new();
853 let known_people = app
854 .directory
855 .me
856 .iter()
857 .map(|me| (me.user_id.clone(), me.display_name.clone()))
858 .chain(
859 app.sidebar
860 .chats
861 .iter()
862 .flat_map(|chat| chat.members.iter())
863 .filter_map(|member| {
864 Some((member.user_id.clone()?, member.display_name.clone()))
865 }),
866 );
867 for (user_id, name) in known_people {
868 names.entry(user_id).or_insert(name);
869 }
853 let names = local_names(app);
870 854 let card_overrides = self
871 855 .current
872 856 .as_ref()
@@ -905,8 +889,8 @@ impl ConversationView {
905 889 if unknown.is_empty() {
906 890 return;
907 891 }
908 let names = self.row_context(cx).names;
909 if unknown.iter().any(|user_id| names.contains_key(user_id)) {
892 let names = resolve_names(self.app.read(cx), &unknown);
893 if !names.is_empty() {
910 894 self.rebuild(false, cx);
911 895 }
912 896 }
@@ -1034,6 +1018,16 @@ impl ConversationView {
1034 1018 .flatten()
1035 1019 .is_none_or(|state| state.has_more);
1036 1020 let mut context = self.row_context(cx);
1021 let reactor_ids: Vec<String> = records
1022 .iter()
1023 .flat_map(teams_core::reactions)
1024 .filter(|reaction| reaction.user_name.is_none())
1025 .filter_map(|reaction| reaction.user_id)
1026 .filter(|user_id| !context.names.contains_key(user_id))
1027 .collect();
1028 for (user_id, name) in resolve_names(self.app.read(cx), &reactor_ids) {
1029 context.names.entry(user_id).or_insert(name);
1030 }
1037 1031 for record in &records {
1038 1032 if let (Some(user_id), Some(name)) = (&record.sender_id, &record.sender_name) {
1039 1033 context
@@ -34,6 +34,7 @@ use crate::data::{is_one_on_one, others};
34use crate::downloads::{self, ClickAction, DownloadKey, Downloads, PartFile, RevealTarget};
34use crate::downloads::{self, ClickAction, DownloadKey, Downloads, PartFile, RevealTarget};
35use crate::emoji;
35use crate::emoji;
36use crate::notice::short_error;
36use crate::notice::short_error;
37use crate::people::{local_names, resolve_names};
37use crate::reaction_model::UNKNOWN_REACTOR;
38use crate::reaction_model::UNKNOWN_REACTOR;
38use crate::read_state::{ReadTrigger, plan_read};
39use crate::read_state::{ReadTrigger, plan_read};
39use crate::render::layout_blocks;
40use crate::render::layout_blocks;
@@ -849,24 +850,7 @@ impl ConversationView {
849 fn row_context(&self, cx: &App) -> RowContext {
850 fn row_context(&self, cx: &App) -> RowContext {
850 let now = Local::now();
851 let now = Local::now();
851 let app = self.app.read(cx);
852 let app = self.app.read(cx);
852 let mut names: HashMap<String, String> = HashMap::new();
853 let names = local_names(app);
853 let known_people = app
854 .directory
855 .me
856 .iter()
857 .map(|me| (me.user_id.clone(), me.display_name.clone()))
858 .chain(
859 app.sidebar
860 .chats
861 .iter()
862 .flat_map(|chat| chat.members.iter())
863 .filter_map(|member| {
864 Some((member.user_id.clone()?, member.display_name.clone()))
865 }),
866 );
867 for (user_id, name) in known_people {
868 names.entry(user_id).or_insert(name);
869 }
870 let card_overrides = self
854 let card_overrides = self
871 .current
855 .current
872 .as_ref()
856 .as_ref()
@@ -905,8 +889,8 @@ impl ConversationView {
905 if unknown.is_empty() {
889 if unknown.is_empty() {
906 return;
890 return;
907 }
891 }
908 let names = self.row_context(cx).names;
892 let names = resolve_names(self.app.read(cx), &unknown);
909 if unknown.iter().any(|user_id| names.contains_key(user_id)) {
893 if !names.is_empty() {
910 self.rebuild(false, cx);
894 self.rebuild(false, cx);
911 }
895 }
912 }
896 }
@@ -1034,6 +1018,16 @@ impl ConversationView {
1034 .flatten()
1018 .flatten()
1035 .is_none_or(|state| state.has_more);
1019 .is_none_or(|state| state.has_more);
1036 let mut context = self.row_context(cx);
1020 let mut context = self.row_context(cx);
1021 let reactor_ids: Vec<String> = records
1022 .iter()
1023 .flat_map(teams_core::reactions)
1024 .filter(|reaction| reaction.user_name.is_none())
1025 .filter_map(|reaction| reaction.user_id)
1026 .filter(|user_id| !context.names.contains_key(user_id))
1027 .collect();
1028 for (user_id, name) in resolve_names(self.app.read(cx), &reactor_ids) {
1029 context.names.entry(user_id).or_insert(name);
1030 }
1037 for record in &records {
1031 for record in &records {
1038 if let (Some(user_id), Some(name)) = (&record.sender_id, &record.sender_name) {
1032 if let (Some(user_id), Some(name)) = (&record.sender_id, &record.sender_name) {
1039 context
1033 context
crates/store/src/messages.rs +27 −0
@@ -140,6 +140,33 @@ impl Store {
140 140 Ok(found)
141 141 }
142 142
143 pub fn display_names(&self, user_ids: &[String]) -> Result<HashMap<String, String>> {
144 if user_ids.is_empty() {
145 return Ok(HashMap::new());
146 }
147 let connection = self.lock()?;
148 let mut statement = connection.prepare_cached(
149 "SELECT value, COALESCE(
150 (SELECT display_name FROM chat_members
151 WHERE user_id = value AND display_name <> '' LIMIT 1),
152 (SELECT sender_name FROM messages
153 WHERE sender_id = value AND sender_name <> ''
154 ORDER BY created_at DESC LIMIT 1))
155 FROM json_each(?1)",
156 )?;
157 let ids = serde_json::to_string(user_ids).unwrap_or_else(|_| "[]".to_owned());
158 let rows = statement.query_map([ids], |row| {
159 Ok((row.get::<_, String>(0)?, row.get::<_, Option<String>>(1)?))
160 })?;
161 let mut names = HashMap::new();
162 for row in rows {
163 if let (user_id, Some(name)) = row? {
164 names.insert(user_id, name);
165 }
166 }
167 Ok(names)
168 }
169
143 170 pub fn thread_has_sender(
144 171 &self,
145 172 conversation_id: &str,
@@ -140,6 +140,33 @@ impl Store {
140 Ok(found)
140 Ok(found)
141 }
141 }
142
142
143 pub fn display_names(&self, user_ids: &[String]) -> Result<HashMap<String, String>> {
144 if user_ids.is_empty() {
145 return Ok(HashMap::new());
146 }
147 let connection = self.lock()?;
148 let mut statement = connection.prepare_cached(
149 "SELECT value, COALESCE(
150 (SELECT display_name FROM chat_members
151 WHERE user_id = value AND display_name <> '' LIMIT 1),
152 (SELECT sender_name FROM messages
153 WHERE sender_id = value AND sender_name <> ''
154 ORDER BY created_at DESC LIMIT 1))
155 FROM json_each(?1)",
156 )?;
157 let ids = serde_json::to_string(user_ids).unwrap_or_else(|_| "[]".to_owned());
158 let rows = statement.query_map([ids], |row| {
159 Ok((row.get::<_, String>(0)?, row.get::<_, Option<String>>(1)?))
160 })?;
161 let mut names = HashMap::new();
162 for row in rows {
163 if let (user_id, Some(name)) = row? {
164 names.insert(user_id, name);
165 }
166 }
167 Ok(names)
168 }
169
143 pub fn thread_has_sender(
170 pub fn thread_has_sender(
144 &self,
171 &self,
145 conversation_id: &str,
172 conversation_id: &str,
crates/store/src/migrations.rs +4 −0
@@ -45,6 +45,10 @@ const MIGRATIONS: &[Migration] = &[
45 45 script: include_str!("migrations/0009_muted.sql"),
46 46 after: None,
47 47 },
48 Migration {
49 script: include_str!("migrations/0010_name_lookup_indexes.sql"),
50 after: None,
51 },
48 52 ];
49 53
50 54 pub fn latest_version() -> i64 {
@@ -45,6 +45,10 @@ const MIGRATIONS: &[Migration] = &[
45 script: include_str!("migrations/0009_muted.sql"),
45 script: include_str!("migrations/0009_muted.sql"),
46 after: None,
46 after: None,
47 },
47 },
48 Migration {
49 script: include_str!("migrations/0010_name_lookup_indexes.sql"),
50 after: None,
51 },
48];
52];
49
53
50pub fn latest_version() -> i64 {
54pub fn latest_version() -> i64 {
crates/store/src/migrations/0010_name_lookup_indexes.sql added +2 −0
@@ -0,0 +1,2 @@
1 CREATE INDEX messages_by_sender ON messages (sender_id, created_at);
2 CREATE INDEX chat_members_by_user ON chat_members (user_id);
@@ -0,0 +1,2 @@
1CREATE INDEX messages_by_sender ON messages (sender_id, created_at);
2CREATE INDEX chat_members_by_user ON chat_members (user_id);
crates/store/tests/store.rs +35 −4
@@ -395,11 +395,11 @@ fn file_database_uses_wal_persists_and_migrates_once() {
395 395 let path = directory.path().join("nested").join("cache.sqlite3");
396 396 {
397 397 let store = Store::open(&path).unwrap();
398 assert_eq!(store.schema_version().unwrap(), 9);
398 assert_eq!(store.schema_version().unwrap(), 10);
399 399 store.upsert_messages(&[message("c", "m1", 1)]).unwrap();
400 400 }
401 401 let reopened = Store::open(&path).unwrap();
402 assert_eq!(reopened.schema_version().unwrap(), 9);
402 assert_eq!(reopened.schema_version().unwrap(), 10);
403 403 assert_eq!(reopened.message_count("c").unwrap(), 1);
404 404 drop(reopened);
405 405 let mode: String = rusqlite_open(&path)
@@ -431,7 +431,7 @@ fn old_schema_is_upgraded_in_place() {
431 431 connection.execute_batch("DROP TABLE messages; DROP TABLE sync_state; DROP TABLE chats; DROP TABLE chat_members; DROP TABLE channels; DROP TABLE teams; DROP TABLE meta; DROP TABLE avatars; DROP TABLE folder_items; DROP TABLE folders; DROP TABLE pinned_channels; DROP TABLE images; DROP TABLE search_keys; DROP TABLE message_search; DROP TABLE title_search; DROP TABLE team_layout; DROP TABLE channel_layout; DROP TABLE presence; DROP TABLE activity; PRAGMA user_version = 0").unwrap();
432 432 drop(connection);
433 433 let store = Store::open(&path).unwrap();
434 assert_eq!(store.schema_version().unwrap(), 9);
434 assert_eq!(store.schema_version().unwrap(), 10);
435 435 store.upsert_messages(&[message("c", "m1", 1)]).unwrap();
436 436 }
437 437
@@ -497,7 +497,7 @@ fn migration_to_v2_keeps_existing_sync_state() {
497 497 let store = Store::open(&path).unwrap();
498 498 let state = store.sync_state("c").unwrap().unwrap();
499 499 assert_eq!(state.delta_link, None);
500 assert_eq!(store.schema_version().unwrap(), 9);
500 assert_eq!(store.schema_version().unwrap(), 10);
501 501 }
502 502
503 503 #[test]
@@ -728,6 +728,7 @@ fn migration_indexes_rows_that_predate_search() {
728 728 DROP TRIGGER channels_title_insert; DROP TRIGGER channels_title_update; DROP TRIGGER channels_title_delete;
729 729 DROP TABLE images; DROP TABLE search_keys; DROP TABLE message_search; DROP TABLE title_search;
730 730 DROP TABLE team_layout; DROP TABLE channel_layout; DROP TABLE presence; DROP TABLE activity;
731 DROP INDEX messages_by_sender; DROP INDEX chat_members_by_user;
731 732 ALTER TABLE messages DROP COLUMN sender_application_id;
732 733 ALTER TABLE chats DROP COLUMN muted;
733 734 PRAGMA user_version = 3;",
@@ -951,3 +952,33 @@ fn activity_prune_drops_only_older_rows() {
951 952 .collect();
952 953 assert_eq!(ids, vec![3, 2]);
953 954 }
955
956 #[test]
957 fn display_names_prefer_members_then_latest_sender_name() {
958 let store = Store::open_in_memory().unwrap();
959 store
960 .upsert_chats(&[chat("chat-1", "Planning", Some(at(5)))])
961 .unwrap();
962 let sent_by = |message_id: &str, minute: u32, sender: &str, name: Option<&str>| MessageRecord {
963 sender_id: Some(sender.to_owned()),
964 sender_name: name.map(str::to_owned),
965 ..message("channel", message_id, minute)
966 };
967 store
968 .upsert_messages(&[
969 sent_by("m1", 1, "user-ada", Some("Ada Sender")),
970 sent_by("m2", 2, "user-sam", Some("Sam Old")),
971 sent_by("m3", 3, "user-sam", Some("Sam New")),
972 sent_by("m4", 4, "user-sam", None),
973 sent_by("m5", 5, "user-blank", Some("")),
974 ])
975 .unwrap();
976 let wanted: Vec<String> = ["user-ada", "user-sam", "user-blank", "user-none"]
977 .map(str::to_owned)
978 .to_vec();
979 let names = store.display_names(&wanted).unwrap();
980 assert_eq!(names.len(), 2);
981 assert_eq!(names["user-ada"], "Ada Example");
982 assert_eq!(names["user-sam"], "Sam New");
983 assert!(store.display_names(&[]).unwrap().is_empty());
984 }
@@ -395,11 +395,11 @@ fn file_database_uses_wal_persists_and_migrates_once() {
395 let path = directory.path().join("nested").join("cache.sqlite3");
395 let path = directory.path().join("nested").join("cache.sqlite3");
396 {
396 {
397 let store = Store::open(&path).unwrap();
397 let store = Store::open(&path).unwrap();
398 assert_eq!(store.schema_version().unwrap(), 9);
398 assert_eq!(store.schema_version().unwrap(), 10);
399 store.upsert_messages(&[message("c", "m1", 1)]).unwrap();
399 store.upsert_messages(&[message("c", "m1", 1)]).unwrap();
400 }
400 }
401 let reopened = Store::open(&path).unwrap();
401 let reopened = Store::open(&path).unwrap();
402 assert_eq!(reopened.schema_version().unwrap(), 9);
402 assert_eq!(reopened.schema_version().unwrap(), 10);
403 assert_eq!(reopened.message_count("c").unwrap(), 1);
403 assert_eq!(reopened.message_count("c").unwrap(), 1);
404 drop(reopened);
404 drop(reopened);
405 let mode: String = rusqlite_open(&path)
405 let mode: String = rusqlite_open(&path)
@@ -431,7 +431,7 @@ fn old_schema_is_upgraded_in_place() {
431 connection.execute_batch("DROP TABLE messages; DROP TABLE sync_state; DROP TABLE chats; DROP TABLE chat_members; DROP TABLE channels; DROP TABLE teams; DROP TABLE meta; DROP TABLE avatars; DROP TABLE folder_items; DROP TABLE folders; DROP TABLE pinned_channels; DROP TABLE images; DROP TABLE search_keys; DROP TABLE message_search; DROP TABLE title_search; DROP TABLE team_layout; DROP TABLE channel_layout; DROP TABLE presence; DROP TABLE activity; PRAGMA user_version = 0").unwrap();
431 connection.execute_batch("DROP TABLE messages; DROP TABLE sync_state; DROP TABLE chats; DROP TABLE chat_members; DROP TABLE channels; DROP TABLE teams; DROP TABLE meta; DROP TABLE avatars; DROP TABLE folder_items; DROP TABLE folders; DROP TABLE pinned_channels; DROP TABLE images; DROP TABLE search_keys; DROP TABLE message_search; DROP TABLE title_search; DROP TABLE team_layout; DROP TABLE channel_layout; DROP TABLE presence; DROP TABLE activity; PRAGMA user_version = 0").unwrap();
432 drop(connection);
432 drop(connection);
433 let store = Store::open(&path).unwrap();
433 let store = Store::open(&path).unwrap();
434 assert_eq!(store.schema_version().unwrap(), 9);
434 assert_eq!(store.schema_version().unwrap(), 10);
435 store.upsert_messages(&[message("c", "m1", 1)]).unwrap();
435 store.upsert_messages(&[message("c", "m1", 1)]).unwrap();
436}
436}
437
437
@@ -497,7 +497,7 @@ fn migration_to_v2_keeps_existing_sync_state() {
497 let store = Store::open(&path).unwrap();
497 let store = Store::open(&path).unwrap();
498 let state = store.sync_state("c").unwrap().unwrap();
498 let state = store.sync_state("c").unwrap().unwrap();
499 assert_eq!(state.delta_link, None);
499 assert_eq!(state.delta_link, None);
500 assert_eq!(store.schema_version().unwrap(), 9);
500 assert_eq!(store.schema_version().unwrap(), 10);
501}
501}
502
502
503#[test]
503#[test]
@@ -728,6 +728,7 @@ fn migration_indexes_rows_that_predate_search() {
728 DROP TRIGGER channels_title_insert; DROP TRIGGER channels_title_update; DROP TRIGGER channels_title_delete;
728 DROP TRIGGER channels_title_insert; DROP TRIGGER channels_title_update; DROP TRIGGER channels_title_delete;
729 DROP TABLE images; DROP TABLE search_keys; DROP TABLE message_search; DROP TABLE title_search;
729 DROP TABLE images; DROP TABLE search_keys; DROP TABLE message_search; DROP TABLE title_search;
730 DROP TABLE team_layout; DROP TABLE channel_layout; DROP TABLE presence; DROP TABLE activity;
730 DROP TABLE team_layout; DROP TABLE channel_layout; DROP TABLE presence; DROP TABLE activity;
731 DROP INDEX messages_by_sender; DROP INDEX chat_members_by_user;
731 ALTER TABLE messages DROP COLUMN sender_application_id;
732 ALTER TABLE messages DROP COLUMN sender_application_id;
732 ALTER TABLE chats DROP COLUMN muted;
733 ALTER TABLE chats DROP COLUMN muted;
733 PRAGMA user_version = 3;",
734 PRAGMA user_version = 3;",
@@ -951,3 +952,33 @@ fn activity_prune_drops_only_older_rows() {
951 .collect();
952 .collect();
952 assert_eq!(ids, vec![3, 2]);
953 assert_eq!(ids, vec![3, 2]);
953}
954}
955
956#[test]
957fn display_names_prefer_members_then_latest_sender_name() {
958 let store = Store::open_in_memory().unwrap();
959 store
960 .upsert_chats(&[chat("chat-1", "Planning", Some(at(5)))])
961 .unwrap();
962 let sent_by = |message_id: &str, minute: u32, sender: &str, name: Option<&str>| MessageRecord {
963 sender_id: Some(sender.to_owned()),
964 sender_name: name.map(str::to_owned),
965 ..message("channel", message_id, minute)
966 };
967 store
968 .upsert_messages(&[
969 sent_by("m1", 1, "user-ada", Some("Ada Sender")),
970 sent_by("m2", 2, "user-sam", Some("Sam Old")),
971 sent_by("m3", 3, "user-sam", Some("Sam New")),
972 sent_by("m4", 4, "user-sam", None),
973 sent_by("m5", 5, "user-blank", Some("")),
974 ])
975 .unwrap();
976 let wanted: Vec<String> = ["user-ada", "user-sam", "user-blank", "user-none"]
977 .map(str::to_owned)
978 .to_vec();
979 let names = store.display_names(&wanted).unwrap();
980 assert_eq!(names.len(), 2);
981 assert_eq!(names["user-ada"], "Ada Example");
982 assert_eq!(names["user-sam"], "Sam New");
983 assert!(store.display_names(&[]).unwrap().is_empty());
984}