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::{
23 ReactionsByKeyBySender, TimelineDetails, event_item::content::other::OtherMessageLike,
24};
25
26#[derive(Clone, Debug)]
27pub enum MsgLikeKind {
28 Message(Message),
30
31 Sticker(Sticker),
33
34 Poll(PollState),
36
37 Redacted,
39
40 UnableToDecrypt(EncryptedMessage),
42
43 Other(OtherMessageLike),
45
46 LiveLocation(LiveLocationState),
48}
49
50#[derive(Clone, Debug)]
51pub struct ThreadSummary {
52 pub latest_event: TimelineDetails<Box<EmbeddedEvent>>,
53
54 pub num_replies: u32,
62}
63
64#[derive(Clone, Debug)]
68pub struct MsgLikeContent {
69 pub kind: MsgLikeKind,
70 pub reactions: ReactionsByKeyBySender,
71 pub in_reply_to: Option<InReplyToDetails>,
73 pub thread_root: Option<OwnedEventId>,
75 pub thread_summary: Option<ThreadSummary>,
77}
78
79impl MsgLikeContent {
80 #[cfg(not(tarpaulin_include))] pub(crate) fn debug_string(&self) -> &'static str {
82 match self.kind {
83 MsgLikeKind::Message(_) => "a message",
84 MsgLikeKind::Sticker(_) => "a sticker",
85 MsgLikeKind::Poll(_) => "a poll",
86 MsgLikeKind::Redacted => "a redacted message",
87 MsgLikeKind::UnableToDecrypt(_) => "an encrypted message we couldn't decrypt",
88 MsgLikeKind::Other(_) => "a custom message-like event",
89 MsgLikeKind::LiveLocation(_) => "a live location share",
90 }
91 }
92
93 pub fn redacted() -> Self {
94 Self {
95 kind: MsgLikeKind::Redacted,
96 reactions: Default::default(),
97 thread_root: None,
98 in_reply_to: None,
99 thread_summary: None,
100 }
101 }
102
103 pub fn unable_to_decrypt(encrypted_message: EncryptedMessage) -> Self {
104 Self {
105 kind: MsgLikeKind::UnableToDecrypt(encrypted_message),
106 reactions: Default::default(),
107 thread_root: None,
108 in_reply_to: None,
109 thread_summary: None,
110 }
111 }
112
113 pub fn is_threaded(&self) -> bool {
115 self.thread_root.is_some()
116 }
117
118 pub fn with_in_reply_to(&self, in_reply_to: InReplyToDetails) -> Self {
119 Self { in_reply_to: Some(in_reply_to), ..self.clone() }
120 }
121
122 pub fn with_kind(&self, kind: MsgLikeKind) -> Self {
123 Self { kind, ..self.clone() }
124 }
125
126 pub fn as_message(&self) -> Option<Message> {
129 as_variant!(&self.kind, MsgLikeKind::Message(message) => message.clone())
130 }
131}