From 1e0493f079d011df56fe2ec93c44a0fea38f0531 Mon Sep 17 00:00:00 2001 From: Owen Jacobson Date: Tue, 26 Aug 2025 03:17:02 -0400 Subject: Store `Message` instances using their events. I found a test bug! The tests for deleting previously-deleted or previously-expired tests were using the wrong user to try to delete those messages. The tests happened to pass anyways because the message authorship check was done after the message lifecycle check. They would have no longer passed; the tests are fixed to use the sender, instead. --- src/conversation/app.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src/conversation') diff --git a/src/conversation/app.rs b/src/conversation/app.rs index 30baf77..5e07292 100644 --- a/src/conversation/app.rs +++ b/src/conversation/app.rs @@ -86,18 +86,21 @@ impl<'a> Conversations<'a> { .not_found(|| DeleteError::NotFound(conversation.clone()))?; let messages = tx.messages().live(&conversation).await?; + let deleted_at = tx.sequence().next(deleted_at).await?; + let has_messages = messages .iter() - .map(message::History::as_snapshot) + .map(|message| message.as_of(deleted_at)) .any(|message| message.is_some()); if has_messages { return Err(DeleteError::NotEmpty(conversation.id().clone())); } - let deleted = tx.sequence().next(deleted_at).await?; - let conversation = conversation.delete(deleted)?; + let conversation = conversation.delete(deleted_at)?; - let events = conversation.events().filter(Sequence::start_from(deleted)); + let events = conversation + .events() + .filter(Sequence::start_from(deleted_at)); tx.conversations().record_events(events.clone()).await?; tx.commit().await?; -- cgit v1.2.3