plub through attachment guids via messages
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
use serde::Deserialize;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::HashMap;
|
||||
use time::OffsetDateTime;
|
||||
use uuid::Uuid;
|
||||
|
||||
@@ -6,6 +7,23 @@ use super::Identifiable;
|
||||
|
||||
pub type MessageID = <Message as Identifiable>::ID;
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct AttributionInfo {
|
||||
/// Picture width
|
||||
#[serde(rename = "pgensh")]
|
||||
pub width: Option<u32>,
|
||||
|
||||
/// Picture height
|
||||
#[serde(rename = "pgensw")]
|
||||
pub height: Option<u32>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct AttachmentMetadata {
|
||||
#[serde(rename = "attributionInfo")]
|
||||
pub attribution_info: Option<AttributionInfo>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub struct Message {
|
||||
pub guid: String,
|
||||
@@ -18,6 +36,14 @@ pub struct Message {
|
||||
|
||||
#[serde(with = "time::serde::iso8601")]
|
||||
pub date: OffsetDateTime,
|
||||
|
||||
/// Array of file transfer GUIDs for attachments
|
||||
#[serde(rename = "fileTransferGUIDs", default)]
|
||||
pub file_transfer_guids: Vec<String>,
|
||||
|
||||
/// Optional attachment metadata, keyed by attachment GUID
|
||||
#[serde(rename = "attachmentMetadata")]
|
||||
pub attachment_metadata: Option<HashMap<String, AttachmentMetadata>>,
|
||||
}
|
||||
|
||||
impl Message {
|
||||
@@ -39,7 +65,9 @@ pub struct MessageBuilder {
|
||||
guid: Option<String>,
|
||||
text: Option<String>,
|
||||
sender: Option<String>,
|
||||
date: Option<OffsetDateTime>,
|
||||
date: Option<OffsetDateTime>,
|
||||
file_transfer_guids: Option<Vec<String>>,
|
||||
attachment_metadata: Option<HashMap<String, AttachmentMetadata>>,
|
||||
}
|
||||
|
||||
impl MessageBuilder {
|
||||
@@ -67,12 +95,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 {
|
||||
guid: self.guid.unwrap_or(Uuid::new_v4().to_string()),
|
||||
text: self.text.unwrap_or("".to_string()),
|
||||
sender: self.sender,
|
||||
date: self.date.unwrap_or(OffsetDateTime::now_utc()),
|
||||
file_transfer_guids: self.file_transfer_guids.unwrap_or_default(),
|
||||
attachment_metadata: self.attachment_metadata,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user