Skip to content

fix: fall back to m.mentions for USER_MENTION annotations#117

Closed
iFixRobots wants to merge 1 commit intomasterfrom
fix/m-mentions-fallback
Closed

fix: fall back to m.mentions for USER_MENTION annotations#117
iFixRobots wants to merge 1 commit intomasterfrom
fix/m-mentions-fallback

Conversation

@iFixRobots
Copy link
Copy Markdown

Problem

When a Matrix client sends a message with m.mentions (MSC3952) but no formatted_body, the bridge drops all mention annotations. Google Chat receives the message as plain text with no USER_MENTION — the mentioned user gets no notification.

This happens because the bridge only extracts mentions from HTML <a href="matrix.to"> pills in formatted_body. When format != HTML, it returns (body, None).

The Beeper Desktop client hits this path because the Google Chat bridge does not report FormattingFeature.UserLink in room capabilities, causing the client to render mentions as <span> instead of <a>, which produces identical plain text for body and formattedBody, so formatted_body is omitted from the event.

Fix

When formatted_body is absent, check for m.mentions.user_ids in the event content. For each mentioned MXID:

  1. Resolve to Google Chat ID via Puppet.get_id_from_mxid
  2. Look up puppet display name via Puppet.get_by_gcid
  3. Find @DisplayName offset in the plain body text
  4. Construct USER_MENTION annotation using existing GCEntity machinery

Gracefully skips unresolvable MXIDs, missing puppets, and display names not found in the body.

Fallback-only path — the existing HTML pill parsing is completely untouched.

Related

@iFixRobots iFixRobots force-pushed the fix/m-mentions-fallback branch from 32c7abc to 54f7f55 Compare April 22, 2026 17:55
…ION annotations

When formatted_body is absent (e.g. Desktop client doesn't report
FormattingFeature.UserLink), the bridge now reads MSC3952 m.mentions
to construct USER_MENTION annotations from the plain text body.

For each mentioned MXID:
1. Resolve to Google Chat ID via Puppet.get_id_from_mxid
2. Look up puppet display name via Puppet.get_by_gcid
3. Find @DisplayName offset in plain body text
4. Construct USER_MENTION annotation using existing GCEntity machinery

Gracefully skips unresolvable MXIDs, missing puppets, and display
names not found in the body text.
@iFixRobots iFixRobots force-pushed the fix/m-mentions-fallback branch from 54f7f55 to a0b13ba Compare April 22, 2026 17:55
@iFixRobots iFixRobots changed the title [DESK-26003] - fix: fall back to m.mentions for USER_MENTION annotations fix: fall back to m.mentions for USER_MENTION annotations Apr 22, 2026
@tulir
Copy link
Copy Markdown
Member

tulir commented Apr 22, 2026

Unformatted mentions aren't valid. If room capabilities are inaccurate, then just need to fix the capabilities

@tulir tulir closed this Apr 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants