cargo fmt
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
use std::fmt::Display;
|
||||
use std::collections::HashMap;
|
||||
use time::OffsetDateTime;
|
||||
use pretty::RcDoc;
|
||||
use dbus::arg::{self, RefArg};
|
||||
use kordophone::model::message::AttachmentMetadata;
|
||||
use pretty::RcDoc;
|
||||
use std::collections::HashMap;
|
||||
use std::fmt::Display;
|
||||
use time::OffsetDateTime;
|
||||
|
||||
pub struct PrintableConversation {
|
||||
pub guid: String,
|
||||
@@ -17,7 +17,7 @@ pub struct PrintableConversation {
|
||||
impl From<kordophone::model::Conversation> for PrintableConversation {
|
||||
fn from(value: kordophone::model::Conversation) -> Self {
|
||||
Self {
|
||||
guid: value.guid,
|
||||
guid: value.guid,
|
||||
date: value.date,
|
||||
unread_count: value.unread_count,
|
||||
last_message_preview: value.last_message_preview,
|
||||
@@ -34,7 +34,11 @@ impl From<kordophone_db::models::Conversation> for PrintableConversation {
|
||||
date: OffsetDateTime::from_unix_timestamp(value.date.and_utc().timestamp()).unwrap(),
|
||||
unread_count: value.unread_count.into(),
|
||||
last_message_preview: value.last_message_preview,
|
||||
participants: value.participants.into_iter().map(|p| p.display_name()).collect(),
|
||||
participants: value
|
||||
.participants
|
||||
.into_iter()
|
||||
.map(|p| p.display_name())
|
||||
.collect(),
|
||||
display_name: value.display_name,
|
||||
}
|
||||
}
|
||||
@@ -44,17 +48,33 @@ impl From<arg::PropMap> for PrintableConversation {
|
||||
fn from(value: arg::PropMap) -> Self {
|
||||
Self {
|
||||
guid: value.get("guid").unwrap().as_str().unwrap().to_string(),
|
||||
date: OffsetDateTime::from_unix_timestamp(value.get("date").unwrap().as_i64().unwrap()).unwrap(),
|
||||
unread_count: value.get("unread_count").unwrap().as_i64().unwrap().try_into().unwrap(),
|
||||
last_message_preview: value.get("last_message_preview").unwrap().as_str().map(|s| s.to_string()),
|
||||
participants: value.get("participants")
|
||||
date: OffsetDateTime::from_unix_timestamp(value.get("date").unwrap().as_i64().unwrap())
|
||||
.unwrap(),
|
||||
unread_count: value
|
||||
.get("unread_count")
|
||||
.unwrap()
|
||||
.as_i64()
|
||||
.unwrap()
|
||||
.try_into()
|
||||
.unwrap(),
|
||||
last_message_preview: value
|
||||
.get("last_message_preview")
|
||||
.unwrap()
|
||||
.as_str()
|
||||
.map(|s| s.to_string()),
|
||||
participants: value
|
||||
.get("participants")
|
||||
.unwrap()
|
||||
.0
|
||||
.as_iter()
|
||||
.unwrap()
|
||||
.map(|s| s.as_str().unwrap().to_string())
|
||||
.collect(),
|
||||
display_name: value.get("display_name").unwrap().as_str().map(|s| s.to_string()),
|
||||
display_name: value
|
||||
.get("display_name")
|
||||
.unwrap()
|
||||
.as_str()
|
||||
.map(|s| s.to_string()),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -97,19 +117,22 @@ impl From<kordophone_db::models::Message> for PrintableMessage {
|
||||
impl From<arg::PropMap> for PrintableMessage {
|
||||
fn from(value: arg::PropMap) -> Self {
|
||||
// Parse file transfer GUIDs from JSON if present
|
||||
let file_transfer_guids = value.get("file_transfer_guids")
|
||||
let file_transfer_guids = value
|
||||
.get("file_transfer_guids")
|
||||
.and_then(|v| v.as_str())
|
||||
.and_then(|json_str| serde_json::from_str(json_str).ok())
|
||||
.unwrap_or_default();
|
||||
|
||||
// Parse attachment metadata from JSON if present
|
||||
let attachment_metadata = value.get("attachment_metadata")
|
||||
let attachment_metadata = value
|
||||
.get("attachment_metadata")
|
||||
.and_then(|v| v.as_str())
|
||||
.and_then(|json_str| serde_json::from_str(json_str).ok());
|
||||
|
||||
Self {
|
||||
guid: value.get("id").unwrap().as_str().unwrap().to_string(),
|
||||
date: OffsetDateTime::from_unix_timestamp(value.get("date").unwrap().as_i64().unwrap()).unwrap(),
|
||||
date: OffsetDateTime::from_unix_timestamp(value.get("date").unwrap().as_i64().unwrap())
|
||||
.unwrap(),
|
||||
sender: value.get("sender").unwrap().as_str().unwrap().to_string(),
|
||||
text: value.get("text").unwrap().as_str().unwrap().to_string(),
|
||||
file_transfer_guids,
|
||||
@@ -119,12 +142,13 @@ impl From<arg::PropMap> for PrintableMessage {
|
||||
}
|
||||
|
||||
pub struct ConversationPrinter<'a> {
|
||||
doc: RcDoc<'a, PrintableConversation>
|
||||
doc: RcDoc<'a, PrintableConversation>,
|
||||
}
|
||||
|
||||
impl<'a> ConversationPrinter<'a> {
|
||||
pub fn new(conversation: &'a PrintableConversation) -> Self {
|
||||
let preview = conversation.last_message_preview
|
||||
let preview = conversation
|
||||
.last_message_preview
|
||||
.as_deref()
|
||||
.unwrap_or("<null>")
|
||||
.replace('\n', " ");
|
||||
@@ -134,33 +158,31 @@ impl<'a> ConversationPrinter<'a> {
|
||||
RcDoc::line()
|
||||
.append("Display Name: ")
|
||||
.append(conversation.display_name.as_deref().unwrap_or("<null>"))
|
||||
.append(RcDoc::line())
|
||||
.append(RcDoc::line())
|
||||
.append("Date: ")
|
||||
.append(conversation.date.to_string())
|
||||
.append(RcDoc::line())
|
||||
.append(RcDoc::line())
|
||||
.append("Unread Count: ")
|
||||
.append(conversation.unread_count.to_string())
|
||||
.append(RcDoc::line())
|
||||
.append(RcDoc::line())
|
||||
.append("Participants: ")
|
||||
.append("[")
|
||||
.append(RcDoc::line()
|
||||
.append(
|
||||
conversation.participants
|
||||
.iter()
|
||||
.map(|name|
|
||||
RcDoc::text(name)
|
||||
.append(",")
|
||||
.append(RcDoc::line())
|
||||
)
|
||||
.fold(RcDoc::nil(), |acc, x| acc.append(x))
|
||||
)
|
||||
.nest(4)
|
||||
.append(
|
||||
RcDoc::line()
|
||||
.append(
|
||||
conversation
|
||||
.participants
|
||||
.iter()
|
||||
.map(|name| RcDoc::text(name).append(",").append(RcDoc::line()))
|
||||
.fold(RcDoc::nil(), |acc, x| acc.append(x)),
|
||||
)
|
||||
.nest(4),
|
||||
)
|
||||
.append("]")
|
||||
.append(RcDoc::line())
|
||||
.append(RcDoc::line())
|
||||
.append("Last Message Preview: ")
|
||||
.append(preview)
|
||||
.nest(4)
|
||||
.nest(4),
|
||||
)
|
||||
.append(RcDoc::line())
|
||||
.append(">");
|
||||
@@ -176,7 +198,7 @@ impl Display for ConversationPrinter<'_> {
|
||||
}
|
||||
|
||||
pub struct MessagePrinter<'a> {
|
||||
doc: RcDoc<'a, PrintableMessage>
|
||||
doc: RcDoc<'a, PrintableMessage>,
|
||||
}
|
||||
|
||||
impl Display for MessagePrinter<'_> {
|
||||
@@ -187,37 +209,40 @@ impl Display for MessagePrinter<'_> {
|
||||
|
||||
impl<'a> MessagePrinter<'a> {
|
||||
pub fn new(message: &'a PrintableMessage) -> Self {
|
||||
let mut doc = RcDoc::text(format!("<Message: \"{}\"", &message.guid))
|
||||
.append(
|
||||
RcDoc::line()
|
||||
.append("Date: ")
|
||||
.append(message.date.to_string())
|
||||
let mut doc = RcDoc::text(format!("<Message: \"{}\"", &message.guid)).append(
|
||||
RcDoc::line()
|
||||
.append("Date: ")
|
||||
.append(message.date.to_string())
|
||||
.append(RcDoc::line())
|
||||
.append("Sender: ")
|
||||
.append(&message.sender)
|
||||
.append("Sender: ")
|
||||
.append(&message.sender)
|
||||
.append(RcDoc::line())
|
||||
.append("Body: ")
|
||||
.append(&message.text)
|
||||
.nest(4)
|
||||
);
|
||||
.append("Body: ")
|
||||
.append(&message.text)
|
||||
.nest(4),
|
||||
);
|
||||
|
||||
// Add file transfer GUIDs and attachment metadata if present
|
||||
if !message.file_transfer_guids.is_empty() {
|
||||
doc = doc.append(RcDoc::line())
|
||||
.append(
|
||||
RcDoc::line()
|
||||
.append("Attachments:")
|
||||
.append(
|
||||
message.file_transfer_guids.iter().map(|guid| {
|
||||
let mut attachment_doc = RcDoc::line()
|
||||
.append("- ")
|
||||
.append(guid);
|
||||
doc = doc.append(RcDoc::line()).append(
|
||||
RcDoc::line()
|
||||
.append("Attachments:")
|
||||
.append(
|
||||
message
|
||||
.file_transfer_guids
|
||||
.iter()
|
||||
.map(|guid| {
|
||||
let mut attachment_doc = RcDoc::line().append("- ").append(guid);
|
||||
|
||||
// Add metadata if available for this GUID
|
||||
if let Some(ref metadata) = message.attachment_metadata {
|
||||
if let Some(attachment_meta) = metadata.get(guid) {
|
||||
if let Some(ref attribution) = attachment_meta.attribution_info {
|
||||
if let (Some(width), Some(height)) = (attribution.width, attribution.height) {
|
||||
if let Some(ref attribution) =
|
||||
attachment_meta.attribution_info
|
||||
{
|
||||
if let (Some(width), Some(height)) =
|
||||
(attribution.width, attribution.height)
|
||||
{
|
||||
attachment_doc = attachment_doc
|
||||
.append(RcDoc::line())
|
||||
.append(" Dimensions: ")
|
||||
@@ -231,14 +256,14 @@ impl<'a> MessagePrinter<'a> {
|
||||
|
||||
attachment_doc
|
||||
})
|
||||
.fold(RcDoc::nil(), |acc, x| acc.append(x))
|
||||
)
|
||||
.nest(4)
|
||||
);
|
||||
.fold(RcDoc::nil(), |acc, x| acc.append(x)),
|
||||
)
|
||||
.nest(4),
|
||||
);
|
||||
}
|
||||
|
||||
doc = doc.append(RcDoc::line()).append(">");
|
||||
|
||||
MessagePrinter { doc }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user