Skip to content

Commit 733665d

Browse files
zecakehpoljar
authored andcommitted
ui: Expose message mentions
Signed-off-by: Kévin Commaille <[email protected]>
1 parent d5df584 commit 733665d

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

crates/matrix-sdk-ui/src/timeline/event_handler.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,7 @@ impl<'a, 'o> TimelineEventHandler<'a, 'o> {
477477
in_reply_to: msg.in_reply_to.clone(),
478478
thread_root: msg.thread_root.clone(),
479479
edited: true,
480+
mentions: replacement.new_content.mentions,
480481
});
481482

482483
let edit_json = match &this.ctx.flow {

crates/matrix-sdk-ui/src/timeline/event_item/content/message.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use ruma::{
2727
SyncRoomMessageEvent,
2828
},
2929
AnyMessageLikeEventContent, AnySyncMessageLikeEvent, AnyTimelineEvent,
30-
BundledMessageLikeRelations,
30+
BundledMessageLikeRelations, Mentions,
3131
},
3232
html::RemoveReplyFallback,
3333
OwnedEventId, OwnedUserId, RoomVersionId, UserId,
@@ -52,6 +52,7 @@ pub struct Message {
5252
/// Event ID of the thread root, if this is a threaded message.
5353
pub(in crate::timeline) thread_root: Option<OwnedEventId>,
5454
pub(in crate::timeline) edited: bool,
55+
pub(in crate::timeline) mentions: Option<Mentions>,
5556
}
5657

5758
impl Message {
@@ -94,11 +95,11 @@ impl Message {
9495
_ => None,
9596
});
9697

97-
let msgtype = match edit {
98+
let (msgtype, mentions) = match edit {
9899
Some(mut e) => {
99100
// Edit's content is never supposed to contain the reply fallback.
100101
e.new_content.msgtype.sanitize(DEFAULT_SANITIZER_MODE, RemoveReplyFallback::No);
101-
e.new_content.msgtype
102+
(e.new_content.msgtype, e.new_content.mentions)
102103
}
103104
None => {
104105
let remove_reply_fallback = if in_reply_to.is_some() {
@@ -109,11 +110,11 @@ impl Message {
109110

110111
let mut msgtype = c.msgtype;
111112
msgtype.sanitize(DEFAULT_SANITIZER_MODE, remove_reply_fallback);
112-
msgtype
113+
(msgtype, c.mentions)
113114
}
114115
};
115116

116-
Self { msgtype, in_reply_to, thread_root, edited }
117+
Self { msgtype, in_reply_to, thread_root, edited, mentions }
117118
}
118119

119120
/// Get the `msgtype`-specific data of this message.
@@ -144,6 +145,11 @@ impl Message {
144145
self.edited
145146
}
146147

148+
/// Get the mentions of this message.
149+
pub fn mentions(&self) -> Option<&Mentions> {
150+
self.mentions.as_ref()
151+
}
152+
147153
pub(in crate::timeline) fn to_content(&self) -> RoomMessageEventContent {
148154
// Like the `impl From<Message> for RoomMessageEventContent` below, but
149155
// takes &self and only copies what's needed.
@@ -192,7 +198,7 @@ fn make_relates_to(
192198
#[cfg(not(tarpaulin_include))]
193199
impl fmt::Debug for Message {
194200
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
195-
let Self { msgtype: _, in_reply_to, thread_root, edited } = self;
201+
let Self { msgtype: _, in_reply_to, thread_root, edited, mentions: _ } = self;
196202
// since timeline items are logged, don't include all fields here so
197203
// people don't leak personal data in bug reports
198204
f.debug_struct("Message")

crates/matrix-sdk-ui/src/timeline/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ impl Timeline {
419419
});
420420

421421
let content = new_content.make_replacement(
422-
ReplacementMetadata::new(event_id.to_owned(), None),
422+
ReplacementMetadata::new(event_id.to_owned(), original_content.mentions.clone()),
423423
replied_to_message.as_ref(),
424424
);
425425

0 commit comments

Comments
 (0)