diff --git a/bridge/matrix.go b/bridge/matrix.go index b99f5ad..6c09bba 100644 --- a/bridge/matrix.go +++ b/bridge/matrix.go @@ -29,6 +29,7 @@ func (b *Bridge) setupEvents() { } b.eventProcessor.On(event.EventMessage, b.matrixHandler.handleMessage) + b.eventProcessor.On(event.EventReaction, b.matrixHandler.handleReaction) b.eventProcessor.On(event.StateMember, b.matrixHandler.handleMembership) } @@ -230,3 +231,14 @@ func (mh *matrixHandler) handleMembership(evt *event.Event) { portal.handleMatrixInvite(user, evt) } } + +func (mh *matrixHandler) handleReaction(evt *event.Event) { + if mh.ignoreEvent(evt) { + return + } + + portal := mh.bridge.GetPortalByMXID(evt.RoomID) + if portal != nil { + portal.handleMatrixReaction(evt) + } +} diff --git a/bridge/portal.go b/bridge/portal.go index 9328cd4..fad5b99 100644 --- a/bridge/portal.go +++ b/bridge/portal.go @@ -367,6 +367,8 @@ func (p *Portal) handleMatrixMessages(msg portalMatrixMessage) { switch msg.evt.Type { case event.EventMessage: p.handleMatrixMessage(msg.user, msg.evt) + default: + p.log.Debugln("unknown event type", msg.evt.Type) } } @@ -514,3 +516,24 @@ func (p *Portal) handleMatrixKick(sender *User, target *Puppet) { // TODO: need to learn how to make this happen as discordgo proper doesn't // support group dms and it looks like it's a binary blob. } + +func (p *Portal) handleMatrixReaction(evt *event.Event) { + reaction := evt.Content.AsReaction() + if reaction.RelatesTo.Type != event.RelAnnotation { + p.log.Errorfln("Ignoring reaction %s due to unknown m.relates_to data", evt.ID) + + return + } + + msg := p.bridge.db.Message.GetByMatrixID(p.Key, reaction.RelatesTo.EventID) + if msg.DiscordID == "" { + p.log.Debugf("Message %s has not yet been sent to discord", reaction.RelatesTo.EventID) + + return + } + + user := p.bridge.GetUserByMXID(evt.Sender) + if user != nil { + user.Session.MessageReactionAdd(p.Key.ChannelID, msg.DiscordID, reaction.RelatesTo.Key) + } +}