瀏覽代碼

Simplify reaction error notices

Tulir Asokan 3 年之前
父節點
當前提交
445da09e1d
共有 4 個文件被更改,包括 8 次插入25 次删除
  1. 1 0
      config/upgrade.go
  2. 1 1
      example-config.yaml
  3. 6 3
      matrix.go
  4. 0 21
      portal.go

+ 1 - 0
config/upgrade.go

@@ -68,6 +68,7 @@ func (helper *UpgradeHelper) doUpgrade() {
 	helper.Copy(Bool, "bridge", "delivery_receipts")
 	helper.Copy(Int, "bridge", "portal_message_buffer")
 	helper.Copy(Bool, "bridge", "call_start_notices")
+	helper.Copy(Bool, "bridge", "reaction_notices")
 	helper.Copy(Bool, "bridge", "history_sync", "create_portals")
 	helper.Copy(Int, "bridge", "history_sync", "max_age")
 	helper.Copy(Bool, "bridge", "history_sync", "backfill")

+ 1 - 1
example-config.yaml

@@ -92,7 +92,7 @@ bridge:
     delivery_receipts: false
     # Should incoming calls send a message to the Matrix room?
     call_start_notices: true
-    # Since WhatsApp does not support reactions, should a warning notice be sent to the Matrix room when a user reacts to a message?
+    # Should a "reactions not yet supported" warning be sent to the Matrix room when a user reacts to a message?
     reaction_notices: true
 
     portal_message_buffer: 128

+ 6 - 3
matrix.go

@@ -436,13 +436,16 @@ func (mx *MatrixHandler) HandleReaction(evt *event.Event) {
 	}
 
 	user := mx.bridge.GetUserByMXID(evt.Sender)
-	if user == nil {
+	if user == nil || !user.RelayWhitelisted {
 		return
 	}
 
 	portal := mx.bridge.GetPortalByMXID(evt.RoomID)
-	if portal != nil && (user.Whitelisted || portal.HasRelaybot()) {
-		portal.HandleMatrixReaction(user, evt)
+	if portal != nil && (user.Whitelisted || portal.HasRelaybot()) && mx.bridge.Config.Bridge.ReactionNotices {
+		_, _ = portal.sendMainIntentMessage(&event.MessageEventContent{
+			MsgType: event.MsgNotice,
+			Body:    fmt.Sprintf("\u26a0 Reactions are not yet supported by WhatsApp."),
+		})
 	}
 }
 

+ 0 - 21
portal.go

@@ -2113,27 +2113,6 @@ func (portal *Portal) HandleMatrixMessage(sender *User, evt *event.Event) {
 	}
 }
 
-func (portal *Portal) HandleMatrixReaction(sender *User, evt *event.Event) {
-	if !portal.canBridgeFrom(sender, "message") {
-		return
-	}
-	portal.log.Debugfln("Received reaction event %s from %s", evt.ID, evt.Sender)
-
-	if evt.Type.Type != event.EventReaction.Type {
-		portal.log.Warnfln("Reaction event is not of Reaction type: %s", evt.Type.Type)
-	}
-
-	if portal.bridge.Config.Bridge.ReactionNotices {
-		_, err := portal.sendMainIntentMessage(&event.MessageEventContent{
-			MsgType: event.MsgNotice,
-			Body:    fmt.Sprintf("\u26a0 Reactions are not supported by WhatsApp."),
-		})
-		if err != nil {
-			portal.log.Warnfln("Failed to send reaction notice message:", err)
-		}
-	}
-}
-
 func (portal *Portal) HandleMatrixRedaction(sender *User, evt *event.Event) {
 	if !portal.canBridgeFrom(sender, "redaction") {
 		return