@@ -285,7 +285,11 @@ def __bool__(self) -> bool:
285
285
)
286
286
287
287
@staticmethod
288
- def empty (next_batch : StreamToken ) -> "SyncResult" :
288
+ def empty (
289
+ next_batch : StreamToken ,
290
+ device_one_time_keys_count : JsonMapping ,
291
+ device_unused_fallback_key_types : List [str ],
292
+ ) -> "SyncResult" :
289
293
"Return a new empty result"
290
294
return SyncResult (
291
295
next_batch = next_batch ,
@@ -297,8 +301,8 @@ def empty(next_batch: StreamToken) -> "SyncResult":
297
301
archived = [],
298
302
to_device = [],
299
303
device_lists = DeviceListUpdates (),
300
- device_one_time_keys_count = {} ,
301
- device_unused_fallback_key_types = [] ,
304
+ device_one_time_keys_count = device_one_time_keys_count ,
305
+ device_unused_fallback_key_types = device_unused_fallback_key_types ,
302
306
)
303
307
304
308
@@ -523,7 +527,28 @@ async def _wait_for_sync_for_user(
523
527
logger .warning (
524
528
"Timed out waiting for worker to catch up. Returning empty response"
525
529
)
526
- return SyncResult .empty (since_token )
530
+ device_id = sync_config .device_id
531
+ one_time_keys_count : JsonMapping = {}
532
+ unused_fallback_key_types : List [str ] = []
533
+ if device_id :
534
+ user_id = sync_config .user .to_string ()
535
+ # TODO: We should have a way to let clients differentiate between the states of:
536
+ # * no change in OTK count since the provided since token
537
+ # * the server has zero OTKs left for this device
538
+ # Spec issue: https://github.com/matrix-org/matrix-doc/issues/3298
539
+ one_time_keys_count = await self .store .count_e2e_one_time_keys (
540
+ user_id , device_id
541
+ )
542
+ unused_fallback_key_types = list (
543
+ await self .store .get_e2e_unused_fallback_key_types (
544
+ user_id , device_id
545
+ )
546
+ )
547
+
548
+ cache_context .should_cache = False # Don't cache empty responses
549
+ return SyncResult .empty (
550
+ since_token , one_time_keys_count , unused_fallback_key_types
551
+ )
527
552
528
553
# If we've spent significant time waiting to catch up, take it off
529
554
# the timeout.
0 commit comments