Implement reactions from the matrix side

This commit is contained in:
Gary Kramlich
2022-02-06 22:20:13 -06:00
parent 312018173f
commit 3efe242d70
2 changed files with 35 additions and 0 deletions

View File

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