From 733665ddcc66c12070ab7dbf2fe065bb6771550f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Commaille?= Date: Sat, 11 May 2024 10:28:23 +0200 Subject: [PATCH] ui: Expose message mentions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Kévin Commaille --- .../src/timeline/event_handler.rs | 1 + .../src/timeline/event_item/content/message.rs | 18 ++++++++++++------ crates/matrix-sdk-ui/src/timeline/mod.rs | 2 +- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/crates/matrix-sdk-ui/src/timeline/event_handler.rs b/crates/matrix-sdk-ui/src/timeline/event_handler.rs index dc2c45b1c..f10014730 100644 --- a/crates/matrix-sdk-ui/src/timeline/event_handler.rs +++ b/crates/matrix-sdk-ui/src/timeline/event_handler.rs @@ -477,6 +477,7 @@ impl<'a, 'o> TimelineEventHandler<'a, 'o> { in_reply_to: msg.in_reply_to.clone(), thread_root: msg.thread_root.clone(), edited: true, + mentions: replacement.new_content.mentions, }); let edit_json = match &this.ctx.flow { diff --git a/crates/matrix-sdk-ui/src/timeline/event_item/content/message.rs b/crates/matrix-sdk-ui/src/timeline/event_item/content/message.rs index 7e4eba92e..5ec6d61ab 100644 --- a/crates/matrix-sdk-ui/src/timeline/event_item/content/message.rs +++ b/crates/matrix-sdk-ui/src/timeline/event_item/content/message.rs @@ -27,7 +27,7 @@ use ruma::{ SyncRoomMessageEvent, }, AnyMessageLikeEventContent, AnySyncMessageLikeEvent, AnyTimelineEvent, - BundledMessageLikeRelations, + BundledMessageLikeRelations, Mentions, }, html::RemoveReplyFallback, OwnedEventId, OwnedUserId, RoomVersionId, UserId, @@ -52,6 +52,7 @@ pub struct Message { /// Event ID of the thread root, if this is a threaded message. pub(in crate::timeline) thread_root: Option, pub(in crate::timeline) edited: bool, + pub(in crate::timeline) mentions: Option, } impl Message { @@ -94,11 +95,11 @@ impl Message { _ => None, }); - let msgtype = match edit { + let (msgtype, mentions) = match edit { Some(mut e) => { // Edit's content is never supposed to contain the reply fallback. e.new_content.msgtype.sanitize(DEFAULT_SANITIZER_MODE, RemoveReplyFallback::No); - e.new_content.msgtype + (e.new_content.msgtype, e.new_content.mentions) } None => { let remove_reply_fallback = if in_reply_to.is_some() { @@ -109,11 +110,11 @@ impl Message { let mut msgtype = c.msgtype; msgtype.sanitize(DEFAULT_SANITIZER_MODE, remove_reply_fallback); - msgtype + (msgtype, c.mentions) } }; - Self { msgtype, in_reply_to, thread_root, edited } + Self { msgtype, in_reply_to, thread_root, edited, mentions } } /// Get the `msgtype`-specific data of this message. @@ -144,6 +145,11 @@ impl Message { self.edited } + /// Get the mentions of this message. + pub fn mentions(&self) -> Option<&Mentions> { + self.mentions.as_ref() + } + pub(in crate::timeline) fn to_content(&self) -> RoomMessageEventContent { // Like the `impl From for RoomMessageEventContent` below, but // takes &self and only copies what's needed. @@ -192,7 +198,7 @@ fn make_relates_to( #[cfg(not(tarpaulin_include))] impl fmt::Debug for Message { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - let Self { msgtype: _, in_reply_to, thread_root, edited } = self; + let Self { msgtype: _, in_reply_to, thread_root, edited, mentions: _ } = self; // since timeline items are logged, don't include all fields here so // people don't leak personal data in bug reports f.debug_struct("Message") diff --git a/crates/matrix-sdk-ui/src/timeline/mod.rs b/crates/matrix-sdk-ui/src/timeline/mod.rs index 8f7133b82..c1599388c 100644 --- a/crates/matrix-sdk-ui/src/timeline/mod.rs +++ b/crates/matrix-sdk-ui/src/timeline/mod.rs @@ -419,7 +419,7 @@ impl Timeline { }); let content = new_content.make_replacement( - ReplacementMetadata::new(event_id.to_owned(), None), + ReplacementMetadata::new(event_id.to_owned(), original_content.mentions.clone()), replied_to_message.as_ref(), );