BlueGit

ict rusty-teams

fix(messages): a quote reply no longer shows twice

- chatsvc answers OriginalArrivalTime as a float, the id was stored as 1793871826192.0 next to the server copy
- migration 0025 drops copies already stored under a float id

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
922e5c899aefb12decbe465157cceb52ae4acee4
Parent
c1c2c0c4
5 files changed +40 −15
crates/chatsvc/src/messages.rs +3 −7
@@ -244,13 +244,9 @@ impl<T: MessageTransport> Messages<T> {
244 244 .send(Request::with_body(Method::Post, &url, body))
245 245 .await?;
246 246 ensure_success(&answer)?;
247 match &answer.body["OriginalArrivalTime"] {
248 Value::Number(number) => Ok(number.to_string()),
249 Value::String(text) => Ok(text.clone()),
250 _ => Err(Error::UnexpectedAnswer(
251 "message post has no OriginalArrivalTime".into(),
252 )),
253 }
247 crate::json_id::id_text(&answer.body["OriginalArrivalTime"]).ok_or_else(|| {
248 Error::UnexpectedAnswer("message post has no OriginalArrivalTime".into())
249 })
254 250 }
255 251
256 252 pub async fn send_typing(&self, conversation: &ConversationRef, active: bool) -> Result<()> {
@@ -244,13 +244,9 @@ impl<T: MessageTransport> Messages<T> {
244 .send(Request::with_body(Method::Post, &url, body))
244 .send(Request::with_body(Method::Post, &url, body))
245 .await?;
245 .await?;
246 ensure_success(&answer)?;
246 ensure_success(&answer)?;
247 match &answer.body["OriginalArrivalTime"] {
247 crate::json_id::id_text(&answer.body["OriginalArrivalTime"]).ok_or_else(|| {
248 Value::Number(number) => Ok(number.to_string()),
248 Error::UnexpectedAnswer("message post has no OriginalArrivalTime".into())
249 Value::String(text) => Ok(text.clone()),
249 })
250 _ => Err(Error::UnexpectedAnswer(
251 "message post has no OriginalArrivalTime".into(),
252 )),
253 }
254 }
250 }
255
251
256 pub async fn send_typing(&self, conversation: &ConversationRef, active: bool) -> Result<()> {
252 pub async fn send_typing(&self, conversation: &ConversationRef, active: bool) -> Result<()> {
crates/chatsvc/tests/messages.rs +1 −1
@@ -396,7 +396,7 @@ impl chatsvc::messages::MessageTransport for &ArrivalMock {
396 396 self.requests.lock().unwrap().push(request);
397 397 Ok(ApiResponse {
398 398 status: 201,
399 body: serde_json::json!({"OriginalArrivalTime": 1727203440000_i64}),
399 body: serde_json::json!({"OriginalArrivalTime": 1727203440000.0}),
400 400 retry_after: None,
401 401 })
402 402 }
@@ -396,7 +396,7 @@ impl chatsvc::messages::MessageTransport for &ArrivalMock {
396 self.requests.lock().unwrap().push(request);
396 self.requests.lock().unwrap().push(request);
397 Ok(ApiResponse {
397 Ok(ApiResponse {
398 status: 201,
398 status: 201,
399 body: serde_json::json!({"OriginalArrivalTime": 1727203440000_i64}),
399 body: serde_json::json!({"OriginalArrivalTime": 1727203440000.0}),
400 retry_after: None,
400 retry_after: None,
401 })
401 })
402 }
402 }
crates/store/src/migrations.rs +4 −0
@@ -105,6 +105,10 @@ const MIGRATIONS: &[Migration] = &[
105 105 script: include_str!("migrations/0024_message_importance.sql"),
106 106 after: None,
107 107 },
108 Migration {
109 script: include_str!("migrations/0025_float_message_ids.sql"),
110 after: None,
111 },
108 112 ];
109 113
110 114 pub fn latest_version() -> i64 {
@@ -105,6 +105,10 @@ const MIGRATIONS: &[Migration] = &[
105 script: include_str!("migrations/0024_message_importance.sql"),
105 script: include_str!("migrations/0024_message_importance.sql"),
106 after: None,
106 after: None,
107 },
107 },
108 Migration {
109 script: include_str!("migrations/0025_float_message_ids.sql"),
110 after: None,
111 },
108];
112];
109
113
110pub fn latest_version() -> i64 {
114pub fn latest_version() -> i64 {
crates/store/src/migrations/0025_float_message_ids.sql added +3 −0
@@ -0,0 +1,3 @@
1 DELETE FROM message_search WHERE rowid IN (SELECT id FROM search_keys WHERE message_id GLOB '*[0-9].0');
2 DELETE FROM search_keys WHERE message_id GLOB '*[0-9].0';
3 DELETE FROM messages WHERE message_id GLOB '*[0-9].0';
@@ -0,0 +1,3 @@
1DELETE FROM message_search WHERE rowid IN (SELECT id FROM search_keys WHERE message_id GLOB '*[0-9].0');
2DELETE FROM search_keys WHERE message_id GLOB '*[0-9].0';
3DELETE FROM messages WHERE message_id GLOB '*[0-9].0';
crates/store/tests/store.rs +29 −7
@@ -589,11 +589,11 @@ fn file_database_uses_wal_persists_and_migrates_once() {
589 589 let path = directory.path().join("nested").join("cache.sqlite3");
590 590 {
591 591 let store = Store::open(&path).unwrap();
592 assert_eq!(store.schema_version().unwrap(), 24);
592 assert_eq!(store.schema_version().unwrap(), 25);
593 593 store.upsert_messages(&[message("c", "m1", 1)]).unwrap();
594 594 }
595 595 let reopened = Store::open(&path).unwrap();
596 assert_eq!(reopened.schema_version().unwrap(), 24);
596 assert_eq!(reopened.schema_version().unwrap(), 25);
597 597 assert_eq!(reopened.message_count("c").unwrap(), 1);
598 598 drop(reopened);
599 599 let mode: String = rusqlite_open(&path)
@@ -625,7 +625,7 @@ fn old_schema_is_upgraded_in_place() {
625 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();
626 626 drop(connection);
627 627 let store = Store::open(&path).unwrap();
628 assert_eq!(store.schema_version().unwrap(), 24);
628 assert_eq!(store.schema_version().unwrap(), 25);
629 629 store.upsert_messages(&[message("c", "m1", 1)]).unwrap();
630 630 }
631 631
@@ -691,7 +691,7 @@ fn migration_to_v2_keeps_existing_sync_state() {
691 691 let store = Store::open(&path).unwrap();
692 692 let state = store.sync_state("c").unwrap().unwrap();
693 693 assert_eq!(state.delta_link, None);
694 assert_eq!(store.schema_version().unwrap(), 24);
694 assert_eq!(store.schema_version().unwrap(), 25);
695 695 }
696 696
697 697 #[test]
@@ -1579,7 +1579,7 @@ fn migration_to_v20_adds_the_call_event_column() {
1579 1579 .unwrap();
1580 1580 }
1581 1581 let store = Store::open(&path).unwrap();
1582 assert_eq!(store.schema_version().unwrap(), 24);
1582 assert_eq!(store.schema_version().unwrap(), 25);
1583 1583 let old = store.messages("c", None, 10).unwrap();
1584 1584 assert_eq!(old[0].call_event_json, None);
1585 1585 assert!(store.sync_state("c").unwrap().is_none());
@@ -1629,7 +1629,7 @@ fn migration_to_v21_refetches_chats_and_channels_for_recordings() {
1629 1629 .unwrap();
1630 1630 }
1631 1631 let store = Store::open(&path).unwrap();
1632 assert_eq!(store.schema_version().unwrap(), 24);
1632 assert_eq!(store.schema_version().unwrap(), 25);
1633 1633 assert!(store.sync_state("c").unwrap().is_none());
1634 1634 assert!(store.sync_state("channel").unwrap().is_none());
1635 1635 assert!(store.sync_state("other").unwrap().is_some());
@@ -1659,7 +1659,7 @@ fn migration_to_v22_adds_read_horizons_that_survive_a_reopen() {
1659 1659 .unwrap();
1660 1660 }
1661 1661 let store = Store::open(&path).unwrap();
1662 assert_eq!(store.schema_version().unwrap(), 24);
1662 assert_eq!(store.schema_version().unwrap(), 25);
1663 1663 assert!(store.read_horizons("c").unwrap().is_empty());
1664 1664 let horizons = [
1665 1665 horizon("8:orgid:ada", 3, Some(4)),
@@ -1728,3 +1728,25 @@ fn local_show_hide_and_channel_pin_writes_reach_the_sidebar() {
1728 1728 .unwrap();
1729 1729 assert_eq!(store.pinned_channel_ids().unwrap(), vec!["c2", "c1"]);
1730 1730 }
1731
1732 #[test]
1733 fn migration_to_v25_drops_copies_stored_under_a_float_id() {
1734 let directory = tempfile::tempdir().unwrap();
1735 let path = directory.path().join("old.sqlite3");
1736 {
1737 let store = Store::open(&path).unwrap();
1738 store
1739 .upsert_messages(&[message("c", "1793871826192.0", 1), message("c", "1793871826192", 1)])
1740 .unwrap();
1741 drop(store);
1742 Connection::open(&path)
1743 .unwrap()
1744 .pragma_update(None, "user_version", 24)
1745 .unwrap();
1746 }
1747 let store = Store::open(&path).unwrap();
1748 let ids = ["1793871826192.0".to_owned(), "1793871826192".to_owned()];
1749 let found = store.messages_by_id("c", &ids).unwrap();
1750 assert_eq!(found.len(), 1);
1751 assert!(found.contains_key("1793871826192"));
1752 }
@@ -589,11 +589,11 @@ fn file_database_uses_wal_persists_and_migrates_once() {
589 let path = directory.path().join("nested").join("cache.sqlite3");
589 let path = directory.path().join("nested").join("cache.sqlite3");
590 {
590 {
591 let store = Store::open(&path).unwrap();
591 let store = Store::open(&path).unwrap();
592 assert_eq!(store.schema_version().unwrap(), 24);
592 assert_eq!(store.schema_version().unwrap(), 25);
593 store.upsert_messages(&[message("c", "m1", 1)]).unwrap();
593 store.upsert_messages(&[message("c", "m1", 1)]).unwrap();
594 }
594 }
595 let reopened = Store::open(&path).unwrap();
595 let reopened = Store::open(&path).unwrap();
596 assert_eq!(reopened.schema_version().unwrap(), 24);
596 assert_eq!(reopened.schema_version().unwrap(), 25);
597 assert_eq!(reopened.message_count("c").unwrap(), 1);
597 assert_eq!(reopened.message_count("c").unwrap(), 1);
598 drop(reopened);
598 drop(reopened);
599 let mode: String = rusqlite_open(&path)
599 let mode: String = rusqlite_open(&path)
@@ -625,7 +625,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();
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();
626 drop(connection);
626 drop(connection);
627 let store = Store::open(&path).unwrap();
627 let store = Store::open(&path).unwrap();
628 assert_eq!(store.schema_version().unwrap(), 24);
628 assert_eq!(store.schema_version().unwrap(), 25);
629 store.upsert_messages(&[message("c", "m1", 1)]).unwrap();
629 store.upsert_messages(&[message("c", "m1", 1)]).unwrap();
630}
630}
631
631
@@ -691,7 +691,7 @@ fn migration_to_v2_keeps_existing_sync_state() {
691 let store = Store::open(&path).unwrap();
691 let store = Store::open(&path).unwrap();
692 let state = store.sync_state("c").unwrap().unwrap();
692 let state = store.sync_state("c").unwrap().unwrap();
693 assert_eq!(state.delta_link, None);
693 assert_eq!(state.delta_link, None);
694 assert_eq!(store.schema_version().unwrap(), 24);
694 assert_eq!(store.schema_version().unwrap(), 25);
695}
695}
696
696
697#[test]
697#[test]
@@ -1579,7 +1579,7 @@ fn migration_to_v20_adds_the_call_event_column() {
1579 .unwrap();
1579 .unwrap();
1580 }
1580 }
1581 let store = Store::open(&path).unwrap();
1581 let store = Store::open(&path).unwrap();
1582 assert_eq!(store.schema_version().unwrap(), 24);
1582 assert_eq!(store.schema_version().unwrap(), 25);
1583 let old = store.messages("c", None, 10).unwrap();
1583 let old = store.messages("c", None, 10).unwrap();
1584 assert_eq!(old[0].call_event_json, None);
1584 assert_eq!(old[0].call_event_json, None);
1585 assert!(store.sync_state("c").unwrap().is_none());
1585 assert!(store.sync_state("c").unwrap().is_none());
@@ -1629,7 +1629,7 @@ fn migration_to_v21_refetches_chats_and_channels_for_recordings() {
1629 .unwrap();
1629 .unwrap();
1630 }
1630 }
1631 let store = Store::open(&path).unwrap();
1631 let store = Store::open(&path).unwrap();
1632 assert_eq!(store.schema_version().unwrap(), 24);
1632 assert_eq!(store.schema_version().unwrap(), 25);
1633 assert!(store.sync_state("c").unwrap().is_none());
1633 assert!(store.sync_state("c").unwrap().is_none());
1634 assert!(store.sync_state("channel").unwrap().is_none());
1634 assert!(store.sync_state("channel").unwrap().is_none());
1635 assert!(store.sync_state("other").unwrap().is_some());
1635 assert!(store.sync_state("other").unwrap().is_some());
@@ -1659,7 +1659,7 @@ fn migration_to_v22_adds_read_horizons_that_survive_a_reopen() {
1659 .unwrap();
1659 .unwrap();
1660 }
1660 }
1661 let store = Store::open(&path).unwrap();
1661 let store = Store::open(&path).unwrap();
1662 assert_eq!(store.schema_version().unwrap(), 24);
1662 assert_eq!(store.schema_version().unwrap(), 25);
1663 assert!(store.read_horizons("c").unwrap().is_empty());
1663 assert!(store.read_horizons("c").unwrap().is_empty());
1664 let horizons = [
1664 let horizons = [
1665 horizon("8:orgid:ada", 3, Some(4)),
1665 horizon("8:orgid:ada", 3, Some(4)),
@@ -1728,3 +1728,25 @@ fn local_show_hide_and_channel_pin_writes_reach_the_sidebar() {
1728 .unwrap();
1728 .unwrap();
1729 assert_eq!(store.pinned_channel_ids().unwrap(), vec!["c2", "c1"]);
1729 assert_eq!(store.pinned_channel_ids().unwrap(), vec!["c2", "c1"]);
1730}
1730}
1731
1732#[test]
1733fn migration_to_v25_drops_copies_stored_under_a_float_id() {
1734 let directory = tempfile::tempdir().unwrap();
1735 let path = directory.path().join("old.sqlite3");
1736 {
1737 let store = Store::open(&path).unwrap();
1738 store
1739 .upsert_messages(&[message("c", "1793871826192.0", 1), message("c", "1793871826192", 1)])
1740 .unwrap();
1741 drop(store);
1742 Connection::open(&path)
1743 .unwrap()
1744 .pragma_update(None, "user_version", 24)
1745 .unwrap();
1746 }
1747 let store = Store::open(&path).unwrap();
1748 let ids = ["1793871826192.0".to_owned(), "1793871826192".to_owned()];
1749 let found = store.messages_by_id("c", &ids).unwrap();
1750 assert_eq!(found.len(), 1);
1751 assert!(found.contains_key("1793871826192"));
1752}