15
15
use std:: { collections:: HashMap , fmt:: Write as _, fs, panic, sync:: Arc } ;
16
16
17
17
use anyhow:: { Context , Result } ;
18
- use as_variant:: as_variant;
19
18
use eyeball_im:: VectorDiff ;
20
19
use futures_util:: pin_mut;
21
20
use matrix_sdk:: {
@@ -64,7 +63,6 @@ use crate::{
64
63
client:: ProgressWatcher ,
65
64
error:: { ClientError , RoomError } ,
66
65
event:: EventOrTransactionId ,
67
- helpers:: unwrap_or_clone_arc,
68
66
ruma:: {
69
67
AssetType , AudioInfo , FileInfo , FormattedBody , ImageInfo , Mentions , PollKind ,
70
68
ThumbnailInfo , VideoInfo ,
@@ -252,17 +250,14 @@ impl Timeline {
252
250
// handled by the caller. See #3535 for details.
253
251
254
252
// First, pass all the items as a reset update.
255
- listener. on_update ( vec ! [ Arc :: new( TimelineDiff :: new( VectorDiff :: Reset {
256
- values: timeline_items,
257
- } ) ) ] ) ;
253
+ listener. on_update ( vec ! [ TimelineDiff :: new( VectorDiff :: Reset { values: timeline_items } ) ] ) ;
258
254
259
255
Arc :: new ( TaskHandle :: new ( get_runtime_handle ( ) . spawn ( async move {
260
256
pin_mut ! ( timeline_stream) ;
261
257
262
258
// Then forward new items.
263
259
while let Some ( diffs) = timeline_stream. next ( ) . await {
264
- listener
265
- . on_update ( diffs. into_iter ( ) . map ( |d| Arc :: new ( TimelineDiff :: new ( d) ) ) . collect ( ) ) ;
260
+ listener. on_update ( diffs. into_iter ( ) . map ( TimelineDiff :: new) . collect ( ) ) ;
266
261
}
267
262
} ) ) )
268
263
}
@@ -790,26 +785,26 @@ pub enum FocusEventError {
790
785
791
786
#[ matrix_sdk_ffi_macros:: export( callback_interface) ]
792
787
pub trait TimelineListener : SyncOutsideWasm + SendOutsideWasm {
793
- fn on_update ( & self , diff : Vec < Arc < TimelineDiff > > ) ;
788
+ fn on_update ( & self , diff : Vec < TimelineDiff > ) ;
794
789
}
795
790
796
791
#[ matrix_sdk_ffi_macros:: export( callback_interface) ]
797
792
pub trait PaginationStatusListener : SyncOutsideWasm + SendOutsideWasm {
798
793
fn on_update ( & self , status : RoomPaginationStatus ) ;
799
794
}
800
795
801
- #[ derive( Clone , uniffi:: Object ) ]
796
+ #[ derive( Clone , uniffi:: Enum ) ]
802
797
pub enum TimelineDiff {
803
798
Append { values : Vec < Arc < TimelineItem > > } ,
804
799
Clear ,
805
800
PushFront { value : Arc < TimelineItem > } ,
806
801
PushBack { value : Arc < TimelineItem > } ,
807
802
PopFront ,
808
803
PopBack ,
809
- Insert { index : usize , value : Arc < TimelineItem > } ,
810
- Set { index : usize , value : Arc < TimelineItem > } ,
811
- Remove { index : usize } ,
812
- Truncate { length : usize } ,
804
+ Insert { index : u32 , value : Arc < TimelineItem > } ,
805
+ Set { index : u32 , value : Arc < TimelineItem > } ,
806
+ Remove { index : u32 } ,
807
+ Truncate { length : u32 } ,
813
808
Reset { values : Vec < Arc < TimelineItem > > } ,
814
809
}
815
810
@@ -820,14 +815,18 @@ impl TimelineDiff {
820
815
Self :: Append { values : values. into_iter ( ) . map ( TimelineItem :: from_arc) . collect ( ) }
821
816
}
822
817
VectorDiff :: Clear => Self :: Clear ,
823
- VectorDiff :: Insert { index, value } => {
824
- Self :: Insert { index, value : TimelineItem :: from_arc ( value) }
825
- }
826
- VectorDiff :: Set { index, value } => {
827
- Self :: Set { index, value : TimelineItem :: from_arc ( value) }
818
+ VectorDiff :: Insert { index, value } => Self :: Insert {
819
+ index : u32:: try_from ( index) . unwrap ( ) ,
820
+ value : TimelineItem :: from_arc ( value) ,
821
+ } ,
822
+ VectorDiff :: Set { index, value } => Self :: Set {
823
+ index : u32:: try_from ( index) . unwrap ( ) ,
824
+ value : TimelineItem :: from_arc ( value) ,
825
+ } ,
826
+ VectorDiff :: Truncate { length } => {
827
+ Self :: Truncate { length : u32:: try_from ( length) . unwrap ( ) }
828
828
}
829
- VectorDiff :: Truncate { length } => Self :: Truncate { length } ,
830
- VectorDiff :: Remove { index } => Self :: Remove { index } ,
829
+ VectorDiff :: Remove { index } => Self :: Remove { index : u32:: try_from ( index) . unwrap ( ) } ,
831
830
VectorDiff :: PushBack { value } => {
832
831
Self :: PushBack { value : TimelineItem :: from_arc ( value) }
833
832
}
@@ -843,67 +842,6 @@ impl TimelineDiff {
843
842
}
844
843
}
845
844
846
- #[ matrix_sdk_ffi_macros:: export]
847
- impl TimelineDiff {
848
- pub fn change ( & self ) -> TimelineChange {
849
- match self {
850
- Self :: Append { .. } => TimelineChange :: Append ,
851
- Self :: Insert { .. } => TimelineChange :: Insert ,
852
- Self :: Set { .. } => TimelineChange :: Set ,
853
- Self :: Remove { .. } => TimelineChange :: Remove ,
854
- Self :: PushBack { .. } => TimelineChange :: PushBack ,
855
- Self :: PushFront { .. } => TimelineChange :: PushFront ,
856
- Self :: PopBack => TimelineChange :: PopBack ,
857
- Self :: PopFront => TimelineChange :: PopFront ,
858
- Self :: Clear => TimelineChange :: Clear ,
859
- Self :: Truncate { .. } => TimelineChange :: Truncate ,
860
- Self :: Reset { .. } => TimelineChange :: Reset ,
861
- }
862
- }
863
-
864
- pub fn append ( self : Arc < Self > ) -> Option < Vec < Arc < TimelineItem > > > {
865
- let this = unwrap_or_clone_arc ( self ) ;
866
- as_variant ! ( this, Self :: Append { values } => values)
867
- }
868
-
869
- pub fn insert ( self : Arc < Self > ) -> Option < InsertData > {
870
- let this = unwrap_or_clone_arc ( self ) ;
871
- as_variant ! ( this, Self :: Insert { index, value } => {
872
- InsertData { index: index. try_into( ) . unwrap( ) , item: value }
873
- } )
874
- }
875
-
876
- pub fn set ( self : Arc < Self > ) -> Option < SetData > {
877
- let this = unwrap_or_clone_arc ( self ) ;
878
- as_variant ! ( this, Self :: Set { index, value } => {
879
- SetData { index: index. try_into( ) . unwrap( ) , item: value }
880
- } )
881
- }
882
-
883
- pub fn remove ( & self ) -> Option < u32 > {
884
- as_variant ! ( self , Self :: Remove { index } => ( * index) . try_into( ) . unwrap( ) )
885
- }
886
-
887
- pub fn push_back ( self : Arc < Self > ) -> Option < Arc < TimelineItem > > {
888
- let this = unwrap_or_clone_arc ( self ) ;
889
- as_variant ! ( this, Self :: PushBack { value } => value)
890
- }
891
-
892
- pub fn push_front ( self : Arc < Self > ) -> Option < Arc < TimelineItem > > {
893
- let this = unwrap_or_clone_arc ( self ) ;
894
- as_variant ! ( this, Self :: PushFront { value } => value)
895
- }
896
-
897
- pub fn reset ( self : Arc < Self > ) -> Option < Vec < Arc < TimelineItem > > > {
898
- let this = unwrap_or_clone_arc ( self ) ;
899
- as_variant ! ( this, Self :: Reset { values } => values)
900
- }
901
-
902
- pub fn truncate ( & self ) -> Option < u32 > {
903
- as_variant ! ( self , Self :: Truncate { length } => ( * length) . try_into( ) . unwrap( ) )
904
- }
905
- }
906
-
907
845
#[ derive( uniffi:: Record ) ]
908
846
pub struct InsertData {
909
847
pub index : u32 ,
0 commit comments