Skip to content

PLAT-39405 connector: turn Reddit @username text into Matrix mentions - #18

Merged
Fizzadar merged 1 commit into
mainfrom
nick/plat-39405-incoming-mentions
Oct 29, 2026
Merged

Fizzadar merged 1 commit into
mainfrom
nick/plat-39405-incoming-mentions

Conversation

@Fizzadar

Copy link
Copy Markdown
Contributor

Reddit sends a mention as plain @username text, with no m.mentions, formatted_body or user reference (captured from reddit.com/chat's composer), so mentions reached Beeper as plain text. Incoming text that names a member of the room as @username now gets a matrix.to pill and m.mentions for that member's ghost, or for the user when they're the one mentioned.

🤖 Generated with Claude Code

Reddit sends mentions as plain "@username" text with no m.mentions or
formatted body, so they arrived in Beeper as plain text.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@indent

indent Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Issues

2 potential issues found:

  • A user mentioned twice in one message (e.g. "@other ping @other") is listed twice in m.mentions.user_ids; dedupe the IDs while still linking each occurrence.
    Found by Indent Review Agent
  • The mention regex has no trailing boundary, so a token longer than 20 chars (e.g. "@some_user_name_that_is_long") can be linked and ping a member whose name equals its 20-char prefix.
    Found by Indent Review Agent

↑ Select any checkbox above to have Indent auto-fix the issue

CI Checks

All CI checks passed on b944020.

Review agents

Select any unchecked box below to run or rerun that agent.

Found issues (1)
  • Indent Review Agent · Only two minor nits in mention linking
Full results

Indent Review Agent

  • Summary: Only two minor nits in mention linking
  • Last ran on commit: b9440202
  • Latest result
    {
      "summary": "Only two minor nits in mention linking",
      "findings": [
        {
          "fix": "Track a seen set and only append a target to `mentioned` the first time; keep linking every occurrence in the HTML.",
          "line": 56,
          "path": "pkg/connector/mentions.go",
          "issue": "linkMentions appends `target` to `mentioned` on every match, so a body like \"@other ping @other\" produces `m.mentions.user_ids` with the same MXID twice. Clients and push rules tolerate it, but the content is redundant and differs from what Matrix clients send.",
          "title": "Same user mentioned twice is listed twice in m.mentions",
          "severity": "nit"
        },
        {
          "fix": "Require a non-username char or end of string after the capture, e.g. `(?:^|[^\\w@/])(@[\\w-]{3,20})(?:[^\\w-]|$)` (Go RE2 has no lookahead, so read only the submatch indices, which the code already does). Alternatively, check in code that `body[end]` is not `[\\w-]`.",
          "line": 14,
          "path": "pkg/connector/mentions.go",
          "issue": "`(@[\\w-]{3,20})` has no trailing boundary. For a token like `@some_user_name_that_is_long`, the regex captures the first 20 chars. If a room member's name equals that prefix, that part gets linked and the member is pinged, and the rest of the token is left as plain text after the link. Reddit usernames max out at 20 chars, so a longer token is never a real mention.",
          "title": "Usernames longer than 20 chars can be linked by their prefix",
          "severity": "nit"
        }
      ]
    }

Comment thread pkg/connector/mentions.go
}
target := beeperMXID(redditMXID)
formatted.WriteString(plainToHTML(body[last:start]))
_, _ = fmt.Fprintf(&formatted, `<a href="%s">%s</a>`, target.URI().MatrixToURL(), html.EscapeString(body[start:end]))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚪️ Nit · Same user mentioned twice is listed twice in m.mentions

target is appended to mentioned on every match, so "@other ping @other" yields the same MXID twice in m.mentions.user_ids. Dedupe with a seen set but keep linking every occurrence in the HTML.

Found by Indent Review Agent

Comment thread pkg/connector/mentions.go
"maunium.net/go/mautrix/id"
)

var mentionPattern = regexp.MustCompile(`(?:^|[^\w@/])(@[\w-]{3,20})`)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚪️ Nit · Usernames longer than 20 chars can be linked by their prefix

(@[\w-]{3,20}) has no trailing boundary. For @some_user_name_that_is_long the first 20 chars are captured, and if a member's name equals that prefix they get linked and pinged while the rest of the token stays plain text. Reddit usernames max out at 20 chars, so a longer token is never a real mention. Require a non-username char or end of string after the capture.

Found by Indent Review Agent

@Fizzadar

Copy link
Copy Markdown
Contributor Author

Live-tested at this head (b944020, build 7990356): mentions picked in reddit.com/chat's composer arrive with an HTML pill and m.mentions (a tester mention → their ghost, a mention of the logged-in user → their own Beeper MXID), bodies unchanged; a plain message and an @ that isn't a member stay plain. On main the same messages arrived as plain text with empty m.mentions.

@Fizzadar
Fizzadar merged commit 62e8dec into main Oct 29, 2026
11 checks passed
@Fizzadar
Fizzadar deleted the nick/plat-39405-incoming-mentions branch October 29, 2026 16:48
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.

1 participant