From cdf97a2df3a7497e5b18baf7143650f6aa902c89 Mon Sep 17 00:00:00 2001 From: Sumner Evans Date: Thu, 19 May 2022 23:20:04 -0600 Subject: [PATCH] backfill: set backfill status state event --- historysync.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/historysync.go b/historysync.go index 00f0e2a..2f952a4 100644 --- a/historysync.go +++ b/historysync.go @@ -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