@@ -162,18 +162,27 @@ impl RoomList {
162
162
163
163
fn entries ( & self , listener : Box < dyn RoomListEntriesListener > ) -> Arc < TaskHandle > {
164
164
let this = self . inner . clone ( ) ;
165
+ let utd_hook = self . room_list_service . utd_hook . clone ( ) ;
165
166
166
167
Arc :: new ( TaskHandle :: new ( RUNTIME . spawn ( async move {
167
168
let ( entries, entries_stream) = this. entries ( ) ;
168
169
169
170
pin_mut ! ( entries_stream) ;
170
171
171
172
listener. on_update ( vec ! [ RoomListEntriesUpdate :: Append {
172
- values: entries. into_iter( ) . map( |v| Arc :: new( v. into( ) ) ) . collect( ) ,
173
+ values: entries
174
+ . into_iter( )
175
+ . map( |room| Arc :: new( RoomListItem :: from( room, utd_hook. clone( ) ) ) )
176
+ . collect( ) ,
173
177
} ] ) ;
174
178
175
- while let Some ( diff) = entries_stream. next ( ) . await {
176
- listener. on_update ( diff. into_iter ( ) . map ( Into :: into) . collect ( ) ) ;
179
+ while let Some ( diffs) = entries_stream. next ( ) . await {
180
+ listener. on_update (
181
+ diffs
182
+ . into_iter ( )
183
+ . map ( |diff| RoomListEntriesUpdate :: from ( diff, utd_hook. clone ( ) ) )
184
+ . collect ( ) ,
185
+ ) ;
177
186
}
178
187
} ) ) )
179
188
}
@@ -185,6 +194,7 @@ impl RoomList {
185
194
) -> Arc < RoomListEntriesWithDynamicAdaptersResult > {
186
195
let this = self . clone ( ) ;
187
196
let client = self . room_list_service . inner . client ( ) ;
197
+ let utd_hook = self . room_list_service . utd_hook . clone ( ) ;
188
198
189
199
// The following code deserves a bit of explanation.
190
200
// `matrix_sdk_ui::room_list_service::RoomList::entries_with_dynamic_adapters`
@@ -244,8 +254,13 @@ impl RoomList {
244
254
let entries_stream = Arc :: new ( TaskHandle :: new ( RUNTIME . spawn ( async move {
245
255
pin_mut ! ( entries_stream) ;
246
256
247
- while let Some ( diff) = entries_stream. next ( ) . await {
248
- listener. on_update ( diff. into_iter ( ) . map ( Into :: into) . collect ( ) ) ;
257
+ while let Some ( diffs) = entries_stream. next ( ) . await {
258
+ listener. on_update (
259
+ diffs
260
+ . into_iter ( )
261
+ . map ( |diff| RoomListEntriesUpdate :: from ( diff, utd_hook. clone ( ) ) )
262
+ . collect ( ) ,
263
+ ) ;
249
264
}
250
265
} ) ) ) ;
251
266
@@ -390,30 +405,45 @@ pub enum RoomListEntriesUpdate {
390
405
Reset { values : Vec < Arc < RoomListItem > > } ,
391
406
}
392
407
393
- impl From < VectorDiff < matrix_sdk_ui:: room_list_service:: Room > > for RoomListEntriesUpdate {
394
- fn from ( other : VectorDiff < matrix_sdk_ui:: room_list_service:: Room > ) -> Self {
395
- match other {
396
- VectorDiff :: Append { values } => {
397
- Self :: Append { values : values. into_iter ( ) . map ( |v| Arc :: new ( v. into ( ) ) ) . collect ( ) }
398
- }
408
+ impl RoomListEntriesUpdate {
409
+ fn from (
410
+ vector_diff : VectorDiff < matrix_sdk_ui:: room_list_service:: Room > ,
411
+ utd_hook : Option < Arc < UtdHookManager > > ,
412
+ ) -> Self {
413
+ match vector_diff {
414
+ VectorDiff :: Append { values } => Self :: Append {
415
+ values : values
416
+ . into_iter ( )
417
+ . map ( |value| Arc :: new ( RoomListItem :: from ( value, utd_hook. clone ( ) ) ) )
418
+ . collect ( ) ,
419
+ } ,
399
420
VectorDiff :: Clear => Self :: Clear ,
400
- VectorDiff :: PushFront { value } => Self :: PushFront { value : Arc :: new ( value. into ( ) ) } ,
401
- VectorDiff :: PushBack { value } => Self :: PushBack { value : Arc :: new ( value. into ( ) ) } ,
402
- VectorDiff :: PopFront => Self :: PopFront ,
403
- VectorDiff :: PopBack => Self :: PopBack ,
404
- VectorDiff :: Insert { index, value } => {
405
- Self :: Insert { index : u32:: try_from ( index) . unwrap ( ) , value : Arc :: new ( value. into ( ) ) }
421
+ VectorDiff :: PushFront { value } => {
422
+ Self :: PushFront { value : Arc :: new ( RoomListItem :: from ( value, utd_hook) ) }
406
423
}
407
- VectorDiff :: Set { index , value } => {
408
- Self :: Set { index : u32 :: try_from ( index ) . unwrap ( ) , value : Arc :: new ( value . into ( ) ) }
424
+ VectorDiff :: PushBack { value } => {
425
+ Self :: PushBack { value : Arc :: new ( RoomListItem :: from ( value , utd_hook ) ) }
409
426
}
427
+ VectorDiff :: PopFront => Self :: PopFront ,
428
+ VectorDiff :: PopBack => Self :: PopBack ,
429
+ VectorDiff :: Insert { index, value } => Self :: Insert {
430
+ index : u32:: try_from ( index) . unwrap ( ) ,
431
+ value : Arc :: new ( RoomListItem :: from ( value, utd_hook) ) ,
432
+ } ,
433
+ VectorDiff :: Set { index, value } => Self :: Set {
434
+ index : u32:: try_from ( index) . unwrap ( ) ,
435
+ value : Arc :: new ( RoomListItem :: from ( value, utd_hook) ) ,
436
+ } ,
410
437
VectorDiff :: Remove { index } => Self :: Remove { index : u32:: try_from ( index) . unwrap ( ) } ,
411
438
VectorDiff :: Truncate { length } => {
412
439
Self :: Truncate { length : u32:: try_from ( length) . unwrap ( ) }
413
440
}
414
- VectorDiff :: Reset { values } => {
415
- Self :: Reset { values : values. into_iter ( ) . map ( |v| Arc :: new ( v. into ( ) ) ) . collect ( ) }
416
- }
441
+ VectorDiff :: Reset { values } => Self :: Reset {
442
+ values : values
443
+ . into_iter ( )
444
+ . map ( |value| Arc :: new ( RoomListItem :: from ( value, utd_hook. clone ( ) ) ) )
445
+ . collect ( ) ,
446
+ } ,
417
447
}
418
448
}
419
449
}
@@ -515,9 +545,12 @@ pub struct RoomListItem {
515
545
utd_hook : Option < Arc < UtdHookManager > > ,
516
546
}
517
547
518
- impl From < matrix_sdk_ui:: room_list_service:: Room > for RoomListItem {
519
- fn from ( value : matrix_sdk_ui:: room_list_service:: Room ) -> Self {
520
- Self { inner : Arc :: new ( value) , utd_hook : None }
548
+ impl RoomListItem {
549
+ fn from (
550
+ value : matrix_sdk_ui:: room_list_service:: Room ,
551
+ utd_hook : Option < Arc < UtdHookManager > > ,
552
+ ) -> Self {
553
+ Self { inner : Arc :: new ( value) , utd_hook }
521
554
}
522
555
}
523
556
0 commit comments