@@ -19,7 +19,7 @@ use crate::revision::RevisionMapping;
1919use crate :: section:: { Section , SectionItem , SectionMap } ;
2020use crate :: {
2121 FolderData , ParentChildRelations , SectionChangeSender , SpacePermission , TrashInfo , View ,
22- ViewChangeReceiver , ViewUpdate , ViewsMap , Workspace , impl_section_op,
22+ ViewChangeReceiver , ViewId , ViewUpdate , ViewsMap , Workspace , impl_section_op,
2323} ;
2424
2525#[ derive( Clone , Debug , Serialize , Deserialize , Eq , PartialEq , Hash ) ]
@@ -215,7 +215,7 @@ impl Folder {
215215 & mut self ,
216216 view_id : & str ,
217217 new_parent_id : & str ,
218- prev_view_id : Option < String > ,
218+ prev_view_id : Option < ViewId > ,
219219 uid : i64 ,
220220 ) -> Option < Arc < View > > {
221221 let mut txn = self . collab . transact_mut ( ) ;
@@ -224,12 +224,12 @@ impl Folder {
224224 . move_nested_view ( & mut txn, view_id, new_parent_id, prev_view_id, uid)
225225 }
226226
227- pub fn set_current_view ( & mut self , view_id : String , uid : i64 ) {
227+ pub fn set_current_view ( & mut self , view_id : ViewId , uid : i64 ) {
228228 let mut txn = self . collab . transact_mut ( ) ;
229229 self . body . set_current_view ( & mut txn, view_id, uid) ;
230230 }
231231
232- pub fn get_current_view ( & self , uid : i64 ) -> Option < String > {
232+ pub fn get_current_view ( & self , uid : i64 ) -> Option < ViewId > {
233233 let txn = self . collab . transact ( ) ;
234234 self . body . get_current_view ( & txn, uid)
235235 }
@@ -343,7 +343,7 @@ impl Folder {
343343 }
344344 }
345345
346- pub fn replace_view ( & mut self , from : & str , to : & str , uid : i64 ) -> bool {
346+ pub fn replace_view ( & mut self , from : & ViewId , to : & ViewId , uid : i64 ) -> bool {
347347 let mut txn = self . collab . transact_mut ( ) ;
348348 self . body . replace_view ( & mut txn, from, to, uid)
349349 }
@@ -715,13 +715,13 @@ impl FolderBody {
715715 txn : & mut TransactionMut ,
716716 view_id : & str ,
717717 new_parent_id : & str ,
718- prev_view_id : Option < String > ,
718+ prev_view_id : Option < ViewId > ,
719719 uid : i64 ,
720720 ) -> Option < Arc < View > > {
721721 tracing:: debug!( "Move nested view: {}" , view_id) ;
722722 let view = self . views . get_view_with_txn ( txn, view_id, uid) ?;
723723 let current_workspace_id = self . get_workspace_id_with_txn ( txn) ?;
724- let parent_id = view. parent_view_id . as_str ( ) ;
724+ let parent_id = view. parent_view_id . as_ref ( ) ;
725725
726726 let new_parent_view = self . views . get_view_with_txn ( txn, new_parent_id, uid) ;
727727
@@ -740,7 +740,7 @@ impl FolderBody {
740740 // place it as the first child.
741741 self
742742 . views
743- . associate_parent_child_with_txn ( txn, new_parent_id, view_id, prev_view_id. clone ( ) ) ;
743+ . associate_parent_child_with_txn ( txn, new_parent_id, view_id, prev_view_id) ;
744744 // Update the view's parent ID.
745745 self
746746 . views
@@ -750,7 +750,7 @@ impl FolderBody {
750750 Some ( view)
751751 }
752752
753- pub fn get_child_of_first_public_view < T : ReadTxn > ( & self , txn : & T , uid : i64 ) -> Option < String > {
753+ pub fn get_child_of_first_public_view < T : ReadTxn > ( & self , txn : & T , uid : i64 ) -> Option < ViewId > {
754754 self
755755 . get_workspace_id ( txn)
756756 . and_then ( |workspace_id| self . views . get_view ( txn, & workspace_id, uid) )
@@ -784,7 +784,7 @@ impl FolderBody {
784784 } )
785785 }
786786
787- pub fn get_current_view < T : ReadTxn > ( & self , txn : & T , uid : i64 ) -> Option < String > {
787+ pub fn get_current_view < T : ReadTxn > ( & self , txn : & T , uid : i64 ) -> Option < ViewId > {
788788 // Fallback to CURRENT_VIEW if CURRENT_VIEW_FOR_USER is not present. This could happen for
789789 // workspace folder created by older version of the app before CURRENT_VIEW_FOR_USER is introduced.
790790 // If user cannot be found in CURRENT_VIEW_FOR_USER, use the first child of the first public space
@@ -795,24 +795,24 @@ impl FolderBody {
795795 } ;
796796 match current_view_for_user_map {
797797 Some ( current_view_for_user) => {
798- let view_for_user: Option < String > =
798+ let view_for_user: Option < ViewId > =
799799 current_view_for_user. get_with_txn ( txn, uid. to_string ( ) . as_ref ( ) ) ;
800800 view_for_user. or ( self . get_child_of_first_public_view ( txn, uid) )
801801 } ,
802802 None => self . meta . get_with_txn ( txn, CURRENT_VIEW ) ,
803803 }
804804 }
805805
806- pub fn set_current_view ( & self , txn : & mut TransactionMut , view : String , uid : i64 ) {
806+ pub fn set_current_view ( & self , txn : & mut TransactionMut , view : ViewId , uid : i64 ) {
807807 let current_view_for_user = self . meta . get_or_init_map ( txn, CURRENT_VIEW_FOR_USER ) ;
808808 current_view_for_user. try_update ( txn, uid. to_string ( ) , view) ;
809809 }
810810
811811 pub fn replace_view (
812812 & self ,
813813 txn : & mut TransactionMut ,
814- old_view_id : & str ,
815- new_view_id : & str ,
814+ old_view_id : & ViewId ,
815+ new_view_id : & ViewId ,
816816 uid : i64 ,
817817 ) -> bool {
818818 self . views . replace_view ( txn, old_view_id, new_view_id, uid)
@@ -821,7 +821,7 @@ impl FolderBody {
821821
822822pub fn default_folder_data ( uid : i64 , workspace_id : & str ) -> FolderData {
823823 let workspace = Workspace {
824- id : workspace_id. to_string ( ) ,
824+ id : workspace_id. into ( ) ,
825825 name : "" . to_string ( ) ,
826826 child_views : Default :: default ( ) ,
827827 created_at : 0 ,
@@ -832,7 +832,7 @@ pub fn default_folder_data(uid: i64, workspace_id: &str) -> FolderData {
832832 FolderData {
833833 uid,
834834 workspace,
835- current_view : "" . to_string ( ) ,
835+ current_view : "" . into ( ) ,
836836 views : vec ! [ ] ,
837837 favorites : HashMap :: new ( ) ,
838838 recent : HashMap :: new ( ) ,
@@ -846,7 +846,7 @@ mod tests {
846846 use std:: collections:: HashMap ;
847847
848848 use crate :: {
849- Folder , FolderData , RepeatedViewIdentifier , SectionItem , SpaceInfo , UserId , View ,
849+ Folder , FolderData , RepeatedViewIdentifier , SectionItem , SpaceInfo , UserId , View , ViewId ,
850850 ViewIdentifier , Workspace ,
851851 } ;
852852 use collab:: core:: collab:: default_client_id;
@@ -860,25 +860,25 @@ mod tests {
860860 let options = CollabOptions :: new ( workspace_id. to_string ( ) , default_client_id ( ) ) ;
861861 let collab = Collab :: new_with_options ( CollabOrigin :: Empty , options) . unwrap ( ) ;
862862 let view_1 = View :: new (
863- "view_1" . to_string ( ) ,
864- workspace_id. to_string ( ) ,
865- "View 1" . to_string ( ) ,
863+ "view_1" . into ( ) ,
864+ workspace_id. into ( ) ,
865+ "View 1" . into ( ) ,
866866 crate :: ViewLayout :: Document ,
867867 Some ( uid) ,
868868 ) ;
869869 let view_1_id = view_1. id . clone ( ) ;
870870 let view_2 = View :: new (
871- "view_2" . to_string ( ) ,
872- workspace_id. to_string ( ) ,
873- "View 2" . to_string ( ) ,
871+ "view_2" . into ( ) ,
872+ workspace_id. into ( ) ,
873+ "View 2" . into ( ) ,
874874 crate :: ViewLayout :: Document ,
875875 Some ( uid) ,
876876 ) ;
877877 let view_2_id = view_2. id . clone ( ) ;
878878 let space_view = View {
879- id : "space_1_id" . to_string ( ) ,
880- parent_view_id : workspace_id. to_string ( ) ,
881- name : "Space 1" . to_string ( ) ,
879+ id : "space_1_id" . into ( ) ,
880+ parent_view_id : workspace_id. into ( ) ,
881+ name : "Space 1" . into ( ) ,
882882 children : RepeatedViewIdentifier :: new ( vec ! [
883883 ViewIdentifier :: new( view_1_id. clone( ) ) ,
884884 ViewIdentifier :: new( view_2_id. clone( ) ) ,
@@ -895,7 +895,7 @@ mod tests {
895895 } ;
896896 let space_view_id = space_view. id . clone ( ) ;
897897 let workspace = Workspace {
898- id : workspace_id. to_string ( ) ,
898+ id : workspace_id. into ( ) ,
899899 name : "Workspace" . to_string ( ) ,
900900 child_views : RepeatedViewIdentifier :: new ( vec ! [ ViewIdentifier :: new( space_view_id. clone( ) ) ] ) ,
901901 created_at : current_time,
@@ -916,12 +916,12 @@ mod tests {
916916 let mut folder = Folder :: create ( collab, None , folder_data) ;
917917
918918 folder. set_current_view ( view_2_id. clone ( ) , uid) ;
919- assert_eq ! ( folder. get_current_view( uid) , Some ( view_2_id. to_string ( ) ) ) ;
919+ assert_eq ! ( folder. get_current_view( uid) , Some ( view_2_id. clone ( ) ) ) ;
920920 // First visit from user 2, should return the first child of the first public space with children.
921- assert_eq ! ( folder. get_current_view( 2 ) , Some ( view_1_id. to_string ( ) ) ) ;
922- folder. set_current_view ( view_1_id. to_string ( ) , 2 ) ;
923- assert_eq ! ( folder. get_current_view( 1 ) , Some ( view_2_id. to_string ( ) ) ) ;
924- assert_eq ! ( folder. get_current_view( 2 ) , Some ( view_1_id. to_string ( ) ) ) ;
921+ assert_eq ! ( folder. get_current_view( 2 ) , Some ( view_1_id. clone ( ) ) ) ;
922+ folder. set_current_view ( view_1_id. clone ( ) , 2 ) ;
923+ assert_eq ! ( folder. get_current_view( 1 ) , Some ( view_2_id) ) ;
924+ assert_eq ! ( folder. get_current_view( 2 ) , Some ( view_1_id) ) ;
925925 }
926926
927927 #[ test]
@@ -931,11 +931,11 @@ mod tests {
931931 let uid = 1 ;
932932 let options = CollabOptions :: new ( workspace_id. to_string ( ) , default_client_id ( ) ) ;
933933 let collab = Collab :: new_with_options ( CollabOrigin :: Empty , options) . unwrap ( ) ;
934- let space_view_id = "space_view_id" . to_string ( ) ;
934+ let space_view_id: ViewId = "space_view_id" . into ( ) ;
935935 let views: Vec < View > = ( 0 ..3 )
936936 . map ( |i| {
937937 View :: new (
938- format ! ( "view_{:?}" , i) ,
938+ format ! ( "view_{:?}" , i) . into ( ) ,
939939 space_view_id. clone ( ) ,
940940 format ! ( "View {:?}" , i) ,
941941 crate :: ViewLayout :: Document ,
@@ -944,9 +944,9 @@ mod tests {
944944 } )
945945 . collect ( ) ;
946946 let space_view = View {
947- id : "space_1_id" . to_string ( ) ,
948- parent_view_id : workspace_id. to_string ( ) ,
949- name : "Space 1" . to_string ( ) ,
947+ id : "space_1_id" . into ( ) ,
948+ parent_view_id : workspace_id. into ( ) ,
949+ name : "Space 1" . into ( ) ,
950950 children : RepeatedViewIdentifier :: new (
951951 views
952952 . iter ( )
@@ -964,7 +964,7 @@ mod tests {
964964 extra : Some ( serde_json:: to_string ( & SpaceInfo :: default ( ) ) . unwrap ( ) ) ,
965965 } ;
966966 let workspace = Workspace {
967- id : workspace_id. to_string ( ) ,
967+ id : workspace_id. into ( ) ,
968968 name : "Workspace" . to_string ( ) ,
969969 child_views : RepeatedViewIdentifier :: new ( vec ! [ ViewIdentifier :: new( space_view_id. clone( ) ) ] ) ,
970970 created_at : current_time,
@@ -996,25 +996,25 @@ mod tests {
996996 let mut folder = Folder :: create ( collab, None , folder_data) ;
997997 let favorite_sections = folder. get_all_favorites_sections ( uid) ;
998998 let expected_favorites = vec ! [
999- SectionItem :: new( "view_0" . to_string ( ) ) ,
1000- SectionItem :: new( "view_1" . to_string ( ) ) ,
1001- SectionItem :: new( "view_2" . to_string ( ) ) ,
999+ SectionItem :: new( "view_0" . into ( ) ) ,
1000+ SectionItem :: new( "view_1" . into ( ) ) ,
1001+ SectionItem :: new( "view_2" . into ( ) ) ,
10021002 ] ;
10031003 assert_eq ! ( favorite_sections, expected_favorites) ;
10041004 folder. move_favorite_view_id ( "view_0" , Some ( "view_1" ) , uid) ;
10051005 let favorite_sections = folder. get_all_favorites_sections ( uid) ;
10061006 let expected_favorites = vec ! [
1007- SectionItem :: new( "view_1" . to_string ( ) ) ,
1008- SectionItem :: new( "view_0" . to_string ( ) ) ,
1009- SectionItem :: new( "view_2" . to_string ( ) ) ,
1007+ SectionItem :: new( "view_1" . into ( ) ) ,
1008+ SectionItem :: new( "view_0" . into ( ) ) ,
1009+ SectionItem :: new( "view_2" . into ( ) ) ,
10101010 ] ;
10111011 assert_eq ! ( favorite_sections, expected_favorites) ;
10121012 folder. move_favorite_view_id ( "view_2" , None , uid) ;
10131013 let favorite_sections = folder. get_all_favorites_sections ( uid) ;
10141014 let expected_favorites = vec ! [
1015- SectionItem :: new( "view_2" . to_string ( ) ) ,
1016- SectionItem :: new( "view_1" . to_string ( ) ) ,
1017- SectionItem :: new( "view_0" . to_string ( ) ) ,
1015+ SectionItem :: new( "view_2" . into ( ) ) ,
1016+ SectionItem :: new( "view_1" . into ( ) ) ,
1017+ SectionItem :: new( "view_0" . into ( ) ) ,
10181018 ] ;
10191019 assert_eq ! ( favorite_sections, expected_favorites) ;
10201020 }
0 commit comments