Skip to content

Commit

Permalink
feat: Add timestamp to Conversation
Browse files Browse the repository at this point in the history
  • Loading branch information
dariusc93 committed Sep 30, 2023
1 parent 50ac9e0 commit 0b9a89f
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 8 deletions.
26 changes: 18 additions & 8 deletions extensions/warp-ipfs/src/store/conversation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ pub struct ConversationDocument {
pub name: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub creator: Option<DID>,
#[serde(skip_serializing_if = "Option::is_none")]
pub creation: Option<DateTime<Utc>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub modified: Option<DateTime<Utc>>,
pub conversation_type: ConversationType,
pub recipients: Vec<DID>,
pub excluded: HashMap<DID, String>,
Expand All @@ -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(),
Expand Down Expand Up @@ -129,13 +134,16 @@ impl ConversationDocument {
}
}

#[allow(clippy::too_many_arguments)]
impl ConversationDocument {
pub fn new(
did: &DID,
name: Option<String>,
mut recipients: Vec<DID>,
id: Option<Uuid>,
conversation_type: ConversationType,
creation: Option<DateTime<Utc>>,
modified: Option<DateTime<Utc>>,
creator: Option<DID>,
signature: Option<String>,
) -> Result<Self, Error> {
Expand All @@ -157,6 +165,8 @@ impl ConversationDocument {
name,
recipients,
creator,
creation,
modified,
conversation_type,
excluded,
messages,
Expand Down Expand Up @@ -196,6 +206,8 @@ impl ConversationDocument {
ConversationType::Direct,
None,
None,
None,
None,
)
}

Expand All @@ -207,6 +219,8 @@ impl ConversationDocument {
recipients.to_vec(),
conversation_id,
ConversationType::Group,
None,
None,
Some(did.clone()),
None,
)
Expand Down Expand Up @@ -560,13 +574,7 @@ impl ConversationDocument {

impl From<ConversationDocument> 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)
}
}

Expand All @@ -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
}
Expand Down
8 changes: 8 additions & 0 deletions extensions/warp-ipfs/src/store/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -1520,6 +1526,8 @@ impl MessageStore {
list.clone(),
Some(conversation_id),
ConversationType::Group,
None,
None,
Some(creator),
signature,
)?;
Expand Down
21 changes: 21 additions & 0 deletions warp/src/raygun/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,8 @@ pub struct Conversation {
#[serde(skip_serializing_if = "Option::is_none")]
name: Option<String>,
creator: Option<DID>,
creation: DateTime<Utc>,
modified: DateTime<Utc>,
conversation_type: ConversationType,
recipients: Vec<DID>,
}
Expand All @@ -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,
}
Expand All @@ -449,6 +454,14 @@ impl Conversation {
self.creator.clone()
}

pub fn creation(&self) -> DateTime<Utc> {
self.creation
}

pub fn modified(&self) -> DateTime<Utc> {
self.modified
}

pub fn conversation_type(&self) -> ConversationType {
self.conversation_type
}
Expand All @@ -471,6 +484,14 @@ impl Conversation {
self.creator = creator;
}

pub fn set_creation(&mut self, creation: DateTime<Utc>) {
self.creation = creation;
}

pub fn set_modified(&mut self, modified: DateTime<Utc>) {
self.modified = modified;
}

pub fn set_conversation_type(&mut self, conversation_type: ConversationType) {
self.conversation_type = conversation_type;
}
Expand Down

0 comments on commit 0b9a89f

Please sign in to comment.