@@ -3,18 +3,21 @@ use std::sync::{Arc, RwLock};
3
3
use anyhow:: Context ;
4
4
use eyeball_im:: VectorDiff ;
5
5
use futures_util:: { future:: join4, pin_mut, StreamExt } ;
6
- use matrix_sdk:: ruma:: {
7
- api:: client:: sync:: sync_events:: {
8
- v4:: RoomSubscription as RumaRoomSubscription ,
9
- UnreadNotificationsCount as RumaUnreadNotificationsCount ,
10
- } ,
11
- assign, IdParseError , OwnedRoomId , RoomId ,
12
- } ;
13
6
pub use matrix_sdk:: {
14
7
ruma:: api:: client:: sync:: sync_events:: v4:: SyncRequestListFilters , Client as MatrixClient ,
15
8
LoopCtrl , RoomListEntry as MatrixRoomEntry , SlidingSyncBuilder as MatrixSlidingSyncBuilder ,
16
9
SlidingSyncMode , SlidingSyncState ,
17
10
} ;
11
+ use matrix_sdk:: {
12
+ ruma:: {
13
+ api:: client:: sync:: sync_events:: {
14
+ v4:: RoomSubscription as RumaRoomSubscription ,
15
+ UnreadNotificationsCount as RumaUnreadNotificationsCount ,
16
+ } ,
17
+ assign, IdParseError , OwnedRoomId , RoomId ,
18
+ } ,
19
+ sliding_sync:: SlidingSyncSelectiveModeBuilder as MatrixSlidingSyncSelectiveModeBuilder ,
20
+ } ;
18
21
use matrix_sdk_ui:: timeline:: SlidingSyncRoomExt ;
19
22
use tokio:: task:: JoinHandle ;
20
23
use tracing:: { debug, error, warn} ;
@@ -104,9 +107,6 @@ pub enum SlidingSyncError {
104
107
/// initialized. It happens when a response is handled before a request has
105
108
/// been sent. It usually happens when testing.
106
109
RequestGeneratorHasNotBeenInitialized { msg : String } ,
107
- /// Someone has tried to modify a sliding sync list's ranges, but the
108
- /// selected sync mode doesn't allow that.
109
- CannotModifyRanges { msg : String } ,
110
110
/// Ranges have a `start` bound greater than `end`.
111
111
InvalidRange {
112
112
/// Start bound.
@@ -129,7 +129,6 @@ impl From<matrix_sdk::sliding_sync::Error> for SlidingSyncError {
129
129
E :: RequestGeneratorHasNotBeenInitialized ( msg) => {
130
130
Self :: RequestGeneratorHasNotBeenInitialized { msg }
131
131
}
132
- E :: CannotModifyRanges ( msg) => Self :: CannotModifyRanges { msg } ,
133
132
E :: InvalidRange { start, end } => Self :: InvalidRange { start, end } ,
134
133
E :: InternalChannelIsBroken => Self :: InternalChannelIsBroken ,
135
134
error => Self :: Unknown { error : error. to_string ( ) } ,
@@ -410,6 +409,25 @@ pub trait SlidingSyncListStateObserver: Sync + Send {
410
409
fn did_receive_update ( & self , new_state : SlidingSyncState ) ;
411
410
}
412
411
412
+ #[ derive( Clone , uniffi:: Object ) ]
413
+ pub struct SlidingSyncSelectiveModeBuilder {
414
+ inner : MatrixSlidingSyncSelectiveModeBuilder ,
415
+ }
416
+
417
+ #[ uniffi:: export]
418
+ impl SlidingSyncSelectiveModeBuilder {
419
+ #[ uniffi:: constructor]
420
+ pub fn new ( ) -> Arc < Self > {
421
+ Arc :: new ( Self { inner : SlidingSyncMode :: new_selective ( ) } )
422
+ }
423
+
424
+ pub fn add_range ( self : Arc < Self > , start : u32 , end_inclusive : u32 ) -> Arc < Self > {
425
+ let mut builder = unwrap_or_clone_arc ( self ) ;
426
+ builder. inner = builder. inner . add_range ( start..=end_inclusive) ;
427
+ Arc :: new ( builder)
428
+ }
429
+ }
430
+
413
431
#[ derive( Clone , uniffi:: Object ) ]
414
432
pub struct SlidingSyncListBuilder {
415
433
inner : matrix_sdk:: SlidingSyncListBuilder ,
@@ -458,9 +476,13 @@ impl SlidingSyncListBuilder {
458
476
Arc :: new ( Self { inner : matrix_sdk:: SlidingSyncList :: builder ( name) } )
459
477
}
460
478
461
- pub fn sync_mode_selective ( self : Arc < Self > ) -> Arc < Self > {
479
+ pub fn sync_mode_selective (
480
+ self : Arc < Self > ,
481
+ selective_mode_builder : Arc < SlidingSyncSelectiveModeBuilder > ,
482
+ ) -> Arc < Self > {
462
483
let mut builder = unwrap_or_clone_arc ( self ) ;
463
- builder. inner = builder. inner . sync_mode ( SlidingSyncMode :: new_selective ( ) ) ;
484
+ let selective_mode_builder = unwrap_or_clone_arc ( selective_mode_builder) ;
485
+ builder. inner = builder. inner . sync_mode ( selective_mode_builder. inner ) ;
464
486
Arc :: new ( builder)
465
487
}
466
488
@@ -526,12 +548,6 @@ impl SlidingSyncListBuilder {
526
548
Arc :: new ( builder)
527
549
}
528
550
529
- pub fn add_range ( self : Arc < Self > , from : u32 , to_included : u32 ) -> Arc < Self > {
530
- let mut builder = unwrap_or_clone_arc ( self ) ;
531
- builder. inner = builder. inner . add_range ( from..=to_included) ;
532
- Arc :: new ( builder)
533
- }
534
-
535
551
pub fn once_built ( self : Arc < Self > , callback : Box < dyn SlidingSyncListOnceBuilt > ) -> Arc < Self > {
536
552
let mut builder = unwrap_or_clone_arc ( self ) ;
537
553
@@ -613,27 +629,6 @@ impl SlidingSyncList {
613
629
self . inner . room_list ( )
614
630
}
615
631
616
- /// Reset the ranges to a particular set
617
- ///
618
- /// Remember to cancel the existing stream and fetch a new one as this will
619
- /// only be applied on the next request.
620
- pub fn set_range ( & self , start : u32 , end : u32 ) -> Result < ( ) , SlidingSyncError > {
621
- self . inner . set_range ( start..=end) . map_err ( Into :: into)
622
- }
623
-
624
- /// Set the ranges to fetch
625
- ///
626
- /// Remember to cancel the existing stream and fetch a new one as this will
627
- /// only be applied on the next request.
628
- pub fn add_range ( & self , start : u32 , end : u32 ) -> Result < ( ) , SlidingSyncError > {
629
- self . inner . add_range ( start..=end) . map_err ( Into :: into)
630
- }
631
-
632
- /// Reset the ranges
633
- pub fn reset_ranges ( & self ) -> Result < ( ) , SlidingSyncError > {
634
- self . inner . reset_ranges ( ) . map_err ( Into :: into)
635
- }
636
-
637
632
/// Total of rooms matching the filter
638
633
pub fn current_room_count ( & self ) -> Option < u32 > {
639
634
self . inner . maximum_number_of_rooms ( )
0 commit comments