فهرست منبع

backfill: set backfill status state event

Sumner Evans 3 سال پیش
والد
کامیت
cdf97a2df3
1فایلهای تغییر یافته به همراه19 افزوده شده و 0 حذف شده
  1. 19 0
      historysync.go

+ 19 - 0
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