Implement message editing from the matrix side

This commit is contained in:
Gary Kramlich
2022-02-10 16:09:54 -06:00
parent b6ee5bccc6
commit 11bd655027

View File

@@ -413,6 +413,21 @@ func (p *Portal) handleMatrixMessage(sender *User, evt *event.Event) {
return return
} }
if content.RelatesTo != nil && content.RelatesTo.Type == event.RelReplace {
existing := p.bridge.db.Message.GetByMatrixID(p.Key, content.RelatesTo.EventID)
if existing != nil && existing.DiscordID != "" {
// we don't have anything to save for the update message right now
// as we're not tracking edited timestamps.
_, err := sender.Session.ChannelMessageEdit(p.Key.ChannelID,
existing.DiscordID, content.NewContent.Body)
if err != nil {
p.log.Errorln("Failed to update message %s: %v", existing.DiscordID, err)
return
}
}
} else {
msg, err := sender.Session.ChannelMessageSend(p.Key.ChannelID, content.Body) msg, err := sender.Session.ChannelMessageSend(p.Key.ChannelID, content.Body)
if err != nil { if err != nil {
p.log.Errorfln("Failed to send message: %v", err) p.log.Errorfln("Failed to send message: %v", err)
@@ -427,6 +442,7 @@ func (p *Portal) handleMatrixMessage(sender *User, evt *event.Event) {
dbMsg.AuthorID = sender.ID dbMsg.AuthorID = sender.ID
dbMsg.Timestamp = time.Now() dbMsg.Timestamp = time.Now()
dbMsg.Insert() dbMsg.Insert()
}
} }
func (p *Portal) handleMatrixLeave(sender *User) { func (p *Portal) handleMatrixLeave(sender *User) {