forked from MirrorHub/mautrix-whatsapp
double puppeting: use fi.mau.double_puppet_source
This commit is contained in:
parent
e38b0bf545
commit
c15b963748
4 changed files with 12 additions and 11 deletions
|
@ -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] = "whatsapp"
|
||||
}
|
||||
wrappedContent := event.Content{
|
||||
Parsed: content,
|
||||
|
|
|
@ -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)
|
||||
|
|
10
portal.go
10
portal.go
|
@ -1269,7 +1269,7 @@ 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"
|
||||
|
||||
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 +1277,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] = "whatsapp"
|
||||
}
|
||||
}
|
||||
var err error
|
||||
eventType, err = portal.encrypt(&wrappedContent, eventType)
|
||||
|
@ -1511,7 +1513,7 @@ func (portal *Portal) leaveWithPuppetMeta(intent *appservice.IntentAPI) (*mautri
|
|||
Membership: event.MembershipLeave,
|
||||
},
|
||||
Raw: map[string]interface{}{
|
||||
doublePuppetField: true,
|
||||
doublePuppetKey: "whatsapp",
|
||||
},
|
||||
}
|
||||
// Bypass IntentAPI, we don't want to EnsureJoined here
|
||||
|
@ -1534,7 +1536,7 @@ func (portal *Portal) HandleWhatsAppInvite(source *User, senderJID *types.JID, j
|
|||
AvatarURL: puppet.AvatarURL.CUString(),
|
||||
},
|
||||
Raw: map[string]interface{}{
|
||||
doublePuppetField: true,
|
||||
doublePuppetKey: "whatsapp",
|
||||
},
|
||||
}
|
||||
resp, err := intent.SendStateEvent(portal.MXID, event.StateMember, puppet.MXID.String(), &content)
|
||||
|
|
8
user.go
8
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", "whatsapp"}
|
||||
err = intent.AddTagWithCustomData(portal.MXID, tag, &data)
|
||||
} else if !active && ok && currentTag.DoublePuppet {
|
||||
} else if !active && ok && currentTag.DoublePuppet == "whatsapp" {
|
||||
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) {
|
||||
|
|
Loading…
Reference in a new issue