浏览代码

Add constant for double puppet value

Tulir Asokan 3 年之前
父节点
当前提交
5e2b54f97e
共有 4 个文件被更改,包括 8 次插入7 次删除
  1. 1 1
      historysync.go
  2. 1 1
      matrix.go
  3. 4 3
      portal.go
  4. 2 2
      user.go

+ 1 - 1
historysync.go

@@ -518,7 +518,7 @@ func (portal *Portal) wrapBatchEvent(info *types.MessageInfo, intent *appservice
 	}
 	}
 	extraContent[backfillIDField] = info.ID
 	extraContent[backfillIDField] = info.ID
 	if intent.IsCustomPuppet {
 	if intent.IsCustomPuppet {
-		extraContent[doublePuppetKey] = "whatsapp"
+		extraContent[doublePuppetKey] = doublePuppetValue
 	}
 	}
 	wrappedContent := event.Content{
 	wrappedContent := event.Content{
 		Parsed: content,
 		Parsed: content,

+ 1 - 1
matrix.go

@@ -522,7 +522,7 @@ func (mx *MatrixHandler) HandleReceipt(evt *event.Event) {
 			} else if customPuppet := mx.bridge.GetPuppetByCustomMXID(user.MXID); customPuppet != nil && !customPuppet.EnableReceipts {
 			} else if customPuppet := mx.bridge.GetPuppetByCustomMXID(user.MXID); customPuppet != nil && !customPuppet.EnableReceipts {
 				// TODO move this flag to the user and/or portal data
 				// TODO move this flag to the user and/or portal data
 				continue
 				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.
 				// Ignore double puppeted read receipts.
 				user.log.Debugfln("Ignoring double puppeted read receipt %+v", evt.Content.Raw)
 				user.log.Debugfln("Ignoring double puppeted read receipt %+v", evt.Content.Raw)
 			} else {
 			} else {

+ 4 - 3
portal.go

@@ -1270,6 +1270,7 @@ func (portal *Portal) encrypt(content *event.Content, eventType event.Type) (eve
 }
 }
 
 
 const doublePuppetKey = "fi.mau.double_puppet_source"
 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) {
 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}
 	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{}{}
 			wrappedContent.Raw = map[string]interface{}{}
 		}
 		}
 		if intent.IsCustomPuppet {
 		if intent.IsCustomPuppet {
-			wrappedContent.Raw[doublePuppetKey] = "whatsapp"
+			wrappedContent.Raw[doublePuppetKey] = doublePuppetValue
 		}
 		}
 	}
 	}
 	var err error
 	var err error
@@ -1513,7 +1514,7 @@ func (portal *Portal) leaveWithPuppetMeta(intent *appservice.IntentAPI) (*mautri
 			Membership: event.MembershipLeave,
 			Membership: event.MembershipLeave,
 		},
 		},
 		Raw: map[string]interface{}{
 		Raw: map[string]interface{}{
-			doublePuppetKey: "whatsapp",
+			doublePuppetKey: doublePuppetValue,
 		},
 		},
 	}
 	}
 	// Bypass IntentAPI, we don't want to EnsureJoined here
 	// 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(),
 				AvatarURL:   puppet.AvatarURL.CUString(),
 			},
 			},
 			Raw: map[string]interface{}{
 			Raw: map[string]interface{}{
-				doublePuppetKey: "whatsapp",
+				doublePuppetKey: doublePuppetValue,
 			},
 			},
 		}
 		}
 		resp, err := intent.SendStateEvent(portal.MXID, event.StateMember, puppet.MXID.String(), &content)
 		resp, err := intent.SendStateEvent(portal.MXID, event.StateMember, puppet.MXID.String(), &content)

+ 2 - 2
user.go

@@ -552,9 +552,9 @@ func (user *User) updateChatTag(intent *appservice.IntentAPI, portal *Portal, ta
 	currentTag, ok := existingTags.Tags[tag]
 	currentTag, ok := existingTags.Tags[tag]
 	if active && !ok {
 	if active && !ok {
 		user.log.Debugln("Adding tag", tag, "to", portal.MXID)
 		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)
 		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)
 		user.log.Debugln("Removing tag", tag, "from", portal.MXID)
 		err = intent.RemoveTag(portal.MXID, tag)
 		err = intent.RemoveTag(portal.MXID, tag)
 	} else {
 	} else {