Skip to content

Commit

Permalink
Ignore old messages even if their ID is higher than new ones
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Apr 8, 2024
1 parent b131f50 commit 2a3acbf
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions portal.go
Original file line number Diff line number Diff line change
Expand Up @@ -754,12 +754,22 @@ func (portal *Portal) handleMessage(source *User, evt *gmproto.Message, raw []by
log.Debug().Msg("Not handling incoming auto-downloading MMS")
return
}
if eventTS.Add(24 * time.Hour).Before(time.Now()) {
if time.Since(eventTS) > 24*time.Hour {
lastMessage, err := portal.bridge.DB.Message.GetLastInChat(ctx, portal.Key)
if err != nil {
log.Warn().Err(err).Msg("Failed to get last message to check if received old message is too old")
} else if lastMessage != nil && lastMessage.Timestamp.After(eventTS) && idToInt(lastMessage.ID) > idToInt(evt.MessageID) {
log.Debug().Msg("Not handling old message")
} else if lastMessage != nil && lastMessage.Timestamp.After(eventTS) {
if idToInt(lastMessage.ID) > idToInt(evt.MessageID) {
log.Warn().
Str("last_message_id", lastMessage.ID).
Time("last_message_ts", lastMessage.Timestamp).
Msg("Not handling old message even though it has higher ID than last new one")
} else {
log.Debug().
Str("last_message_id", lastMessage.ID).
Time("last_message_ts", lastMessage.Timestamp).
Msg("Not handling old message")
}
return
}
}
Expand Down

0 comments on commit 2a3acbf

Please sign in to comment.