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 pub public_read_receipt_event_id: Option<OwnedEventId>,
59
60 pub private_read_receipt_event_id: Option<OwnedEventId>,
63}
64
65#[derive(Clone, Debug)]
69pub struct MsgLikeContent {
70 pub kind: MsgLikeKind,
71 pub reactions: ReactionsByKeyBySender,
72 pub in_reply_to: Option<InReplyToDetails>,
74 pub thread_root: Option<OwnedEventId>,
76 pub thread_summary: Option<ThreadSummary>,
78}
79
80impl MsgLikeContent {
81 #[cfg(not(tarpaulin_include))] pub(crate) fn debug_string(&self) -> &'static str {
83 match self.kind {
84 MsgLikeKind::Message(_) => "a message",
85 MsgLikeKind::Sticker(_) => "a sticker",
86 MsgLikeKind::Poll(_) => "a poll",
87 MsgLikeKind::Redacted => "a redacted message",
88 MsgLikeKind::UnableToDecrypt(_) => "an encrypted message we couldn't decrypt",
89 MsgLikeKind::Other(_) => "a custom message-like event",
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}