Implements mark as read
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use crate::models::participant::Participant;
|
||||
use crate::models::{message::Message, participant::Participant};
|
||||
use chrono::{DateTime, NaiveDateTime};
|
||||
use uuid::Uuid;
|
||||
|
||||
@@ -27,6 +27,36 @@ impl Conversation {
|
||||
display_name: self.display_name.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn merge(&self, other: &Conversation, last_message: Option<&Message>) -> Conversation {
|
||||
let mut new_conversation = self.clone();
|
||||
new_conversation.unread_count = other.unread_count;
|
||||
new_conversation.participants = other.participants.clone();
|
||||
new_conversation.display_name = other.display_name.clone();
|
||||
|
||||
if let Some(last_message) = last_message {
|
||||
if last_message.date > self.date {
|
||||
new_conversation.date = last_message.date;
|
||||
}
|
||||
|
||||
if !last_message.text.is_empty() && !last_message.text.trim().is_empty() {
|
||||
new_conversation.last_message_preview = Some(last_message.text.clone());
|
||||
}
|
||||
}
|
||||
|
||||
new_conversation
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for Conversation {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.guid == other.guid &&
|
||||
self.unread_count == other.unread_count &&
|
||||
self.display_name == other.display_name &&
|
||||
self.last_message_preview == other.last_message_preview &&
|
||||
self.date == other.date &&
|
||||
self.participants == other.participants
|
||||
}
|
||||
}
|
||||
|
||||
impl From<kordophone::model::Conversation> for Conversation {
|
||||
|
||||
Reference in New Issue
Block a user