mirror of
https://github.com/tulir/mautrix-whatsapp
synced 2025-03-05 00:40:18 +01:00
Add constant for double puppet value
This commit is contained in:
parent
c15b963748
commit
5e2b54f97e
4 changed files with 8 additions and 7 deletions
|
@ -518,7 +518,7 @@ func (portal *Portal) wrapBatchEvent(info *types.MessageInfo, intent *appservice
|
|||
}
|
||||
extraContent[backfillIDField] = info.ID
|
||||
if intent.IsCustomPuppet {
|
||||
extraContent[doublePuppetKey] = "whatsapp"
|
||||
extraContent[doublePuppetKey] = doublePuppetValue
|
||||
}
|
||||
wrappedContent := event.Content{
|
||||
Parsed: content,
|
||||
|
|
|
@ -522,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 {
|
||||
|
|
|
@ -1270,6 +1270,7 @@ func (portal *Portal) encrypt(content *event.Content, eventType event.Type) (eve
|
|||
}
|
||||
|
||||
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}
|
||||
|
@ -1278,7 +1279,7 @@ func (portal *Portal) sendMessage(intent *appservice.IntentAPI, eventType event.
|
|||
wrappedContent.Raw = map[string]interface{}{}
|
||||
}
|
||||
if intent.IsCustomPuppet {
|
||||
wrappedContent.Raw[doublePuppetKey] = "whatsapp"
|
||||
wrappedContent.Raw[doublePuppetKey] = doublePuppetValue
|
||||
}
|
||||
}
|
||||
var err error
|
||||
|
@ -1513,7 +1514,7 @@ func (portal *Portal) leaveWithPuppetMeta(intent *appservice.IntentAPI) (*mautri
|
|||
Membership: event.MembershipLeave,
|
||||
},
|
||||
Raw: map[string]interface{}{
|
||||
doublePuppetKey: "whatsapp",
|
||||
doublePuppetKey: doublePuppetValue,
|
||||
},
|
||||
}
|
||||
// Bypass IntentAPI, we don't want to EnsureJoined here
|
||||
|
@ -1536,7 +1537,7 @@ func (portal *Portal) HandleWhatsAppInvite(source *User, senderJID *types.JID, j
|
|||
AvatarURL: puppet.AvatarURL.CUString(),
|
||||
},
|
||||
Raw: map[string]interface{}{
|
||||
doublePuppetKey: "whatsapp",
|
||||
doublePuppetKey: doublePuppetValue,
|
||||
},
|
||||
}
|
||||
resp, err := intent.SendStateEvent(portal.MXID, event.StateMember, puppet.MXID.String(), &content)
|
||||
|
|
4
user.go
4
user.go
|
@ -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", "whatsapp"}
|
||||
data := CustomTagData{"0.5", doublePuppetValue}
|
||||
err = intent.AddTagWithCustomData(portal.MXID, tag, &data)
|
||||
} else if !active && ok && currentTag.DoublePuppet == "whatsapp" {
|
||||
} else if !active && ok && currentTag.DoublePuppet == doublePuppetValue {
|
||||
user.log.Debugln("Removing tag", tag, "from", portal.MXID)
|
||||
err = intent.RemoveTag(portal.MXID, tag)
|
||||
} else {
|
||||
|
|
Loading…
Add table
Reference in a new issue