From 999d612a331fd6a78326cb02b6e05475ab7f2e84 Mon Sep 17 00:00:00 2001 From: rasmus Date: Tue, 10 Mar 2026 20:02:08 +0100 Subject: [PATCH] feat(sdk): add add_mentions toggle to Reply Signed-off-by: rasmus --- crates/matrix-sdk-ui/src/timeline/mod.rs | 9 ++++- crates/matrix-sdk/src/room/reply.rs | 40 +++++++++++++++---- .../tests/integration/room/attachment/mod.rs | 6 ++- .../tests/integration/send_queue.rs | 4 +- .../src/tests/timeline.rs | 4 +- 5 files changed, 51 insertions(+), 12 deletions(-) diff --git a/crates/matrix-sdk-ui/src/timeline/mod.rs b/crates/matrix-sdk-ui/src/timeline/mod.rs index 14c9133ef..8ce5fb2fa 100644 --- a/crates/matrix-sdk-ui/src/timeline/mod.rs +++ b/crates/matrix-sdk-ui/src/timeline/mod.rs @@ -48,7 +48,7 @@ use ruma::{ receipt::{Receipt, ReceiptThread}, relation::Thread, room::message::{ - Relation, RelationWithoutReplacement, ReplyWithinThread, + AddMentions, Relation, RelationWithoutReplacement, ReplyWithinThread, RoomMessageEventContentWithoutRelation, TextMessageEventContent, }, }, @@ -420,7 +420,11 @@ impl Timeline { } else { EnforceThread::MaybeThreaded }; - return Some(Reply { event_id: in_reply_to, enforce_thread }); + return Some(Reply { + event_id: in_reply_to, + enforce_thread, + add_mentions: AddMentions::Yes, + }); } let thread_root = self.controller.thread_root()?; @@ -452,6 +456,7 @@ impl Timeline { Some(Reply { event_id: latest_event_id, enforce_thread: EnforceThread::Threaded(ReplyWithinThread::No), + add_mentions: AddMentions::Yes, }) } diff --git a/crates/matrix-sdk/src/room/reply.rs b/crates/matrix-sdk/src/room/reply.rs index 22558f3a3..9e4b8a2ee 100644 --- a/crates/matrix-sdk/src/room/reply.rs +++ b/crates/matrix-sdk/src/room/reply.rs @@ -40,6 +40,9 @@ pub struct Reply { pub event_id: OwnedEventId, /// Whether to enforce a thread relation. pub enforce_thread: EnforceThread, + /// Whether to add intentional Mentions. Might be ignored if the reply is + /// sent by the same user as the event that it replies to. + pub add_mentions: AddMentions, } /// Errors specific to unsupported replies. @@ -125,7 +128,7 @@ async fn make_reply_event( // If the replied to event has been written by the current user, let's toggle to // `AddMentions::No`. let mention_the_sender = - if own_user_id == event.sender() { AddMentions::No } else { AddMentions::Yes }; + if own_user_id == event.sender() { AddMentions::No } else { reply.add_mentions }; let content = match reply.enforce_thread { EnforceThread::Threaded(is_reply) => { @@ -153,7 +156,9 @@ mod tests { EventId, OwnedEventId, event_id, events::{ AnySyncTimelineEvent, - room::message::{Relation, ReplyWithinThread, RoomMessageEventContentWithoutRelation}, + room::message::{ + AddMentions, Relation, ReplyWithinThread, RoomMessageEventContentWithoutRelation, + }, }, serde::Raw, user_id, @@ -198,7 +203,8 @@ mod tests { content, Reply { event_id: event_id!("$2").into(), - enforce_thread: EnforceThread::Unthreaded + enforce_thread: EnforceThread::Unthreaded, + add_mentions: AddMentions::Yes, }, ) .await, @@ -239,7 +245,11 @@ mod tests { cache, own_user_id, content, - Reply { event_id: event_id.into(), enforce_thread: EnforceThread::Unthreaded }, + Reply { + event_id: event_id.into(), + enforce_thread: EnforceThread::Unthreaded, + add_mentions: AddMentions::Yes, + }, ) .await, Err(ReplyError::Deserialization) @@ -265,7 +275,11 @@ mod tests { cache, own_user_id, content, - Reply { event_id: event_id.into(), enforce_thread: EnforceThread::Unthreaded }, + Reply { + event_id: event_id.into(), + enforce_thread: EnforceThread::Unthreaded, + add_mentions: AddMentions::Yes, + }, ) .await, Err(ReplyError::StateEvent) @@ -290,7 +304,11 @@ mod tests { cache, own_user_id, content, - Reply { event_id: event_id.into(), enforce_thread: EnforceThread::Unthreaded }, + Reply { + event_id: event_id.into(), + enforce_thread: EnforceThread::Unthreaded, + add_mentions: AddMentions::Yes, + }, ) .await .unwrap(); @@ -321,6 +339,7 @@ mod tests { Reply { event_id: event_id.into(), enforce_thread: EnforceThread::Threaded(ReplyWithinThread::No), + add_mentions: AddMentions::Yes, }, ) .await @@ -363,6 +382,7 @@ mod tests { Reply { event_id: event_id.into(), enforce_thread: EnforceThread::Threaded(ReplyWithinThread::No), + add_mentions: AddMentions::Yes, }, ) .await @@ -405,6 +425,7 @@ mod tests { Reply { event_id: event_id.into(), enforce_thread: EnforceThread::Threaded(ReplyWithinThread::Yes), + add_mentions: AddMentions::Yes, }, ) .await @@ -444,7 +465,11 @@ mod tests { cache, own_user_id, content, - Reply { event_id: event_id.into(), enforce_thread: EnforceThread::MaybeThreaded }, + Reply { + event_id: event_id.into(), + enforce_thread: EnforceThread::MaybeThreaded, + add_mentions: AddMentions::Yes, + }, ) .await .unwrap(); @@ -487,6 +512,7 @@ mod tests { Reply { event_id: event_id.into(), enforce_thread: EnforceThread::Threaded(ReplyWithinThread::No), + add_mentions: AddMentions::Yes, }, ) .await diff --git a/crates/matrix-sdk/tests/integration/room/attachment/mod.rs b/crates/matrix-sdk/tests/integration/room/attachment/mod.rs index 03df8df3f..04ee27df8 100644 --- a/crates/matrix-sdk/tests/integration/room/attachment/mod.rs +++ b/crates/matrix-sdk/tests/integration/room/attachment/mod.rs @@ -13,7 +13,7 @@ use ruma::{ Mentions, room::{ MediaSource, - message::{ReplyWithinThread, TextMessageEventContent}, + message::{AddMentions, ReplyWithinThread, TextMessageEventContent}, }, }, mxc_uri, owned_mxc_uri, owned_user_id, uint, @@ -407,6 +407,7 @@ async fn test_room_attachment_reply_outside_thread() { .reply(Some(Reply { event_id: replied_to_event_id.into(), enforce_thread: EnforceThread::Unthreaded, + add_mentions: AddMentions::Yes, })), ) .await @@ -473,6 +474,7 @@ async fn test_room_attachment_start_thread() { .reply(Some(Reply { event_id: replied_to_event_id.into(), enforce_thread: EnforceThread::Threaded(ReplyWithinThread::No), + add_mentions: AddMentions::Yes, })), ) .await @@ -540,6 +542,7 @@ async fn test_room_attachment_reply_on_thread_as_reply() { .reply(Some(Reply { event_id: replied_to_event_id.into(), enforce_thread: EnforceThread::Threaded(ReplyWithinThread::Yes), + add_mentions: AddMentions::Yes, })), ) .await @@ -608,6 +611,7 @@ async fn test_room_attachment_reply_forwarding_thread() { .reply(Some(Reply { event_id: replied_to_event_id.into(), enforce_thread: EnforceThread::MaybeThreaded, + add_mentions: AddMentions::Yes, })), ) .await diff --git a/crates/matrix-sdk/tests/integration/send_queue.rs b/crates/matrix-sdk/tests/integration/send_queue.rs index 90f5ef987..a48ec9ad0 100644 --- a/crates/matrix-sdk/tests/integration/send_queue.rs +++ b/crates/matrix-sdk/tests/integration/send_queue.rs @@ -37,7 +37,7 @@ use ruma::{ room::{ MediaSource, message::{ - ImageMessageEventContent, MessageType, Relation, ReplyWithinThread, + AddMentions, ImageMessageEventContent, MessageType, Relation, ReplyWithinThread, RoomMessageEventContent, TextMessageEventContent, }, }, @@ -1942,6 +1942,7 @@ async fn test_media_uploads() { .reply(Some(Reply { event_id: replied_to_event_id.into(), enforce_thread: matrix_sdk::room::reply::EnforceThread::Threaded(ReplyWithinThread::No), + add_mentions: AddMentions::Yes, })) .info(attachment_info); @@ -2269,6 +2270,7 @@ async fn test_gallery_uploads() { .reply(Some(Reply { event_id: replied_to_event_id.into(), enforce_thread: matrix_sdk::room::reply::EnforceThread::Threaded(ReplyWithinThread::No), + add_mentions: AddMentions::Yes, })); // ---------------------- diff --git a/testing/matrix-sdk-integration-testing/src/tests/timeline.rs b/testing/matrix-sdk-integration-testing/src/tests/timeline.rs index da3c0d097..d90e1ab44 100644 --- a/testing/matrix-sdk-integration-testing/src/tests/timeline.rs +++ b/testing/matrix-sdk-integration-testing/src/tests/timeline.rs @@ -40,7 +40,7 @@ use matrix_sdk::{ room::{ encryption::RoomEncryptionEventContent, message::{ - ReplyWithinThread, RoomMessageEventContent, + AddMentions, ReplyWithinThread, RoomMessageEventContent, RoomMessageEventContentWithoutRelation, }, }, @@ -963,6 +963,7 @@ async fn test_thread_focused_timeline() -> TestResult { Reply { event_id: thread_root.clone(), enforce_thread: EnforceThread::Threaded(ReplyWithinThread::No), + add_mentions: AddMentions::Yes, }, ) .await?; @@ -1520,6 +1521,7 @@ async fn test_latest_thread_event_is_redecrypted_and_updated() -> TestResult { Reply { event_id: thread_root_event_id.clone(), enforce_thread: EnforceThread::Threaded(ReplyWithinThread::No), + add_mentions: AddMentions::Yes, }, ) .await?;