diff --git a/crates/chatd/src/store.rs b/crates/chatd/src/store.rs index 7faec748..8b268d04 100644 --- a/crates/chatd/src/store.rs +++ b/crates/chatd/src/store.rs @@ -5672,7 +5672,8 @@ impl Store { // Retention. /// Keeps the newest [`KEEP_MESSAGES`] of every conversation, and nothing older than `days` - /// (P4, [`KEEP_DAYS`] by default) unless the conversation was opened in that time. Runs + /// (P4, [`KEEP_DAYS`] by default) unless the conversation was opened in that time. Signal keeps + /// everything: no request brings one of its messages back. Runs /// shortly after the boot, never inside it (the sign-in has the store busy), then daily, /// and when P4 changes. Unsent messages are the user's and are never pruned. /// Returns how many rows went. @@ -7516,6 +7517,29 @@ mod tests { assert!(store.message(&key, "1").unwrap().is_some()); } + #[test] + fn pruning_trims_a_crowded_discord_conversation_and_leaves_a_crowded_signal_one_whole() { + // 2,100 each, all newer than the age rule: only the cap can delete them. + let (mut store, discord) = store(); + let account = AccountKey { network: Network::Signal, account: "me".into() }; + let signal = Key::new(&account, "mara"); + store.upsert_conversation(&account, &ConversationRow::new("mara", ConversationKind::Direct, "Mara")).unwrap(); + let stored = KEEP_MESSAGES + 100; + for n in 0..stored { + let sent = NOW - i64::from(stored - n); + store.ingest(&discord, &said(&n.to_string(), "line", sent), false).unwrap(); + store.ingest(&signal, &said(&n.to_string(), "line", sent), false).unwrap(); + } + + // Discord serves its messages again, so its oldest 100 went. Signal's all stay: no + // request brings one of them back. + assert_eq!(store.prune(NOW, KEEP_DAYS as u32).unwrap(), 100); + for n in 0..stored { + assert_eq!(store.message(&discord, &n.to_string()).unwrap().is_some(), n >= stored - KEEP_MESSAGES, "Discord message {n}"); + assert!(store.message(&signal, &n.to_string()).unwrap().is_some(), "Signal message {n} went"); + } + } + #[test] fn what_a_send_carried_is_kept_while_it_is_unsent() { let (mut store, key) = store();