Jelajahi Sumber

backfill status event: send after room exists

Sumner Evans 3 tahun lalu
induk
melakukan
03d46630c2
1 mengubah file dengan 8 tambahan dan 6 penghapusan
  1. 8 6
      historysync.go

+ 8 - 6
historysync.go

@@ -132,17 +132,16 @@ func (user *User) backfillInChunks(req *database.Backfill, conv *database.Histor
 	portal.backfillLock.Lock()
 	defer portal.backfillLock.Unlock()
 
+	if !user.shouldCreatePortalForHistorySync(conv, portal) {
+		return
+	}
+
 	backfillState := user.bridge.DB.Backfill.GetBackfillState(user.MXID, &portal.Key)
 	if backfillState == nil {
 		backfillState = user.bridge.DB.Backfill.NewBackfillState(user.MXID, &portal.Key)
 	}
 	backfillState.SetProcessingBatch(true)
 	defer backfillState.SetProcessingBatch(false)
-	portal.updateBackfillStatus(backfillState)
-
-	if !user.shouldCreatePortalForHistorySync(conv, portal) {
-		return
-	}
 
 	var forwardPrevID id.EventID
 	var timeEnd *time.Time
@@ -194,6 +193,9 @@ func (user *User) backfillInChunks(req *database.Backfill, conv *database.Histor
 		}
 	}
 
+	// Update the backfill status here after the room has been created.
+	portal.updateBackfillStatus(backfillState)
+
 	if sendDisappearedNotice {
 		user.log.Debugfln("Sending notice to %s that there are disappeared messages ending at %v", portal.Key.JID, conv.LastMessageTimestamp)
 		resp, err := portal.sendMessage(portal.MainIntent(), event.EventMessage, &event.MessageEventContent{
@@ -735,7 +737,7 @@ func (portal *Portal) updateBackfillStatus(backfillState *database.BackfillState
 		"first_timestamp": backfillState.FirstExpectedTimestamp,
 	})
 	if err != nil {
-		portal.log.Errorln("Error sending backfill status dummy event:", err)
+		portal.log.Errorln("Error sending backfill status event:", err)
 	}
 }