reorg
This commit is contained in:
86
kordophone/src/model/conversation.rs
Normal file
86
kordophone/src/model/conversation.rs
Normal file
@@ -0,0 +1,86 @@
|
||||
use serde::Deserialize;
|
||||
use time::OffsetDateTime;
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub struct Conversation {
|
||||
pub guid: String,
|
||||
|
||||
#[serde(with = "time::serde::iso8601")]
|
||||
pub date: OffsetDateTime,
|
||||
|
||||
#[serde(rename = "unreadCount")]
|
||||
pub unread_count: i32,
|
||||
|
||||
#[serde(rename = "lastMessagePreview")]
|
||||
pub last_message_preview: Option<String>,
|
||||
|
||||
#[serde(rename = "participantDisplayNames")]
|
||||
pub participant_display_names: Vec<String>,
|
||||
|
||||
#[serde(rename = "displayName")]
|
||||
pub display_name: Option<String>,
|
||||
}
|
||||
|
||||
impl Conversation {
|
||||
pub fn builder() -> ConversationBuilder {
|
||||
ConversationBuilder::new()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct ConversationBuilder {
|
||||
guid: Option<String>,
|
||||
date: Option<OffsetDateTime>,
|
||||
unread_count: Option<i32>,
|
||||
last_message_preview: Option<String>,
|
||||
participant_display_names: Option<Vec<String>>,
|
||||
display_name: Option<String>,
|
||||
}
|
||||
|
||||
impl ConversationBuilder {
|
||||
pub fn new() -> Self {
|
||||
Self::default()
|
||||
}
|
||||
|
||||
pub fn guid(mut self, guid: String) -> Self {
|
||||
self.guid = Some(guid);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn date(mut self, date: OffsetDateTime) -> Self {
|
||||
self.date = Some(date);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn unread_count(mut self, unread_count: i32) -> Self {
|
||||
self.unread_count = Some(unread_count);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn last_message_preview(mut self, last_message_preview: String) -> Self {
|
||||
self.last_message_preview = Some(last_message_preview);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn participant_display_names(mut self, participant_display_names: Vec<String>) -> Self {
|
||||
self.participant_display_names = Some(participant_display_names);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn display_name<T>(mut self, display_name: T) -> Self where T: Into<String> {
|
||||
self.display_name = Some(display_name.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn build(self) -> Conversation {
|
||||
Conversation {
|
||||
guid: self.guid.unwrap_or(Uuid::new_v4().to_string()),
|
||||
date: self.date.unwrap_or(OffsetDateTime::now_utc()),
|
||||
unread_count: self.unread_count.unwrap_or(0),
|
||||
last_message_preview: self.last_message_preview,
|
||||
participant_display_names: self.participant_display_names.unwrap_or(vec![]),
|
||||
display_name: self.display_name,
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user