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/conversation/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/conversation/snapshot.rs')
| -rw-r--r-- | src/conversation/snapshot.rs | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/conversation/snapshot.rs b/src/conversation/snapshot.rs index da9eaae..440f3c0 100644 --- a/src/conversation/snapshot.rs +++ b/src/conversation/snapshot.rs @@ -1,8 +1,10 @@ +use serde_with::with_prefix; + use super::{ Id, event::{Created, Event}, }; -use crate::{clock::DateTime, event::Instant, name::Name}; +use crate::{event::Instant, name::Name}; #[derive(Clone, Debug, Eq, PartialEq, serde::Serialize)] pub struct Conversation { @@ -10,10 +12,16 @@ pub struct Conversation { pub created: Instant, pub id: Id, pub name: Name, - #[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 Conversation { fn apply(state: Option<Self>, event: Event) -> Option<Self> { match (state, event) { |
