diff --git a/frontend/app_flowy/lib/workspace/application/menu/menu_user_bloc.dart b/frontend/app_flowy/lib/workspace/application/menu/menu_user_bloc.dart index ee024bb1b2..07361cfe45 100644 --- a/frontend/app_flowy/lib/workspace/application/menu/menu_user_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/menu/menu_user_bloc.dart @@ -31,6 +31,17 @@ class MenuUserBloc extends Bloc { fetchWorkspaces: () async { // }, + didReceiveUserProfile: (UserProfile newUserProfile) { + emit(state.copyWith(userProfile: newUserProfile)); + }, + updateUserName: (String name) { + _userService.updateUserProfile(name: name).then((result) { + result.fold( + (l) => null, + (err) => Log.error(err), + ); + }); + }, ); }); } @@ -47,7 +58,12 @@ class MenuUserBloc extends Bloc { result.fold((l) => null, (error) => Log.error(error)); } - void _profileUpdated(Either userProfileOrFailed) {} + void _profileUpdated(Either userProfileOrFailed) { + userProfileOrFailed.fold( + (newUserProfile) => add(MenuUserEvent.didReceiveUserProfile(newUserProfile)), + (err) => Log.error(err), + ); + } void _workspaceListUpdated(Either, FlowyError> workspacesOrFailed) { // Do nothing by now @@ -58,6 +74,8 @@ class MenuUserBloc extends Bloc { class MenuUserEvent with _$MenuUserEvent { const factory MenuUserEvent.initial() = _Initial; const factory MenuUserEvent.fetchWorkspaces() = _FetchWorkspaces; + const factory MenuUserEvent.updateUserName(String name) = _UpdateUserName; + const factory MenuUserEvent.didReceiveUserProfile(UserProfile newUserProfile) = _DidReceiveUserProfile; } @freezed diff --git a/frontend/rust-lib/flowy-user/src/services/user_session.rs b/frontend/rust-lib/flowy-user/src/services/user_session.rs index cf81b6be89..8167b05a19 100644 --- a/frontend/rust-lib/flowy-user/src/services/user_session.rs +++ b/frontend/rust-lib/flowy-user/src/services/user_session.rs @@ -183,23 +183,23 @@ impl UserSession { } impl UserSession { - fn read_user_profile_on_server(&self, token: &str) -> Result<(), FlowyError> { - let server = self.cloud_service.clone(); - let token = token.to_owned(); - tokio::spawn(async move { - match server.get_user(&token).await { - Ok(profile) => { - // dart_notify(&token, UserNotification::UserProfileUpdated) - // .payload(profile) - // .send(); - } - Err(_e) => { - // dart_notify(&token, UserNotification::UserProfileUpdated) - // .error(e) - // .send(); - } - } - }); + fn read_user_profile_on_server(&self, _token: &str) -> Result<(), FlowyError> { + // let server = self.cloud_service.clone(); + // let token = token.to_owned(); + // tokio::spawn(async move { + // match server.get_user(&token).await { + // Ok(profile) => { + // dart_notify(&token, UserNotification::UserProfileUpdated) + // .payload(profile) + // .send(); + // } + // Err(e) => { + // dart_notify(&token, UserNotification::UserProfileUpdated) + // .error(e) + // .send(); + // } + // } + // }); Ok(()) }