matrix_sdk_ui/timeline/event_item/content/
msg_like.rs1use as_variant::as_variant;
16use ruma::OwnedEventId;
17
18use super::{EmbeddedEvent, EncryptedMessage, InReplyToDetails, Message, PollState, Sticker};
19use crate::timeline::{
20 ReactionsByKeyBySender, TimelineDetails, event_item::content::other::OtherMessageLike,
21};
22
23#[derive(Clone, Debug)]
24pub enum MsgLikeKind {
25 Message(Message),
27
28 Sticker(Sticker),
30
31 Poll(PollState),
33
34 Redacted,
36
37 UnableToDecrypt(EncryptedMessage),
39
40 Other(OtherMessageLike),
42}
43
44#[derive(Clone, Debug)]
45pub struct ThreadSummary {
46 pub latest_event: TimelineDetails<Box<EmbeddedEvent>>,
47
48 pub num_replies: u32,
56}
57
58#[derive(Clone, Debug)]
62pub struct MsgLikeContent {
63 pub kind: MsgLikeKind,
64 pub reactions: ReactionsByKeyBySender,
65 pub in_reply_to: Option<InReplyToDetails>,
67 pub thread_root: Option<OwnedEventId>,
69 pub thread_summary: Option<ThreadSummary>,
71}
72
73impl MsgLikeContent {
74 #[cfg(not(tarpaulin_include))] pub(crate) fn debug_string(&self) -> &'static str {
76 match self.kind {
77 MsgLikeKind::Message(_) => "a message",
78 MsgLikeKind::Sticker(_) => "a sticker",
79 MsgLikeKind::Poll(_) => "a poll",
80 MsgLikeKind::Redacted => "a redacted message",
81 MsgLikeKind::UnableToDecrypt(_) => "an encrypted message we couldn't decrypt",
82 MsgLikeKind::Other(_) => "a custom message-like event",
83 }
84 }
85
86 pub fn redacted() -> Self {
87 Self {
88 kind: MsgLikeKind::Redacted,
89 reactions: Default::default(),
90 thread_root: None,
91 in_reply_to: None,
92 thread_summary: None,
93 }
94 }
95
96 pub fn unable_to_decrypt(encrypted_message: EncryptedMessage) -> Self {
97 Self {
98 kind: MsgLikeKind::UnableToDecrypt(encrypted_message),
99 reactions: Default::default(),
100 thread_root: None,
101 in_reply_to: None,
102 thread_summary: None,
103 }
104 }
105
106 pub fn is_threaded(&self) -> bool {
108 self.thread_root.is_some()
109 }
110
111 pub fn with_in_reply_to(&self, in_reply_to: InReplyToDetails) -> Self {
112 Self { in_reply_to: Some(in_reply_to), ..self.clone() }
113 }
114
115 pub fn with_kind(&self, kind: MsgLikeKind) -> Self {
116 Self { kind, ..self.clone() }
117 }
118
119 pub fn as_message(&self) -> Option<Message> {
122 as_variant!(&self.kind, MsgLikeKind::Message(message) => message.clone())
123 }
124}