forked from MirrorHub/mautrix-whatsapp
Don't create rooms with no messages when backfilling
This commit is contained in:
parent
8711519c2b
commit
e6da32518e
1 changed files with 37 additions and 36 deletions
|
@ -114,6 +114,12 @@ func (user *User) createOrUpdatePortalAndBackfillWithLock(req *database.Backfill
|
|||
return
|
||||
}
|
||||
|
||||
allMsgs := user.bridge.DB.HistorySyncQuery.GetMessagesBetween(user.MXID, conv.ConversationID, req.TimeStart, req.TimeEnd, req.MaxTotalEvents)
|
||||
if len(allMsgs) == 0 {
|
||||
user.log.Debugfln("Not backfilling %s: no bridgeable messages found", portal.Key.JID)
|
||||
return
|
||||
}
|
||||
|
||||
if len(portal.MXID) == 0 {
|
||||
user.log.Debugln("Creating portal for", portal.Key.JID, "as part of history sync handling")
|
||||
err := portal.CreateMatrixRoom(user, nil, true, false)
|
||||
|
@ -123,12 +129,9 @@ func (user *User) createOrUpdatePortalAndBackfillWithLock(req *database.Backfill
|
|||
}
|
||||
}
|
||||
|
||||
allMsgs := user.bridge.DB.HistorySyncQuery.GetMessagesBetween(user.MXID, conv.ConversationID, req.TimeStart, req.TimeEnd, req.MaxTotalEvents)
|
||||
|
||||
if len(allMsgs) > 0 {
|
||||
user.log.Debugfln("Backfilling %d messages in %s, %d messages at a time", len(allMsgs), portal.Key.JID, req.MaxBatchEvents)
|
||||
toBackfill := allMsgs[0:]
|
||||
insertionEventIds := []id.EventID{}
|
||||
var insertionEventIds []id.EventID
|
||||
for {
|
||||
if len(toBackfill) == 0 {
|
||||
break
|
||||
|
@ -145,11 +148,11 @@ func (user *User) createOrUpdatePortalAndBackfillWithLock(req *database.Backfill
|
|||
|
||||
if len(msgs) > 0 {
|
||||
time.Sleep(time.Duration(req.BatchDelay) * time.Second)
|
||||
user.log.Debugfln("Backfilling %d messages in %s", len(msgs), portal.Key.JID)
|
||||
user.log.Debugfln("Backfilling %d messages in %s (queue ID: %d)", len(msgs), portal.Key.JID, req.QueueID)
|
||||
insertionEventIds = append(insertionEventIds, portal.backfill(user, msgs)...)
|
||||
}
|
||||
}
|
||||
user.log.Debugfln("Finished backfilling %d messages in %s", len(allMsgs), portal.Key.JID)
|
||||
user.log.Debugfln("Finished backfilling %d messages in %s (queue ID: %d)", len(allMsgs), portal.Key.JID, req.QueueID)
|
||||
if len(insertionEventIds) > 0 {
|
||||
portal.sendPostBackfillDummy(
|
||||
time.Unix(int64(allMsgs[len(allMsgs)-1].GetMessageTimestamp()), 0),
|
||||
|
@ -160,9 +163,7 @@ func (user *User) createOrUpdatePortalAndBackfillWithLock(req *database.Backfill
|
|||
if err != nil {
|
||||
user.log.Warnfln("Failed to delete %d history sync messages after backfilling: %v", len(allMsgs), err)
|
||||
}
|
||||
} else {
|
||||
user.log.Debugfln("Not backfilling %s: no bridgeable messages found", portal.Key.JID)
|
||||
}
|
||||
|
||||
if !conv.MarkedAsUnread && conv.UnreadCount == 0 {
|
||||
user.markSelfReadFull(portal)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue