Fix some bugs in missed message and initial history filling
This commit is contained in:
11
portal.go
11
portal.go
@ -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()})
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user