Fix some bugs in missed message and initial history filling

This commit is contained in:
Tulir Asokan
2019-05-22 23:05:58 +03:00
parent 4db9777b9a
commit 14f96bd96f
3 changed files with 48 additions and 14 deletions

View File

@ -120,6 +120,7 @@ func (bridge *Bridge) NewPortal(dbPortal *database.Portal) *Portal {
const recentlyHandledLength = 100
type PortalMessage struct {
chat string
source *User
data interface{}
timestamp uint64
@ -162,7 +163,9 @@ func (portal *Portal) handleMessageLoop() {
return
}
}
portal.backfillLock.Lock()
portal.handleMessage(msg)
portal.backfillLock.Unlock()
}
}
@ -531,7 +534,7 @@ func (portal *Portal) RestrictMetadataChanges(restrict bool) {
}
}
func (portal *Portal) BackfillHistory(user *User) error {
func (portal *Portal) BackfillHistory(user *User, lastMessageTime uint64) error {
if !portal.bridge.Config.Bridge.RecoverHistory {
return nil
}
@ -541,6 +544,10 @@ func (portal *Portal) BackfillHistory(user *User) error {
if lastMessage == nil {
return nil
}
if lastMessage.Timestamp <= lastMessageTime {
portal.log.Debugln("Not backfilling: no new messages")
return nil
}
lastMessageID := lastMessage.JID
portal.log.Infoln("Backfilling history since", lastMessageID, "for", user.MXID)
@ -619,7 +626,7 @@ func (portal *Portal) handleHistory(user *User, messages []interface{}) {
continue
}
data := whatsapp.ParseProtoMessage(message)
portal.handleMessage(PortalMessage{user, data, message.GetMessageTimestamp()})
portal.handleMessage(PortalMessage{portal.Key.JID, user, data, message.GetMessageTimestamp()})
}
}