mirror of
https://github.com/tulir/mautrix-whatsapp
synced 2024-09-26 11:38:54 +02:00
backfill: set backfill status state event
This commit is contained in:
parent
4eac1ea719
commit
cdf97a2df3
1 changed files with 19 additions and 0 deletions
|
@ -136,6 +136,7 @@ func (user *User) backfillInChunks(req *database.Backfill, conv *database.Histor
|
||||||
}
|
}
|
||||||
backfillState.SetProcessingBatch(true)
|
backfillState.SetProcessingBatch(true)
|
||||||
defer backfillState.SetProcessingBatch(false)
|
defer backfillState.SetProcessingBatch(false)
|
||||||
|
portal.updateBackfillStatus(backfillState)
|
||||||
|
|
||||||
if !user.shouldCreatePortalForHistorySync(conv, portal) {
|
if !user.shouldCreatePortalForHistorySync(conv, portal) {
|
||||||
return
|
return
|
||||||
|
@ -266,6 +267,7 @@ func (user *User) backfillInChunks(req *database.Backfill, conv *database.Histor
|
||||||
backfillState.FirstExpectedTimestamp = 0
|
backfillState.FirstExpectedTimestamp = 0
|
||||||
}
|
}
|
||||||
backfillState.Upsert()
|
backfillState.Upsert()
|
||||||
|
portal.updateBackfillStatus(backfillState)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !conv.MarkedAsUnread && conv.UnreadCount == 0 {
|
if !conv.MarkedAsUnread && conv.UnreadCount == 0 {
|
||||||
|
@ -442,6 +444,8 @@ var (
|
||||||
|
|
||||||
BackfillEndDummyEvent = event.Type{Type: "fi.mau.dummy.backfill_end", Class: event.MessageEventType}
|
BackfillEndDummyEvent = event.Type{Type: "fi.mau.dummy.backfill_end", Class: event.MessageEventType}
|
||||||
HistorySyncMarker = event.Type{Type: "org.matrix.msc2716.marker", 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 {
|
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)
|
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
|
// endregion
|
||||||
|
|
Loading…
Reference in a new issue