Skip to content

Commit

Permalink
Restore fallback support for user mentions
Browse files Browse the repository at this point in the history
Fallback support was intentionally removed in 9908512,
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).
  • Loading branch information
spantaleev committed Oct 3, 2024
1 parent b89f0db commit b402268
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions src/conversation/matrix/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit b402268

Please sign in to comment.