Send portal notice on reactions

Closes #373
This commit is contained in:
abmantis 2021-11-09 15:12:03 +02:00 committed by Tulir Asokan
parent 53eac40711
commit b652281682
4 changed files with 43 additions and 0 deletions

View file

@ -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"`

View file

@ -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,

View file

@ -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)()

View file

@ -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