Restore fallback support for user mentions
Fallback support was intentionally removed in 9908512968,
because it was deemed OK to do so.
It turns out that Element iOS still doesn't properly do user mentions
(and likely never will, until Element X replaces it), so we can't just
drop the fallback user mentions logic without affecting all these
clients. It's possible that the Element Android is no better (unverified claim).
This commit is contained in:
@@ -423,18 +423,26 @@ fn is_event_mentioning_bot(
|
||||
event_content: &RoomMessageEventContent,
|
||||
bot_user_id: &OwnedUserId,
|
||||
) -> bool {
|
||||
// As a fallback, we used to do string matching (`event_content.body().contains(bot_user_id.as_str())`) here as well.
|
||||
// However, this is unreliable. In 2024+, clients that do not have proper mentions support should get fixed,
|
||||
// instead of us having to deal with the possibility of false positives.
|
||||
//
|
||||
let Some(mentions) = &event_content.mentions else {
|
||||
return false;
|
||||
};
|
||||
|
||||
mentions
|
||||
.user_ids
|
||||
.iter()
|
||||
.any(|user_id| user_id == bot_user_id)
|
||||
if let Some(mentions) = &event_content.mentions {
|
||||
mentions
|
||||
.user_ids
|
||||
.iter()
|
||||
.any(|user_id| user_id == bot_user_id)
|
||||
} else {
|
||||
// For compatibility with clients that do not support the new Mentions specification
|
||||
// (see https://spec.matrix.org/latest/client-server-api/#user-and-room-mentions),
|
||||
// we also do string matching here.
|
||||
//
|
||||
// As of 2024-10-03, at least Element iOS does not support the new Mentions specification
|
||||
// and is still quite widespread.
|
||||
//
|
||||
// It may be even better to match not only against the MXID, but also against the bot's
|
||||
// room-specific display name.
|
||||
//
|
||||
// We may consider dropping this string-matching behavior altogether in the future,
|
||||
// so improving this compatibility block is not a high priority.
|
||||
event_content.body().contains(bot_user_id.as_str())
|
||||
}
|
||||
}
|
||||
|
||||
/// Strips the rich reply fallback text from the given text.
|
||||
|
||||
Reference in New Issue
Block a user