From 0b9a89fc60b3d2b3ad0aa2e3348544f008d40f56 Mon Sep 17 00:00:00 2001 From: Darius Date: Sat, 30 Sep 2023 19:17:53 -0400 Subject: [PATCH] feat: Add timestamp to `Conversation` --- .../warp-ipfs/src/store/conversation.rs | 26 +++++++++++++------ extensions/warp-ipfs/src/store/message.rs | 8 ++++++ warp/src/raygun/mod.rs | 21 +++++++++++++++ 3 files changed, 47 insertions(+), 8 deletions(-) diff --git a/extensions/warp-ipfs/src/store/conversation.rs b/extensions/warp-ipfs/src/store/conversation.rs index caa0ff4cc..fcef07dce 100644 --- a/extensions/warp-ipfs/src/store/conversation.rs +++ b/extensions/warp-ipfs/src/store/conversation.rs @@ -36,6 +36,10 @@ pub struct ConversationDocument { pub name: Option, #[serde(skip_serializing_if = "Option::is_none")] pub creator: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub creation: Option>, + #[serde(skip_serializing_if = "Option::is_none")] + pub modified: Option>, pub conversation_type: ConversationType, pub recipients: Vec, pub excluded: HashMap, @@ -57,7 +61,8 @@ impl From<&Conversation> for ConversationDocument { id: conversation.id(), name: conversation.name(), creator: conversation.creator(), - + creation: Some(conversation.creation()), + modified: Some(conversation.modified()), conversation_type: conversation.conversation_type(), recipients: conversation.recipients(), excluded: Default::default(), @@ -129,6 +134,7 @@ impl ConversationDocument { } } +#[allow(clippy::too_many_arguments)] impl ConversationDocument { pub fn new( did: &DID, @@ -136,6 +142,8 @@ impl ConversationDocument { mut recipients: Vec, id: Option, conversation_type: ConversationType, + creation: Option>, + modified: Option>, creator: Option, signature: Option, ) -> Result { @@ -157,6 +165,8 @@ impl ConversationDocument { name, recipients, creator, + creation, + modified, conversation_type, excluded, messages, @@ -196,6 +206,8 @@ impl ConversationDocument { ConversationType::Direct, None, None, + None, + None, ) } @@ -207,6 +219,8 @@ impl ConversationDocument { recipients.to_vec(), conversation_id, ConversationType::Group, + None, + None, Some(did.clone()), None, ) @@ -560,13 +574,7 @@ impl ConversationDocument { impl From for Conversation { fn from(document: ConversationDocument) -> Self { - let mut conversation = Conversation::default(); - conversation.set_id(document.id); - conversation.set_name(document.name()); - conversation.set_creator(document.creator.clone()); - conversation.set_conversation_type(document.conversation_type); - conversation.set_recipients(document.recipients()); - conversation + Self::from(&document) } } @@ -577,6 +585,8 @@ impl From<&ConversationDocument> for Conversation { conversation.set_name(document.name.clone()); conversation.set_creator(document.creator.clone()); conversation.set_conversation_type(document.conversation_type); + conversation.set_creation(document.creation.unwrap_or_default()); + conversation.set_modified(document.modified.unwrap_or_default()); conversation.set_recipients(document.recipients()); conversation } diff --git a/extensions/warp-ipfs/src/store/message.rs b/extensions/warp-ipfs/src/store/message.rs index 219074f70..f2b297d75 100644 --- a/extensions/warp-ipfs/src/store/message.rs +++ b/extensions/warp-ipfs/src/store/message.rs @@ -247,6 +247,12 @@ impl MessageStore { while let Some(event) = rx.next().await { match event { ConversationEventHandle::Set(mut document, ret) => { + if document.creation.is_none() { + document.creation = Some(Utc::now()); + } + + document.modified = Some(Utc::now()); + let result = { let own_did = own_did.clone(); let ipfs = ipfs.clone(); @@ -1520,6 +1526,8 @@ impl MessageStore { list.clone(), Some(conversation_id), ConversationType::Group, + None, + None, Some(creator), signature, )?; diff --git a/warp/src/raygun/mod.rs b/warp/src/raygun/mod.rs index 5c638fdcc..0a6c74d25 100644 --- a/warp/src/raygun/mod.rs +++ b/warp/src/raygun/mod.rs @@ -403,6 +403,8 @@ pub struct Conversation { #[serde(skip_serializing_if = "Option::is_none")] name: Option, creator: Option, + creation: DateTime, + modified: DateTime, conversation_type: ConversationType, recipients: Vec, } @@ -426,10 +428,13 @@ impl Default for Conversation { let creator = None; let conversation_type = ConversationType::Direct; let recipients = Vec::new(); + let timestamp = Utc::now(); Self { id, name, creator, + creation: timestamp, + modified: timestamp, conversation_type, recipients, } @@ -449,6 +454,14 @@ impl Conversation { self.creator.clone() } + pub fn creation(&self) -> DateTime { + self.creation + } + + pub fn modified(&self) -> DateTime { + self.modified + } + pub fn conversation_type(&self) -> ConversationType { self.conversation_type } @@ -471,6 +484,14 @@ impl Conversation { self.creator = creator; } + pub fn set_creation(&mut self, creation: DateTime) { + self.creation = creation; + } + + pub fn set_modified(&mut self, modified: DateTime) { + self.modified = modified; + } + pub fn set_conversation_type(&mut self, conversation_type: ConversationType) { self.conversation_type = conversation_type; }