BlueGit

ict rusty-teams

fix(chat-list): time follows the kept line after a call

- New chats.preview_at column: time of the line the chat list shows
- A call moves the chat up but keeps the line and its time, like Teams

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

metis Daniel Däschle · pushed by metis

Authored 2026-11-08 · 3 weeks ago

Hash
5a8ed05779027f9bce04d1502ca7a0d93501f80b
Parent
465863c0
9 files changed +48 −20
crates/app-state/src/agents/message_context.rs +1 −0
@@ -154,6 +154,7 @@ mod tests {
154 154 title: "Ops".to_owned(),
155 155 member_summary: String::new(),
156 156 last_message_at: None,
157 preview_at: None,
157 158 last_read_at: None,
158 159 unread: false,
159 160 muted: false,
@@ -154,6 +154,7 @@ mod tests {
154 title: "Ops".to_owned(),
154 title: "Ops".to_owned(),
155 member_summary: String::new(),
155 member_summary: String::new(),
156 last_message_at: None,
156 last_message_at: None,
157 preview_at: None,
157 last_read_at: None,
158 last_read_at: None,
158 unread: false,
159 unread: false,
159 muted: false,
160 muted: false,
crates/app-state/src/demo.rs +1 −0
@@ -534,6 +534,7 @@ pub fn send_in_chat(
534 534 ) -> (ChatRecord, MessageRecord) {
535 535 let mut chat = chat.clone();
536 536 chat.last_message_at = Some(now);
537 chat.preview_at = Some(now);
537 538 chat.last_message_preview = Some(preview.to_owned());
538 539 chat.last_message_sender_id = Some(DEMO_USER_ID.to_owned());
539 540 chat.last_message_sender_name = Some(DEMO_USER_NAME.to_owned());
@@ -534,6 +534,7 @@ pub fn send_in_chat(
534) -> (ChatRecord, MessageRecord) {
534) -> (ChatRecord, MessageRecord) {
535 let mut chat = chat.clone();
535 let mut chat = chat.clone();
536 chat.last_message_at = Some(now);
536 chat.last_message_at = Some(now);
537 chat.preview_at = Some(now);
537 chat.last_message_preview = Some(preview.to_owned());
538 chat.last_message_preview = Some(preview.to_owned());
538 chat.last_message_sender_id = Some(DEMO_USER_ID.to_owned());
539 chat.last_message_sender_id = Some(DEMO_USER_ID.to_owned());
539 chat.last_message_sender_name = Some(DEMO_USER_NAME.to_owned());
540 chat.last_message_sender_name = Some(DEMO_USER_NAME.to_owned());
crates/app-state/src/sidebar_model.rs +2 −1
@@ -198,7 +198,8 @@ pub fn chat_item(chat: &ChatRecord, input: &SectionInput<'_>, folder_id: Option<
198 198 id: chat.id.clone(),
199 199 title: chat_title(chat),
200 200 time_label: chat
201 .last_message_at
201 .preview_at
202 .or(chat.last_message_at)
202 203 .map(|time| {
203 204 format::list_time_label(
204 205 time,
@@ -198,7 +198,8 @@ pub fn chat_item(chat: &ChatRecord, input: &SectionInput<'_>, folder_id: Option<
198 id: chat.id.clone(),
198 id: chat.id.clone(),
199 title: chat_title(chat),
199 title: chat_title(chat),
200 time_label: chat
200 time_label: chat
201 .last_message_at
201 .preview_at
202 .or(chat.last_message_at)
202 .map(|time| {
203 .map(|time| {
203 format::list_time_label(
204 format::list_time_label(
204 time,
205 time,
crates/core/src/mapping.rs +1 −0
@@ -58,6 +58,7 @@ pub fn chat_record(chat: &Chat, my_user_id: &str) -> ChatRecord {
58 58 .collect::<Vec<_>>()
59 59 .join(", "),
60 60 last_message_at,
61 preview_at: last_message_at.filter(|_| !keeps_stored_preview),
61 62 last_read_at,
62 63 unread: !last_event_system
63 64 && is_unread(chat.last_message_time(), last_read_at, last_from_me),
@@ -58,6 +58,7 @@ pub fn chat_record(chat: &Chat, my_user_id: &str) -> ChatRecord {
58 .collect::<Vec<_>>()
58 .collect::<Vec<_>>()
59 .join(", "),
59 .join(", "),
60 last_message_at,
60 last_message_at,
61 preview_at: last_message_at.filter(|_| !keeps_stored_preview),
61 last_read_at,
62 last_read_at,
62 unread: !last_event_system
63 unread: !last_event_system
63 && is_unread(chat.last_message_time(), last_read_at, last_from_me),
64 && is_unread(chat.last_message_time(), last_read_at, last_from_me),
crates/store/src/chats.rs +9 −6
@@ -9,7 +9,7 @@ use crate::store::{Store, json_ids};
9 9 use crate::time::{optional_from_millis, optional_to_millis, to_millis};
10 10
11 11 const CHAT_COLUMNS: &str = "id, kind, title, member_summary, last_message_at, last_read_at, unread, \
12 last_message_preview, last_message_sender_id, last_message_sender_name, last_message_deleted, muted";
12 last_message_preview, last_message_sender_id, last_message_sender_name, last_message_deleted, muted, preview_at";
13 13
14 14 impl Store {
15 15 pub fn upsert_chats(&self, chats: &[ChatRecord]) -> Result<()> {
@@ -18,8 +18,8 @@ impl Store {
18 18 {
19 19 let mut upsert = transaction.prepare_cached(
20 20 "INSERT INTO chats (id, kind, title, member_summary, last_message_at, last_read_at, unread,
21 last_message_preview, last_message_sender_id, last_message_sender_name, last_message_deleted)
22 VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11)
21 last_message_preview, last_message_sender_id, last_message_sender_name, last_message_deleted, preview_at)
22 VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?14)
23 23 ON CONFLICT (id) DO UPDATE SET
24 24 kind = excluded.kind,
25 25 title = CASE WHEN excluded.title IN ('(only you)', 'Unknown User') AND chats.title NOT IN ('', '?', '(only you)', 'Unknown User')
@@ -35,7 +35,8 @@ impl Store {
35 35 last_message_preview = CASE WHEN ?13 THEN chats.last_message_preview ELSE excluded.last_message_preview END,
36 36 last_message_sender_id = CASE WHEN ?13 THEN chats.last_message_sender_id ELSE excluded.last_message_sender_id END,
37 37 last_message_sender_name = CASE WHEN ?13 THEN chats.last_message_sender_name ELSE excluded.last_message_sender_name END,
38 last_message_deleted = CASE WHEN ?13 THEN chats.last_message_deleted ELSE excluded.last_message_deleted END",
38 last_message_deleted = CASE WHEN ?13 THEN chats.last_message_deleted ELSE excluded.last_message_deleted END,
39 preview_at = CASE WHEN ?13 THEN chats.preview_at ELSE excluded.preview_at END",
39 40 )?;
40 41 let mut clear_members =
41 42 transaction.prepare_cached("DELETE FROM chat_members WHERE chat_id = ?1")?;
@@ -57,6 +58,7 @@ impl Store {
57 58 chat.last_message_deleted,
58 59 chat.last_event_system,
59 60 chat.keeps_stored_preview,
61 optional_to_millis(chat.preview_at),
60 62 ])?;
61 63 clear_members.execute([&chat.id])?;
62 64 for (position, member) in chat.members.iter().enumerate() {
@@ -159,10 +161,10 @@ impl Store {
159 161 ) -> Result<bool> {
160 162 let connection = self.lock()?;
161 163 let changed = connection.execute(
162 "UPDATE chats SET last_message_at = ?2, last_message_preview = ?3, last_message_sender_id = ?4,
164 "UPDATE chats SET last_message_at = ?2, preview_at = ?2, last_message_preview = ?3, last_message_sender_id = ?4,
163 165 last_message_sender_name = ?5, last_message_deleted = ?6
164 166 WHERE id = ?1 AND (last_message_at IS NULL OR last_message_at <= ?2)
165 AND (last_message_at IS NOT ?2 OR last_message_preview IS NOT ?3 OR last_message_sender_id IS NOT ?4
167 AND (last_message_at IS NOT ?2 OR preview_at IS NOT ?2 OR last_message_preview IS NOT ?3 OR last_message_sender_id IS NOT ?4
166 168 OR last_message_sender_name IS NOT ?5 OR last_message_deleted IS NOT ?6)",
167 169 params![
168 170 chat_id,
@@ -225,6 +227,7 @@ fn chat_from_row(row: &Row<'_>) -> rusqlite::Result<ChatRecord> {
225 227 last_message_sender_name: row.get(9)?,
226 228 last_message_deleted: row.get(10)?,
227 229 muted: row.get(11)?,
230 preview_at: optional_from_millis(row.get(12)?),
228 231 last_event_system: false,
229 232 keeps_stored_preview: false,
230 233 })
@@ -9,7 +9,7 @@ use crate::store::{Store, json_ids};
9use crate::time::{optional_from_millis, optional_to_millis, to_millis};
9use crate::time::{optional_from_millis, optional_to_millis, to_millis};
10
10
11const CHAT_COLUMNS: &str = "id, kind, title, member_summary, last_message_at, last_read_at, unread, \
11const CHAT_COLUMNS: &str = "id, kind, title, member_summary, last_message_at, last_read_at, unread, \
12 last_message_preview, last_message_sender_id, last_message_sender_name, last_message_deleted, muted";
12 last_message_preview, last_message_sender_id, last_message_sender_name, last_message_deleted, muted, preview_at";
13
13
14impl Store {
14impl Store {
15 pub fn upsert_chats(&self, chats: &[ChatRecord]) -> Result<()> {
15 pub fn upsert_chats(&self, chats: &[ChatRecord]) -> Result<()> {
@@ -18,8 +18,8 @@ impl Store {
18 {
18 {
19 let mut upsert = transaction.prepare_cached(
19 let mut upsert = transaction.prepare_cached(
20 "INSERT INTO chats (id, kind, title, member_summary, last_message_at, last_read_at, unread,
20 "INSERT INTO chats (id, kind, title, member_summary, last_message_at, last_read_at, unread,
21 last_message_preview, last_message_sender_id, last_message_sender_name, last_message_deleted)
21 last_message_preview, last_message_sender_id, last_message_sender_name, last_message_deleted, preview_at)
22 VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11)
22 VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?14)
23 ON CONFLICT (id) DO UPDATE SET
23 ON CONFLICT (id) DO UPDATE SET
24 kind = excluded.kind,
24 kind = excluded.kind,
25 title = CASE WHEN excluded.title IN ('(only you)', 'Unknown User') AND chats.title NOT IN ('', '?', '(only you)', 'Unknown User')
25 title = CASE WHEN excluded.title IN ('(only you)', 'Unknown User') AND chats.title NOT IN ('', '?', '(only you)', 'Unknown User')
@@ -35,7 +35,8 @@ impl Store {
35 last_message_preview = CASE WHEN ?13 THEN chats.last_message_preview ELSE excluded.last_message_preview END,
35 last_message_preview = CASE WHEN ?13 THEN chats.last_message_preview ELSE excluded.last_message_preview END,
36 last_message_sender_id = CASE WHEN ?13 THEN chats.last_message_sender_id ELSE excluded.last_message_sender_id END,
36 last_message_sender_id = CASE WHEN ?13 THEN chats.last_message_sender_id ELSE excluded.last_message_sender_id END,
37 last_message_sender_name = CASE WHEN ?13 THEN chats.last_message_sender_name ELSE excluded.last_message_sender_name END,
37 last_message_sender_name = CASE WHEN ?13 THEN chats.last_message_sender_name ELSE excluded.last_message_sender_name END,
38 last_message_deleted = CASE WHEN ?13 THEN chats.last_message_deleted ELSE excluded.last_message_deleted END",
38 last_message_deleted = CASE WHEN ?13 THEN chats.last_message_deleted ELSE excluded.last_message_deleted END,
39 preview_at = CASE WHEN ?13 THEN chats.preview_at ELSE excluded.preview_at END",
39 )?;
40 )?;
40 let mut clear_members =
41 let mut clear_members =
41 transaction.prepare_cached("DELETE FROM chat_members WHERE chat_id = ?1")?;
42 transaction.prepare_cached("DELETE FROM chat_members WHERE chat_id = ?1")?;
@@ -57,6 +58,7 @@ impl Store {
57 chat.last_message_deleted,
58 chat.last_message_deleted,
58 chat.last_event_system,
59 chat.last_event_system,
59 chat.keeps_stored_preview,
60 chat.keeps_stored_preview,
61 optional_to_millis(chat.preview_at),
60 ])?;
62 ])?;
61 clear_members.execute([&chat.id])?;
63 clear_members.execute([&chat.id])?;
62 for (position, member) in chat.members.iter().enumerate() {
64 for (position, member) in chat.members.iter().enumerate() {
@@ -159,10 +161,10 @@ impl Store {
159 ) -> Result<bool> {
161 ) -> Result<bool> {
160 let connection = self.lock()?;
162 let connection = self.lock()?;
161 let changed = connection.execute(
163 let changed = connection.execute(
162 "UPDATE chats SET last_message_at = ?2, last_message_preview = ?3, last_message_sender_id = ?4,
164 "UPDATE chats SET last_message_at = ?2, preview_at = ?2, last_message_preview = ?3, last_message_sender_id = ?4,
163 last_message_sender_name = ?5, last_message_deleted = ?6
165 last_message_sender_name = ?5, last_message_deleted = ?6
164 WHERE id = ?1 AND (last_message_at IS NULL OR last_message_at <= ?2)
166 WHERE id = ?1 AND (last_message_at IS NULL OR last_message_at <= ?2)
165 AND (last_message_at IS NOT ?2 OR last_message_preview IS NOT ?3 OR last_message_sender_id IS NOT ?4
167 AND (last_message_at IS NOT ?2 OR preview_at IS NOT ?2 OR last_message_preview IS NOT ?3 OR last_message_sender_id IS NOT ?4
166 OR last_message_sender_name IS NOT ?5 OR last_message_deleted IS NOT ?6)",
168 OR last_message_sender_name IS NOT ?5 OR last_message_deleted IS NOT ?6)",
167 params![
169 params![
168 chat_id,
170 chat_id,
@@ -225,6 +227,7 @@ fn chat_from_row(row: &Row<'_>) -> rusqlite::Result<ChatRecord> {
225 last_message_sender_name: row.get(9)?,
227 last_message_sender_name: row.get(9)?,
226 last_message_deleted: row.get(10)?,
228 last_message_deleted: row.get(10)?,
227 muted: row.get(11)?,
229 muted: row.get(11)?,
230 preview_at: optional_from_millis(row.get(12)?),
228 last_event_system: false,
231 last_event_system: false,
229 keeps_stored_preview: false,
232 keeps_stored_preview: false,
230 })
233 })
crates/store/src/migrations.rs +4 −0
@@ -117,6 +117,10 @@ const MIGRATIONS: &[Migration] = &[
117 117 script: include_str!("migrations/0027_team_rights.sql"),
118 118 after: None,
119 119 },
120 Migration {
121 script: include_str!("migrations/0028_chat_preview_at.sql"),
122 after: None,
123 },
120 124 ];
121 125
122 126 pub fn latest_version() -> i64 {
@@ -117,6 +117,10 @@ const MIGRATIONS: &[Migration] = &[
117 script: include_str!("migrations/0027_team_rights.sql"),
117 script: include_str!("migrations/0027_team_rights.sql"),
118 after: None,
118 after: None,
119 },
119 },
120 Migration {
121 script: include_str!("migrations/0028_chat_preview_at.sql"),
122 after: None,
123 },
120];
124];
121
125
122pub fn latest_version() -> i64 {
126pub fn latest_version() -> i64 {
crates/store/src/migrations/0028_chat_preview_at.sql added +1 −0
@@ -0,0 +1 @@
1 ALTER TABLE chats ADD COLUMN preview_at INTEGER;
@@ -0,0 +1 @@
1ALTER TABLE chats ADD COLUMN preview_at INTEGER;
crates/store/src/models.rs +1 −0
@@ -28,6 +28,7 @@ pub struct ChatRecord {
28 28 pub title: String,
29 29 pub member_summary: String,
30 30 pub last_message_at: Option<DateTime<Utc>>,
31 pub preview_at: Option<DateTime<Utc>>,
31 32 pub last_read_at: Option<DateTime<Utc>>,
32 33 pub unread: bool,
33 34 pub muted: bool,
@@ -28,6 +28,7 @@ pub struct ChatRecord {
28 pub title: String,
28 pub title: String,
29 pub member_summary: String,
29 pub member_summary: String,
30 pub last_message_at: Option<DateTime<Utc>>,
30 pub last_message_at: Option<DateTime<Utc>>,
31 pub preview_at: Option<DateTime<Utc>>,
31 pub last_read_at: Option<DateTime<Utc>>,
32 pub last_read_at: Option<DateTime<Utc>>,
32 pub unread: bool,
33 pub unread: bool,
33 pub muted: bool,
34 pub muted: bool,
crates/store/tests/store.rs +28 −13
@@ -608,11 +608,11 @@ fn file_database_uses_wal_persists_and_migrates_once() {
608 608 let path = directory.path().join("nested").join("cache.sqlite3");
609 609 {
610 610 let store = Store::open(&path).unwrap();
611 assert_eq!(store.schema_version().unwrap(), 27);
611 assert_eq!(store.schema_version().unwrap(), 28);
612 612 store.upsert_messages(&[message("c", "m1", 1)]).unwrap();
613 613 }
614 614 let reopened = Store::open(&path).unwrap();
615 assert_eq!(reopened.schema_version().unwrap(), 27);
615 assert_eq!(reopened.schema_version().unwrap(), 28);
616 616 assert_eq!(reopened.message_count("c").unwrap(), 1);
617 617 drop(reopened);
618 618 let mode: String = rusqlite_open(&path)
@@ -644,7 +644,7 @@ fn old_schema_is_upgraded_in_place() {
644 644 connection.execute_batch("ALTER TABLE team_layout DROP COLUMN owner; ALTER TABLE team_layout DROP COLUMN add_channel; ALTER TABLE team_layout DROP COLUMN add_private_channel; ALTER TABLE team_layout DROP COLUMN edit_channel; ALTER TABLE team_layout DROP COLUMN delete_channel; ALTER TABLE channel_layout DROP COLUMN substrate_group_id; 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();
645 645 drop(connection);
646 646 let store = Store::open(&path).unwrap();
647 assert_eq!(store.schema_version().unwrap(), 27);
647 assert_eq!(store.schema_version().unwrap(), 28);
648 648 store.upsert_messages(&[message("c", "m1", 1)]).unwrap();
649 649 }
650 650
@@ -710,7 +710,7 @@ fn migration_to_v2_keeps_existing_sync_state() {
710 710 let store = Store::open(&path).unwrap();
711 711 let state = store.sync_state("c").unwrap().unwrap();
712 712 assert_eq!(state.delta_link, None);
713 assert_eq!(store.schema_version().unwrap(), 27);
713 assert_eq!(store.schema_version().unwrap(), 28);
714 714 }
715 715
716 716 #[test]
@@ -735,7 +735,7 @@ fn migration_to_v13_clears_channel_delta_links_only() {
735 735 ALTER TABLE channel_layout DROP COLUMN notification_level;
736 736 ALTER TABLE channel_layout DROP COLUMN include_replies;
737 737 ALTER TABLE channels DROP COLUMN read_until;
738 PRAGMA user_version = 12",
738 ALTER TABLE chats DROP COLUMN preview_at; PRAGMA user_version = 12",
739 739 )
740 740 .unwrap();
741 741 }
@@ -800,6 +800,21 @@ fn a_call_moves_the_chat_time_and_keeps_the_line() {
800 800 assert_eq!(record.last_message_preview, before);
801 801 }
802 802
803 #[test]
804 fn the_kept_line_keeps_its_own_time_after_a_call() {
805 let store = Store::open_in_memory().unwrap();
806 let mut line = chat("a", "A", Some(at(5)));
807 line.preview_at = Some(at(5));
808 store.upsert_chats(&[line]).unwrap();
809 store.touch_chat_time("a", at(7)).unwrap();
810 let mut call_sync = chat("a", "A", Some(at(9)));
811 call_sync.keeps_stored_preview = true;
812 store.upsert_chats(&[call_sync]).unwrap();
813 let record = store.chat("a").unwrap().unwrap();
814 assert_eq!(record.last_message_at, Some(at(9)));
815 assert_eq!(record.preview_at, Some(at(5)));
816 }
817
803 818 #[test]
804 819 fn avatars_round_trip_and_report_stale_ids() {
805 820 let store = Store::open_in_memory().unwrap();
@@ -1032,7 +1047,7 @@ fn migration_indexes_rows_that_predate_search() {
1032 1047 ALTER TABLE chats DROP COLUMN muted;
1033 1048 ALTER TABLE folders DROP COLUMN expanded;
1034 1049 ALTER TABLE channels DROP COLUMN read_until;
1035 PRAGMA user_version = 3;",
1050 ALTER TABLE chats DROP COLUMN preview_at; PRAGMA user_version = 3;",
1036 1051 )
1037 1052 .unwrap();
1038 1053 }
@@ -1601,12 +1616,12 @@ fn migration_to_v20_adds_the_call_event_column() {
1601 1616 Connection::open(&path)
1602 1617 .unwrap()
1603 1618 .execute_batch(
1604 "ALTER TABLE team_layout DROP COLUMN owner; ALTER TABLE team_layout DROP COLUMN add_channel; ALTER TABLE team_layout DROP COLUMN add_private_channel; ALTER TABLE team_layout DROP COLUMN edit_channel; ALTER TABLE team_layout DROP COLUMN delete_channel; ALTER TABLE channel_layout DROP COLUMN substrate_group_id; 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",
1619 "ALTER TABLE team_layout DROP COLUMN owner; ALTER TABLE team_layout DROP COLUMN add_channel; ALTER TABLE team_layout DROP COLUMN add_private_channel; ALTER TABLE team_layout DROP COLUMN edit_channel; ALTER TABLE team_layout DROP COLUMN delete_channel; ALTER TABLE channel_layout DROP COLUMN substrate_group_id; ALTER TABLE channels DROP COLUMN read_until; ALTER TABLE messages DROP COLUMN call_event_json; ALTER TABLE messages DROP COLUMN importance; ALTER TABLE chats DROP COLUMN preview_at; PRAGMA user_version = 19",
1605 1620 )
1606 1621 .unwrap();
1607 1622 }
1608 1623 let store = Store::open(&path).unwrap();
1609 assert_eq!(store.schema_version().unwrap(), 27);
1624 assert_eq!(store.schema_version().unwrap(), 28);
1610 1625 let old = store.messages("c", None, 10).unwrap();
1611 1626 assert_eq!(old[0].call_event_json, None);
1612 1627 assert!(store.sync_state("c").unwrap().is_none());
@@ -1652,11 +1667,11 @@ fn migration_to_v21_refetches_chats_and_channels_for_recordings() {
1652 1667 drop(store);
1653 1668 Connection::open(&path)
1654 1669 .unwrap()
1655 .execute_batch("ALTER TABLE team_layout DROP COLUMN owner; ALTER TABLE team_layout DROP COLUMN add_channel; ALTER TABLE team_layout DROP COLUMN add_private_channel; ALTER TABLE team_layout DROP COLUMN edit_channel; ALTER TABLE team_layout DROP COLUMN delete_channel; ALTER TABLE channel_layout DROP COLUMN substrate_group_id; ALTER TABLE channels DROP COLUMN read_until; ALTER TABLE messages DROP COLUMN importance; PRAGMA user_version = 20")
1670 .execute_batch("ALTER TABLE team_layout DROP COLUMN owner; ALTER TABLE team_layout DROP COLUMN add_channel; ALTER TABLE team_layout DROP COLUMN add_private_channel; ALTER TABLE team_layout DROP COLUMN edit_channel; ALTER TABLE team_layout DROP COLUMN delete_channel; ALTER TABLE channel_layout DROP COLUMN substrate_group_id; ALTER TABLE channels DROP COLUMN read_until; ALTER TABLE messages DROP COLUMN importance; ALTER TABLE chats DROP COLUMN preview_at; PRAGMA user_version = 20")
1656 1671 .unwrap();
1657 1672 }
1658 1673 let store = Store::open(&path).unwrap();
1659 assert_eq!(store.schema_version().unwrap(), 27);
1674 assert_eq!(store.schema_version().unwrap(), 28);
1660 1675 assert!(store.sync_state("c").unwrap().is_none());
1661 1676 assert!(store.sync_state("channel").unwrap().is_none());
1662 1677 assert!(store.sync_state("other").unwrap().is_some());
@@ -1682,11 +1697,11 @@ fn migration_to_v22_adds_read_horizons_that_survive_a_reopen() {
1682 1697 drop(store);
1683 1698 Connection::open(&path)
1684 1699 .unwrap()
1685 .execute_batch("ALTER TABLE team_layout DROP COLUMN owner; ALTER TABLE team_layout DROP COLUMN add_channel; ALTER TABLE team_layout DROP COLUMN add_private_channel; ALTER TABLE team_layout DROP COLUMN edit_channel; ALTER TABLE team_layout DROP COLUMN delete_channel; ALTER TABLE channel_layout DROP COLUMN substrate_group_id; ALTER TABLE channels DROP COLUMN read_until; DROP TABLE read_horizons; ALTER TABLE messages DROP COLUMN importance; PRAGMA user_version = 21")
1700 .execute_batch("ALTER TABLE team_layout DROP COLUMN owner; ALTER TABLE team_layout DROP COLUMN add_channel; ALTER TABLE team_layout DROP COLUMN add_private_channel; ALTER TABLE team_layout DROP COLUMN edit_channel; ALTER TABLE team_layout DROP COLUMN delete_channel; ALTER TABLE channel_layout DROP COLUMN substrate_group_id; ALTER TABLE channels DROP COLUMN read_until; DROP TABLE read_horizons; ALTER TABLE messages DROP COLUMN importance; ALTER TABLE chats DROP COLUMN preview_at; PRAGMA user_version = 21")
1686 1701 .unwrap();
1687 1702 }
1688 1703 let store = Store::open(&path).unwrap();
1689 assert_eq!(store.schema_version().unwrap(), 27);
1704 assert_eq!(store.schema_version().unwrap(), 28);
1690 1705 assert!(store.read_horizons("c").unwrap().is_empty());
1691 1706 let horizons = [
1692 1707 horizon("8:orgid:ada", 3, Some(4)),
@@ -1768,7 +1783,7 @@ fn migration_to_v25_drops_copies_stored_under_a_float_id() {
1768 1783 drop(store);
1769 1784 Connection::open(&path)
1770 1785 .unwrap()
1771 .execute_batch("ALTER TABLE team_layout DROP COLUMN owner; ALTER TABLE team_layout DROP COLUMN add_channel; ALTER TABLE team_layout DROP COLUMN add_private_channel; ALTER TABLE team_layout DROP COLUMN edit_channel; ALTER TABLE team_layout DROP COLUMN delete_channel; ALTER TABLE channel_layout DROP COLUMN substrate_group_id; ALTER TABLE channels DROP COLUMN read_until; PRAGMA user_version = 24")
1786 .execute_batch("ALTER TABLE team_layout DROP COLUMN owner; ALTER TABLE team_layout DROP COLUMN add_channel; ALTER TABLE team_layout DROP COLUMN add_private_channel; ALTER TABLE team_layout DROP COLUMN edit_channel; ALTER TABLE team_layout DROP COLUMN delete_channel; ALTER TABLE channel_layout DROP COLUMN substrate_group_id; ALTER TABLE channels DROP COLUMN read_until; ALTER TABLE chats DROP COLUMN preview_at; PRAGMA user_version = 24")
1772 1787 .unwrap();
1773 1788 }
1774 1789 let store = Store::open(&path).unwrap();
@@ -608,11 +608,11 @@ fn file_database_uses_wal_persists_and_migrates_once() {
608 let path = directory.path().join("nested").join("cache.sqlite3");
608 let path = directory.path().join("nested").join("cache.sqlite3");
609 {
609 {
610 let store = Store::open(&path).unwrap();
610 let store = Store::open(&path).unwrap();
611 assert_eq!(store.schema_version().unwrap(), 27);
611 assert_eq!(store.schema_version().unwrap(), 28);
612 store.upsert_messages(&[message("c", "m1", 1)]).unwrap();
612 store.upsert_messages(&[message("c", "m1", 1)]).unwrap();
613 }
613 }
614 let reopened = Store::open(&path).unwrap();
614 let reopened = Store::open(&path).unwrap();
615 assert_eq!(reopened.schema_version().unwrap(), 27);
615 assert_eq!(reopened.schema_version().unwrap(), 28);
616 assert_eq!(reopened.message_count("c").unwrap(), 1);
616 assert_eq!(reopened.message_count("c").unwrap(), 1);
617 drop(reopened);
617 drop(reopened);
618 let mode: String = rusqlite_open(&path)
618 let mode: String = rusqlite_open(&path)
@@ -644,7 +644,7 @@ fn old_schema_is_upgraded_in_place() {
644 connection.execute_batch("ALTER TABLE team_layout DROP COLUMN owner; ALTER TABLE team_layout DROP COLUMN add_channel; ALTER TABLE team_layout DROP COLUMN add_private_channel; ALTER TABLE team_layout DROP COLUMN edit_channel; ALTER TABLE team_layout DROP COLUMN delete_channel; ALTER TABLE channel_layout DROP COLUMN substrate_group_id; 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();
644 connection.execute_batch("ALTER TABLE team_layout DROP COLUMN owner; ALTER TABLE team_layout DROP COLUMN add_channel; ALTER TABLE team_layout DROP COLUMN add_private_channel; ALTER TABLE team_layout DROP COLUMN edit_channel; ALTER TABLE team_layout DROP COLUMN delete_channel; ALTER TABLE channel_layout DROP COLUMN substrate_group_id; 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();
645 drop(connection);
645 drop(connection);
646 let store = Store::open(&path).unwrap();
646 let store = Store::open(&path).unwrap();
647 assert_eq!(store.schema_version().unwrap(), 27);
647 assert_eq!(store.schema_version().unwrap(), 28);
648 store.upsert_messages(&[message("c", "m1", 1)]).unwrap();
648 store.upsert_messages(&[message("c", "m1", 1)]).unwrap();
649}
649}
650
650
@@ -710,7 +710,7 @@ fn migration_to_v2_keeps_existing_sync_state() {
710 let store = Store::open(&path).unwrap();
710 let store = Store::open(&path).unwrap();
711 let state = store.sync_state("c").unwrap().unwrap();
711 let state = store.sync_state("c").unwrap().unwrap();
712 assert_eq!(state.delta_link, None);
712 assert_eq!(state.delta_link, None);
713 assert_eq!(store.schema_version().unwrap(), 27);
713 assert_eq!(store.schema_version().unwrap(), 28);
714}
714}
715
715
716#[test]
716#[test]
@@ -735,7 +735,7 @@ fn migration_to_v13_clears_channel_delta_links_only() {
735 ALTER TABLE channel_layout DROP COLUMN notification_level;
735 ALTER TABLE channel_layout DROP COLUMN notification_level;
736 ALTER TABLE channel_layout DROP COLUMN include_replies;
736 ALTER TABLE channel_layout DROP COLUMN include_replies;
737 ALTER TABLE channels DROP COLUMN read_until;
737 ALTER TABLE channels DROP COLUMN read_until;
738 PRAGMA user_version = 12",
738 ALTER TABLE chats DROP COLUMN preview_at; PRAGMA user_version = 12",
739 )
739 )
740 .unwrap();
740 .unwrap();
741 }
741 }
@@ -800,6 +800,21 @@ fn a_call_moves_the_chat_time_and_keeps_the_line() {
800 assert_eq!(record.last_message_preview, before);
800 assert_eq!(record.last_message_preview, before);
801}
801}
802
802
803#[test]
804fn the_kept_line_keeps_its_own_time_after_a_call() {
805 let store = Store::open_in_memory().unwrap();
806 let mut line = chat("a", "A", Some(at(5)));
807 line.preview_at = Some(at(5));
808 store.upsert_chats(&[line]).unwrap();
809 store.touch_chat_time("a", at(7)).unwrap();
810 let mut call_sync = chat("a", "A", Some(at(9)));
811 call_sync.keeps_stored_preview = true;
812 store.upsert_chats(&[call_sync]).unwrap();
813 let record = store.chat("a").unwrap().unwrap();
814 assert_eq!(record.last_message_at, Some(at(9)));
815 assert_eq!(record.preview_at, Some(at(5)));
816}
817
803#[test]
818#[test]
804fn avatars_round_trip_and_report_stale_ids() {
819fn avatars_round_trip_and_report_stale_ids() {
805 let store = Store::open_in_memory().unwrap();
820 let store = Store::open_in_memory().unwrap();
@@ -1032,7 +1047,7 @@ fn migration_indexes_rows_that_predate_search() {
1032 ALTER TABLE chats DROP COLUMN muted;
1047 ALTER TABLE chats DROP COLUMN muted;
1033 ALTER TABLE folders DROP COLUMN expanded;
1048 ALTER TABLE folders DROP COLUMN expanded;
1034 ALTER TABLE channels DROP COLUMN read_until;
1049 ALTER TABLE channels DROP COLUMN read_until;
1035 PRAGMA user_version = 3;",
1050 ALTER TABLE chats DROP COLUMN preview_at; PRAGMA user_version = 3;",
1036 )
1051 )
1037 .unwrap();
1052 .unwrap();
1038 }
1053 }
@@ -1601,12 +1616,12 @@ fn migration_to_v20_adds_the_call_event_column() {
1601 Connection::open(&path)
1616 Connection::open(&path)
1602 .unwrap()
1617 .unwrap()
1603 .execute_batch(
1618 .execute_batch(
1604 "ALTER TABLE team_layout DROP COLUMN owner; ALTER TABLE team_layout DROP COLUMN add_channel; ALTER TABLE team_layout DROP COLUMN add_private_channel; ALTER TABLE team_layout DROP COLUMN edit_channel; ALTER TABLE team_layout DROP COLUMN delete_channel; ALTER TABLE channel_layout DROP COLUMN substrate_group_id; 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",
1619 "ALTER TABLE team_layout DROP COLUMN owner; ALTER TABLE team_layout DROP COLUMN add_channel; ALTER TABLE team_layout DROP COLUMN add_private_channel; ALTER TABLE team_layout DROP COLUMN edit_channel; ALTER TABLE team_layout DROP COLUMN delete_channel; ALTER TABLE channel_layout DROP COLUMN substrate_group_id; ALTER TABLE channels DROP COLUMN read_until; ALTER TABLE messages DROP COLUMN call_event_json; ALTER TABLE messages DROP COLUMN importance; ALTER TABLE chats DROP COLUMN preview_at; PRAGMA user_version = 19",
1605 )
1620 )
1606 .unwrap();
1621 .unwrap();
1607 }
1622 }
1608 let store = Store::open(&path).unwrap();
1623 let store = Store::open(&path).unwrap();
1609 assert_eq!(store.schema_version().unwrap(), 27);
1624 assert_eq!(store.schema_version().unwrap(), 28);
1610 let old = store.messages("c", None, 10).unwrap();
1625 let old = store.messages("c", None, 10).unwrap();
1611 assert_eq!(old[0].call_event_json, None);
1626 assert_eq!(old[0].call_event_json, None);
1612 assert!(store.sync_state("c").unwrap().is_none());
1627 assert!(store.sync_state("c").unwrap().is_none());
@@ -1652,11 +1667,11 @@ fn migration_to_v21_refetches_chats_and_channels_for_recordings() {
1652 drop(store);
1667 drop(store);
1653 Connection::open(&path)
1668 Connection::open(&path)
1654 .unwrap()
1669 .unwrap()
1655 .execute_batch("ALTER TABLE team_layout DROP COLUMN owner; ALTER TABLE team_layout DROP COLUMN add_channel; ALTER TABLE team_layout DROP COLUMN add_private_channel; ALTER TABLE team_layout DROP COLUMN edit_channel; ALTER TABLE team_layout DROP COLUMN delete_channel; ALTER TABLE channel_layout DROP COLUMN substrate_group_id; ALTER TABLE channels DROP COLUMN read_until; ALTER TABLE messages DROP COLUMN importance; PRAGMA user_version = 20")
1670 .execute_batch("ALTER TABLE team_layout DROP COLUMN owner; ALTER TABLE team_layout DROP COLUMN add_channel; ALTER TABLE team_layout DROP COLUMN add_private_channel; ALTER TABLE team_layout DROP COLUMN edit_channel; ALTER TABLE team_layout DROP COLUMN delete_channel; ALTER TABLE channel_layout DROP COLUMN substrate_group_id; ALTER TABLE channels DROP COLUMN read_until; ALTER TABLE messages DROP COLUMN importance; ALTER TABLE chats DROP COLUMN preview_at; PRAGMA user_version = 20")
1656 .unwrap();
1671 .unwrap();
1657 }
1672 }
1658 let store = Store::open(&path).unwrap();
1673 let store = Store::open(&path).unwrap();
1659 assert_eq!(store.schema_version().unwrap(), 27);
1674 assert_eq!(store.schema_version().unwrap(), 28);
1660 assert!(store.sync_state("c").unwrap().is_none());
1675 assert!(store.sync_state("c").unwrap().is_none());
1661 assert!(store.sync_state("channel").unwrap().is_none());
1676 assert!(store.sync_state("channel").unwrap().is_none());
1662 assert!(store.sync_state("other").unwrap().is_some());
1677 assert!(store.sync_state("other").unwrap().is_some());
@@ -1682,11 +1697,11 @@ fn migration_to_v22_adds_read_horizons_that_survive_a_reopen() {
1682 drop(store);
1697 drop(store);
1683 Connection::open(&path)
1698 Connection::open(&path)
1684 .unwrap()
1699 .unwrap()
1685 .execute_batch("ALTER TABLE team_layout DROP COLUMN owner; ALTER TABLE team_layout DROP COLUMN add_channel; ALTER TABLE team_layout DROP COLUMN add_private_channel; ALTER TABLE team_layout DROP COLUMN edit_channel; ALTER TABLE team_layout DROP COLUMN delete_channel; ALTER TABLE channel_layout DROP COLUMN substrate_group_id; ALTER TABLE channels DROP COLUMN read_until; DROP TABLE read_horizons; ALTER TABLE messages DROP COLUMN importance; PRAGMA user_version = 21")
1700 .execute_batch("ALTER TABLE team_layout DROP COLUMN owner; ALTER TABLE team_layout DROP COLUMN add_channel; ALTER TABLE team_layout DROP COLUMN add_private_channel; ALTER TABLE team_layout DROP COLUMN edit_channel; ALTER TABLE team_layout DROP COLUMN delete_channel; ALTER TABLE channel_layout DROP COLUMN substrate_group_id; ALTER TABLE channels DROP COLUMN read_until; DROP TABLE read_horizons; ALTER TABLE messages DROP COLUMN importance; ALTER TABLE chats DROP COLUMN preview_at; PRAGMA user_version = 21")
1686 .unwrap();
1701 .unwrap();
1687 }
1702 }
1688 let store = Store::open(&path).unwrap();
1703 let store = Store::open(&path).unwrap();
1689 assert_eq!(store.schema_version().unwrap(), 27);
1704 assert_eq!(store.schema_version().unwrap(), 28);
1690 assert!(store.read_horizons("c").unwrap().is_empty());
1705 assert!(store.read_horizons("c").unwrap().is_empty());
1691 let horizons = [
1706 let horizons = [
1692 horizon("8:orgid:ada", 3, Some(4)),
1707 horizon("8:orgid:ada", 3, Some(4)),
@@ -1768,7 +1783,7 @@ fn migration_to_v25_drops_copies_stored_under_a_float_id() {
1768 drop(store);
1783 drop(store);
1769 Connection::open(&path)
1784 Connection::open(&path)
1770 .unwrap()
1785 .unwrap()
1771 .execute_batch("ALTER TABLE team_layout DROP COLUMN owner; ALTER TABLE team_layout DROP COLUMN add_channel; ALTER TABLE team_layout DROP COLUMN add_private_channel; ALTER TABLE team_layout DROP COLUMN edit_channel; ALTER TABLE team_layout DROP COLUMN delete_channel; ALTER TABLE channel_layout DROP COLUMN substrate_group_id; ALTER TABLE channels DROP COLUMN read_until; PRAGMA user_version = 24")
1786 .execute_batch("ALTER TABLE team_layout DROP COLUMN owner; ALTER TABLE team_layout DROP COLUMN add_channel; ALTER TABLE team_layout DROP COLUMN add_private_channel; ALTER TABLE team_layout DROP COLUMN edit_channel; ALTER TABLE team_layout DROP COLUMN delete_channel; ALTER TABLE channel_layout DROP COLUMN substrate_group_id; ALTER TABLE channels DROP COLUMN read_until; ALTER TABLE chats DROP COLUMN preview_at; PRAGMA user_version = 24")
1772 .unwrap();
1787 .unwrap();
1773 }
1788 }
1774 let store = Store::open(&path).unwrap();
1789 let store = Store::open(&path).unwrap();