BlueGit

ict rusty-teams

Merge remote-tracking branch 'origin/main' into feat/composer-quote-table-markdown

metis Daniel Däschle · pushed by metis

Authored 2026-10-17 · 6 weeks ago

Hash
24a64e8989575032d651d0b636cb4afec09e7f9c
16 files changed +145 −27
crates/app/src/layout_guard.rs +70 −0
@@ -988,3 +988,73 @@ fn lines_are_solid() {
988 988 .collect();
989 989 assert!(violations.is_empty(), "{}", violations.join("\n"));
990 990 }
991
992 fn indentation(line: &str) -> usize {
993 line.len() - line.trim_start().len()
994 }
995
996 fn chain_lines<'a>(lines: &[&'a str], index: usize) -> Vec<&'a str> {
997 let indent = indentation(lines[index]);
998 let belongs = |line: &&str| line.trim().is_empty() || indentation(line) >= indent;
999 let start = lines[..index]
1000 .iter()
1001 .rposition(|line| !belongs(line))
1002 .map_or(0, |position| position + 1);
1003 let end = lines[index..]
1004 .iter()
1005 .position(|line| !belongs(line))
1006 .map_or(lines.len(), |position| index + position);
1007 lines[start..end]
1008 .iter()
1009 .filter(|line| indentation(line) == indent)
1010 .copied()
1011 .collect()
1012 }
1013
1014 fn shrinking_rows(row_height: &Regex, source: &str) -> Vec<usize> {
1015 let lines: Vec<&str> = source.lines().collect();
1016 (0..lines.len())
1017 .filter(|&index| row_height.is_match(lines[index]))
1018 .filter(|&index| {
1019 !chain_lines(&lines, index).iter().any(|line| {
1020 let line = line.trim();
1021 line.starts_with(".flex_none()") || line.starts_with(".flex_shrink_0()")
1022 })
1023 })
1024 .map(|index| index + 1)
1025 .collect()
1026 }
1027
1028 fn row_height_pattern() -> Regex {
1029 Regex::new(r"^\s*\.h\(px\(((\w+_)?(ROW|ENTRY)_HEIGHT|row_height)\)\)").expect("pattern")
1030 }
1031
1032 #[test]
1033 fn matcher_finds_rows_without_flex_none() {
1034 let source = "fn rows() {\n h_flex()\n .h(px(ROW_HEIGHT))\n .child(\n div()\n .flex_none(),\n );\n div()\n .id(1)\n .h(px(OWN_ROW_HEIGHT))\n .flex_none();\n}\n";
1035 assert_eq!(shrinking_rows(&row_height_pattern(), source), [3]);
1036 }
1037
1038 #[test]
1039 fn fixed_height_rows_never_shrink() {
1040 let row_height = row_height_pattern();
1041 let mut files = Vec::new();
1042 for root in source_roots() {
1043 source_files(&root, &mut files);
1044 }
1045 let violations: Vec<String> = files
1046 .iter()
1047 .filter(|file| !file.ends_with("layout_guard.rs"))
1048 .flat_map(|file| {
1049 let source = fs::read_to_string(file).expect("read source file");
1050 shrinking_rows(&row_height, &source)
1051 .into_iter()
1052 .map(|line| format!("{}:{line}", file.display()))
1053 .collect::<Vec<_>>()
1054 })
1055 .collect();
1056 assert!(
1057 violations.is_empty(),
1058 "a fixed-height row needs .flex_none(), or a max_h scroll list shrinks it to its content: {violations:?}"
1059 );
1060 }
@@ -988,3 +988,73 @@ fn lines_are_solid() {
988 .collect();
988 .collect();
989 assert!(violations.is_empty(), "{}", violations.join("\n"));
989 assert!(violations.is_empty(), "{}", violations.join("\n"));
990}
990}
991
992fn indentation(line: &str) -> usize {
993 line.len() - line.trim_start().len()
994}
995
996fn chain_lines<'a>(lines: &[&'a str], index: usize) -> Vec<&'a str> {
997 let indent = indentation(lines[index]);
998 let belongs = |line: &&str| line.trim().is_empty() || indentation(line) >= indent;
999 let start = lines[..index]
1000 .iter()
1001 .rposition(|line| !belongs(line))
1002 .map_or(0, |position| position + 1);
1003 let end = lines[index..]
1004 .iter()
1005 .position(|line| !belongs(line))
1006 .map_or(lines.len(), |position| index + position);
1007 lines[start..end]
1008 .iter()
1009 .filter(|line| indentation(line) == indent)
1010 .copied()
1011 .collect()
1012}
1013
1014fn shrinking_rows(row_height: &Regex, source: &str) -> Vec<usize> {
1015 let lines: Vec<&str> = source.lines().collect();
1016 (0..lines.len())
1017 .filter(|&index| row_height.is_match(lines[index]))
1018 .filter(|&index| {
1019 !chain_lines(&lines, index).iter().any(|line| {
1020 let line = line.trim();
1021 line.starts_with(".flex_none()") || line.starts_with(".flex_shrink_0()")
1022 })
1023 })
1024 .map(|index| index + 1)
1025 .collect()
1026}
1027
1028fn row_height_pattern() -> Regex {
1029 Regex::new(r"^\s*\.h\(px\(((\w+_)?(ROW|ENTRY)_HEIGHT|row_height)\)\)").expect("pattern")
1030}
1031
1032#[test]
1033fn matcher_finds_rows_without_flex_none() {
1034 let source = "fn rows() {\n h_flex()\n .h(px(ROW_HEIGHT))\n .child(\n div()\n .flex_none(),\n );\n div()\n .id(1)\n .h(px(OWN_ROW_HEIGHT))\n .flex_none();\n}\n";
1035 assert_eq!(shrinking_rows(&row_height_pattern(), source), [3]);
1036}
1037
1038#[test]
1039fn fixed_height_rows_never_shrink() {
1040 let row_height = row_height_pattern();
1041 let mut files = Vec::new();
1042 for root in source_roots() {
1043 source_files(&root, &mut files);
1044 }
1045 let violations: Vec<String> = files
1046 .iter()
1047 .filter(|file| !file.ends_with("layout_guard.rs"))
1048 .flat_map(|file| {
1049 let source = fs::read_to_string(file).expect("read source file");
1050 shrinking_rows(&row_height, &source)
1051 .into_iter()
1052 .map(|line| format!("{}:{line}", file.display()))
1053 .collect::<Vec<_>>()
1054 })
1055 .collect();
1056 assert!(
1057 violations.is_empty(),
1058 "a fixed-height row needs .flex_none(), or a max_h scroll list shrinks it to its content: {violations:?}"
1059 );
1060}
crates/app/src/views/calls_tab.rs +2 −0
@@ -62,6 +62,7 @@ fn call_row(
62 62 .id(SharedString::from(format!("call-{}", row.key)))
63 63 .mx(px(6.))
64 64 .h(px(CALL_ROW_HEIGHT))
65 .flex_none()
65 66 .px(px(10.))
66 67 .gap(px(12.))
67 68 .items_center()
@@ -336,6 +337,7 @@ fn agenda_row(
336 337 .id(SharedString::from(format!("agenda-{}", row.key)))
337 338 .mx(px(6.))
338 339 .h(px(AGENDA_ROW_HEIGHT))
340 .flex_none()
339 341 .px(px(10.))
340 342 .gap(px(12.))
341 343 .items_center()
@@ -62,6 +62,7 @@ fn call_row(
62 .id(SharedString::from(format!("call-{}", row.key)))
62 .id(SharedString::from(format!("call-{}", row.key)))
63 .mx(px(6.))
63 .mx(px(6.))
64 .h(px(CALL_ROW_HEIGHT))
64 .h(px(CALL_ROW_HEIGHT))
65 .flex_none()
65 .px(px(10.))
66 .px(px(10.))
66 .gap(px(12.))
67 .gap(px(12.))
67 .items_center()
68 .items_center()
@@ -336,6 +337,7 @@ fn agenda_row(
336 .id(SharedString::from(format!("agenda-{}", row.key)))
337 .id(SharedString::from(format!("agenda-{}", row.key)))
337 .mx(px(6.))
338 .mx(px(6.))
338 .h(px(AGENDA_ROW_HEIGHT))
339 .h(px(AGENDA_ROW_HEIGHT))
340 .flex_none()
339 .px(px(10.))
341 .px(px(10.))
340 .gap(px(12.))
342 .gap(px(12.))
341 .items_center()
343 .items_center()
crates/app/src/views/chat_members.rs +9 −1
@@ -22,6 +22,7 @@ const LIST_MAX_HEIGHT: f32 = 300.;
22 22 const POPUP_OFFSET: f32 = 16.;
23 23 const SECTION_HEIGHT: f32 = 24.;
24 24 const ROW_HEIGHT: f32 = 40.;
25 const OWN_ROW_HEIGHT: f32 = 43.;
25 26 const AVATAR_SIZE: f32 = 32.;
26 27 const EDGE_PADDING: f32 = 12.;
27 28 const ACTION_HEIGHT: f32 = 36.;
@@ -75,6 +76,7 @@ fn members_panel(
75 76 .child(
76 77 div()
77 78 .h(px(SECTION_HEIGHT))
79 .flex_none()
78 80 .px(px(EDGE_PADDING))
79 81 .flex()
80 82 .items_center()
@@ -148,10 +150,16 @@ fn member_row(
148 150 None => avatar,
149 151 };
150 152 let opens_chat = user_id.filter(|_| !row.is_self).map(str::to_owned);
153 let row_height = if row.is_self {
154 OWN_ROW_HEIGHT
155 } else {
156 ROW_HEIGHT
157 };
151 158 h_flex()
152 159 .id(("chat-member", index))
153 160 .group(group.clone())
154 .h(px(ROW_HEIGHT))
161 .h(px(row_height))
162 .flex_none()
155 163 .px(px(EDGE_PADDING))
156 164 .gap(px(8.))
157 165 .items_center()
@@ -22,6 +22,7 @@ const LIST_MAX_HEIGHT: f32 = 300.;
22const POPUP_OFFSET: f32 = 16.;
22const POPUP_OFFSET: f32 = 16.;
23const SECTION_HEIGHT: f32 = 24.;
23const SECTION_HEIGHT: f32 = 24.;
24const ROW_HEIGHT: f32 = 40.;
24const ROW_HEIGHT: f32 = 40.;
25const OWN_ROW_HEIGHT: f32 = 43.;
25const AVATAR_SIZE: f32 = 32.;
26const AVATAR_SIZE: f32 = 32.;
26const EDGE_PADDING: f32 = 12.;
27const EDGE_PADDING: f32 = 12.;
27const ACTION_HEIGHT: f32 = 36.;
28const ACTION_HEIGHT: f32 = 36.;
@@ -75,6 +76,7 @@ fn members_panel(
75 .child(
76 .child(
76 div()
77 div()
77 .h(px(SECTION_HEIGHT))
78 .h(px(SECTION_HEIGHT))
79 .flex_none()
78 .px(px(EDGE_PADDING))
80 .px(px(EDGE_PADDING))
79 .flex()
81 .flex()
80 .items_center()
82 .items_center()
@@ -148,10 +150,16 @@ fn member_row(
148 None => avatar,
150 None => avatar,
149 };
151 };
150 let opens_chat = user_id.filter(|_| !row.is_self).map(str::to_owned);
152 let opens_chat = user_id.filter(|_| !row.is_self).map(str::to_owned);
153 let row_height = if row.is_self {
154 OWN_ROW_HEIGHT
155 } else {
156 ROW_HEIGHT
157 };
151 h_flex()
158 h_flex()
152 .id(("chat-member", index))
159 .id(("chat-member", index))
153 .group(group.clone())
160 .group(group.clone())
154 .h(px(ROW_HEIGHT))
161 .h(px(row_height))
162 .flex_none()
155 .px(px(EDGE_PADDING))
163 .px(px(EDGE_PADDING))
156 .gap(px(8.))
164 .gap(px(8.))
157 .items_center()
165 .items_center()
crates/app/src/views/composer.rs +1 −0
@@ -2213,6 +2213,7 @@ impl Composer {
2213 2213 .mx(px(6.))
2214 2214 .px(px(6.))
2215 2215 .h(px(POPUP_ROW_HEIGHT))
2216 .flex_none()
2216 2217 .gap(px(8.))
2217 2218 .items_center()
2218 2219 .rounded(px(6.))
@@ -2213,6 +2213,7 @@ impl Composer {
2213 .mx(px(6.))
2213 .mx(px(6.))
2214 .px(px(6.))
2214 .px(px(6.))
2215 .h(px(POPUP_ROW_HEIGHT))
2215 .h(px(POPUP_ROW_HEIGHT))
2216 .flex_none()
2216 .gap(px(8.))
2217 .gap(px(8.))
2217 .items_center()
2218 .items_center()
2218 .rounded(px(6.))
2219 .rounded(px(6.))
crates/app/src/views/composer/schedule.rs +1 −0
@@ -57,6 +57,7 @@ fn menu_row(id: ElementId, highlighted: bool) -> Stateful<Div> {
57 57 h_flex()
58 58 .id(id)
59 59 .h(px(ROW_HEIGHT))
60 .flex_none()
60 61 .px(px(10.))
61 62 .gap(px(10.))
62 63 .items_center()
@@ -57,6 +57,7 @@ fn menu_row(id: ElementId, highlighted: bool) -> Stateful<Div> {
57 h_flex()
57 h_flex()
58 .id(id)
58 .id(id)
59 .h(px(ROW_HEIGHT))
59 .h(px(ROW_HEIGHT))
60 .flex_none()
60 .px(px(10.))
61 .px(px(10.))
61 .gap(px(10.))
62 .gap(px(10.))
62 .items_center()
63 .items_center()
crates/app/src/views/new_chat.rs +1 −0
@@ -474,6 +474,7 @@ impl NewChatDraft {
474 474 .id(ElementId::Name(format!("new-chat-result-{index}").into()))
475 475 .px(px(6.))
476 476 .h(px(POPUP_ROW_HEIGHT))
477 .flex_none()
477 478 .gap(px(8.))
478 479 .items_center()
479 480 .rounded(px(6.))
@@ -474,6 +474,7 @@ impl NewChatDraft {
474 .id(ElementId::Name(format!("new-chat-result-{index}").into()))
474 .id(ElementId::Name(format!("new-chat-result-{index}").into()))
475 .px(px(6.))
475 .px(px(6.))
476 .h(px(POPUP_ROW_HEIGHT))
476 .h(px(POPUP_ROW_HEIGHT))
477 .flex_none()
477 .gap(px(8.))
478 .gap(px(8.))
478 .items_center()
479 .items_center()
479 .rounded(px(6.))
480 .rounded(px(6.))
crates/app/src/views/reaction_pills.rs +1 −0
@@ -197,6 +197,7 @@ fn tab_button(tab: &ReactionTab, active: bool, select_tab: SelectTab) -> Statefu
197 197 fn entry_row(entry: &ReactionEntry, directory: &Directory) -> Div {
198 198 h_flex()
199 199 .h(px(ENTRY_HEIGHT))
200 .flex_none()
200 201 .px(px(8.))
201 202 .gap(px(8.))
202 203 .items_center()
@@ -197,6 +197,7 @@ fn tab_button(tab: &ReactionTab, active: bool, select_tab: SelectTab) -> Statefu
197fn entry_row(entry: &ReactionEntry, directory: &Directory) -> Div {
197fn entry_row(entry: &ReactionEntry, directory: &Directory) -> Div {
198 h_flex()
198 h_flex()
199 .h(px(ENTRY_HEIGHT))
199 .h(px(ENTRY_HEIGHT))
200 .flex_none()
200 .px(px(8.))
201 .px(px(8.))
201 .gap(px(8.))
202 .gap(px(8.))
202 .items_center()
203 .items_center()
crates/app/src/views/shared_tab.rs +1 −0
@@ -348,6 +348,7 @@ fn skeleton_rows() -> impl IntoElement {
348 348 ))
349 349 .w_full()
350 350 .h(px(ROW_HEIGHT))
351 .flex_none()
351 352 .px(px(SIDE_PADDING))
352 353 .gap(px(12.))
353 354 .items_center()
@@ -348,6 +348,7 @@ fn skeleton_rows() -> impl IntoElement {
348 ))
348 ))
349 .w_full()
349 .w_full()
350 .h(px(ROW_HEIGHT))
350 .h(px(ROW_HEIGHT))
351 .flex_none()
351 .px(px(SIDE_PADDING))
352 .px(px(SIDE_PADDING))
352 .gap(px(12.))
353 .gap(px(12.))
353 .items_center()
354 .items_center()
crates/app/src/views/sidebar.rs +5 −0
@@ -746,6 +746,7 @@ impl SidebarView {
746 746 .id("new-chat-draft")
747 747 .mx(px(6.))
748 748 .h(px(ROW_HEIGHT))
749 .flex_none()
749 750 .px(px(10.))
750 751 .gap(px(12.))
751 752 .items_center()
@@ -1010,6 +1011,7 @@ impl SidebarView {
1010 1011 .id(SharedString::from(format!("chat-{}", item.id)))
1011 1012 .mx(px(6.))
1012 1013 .h(px(ROW_HEIGHT))
1014 .flex_none()
1013 1015 .px(px(10.))
1014 1016 .gap(px(12.))
1015 1017 .items_center()
@@ -1327,6 +1329,7 @@ impl SidebarView {
1327 1329 .id(SharedString::from(format!("team-{team_id}")))
1328 1330 .mx(px(6.))
1329 1331 .h(px(TEAM_ROW_HEIGHT))
1332 .flex_none()
1330 1333 .px(px(10.))
1331 1334 .gap(px(8.))
1332 1335 .items_center()
@@ -1426,6 +1429,7 @@ impl SidebarView {
1426 1429 .id(id)
1427 1430 .mx(px(6.))
1428 1431 .h(px(REVEAL_ROW_HEIGHT))
1432 .flex_none()
1429 1433 .pl(px(indent))
1430 1434 .pr(px(10.))
1431 1435 .gap(px(8.))
@@ -1466,6 +1470,7 @@ impl SidebarView {
1466 1470 .id(SharedString::from(format!("channel-{}", channel.id)))
1467 1471 .mx(px(6.))
1468 1472 .h(px(TEAM_ROW_HEIGHT))
1473 .flex_none()
1469 1474 .pl(px(40.))
1470 1475 .pr(px(10.))
1471 1476 .gap(px(8.))
@@ -746,6 +746,7 @@ impl SidebarView {
746 .id("new-chat-draft")
746 .id("new-chat-draft")
747 .mx(px(6.))
747 .mx(px(6.))
748 .h(px(ROW_HEIGHT))
748 .h(px(ROW_HEIGHT))
749 .flex_none()
749 .px(px(10.))
750 .px(px(10.))
750 .gap(px(12.))
751 .gap(px(12.))
751 .items_center()
752 .items_center()
@@ -1010,6 +1011,7 @@ impl SidebarView {
1010 .id(SharedString::from(format!("chat-{}", item.id)))
1011 .id(SharedString::from(format!("chat-{}", item.id)))
1011 .mx(px(6.))
1012 .mx(px(6.))
1012 .h(px(ROW_HEIGHT))
1013 .h(px(ROW_HEIGHT))
1014 .flex_none()
1013 .px(px(10.))
1015 .px(px(10.))
1014 .gap(px(12.))
1016 .gap(px(12.))
1015 .items_center()
1017 .items_center()
@@ -1327,6 +1329,7 @@ impl SidebarView {
1327 .id(SharedString::from(format!("team-{team_id}")))
1329 .id(SharedString::from(format!("team-{team_id}")))
1328 .mx(px(6.))
1330 .mx(px(6.))
1329 .h(px(TEAM_ROW_HEIGHT))
1331 .h(px(TEAM_ROW_HEIGHT))
1332 .flex_none()
1330 .px(px(10.))
1333 .px(px(10.))
1331 .gap(px(8.))
1334 .gap(px(8.))
1332 .items_center()
1335 .items_center()
@@ -1426,6 +1429,7 @@ impl SidebarView {
1426 .id(id)
1429 .id(id)
1427 .mx(px(6.))
1430 .mx(px(6.))
1428 .h(px(REVEAL_ROW_HEIGHT))
1431 .h(px(REVEAL_ROW_HEIGHT))
1432 .flex_none()
1429 .pl(px(indent))
1433 .pl(px(indent))
1430 .pr(px(10.))
1434 .pr(px(10.))
1431 .gap(px(8.))
1435 .gap(px(8.))
@@ -1466,6 +1470,7 @@ impl SidebarView {
1466 .id(SharedString::from(format!("channel-{}", channel.id)))
1470 .id(SharedString::from(format!("channel-{}", channel.id)))
1467 .mx(px(6.))
1471 .mx(px(6.))
1468 .h(px(TEAM_ROW_HEIGHT))
1472 .h(px(TEAM_ROW_HEIGHT))
1473 .flex_none()
1469 .pl(px(40.))
1474 .pl(px(40.))
1470 .pr(px(10.))
1475 .pr(px(10.))
1471 .gap(px(8.))
1476 .gap(px(8.))
crates/core/src/mapping.rs +25 −12
@@ -10,8 +10,6 @@ use crate::markdown::plain_text_to_html;
10 10 use crate::preview::OwnedPreview;
11 11 use crate::stored::{AttachmentInfo, MentionInfo, QuoteInfo, ReactionInfo};
12 12
13 const NO_NAME: &str = "?";
14
15 13 pub fn graph_hidden(chat: &Chat) -> bool {
16 14 chat.viewpoint
17 15 .as_ref()
@@ -49,7 +47,7 @@ pub fn chat_record(chat: &Chat, my_user_id: &str) -> ChatRecord {
49 47 title: chat.title(my_user_id),
50 48 member_summary: others
51 49 .iter()
52 .map(|member| member_name(member))
50 .map(|member| member.name())
53 51 .collect::<Vec<_>>()
54 52 .join(", "),
55 53 last_message_at,
@@ -62,7 +60,7 @@ pub fn chat_record(chat: &Chat, my_user_id: &str) -> ChatRecord {
62 60 .iter()
63 61 .map(|member| MemberRecord {
64 62 user_id: member.user_id.clone(),
65 display_name: member_name(member).to_owned(),
63 display_name: member.name().to_owned(),
66 64 })
67 65 .collect(),
68 66 last_message_deleted: preview.as_ref().is_some_and(|preview| preview.deleted),
@@ -78,14 +76,6 @@ pub fn chat_record(chat: &Chat, my_user_id: &str) -> ChatRecord {
78 76 }
79 77 }
80 78
81 fn member_name(member: &graph::Member) -> &str {
82 member
83 .display_name
84 .as_deref()
85 .or(member.email.as_deref())
86 .unwrap_or(NO_NAME)
87 }
88
89 79 fn is_unread(
90 80 last_message: Option<DateTime<Utc>>,
91 81 last_read: Option<DateTime<Utc>>,
@@ -350,6 +340,29 @@ mod tests {
350 340 assert!(!record.last_event_system);
351 341 }
352 342
343 #[test]
344 fn a_member_without_name_or_email_is_an_unknown_user() {
345 let chat: Chat = serde_json::from_value(json!({
346 "id": "19:group@thread.v2",
347 "chatType": "group",
348 "members": [
349 {"userId": "me", "displayName": "Daniel"},
350 {"userId": "gone", "displayName": null, "email": ""},
351 {"userId": "mail", "displayName": " ", "email": "anna@example.com"},
352 ],
353 }))
354 .unwrap();
355 let record = chat_record(&chat, "me");
356 let names: Vec<&str> = record
357 .members
358 .iter()
359 .map(|member| member.display_name.as_str())
360 .collect();
361 assert_eq!(names, ["Daniel", "Unknown User", "anna@example.com"]);
362 assert_eq!(record.title, "Unknown User, anna@example.com");
363 assert_eq!(graph::UNKNOWN_USER_NAME, store::UNKNOWN_USER_NAME);
364 }
365
353 366 fn record_with_subject(subject: serde_json::Value) -> Option<String> {
354 367 let message: Message = serde_json::from_value(json!({
355 368 "id": "1",
@@ -10,8 +10,6 @@ use crate::markdown::plain_text_to_html;
10use crate::preview::OwnedPreview;
10use crate::preview::OwnedPreview;
11use crate::stored::{AttachmentInfo, MentionInfo, QuoteInfo, ReactionInfo};
11use crate::stored::{AttachmentInfo, MentionInfo, QuoteInfo, ReactionInfo};
12
12
13const NO_NAME: &str = "?";
14
15pub fn graph_hidden(chat: &Chat) -> bool {
13pub fn graph_hidden(chat: &Chat) -> bool {
16 chat.viewpoint
14 chat.viewpoint
17 .as_ref()
15 .as_ref()
@@ -49,7 +47,7 @@ pub fn chat_record(chat: &Chat, my_user_id: &str) -> ChatRecord {
49 title: chat.title(my_user_id),
47 title: chat.title(my_user_id),
50 member_summary: others
48 member_summary: others
51 .iter()
49 .iter()
52 .map(|member| member_name(member))
50 .map(|member| member.name())
53 .collect::<Vec<_>>()
51 .collect::<Vec<_>>()
54 .join(", "),
52 .join(", "),
55 last_message_at,
53 last_message_at,
@@ -62,7 +60,7 @@ pub fn chat_record(chat: &Chat, my_user_id: &str) -> ChatRecord {
62 .iter()
60 .iter()
63 .map(|member| MemberRecord {
61 .map(|member| MemberRecord {
64 user_id: member.user_id.clone(),
62 user_id: member.user_id.clone(),
65 display_name: member_name(member).to_owned(),
63 display_name: member.name().to_owned(),
66 })
64 })
67 .collect(),
65 .collect(),
68 last_message_deleted: preview.as_ref().is_some_and(|preview| preview.deleted),
66 last_message_deleted: preview.as_ref().is_some_and(|preview| preview.deleted),
@@ -78,14 +76,6 @@ pub fn chat_record(chat: &Chat, my_user_id: &str) -> ChatRecord {
78 }
76 }
79}
77}
80
78
81fn member_name(member: &graph::Member) -> &str {
82 member
83 .display_name
84 .as_deref()
85 .or(member.email.as_deref())
86 .unwrap_or(NO_NAME)
87}
88
89fn is_unread(
79fn is_unread(
90 last_message: Option<DateTime<Utc>>,
80 last_message: Option<DateTime<Utc>>,
91 last_read: Option<DateTime<Utc>>,
81 last_read: Option<DateTime<Utc>>,
@@ -350,6 +340,29 @@ mod tests {
350 assert!(!record.last_event_system);
340 assert!(!record.last_event_system);
351 }
341 }
352
342
343 #[test]
344 fn a_member_without_name_or_email_is_an_unknown_user() {
345 let chat: Chat = serde_json::from_value(json!({
346 "id": "19:group@thread.v2",
347 "chatType": "group",
348 "members": [
349 {"userId": "me", "displayName": "Daniel"},
350 {"userId": "gone", "displayName": null, "email": ""},
351 {"userId": "mail", "displayName": " ", "email": "anna@example.com"},
352 ],
353 }))
354 .unwrap();
355 let record = chat_record(&chat, "me");
356 let names: Vec<&str> = record
357 .members
358 .iter()
359 .map(|member| member.display_name.as_str())
360 .collect();
361 assert_eq!(names, ["Daniel", "Unknown User", "anna@example.com"]);
362 assert_eq!(record.title, "Unknown User, anna@example.com");
363 assert_eq!(graph::UNKNOWN_USER_NAME, store::UNKNOWN_USER_NAME);
364 }
365
353 fn record_with_subject(subject: serde_json::Value) -> Option<String> {
366 fn record_with_subject(subject: serde_json::Value) -> Option<String> {
354 let message: Message = serde_json::from_value(json!({
367 let message: Message = serde_json::from_value(json!({
355 "id": "1",
368 "id": "1",
crates/graph/src/lib.rs +1 −1
@@ -23,7 +23,7 @@ pub use files::{
23 23 pub use library::DriveEntry;
24 24 pub use models::{
25 25 Attachment, Body, Channel, Chat, ChatViewpoint, Identity, Member, Mention, Message, Photo,
26 Presence, Reaction, Sender, Team, User,
26 Presence, Reaction, Sender, Team, UNKNOWN_USER_NAME, User,
27 27 };
28 28 pub use outgoing::{
29 29 FileReference, HostedImage, KeptAttachment, MentionTarget, MessageExtras, OutgoingMention,
@@ -23,7 +23,7 @@ pub use files::{
23pub use library::DriveEntry;
23pub use library::DriveEntry;
24pub use models::{
24pub use models::{
25 Attachment, Body, Channel, Chat, ChatViewpoint, Identity, Member, Mention, Message, Photo,
25 Attachment, Body, Channel, Chat, ChatViewpoint, Identity, Member, Mention, Message, Photo,
26 Presence, Reaction, Sender, Team, User,
26 Presence, Reaction, Sender, Team, UNKNOWN_USER_NAME, User,
27};
27};
28pub use outgoing::{
28pub use outgoing::{
29 FileReference, HostedImage, KeptAttachment, MentionTarget, MessageExtras, OutgoingMention,
29 FileReference, HostedImage, KeptAttachment, MentionTarget, MessageExtras, OutgoingMention,
crates/graph/src/models.rs +14 −7
@@ -1,6 +1,8 @@
1 1 use chrono::{DateTime, Utc};
2 2 use serde::Deserialize;
3 3
4 pub const UNKNOWN_USER_NAME: &str = "Unknown User";
5
4 6 #[derive(Debug, Clone, Deserialize, PartialEq)]
5 7 #[serde(rename_all = "camelCase")]
6 8 pub struct User {
@@ -22,6 +24,17 @@ pub struct Member {
22 24 pub email: Option<String>,
23 25 }
24 26
27 impl Member {
28 pub fn name(&self) -> &str {
29 [&self.display_name, &self.email]
30 .into_iter()
31 .flatten()
32 .map(|name| name.trim())
33 .find(|name| !name.is_empty())
34 .unwrap_or(UNKNOWN_USER_NAME)
35 }
36 }
37
25 38 #[derive(Debug, Clone, Deserialize, PartialEq)]
26 39 #[serde(rename_all = "camelCase")]
27 40 pub struct Identity {
@@ -160,13 +173,7 @@ impl Chat {
160 173 .members
161 174 .iter()
162 175 .filter(|member| member.user_id.as_deref() != Some(my_user_id))
163 .map(|member| {
164 member
165 .display_name
166 .as_deref()
167 .or(member.email.as_deref())
168 .unwrap_or("?")
169 })
176 .map(Member::name)
170 177 .collect();
171 178 if names.is_empty() {
172 179 self.preview_sender_name(my_user_id)
@@ -1,6 +1,8 @@
1use chrono::{DateTime, Utc};
1use chrono::{DateTime, Utc};
2use serde::Deserialize;
2use serde::Deserialize;
3
3
4pub const UNKNOWN_USER_NAME: &str = "Unknown User";
5
4#[derive(Debug, Clone, Deserialize, PartialEq)]
6#[derive(Debug, Clone, Deserialize, PartialEq)]
5#[serde(rename_all = "camelCase")]
7#[serde(rename_all = "camelCase")]
6pub struct User {
8pub struct User {
@@ -22,6 +24,17 @@ pub struct Member {
22 pub email: Option<String>,
24 pub email: Option<String>,
23}
25}
24
26
27impl Member {
28 pub fn name(&self) -> &str {
29 [&self.display_name, &self.email]
30 .into_iter()
31 .flatten()
32 .map(|name| name.trim())
33 .find(|name| !name.is_empty())
34 .unwrap_or(UNKNOWN_USER_NAME)
35 }
36}
37
25#[derive(Debug, Clone, Deserialize, PartialEq)]
38#[derive(Debug, Clone, Deserialize, PartialEq)]
26#[serde(rename_all = "camelCase")]
39#[serde(rename_all = "camelCase")]
27pub struct Identity {
40pub struct Identity {
@@ -160,13 +173,7 @@ impl Chat {
160 .members
173 .members
161 .iter()
174 .iter()
162 .filter(|member| member.user_id.as_deref() != Some(my_user_id))
175 .filter(|member| member.user_id.as_deref() != Some(my_user_id))
163 .map(|member| {
176 .map(Member::name)
164 member
165 .display_name
166 .as_deref()
167 .or(member.email.as_deref())
168 .unwrap_or("?")
169 })
170 .collect();
177 .collect();
171 if names.is_empty() {
178 if names.is_empty() {
172 self.preview_sender_name(my_user_id)
179 self.preview_sender_name(my_user_id)
crates/store/src/lib.rs +1 −1
@@ -31,7 +31,7 @@ pub use models::{
31 31 ChannelNotifications, ChannelRecord, ChannelTabRecord, ChatPreview, ChatRecord,
32 32 ConversationHit, DraftRecord, FolderRecord, ImageRecord, MemberRecord, MessageRecord,
33 33 OutboxRecord, OutboxState, OutboxTarget, ReadHorizonRecord, RecentScope, SearchHit, Sidebar,
34 SidebarTeam, SyncState, TeamLayoutRecord, TeamRecord, is_bot_id,
34 SidebarTeam, SyncState, TeamLayoutRecord, TeamRecord, UNKNOWN_USER_NAME, is_bot_id,
35 35 };
36 36 pub use search::{HIGHLIGHT_END, HIGHLIGHT_START};
37 37 pub use store::{DATA_DIR_NAME, Store, default_database_path};
@@ -31,7 +31,7 @@ pub use models::{
31 ChannelNotifications, ChannelRecord, ChannelTabRecord, ChatPreview, ChatRecord,
31 ChannelNotifications, ChannelRecord, ChannelTabRecord, ChatPreview, ChatRecord,
32 ConversationHit, DraftRecord, FolderRecord, ImageRecord, MemberRecord, MessageRecord,
32 ConversationHit, DraftRecord, FolderRecord, ImageRecord, MemberRecord, MessageRecord,
33 OutboxRecord, OutboxState, OutboxTarget, ReadHorizonRecord, RecentScope, SearchHit, Sidebar,
33 OutboxRecord, OutboxState, OutboxTarget, ReadHorizonRecord, RecentScope, SearchHit, Sidebar,
34 SidebarTeam, SyncState, TeamLayoutRecord, TeamRecord, is_bot_id,
34 SidebarTeam, SyncState, TeamLayoutRecord, TeamRecord, UNKNOWN_USER_NAME, is_bot_id,
35};
35};
36pub use search::{HIGHLIGHT_END, HIGHLIGHT_START};
36pub use search::{HIGHLIGHT_END, HIGHLIGHT_START};
37pub use store::{DATA_DIR_NAME, Store, default_database_path};
37pub use store::{DATA_DIR_NAME, Store, default_database_path};
crates/store/src/messages.rs +3 −3
@@ -4,7 +4,7 @@ use chrono::{DateTime, Utc};
4 4 use rusqlite::{OptionalExtension, Row, params, params_from_iter};
5 5
6 6 use crate::error::Result;
7 use crate::models::{MessageRecord, RecentScope};
7 use crate::models::{MessageRecord, RecentScope, UNKNOWN_USER_NAME};
8 8 use crate::search::index_message;
9 9 use crate::store::Store;
10 10 use crate::time::{from_millis, optional_from_millis, optional_to_millis, to_millis};
@@ -370,14 +370,14 @@ impl Store {
370 370 let mut statement = connection.prepare_cached(
371 371 "SELECT value, COALESCE(
372 372 (SELECT display_name FROM chat_members
373 WHERE user_id = value AND display_name <> '' LIMIT 1),
373 WHERE user_id = value AND display_name NOT IN ('', ?2) LIMIT 1),
374 374 (SELECT sender_name FROM messages
375 375 WHERE sender_id = value AND sender_name <> ''
376 376 ORDER BY created_at DESC LIMIT 1))
377 377 FROM json_each(?1)",
378 378 )?;
379 379 let ids = serde_json::to_string(user_ids).unwrap_or_else(|_| "[]".to_owned());
380 let rows = statement.query_map([ids], |row| {
380 let rows = statement.query_map(params![ids, UNKNOWN_USER_NAME], |row| {
381 381 Ok((row.get::<_, String>(0)?, row.get::<_, Option<String>>(1)?))
382 382 })?;
383 383 let mut names = HashMap::new();
@@ -4,7 +4,7 @@ use chrono::{DateTime, Utc};
4use rusqlite::{OptionalExtension, Row, params, params_from_iter};
4use rusqlite::{OptionalExtension, Row, params, params_from_iter};
5
5
6use crate::error::Result;
6use crate::error::Result;
7use crate::models::{MessageRecord, RecentScope};
7use crate::models::{MessageRecord, RecentScope, UNKNOWN_USER_NAME};
8use crate::search::index_message;
8use crate::search::index_message;
9use crate::store::Store;
9use crate::store::Store;
10use crate::time::{from_millis, optional_from_millis, optional_to_millis, to_millis};
10use crate::time::{from_millis, optional_from_millis, optional_to_millis, to_millis};
@@ -370,14 +370,14 @@ impl Store {
370 let mut statement = connection.prepare_cached(
370 let mut statement = connection.prepare_cached(
371 "SELECT value, COALESCE(
371 "SELECT value, COALESCE(
372 (SELECT display_name FROM chat_members
372 (SELECT display_name FROM chat_members
373 WHERE user_id = value AND display_name <> '' LIMIT 1),
373 WHERE user_id = value AND display_name NOT IN ('', ?2) LIMIT 1),
374 (SELECT sender_name FROM messages
374 (SELECT sender_name FROM messages
375 WHERE sender_id = value AND sender_name <> ''
375 WHERE sender_id = value AND sender_name <> ''
376 ORDER BY created_at DESC LIMIT 1))
376 ORDER BY created_at DESC LIMIT 1))
377 FROM json_each(?1)",
377 FROM json_each(?1)",
378 )?;
378 )?;
379 let ids = serde_json::to_string(user_ids).unwrap_or_else(|_| "[]".to_owned());
379 let ids = serde_json::to_string(user_ids).unwrap_or_else(|_| "[]".to_owned());
380 let rows = statement.query_map([ids], |row| {
380 let rows = statement.query_map(params![ids, UNKNOWN_USER_NAME], |row| {
381 Ok((row.get::<_, String>(0)?, row.get::<_, Option<String>>(1)?))
381 Ok((row.get::<_, String>(0)?, row.get::<_, Option<String>>(1)?))
382 })?;
382 })?;
383 let mut names = HashMap::new();
383 let mut names = HashMap::new();
crates/store/src/models.rs +1 −0
@@ -3,6 +3,7 @@ use std::collections::HashMap;
3 3 use chrono::{DateTime, Utc};
4 4
5 5 pub const BOT_MRI_PREFIX: &str = "28:";
6 pub const UNKNOWN_USER_NAME: &str = "Unknown User";
6 7
7 8 pub fn is_bot_id(user_id: &str) -> bool {
8 9 user_id.starts_with(BOT_MRI_PREFIX)
@@ -3,6 +3,7 @@ use std::collections::HashMap;
3use chrono::{DateTime, Utc};
3use chrono::{DateTime, Utc};
4
4
5pub const BOT_MRI_PREFIX: &str = "28:";
5pub const BOT_MRI_PREFIX: &str = "28:";
6pub const UNKNOWN_USER_NAME: &str = "Unknown User";
6
7
7pub fn is_bot_id(user_id: &str) -> bool {
8pub fn is_bot_id(user_id: &str) -> bool {
8 user_id.starts_with(BOT_MRI_PREFIX)
9 user_id.starts_with(BOT_MRI_PREFIX)
crates/store/tests/store.rs +9 −2
@@ -4,7 +4,7 @@ use store::{
4 4 AvatarRecord, ChannelLayoutRecord, ChannelNotificationLevel, ChannelNotifications,
5 5 ChannelRecord, ChannelTabRecord, ChatPreview, ChatRecord, FolderRecord, MemberRecord,
6 6 MessageRecord, ReadHorizonRecord, RecentScope, Store, SyncState, TeamLayoutRecord,
7 TeamRecord,
7 TeamRecord, UNKNOWN_USER_NAME,
8 8 };
9 9
10 10 #[test]
@@ -1176,8 +1176,15 @@ fn activity_prune_drops_only_older_rows() {
1176 1176 #[test]
1177 1177 fn display_names_prefer_members_then_latest_sender_name() {
1178 1178 let store = Store::open_in_memory().unwrap();
1179 let unnamed_member = ChatRecord {
1180 members: vec![MemberRecord {
1181 user_id: Some("user-sam".to_owned()),
1182 display_name: UNKNOWN_USER_NAME.to_owned(),
1183 }],
1184 ..chat("chat-2", "Review", Some(at(6)))
1185 };
1179 1186 store
1180 .upsert_chats(&[chat("chat-1", "Planning", Some(at(5)))])
1187 .upsert_chats(&[chat("chat-1", "Planning", Some(at(5))), unnamed_member])
1181 1188 .unwrap();
1182 1189 let sent_by = |message_id: &str, minute: u32, sender: &str, name: Option<&str>| MessageRecord {
1183 1190 sender_id: Some(sender.to_owned()),
@@ -4,7 +4,7 @@ use store::{
4 AvatarRecord, ChannelLayoutRecord, ChannelNotificationLevel, ChannelNotifications,
4 AvatarRecord, ChannelLayoutRecord, ChannelNotificationLevel, ChannelNotifications,
5 ChannelRecord, ChannelTabRecord, ChatPreview, ChatRecord, FolderRecord, MemberRecord,
5 ChannelRecord, ChannelTabRecord, ChatPreview, ChatRecord, FolderRecord, MemberRecord,
6 MessageRecord, ReadHorizonRecord, RecentScope, Store, SyncState, TeamLayoutRecord,
6 MessageRecord, ReadHorizonRecord, RecentScope, Store, SyncState, TeamLayoutRecord,
7 TeamRecord,
7 TeamRecord, UNKNOWN_USER_NAME,
8};
8};
9
9
10#[test]
10#[test]
@@ -1176,8 +1176,15 @@ fn activity_prune_drops_only_older_rows() {
1176#[test]
1176#[test]
1177fn display_names_prefer_members_then_latest_sender_name() {
1177fn display_names_prefer_members_then_latest_sender_name() {
1178 let store = Store::open_in_memory().unwrap();
1178 let store = Store::open_in_memory().unwrap();
1179 let unnamed_member = ChatRecord {
1180 members: vec![MemberRecord {
1181 user_id: Some("user-sam".to_owned()),
1182 display_name: UNKNOWN_USER_NAME.to_owned(),
1183 }],
1184 ..chat("chat-2", "Review", Some(at(6)))
1185 };
1179 store
1186 store
1180 .upsert_chats(&[chat("chat-1", "Planning", Some(at(5)))])
1187 .upsert_chats(&[chat("chat-1", "Planning", Some(at(5))), unnamed_member])
1181 .unwrap();
1188 .unwrap();
1182 let sent_by = |message_id: &str, minute: u32, sender: &str, name: Option<&str>| MessageRecord {
1189 let sent_by = |message_id: &str, minute: u32, sender: &str, name: Option<&str>| MessageRecord {
1183 sender_id: Some(sender.to_owned()),
1190 sender_id: Some(sender.to_owned()),