From 53e992c25dc5bf1f970188fb2eb27a8b7a1343be Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Mon, 4 Sep 2023 11:33:03 +0300 Subject: [PATCH] Fix handling updates to multipart messages --- portal.go | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/portal.go b/portal.go index 1e0a4fe..ddd3c70 100644 --- a/portal.go +++ b/portal.go @@ -507,15 +507,9 @@ func (portal *Portal) handleExistingMessageUpdate(ctx context.Context, source *U if chatIDChanged { isEdit = false } else if i == 0 { - part.Content.SetEdit(dbMsg.MXID) - part.Extra = map[string]any{ - "m.new_content": part.Extra, - } + part.SetEdit(dbMsg.MXID) } else if existingPart, ok := dbMsg.Status.MediaParts[part.ID]; ok { - part.Content.SetEdit(existingPart.EventID) - part.Extra = map[string]any{ - "m.new_content": part.Extra, - } + part.SetEdit(existingPart.EventID) } else { ts = converted.Timestamp.UnixMilli() isEdit = false @@ -790,6 +784,15 @@ type ConvertedMessagePart struct { Extra map[string]any } +func (cmp *ConvertedMessagePart) SetEdit(eventID id.EventID) { + cmp.Content.SetEdit(eventID) + if cmp.Extra != nil { + cmp.Extra = map[string]any{ + "m.new_content": cmp.Extra, + } + } +} + type ConvertedMessage struct { ID string SenderID string