Skip to content

Commit

Permalink
Don't use mxid in mention pills
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Jul 15, 2024
1 parent 035f2a4 commit 2f5b3fc
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions formatter_tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/yuin/goldmark/renderer"
"github.com/yuin/goldmark/text"
"github.com/yuin/goldmark/util"
"maunium.net/go/mautrix/id"

"go.mau.fi/mautrix-discord/database"
)
Expand Down Expand Up @@ -262,11 +263,19 @@ func (r *discordTagHTMLRenderer) renderDiscordMention(w util.BufWriter, source [
}
switch node := n.(type) {
case *astDiscordUserMention:
var mxid id.UserID
var name string
if puppet := node.portal.bridge.GetPuppetByID(strconv.FormatInt(node.id, 10)); puppet != nil {
mxid = puppet.MXID
name = puppet.Name
}
if user := node.portal.bridge.GetUserByID(strconv.FormatInt(node.id, 10)); user != nil {
_, _ = fmt.Fprintf(w, `<a href="%s">%s</a>`, user.MXID.URI().MatrixToURL(), user.MXID)
} else if puppet := node.portal.bridge.GetPuppetByID(strconv.FormatInt(node.id, 10)); puppet != nil {
_, _ = fmt.Fprintf(w, `<a href="%s">%s</a>`, puppet.MXID.URI().MatrixToURL(), puppet.Name)
mxid = user.MXID
if name == "" {
name = user.MXID.Localpart()
}
}
_, _ = fmt.Fprintf(w, `<a href="%s">%s</a>`, mxid.URI().MatrixToURL(), name)
return
case *astDiscordRoleMention:
role := node.portal.bridge.DB.Role.GetByID(node.portal.GuildID, strconv.FormatInt(node.id, 10))
Expand Down

0 comments on commit 2f5b3fc

Please sign in to comment.