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