@@ -74,7 +74,7 @@ func (portal *Portal) doForwardBackfill(ctx context.Context, source *UserLogin,
7474		log .Warn ().Msg ("No messages left to backfill after cutting off old messages" )
7575		return 
7676	}
77- 	portal .sendBackfill (ctx , source , resp .Messages , true , resp .MarkRead , false )
77+ 	portal .sendBackfill (ctx , source , resp .Messages , true , resp .MarkRead , false ,  resp . CompleteCallback )
7878}
7979
8080func  (portal  * Portal ) DoBackwardsBackfill (ctx  context.Context , source  * UserLogin , task  * database.BackfillTask ) error  {
@@ -134,7 +134,7 @@ func (portal *Portal) DoBackwardsBackfill(ctx context.Context, source *UserLogin
134134	if  len (resp .Messages ) ==  0  {
135135		return  fmt .Errorf ("no messages left to backfill after cutting off too new messages" )
136136	}
137- 	portal .sendBackfill (ctx , source , resp .Messages , false , resp .MarkRead , false )
137+ 	portal .sendBackfill (ctx , source , resp .Messages , false , resp .MarkRead , false ,  resp . CompleteCallback )
138138	if  len (resp .Messages ) >  0  {
139139		task .OldestMessageID  =  resp .Messages [0 ].ID 
140140	}
@@ -182,7 +182,7 @@ func (portal *Portal) doThreadBackfill(ctx context.Context, source *UserLogin, t
182182	}
183183	resp  :=  portal .fetchThreadBackfill (ctx , source , anchorMessage )
184184	if  resp  !=  nil  {
185- 		portal .sendBackfill (ctx , source , resp .Messages , true , resp .MarkRead , true )
185+ 		portal .sendBackfill (ctx , source , resp .Messages , true , resp .MarkRead , true ,  resp . CompleteCallback )
186186	}
187187}
188188
@@ -257,7 +257,15 @@ func (portal *Portal) cutoffMessages(ctx context.Context, messages []*BackfillMe
257257	return  messages 
258258}
259259
260- func  (portal  * Portal ) sendBackfill (ctx  context.Context , source  * UserLogin , messages  []* BackfillMessage , forceForward , markRead , inThread  bool ) {
260+ func  (portal  * Portal ) sendBackfill (
261+ 	ctx  context.Context ,
262+ 	source  * UserLogin ,
263+ 	messages  []* BackfillMessage ,
264+ 	forceForward ,
265+ 	markRead ,
266+ 	inThread  bool ,
267+ 	done  func (),
268+ ) {
261269	canBatchSend  :=  portal .Bridge .Matrix .GetCapabilities ().BatchSending 
262270	unreadThreshold  :=  time .Duration (portal .Bridge .Config .Backfill .UnreadHoursThreshold ) *  time .Hour 
263271	forceMarkRead  :=  unreadThreshold  >  0  &&  time .Since (messages [len (messages )- 1 ].Timestamp ) >  unreadThreshold 
@@ -272,6 +280,9 @@ func (portal *Portal) sendBackfill(ctx context.Context, source *UserLogin, messa
272280	} else  {
273281		portal .sendLegacyBackfill (ctx , source , messages , markRead  ||  forceMarkRead )
274282	}
283+ 	if  done  !=  nil  {
284+ 		done ()
285+ 	}
275286	zerolog .Ctx (ctx ).Debug ().Msg ("Backfill finished" )
276287	if  ! canBatchSend  &&  ! inThread  &&  portal .Bridge .Config .Backfill .Threads .MaxInitialMessages  >  0  {
277288		for  _ , msg  :=  range  messages  {
0 commit comments