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 pub public_read_receipt_event_id: Option<OwnedEventId>,
65
66 pub private_read_receipt_event_id: Option<OwnedEventId>,
69}
70
71#[derive(Clone, Debug)]
75pub struct MsgLikeContent {
76 pub kind: MsgLikeKind,
77 pub reactions: ReactionsByKeyBySender,
78 pub in_reply_to: Option<InReplyToDetails>,
80 pub thread_root: Option<OwnedEventId>,
82 pub thread_summary: Option<ThreadSummary>,
84}
85
86impl MsgLikeContent {
87 #[cfg(not(tarpaulin_include))] pub(crate) fn debug_string(&self) -> &'static str {
89 match self.kind {
90 MsgLikeKind::Message(_) => "a message",
91 MsgLikeKind::Sticker(_) => "a sticker",
92 MsgLikeKind::Poll(_) => "a poll",
93 MsgLikeKind::Redacted => "a redacted message",
94 MsgLikeKind::UnableToDecrypt(_) => "an encrypted message we couldn't decrypt",
95 MsgLikeKind::Other(_) => "a custom message-like event",
96 MsgLikeKind::LiveLocation(_) => "a live location share",
97 }
98 }
99
100 pub fn redacted() -> Self {
101 Self {
102 kind: MsgLikeKind::Redacted,
103 reactions: Default::default(),
104 thread_root: None,
105 in_reply_to: None,
106 thread_summary: None,
107 }
108 }
109
110 pub fn unable_to_decrypt(encrypted_message: EncryptedMessage) -> Self {
111 Self {
112 kind: MsgLikeKind::UnableToDecrypt(encrypted_message),
113 reactions: Default::default(),
114 thread_root: None,
115 in_reply_to: None,
116 thread_summary: None,
117 }
118 }
119
120 pub fn is_threaded(&self) -> bool {
122 self.thread_root.is_some()
123 }
124
125 pub fn with_in_reply_to(&self, in_reply_to: InReplyToDetails) -> Self {
126 Self { in_reply_to: Some(in_reply_to), ..self.clone() }
127 }
128
129 pub fn with_kind(&self, kind: MsgLikeKind) -> Self {
130 Self { kind, ..self.clone() }
131 }
132
133 pub fn as_message(&self) -> Option<Message> {
136 as_variant!(&self.kind, MsgLikeKind::Message(message) => message.clone())
137 }
138}