feat(sdk): add add_mentions toggle to Reply

Signed-off-by: rasmus <mail@rasmusantons.de>
This commit is contained in:
rasmus
2026-03-10 20:02:08 +01:00
committed by Benjamin Bouvier
parent f25af6be6b
commit 999d612a33
5 changed files with 51 additions and 12 deletions
+7 -2
View File
@@ -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,
})
}
+33 -7
View File
@@ -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<S: EventSource>(
// 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
@@ -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
@@ -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,
}));
// ----------------------
@@ -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?;