Skip to content

Commit

Permalink
Update message timestamp when editing
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Jan 2, 2024
1 parent 470f59d commit 67077b4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
7 changes: 7 additions & 0 deletions database/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ const (
DELETE FROM message
WHERE sender=$1 AND timestamp=$2 AND part_index=$3 AND signal_receiver=$4
`
updateMessageTimestampQuery = `
UPDATE message SET timestamp=$4 WHERE sender=$1 AND timestamp=$2 AND signal_receiver=$3
`
)

type MessageQuery struct {
Expand Down Expand Up @@ -161,3 +164,7 @@ func (msg *Message) Insert(ctx context.Context) error {
func (msg *Message) Delete(ctx context.Context) error {
return msg.qh.Exec(ctx, deleteMessageQuery, msg.Sender, msg.Timestamp, msg.PartIndex, msg.SignalReceiver)
}

func (msg *Message) SetTimestamp(ctx context.Context, editTime uint64) error {
return msg.qh.Exec(ctx, updateMessageTimestampQuery, msg.Sender, msg.Timestamp, msg.SignalReceiver, editTime)
}
7 changes: 6 additions & 1 deletion portal.go
Original file line number Diff line number Diff line change
Expand Up @@ -1242,6 +1242,7 @@ func (portal *Portal) handleSignalEditMessage(sender *Puppet, timestamp uint64,
Str("action", "handle signal edit").
Str("sender_uuid", sender.SignalID.String()).
Uint64("target_msg_ts", timestamp).
Uint64("edit_msg_ts", msg.GetTimestamp()).
Logger()
if portal.MXID == "" {
log.Debug().Msg("Dropping edit message in chat with no portal")
Expand All @@ -1253,7 +1254,7 @@ func (portal *Portal) handleSignalEditMessage(sender *Puppet, timestamp uint64,
log.Err(err).Msg("Failed to get target message")
return
} else if len(targetMessage) == 0 {
log.Warn().Msg("Target message not found")
log.Debug().Msg("Target message not found (edit may have been already handled)")
return
}

Expand Down Expand Up @@ -1282,6 +1283,10 @@ func (portal *Portal) handleSignalEditMessage(sender *Puppet, timestamp uint64,
log.Err(err).Int("part_index", i).Msg("Failed to send edit to Matrix")
}
}
err = targetMessage[0].SetTimestamp(ctx, msg.GetTimestamp())
if err != nil {
log.Err(err).Msg("Failed to update message edit timestamp in database")
}
}

const SignalTypingTimeout = 15 * time.Second
Expand Down

0 comments on commit 67077b4

Please sign in to comment.