@@ -11,6 +11,7 @@ use crate::{
1111} ;
1212use flowy_sqlite:: kv:: KV ;
1313use folder_model:: { AppRevision , WorkspaceRevision } ;
14+ use lib_dispatch:: prelude:: ToBytes ;
1415use std:: sync:: Arc ;
1516
1617pub struct WorkspaceController {
@@ -41,7 +42,6 @@ impl WorkspaceController {
4142 ) -> Result < WorkspaceRevision , FlowyError > {
4243 let workspace = self . create_workspace_on_server ( params. clone ( ) ) . await ?;
4344 let user_id = self . user . user_id ( ) ?;
44- let token = self . user . token ( ) ?;
4545 let workspaces = self
4646 . persistence
4747 . begin_transaction ( |transaction| {
@@ -53,9 +53,7 @@ impl WorkspaceController {
5353 . map ( |workspace_rev| workspace_rev. into ( ) )
5454 . collect ( ) ;
5555 let repeated_workspace = RepeatedWorkspacePB { items : workspaces } ;
56- send_notification ( & token, FolderNotification :: DidCreateWorkspace )
57- . payload ( repeated_workspace)
58- . send ( ) ;
56+ send_workspace_notification ( FolderNotification :: DidCreateWorkspace , repeated_workspace) ;
5957 set_current_workspace ( & user_id, & workspace. id ) ;
6058 Ok ( workspace)
6159 }
@@ -76,9 +74,7 @@ impl WorkspaceController {
7674 } )
7775 . await ?;
7876
79- send_notification ( & workspace_id, FolderNotification :: DidUpdateWorkspace )
80- . payload ( workspace)
81- . send ( ) ;
77+ send_workspace_notification ( FolderNotification :: DidUpdateWorkspace , workspace) ;
8278 self . update_workspace_on_server ( params) ?;
8379
8480 Ok ( ( ) )
@@ -87,17 +83,15 @@ impl WorkspaceController {
8783 #[ allow( dead_code) ]
8884 pub ( crate ) async fn delete_workspace ( & self , workspace_id : & str ) -> Result < ( ) , FlowyError > {
8985 let user_id = self . user . user_id ( ) ?;
90- let token = self . user . token ( ) ?;
9186 let repeated_workspace = self
9287 . persistence
9388 . begin_transaction ( |transaction| {
9489 transaction. delete_workspace ( workspace_id) ?;
9590 self . read_workspaces ( None , & user_id, & transaction)
9691 } )
9792 . await ?;
98- send_notification ( & token, FolderNotification :: DidDeleteWorkspace )
99- . payload ( repeated_workspace)
100- . send ( ) ;
93+
94+ send_workspace_notification ( FolderNotification :: DidDeleteWorkspace , repeated_workspace) ;
10195 self . delete_workspace_on_server ( workspace_id) ?;
10296 Ok ( ( ) )
10397 }
@@ -224,7 +218,6 @@ pub async fn notify_workspace_setting_did_change(
224218 view_id : & str ,
225219) -> FlowyResult < ( ) > {
226220 let user_id = folder_manager. user . user_id ( ) ?;
227- let token = folder_manager. user . token ( ) ?;
228221 let workspace_id = get_current_workspace ( & user_id) ?;
229222
230223 let workspace_setting = folder_manager
@@ -250,11 +243,20 @@ pub async fn notify_workspace_setting_did_change(
250243 Ok ( setting)
251244 } )
252245 . await ?;
246+ send_workspace_notification (
247+ FolderNotification :: DidUpdateWorkspaceSetting ,
248+ workspace_setting,
249+ ) ;
250+ Ok ( ( ) )
251+ }
253252
254- send_notification ( & token, FolderNotification :: DidUpdateWorkspaceSetting )
255- . payload ( workspace_setting)
253+ /// The [CURRENT_WORKSPACE] represents as the current workspace that opened by the
254+ /// user. Only one workspace can be opened at a time.
255+ const CURRENT_WORKSPACE : & str = "current-workspace" ;
256+ fn send_workspace_notification < T : ToBytes > ( ty : FolderNotification , payload : T ) {
257+ send_notification ( CURRENT_WORKSPACE , ty)
258+ . payload ( payload)
256259 . send ( ) ;
257- Ok ( ( ) )
258260}
259261
260262const CURRENT_WORKSPACE_ID : & str = "current_workspace_id" ;
0 commit comments