From 2f5b3fcbfb8cef14776940d38e55b2c4c46d31af Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Mon, 15 Jul 2024 19:26:09 +0300 Subject: [PATCH] Don't use mxid in mention pills --- formatter_tag.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/formatter_tag.go b/formatter_tag.go index ff76600..fb7f741 100644 --- a/formatter_tag.go +++ b/formatter_tag.go @@ -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" ) @@ -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, `%s`, user.MXID.URI().MatrixToURL(), user.MXID) - } else if puppet := node.portal.bridge.GetPuppetByID(strconv.FormatInt(node.id, 10)); puppet != nil { - _, _ = fmt.Fprintf(w, `%s`, puppet.MXID.URI().MatrixToURL(), puppet.Name) + mxid = user.MXID + if name == "" { + name = user.MXID.Localpart() + } } + _, _ = fmt.Fprintf(w, `%s`, mxid.URI().MatrixToURL(), name) return case *astDiscordRoleMention: role := node.portal.bridge.DB.Role.GetByID(node.portal.GuildID, strconv.FormatInt(node.id, 10))