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