Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion crates/chatd/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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();
Expand Down
Loading