diff --git a/src/content.rs b/src/content.rs index 8fead84b8..b779c4c86 100644 --- a/src/content.rs +++ b/src/content.rs @@ -1,4 +1,5 @@ use libsignal_protocol::ProtocolAddress; +use std::fmt; use uuid::Uuid; pub use crate::{ @@ -31,6 +32,21 @@ pub struct Metadata { pub server_guid: Option, } +impl fmt::Display for Metadata { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!( + f, + "Metadata {{ sender: {}, guid: {} }}", + self.sender.to_service_id(), + // XXX: should this still be optional? + self.server_guid + .map(|u| u.to_string()) + .as_deref() + .unwrap_or("None"), + ) + } +} + impl Metadata { pub(crate) fn protocol_address(&self) -> ProtocolAddress { self.sender.to_protocol_address(self.sender_device) @@ -88,6 +104,46 @@ impl Content { } } +impl fmt::Display for ContentBody { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + Self::NullMessage(_) => write!(f, "NullMessage"), + Self::DataMessage(m) => { + match (&m.body, &m.reaction, m.attachments.len()) { + (Some(body), _, 0) => { + write!(f, "DataMessage({}", body) + }, + (Some(body), _, n) => { + write!(f, "DataMessage({}, attachments: {n})", body) + }, + (None, Some(emoji), _) => { + write!( + f, + "DataMessage(reaction: {})", + emoji.emoji.as_deref().unwrap_or("None") + ) + }, + (None, _, n) if n > 0 => { + write!(f, "DataMessage(attachments: {n})") + }, + _ => { + write!(f, "{self:?}") + }, + } + }, + Self::SynchronizeMessage(_) => write!(f, "SynchronizeMessage"), + Self::CallMessage(_) => write!(f, "CallMessage"), + Self::ReceiptMessage(_) => write!(f, "ReceiptMessage"), + Self::TypingMessage(_) => write!(f, "TypingMessage"), + // Self::SenderKeyDistributionMessage(_) => write!(f, "SenderKeyDistributionMessage"), + // Self::DecryptionErrorMessage(_) => write!(f, "DecryptionErrorMessage"), + Self::StoryMessage(_) => write!(f, "StoryMessage"), + Self::PniSignatureMessage(_) => write!(f, "PniSignatureMessage"), + Self::EditMessage(_) => write!(f, "EditMessage"), + } + } +} + #[derive(Clone, Debug)] #[allow(clippy::large_enum_variant)] pub enum ContentBody { diff --git a/src/envelope.rs b/src/envelope.rs index ff247c9a3..2d10194ca 100644 --- a/src/envelope.rs +++ b/src/envelope.rs @@ -26,7 +26,7 @@ impl TryFrom for Envelope { } impl Envelope { - #[tracing::instrument(skip(input, signaling_key), fields(input_size = input.len()))] + #[tracing::instrument(skip(input, signaling_key), fields(signaling_key_present = signaling_key.is_some(), input_size = input.len()))] pub fn decrypt( input: &[u8], signaling_key: Option<&SignalingKey>,