mirror of
https://github.com/tulir/mautrix-whatsapp
synced 2024-11-10 20:11:39 +01:00
Get displayname when converting mentions of Matrix users. Fixes #338
This commit is contained in:
parent
cf1ae3b102
commit
e215850fcf
3 changed files with 14 additions and 9 deletions
|
@ -6,6 +6,7 @@
|
|||
* Added initial support for re-fetching old media from phone.
|
||||
* Added support for bridging audio message waveforms in both directions.
|
||||
* Added support for sending URL previews to WhatsApp (both custom and autogenerated).
|
||||
* Updated formatter to get Matrix user displayname when converting WhatsApp mentions.
|
||||
* Fixed some issues with read receipt bridging
|
||||
* Fixed `!wa open` not working with new-style group IDs.
|
||||
* Fixed panic in disappearing message handling code if a portal is deleted with
|
||||
|
|
|
@ -93,18 +93,22 @@ func NewFormatter(bridge *Bridge) *Formatter {
|
|||
return formatter
|
||||
}
|
||||
|
||||
func (formatter *Formatter) getMatrixInfoByJID(jid types.JID) (mxid id.UserID, displayname string) {
|
||||
if user := formatter.bridge.GetUserByJID(jid); user != nil {
|
||||
mxid = user.MXID
|
||||
displayname = string(user.MXID)
|
||||
} else if puppet := formatter.bridge.GetPuppetByJID(jid); puppet != nil {
|
||||
func (formatter *Formatter) getMatrixInfoByJID(roomID id.RoomID, jid types.JID) (mxid id.UserID, displayname string) {
|
||||
if puppet := formatter.bridge.GetPuppetByJID(jid); puppet != nil {
|
||||
mxid = puppet.MXID
|
||||
displayname = puppet.Displayname
|
||||
}
|
||||
if user := formatter.bridge.GetUserByJID(jid); user != nil {
|
||||
mxid = user.MXID
|
||||
member := formatter.bridge.StateStore.GetMember(roomID, user.MXID)
|
||||
if len(member.Displayname) > 0 {
|
||||
displayname = member.Displayname
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (formatter *Formatter) ParseWhatsApp(content *event.MessageEventContent, mentionedJIDs []string) {
|
||||
func (formatter *Formatter) ParseWhatsApp(roomID id.RoomID, content *event.MessageEventContent, mentionedJIDs []string) {
|
||||
output := html.EscapeString(content.Body)
|
||||
for regex, replacement := range formatter.waReplString {
|
||||
output = regex.ReplaceAllString(output, replacement)
|
||||
|
@ -119,7 +123,7 @@ func (formatter *Formatter) ParseWhatsApp(content *event.MessageEventContent, me
|
|||
} else if jid.Server == types.LegacyUserServer {
|
||||
jid.Server = types.DefaultUserServer
|
||||
}
|
||||
mxid, displayname := formatter.getMatrixInfoByJID(jid)
|
||||
mxid, displayname := formatter.getMatrixInfoByJID(roomID, jid)
|
||||
number := "@" + jid.User
|
||||
output = strings.ReplaceAll(output, number, fmt.Sprintf(`<a href="https://matrix.to/#/%s">%s</a>`, mxid, displayname))
|
||||
content.Body = strings.ReplaceAll(content.Body, number, displayname)
|
||||
|
|
|
@ -1517,7 +1517,7 @@ func (portal *Portal) convertTextMessage(intent *appservice.IntentAPI, source *U
|
|||
}
|
||||
|
||||
contextInfo := msg.GetExtendedTextMessage().GetContextInfo()
|
||||
portal.bridge.Formatter.ParseWhatsApp(content, contextInfo.GetMentionedJid())
|
||||
portal.bridge.Formatter.ParseWhatsApp(portal.MXID, content, contextInfo.GetMentionedJid())
|
||||
replyTo := contextInfo.GetStanzaId()
|
||||
expiresIn := contextInfo.GetExpiration()
|
||||
extraAttrs := map[string]interface{}{}
|
||||
|
@ -2002,7 +2002,7 @@ func (portal *Portal) convertMediaMessageContent(intent *appservice.IntentAPI, m
|
|||
MsgType: event.MsgNotice,
|
||||
}
|
||||
|
||||
portal.bridge.Formatter.ParseWhatsApp(captionContent, msg.GetContextInfo().GetMentionedJid())
|
||||
portal.bridge.Formatter.ParseWhatsApp(portal.MXID, captionContent, msg.GetContextInfo().GetMentionedJid())
|
||||
}
|
||||
|
||||
return &ConvertedMessage{
|
||||
|
|
Loading…
Reference in a new issue