Skip to content

Commit

Permalink
bridgev2/portal: re-id outgoing reactions too
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Oct 22, 2024
1 parent 8a81631 commit 9b82442
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions bridgev2/portal.go
Original file line number Diff line number Diff line change
Expand Up @@ -1143,14 +1143,18 @@ func (portal *Portal) handleMatrixReaction(ctx context.Context, sender *UserLogi
portal.sendErrorStatus(ctx, evt, err)
return
}
var deterministicID id.EventID
if portal.Bridge.Config.OutgoingMessageReID {
deterministicID = portal.Bridge.Matrix.GenerateReactionEventID(portal.MXID, reactionTarget, preResp.SenderID, preResp.EmojiID)
}
existing, err := portal.Bridge.DB.Reaction.GetByID(ctx, reactionTarget.ID, reactionTarget.PartID, preResp.SenderID, preResp.EmojiID)
if err != nil {
log.Err(err).Msg("Failed to check if reaction is a duplicate")
return
} else if existing != nil {
if existing.EmojiID != "" || existing.Emoji == preResp.Emoji {
log.Debug().Msg("Ignoring duplicate reaction")
portal.sendSuccessStatus(ctx, evt, 0, "")
portal.sendSuccessStatus(ctx, evt, 0, deterministicID)
return
}
react.ReactionToOverride = existing
Expand Down Expand Up @@ -1209,7 +1213,9 @@ func (portal *Portal) handleMatrixReaction(ctx context.Context, sender *UserLogi
dbReaction.MessageID = reactionTarget.ID
dbReaction.MessagePartID = reactionTarget.PartID
}
if dbReaction.MXID == "" {
if deterministicID != "" {
dbReaction.MXID = deterministicID
} else if dbReaction.MXID == "" {
dbReaction.MXID = evt.ID
}
if dbReaction.Timestamp.IsZero() {
Expand All @@ -1232,7 +1238,7 @@ func (portal *Portal) handleMatrixReaction(ctx context.Context, sender *UserLogi
if err != nil {
log.Err(err).Msg("Failed to save reaction to database")
}
portal.sendSuccessStatus(ctx, evt, 0, "")
portal.sendSuccessStatus(ctx, evt, 0, deterministicID)
}

func handleMatrixRoomMeta[APIType any, ContentType any](
Expand Down

0 comments on commit 9b82442

Please sign in to comment.