use as_variant::as_variant;
use ruma::OwnedEventId;
use super::{
EmbeddedEvent, EncryptedMessage, InReplyToDetails, LiveLocationState, Message, PollState,
Sticker,
};
use crate::timeline::{
ReactionsByKeyBySender, TimelineDetails, event_item::content::other::OtherMessageLike,
};
#[derive(Clone, Debug)]
pub enum MsgLikeKind {
Message(Message),
Sticker(Sticker),
Poll(PollState),
Redacted,
UnableToDecrypt(EncryptedMessage),
Other(OtherMessageLike),
LiveLocation(LiveLocationState),
}
#[derive(Clone, Debug)]
pub struct ThreadSummary {
pub latest_event: TimelineDetails<Box<EmbeddedEvent>>,
pub num_replies: u32,
pub public_read_receipt_event_id: Option<OwnedEventId>,
pub private_read_receipt_event_id: Option<OwnedEventId>,
}
#[derive(Clone, Debug)]
pub struct MsgLikeContent {
pub kind: MsgLikeKind,
pub reactions: ReactionsByKeyBySender,
pub in_reply_to: Option<InReplyToDetails>,
pub thread_root: Option<OwnedEventId>,
pub thread_summary: Option<ThreadSummary>,
}
impl MsgLikeContent {
#[cfg(not(tarpaulin_include))] pub(crate) fn debug_string(&self) -> &'static str {
match self.kind {
MsgLikeKind::Message(_) => "a message",
MsgLikeKind::Sticker(_) => "a sticker",
MsgLikeKind::Poll(_) => "a poll",
MsgLikeKind::Redacted => "a redacted message",
MsgLikeKind::UnableToDecrypt(_) => "an encrypted message we couldn't decrypt",
MsgLikeKind::Other(_) => "a custom message-like event",
MsgLikeKind::LiveLocation(_) => "a live location share",
}
}
pub fn redacted() -> Self {
Self {
kind: MsgLikeKind::Redacted,
reactions: Default::default(),
thread_root: None,
in_reply_to: None,
thread_summary: None,
}
}
pub fn unable_to_decrypt(encrypted_message: EncryptedMessage) -> Self {
Self {
kind: MsgLikeKind::UnableToDecrypt(encrypted_message),
reactions: Default::default(),
thread_root: None,
in_reply_to: None,
thread_summary: None,
}
}
pub fn is_threaded(&self) -> bool {
self.thread_root.is_some()
}
pub fn with_in_reply_to(&self, in_reply_to: InReplyToDetails) -> Self {
Self { in_reply_to: Some(in_reply_to), ..self.clone() }
}
pub fn with_kind(&self, kind: MsgLikeKind) -> Self {
Self { kind, ..self.clone() }
}
pub fn as_message(&self) -> Option<Message> {
as_variant!(&self.kind, MsgLikeKind::Message(message) => message.clone())
}
}