diff --git a/historysync.go b/historysync.go index 7a43655..6f84daf 100644 --- a/historysync.go +++ b/historysync.go @@ -518,7 +518,7 @@ func (portal *Portal) wrapBatchEvent(info *types.MessageInfo, intent *appservice } extraContent[backfillIDField] = info.ID if intent.IsCustomPuppet { - extraContent[doublePuppetField] = intent.IsCustomPuppet + extraContent[doublePuppetKey] = doublePuppetValue } wrappedContent := event.Content{ Parsed: content, diff --git a/matrix.go b/matrix.go index d695f77..c86b9a3 100644 --- a/matrix.go +++ b/matrix.go @@ -320,8 +320,7 @@ func (mx *MatrixHandler) shouldIgnoreEvent(evt *event.Event) bool { if _, isPuppet := mx.bridge.ParsePuppetMXID(evt.Sender); evt.Sender == mx.bridge.Bot.UserID || isPuppet { return true } - isCustomPuppet, ok := evt.Content.Raw[doublePuppetField].(bool) - if ok && isCustomPuppet && mx.bridge.GetPuppetByCustomMXID(evt.Sender) != nil { + if _, ok := evt.Content.Raw[doublePuppetKey]; ok && mx.bridge.GetPuppetByCustomMXID(evt.Sender) != nil { return true } user := mx.bridge.GetUserByMXID(evt.Sender) @@ -523,7 +522,7 @@ func (mx *MatrixHandler) HandleReceipt(evt *event.Event) { } else if customPuppet := mx.bridge.GetPuppetByCustomMXID(user.MXID); customPuppet != nil && !customPuppet.EnableReceipts { // TODO move this flag to the user and/or portal data continue - } else if isDoublePuppeted, _ := receipt.Extra[doublePuppetField].(bool); isDoublePuppeted { + } else if val, ok := receipt.Extra[doublePuppetKey].(string); ok && customPuppet != nil && val == doublePuppetValue { // Ignore double puppeted read receipts. user.log.Debugfln("Ignoring double puppeted read receipt %+v", evt.Content.Raw) } else { diff --git a/portal.go b/portal.go index 1df2d4e..212cf66 100644 --- a/portal.go +++ b/portal.go @@ -1269,7 +1269,8 @@ func (portal *Portal) encrypt(content *event.Content, eventType event.Type) (eve return eventType, nil } -const doublePuppetField = "net.maunium.whatsapp.puppet" +const doublePuppetKey = "fi.mau.double_puppet_source" +const doublePuppetValue = "mautrix-whatsapp" func (portal *Portal) sendMessage(intent *appservice.IntentAPI, eventType event.Type, content *event.MessageEventContent, extraContent map[string]interface{}, timestamp int64) (*mautrix.RespSendEvent, error) { wrappedContent := event.Content{Parsed: content, Raw: extraContent} @@ -1277,7 +1278,9 @@ func (portal *Portal) sendMessage(intent *appservice.IntentAPI, eventType event. if wrappedContent.Raw == nil { wrappedContent.Raw = map[string]interface{}{} } - wrappedContent.Raw[doublePuppetField] = intent.IsCustomPuppet + if intent.IsCustomPuppet { + wrappedContent.Raw[doublePuppetKey] = doublePuppetValue + } } var err error eventType, err = portal.encrypt(&wrappedContent, eventType) @@ -1511,7 +1514,7 @@ func (portal *Portal) leaveWithPuppetMeta(intent *appservice.IntentAPI) (*mautri Membership: event.MembershipLeave, }, Raw: map[string]interface{}{ - doublePuppetField: true, + doublePuppetKey: doublePuppetValue, }, } // Bypass IntentAPI, we don't want to EnsureJoined here @@ -1534,7 +1537,7 @@ func (portal *Portal) HandleWhatsAppInvite(source *User, senderJID *types.JID, j AvatarURL: puppet.AvatarURL.CUString(), }, Raw: map[string]interface{}{ - doublePuppetField: true, + doublePuppetKey: doublePuppetValue, }, } resp, err := intent.SendStateEvent(portal.MXID, event.StateMember, puppet.MXID.String(), &content) diff --git a/user.go b/user.go index eeb759d..7e067e7 100644 --- a/user.go +++ b/user.go @@ -527,7 +527,7 @@ func (user *User) updateChatMute(intent *appservice.IntentAPI, portal *Portal, m type CustomTagData struct { Order json.Number `json:"order"` - DoublePuppet bool `json:"net.maunium.whatsapp.puppet"` + DoublePuppet string `json:"fi.mau.double_puppet_source"` } type CustomTagEventContent struct { @@ -552,9 +552,9 @@ func (user *User) updateChatTag(intent *appservice.IntentAPI, portal *Portal, ta currentTag, ok := existingTags.Tags[tag] if active && !ok { user.log.Debugln("Adding tag", tag, "to", portal.MXID) - data := CustomTagData{"0.5", true} + data := CustomTagData{"0.5", doublePuppetValue} err = intent.AddTagWithCustomData(portal.MXID, tag, &data) - } else if !active && ok && currentTag.DoublePuppet { + } else if !active && ok && currentTag.DoublePuppet == doublePuppetValue { user.log.Debugln("Removing tag", tag, "from", portal.MXID) err = intent.RemoveTag(portal.MXID, tag) } else { @@ -567,7 +567,7 @@ func (user *User) updateChatTag(intent *appservice.IntentAPI, portal *Portal, ta type CustomReadReceipt struct { Timestamp int64 `json:"ts,omitempty"` - DoublePuppet bool `json:"net.maunium.whatsapp.puppet,omitempty"` + DoublePuppet bool `json:"fi.mau.double_puppet_source,omitempty"` } func (user *User) syncChatDoublePuppetDetails(portal *Portal, justCreated bool) {