Private
Public Access
1
0

plub through attachment guids via messages

This commit is contained in:
2025-05-26 16:52:38 -07:00
parent 2b5df53cc3
commit e55b29eb4d
15 changed files with 214 additions and 20 deletions

View File

@@ -1,7 +1,9 @@
use chrono::{DateTime, NaiveDateTime};
use std::collections::HashMap;
use uuid::Uuid;
use crate::models::participant::Participant;
use kordophone::model::outgoing_message::OutgoingMessage;
use kordophone::model::message::AttachmentMetadata;
#[derive(Clone, Debug)]
pub struct Message {
@@ -9,6 +11,8 @@ pub struct Message {
pub sender: Participant,
pub text: String,
pub date: NaiveDateTime,
pub file_transfer_guids: Vec<String>,
pub attachment_metadata: Option<HashMap<String, AttachmentMetadata>>,
}
impl Message {
@@ -36,7 +40,9 @@ impl From<kordophone::model::Message> for Message {
.unwrap_or(0),
)
.unwrap()
.naive_local()
.naive_local(),
file_transfer_guids: value.file_transfer_guids,
attachment_metadata: value.attachment_metadata,
}
}
}
@@ -48,6 +54,8 @@ impl From<&OutgoingMessage> for Message {
sender: Participant::Me,
text: value.text.clone(),
date: value.date,
file_transfer_guids: Vec::new(), // Outgoing messages don't have file transfer GUIDs initially
attachment_metadata: None, // Outgoing messages don't have attachment metadata initially
}
}
}
@@ -57,6 +65,8 @@ pub struct MessageBuilder {
sender: Option<Participant>,
text: Option<String>,
date: Option<NaiveDateTime>,
file_transfer_guids: Option<Vec<String>>,
attachment_metadata: Option<HashMap<String, AttachmentMetadata>>,
}
impl Default for MessageBuilder {
@@ -72,6 +82,8 @@ impl MessageBuilder {
sender: None,
text: None,
date: None,
file_transfer_guids: None,
attachment_metadata: None,
}
}
@@ -90,12 +102,24 @@ impl MessageBuilder {
self
}
pub fn file_transfer_guids(mut self, file_transfer_guids: Vec<String>) -> Self {
self.file_transfer_guids = Some(file_transfer_guids);
self
}
pub fn attachment_metadata(mut self, attachment_metadata: HashMap<String, AttachmentMetadata>) -> Self {
self.attachment_metadata = Some(attachment_metadata);
self
}
pub fn build(self) -> Message {
Message {
id: self.id.unwrap_or_else(|| Uuid::new_v4().to_string()),
sender: self.sender.unwrap_or(Participant::Me),
text: self.text.unwrap_or_default(),
date: self.date.unwrap_or_else(|| chrono::Utc::now().naive_utc()),
file_transfer_guids: self.file_transfer_guids.unwrap_or_default(),
attachment_metadata: self.attachment_metadata,
}
}
}