Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.
Dart blogconfluence-alternativecontent-managementcontent-servicesdocumentationflutternote-takingnotion-alternativeproject-managementtask-managementteam-collaborationwiki
fix: create default workspace after sign in
appflowy64b8f37470fd
diff --git a/app_flowy/lib/user/application/sign_in/sign_in_bloc.dart b/app_flowy/lib/user/application/sign_in/sign_in_bloc.dartindex c17bcadd1e..8bb9a87ff8 100644--- a/app_flowy/lib/user/application/sign_in/sign_in_bloc.dart+++ b/app_flowy/lib/user/application/sign_in/sign_in_bloc.dart@@ -5,8 +5,6 @@ import 'package:freezed_annotation/freezed_annotation.dart';// ignore: import_of_legacy_library_into_null_safeimport 'package:flutter_bloc/flutter_bloc.dart';-part 'sign_in_event.dart';-part 'sign_in_state.dart';part 'sign_in_bloc.freezed.dart';class SignInBloc extends Bloc<SignInEvent, SignInState> {@@ -43,3 +41,27 @@ class SignInBloc extends Bloc<SignInEvent, SignInState> {);}}++@freezed+abstract class SignInEvent with _$SignInEvent {+ const factory SignInEvent.signedInWithUserEmailAndPassword() =+ SignedInWithUserEmailAndPassword;++ const factory SignInEvent.emailChanged(String email) = EmailChanged;+ const factory SignInEvent.passwordChanged(String password) = PasswordChanged;+}++@freezed+abstract class SignInState with _$SignInState {+ const factory SignInState({+ String? email,+ String? password,+ required bool isSubmitting,+ required Option<Either<UserDetail, UserError>> signInFailure,+ }) = _SignInState;++ factory SignInState.initial() => SignInState(+ isSubmitting: false,+ signInFailure: none(),+ );+}diff --git a/app_flowy/lib/user/application/sign_in/sign_in_event.dart b/app_flowy/lib/user/application/sign_in/sign_in_event.dartdeleted file mode 100644index 702afea0bc..0000000000--- a/app_flowy/lib/user/application/sign_in/sign_in_event.dart+++ /dev/null@@ -1,10 +0,0 @@-part of 'sign_in_bloc.dart';--@freezed-abstract class SignInEvent with _$SignInEvent {- const factory SignInEvent.signedInWithUserEmailAndPassword() =- SignedInWithUserEmailAndPassword;-- const factory SignInEvent.emailChanged(String email) = EmailChanged;- const factory SignInEvent.passwordChanged(String password) = PasswordChanged;-}diff --git a/app_flowy/lib/user/application/sign_in/sign_in_state.dart b/app_flowy/lib/user/application/sign_in/sign_in_state.dartdeleted file mode 100644index 76555cb38b..0000000000--- a/app_flowy/lib/user/application/sign_in/sign_in_state.dart+++ /dev/null@@ -1,16 +0,0 @@-part of 'sign_in_bloc.dart';--@freezed-abstract class SignInState with _$SignInState {- const factory SignInState({- String? email,- String? password,- required bool isSubmitting,- required Option<Either<UserDetail, UserError>> signInFailure,- }) = _SignInState;-- factory SignInState.initial() => SignInState(- isSubmitting: false,- signInFailure: none(),- );-}diff --git a/app_flowy/lib/welcome/application/welcome_bloc.dart b/app_flowy/lib/welcome/application/welcome_bloc.dartindex 39a142fd56..6595029a4a 100644--- a/app_flowy/lib/welcome/application/welcome_bloc.dart+++ b/app_flowy/lib/welcome/application/welcome_bloc.dart@@ -3,8 +3,6 @@ import 'package:app_flowy/welcome/domain/i_welcome.dart';import 'package:flutter_bloc/flutter_bloc.dart';import 'package:freezed_annotation/freezed_annotation.dart';-part 'welcome_event.dart';-part 'welcome_state.dart';part 'welcome_bloc.freezed.dart';class WelcomeBloc extends Bloc<WelcomeEvent, WelcomeState> {@@ -21,3 +19,19 @@ class WelcomeBloc extends Bloc<WelcomeEvent, WelcomeState> {);}}++@freezed+abstract class WelcomeEvent with _$WelcomeEvent {+ const factory WelcomeEvent.getUser() = _GetUser;+}++@freezed+abstract class WelcomeState implements _$WelcomeState {+ const factory WelcomeState({+ required AuthState auth,+ }) = _WelcomeState;++ factory WelcomeState.initial() => const WelcomeState(+ auth: AuthState.initial(),+ );+}diff --git a/app_flowy/lib/welcome/application/welcome_event.dart b/app_flowy/lib/welcome/application/welcome_event.dartdeleted file mode 100644index 0ade68c9df..0000000000--- a/app_flowy/lib/welcome/application/welcome_event.dart+++ /dev/null@@ -1,6 +0,0 @@-part of 'welcome_bloc.dart';--@freezed-abstract class WelcomeEvent with _$WelcomeEvent {- const factory WelcomeEvent.getUser() = _GetUser;-}diff --git a/app_flowy/lib/welcome/application/welcome_state.dart b/app_flowy/lib/welcome/application/welcome_state.dartdeleted file mode 100644index 04ba534244..0000000000--- a/app_flowy/lib/welcome/application/welcome_state.dart+++ /dev/null@@ -1,12 +0,0 @@-part of 'welcome_bloc.dart';--@freezed-abstract class WelcomeState implements _$WelcomeState {- const factory WelcomeState({- required AuthState auth,- }) = _WelcomeState;-- factory WelcomeState.initial() => const WelcomeState(- auth: AuthState.initial(),- );-}diff --git a/app_flowy/lib/workspace/presentation/widgets/menu/app_list.dart b/app_flowy/lib/workspace/presentation/widgets/menu/app_list.dartindex 4f302b4886..ddb50cb832 100644--- a/app_flowy/lib/workspace/presentation/widgets/menu/app_list.dart+++ b/app_flowy/lib/workspace/presentation/widgets/menu/app_list.dart@@ -11,7 +11,7 @@ class AppList extends StatelessWidget {@overrideWidget build(BuildContext context) {return apps.fold(() {- return const Text('You have no apps, create one?');+ return const Expanded(child: Text('You have no apps, create one?'));}, (apps) {return ExpandableTheme(data: const ExpandableThemeData(diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user/errors.pbenum.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user/errors.pbenum.dartindex 28205f8984..42ddf173b1 100644--- a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user/errors.pbenum.dart+++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user/errors.pbenum.dart@@ -25,6 +25,7 @@ class UserErrorCode extends $pb.ProtobufEnum {static const UserErrorCode UserWorkspaceInvalid = UserErrorCode._(23, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'UserWorkspaceInvalid');static const UserErrorCode UserIdInvalid = UserErrorCode._(24, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'UserIdInvalid');static const UserErrorCode CreateDefaultWorkspaceFailed = UserErrorCode._(25, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'CreateDefaultWorkspaceFailed');+ static const UserErrorCode DefaultWorkspaceAlreadyExist = UserErrorCode._(26, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'DefaultWorkspaceAlreadyExist');static const $core.List<UserErrorCode> values = <UserErrorCode> [Unknown,@@ -42,6 +43,7 @@ class UserErrorCode extends $pb.ProtobufEnum {UserWorkspaceInvalid,UserIdInvalid,CreateDefaultWorkspaceFailed,+ DefaultWorkspaceAlreadyExist,];static final $core.Map<$core.int, UserErrorCode> _byValue = $pb.ProtobufEnum.initByValue(values);diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user/errors.pbjson.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user/errors.pbjson.dartindex 70e80819c6..3bf44c6ee6 100644--- a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user/errors.pbjson.dart+++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user/errors.pbjson.dart@@ -27,11 +27,12 @@ const UserErrorCode$json = const {const {'1': 'UserWorkspaceInvalid', '2': 23},const {'1': 'UserIdInvalid', '2': 24},const {'1': 'CreateDefaultWorkspaceFailed', '2': 25},+ const {'1': 'DefaultWorkspaceAlreadyExist', '2': 26},],};/// Descriptor for `UserErrorCode`. Decode as a `google.protobuf.EnumDescriptorProto`.-final $typed_data.Uint8List userErrorCodeDescriptor = $convert.base64Decode('Cg1Vc2VyRXJyb3JDb2RlEgsKB1Vua25vd24QABIaChZVc2VyRGF0YWJhc2VJbml0RmFpbGVkEAESGwoXVXNlckRhdGFiYXNlV3JpdGVMb2NrZWQQAhIaChZVc2VyRGF0YWJhc2VSZWFkTG9ja2VkEAMSGwoXVXNlckRhdGFiYXNlRGlkTm90TWF0Y2gQBBIdChlVc2VyRGF0YWJhc2VJbnRlcm5hbEVycm9yEAUSEwoPVXNlck5vdExvZ2luWWV0EAoSFwoTUmVhZEN1cnJlbnRJZEZhaWxlZBALEhgKFFdyaXRlQ3VycmVudElkRmFpbGVkEAwSEAoMRW1haWxJbnZhbGlkEBQSEwoPUGFzc3dvcmRJbnZhbGlkEBUSEwoPVXNlck5hbWVJbnZhbGlkEBYSGAoUVXNlcldvcmtzcGFjZUludmFsaWQQFxIRCg1Vc2VySWRJbnZhbGlkEBgSIAocQ3JlYXRlRGVmYXVsdFdvcmtzcGFjZUZhaWxlZBAZ');+final $typed_data.Uint8List userErrorCodeDescriptor = $convert.base64Decode('Cg1Vc2VyRXJyb3JDb2RlEgsKB1Vua25vd24QABIaChZVc2VyRGF0YWJhc2VJbml0RmFpbGVkEAESGwoXVXNlckRhdGFiYXNlV3JpdGVMb2NrZWQQAhIaChZVc2VyRGF0YWJhc2VSZWFkTG9ja2VkEAMSGwoXVXNlckRhdGFiYXNlRGlkTm90TWF0Y2gQBBIdChlVc2VyRGF0YWJhc2VJbnRlcm5hbEVycm9yEAUSEwoPVXNlck5vdExvZ2luWWV0EAoSFwoTUmVhZEN1cnJlbnRJZEZhaWxlZBALEhgKFFdyaXRlQ3VycmVudElkRmFpbGVkEAwSEAoMRW1haWxJbnZhbGlkEBQSEwoPUGFzc3dvcmRJbnZhbGlkEBUSEwoPVXNlck5hbWVJbnZhbGlkEBYSGAoUVXNlcldvcmtzcGFjZUludmFsaWQQFxIRCg1Vc2VySWRJbnZhbGlkEBgSIAocQ3JlYXRlRGVmYXVsdFdvcmtzcGFjZUZhaWxlZBAZEiAKHERlZmF1bHRXb3Jrc3BhY2VBbHJlYWR5RXhpc3QQGg==');@$core.Deprecated('Use userErrorDescriptor instead')const UserError$json = const {'1': 'UserError',diff --git a/rust-lib/flowy-sdk/src/flowy_server.rs b/rust-lib/flowy-sdk/src/flowy_server.rsindex 08d5a8ea84..9fc7f577d7 100644--- a/rust-lib/flowy-sdk/src/flowy_server.rs+++ b/rust-lib/flowy-sdk/src/flowy_server.rs@@ -53,7 +53,8 @@ impl UserServer for FlowyServerMocker {name: &str,desc: &str,_user_id: &str,- ) -> DispatchFuture<Result<(), UserError>> {+ ) -> DispatchFuture<Result<String, UserError>> {+ log::info!("Create user workspace: {:?}", name);let payload: Vec<u8> = CreateWorkspaceRequest {name: name.to_string(),desc: desc.to_string(),@@ -64,7 +65,7 @@ impl UserServer for FlowyServerMocker {let request = ModuleRequest::new(CreateWorkspace).payload(payload);DispatchFuture {fut: Box::pin(async move {- let _ = EventDispatch::async_send(request)+ let result = EventDispatch::async_send(request).await.parse::<Workspace, WorkspaceError>().map_err(|e| {@@ -72,7 +73,13 @@ impl UserServer for FlowyServerMocker {.error(e).build()})?;- Ok(())++ let workspace = result.map_err(|e| {+ ErrorBuilder::new(UserErrorCode::CreateDefaultWorkspaceFailed)+ .error(e)+ .build()+ })?;+ Ok(workspace.id)}),}}diff --git a/rust-lib/flowy-user/src/errors.rs b/rust-lib/flowy-user/src/errors.rsindex ce8ec37830..454cbf8ec3 100644--- a/rust-lib/flowy-user/src/errors.rs+++ b/rust-lib/flowy-user/src/errors.rs@@ -55,6 +55,9 @@ pub enum UserErrorCode {UserIdInvalid = 24,#[display(fmt = "Create user default workspace failed")]CreateDefaultWorkspaceFailed = 25,++ #[display(fmt = "User default workspace already exists")]+ DefaultWorkspaceAlreadyExist = 26,}impl std::default::Default for UserErrorCode {diff --git a/rust-lib/flowy-user/src/protobuf/model/errors.rs b/rust-lib/flowy-user/src/protobuf/model/errors.rsindex 5c5e9468e0..07209a5631 100644--- a/rust-lib/flowy-user/src/protobuf/model/errors.rs+++ b/rust-lib/flowy-user/src/protobuf/model/errors.rs@@ -230,6 +230,7 @@ pub enum UserErrorCode {UserWorkspaceInvalid = 23,UserIdInvalid = 24,CreateDefaultWorkspaceFailed = 25,+ DefaultWorkspaceAlreadyExist = 26,}impl ::protobuf::ProtobufEnum for UserErrorCode {@@ -254,6 +255,7 @@ impl ::protobuf::ProtobufEnum for UserErrorCode {23 => ::std::option::Option::Some(UserErrorCode::UserWorkspaceInvalid),24 => ::std::option::Option::Some(UserErrorCode::UserIdInvalid),25 => ::std::option::Option::Some(UserErrorCode::CreateDefaultWorkspaceFailed),+ 26 => ::std::option::Option::Some(UserErrorCode::DefaultWorkspaceAlreadyExist),_ => ::std::option::Option::None}}@@ -275,6 +277,7 @@ impl ::protobuf::ProtobufEnum for UserErrorCode {UserErrorCode::UserWorkspaceInvalid,UserErrorCode::UserIdInvalid,UserErrorCode::CreateDefaultWorkspaceFailed,+ UserErrorCode::DefaultWorkspaceAlreadyExist,];values}@@ -305,7 +308,7 @@ impl ::protobuf::reflect::ProtobufValue for UserErrorCode {static file_descriptor_proto_data: &'static [u8] = b"\\n\x0cerrors.proto\"A\n\tUserError\x12\"\n\x04code\x18\x01\x20\x01(\x0e2\\x0e.UserErrorCodeR\x04code\x12\x10\n\x03msg\x18\x02\x20\x01(\tR\x03msg*\- \x80\x03\n\rUserErrorCode\x12\x0b\n\x07Unknown\x10\0\x12\x1a\n\x16UserDa\+ \xa2\x03\n\rUserErrorCode\x12\x0b\n\x07Unknown\x10\0\x12\x1a\n\x16UserDa\tabaseInitFailed\x10\x01\x12\x1b\n\x17UserDatabaseWriteLocked\x10\x02\\x12\x1a\n\x16UserDatabaseReadLocked\x10\x03\x12\x1b\n\x17UserDatabaseDi\dNotMatch\x10\x04\x12\x1d\n\x19UserDatabaseInternalError\x10\x05\x12\x13\@@ -313,46 +316,49 @@ static file_descriptor_proto_data: &'static [u8] = b"\\x18\n\x14WriteCurrentIdFailed\x10\x0c\x12\x10\n\x0cEmailInvalid\x10\x14\\x12\x13\n\x0fPasswordInvalid\x10\x15\x12\x13\n\x0fUserNameInvalid\x10\\x16\x12\x18\n\x14UserWorkspaceInvalid\x10\x17\x12\x11\n\rUserIdInvalid\- \x10\x18\x12\x20\n\x1cCreateDefaultWorkspaceFailed\x10\x19J\x97\x06\n\- \x06\x12\x04\0\0\x16\x01\n\x08\n\x01\x0c\x12\x03\0\0\x12\n\n\n\x02\x04\0\- \x12\x04\x02\0\x05\x01\n\n\n\x03\x04\0\x01\x12\x03\x02\x08\x11\n\x0b\n\- \x04\x04\0\x02\0\x12\x03\x03\x04\x1b\n\x0c\n\x05\x04\0\x02\0\x06\x12\x03\- \x03\x04\x11\n\x0c\n\x05\x04\0\x02\0\x01\x12\x03\x03\x12\x16\n\x0c\n\x05\- \x04\0\x02\0\x03\x12\x03\x03\x19\x1a\n\x0b\n\x04\x04\0\x02\x01\x12\x03\- \x04\x04\x13\n\x0c\n\x05\x04\0\x02\x01\x05\x12\x03\x04\x04\n\n\x0c\n\x05\- \x04\0\x02\x01\x01\x12\x03\x04\x0b\x0e\n\x0c\n\x05\x04\0\x02\x01\x03\x12\- \x03\x04\x11\x12\n\n\n\x02\x05\0\x12\x04\x06\0\x16\x01\n\n\n\x03\x05\0\- \x01\x12\x03\x06\x05\x12\n\x0b\n\x04\x05\0\x02\0\x12\x03\x07\x04\x10\n\- \x0c\n\x05\x05\0\x02\0\x01\x12\x03\x07\x04\x0b\n\x0c\n\x05\x05\0\x02\0\- \x02\x12\x03\x07\x0e\x0f\n\x0b\n\x04\x05\0\x02\x01\x12\x03\x08\x04\x1f\n\- \x0c\n\x05\x05\0\x02\x01\x01\x12\x03\x08\x04\x1a\n\x0c\n\x05\x05\0\x02\- \x01\x02\x12\x03\x08\x1d\x1e\n\x0b\n\x04\x05\0\x02\x02\x12\x03\t\x04\x20\- \n\x0c\n\x05\x05\0\x02\x02\x01\x12\x03\t\x04\x1b\n\x0c\n\x05\x05\0\x02\- \x02\x02\x12\x03\t\x1e\x1f\n\x0b\n\x04\x05\0\x02\x03\x12\x03\n\x04\x1f\n\- \x0c\n\x05\x05\0\x02\x03\x01\x12\x03\n\x04\x1a\n\x0c\n\x05\x05\0\x02\x03\- \x02\x12\x03\n\x1d\x1e\n\x0b\n\x04\x05\0\x02\x04\x12\x03\x0b\x04\x20\n\- \x0c\n\x05\x05\0\x02\x04\x01\x12\x03\x0b\x04\x1b\n\x0c\n\x05\x05\0\x02\- \x04\x02\x12\x03\x0b\x1e\x1f\n\x0b\n\x04\x05\0\x02\x05\x12\x03\x0c\x04\"\- \n\x0c\n\x05\x05\0\x02\x05\x01\x12\x03\x0c\x04\x1d\n\x0c\n\x05\x05\0\x02\- \x05\x02\x12\x03\x0c\x20!\n\x0b\n\x04\x05\0\x02\x06\x12\x03\r\x04\x19\n\- \x0c\n\x05\x05\0\x02\x06\x01\x12\x03\r\x04\x13\n\x0c\n\x05\x05\0\x02\x06\- \x02\x12\x03\r\x16\x18\n\x0b\n\x04\x05\0\x02\x07\x12\x03\x0e\x04\x1d\n\- \x0c\n\x05\x05\0\x02\x07\x01\x12\x03\x0e\x04\x17\n\x0c\n\x05\x05\0\x02\- \x07\x02\x12\x03\x0e\x1a\x1c\n\x0b\n\x04\x05\0\x02\x08\x12\x03\x0f\x04\- \x1e\n\x0c\n\x05\x05\0\x02\x08\x01\x12\x03\x0f\x04\x18\n\x0c\n\x05\x05\0\- \x02\x08\x02\x12\x03\x0f\x1b\x1d\n\x0b\n\x04\x05\0\x02\t\x12\x03\x10\x04\- \x16\n\x0c\n\x05\x05\0\x02\t\x01\x12\x03\x10\x04\x10\n\x0c\n\x05\x05\0\- \x02\t\x02\x12\x03\x10\x13\x15\n\x0b\n\x04\x05\0\x02\n\x12\x03\x11\x04\- \x19\n\x0c\n\x05\x05\0\x02\n\x01\x12\x03\x11\x04\x13\n\x0c\n\x05\x05\0\- \x02\n\x02\x12\x03\x11\x16\x18\n\x0b\n\x04\x05\0\x02\x0b\x12\x03\x12\x04\- \x19\n\x0c\n\x05\x05\0\x02\x0b\x01\x12\x03\x12\x04\x13\n\x0c\n\x05\x05\0\- \x02\x0b\x02\x12\x03\x12\x16\x18\n\x0b\n\x04\x05\0\x02\x0c\x12\x03\x13\- \x04\x1e\n\x0c\n\x05\x05\0\x02\x0c\x01\x12\x03\x13\x04\x18\n\x0c\n\x05\- \x05\0\x02\x0c\x02\x12\x03\x13\x1b\x1d\n\x0b\n\x04\x05\0\x02\r\x12\x03\- \x14\x04\x17\n\x0c\n\x05\x05\0\x02\r\x01\x12\x03\x14\x04\x11\n\x0c\n\x05\- \x05\0\x02\r\x02\x12\x03\x14\x14\x16\n\x0b\n\x04\x05\0\x02\x0e\x12\x03\- \x15\x04&\n\x0c\n\x05\x05\0\x02\x0e\x01\x12\x03\x15\x04\x20\n\x0c\n\x05\- \x05\0\x02\x0e\x02\x12\x03\x15#%b\x06proto3\+ \x10\x18\x12\x20\n\x1cCreateDefaultWorkspaceFailed\x10\x19\x12\x20\n\x1c\+ DefaultWorkspaceAlreadyExist\x10\x1aJ\xc0\x06\n\x06\x12\x04\0\0\x17\x01\+ \n\x08\n\x01\x0c\x12\x03\0\0\x12\n\n\n\x02\x04\0\x12\x04\x02\0\x05\x01\n\+ \n\n\x03\x04\0\x01\x12\x03\x02\x08\x11\n\x0b\n\x04\x04\0\x02\0\x12\x03\+ \x03\x04\x1b\n\x0c\n\x05\x04\0\x02\0\x06\x12\x03\x03\x04\x11\n\x0c\n\x05\+ \x04\0\x02\0\x01\x12\x03\x03\x12\x16\n\x0c\n\x05\x04\0\x02\0\x03\x12\x03\+ \x03\x19\x1a\n\x0b\n\x04\x04\0\x02\x01\x12\x03\x04\x04\x13\n\x0c\n\x05\+ \x04\0\x02\x01\x05\x12\x03\x04\x04\n\n\x0c\n\x05\x04\0\x02\x01\x01\x12\+ \x03\x04\x0b\x0e\n\x0c\n\x05\x04\0\x02\x01\x03\x12\x03\x04\x11\x12\n\n\n\+ \x02\x05\0\x12\x04\x06\0\x17\x01\n\n\n\x03\x05\0\x01\x12\x03\x06\x05\x12\+ \n\x0b\n\x04\x05\0\x02\0\x12\x03\x07\x04\x10\n\x0c\n\x05\x05\0\x02\0\x01\+ \x12\x03\x07\x04\x0b\n\x0c\n\x05\x05\0\x02\0\x02\x12\x03\x07\x0e\x0f\n\+ \x0b\n\x04\x05\0\x02\x01\x12\x03\x08\x04\x1f\n\x0c\n\x05\x05\0\x02\x01\+ \x01\x12\x03\x08\x04\x1a\n\x0c\n\x05\x05\0\x02\x01\x02\x12\x03\x08\x1d\+ \x1e\n\x0b\n\x04\x05\0\x02\x02\x12\x03\t\x04\x20\n\x0c\n\x05\x05\0\x02\+ \x02\x01\x12\x03\t\x04\x1b\n\x0c\n\x05\x05\0\x02\x02\x02\x12\x03\t\x1e\+ \x1f\n\x0b\n\x04\x05\0\x02\x03\x12\x03\n\x04\x1f\n\x0c\n\x05\x05\0\x02\+ \x03\x01\x12\x03\n\x04\x1a\n\x0c\n\x05\x05\0\x02\x03\x02\x12\x03\n\x1d\+ \x1e\n\x0b\n\x04\x05\0\x02\x04\x12\x03\x0b\x04\x20\n\x0c\n\x05\x05\0\x02\+ \x04\x01\x12\x03\x0b\x04\x1b\n\x0c\n\x05\x05\0\x02\x04\x02\x12\x03\x0b\+ \x1e\x1f\n\x0b\n\x04\x05\0\x02\x05\x12\x03\x0c\x04\"\n\x0c\n\x05\x05\0\+ \x02\x05\x01\x12\x03\x0c\x04\x1d\n\x0c\n\x05\x05\0\x02\x05\x02\x12\x03\+ \x0c\x20!\n\x0b\n\x04\x05\0\x02\x06\x12\x03\r\x04\x19\n\x0c\n\x05\x05\0\+ \x02\x06\x01\x12\x03\r\x04\x13\n\x0c\n\x05\x05\0\x02\x06\x02\x12\x03\r\+ \x16\x18\n\x0b\n\x04\x05\0\x02\x07\x12\x03\x0e\x04\x1d\n\x0c\n\x05\x05\0\+ \x02\x07\x01\x12\x03\x0e\x04\x17\n\x0c\n\x05\x05\0\x02\x07\x02\x12\x03\+ \x0e\x1a\x1c\n\x0b\n\x04\x05\0\x02\x08\x12\x03\x0f\x04\x1e\n\x0c\n\x05\+ \x05\0\x02\x08\x01\x12\x03\x0f\x04\x18\n\x0c\n\x05\x05\0\x02\x08\x02\x12\+ \x03\x0f\x1b\x1d\n\x0b\n\x04\x05\0\x02\t\x12\x03\x10\x04\x16\n\x0c\n\x05\+ \x05\0\x02\t\x01\x12\x03\x10\x04\x10\n\x0c\n\x05\x05\0\x02\t\x02\x12\x03\+ \x10\x13\x15\n\x0b\n\x04\x05\0\x02\n\x12\x03\x11\x04\x19\n\x0c\n\x05\x05\+ \0\x02\n\x01\x12\x03\x11\x04\x13\n\x0c\n\x05\x05\0\x02\n\x02\x12\x03\x11\+ \x16\x18\n\x0b\n\x04\x05\0\x02\x0b\x12\x03\x12\x04\x19\n\x0c\n\x05\x05\0\+ \x02\x0b\x01\x12\x03\x12\x04\x13\n\x0c\n\x05\x05\0\x02\x0b\x02\x12\x03\+ \x12\x16\x18\n\x0b\n\x04\x05\0\x02\x0c\x12\x03\x13\x04\x1e\n\x0c\n\x05\+ \x05\0\x02\x0c\x01\x12\x03\x13\x04\x18\n\x0c\n\x05\x05\0\x02\x0c\x02\x12\+ \x03\x13\x1b\x1d\n\x0b\n\x04\x05\0\x02\r\x12\x03\x14\x04\x17\n\x0c\n\x05\+ \x05\0\x02\r\x01\x12\x03\x14\x04\x11\n\x0c\n\x05\x05\0\x02\r\x02\x12\x03\+ \x14\x14\x16\n\x0b\n\x04\x05\0\x02\x0e\x12\x03\x15\x04&\n\x0c\n\x05\x05\+ \0\x02\x0e\x01\x12\x03\x15\x04\x20\n\x0c\n\x05\x05\0\x02\x0e\x02\x12\x03\+ \x15#%\n\x0b\n\x04\x05\0\x02\x0f\x12\x03\x16\x04&\n\x0c\n\x05\x05\0\x02\+ \x0f\x01\x12\x03\x16\x04\x20\n\x0c\n\x05\x05\0\x02\x0f\x02\x12\x03\x16#%\+ b\x06proto3\";static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT;diff --git a/rust-lib/flowy-user/src/protobuf/proto/errors.proto b/rust-lib/flowy-user/src/protobuf/proto/errors.protoindex 1e644873fa..dfccb02b99 100644--- a/rust-lib/flowy-user/src/protobuf/proto/errors.proto+++ b/rust-lib/flowy-user/src/protobuf/proto/errors.proto@@ -20,4 +20,5 @@ enum UserErrorCode {UserWorkspaceInvalid = 23;UserIdInvalid = 24;CreateDefaultWorkspaceFailed = 25;+ DefaultWorkspaceAlreadyExist = 26;}diff --git a/rust-lib/flowy-user/src/services/user_session/user_server.rs b/rust-lib/flowy-user/src/services/user_session/user_server.rsindex ab9085b535..868b8d2b34 100644--- a/rust-lib/flowy-user/src/services/user_session/user_server.rs+++ b/rust-lib/flowy-user/src/services/user_session/user_server.rs@@ -19,5 +19,5 @@ pub trait UserServer {name: &str,desc: &str,user_id: &str,- ) -> DispatchFuture<Result<(), UserError>>;+ ) -> DispatchFuture<Result<String, UserError>>;}diff --git a/rust-lib/flowy-user/src/services/user_session/user_session.rs b/rust-lib/flowy-user/src/services/user_session/user_session.rsindex 72fffa4234..92dc040098 100644--- a/rust-lib/flowy-user/src/services/user_session/user_session.rs+++ b/rust-lib/flowy-user/src/services/user_session/user_session.rs@@ -63,21 +63,16 @@ impl UserSession {pub async fn sign_in(&self, params: SignInParams) -> Result<UserTable, UserError> {let user = self.server.sign_in(params)?;let _ = self.set_user_id(Some(user.id.clone()))?;+ let user_table = self.save_user(user).await?;- let user_table = self.save_user(user)?;- let _ = self- .create_default_workspace_if_need(&user_table.id)- .await?;Ok(user_table)}pub async fn sign_up(&self, params: SignUpParams) -> Result<UserTable, UserError> {let user = self.server.sign_up(params)?;let _ = self.set_user_id(Some(user.id.clone()))?;- let user_table = self.save_user(user)?;- let _ = self- .create_default_workspace_if_need(&user_table.id)- .await?;+ let user_table = self.save_user(user).await?;+Ok(user_table)}@@ -96,7 +91,13 @@ impl UserSession {Ok(())}- fn save_user(&self, user: UserTable) -> Result<UserTable, UserError> {+ async fn save_user(&self, mut user: UserTable) -> Result<UserTable, UserError> {+ if user.workspace.is_empty() {+ log::info!("Try to create user default workspace");+ let workspace_id = self.create_default_workspace_if_need(&user.id).await?;+ user.workspace = workspace_id;+ }+let conn = self.get_db_connection()?;let _ = diesel::insert_into(user_table::table).values(user.clone())@@ -188,19 +189,18 @@ impl UserSession {Ok(())}- async fn create_default_workspace_if_need(&self, user_id: &str) -> Result<(), UserError> {+ async fn create_default_workspace_if_need(&self, user_id: &str) -> Result<String, UserError> {let key = format!("{}{}", user_id, DEFAULT_WORKSPACE);if KVStore::get_bool(&key).unwrap_or(false) {- return Ok(());+ return Err(ErrorBuilder::new(UserErrorCode::DefaultWorkspaceAlreadyExist).build());}-KVStore::set_bool(&key, true);log::debug!("Create user:{} default workspace", user_id);- let _ = self+ let workspace_id = self.server.create_workspace(DEFAULT_WORKSPACE_NAME, DEFAULT_WORKSPACE_DESC, user_id).await?;- Ok(())+ Ok(workspace_id)}}diff --git a/rust-lib/flowy-workspace/src/services/workspace_controller.rs b/rust-lib/flowy-workspace/src/services/workspace_controller.rsindex 22e9e14649..13564a173f 100644--- a/rust-lib/flowy-workspace/src/services/workspace_controller.rs+++ b/rust-lib/flowy-workspace/src/services/workspace_controller.rs@@ -36,7 +36,7 @@ impl WorkspaceController {let workspace_table = WorkspaceTable::new(params);let detail: Workspace = workspace_table.clone().into();let _ = self.sql.create_workspace(workspace_table)?;- let _ = self.user.set_cur_workspace_id(&detail.id).await?;+ // let _ = self.user.set_cur_workspace_id(&detail.id).await?;Ok(detail)}