diff options
| author | Owen Jacobson <owen@grimoire.ca> | 2025-08-21 23:47:15 -0400 |
|---|---|---|
| committer | Owen Jacobson <owen@grimoire.ca> | 2025-08-24 04:50:49 -0400 |
| commit | 53944ef14af4d37c08464cb1bb9f3a8f09277194 (patch) | |
| tree | 8458167c1608222a914ce0bdcc1fb5f966cf4f95 /src/message/snapshot.rs | |
| parent | fd6a74e8ca1f5ded2a760b8ac644124862d80d54 (diff) | |
Collapse redundant "deleted_at" timestaps and "deleted" event instants.
These were separated as there wasn't an obvious way to serialize two fields with the same _type_ with different _prefixes_. Turns out this is a common problem, and someone's written a crate for it that remaps the names for you.
Diffstat (limited to 'src/message/snapshot.rs')
| -rw-r--r-- | src/message/snapshot.rs | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/message/snapshot.rs b/src/message/snapshot.rs index 12d4daa..19a98a3 100644 --- a/src/message/snapshot.rs +++ b/src/message/snapshot.rs @@ -2,7 +2,8 @@ use super::{ Body, Id, event::{Event, Sent}, }; -use crate::{clock::DateTime, conversation, event::Instant, user}; +use crate::{conversation, event::Instant, user}; +use serde_with::with_prefix; #[derive(Clone, Debug, Eq, PartialEq, serde::Serialize)] pub struct Message { @@ -12,10 +13,16 @@ pub struct Message { pub sender: user::Id, pub id: Id, pub body: Body, - #[serde(skip_serializing_if = "Option::is_none")] - pub deleted_at: Option<DateTime>, + #[serde( + flatten, + with = "prefix_deleted", + skip_serializing_if = "Option::is_none" + )] + pub deleted: Option<Instant>, } +with_prefix!(prefix_deleted "deleted_"); + impl Message { fn apply(state: Option<Self>, event: Event) -> Option<Self> { match (state, event) { |
