Ignore old messages even if their ID is higher than new ones

This commit is contained in:
Tulir Asokan 2024-04-08 15:21:08 +03:00
parent b131f50e51
commit 2a3acbff1b

View file

@ -754,12 +754,22 @@ func (portal *Portal) handleMessage(source *User, evt *gmproto.Message, raw []by
log.Debug().Msg("Not handling incoming auto-downloading MMS") log.Debug().Msg("Not handling incoming auto-downloading MMS")
return 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) lastMessage, err := portal.bridge.DB.Message.GetLastInChat(ctx, portal.Key)
if err != nil { if err != nil {
log.Warn().Err(err).Msg("Failed to get last message to check if received old message is too old") 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) { } else if lastMessage != nil && lastMessage.Timestamp.After(eventTS) {
log.Debug().Msg("Not handling old message") 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 return
} }
} }