瀏覽代碼

Send portal notice on reactions

Closes #373
abmantis 3 年之前
父節點
當前提交
b652281682
共有 4 個文件被更改,包括 43 次插入0 次删除
  1. 1 0
      config/bridge.go
  2. 3 0
      example-config.yaml
  3. 18 0
      matrix.go
  4. 21 0
      portal.go

+ 1 - 0
config/bridge.go

@@ -35,6 +35,7 @@ type BridgeConfig struct {
 	DeliveryReceipts    bool `yaml:"delivery_receipts"`
 	PortalMessageBuffer int  `yaml:"portal_message_buffer"`
 	CallStartNotices    bool `yaml:"call_start_notices"`
+	ReactionNotices     bool `yaml:"reaction_notices"`
 
 	HistorySync struct {
 		CreatePortals        bool  `yaml:"create_portals"`

+ 3 - 0
example-config.yaml

@@ -92,6 +92,9 @@ 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?
+    reaction_notices: true
+
     portal_message_buffer: 128
 
     # Settings for handling history sync payloads. These settings only apply right after login,

+ 18 - 0
matrix.go

@@ -50,6 +50,7 @@ func NewMatrixHandler(bridge *Bridge) *MatrixHandler {
 	bridge.EventProcessor.On(event.EventMessage, handler.HandleMessage)
 	bridge.EventProcessor.On(event.EventEncrypted, handler.HandleEncrypted)
 	bridge.EventProcessor.On(event.EventSticker, handler.HandleMessage)
+	bridge.EventProcessor.On(event.EventReaction, handler.HandleReaction)
 	bridge.EventProcessor.On(event.EventRedaction, handler.HandleRedaction)
 	bridge.EventProcessor.On(event.StateMember, handler.HandleMembership)
 	bridge.EventProcessor.On(event.StateRoomName, handler.HandleRoomMetadata)
@@ -428,6 +429,23 @@ func (mx *MatrixHandler) HandleMessage(evt *event.Event) {
 	}
 }
 
+func (mx *MatrixHandler) HandleReaction(evt *event.Event) {
+	defer mx.bridge.Metrics.TrackMatrixEvent(evt.Type)()
+	if mx.shouldIgnoreEvent(evt) {
+		return
+	}
+
+	user := mx.bridge.GetUserByMXID(evt.Sender)
+	if user == nil {
+		return
+	}
+
+	portal := mx.bridge.GetPortalByMXID(evt.RoomID)
+	if portal != nil && (user.Whitelisted || portal.HasRelaybot()) {
+		portal.HandleMatrixReaction(user, evt)
+	}
+}
+
 func (mx *MatrixHandler) HandleRedaction(evt *event.Event) {
 	defer mx.bridge.Metrics.TrackMatrixEvent(evt.Type)()
 

+ 21 - 0
portal.go

@@ -2113,6 +2113,27 @@ 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