@@ -309,68 +309,76 @@ impl SlidingSync {
309
309
}
310
310
311
311
let update_summary = {
312
- let mut rooms_map = self . inner . rooms . write ( ) . unwrap ( ) ;
313
-
314
312
// Update the rooms.
315
- let mut updated_rooms = Vec :: with_capacity ( sliding_sync_response. rooms . len ( ) ) ;
316
-
317
- for ( room_id, mut room_data) in sliding_sync_response. rooms . into_iter ( ) {
318
- // `sync_response` contains the rooms with decrypted events if any, so look at
319
- // the timeline events here first if the room exists.
320
- // Otherwise, let's look at the timeline inside the `sliding_sync_response`.
321
- let timeline = if let Some ( joined_room) = sync_response. rooms . join . remove ( & room_id)
322
- {
323
- joined_room. timeline . events
324
- } else {
325
- room_data. timeline . drain ( ..) . map ( Into :: into) . collect ( )
326
- } ;
327
-
328
- if let Some ( mut room) = rooms_map. remove ( & room_id) {
329
- // The room existed before, let's update it.
330
-
331
- room. update ( room_data, timeline) ;
332
- rooms_map. insert ( room_id. clone ( ) , room) ;
333
- } else {
334
- // First time we need this room, let's create it.
335
-
336
- rooms_map. insert (
337
- room_id. clone ( ) ,
338
- SlidingSyncRoom :: new (
339
- self . inner . client . clone ( ) ,
340
- room_id. clone ( ) ,
341
- room_data,
342
- timeline,
343
- ) ,
344
- ) ;
313
+ let updated_rooms = {
314
+ let mut rooms_map = self . inner . rooms . write ( ) . unwrap ( ) ;
315
+
316
+ let mut updated_rooms = Vec :: with_capacity ( sliding_sync_response. rooms . len ( ) ) ;
317
+
318
+ for ( room_id, mut room_data) in sliding_sync_response. rooms . into_iter ( ) {
319
+ // `sync_response` contains the rooms with decrypted events if any, so look at
320
+ // the timeline events here first if the room exists.
321
+ // Otherwise, let's look at the timeline inside the `sliding_sync_response`.
322
+ let timeline =
323
+ if let Some ( joined_room) = sync_response. rooms . join . remove ( & room_id) {
324
+ joined_room. timeline . events
325
+ } else {
326
+ room_data. timeline . drain ( ..) . map ( Into :: into) . collect ( )
327
+ } ;
328
+
329
+ match rooms_map. get_mut ( & room_id) {
330
+ // The room existed before, let's update it.
331
+ Some ( room) => {
332
+ room. update ( room_data, timeline) ;
333
+ }
334
+
335
+ // First time we need this room, let's create it.
336
+ None => {
337
+ rooms_map. insert (
338
+ room_id. clone ( ) ,
339
+ SlidingSyncRoom :: new (
340
+ self . inner . client . clone ( ) ,
341
+ room_id. clone ( ) ,
342
+ room_data,
343
+ timeline,
344
+ ) ,
345
+ ) ;
346
+ }
347
+ }
348
+
349
+ updated_rooms. push ( room_id) ;
345
350
}
346
351
347
- updated_rooms. push ( room_id ) ;
348
- }
352
+ updated_rooms
353
+ } ;
349
354
350
355
// Update the lists.
351
- let mut updated_lists = Vec :: with_capacity ( sliding_sync_response. lists . len ( ) ) ;
356
+ let updated_lists = {
357
+ let mut updated_lists = Vec :: with_capacity ( sliding_sync_response. lists . len ( ) ) ;
358
+ let mut lists = self . inner . lists . write ( ) . unwrap ( ) ;
352
359
353
- let mut lists = self . inner . lists . write ( ) . unwrap ( ) ;
360
+ for ( name, updates) in sliding_sync_response. lists {
361
+ let Some ( list) = lists. get_mut ( & name) else {
362
+ error ! ( "Response for list `{name}` - unknown to us; skipping" ) ;
354
363
355
- for ( name, updates) in sliding_sync_response. lists {
356
- let Some ( list) = lists. get_mut ( & name) else {
357
- error ! ( "Response for list `{name}` - unknown to us; skipping" ) ;
364
+ continue ;
365
+ } ;
358
366
359
- continue ;
360
- } ;
367
+ let maximum_number_of_rooms : u32 =
368
+ updates . count . try_into ( ) . expect ( "failed to convert `count` to `u32`" ) ;
361
369
362
- let maximum_number_of_rooms: u32 =
363
- updates. count . try_into ( ) . expect ( "failed to convert `count` to `u32`" ) ;
370
+ if list. update ( maximum_number_of_rooms, & updates. ops , & updated_rooms) ? {
371
+ updated_lists. push ( name. clone ( ) ) ;
372
+ }
373
+ }
364
374
365
- if list. update ( maximum_number_of_rooms, & updates. ops , & updated_rooms) ? {
366
- updated_lists. push ( name. clone ( ) ) ;
375
+ // Update the `to-device` next-batch if any.
376
+ if let Some ( to_device) = sliding_sync_response. extensions . to_device {
377
+ self . update_to_device_since ( to_device. next_batch ) ;
367
378
}
368
- }
369
379
370
- // Update the `to-device` next-batch if any.
371
- if let Some ( to_device) = sliding_sync_response. extensions . to_device {
372
- self . update_to_device_since ( to_device. next_batch ) ;
373
- }
380
+ updated_lists
381
+ } ;
374
382
375
383
UpdateSummary { lists : updated_lists, rooms : updated_rooms }
376
384
} ;
0 commit comments