From 53944ef14af4d37c08464cb1bb9f3a8f09277194 Mon Sep 17 00:00:00 2001 From: Owen Jacobson Date: Thu, 21 Aug 2025 23:47:15 -0400 Subject: 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. --- src/conversation/snapshot.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src/conversation/snapshot.rs') 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, + #[serde( + flatten, + with = "prefix_deleted", + skip_serializing_if = "Option::is_none" + )] + pub deleted: Option, } +with_prefix!(prefix_deleted "deleted_"); + impl Conversation { fn apply(state: Option, event: Event) -> Option { match (state, event) { -- cgit v1.2.3