BlueGit

ict rusty-teams

feat(channels): unread posts get the Teams "New" badge, post header on one line

- channels store the chatsvc read horizon (migration 0026)
- posts from others after the horizon at open get an accent stripe and "New"
- post header shows name and time on one line like Teams

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

metis Daniel Däschle · pushed by metis

Authored 2026-11-05 · 3 weeks ago

Hash
eee4bcf575c04f589249390b68bf4f2494e8dec9
Parent
101d371b
14 files changed +181 −67
crates/app-state/src/app_state.rs +7 −2
@@ -842,12 +842,17 @@ impl AppState {
842 842 let Some(engine_or_demo) = self.chat_action_engine(cx) else {
843 843 return;
844 844 };
845 let previous_unread: Vec<(String, bool, Option<DateTime<Utc>>)> = self
845 let previous_unread: Vec<store::ChannelReadState> = self
846 846 .sidebar
847 847 .teams
848 848 .iter()
849 849 .flat_map(|team| team.channels.iter())
850 .map(|channel| (channel.id.clone(), channel.unread, None))
850 .map(|channel| store::ChannelReadState {
851 channel_id: channel.id.clone(),
852 unread: channel.unread,
853 last_message_at: None,
854 read_until: None,
855 })
851 856 .collect();
852 857 let previous_mentions: Vec<(String, store::ChannelMentions)> = self
853 858 .sidebar
@@ -842,12 +842,17 @@ impl AppState {
842 let Some(engine_or_demo) = self.chat_action_engine(cx) else {
842 let Some(engine_or_demo) = self.chat_action_engine(cx) else {
843 return;
843 return;
844 };
844 };
845 let previous_unread: Vec<(String, bool, Option<DateTime<Utc>>)> = self
845 let previous_unread: Vec<store::ChannelReadState> = self
846 .sidebar
846 .sidebar
847 .teams
847 .teams
848 .iter()
848 .iter()
849 .flat_map(|team| team.channels.iter())
849 .flat_map(|team| team.channels.iter())
850 .map(|channel| (channel.id.clone(), channel.unread, None))
850 .map(|channel| store::ChannelReadState {
851 channel_id: channel.id.clone(),
852 unread: channel.unread,
853 last_message_at: None,
854 read_until: None,
855 })
851 .collect();
856 .collect();
852 let previous_mentions: Vec<(String, store::ChannelMentions)> = self
857 let previous_mentions: Vec<(String, store::ChannelMentions)> = self
853 .sidebar
858 .sidebar
crates/app-state/src/demo.rs +4 −0
@@ -673,6 +673,10 @@ pub fn translations(message_ids: &[String]) -> Vec<Translation> {
673 673 .collect()
674 674 }
675 675
676 pub fn channel_read_until(channel_id: &str) -> Option<DateTime<Utc>> {
677 (channel_id == PINNED_CHANNEL).then(|| at(0, 11, 0))
678 }
679
676 680 pub fn first_unread(conversation_id: &str) -> Option<String> {
677 681 (conversation_id == UNREAD_CHAT).then(|| "u3".to_owned())
678 682 }
@@ -673,6 +673,10 @@ pub fn translations(message_ids: &[String]) -> Vec<Translation> {
673 .collect()
673 .collect()
674}
674}
675
675
676pub fn channel_read_until(channel_id: &str) -> Option<DateTime<Utc>> {
677 (channel_id == PINNED_CHANNEL).then(|| at(0, 11, 0))
678}
679
676pub fn first_unread(conversation_id: &str) -> Option<String> {
680pub fn first_unread(conversation_id: &str) -> Option<String> {
677 (conversation_id == UNREAD_CHAT).then(|| "u3".to_owned())
681 (conversation_id == UNREAD_CHAT).then(|| "u3".to_owned())
678}
682}
crates/app-state/src/rows.rs +31 −0
@@ -321,6 +321,7 @@ pub struct PostRow {
321 321 pub replies: Vec<MessageRow>,
322 322 pub hidden_reply_count: usize,
323 323 pub hidden_repliers: Vec<String>,
324 pub is_new: bool,
324 325 }
325 326
326 327 impl PostRow {
@@ -330,6 +331,7 @@ impl PostRow {
330 331 replies: Vec::new(),
331 332 hidden_reply_count: 0,
332 333 hidden_repliers: Vec::new(),
334 is_new: false,
333 335 }
334 336 }
335 337
@@ -337,6 +339,11 @@ impl PostRow {
337 339 std::iter::once(&self.root).chain(&self.replies)
338 340 }
339 341
342 /// Teams marks a post "New" when someone else posted it after the channel's read horizon.
343 pub fn mark_new_after(&mut self, read_until: DateTime<Utc>) {
344 self.is_new = !self.root.own && self.root.created_at > read_until;
345 }
346
340 347 pub fn hidden_replies_label(&self) -> Option<String> {
341 348 (self.hidden_reply_count > 0)
342 349 .then(|| replies_label(self.hidden_reply_count, &self.hidden_repliers))
@@ -1049,6 +1056,7 @@ fn post_row(
1049 1056 .iter()
1050 1057 .map(|reply| post_message_row(reply, context, timeline))
1051 1058 .collect(),
1059 is_new: false,
1052 1060 }
1053 1061 }
1054 1062
@@ -2199,6 +2207,29 @@ mod tests {
2199 2207 post
2200 2208 }
2201 2209
2210 #[test]
2211 fn posts_from_others_after_the_read_horizon_are_new() {
2212 let records = vec![
2213 record_by("old", "u", 9, 0, 7),
2214 record_by("fresh", "u", 11, 0, 7),
2215 record_by("mine", "me", 12, 0, 7),
2216 ];
2217 let read_until = Utc.with_ymd_and_hms(2026, 10, 7, 10, 0, 0).unwrap();
2218 let new: Vec<(String, bool)> = thread_list_rows(&records, &call_context(), false)
2219 .into_iter()
2220 .map(|row| {
2221 let Row::Post(mut post) = row else {
2222 panic!("not a post")
2223 };
2224 post.mark_new_after(read_until);
2225 (post.root.key.clone(), post.is_new)
2226 })
2227 .collect();
2228 assert!(new.contains(&("fresh".to_owned(), true)));
2229 assert!(new.contains(&("old".to_owned(), false)));
2230 assert!(new.contains(&("mine".to_owned(), false)));
2231 }
2232
2202 2233 #[test]
2203 2234 fn meet_now_root_is_a_post_with_the_ended_meeting_card() {
2204 2235 let records = fixture_records("channel_adhoc_meeting.json");
@@ -321,6 +321,7 @@ pub struct PostRow {
321 pub replies: Vec<MessageRow>,
321 pub replies: Vec<MessageRow>,
322 pub hidden_reply_count: usize,
322 pub hidden_reply_count: usize,
323 pub hidden_repliers: Vec<String>,
323 pub hidden_repliers: Vec<String>,
324 pub is_new: bool,
324}
325}
325
326
326impl PostRow {
327impl PostRow {
@@ -330,6 +331,7 @@ impl PostRow {
330 replies: Vec::new(),
331 replies: Vec::new(),
331 hidden_reply_count: 0,
332 hidden_reply_count: 0,
332 hidden_repliers: Vec::new(),
333 hidden_repliers: Vec::new(),
334 is_new: false,
333 }
335 }
334 }
336 }
335
337
@@ -337,6 +339,11 @@ impl PostRow {
337 std::iter::once(&self.root).chain(&self.replies)
339 std::iter::once(&self.root).chain(&self.replies)
338 }
340 }
339
341
342 /// Teams marks a post "New" when someone else posted it after the channel's read horizon.
343 pub fn mark_new_after(&mut self, read_until: DateTime<Utc>) {
344 self.is_new = !self.root.own && self.root.created_at > read_until;
345 }
346
340 pub fn hidden_replies_label(&self) -> Option<String> {
347 pub fn hidden_replies_label(&self) -> Option<String> {
341 (self.hidden_reply_count > 0)
348 (self.hidden_reply_count > 0)
342 .then(|| replies_label(self.hidden_reply_count, &self.hidden_repliers))
349 .then(|| replies_label(self.hidden_reply_count, &self.hidden_repliers))
@@ -1049,6 +1056,7 @@ fn post_row(
1049 .iter()
1056 .iter()
1050 .map(|reply| post_message_row(reply, context, timeline))
1057 .map(|reply| post_message_row(reply, context, timeline))
1051 .collect(),
1058 .collect(),
1059 is_new: false,
1052 }
1060 }
1053}
1061}
1054
1062
@@ -2199,6 +2207,29 @@ mod tests {
2199 post
2207 post
2200 }
2208 }
2201
2209
2210 #[test]
2211 fn posts_from_others_after_the_read_horizon_are_new() {
2212 let records = vec![
2213 record_by("old", "u", 9, 0, 7),
2214 record_by("fresh", "u", 11, 0, 7),
2215 record_by("mine", "me", 12, 0, 7),
2216 ];
2217 let read_until = Utc.with_ymd_and_hms(2026, 10, 7, 10, 0, 0).unwrap();
2218 let new: Vec<(String, bool)> = thread_list_rows(&records, &call_context(), false)
2219 .into_iter()
2220 .map(|row| {
2221 let Row::Post(mut post) = row else {
2222 panic!("not a post")
2223 };
2224 post.mark_new_after(read_until);
2225 (post.root.key.clone(), post.is_new)
2226 })
2227 .collect();
2228 assert!(new.contains(&("fresh".to_owned(), true)));
2229 assert!(new.contains(&("old".to_owned(), false)));
2230 assert!(new.contains(&("mine".to_owned(), false)));
2231 }
2232
2202 #[test]
2233 #[test]
2203 fn meet_now_root_is_a_post_with_the_ended_meeting_card() {
2234 fn meet_now_root_is_a_post_with_the_ended_meeting_card() {
2204 let records = fixture_records("channel_adhoc_meeting.json");
2235 let records = fixture_records("channel_adhoc_meeting.json");
crates/app/src/views/conversation.rs +22 −0
@@ -179,6 +179,7 @@ struct Current {
179 179 older_blocked: bool,
180 180 fetched: bool,
181 181 first_unread: Option<String>,
182 posts_new_after: Option<DateTime<Utc>>,
182 183 sync: SyncProgress,
183 184 detached: Option<DetachedWindow>,
184 185 window_request: Option<String>,
@@ -916,6 +917,7 @@ impl ConversationView {
916 917 Selection::Channel(_) => ViewMode::ThreadList,
917 918 };
918 919 let first_unread = self.first_unread_id(&selection, cx);
920 let posts_new_after = self.channel_read_until(&selection, cx);
919 921 self.current = Some(Current {
920 922 loaded_limit: open_limit(&selection),
921 923 selection,
@@ -927,6 +929,7 @@ impl ConversationView {
927 929 older_blocked: false,
928 930 fetched: false,
929 931 first_unread,
932 posts_new_after,
930 933 sync: SyncProgress::default(),
931 934 detached: None,
932 935 window_request: None,
@@ -1353,6 +1356,17 @@ impl ConversationView {
1353 1356 });
1354 1357 }
1355 1358
1359 fn channel_read_until(&self, selection: &Selection, cx: &App) -> Option<DateTime<Utc>> {
1360 let Selection::Channel(channel_id) = selection else {
1361 return None;
1362 };
1363 let state = self.app.read(cx);
1364 if state.mode.demo {
1365 return crate::demo::channel_read_until(channel_id);
1366 }
1367 state.engine.as_ref()?.channel_read_until(channel_id)
1368 }
1369
1356 1370 fn first_unread_id(&self, selection: &Selection, cx: &App) -> Option<String> {
1357 1371 let Selection::Chat(chat_id) = selection else {
1358 1372 return None;
@@ -1631,6 +1645,7 @@ impl ConversationView {
1631 1645 let start = self.start_info(cx);
1632 1646 let current = self.current.as_mut().expect("checked above");
1633 1647 let first_unread = current.first_unread.clone();
1648 let posts_new_after = current.posts_new_after;
1634 1649 current.loaded_limit = limit;
1635 1650 if thread_root.is_none() {
1636 1651 current.loaded_count = records.len();
@@ -1698,6 +1713,13 @@ impl ConversationView {
1698 1713 message.receipt_label = receipt_labels.get(&message.key).cloned();
1699 1714 }
1700 1715 }
1716 if let Some(read_until) = posts_new_after.filter(|_| in_feed) {
1717 for row in rows.iter_mut() {
1718 if let Row::Post(post) = row {
1719 post.mark_new_after(read_until);
1720 }
1721 }
1722 }
1701 1723 if let Some(unread_id) = &first_unread {
1702 1724 for row in rows.iter_mut() {
1703 1725 if let Row::Message(message) = row
@@ -179,6 +179,7 @@ struct Current {
179 older_blocked: bool,
179 older_blocked: bool,
180 fetched: bool,
180 fetched: bool,
181 first_unread: Option<String>,
181 first_unread: Option<String>,
182 posts_new_after: Option<DateTime<Utc>>,
182 sync: SyncProgress,
183 sync: SyncProgress,
183 detached: Option<DetachedWindow>,
184 detached: Option<DetachedWindow>,
184 window_request: Option<String>,
185 window_request: Option<String>,
@@ -916,6 +917,7 @@ impl ConversationView {
916 Selection::Channel(_) => ViewMode::ThreadList,
917 Selection::Channel(_) => ViewMode::ThreadList,
917 };
918 };
918 let first_unread = self.first_unread_id(&selection, cx);
919 let first_unread = self.first_unread_id(&selection, cx);
920 let posts_new_after = self.channel_read_until(&selection, cx);
919 self.current = Some(Current {
921 self.current = Some(Current {
920 loaded_limit: open_limit(&selection),
922 loaded_limit: open_limit(&selection),
921 selection,
923 selection,
@@ -927,6 +929,7 @@ impl ConversationView {
927 older_blocked: false,
929 older_blocked: false,
928 fetched: false,
930 fetched: false,
929 first_unread,
931 first_unread,
932 posts_new_after,
930 sync: SyncProgress::default(),
933 sync: SyncProgress::default(),
931 detached: None,
934 detached: None,
932 window_request: None,
935 window_request: None,
@@ -1353,6 +1356,17 @@ impl ConversationView {
1353 });
1356 });
1354 }
1357 }
1355
1358
1359 fn channel_read_until(&self, selection: &Selection, cx: &App) -> Option<DateTime<Utc>> {
1360 let Selection::Channel(channel_id) = selection else {
1361 return None;
1362 };
1363 let state = self.app.read(cx);
1364 if state.mode.demo {
1365 return crate::demo::channel_read_until(channel_id);
1366 }
1367 state.engine.as_ref()?.channel_read_until(channel_id)
1368 }
1369
1356 fn first_unread_id(&self, selection: &Selection, cx: &App) -> Option<String> {
1370 fn first_unread_id(&self, selection: &Selection, cx: &App) -> Option<String> {
1357 let Selection::Chat(chat_id) = selection else {
1371 let Selection::Chat(chat_id) = selection else {
1358 return None;
1372 return None;
@@ -1631,6 +1645,7 @@ impl ConversationView {
1631 let start = self.start_info(cx);
1645 let start = self.start_info(cx);
1632 let current = self.current.as_mut().expect("checked above");
1646 let current = self.current.as_mut().expect("checked above");
1633 let first_unread = current.first_unread.clone();
1647 let first_unread = current.first_unread.clone();
1648 let posts_new_after = current.posts_new_after;
1634 current.loaded_limit = limit;
1649 current.loaded_limit = limit;
1635 if thread_root.is_none() {
1650 if thread_root.is_none() {
1636 current.loaded_count = records.len();
1651 current.loaded_count = records.len();
@@ -1698,6 +1713,13 @@ impl ConversationView {
1698 message.receipt_label = receipt_labels.get(&message.key).cloned();
1713 message.receipt_label = receipt_labels.get(&message.key).cloned();
1699 }
1714 }
1700 }
1715 }
1716 if let Some(read_until) = posts_new_after.filter(|_| in_feed) {
1717 for row in rows.iter_mut() {
1718 if let Row::Post(post) = row {
1719 post.mark_new_after(read_until);
1720 }
1721 }
1722 }
1701 if let Some(unread_id) = &first_unread {
1723 if let Some(unread_id) = &first_unread {
1702 for row in rows.iter_mut() {
1724 for row in rows.iter_mut() {
1703 if let Row::Message(message) = row
1725 if let Row::Message(message) = row
crates/app/src/views/post_card.rs +36 −35
@@ -39,6 +39,9 @@ const FOOTER_AVATAR: f32 = 20.;
39 39 const FOOTER_BUTTON_PADDING: f32 = 6.;
40 40 const FOOTER_BUTTON_VERTICAL: f32 = 4.;
41 41 const REPLY_IN_THREAD: &str = "Reply in thread";
42 const NEW_STRIPE_WIDTH: f32 = 3.;
43 const NEW_BADGE_HEIGHT: f32 = 20.;
44 const NEW_LABEL: &str = "New";
42 45 pub const POST_CARD_TAG: &str = "post-card";
43 46 pub const POST_AVATAR_TAG: &str = "post-card/avatar";
44 47 pub const POST_BODY_TAG: &str = "post-card/body";
@@ -210,40 +213,6 @@ fn author_name(index: usize, author: String, profile_user: Option<&str>) -> Stat
210 213 .child(author)
211 214 }
212 215
213 fn root_header(
214 row: &MessageRow,
215 index: usize,
216 author: String,
217 profile_user: Option<&str>,
218 saved: bool,
219 pinned: bool,
220 ) -> Div {
221 v_flex()
222 .min_w_0()
223 .child(
224 h_flex()
225 .gap(px(6.))
226 .items_center()
227 .child(author_name(index, author, profile_user))
228 .when(saved, |line| {
229 line.child(icon(IconName::Bookmark, 12., theme::accent_text()))
230 })
231 .when(row.delivery == Delivery::Sending, |line| {
232 line.child(symbol("schedule", 13., theme::text_muted()))
233 }),
234 )
235 .child(
236 h_flex()
237 .gap(px(6.))
238 .items_center()
239 .text_size(px(11.))
240 .text_color(theme::text_muted())
241 .child(row.time.clone())
242 .when(row.edited, |line| line.child(edited_marker()))
243 .when(pinned, |line| line.child(pinned_marker())),
244 )
245 }
246
247 216 fn message_block(
248 217 row: &MessageRow,
249 218 index: usize,
@@ -348,7 +317,7 @@ fn message_block(
348 317 .items_center()
349 318 .gap(px(AVATAR_GAP))
350 319 .child(avatar.debug_selector(|| POST_AVATAR_TAG.into()))
351 .child(root_header(row, index, author, profile_user, saved, pinned)),
320 .child(message_header(row, index, author, profile_user, saved, pinned)),
352 321 )
353 322 .child(details.debug_selector(|| POST_BODY_TAG.into())),
354 323 Role::Reply => h_flex().items_start().gap(px(8.)).child(avatar).child(
@@ -471,6 +440,34 @@ fn reply_footer(
471 440 )
472 441 }
473 442
443 fn new_post_badge() -> Div {
444 div()
445 .absolute()
446 .top(px(CARD_PADDING + (ROOT_AVATAR - NEW_BADGE_HEIGHT) / 2.))
447 .right(px(CARD_PADDING))
448 .h(px(NEW_BADGE_HEIGHT))
449 .px(px(8.))
450 .flex()
451 .items_center()
452 .rounded_full()
453 .bg(theme::mention_background(false))
454 .text_size(px(11.))
455 .font_weight(FontWeight::SEMIBOLD)
456 .text_color(theme::accent_text())
457 .child(NEW_LABEL)
458 }
459
460 fn new_post_stripe() -> Div {
461 div()
462 .absolute()
463 .top_0()
464 .bottom_0()
465 .left_0()
466 .w(px(NEW_STRIPE_WIDTH))
467 .rounded_l(px(CARD_RADIUS))
468 .bg(theme::accent())
469 }
470
474 471 pub fn render_post(
475 472 post: &PostRow,
476 473 index: usize,
@@ -487,6 +484,7 @@ pub fn render_post(
487 484 } = actions;
488 485 let mut card = v_flex()
489 486 .debug_selector(|| POST_CARD_TAG.into())
487 .relative()
490 488 .w_full()
491 489 .rounded(px(CARD_RADIUS))
492 490 .bg(theme::row_hover())
@@ -518,6 +516,9 @@ pub fn render_post(
518 516 );
519 517 }
520 518 card = card.children(reply_footer(index, open_reply, reply_editor, directory));
519 if post.is_new {
520 card = card.child(new_post_stripe()).child(new_post_badge());
521 }
521 522 div()
522 523 .w_full()
523 524 .px(px(20.))
@@ -39,6 +39,9 @@ const FOOTER_AVATAR: f32 = 20.;
39const FOOTER_BUTTON_PADDING: f32 = 6.;
39const FOOTER_BUTTON_PADDING: f32 = 6.;
40const FOOTER_BUTTON_VERTICAL: f32 = 4.;
40const FOOTER_BUTTON_VERTICAL: f32 = 4.;
41const REPLY_IN_THREAD: &str = "Reply in thread";
41const REPLY_IN_THREAD: &str = "Reply in thread";
42const NEW_STRIPE_WIDTH: f32 = 3.;
43const NEW_BADGE_HEIGHT: f32 = 20.;
44const NEW_LABEL: &str = "New";
42pub const POST_CARD_TAG: &str = "post-card";
45pub const POST_CARD_TAG: &str = "post-card";
43pub const POST_AVATAR_TAG: &str = "post-card/avatar";
46pub const POST_AVATAR_TAG: &str = "post-card/avatar";
44pub const POST_BODY_TAG: &str = "post-card/body";
47pub const POST_BODY_TAG: &str = "post-card/body";
@@ -210,40 +213,6 @@ fn author_name(index: usize, author: String, profile_user: Option<&str>) -> Stat
210 .child(author)
213 .child(author)
211}
214}
212
215
213fn root_header(
214 row: &MessageRow,
215 index: usize,
216 author: String,
217 profile_user: Option<&str>,
218 saved: bool,
219 pinned: bool,
220) -> Div {
221 v_flex()
222 .min_w_0()
223 .child(
224 h_flex()
225 .gap(px(6.))
226 .items_center()
227 .child(author_name(index, author, profile_user))
228 .when(saved, |line| {
229 line.child(icon(IconName::Bookmark, 12., theme::accent_text()))
230 })
231 .when(row.delivery == Delivery::Sending, |line| {
232 line.child(symbol("schedule", 13., theme::text_muted()))
233 }),
234 )
235 .child(
236 h_flex()
237 .gap(px(6.))
238 .items_center()
239 .text_size(px(11.))
240 .text_color(theme::text_muted())
241 .child(row.time.clone())
242 .when(row.edited, |line| line.child(edited_marker()))
243 .when(pinned, |line| line.child(pinned_marker())),
244 )
245}
246
247fn message_block(
216fn message_block(
248 row: &MessageRow,
217 row: &MessageRow,
249 index: usize,
218 index: usize,
@@ -348,7 +317,7 @@ fn message_block(
348 .items_center()
317 .items_center()
349 .gap(px(AVATAR_GAP))
318 .gap(px(AVATAR_GAP))
350 .child(avatar.debug_selector(|| POST_AVATAR_TAG.into()))
319 .child(avatar.debug_selector(|| POST_AVATAR_TAG.into()))
351 .child(root_header(row, index, author, profile_user, saved, pinned)),
320 .child(message_header(row, index, author, profile_user, saved, pinned)),
352 )
321 )
353 .child(details.debug_selector(|| POST_BODY_TAG.into())),
322 .child(details.debug_selector(|| POST_BODY_TAG.into())),
354 Role::Reply => h_flex().items_start().gap(px(8.)).child(avatar).child(
323 Role::Reply => h_flex().items_start().gap(px(8.)).child(avatar).child(
@@ -471,6 +440,34 @@ fn reply_footer(
471 )
440 )
472}
441}
473
442
443fn new_post_badge() -> Div {
444 div()
445 .absolute()
446 .top(px(CARD_PADDING + (ROOT_AVATAR - NEW_BADGE_HEIGHT) / 2.))
447 .right(px(CARD_PADDING))
448 .h(px(NEW_BADGE_HEIGHT))
449 .px(px(8.))
450 .flex()
451 .items_center()
452 .rounded_full()
453 .bg(theme::mention_background(false))
454 .text_size(px(11.))
455 .font_weight(FontWeight::SEMIBOLD)
456 .text_color(theme::accent_text())
457 .child(NEW_LABEL)
458}
459
460fn new_post_stripe() -> Div {
461 div()
462 .absolute()
463 .top_0()
464 .bottom_0()
465 .left_0()
466 .w(px(NEW_STRIPE_WIDTH))
467 .rounded_l(px(CARD_RADIUS))
468 .bg(theme::accent())
469}
470
474pub fn render_post(
471pub fn render_post(
475 post: &PostRow,
472 post: &PostRow,
476 index: usize,
473 index: usize,
@@ -487,6 +484,7 @@ pub fn render_post(
487 } = actions;
484 } = actions;
488 let mut card = v_flex()
485 let mut card = v_flex()
489 .debug_selector(|| POST_CARD_TAG.into())
486 .debug_selector(|| POST_CARD_TAG.into())
487 .relative()
490 .w_full()
488 .w_full()
491 .rounded(px(CARD_RADIUS))
489 .rounded(px(CARD_RADIUS))
492 .bg(theme::row_hover())
490 .bg(theme::row_hover())
@@ -518,6 +516,9 @@ pub fn render_post(
518 );
516 );
519 }
517 }
520 card = card.children(reply_footer(index, open_reply, reply_editor, directory));
518 card = card.children(reply_footer(index, open_reply, reply_editor, directory));
519 if post.is_new {
520 card = card.child(new_post_stripe()).child(new_post_badge());
521 }
521 div()
522 div()
522 .w_full()
523 .w_full()
523 .px(px(20.))
524 .px(px(20.))
crates/chatsvc/src/read_horizon.rs +5 −1
@@ -35,6 +35,10 @@ impl ReadHorizon {
35 35 }
36 36 }
37 37
38 pub fn read_until_ms(&self, app_horizon_ms: i64) -> i64 {
39 self.consumed_until_ms.max(app_horizon_ms)
40 }
41
38 42 pub fn is_unread(&self, my_user_id: &str) -> bool {
39 43 self.is_unread_after(my_user_id, 0)
40 44 }
@@ -47,7 +51,7 @@ impl ReadHorizon {
47 51 if bookmark_ms != 0 && self.bookmark_message_set {
48 52 return true;
49 53 }
50 let consumed_until_ms = self.consumed_until_ms.max(app_horizon_ms);
54 let consumed_until_ms = self.read_until_ms(app_horizon_ms);
51 55 let unread = bookmark_ms != 0 || self.last_message_ms > consumed_until_ms;
52 56 let from_me = self
53 57 .last_message_from
@@ -35,6 +35,10 @@ impl ReadHorizon {
35 }
35 }
36 }
36 }
37
37
38 pub fn read_until_ms(&self, app_horizon_ms: i64) -> i64 {
39 self.consumed_until_ms.max(app_horizon_ms)
40 }
41
38 pub fn is_unread(&self, my_user_id: &str) -> bool {
42 pub fn is_unread(&self, my_user_id: &str) -> bool {
39 self.is_unread_after(my_user_id, 0)
43 self.is_unread_after(my_user_id, 0)
40 }
44 }
@@ -47,7 +51,7 @@ impl ReadHorizon {
47 if bookmark_ms != 0 && self.bookmark_message_set {
51 if bookmark_ms != 0 && self.bookmark_message_set {
48 return true;
52 return true;
49 }
53 }
50 let consumed_until_ms = self.consumed_until_ms.max(app_horizon_ms);
54 let consumed_until_ms = self.read_until_ms(app_horizon_ms);
51 let unread = bookmark_ms != 0 || self.last_message_ms > consumed_until_ms;
55 let unread = bookmark_ms != 0 || self.last_message_ms > consumed_until_ms;
52 let from_me = self
56 let from_me = self
53 .last_message_from
57 .last_message_from
crates/core/src/search.rs +5 −0
@@ -1,3 +1,4 @@
1 use chrono::{DateTime, Utc};
1 2 use store::{ConversationHit, SearchHit};
2 3
3 4 use crate::engine::{META_USER_ID, SyncEngine};
@@ -26,6 +27,10 @@ impl<R: Remote> SyncEngine<R> {
26 27 }
27 28
28 29 /// First cached message from others after the chat's last read time, `None` for a read chat. Call before `mark_read`.
30 pub fn channel_read_until(&self, channel_id: &str) -> Option<DateTime<Utc>> {
31 self.store.channel_read_until(channel_id).ok().flatten()
32 }
33
29 34 pub fn first_unread_message_id(&self, conversation_id: &str) -> Option<String> {
30 35 let chat = self
31 36 .store
@@ -1,3 +1,4 @@
1use chrono::{DateTime, Utc};
1use store::{ConversationHit, SearchHit};
2use store::{ConversationHit, SearchHit};
2
3
3use crate::engine::{META_USER_ID, SyncEngine};
4use crate::engine::{META_USER_ID, SyncEngine};
@@ -26,6 +27,10 @@ impl<R: Remote> SyncEngine<R> {
26 }
27 }
27
28
28 /// First cached message from others after the chat's last read time, `None` for a read chat. Call before `mark_read`.
29 /// First cached message from others after the chat's last read time, `None` for a read chat. Call before `mark_read`.
30 pub fn channel_read_until(&self, channel_id: &str) -> Option<DateTime<Utc>> {
31 self.store.channel_read_until(channel_id).ok().flatten()
32 }
33
29 pub fn first_unread_message_id(&self, conversation_id: &str) -> Option<String> {
34 pub fn first_unread_message_id(&self, conversation_id: &str) -> Option<String> {
30 let chat = self
35 let chat = self
31 .store
36 .store
crates/core/src/sidebar_sync.rs +8 −7
@@ -2,7 +2,7 @@ use std::collections::HashMap;
2 2
3 3 use chatsvc::{ConversationState, MentionActivity};
4 4 use chrono::{DateTime, Duration, Utc};
5 use store::{ChatRecord, Store};
5 use store::{ChannelReadState, ChatRecord, Store};
6 6
7 7 use crate::bot_partners::BotPartners;
8 8 use crate::channel_mentions::channel_mentions;
@@ -199,12 +199,13 @@ impl<R: Remote> SyncEngine<R> {
199 199 };
200 200 let read_states: Vec<_> = states
201 201 .iter()
202 .map(|state| {
203 (
204 state.id.clone(),
205 state.read.is_unread_after(my_user_id, app_horizon_ms),
206 state.read.last_message_at(),
207 )
202 .map(|state| ChannelReadState {
203 channel_id: state.id.clone(),
204 unread: state.read.is_unread_after(my_user_id, app_horizon_ms),
205 last_message_at: state.read.last_message_at(),
206 read_until: Some(state.read.read_until_ms(app_horizon_ms))
207 .filter(|read_until_ms| *read_until_ms > 0)
208 .and_then(DateTime::from_timestamp_millis),
208 209 })
209 210 .collect();
210 211 if let Err(error) = self.store.apply_channel_read_states(&read_states) {
@@ -2,7 +2,7 @@ use std::collections::HashMap;
2
2
3use chatsvc::{ConversationState, MentionActivity};
3use chatsvc::{ConversationState, MentionActivity};
4use chrono::{DateTime, Duration, Utc};
4use chrono::{DateTime, Duration, Utc};
5use store::{ChatRecord, Store};
5use store::{ChannelReadState, ChatRecord, Store};
6
6
7use crate::bot_partners::BotPartners;
7use crate::bot_partners::BotPartners;
8use crate::channel_mentions::channel_mentions;
8use crate::channel_mentions::channel_mentions;
@@ -199,12 +199,13 @@ impl<R: Remote> SyncEngine<R> {
199 };
199 };
200 let read_states: Vec<_> = states
200 let read_states: Vec<_> = states
201 .iter()
201 .iter()
202 .map(|state| {
202 .map(|state| ChannelReadState {
203 (
203 channel_id: state.id.clone(),
204 state.id.clone(),
204 unread: state.read.is_unread_after(my_user_id, app_horizon_ms),
205 state.read.is_unread_after(my_user_id, app_horizon_ms),
205 last_message_at: state.read.last_message_at(),
206 state.read.last_message_at(),
206 read_until: Some(state.read.read_until_ms(app_horizon_ms))
207 )
207 .filter(|read_until_ms| *read_until_ms > 0)
208 .and_then(DateTime::from_timestamp_millis),
208 })
209 })
209 .collect();
210 .collect();
210 if let Err(error) = self.store.apply_channel_read_states(&read_states) {
211 if let Err(error) = self.store.apply_channel_read_states(&read_states) {
crates/store/src/lib.rs +1 −1
@@ -28,7 +28,7 @@ pub use image_files::ImageFileCache;
28 28 pub use models::{
29 29 ActivityRecord, AgentProposalMention, AgentProposalRecord, AgentReactionRecord,
30 30 AttachmentImage, AvatarRecord, BOT_MRI_PREFIX, ChannelLayoutRecord, ChannelMentions,
31 ChannelNotificationLevel, ChannelNotifications, ChannelRecord, ChannelTabRecord, ChatPreview,
31 ChannelNotificationLevel, ChannelNotifications, ChannelReadState, ChannelRecord, ChannelTabRecord, ChatPreview,
32 32 ChatRecord, ConversationHit, DraftRecord, FolderRecord, ImageRecord, MemberRecord,
33 33 MessageImportance, MessageRecord, OutboxRecord, OutboxState, OutboxTarget, ReadHorizonRecord,
34 34 RecentScope, SearchHit, Sidebar, SidebarTeam, SyncState, TeamLayoutRecord, TeamRecord,
@@ -28,7 +28,7 @@ pub use image_files::ImageFileCache;
28pub use models::{
28pub use models::{
29 ActivityRecord, AgentProposalMention, AgentProposalRecord, AgentReactionRecord,
29 ActivityRecord, AgentProposalMention, AgentProposalRecord, AgentReactionRecord,
30 AttachmentImage, AvatarRecord, BOT_MRI_PREFIX, ChannelLayoutRecord, ChannelMentions,
30 AttachmentImage, AvatarRecord, BOT_MRI_PREFIX, ChannelLayoutRecord, ChannelMentions,
31 ChannelNotificationLevel, ChannelNotifications, ChannelRecord, ChannelTabRecord, ChatPreview,
31 ChannelNotificationLevel, ChannelNotifications, ChannelReadState, ChannelRecord, ChannelTabRecord, ChatPreview,
32 ChatRecord, ConversationHit, DraftRecord, FolderRecord, ImageRecord, MemberRecord,
32 ChatRecord, ConversationHit, DraftRecord, FolderRecord, ImageRecord, MemberRecord,
33 MessageImportance, MessageRecord, OutboxRecord, OutboxState, OutboxTarget, ReadHorizonRecord,
33 MessageImportance, MessageRecord, OutboxRecord, OutboxState, OutboxTarget, ReadHorizonRecord,
34 RecentScope, SearchHit, Sidebar, SidebarTeam, SyncState, TeamLayoutRecord, TeamRecord,
34 RecentScope, SearchHit, Sidebar, SidebarTeam, SyncState, TeamLayoutRecord, TeamRecord,
crates/store/src/migrations.rs +4 −0
@@ -109,6 +109,10 @@ const MIGRATIONS: &[Migration] = &[
109 109 script: include_str!("migrations/0025_float_message_ids.sql"),
110 110 after: None,
111 111 },
112 Migration {
113 script: include_str!("migrations/0026_channel_read_until.sql"),
114 after: None,
115 },
112 116 ];
113 117
114 118 pub fn latest_version() -> i64 {
@@ -109,6 +109,10 @@ const MIGRATIONS: &[Migration] = &[
109 script: include_str!("migrations/0025_float_message_ids.sql"),
109 script: include_str!("migrations/0025_float_message_ids.sql"),
110 after: None,
110 after: None,
111 },
111 },
112 Migration {
113 script: include_str!("migrations/0026_channel_read_until.sql"),
114 after: None,
115 },
112];
116];
113
117
114pub fn latest_version() -> i64 {
118pub fn latest_version() -> i64 {
crates/store/src/migrations/0026_channel_read_until.sql added +1 −0
@@ -0,0 +1 @@
1 ALTER TABLE channels ADD COLUMN read_until INTEGER;
@@ -0,0 +1 @@
1ALTER TABLE channels ADD COLUMN read_until INTEGER;
crates/store/src/models.rs +8 −0
@@ -75,6 +75,14 @@ pub struct TeamRecord {
75 75 pub name: String,
76 76 }
77 77
78 #[derive(Debug, Clone, PartialEq)]
79 pub struct ChannelReadState {
80 pub channel_id: String,
81 pub unread: bool,
82 pub last_message_at: Option<DateTime<Utc>>,
83 pub read_until: Option<DateTime<Utc>>,
84 }
85
78 86 #[derive(Debug, Clone, PartialEq)]
79 87 pub struct ChannelRecord {
80 88 pub id: String,
@@ -75,6 +75,14 @@ pub struct TeamRecord {
75 pub name: String,
75 pub name: String,
76}
76}
77
77
78#[derive(Debug, Clone, PartialEq)]
79pub struct ChannelReadState {
80 pub channel_id: String,
81 pub unread: bool,
82 pub last_message_at: Option<DateTime<Utc>>,
83 pub read_until: Option<DateTime<Utc>>,
84}
85
78#[derive(Debug, Clone, PartialEq)]
86#[derive(Debug, Clone, PartialEq)]
79pub struct ChannelRecord {
87pub struct ChannelRecord {
80 pub id: String,
88 pub id: String,
crates/store/src/teams.rs +21 −7
@@ -2,7 +2,7 @@ use chrono::{DateTime, Utc};
2 2 use rusqlite::{OptionalExtension, Row, params};
3 3
4 4 use crate::error::Result;
5 use crate::models::{ChannelRecord, TeamRecord};
5 use crate::models::{ChannelReadState, ChannelRecord, TeamRecord};
6 6 use crate::store::{Store, json_ids};
7 7 use crate::time::{optional_from_millis, optional_to_millis};
8 8
@@ -51,21 +51,23 @@ impl Store {
51 51 /// Read state comes from chatsvc only; channel metadata refreshes leave it alone.
52 52 pub fn apply_channel_read_states(
53 53 &self,
54 states: &[(String, bool, Option<DateTime<Utc>>)],
54 states: &[ChannelReadState],
55 55 ) -> Result<()> {
56 56 let mut connection = self.lock()?;
57 57 let transaction = connection.transaction()?;
58 58 {
59 59 let mut update = transaction.prepare_cached(
60 60 "UPDATE channels SET unread = ?2,
61 last_message_at = COALESCE(?3, last_message_at)
61 last_message_at = COALESCE(?3, last_message_at),
62 read_until = COALESCE(?4, read_until)
62 63 WHERE id = ?1",
63 64 )?;
64 for (channel_id, unread, last_message_at) in states {
65 for state in states {
65 66 update.execute(params![
66 channel_id,
67 unread,
68 optional_to_millis(*last_message_at)
67 state.channel_id,
68 state.unread,
69 optional_to_millis(state.last_message_at),
70 optional_to_millis(state.read_until)
69 71 ])?;
70 72 }
71 73 }
@@ -126,6 +128,18 @@ impl Store {
126 128 .optional()?)
127 129 }
128 130
131 pub fn channel_read_until(&self, channel_id: &str) -> Result<Option<DateTime<Utc>>> {
132 let connection = self.lock()?;
133 let read_until: Option<Option<i64>> = connection
134 .query_row(
135 "SELECT read_until FROM channels WHERE id = ?1",
136 [channel_id],
137 |row| row.get(0),
138 )
139 .optional()?;
140 Ok(optional_from_millis(read_until.flatten()))
141 }
142
129 143 pub fn channel(&self, channel_id: &str) -> Result<Option<ChannelRecord>> {
130 144 let connection = self.lock()?;
131 145 let mut statement = connection.prepare_cached(&format!(
@@ -2,7 +2,7 @@ use chrono::{DateTime, Utc};
2use rusqlite::{OptionalExtension, Row, params};
2use rusqlite::{OptionalExtension, Row, params};
3
3
4use crate::error::Result;
4use crate::error::Result;
5use crate::models::{ChannelRecord, TeamRecord};
5use crate::models::{ChannelReadState, ChannelRecord, TeamRecord};
6use crate::store::{Store, json_ids};
6use crate::store::{Store, json_ids};
7use crate::time::{optional_from_millis, optional_to_millis};
7use crate::time::{optional_from_millis, optional_to_millis};
8
8
@@ -51,21 +51,23 @@ impl Store {
51 /// Read state comes from chatsvc only; channel metadata refreshes leave it alone.
51 /// Read state comes from chatsvc only; channel metadata refreshes leave it alone.
52 pub fn apply_channel_read_states(
52 pub fn apply_channel_read_states(
53 &self,
53 &self,
54 states: &[(String, bool, Option<DateTime<Utc>>)],
54 states: &[ChannelReadState],
55 ) -> Result<()> {
55 ) -> Result<()> {
56 let mut connection = self.lock()?;
56 let mut connection = self.lock()?;
57 let transaction = connection.transaction()?;
57 let transaction = connection.transaction()?;
58 {
58 {
59 let mut update = transaction.prepare_cached(
59 let mut update = transaction.prepare_cached(
60 "UPDATE channels SET unread = ?2,
60 "UPDATE channels SET unread = ?2,
61 last_message_at = COALESCE(?3, last_message_at)
61 last_message_at = COALESCE(?3, last_message_at),
62 read_until = COALESCE(?4, read_until)
62 WHERE id = ?1",
63 WHERE id = ?1",
63 )?;
64 )?;
64 for (channel_id, unread, last_message_at) in states {
65 for state in states {
65 update.execute(params![
66 update.execute(params![
66 channel_id,
67 state.channel_id,
67 unread,
68 state.unread,
68 optional_to_millis(*last_message_at)
69 optional_to_millis(state.last_message_at),
70 optional_to_millis(state.read_until)
69 ])?;
71 ])?;
70 }
72 }
71 }
73 }
@@ -126,6 +128,18 @@ impl Store {
126 .optional()?)
128 .optional()?)
127 }
129 }
128
130
131 pub fn channel_read_until(&self, channel_id: &str) -> Result<Option<DateTime<Utc>>> {
132 let connection = self.lock()?;
133 let read_until: Option<Option<i64>> = connection
134 .query_row(
135 "SELECT read_until FROM channels WHERE id = ?1",
136 [channel_id],
137 |row| row.get(0),
138 )
139 .optional()?;
140 Ok(optional_from_millis(read_until.flatten()))
141 }
142
129 pub fn channel(&self, channel_id: &str) -> Result<Option<ChannelRecord>> {
143 pub fn channel(&self, channel_id: &str) -> Result<Option<ChannelRecord>> {
130 let connection = self.lock()?;
144 let connection = self.lock()?;
131 let mut statement = connection.prepare_cached(&format!(
145 let mut statement = connection.prepare_cached(&format!(
crates/store/tests/store.rs +28 −14
@@ -2,7 +2,7 @@ use chrono::{DateTime, TimeZone, Utc};
2 2 use rusqlite::Connection;
3 3 use store::{
4 4 AvatarRecord, ChannelLayoutRecord, ChannelMentions, ChannelNotificationLevel,
5 ChannelNotifications, ChannelRecord, ChannelTabRecord, ChatPreview, ChatRecord, FolderRecord,
5 ChannelNotifications, ChannelReadState, ChannelRecord, ChannelTabRecord, ChatPreview, ChatRecord, FolderRecord,
6 6 MemberRecord, MessageImportance, MessageRecord, ReadHorizonRecord, RecentScope, Store,
7 7 SyncState, TeamLayoutRecord, TeamRecord, UNKNOWN_USER_NAME,
8 8 };
@@ -529,8 +529,18 @@ fn channel_read_state_survives_a_metadata_refresh() {
529 529 .unwrap();
530 530 store
531 531 .apply_channel_read_states(&[
532 ("c1".to_owned(), true, Some(at(9))),
533 ("unknown".to_owned(), true, None),
532 ChannelReadState {
533 channel_id: "c1".to_owned(),
534 unread: true,
535 last_message_at: Some(at(9)),
536 read_until: Some(at(7)),
537 },
538 ChannelReadState {
539 channel_id: "unknown".to_owned(),
540 unread: true,
541 last_message_at: None,
542 read_until: None,
543 },
534 544 ])
535 545 .unwrap();
536 546 store
@@ -539,6 +549,8 @@ fn channel_read_state_survives_a_metadata_refresh() {
539 549 let stored = store.channel("c1").unwrap().unwrap();
540 550 assert!(stored.unread);
541 551 assert_eq!(stored.last_message_at, Some(at(9)));
552 assert_eq!(store.channel_read_until("c1").unwrap(), Some(at(7)));
553 assert_eq!(store.channel_read_until("unknown").unwrap(), None);
542 554 assert!(store.channel("unknown").unwrap().is_none());
543 555
544 556 store.mark_channel_read("c1").unwrap();
@@ -589,11 +601,11 @@ fn file_database_uses_wal_persists_and_migrates_once() {
589 601 let path = directory.path().join("nested").join("cache.sqlite3");
590 602 {
591 603 let store = Store::open(&path).unwrap();
592 assert_eq!(store.schema_version().unwrap(), 25);
604 assert_eq!(store.schema_version().unwrap(), 26);
593 605 store.upsert_messages(&[message("c", "m1", 1)]).unwrap();
594 606 }
595 607 let reopened = Store::open(&path).unwrap();
596 assert_eq!(reopened.schema_version().unwrap(), 25);
608 assert_eq!(reopened.schema_version().unwrap(), 26);
597 609 assert_eq!(reopened.message_count("c").unwrap(), 1);
598 610 drop(reopened);
599 611 let mode: String = rusqlite_open(&path)
@@ -625,7 +637,7 @@ fn old_schema_is_upgraded_in_place() {
625 637 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 channel_tabs; DROP TABLE presence; DROP TABLE activity; DROP TABLE outbox; DROP TABLE drafts; DROP TABLE attachment_images; DROP TABLE agent_reaction_proposals; DROP TABLE agent_proposals; PRAGMA user_version = 0").unwrap();
626 638 drop(connection);
627 639 let store = Store::open(&path).unwrap();
628 assert_eq!(store.schema_version().unwrap(), 25);
640 assert_eq!(store.schema_version().unwrap(), 26);
629 641 store.upsert_messages(&[message("c", "m1", 1)]).unwrap();
630 642 }
631 643
@@ -691,7 +703,7 @@ fn migration_to_v2_keeps_existing_sync_state() {
691 703 let store = Store::open(&path).unwrap();
692 704 let state = store.sync_state("c").unwrap().unwrap();
693 705 assert_eq!(state.delta_link, None);
694 assert_eq!(store.schema_version().unwrap(), 25);
706 assert_eq!(store.schema_version().unwrap(), 26);
695 707 }
696 708
697 709 #[test]
@@ -715,6 +727,7 @@ fn migration_to_v13_clears_channel_delta_links_only() {
715 727 DROP TABLE agent_reaction_proposals; DROP TABLE agent_proposals;
716 728 ALTER TABLE channel_layout DROP COLUMN notification_level;
717 729 ALTER TABLE channel_layout DROP COLUMN include_replies;
730 ALTER TABLE channels DROP COLUMN read_until;
718 731 PRAGMA user_version = 12",
719 732 )
720 733 .unwrap();
@@ -1011,6 +1024,7 @@ fn migration_indexes_rows_that_predate_search() {
1011 1024 ALTER TABLE messages DROP COLUMN importance;
1012 1025 ALTER TABLE chats DROP COLUMN muted;
1013 1026 ALTER TABLE folders DROP COLUMN expanded;
1027 ALTER TABLE channels DROP COLUMN read_until;
1014 1028 PRAGMA user_version = 3;",
1015 1029 )
1016 1030 .unwrap();
@@ -1574,12 +1588,12 @@ fn migration_to_v20_adds_the_call_event_column() {
1574 1588 Connection::open(&path)
1575 1589 .unwrap()
1576 1590 .execute_batch(
1577 "ALTER TABLE messages DROP COLUMN call_event_json; ALTER TABLE messages DROP COLUMN importance; PRAGMA user_version = 19",
1591 "ALTER TABLE channels DROP COLUMN read_until; ALTER TABLE messages DROP COLUMN call_event_json; ALTER TABLE messages DROP COLUMN importance; PRAGMA user_version = 19",
1578 1592 )
1579 1593 .unwrap();
1580 1594 }
1581 1595 let store = Store::open(&path).unwrap();
1582 assert_eq!(store.schema_version().unwrap(), 25);
1596 assert_eq!(store.schema_version().unwrap(), 26);
1583 1597 let old = store.messages("c", None, 10).unwrap();
1584 1598 assert_eq!(old[0].call_event_json, None);
1585 1599 assert!(store.sync_state("c").unwrap().is_none());
@@ -1625,11 +1639,11 @@ fn migration_to_v21_refetches_chats_and_channels_for_recordings() {
1625 1639 drop(store);
1626 1640 Connection::open(&path)
1627 1641 .unwrap()
1628 .execute_batch("ALTER TABLE messages DROP COLUMN importance; PRAGMA user_version = 20")
1642 .execute_batch("ALTER TABLE channels DROP COLUMN read_until; ALTER TABLE messages DROP COLUMN importance; PRAGMA user_version = 20")
1629 1643 .unwrap();
1630 1644 }
1631 1645 let store = Store::open(&path).unwrap();
1632 assert_eq!(store.schema_version().unwrap(), 25);
1646 assert_eq!(store.schema_version().unwrap(), 26);
1633 1647 assert!(store.sync_state("c").unwrap().is_none());
1634 1648 assert!(store.sync_state("channel").unwrap().is_none());
1635 1649 assert!(store.sync_state("other").unwrap().is_some());
@@ -1655,11 +1669,11 @@ fn migration_to_v22_adds_read_horizons_that_survive_a_reopen() {
1655 1669 drop(store);
1656 1670 Connection::open(&path)
1657 1671 .unwrap()
1658 .execute_batch("DROP TABLE read_horizons; ALTER TABLE messages DROP COLUMN importance; PRAGMA user_version = 21")
1672 .execute_batch("ALTER TABLE channels DROP COLUMN read_until; DROP TABLE read_horizons; ALTER TABLE messages DROP COLUMN importance; PRAGMA user_version = 21")
1659 1673 .unwrap();
1660 1674 }
1661 1675 let store = Store::open(&path).unwrap();
1662 assert_eq!(store.schema_version().unwrap(), 25);
1676 assert_eq!(store.schema_version().unwrap(), 26);
1663 1677 assert!(store.read_horizons("c").unwrap().is_empty());
1664 1678 let horizons = [
1665 1679 horizon("8:orgid:ada", 3, Some(4)),
@@ -1741,7 +1755,7 @@ fn migration_to_v25_drops_copies_stored_under_a_float_id() {
1741 1755 drop(store);
1742 1756 Connection::open(&path)
1743 1757 .unwrap()
1744 .pragma_update(None, "user_version", 24)
1758 .execute_batch("ALTER TABLE channels DROP COLUMN read_until; PRAGMA user_version = 24")
1745 1759 .unwrap();
1746 1760 }
1747 1761 let store = Store::open(&path).unwrap();
@@ -2,7 +2,7 @@ use chrono::{DateTime, TimeZone, Utc};
2use rusqlite::Connection;
2use rusqlite::Connection;
3use store::{
3use store::{
4 AvatarRecord, ChannelLayoutRecord, ChannelMentions, ChannelNotificationLevel,
4 AvatarRecord, ChannelLayoutRecord, ChannelMentions, ChannelNotificationLevel,
5 ChannelNotifications, ChannelRecord, ChannelTabRecord, ChatPreview, ChatRecord, FolderRecord,
5 ChannelNotifications, ChannelReadState, ChannelRecord, ChannelTabRecord, ChatPreview, ChatRecord, FolderRecord,
6 MemberRecord, MessageImportance, MessageRecord, ReadHorizonRecord, RecentScope, Store,
6 MemberRecord, MessageImportance, MessageRecord, ReadHorizonRecord, RecentScope, Store,
7 SyncState, TeamLayoutRecord, TeamRecord, UNKNOWN_USER_NAME,
7 SyncState, TeamLayoutRecord, TeamRecord, UNKNOWN_USER_NAME,
8};
8};
@@ -529,8 +529,18 @@ fn channel_read_state_survives_a_metadata_refresh() {
529 .unwrap();
529 .unwrap();
530 store
530 store
531 .apply_channel_read_states(&[
531 .apply_channel_read_states(&[
532 ("c1".to_owned(), true, Some(at(9))),
532 ChannelReadState {
533 ("unknown".to_owned(), true, None),
533 channel_id: "c1".to_owned(),
534 unread: true,
535 last_message_at: Some(at(9)),
536 read_until: Some(at(7)),
537 },
538 ChannelReadState {
539 channel_id: "unknown".to_owned(),
540 unread: true,
541 last_message_at: None,
542 read_until: None,
543 },
534 ])
544 ])
535 .unwrap();
545 .unwrap();
536 store
546 store
@@ -539,6 +549,8 @@ fn channel_read_state_survives_a_metadata_refresh() {
539 let stored = store.channel("c1").unwrap().unwrap();
549 let stored = store.channel("c1").unwrap().unwrap();
540 assert!(stored.unread);
550 assert!(stored.unread);
541 assert_eq!(stored.last_message_at, Some(at(9)));
551 assert_eq!(stored.last_message_at, Some(at(9)));
552 assert_eq!(store.channel_read_until("c1").unwrap(), Some(at(7)));
553 assert_eq!(store.channel_read_until("unknown").unwrap(), None);
542 assert!(store.channel("unknown").unwrap().is_none());
554 assert!(store.channel("unknown").unwrap().is_none());
543
555
544 store.mark_channel_read("c1").unwrap();
556 store.mark_channel_read("c1").unwrap();
@@ -589,11 +601,11 @@ fn file_database_uses_wal_persists_and_migrates_once() {
589 let path = directory.path().join("nested").join("cache.sqlite3");
601 let path = directory.path().join("nested").join("cache.sqlite3");
590 {
602 {
591 let store = Store::open(&path).unwrap();
603 let store = Store::open(&path).unwrap();
592 assert_eq!(store.schema_version().unwrap(), 25);
604 assert_eq!(store.schema_version().unwrap(), 26);
593 store.upsert_messages(&[message("c", "m1", 1)]).unwrap();
605 store.upsert_messages(&[message("c", "m1", 1)]).unwrap();
594 }
606 }
595 let reopened = Store::open(&path).unwrap();
607 let reopened = Store::open(&path).unwrap();
596 assert_eq!(reopened.schema_version().unwrap(), 25);
608 assert_eq!(reopened.schema_version().unwrap(), 26);
597 assert_eq!(reopened.message_count("c").unwrap(), 1);
609 assert_eq!(reopened.message_count("c").unwrap(), 1);
598 drop(reopened);
610 drop(reopened);
599 let mode: String = rusqlite_open(&path)
611 let mode: String = rusqlite_open(&path)
@@ -625,7 +637,7 @@ fn old_schema_is_upgraded_in_place() {
625 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 channel_tabs; DROP TABLE presence; DROP TABLE activity; DROP TABLE outbox; DROP TABLE drafts; DROP TABLE attachment_images; DROP TABLE agent_reaction_proposals; DROP TABLE agent_proposals; PRAGMA user_version = 0").unwrap();
637 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 channel_tabs; DROP TABLE presence; DROP TABLE activity; DROP TABLE outbox; DROP TABLE drafts; DROP TABLE attachment_images; DROP TABLE agent_reaction_proposals; DROP TABLE agent_proposals; PRAGMA user_version = 0").unwrap();
626 drop(connection);
638 drop(connection);
627 let store = Store::open(&path).unwrap();
639 let store = Store::open(&path).unwrap();
628 assert_eq!(store.schema_version().unwrap(), 25);
640 assert_eq!(store.schema_version().unwrap(), 26);
629 store.upsert_messages(&[message("c", "m1", 1)]).unwrap();
641 store.upsert_messages(&[message("c", "m1", 1)]).unwrap();
630}
642}
631
643
@@ -691,7 +703,7 @@ fn migration_to_v2_keeps_existing_sync_state() {
691 let store = Store::open(&path).unwrap();
703 let store = Store::open(&path).unwrap();
692 let state = store.sync_state("c").unwrap().unwrap();
704 let state = store.sync_state("c").unwrap().unwrap();
693 assert_eq!(state.delta_link, None);
705 assert_eq!(state.delta_link, None);
694 assert_eq!(store.schema_version().unwrap(), 25);
706 assert_eq!(store.schema_version().unwrap(), 26);
695}
707}
696
708
697#[test]
709#[test]
@@ -715,6 +727,7 @@ fn migration_to_v13_clears_channel_delta_links_only() {
715 DROP TABLE agent_reaction_proposals; DROP TABLE agent_proposals;
727 DROP TABLE agent_reaction_proposals; DROP TABLE agent_proposals;
716 ALTER TABLE channel_layout DROP COLUMN notification_level;
728 ALTER TABLE channel_layout DROP COLUMN notification_level;
717 ALTER TABLE channel_layout DROP COLUMN include_replies;
729 ALTER TABLE channel_layout DROP COLUMN include_replies;
730 ALTER TABLE channels DROP COLUMN read_until;
718 PRAGMA user_version = 12",
731 PRAGMA user_version = 12",
719 )
732 )
720 .unwrap();
733 .unwrap();
@@ -1011,6 +1024,7 @@ fn migration_indexes_rows_that_predate_search() {
1011 ALTER TABLE messages DROP COLUMN importance;
1024 ALTER TABLE messages DROP COLUMN importance;
1012 ALTER TABLE chats DROP COLUMN muted;
1025 ALTER TABLE chats DROP COLUMN muted;
1013 ALTER TABLE folders DROP COLUMN expanded;
1026 ALTER TABLE folders DROP COLUMN expanded;
1027 ALTER TABLE channels DROP COLUMN read_until;
1014 PRAGMA user_version = 3;",
1028 PRAGMA user_version = 3;",
1015 )
1029 )
1016 .unwrap();
1030 .unwrap();
@@ -1574,12 +1588,12 @@ fn migration_to_v20_adds_the_call_event_column() {
1574 Connection::open(&path)
1588 Connection::open(&path)
1575 .unwrap()
1589 .unwrap()
1576 .execute_batch(
1590 .execute_batch(
1577 "ALTER TABLE messages DROP COLUMN call_event_json; ALTER TABLE messages DROP COLUMN importance; PRAGMA user_version = 19",
1591 "ALTER TABLE channels DROP COLUMN read_until; ALTER TABLE messages DROP COLUMN call_event_json; ALTER TABLE messages DROP COLUMN importance; PRAGMA user_version = 19",
1578 )
1592 )
1579 .unwrap();
1593 .unwrap();
1580 }
1594 }
1581 let store = Store::open(&path).unwrap();
1595 let store = Store::open(&path).unwrap();
1582 assert_eq!(store.schema_version().unwrap(), 25);
1596 assert_eq!(store.schema_version().unwrap(), 26);
1583 let old = store.messages("c", None, 10).unwrap();
1597 let old = store.messages("c", None, 10).unwrap();
1584 assert_eq!(old[0].call_event_json, None);
1598 assert_eq!(old[0].call_event_json, None);
1585 assert!(store.sync_state("c").unwrap().is_none());
1599 assert!(store.sync_state("c").unwrap().is_none());
@@ -1625,11 +1639,11 @@ fn migration_to_v21_refetches_chats_and_channels_for_recordings() {
1625 drop(store);
1639 drop(store);
1626 Connection::open(&path)
1640 Connection::open(&path)
1627 .unwrap()
1641 .unwrap()
1628 .execute_batch("ALTER TABLE messages DROP COLUMN importance; PRAGMA user_version = 20")
1642 .execute_batch("ALTER TABLE channels DROP COLUMN read_until; ALTER TABLE messages DROP COLUMN importance; PRAGMA user_version = 20")
1629 .unwrap();
1643 .unwrap();
1630 }
1644 }
1631 let store = Store::open(&path).unwrap();
1645 let store = Store::open(&path).unwrap();
1632 assert_eq!(store.schema_version().unwrap(), 25);
1646 assert_eq!(store.schema_version().unwrap(), 26);
1633 assert!(store.sync_state("c").unwrap().is_none());
1647 assert!(store.sync_state("c").unwrap().is_none());
1634 assert!(store.sync_state("channel").unwrap().is_none());
1648 assert!(store.sync_state("channel").unwrap().is_none());
1635 assert!(store.sync_state("other").unwrap().is_some());
1649 assert!(store.sync_state("other").unwrap().is_some());
@@ -1655,11 +1669,11 @@ fn migration_to_v22_adds_read_horizons_that_survive_a_reopen() {
1655 drop(store);
1669 drop(store);
1656 Connection::open(&path)
1670 Connection::open(&path)
1657 .unwrap()
1671 .unwrap()
1658 .execute_batch("DROP TABLE read_horizons; ALTER TABLE messages DROP COLUMN importance; PRAGMA user_version = 21")
1672 .execute_batch("ALTER TABLE channels DROP COLUMN read_until; DROP TABLE read_horizons; ALTER TABLE messages DROP COLUMN importance; PRAGMA user_version = 21")
1659 .unwrap();
1673 .unwrap();
1660 }
1674 }
1661 let store = Store::open(&path).unwrap();
1675 let store = Store::open(&path).unwrap();
1662 assert_eq!(store.schema_version().unwrap(), 25);
1676 assert_eq!(store.schema_version().unwrap(), 26);
1663 assert!(store.read_horizons("c").unwrap().is_empty());
1677 assert!(store.read_horizons("c").unwrap().is_empty());
1664 let horizons = [
1678 let horizons = [
1665 horizon("8:orgid:ada", 3, Some(4)),
1679 horizon("8:orgid:ada", 3, Some(4)),
@@ -1741,7 +1755,7 @@ fn migration_to_v25_drops_copies_stored_under_a_float_id() {
1741 drop(store);
1755 drop(store);
1742 Connection::open(&path)
1756 Connection::open(&path)
1743 .unwrap()
1757 .unwrap()
1744 .pragma_update(None, "user_version", 24)
1758 .execute_batch("ALTER TABLE channels DROP COLUMN read_until; PRAGMA user_version = 24")
1745 .unwrap();
1759 .unwrap();
1746 }
1760 }
1747 let store = Store::open(&path).unwrap();
1761 let store = Store::open(&path).unwrap();