backfill: set backfill status state event

This commit is contained in:
Sumner Evans 2022-05-19 23:20:04 -06:00
parent 4eac1ea719
commit cdf97a2df3
No known key found for this signature in database
GPG key ID: 8904527AB50022FD

View file

@ -136,6 +136,7 @@ func (user *User) backfillInChunks(req *database.Backfill, conv *database.Histor
}
backfillState.SetProcessingBatch(true)
defer backfillState.SetProcessingBatch(false)
portal.updateBackfillStatus(backfillState)
if !user.shouldCreatePortalForHistorySync(conv, portal) {
return
@ -266,6 +267,7 @@ func (user *User) backfillInChunks(req *database.Backfill, conv *database.Histor
backfillState.FirstExpectedTimestamp = 0
}
backfillState.Upsert()
portal.updateBackfillStatus(backfillState)
}
if !conv.MarkedAsUnread && conv.UnreadCount == 0 {
@ -442,6 +444,8 @@ var (
BackfillEndDummyEvent = event.Type{Type: "fi.mau.dummy.backfill_end", Class: event.MessageEventType}
HistorySyncMarker = event.Type{Type: "org.matrix.msc2716.marker", Class: event.MessageEventType}
BackfillStatusEvent = event.Type{Type: "com.beeper.backfill_status", Class: event.StateEventType}
)
func (portal *Portal) backfill(source *User, messages []*waProto.WebMessageInfo, isForward, isLatest bool, prevEventID id.EventID) *mautrix.RespBatchSend {
@ -718,4 +722,19 @@ func (portal *Portal) sendPostBackfillDummy(lastTimestamp time.Time, insertionEv
msg.Insert(nil)
}
func (portal *Portal) updateBackfillStatus(backfillState *database.BackfillState) {
backfillStatus := "backfilling"
if backfillState.BackfillComplete {
backfillStatus = "complete"
}
_, err := portal.MainIntent().SendStateEvent(portal.MXID, BackfillStatusEvent, "", map[string]interface{}{
"status": backfillStatus,
"first_timestamp": backfillState.FirstExpectedTimestamp,
})
if err != nil {
portal.log.Errorln("Error sending post-backfill dummy event:", err)
}
}
// endregion