From 445da09e1d7e1994cb99ed545ea6cad39bafb7f4 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Tue, 9 Nov 2021 15:17:23 +0200 Subject: [PATCH] Simplify reaction error notices --- config/upgrade.go | 1 + example-config.yaml | 2 +- matrix.go | 9 ++++++--- portal.go | 21 --------------------- 4 files changed, 8 insertions(+), 25 deletions(-) diff --git a/config/upgrade.go b/config/upgrade.go index 4fd7789..45b3124 100644 --- a/config/upgrade.go +++ b/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") diff --git a/example-config.yaml b/example-config.yaml index a88be4a..632f82b 100644 --- a/example-config.yaml +++ b/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 diff --git a/matrix.go b/matrix.go index ee0424e..981fa30 100644 --- a/matrix.go +++ b/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."), + }) } } diff --git a/portal.go b/portal.go index f851974..d76b4f3 100644 --- a/portal.go +++ b/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