Skip to content

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.

chore: remove unused code

Nathand478ecfd416f
diff --git a/frontend/appflowy_flutter/lib/mobile/presentation/home/workspaces/workspace_menu_bottom_sheet.dart b/frontend/appflowy_flutter/lib/mobile/presentation/home/workspaces/workspace_menu_bottom_sheet.dart
index ef7f4492a5..eff2b4f420 100644
--- a/frontend/appflowy_flutter/lib/mobile/presentation/home/workspaces/workspace_menu_bottom_sheet.dart
+++ b/frontend/appflowy_flutter/lib/mobile/presentation/home/workspaces/workspace_menu_bottom_sheet.dart
@@ -123,6 +123,7 @@ class _CreateWorkspaceButton extends StatelessWidget {
context.read<UserWorkspaceBloc>().add(
UserWorkspaceEvent.createWorkspace(
name,
+ AuthTypePB.CloudAuthType,
),
);
},
diff --git a/frontend/appflowy_flutter/lib/startup/tasks/generate_router.dart b/frontend/appflowy_flutter/lib/startup/tasks/generate_router.dart
index 7f9a2df329..e64e0f98de 100644
--- a/frontend/appflowy_flutter/lib/startup/tasks/generate_router.dart
+++ b/frontend/appflowy_flutter/lib/startup/tasks/generate_router.dart
@@ -119,18 +119,6 @@ GoRouter generateRouter(Widget child) {
);
},
),
- GoRoute(
- path: SignUpScreen.routeName,
- pageBuilder: (context, state) {
- return CustomTransitionPage(
- child: SignUpScreen(
- router: getIt<AuthRouter>(),
- ),
- transitionsBuilder: _buildFadeTransition,
- transitionDuration: _slowDuration,
- );
- },
- ),
],
);
}
diff --git a/frontend/appflowy_flutter/lib/user/application/user_service.dart b/frontend/appflowy_flutter/lib/user/application/user_service.dart
index 5e163b4e62..3ec181e009 100644
--- a/frontend/appflowy_flutter/lib/user/application/user_service.dart
+++ b/frontend/appflowy_flutter/lib/user/application/user_service.dart
@@ -140,25 +140,13 @@ class UserBackendService implements IUserBackendService {
});
}
- Future<FlowyResult<WorkspacePB, FlowyError>> createWorkspace(
- String name,
- String desc,
- ) {
- final request = CreateWorkspacePayloadPB.create()
- ..name = name
- ..desc = desc;
- return FolderEventCreateFolderWorkspace(request).send().then((result) {
- return result.fold(
- (workspace) => FlowyResult.success(workspace),
- (error) => FlowyResult.failure(error),
- );
- });
- }
-
Future<FlowyResult<UserWorkspacePB, FlowyError>> createUserWorkspace(
String name,
+ AuthTypePB authType,
) {
- final request = CreateWorkspacePB.create()..name = name;
+ final request = CreateWorkspacePB.create()
+ ..name = name
+ ..authType = authType;
return UserEventCreateWorkspace(request).send();
}
diff --git a/frontend/appflowy_flutter/lib/user/presentation/helpers/handle_user_profile_result.dart b/frontend/appflowy_flutter/lib/user/presentation/helpers/handle_user_profile_result.dart
deleted file mode 100644
index 83007786f1..0000000000
--- a/frontend/appflowy_flutter/lib/user/presentation/helpers/handle_user_profile_result.dart
+++ /dev/null
@@ -1,21 +0,0 @@
-import 'package:appflowy/user/presentation/helpers/helpers.dart';
-import 'package:appflowy/user/presentation/presentation.dart';
-import 'package:appflowy_backend/protobuf/flowy-error/protobuf.dart';
-import 'package:appflowy_backend/protobuf/flowy-user/user_profile.pb.dart';
-import 'package:appflowy_result/appflowy_result.dart';
-import 'package:flutter/material.dart';
-
-void handleUserProfileResult(
- FlowyResult<UserProfilePB, FlowyError> userProfileResult,
- BuildContext context,
- AuthRouter authRouter,
-) {
- userProfileResult.fold(
- (userProfile) {
- authRouter.goHomeScreen(context, userProfile);
- },
- (error) {
- handleOpenWorkspaceError(context, error);
- },
- );
-}
diff --git a/frontend/appflowy_flutter/lib/user/presentation/helpers/helpers.dart b/frontend/appflowy_flutter/lib/user/presentation/helpers/helpers.dart
index 084a360666..11f321232e 100644
--- a/frontend/appflowy_flutter/lib/user/presentation/helpers/helpers.dart
+++ b/frontend/appflowy_flutter/lib/user/presentation/helpers/helpers.dart
@@ -1,2 +1 @@
export 'handle_open_workspace_error.dart';
-export 'handle_user_profile_result.dart';
diff --git a/frontend/appflowy_flutter/lib/user/presentation/router.dart b/frontend/appflowy_flutter/lib/user/presentation/router.dart
index f6f6ec3e3a..339c2f29f7 100644
--- a/frontend/appflowy_flutter/lib/user/presentation/router.dart
+++ b/frontend/appflowy_flutter/lib/user/presentation/router.dart
@@ -21,10 +21,6 @@ class AuthRouter {
getIt<SplashRouter>().pushWorkspaceStartScreen(context, userProfile);
}
- void pushSignUpScreen(BuildContext context) {
- context.push(SignUpScreen.routeName);
- }
-
/// Navigates to the home screen based on the current workspace and platform.
///
/// This function takes in a [BuildContext] and a [UserProfilePB] object to
diff --git a/frontend/appflowy_flutter/lib/user/presentation/screens/screens.dart b/frontend/appflowy_flutter/lib/user/presentation/screens/screens.dart
index 540da8c2b4..2aeba87995 100644
--- a/frontend/appflowy_flutter/lib/user/presentation/screens/screens.dart
+++ b/frontend/appflowy_flutter/lib/user/presentation/screens/screens.dart
@@ -1,6 +1,5 @@
export 'sign_in_screen/sign_in_screen.dart';
export 'skip_log_in_screen.dart';
export 'splash_screen.dart';
-export 'sign_up_screen.dart';
export 'workspace_error_screen.dart';
export 'workspace_start_screen/workspace_start_screen.dart';
diff --git a/frontend/appflowy_flutter/lib/user/presentation/screens/sign_up_screen.dart b/frontend/appflowy_flutter/lib/user/presentation/screens/sign_up_screen.dart
deleted file mode 100644
index 8aea8dde55..0000000000
--- a/frontend/appflowy_flutter/lib/user/presentation/screens/sign_up_screen.dart
+++ /dev/null
@@ -1,220 +0,0 @@
-import 'package:appflowy/generated/flowy_svgs.g.dart';
-import 'package:appflowy/generated/locale_keys.g.dart';
-import 'package:appflowy/startup/startup.dart';
-import 'package:appflowy/user/application/sign_up_bloc.dart';
-import 'package:appflowy/user/presentation/router.dart';
-import 'package:appflowy/user/presentation/widgets/widgets.dart';
-import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
-import 'package:appflowy_backend/protobuf/flowy-user/protobuf.dart'
- show UserProfilePB;
-import 'package:appflowy_result/appflowy_result.dart';
-import 'package:easy_localization/easy_localization.dart';
-import 'package:flowy_infra_ui/style_widget/snap_bar.dart';
-import 'package:flowy_infra_ui/style_widget/text.dart';
-import 'package:flowy_infra_ui/widget/rounded_button.dart';
-import 'package:flowy_infra_ui/widget/rounded_input_field.dart';
-import 'package:flowy_infra_ui/widget/spacing.dart';
-import 'package:flutter/material.dart';
-import 'package:flutter_bloc/flutter_bloc.dart';
-
-class SignUpScreen extends StatelessWidget {
- const SignUpScreen({
- super.key,
- required this.router,
- });
-
- static const routeName = '/SignUpScreen';
- final AuthRouter router;
-
- @override
- Widget build(BuildContext context) {
- return BlocProvider(
- create: (context) => getIt<SignUpBloc>(),
- child: BlocListener<SignUpBloc, SignUpState>(
- listener: (context, state) {
- final successOrFail = state.successOrFail;
- if (successOrFail != null) {
- _handleSuccessOrFail(context, successOrFail);
- }
- },
- child: const Scaffold(body: SignUpForm()),
- ),
- );
- }
-
- void _handleSuccessOrFail(
- BuildContext context,
- FlowyResult<UserProfilePB, FlowyError> result,
- ) {
- result.fold(
- (user) => router.pushWorkspaceStartScreen(context, user),
- (error) => showSnapBar(context, error.msg),
- );
- }
-}
-
-class SignUpForm extends StatelessWidget {
- const SignUpForm({
- super.key,
- });
-
- @override
- Widget build(BuildContext context) {
- return Align(
- child: AuthFormContainer(
- children: [
- FlowyLogoTitle(
- title: LocaleKeys.signUp_title.tr(),
- logoSize: const Size(60, 60),
- ),
- const VSpace(30),
- const EmailTextField(),
- const VSpace(5),
- const PasswordTextField(),
- const VSpace(5),
- const RepeatPasswordTextField(),
- const VSpace(30),
- const SignUpButton(),
- const VSpace(10),
- const SignUpPrompt(),
- if (context.read<SignUpBloc>().state.isSubmitting) ...[
- const SizedBox(height: 8),
- const LinearProgressIndicator(),
- ],
- ],
- ),
- );
- }
-}
-
-class SignUpPrompt extends StatelessWidget {
- const SignUpPrompt({
- super.key,
- });
-
- @override
- Widget build(BuildContext context) {
- return Row(
- mainAxisAlignment: MainAxisAlignment.center,
- children: [
- FlowyText.medium(
- LocaleKeys.signUp_alreadyHaveAnAccount.tr(),
- color: Theme.of(context).hintColor,
- ),
- TextButton(
- style: TextButton.styleFrom(
- textStyle: Theme.of(context).textTheme.bodyMedium,
- ),
- onPressed: () => Navigator.pop(context),
- child: FlowyText.medium(
- LocaleKeys.signIn_buttonText.tr(),
- color: Theme.of(context).colorScheme.primary,
- ),
- ),
- ],
- );
- }
-}
-
-class SignUpButton extends StatelessWidget {
- const SignUpButton({
- super.key,
- });
-
- @override
- Widget build(BuildContext context) {
- return RoundedTextButton(
- title: LocaleKeys.signUp_getStartedText.tr(),
- height: 48,
- onPressed: () {
- context
- .read<SignUpBloc>()
- .add(const SignUpEvent.signUpWithUserEmailAndPassword());
- },
- );
- }
-}
-
-class PasswordTextField extends StatelessWidget {
- const PasswordTextField({
- super.key,
- });
-
- @override
- Widget build(BuildContext context) {
- return BlocBuilder<SignUpBloc, SignUpState>(
- buildWhen: (previous, current) =>
- previous.passwordError != current.passwordError,
- builder: (context, state) {
- return RoundedInputField(
- obscureText: true,
- obscureIcon: const FlowySvg(FlowySvgs.hide_m),
- obscureHideIcon: const FlowySvg(FlowySvgs.show_m),
- hintText: LocaleKeys.signUp_passwordHint.tr(),
- normalBorderColor: Theme.of(context).colorScheme.outline,
- errorBorderColor: Theme.of(context).colorScheme.error,
- cursorColor: Theme.of(context).colorScheme.primary,
- errorText: context.read<SignUpBloc>().state.passwordError ?? '',
- onChanged: (value) => context
- .read<SignUpBloc>()
- .add(SignUpEvent.passwordChanged(value)),
- );
- },
- );
- }
-}
-
-class RepeatPasswordTextField extends StatelessWidget {
- const RepeatPasswordTextField({
- super.key,
- });
-
- @override
- Widget build(BuildContext context) {
- return BlocBuilder<SignUpBloc, SignUpState>(
- buildWhen: (previous, current) =>
- previous.repeatPasswordError != current.repeatPasswordError,
- builder: (context, state) {
- return RoundedInputField(
- obscureText: true,
- obscureIcon: const FlowySvg(FlowySvgs.hide_m),
- obscureHideIcon: const FlowySvg(FlowySvgs.show_m),
- hintText: LocaleKeys.signUp_repeatPasswordHint.tr(),
- normalBorderColor: Theme.of(context).colorScheme.outline,
- errorBorderColor: Theme.of(context).colorScheme.error,
- cursorColor: Theme.of(context).colorScheme.primary,
- errorText: context.read<SignUpBloc>().state.repeatPasswordError ?? '',
- onChanged: (value) => context
- .read<SignUpBloc>()
- .add(SignUpEvent.repeatPasswordChanged(value)),
- );
- },
- );
- }
-}
-
-class EmailTextField extends StatelessWidget {
- const EmailTextField({
- super.key,
- });
-
- @override
- Widget build(BuildContext context) {
- return BlocBuilder<SignUpBloc, SignUpState>(
- buildWhen: (previous, current) =>
- previous.emailError != current.emailError,
- builder: (context, state) {
- return RoundedInputField(
- hintText: LocaleKeys.signUp_emailHint.tr(),
- style: const TextStyle(fontSize: 14, fontWeight: FontWeight.w500),
- normalBorderColor: Theme.of(context).colorScheme.outline,
- errorBorderColor: Theme.of(context).colorScheme.error,
- cursorColor: Theme.of(context).colorScheme.primary,
- errorText: context.read<SignUpBloc>().state.emailError ?? '',
- onChanged: (value) =>
- context.read<SignUpBloc>().add(SignUpEvent.emailChanged(value)),
- );
- },
- );
- }
-}
diff --git a/frontend/appflowy_flutter/lib/workspace/application/user/user_workspace_bloc.dart b/frontend/appflowy_flutter/lib/workspace/application/user/user_workspace_bloc.dart
index 7e341f4f1f..44e9fa3f92 100644
--- a/frontend/appflowy_flutter/lib/workspace/application/user/user_workspace_bloc.dart
+++ b/frontend/appflowy_flutter/lib/workspace/application/user/user_workspace_bloc.dart
@@ -97,7 +97,7 @@ class UserWorkspaceBloc extends Bloc<UserWorkspaceEvent, UserWorkspaceState> {
);
}
},
- createWorkspace: (name) async {
+ createWorkspace: (name, authType) async {
emit(
state.copyWith(
actionResult: const UserWorkspaceActionResult(
@@ -107,7 +107,10 @@ class UserWorkspaceBloc extends Bloc<UserWorkspaceEvent, UserWorkspaceState> {
),
),
);
- final result = await _userService.createUserWorkspace(name);
+ final result = await _userService.createUserWorkspace(
+ name,
+ authType,
+ );
final workspaces = result.fold(
(s) => [...state.workspaces, s],
(e) => state.workspaces,
@@ -472,8 +475,10 @@ class UserWorkspaceBloc extends Bloc<UserWorkspaceEvent, UserWorkspaceState> {
class UserWorkspaceEvent with _$UserWorkspaceEvent {
const factory UserWorkspaceEvent.initial() = Initial;
const factory UserWorkspaceEvent.fetchWorkspaces() = FetchWorkspaces;
- const factory UserWorkspaceEvent.createWorkspace(String name) =
- CreateWorkspace;
+ const factory UserWorkspaceEvent.createWorkspace(
+ String name,
+ AuthTypePB authType,
+ ) = CreateWorkspace;
const factory UserWorkspaceEvent.deleteWorkspace(String workspaceId) =
DeleteWorkspace;
const factory UserWorkspaceEvent.openWorkspace(
diff --git a/frontend/appflowy_flutter/lib/workspace/application/workspace/workspace_bloc.dart b/frontend/appflowy_flutter/lib/workspace/application/workspace/workspace_bloc.dart
index d8d5db45b4..0db1ac9443 100644
--- a/frontend/appflowy_flutter/lib/workspace/application/workspace/workspace_bloc.dart
+++ b/frontend/appflowy_flutter/lib/workspace/application/workspace/workspace_bloc.dart
@@ -2,6 +2,7 @@ import 'package:appflowy/user/application/user_service.dart';
import 'package:appflowy_backend/log.dart';
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/workspace.pb.dart';
+import 'package:appflowy_backend/protobuf/flowy-user/workspace.pb.dart';
import 'package:appflowy_result/appflowy_result.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
@@ -64,7 +65,8 @@ class WorkspaceBloc extends Bloc<WorkspaceEvent, WorkspaceState> {
String desc,
Emitter<WorkspaceState> emit,
) async {
- final result = await userService.createWorkspace(name, desc);
+ final result =
+ await userService.createUserWorkspace(name, AuthTypePB.CloudAuthType);
emit(
result.fold(
(workspace) {
diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/workspace/_sidebar_workspace_menu.dart b/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/workspace/_sidebar_workspace_menu.dart
index daf332cc15..24a122fee5 100644
--- a/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/workspace/_sidebar_workspace_menu.dart
+++ b/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/workspace/_sidebar_workspace_menu.dart
@@ -386,7 +386,12 @@ class _CreateWorkspaceButton extends StatelessWidget {
final workspaceBloc = context.read<UserWorkspaceBloc>();
await CreateWorkspaceDialog(
onConfirm: (name) {
- workspaceBloc.add(UserWorkspaceEvent.createWorkspace(name));
+ workspaceBloc.add(
+ UserWorkspaceEvent.createWorkspace(
+ name,
+ AuthTypePB.CloudAuthType,
+ ),
+ );
},
).show(context);
}
diff --git a/frontend/rust-lib/flowy-server/src/af_cloud/impls/user/cloud_service_impl.rs b/frontend/rust-lib/flowy-server/src/af_cloud/impls/user/cloud_service_impl.rs
index 8309e4c65f..e0f81a62e4 100644
--- a/frontend/rust-lib/flowy-server/src/af_cloud/impls/user/cloud_service_impl.rs
+++ b/frontend/rust-lib/flowy-server/src/af_cloud/impls/user/cloud_service_impl.rs
@@ -24,8 +24,8 @@ use tracing::{instrument, trace};
use flowy_error::{ErrorCode, FlowyError, FlowyResult};
use flowy_user_pub::cloud::{UserCloudService, UserCollabParams, UserUpdate, UserUpdateReceiver};
use flowy_user_pub::entities::{
- AFCloudOAuthParams, AuthResponse, Role, UpdateUserProfileParams, UserCredentials, UserProfile,
- UserWorkspace, WorkspaceInvitation, WorkspaceInvitationStatus, WorkspaceMember,
+ AFCloudOAuthParams, AuthResponse, Role, UpdateUserProfileParams, UserProfile, UserWorkspace,
+ WorkspaceInvitation, WorkspaceInvitationStatus, WorkspaceMember,
};
use lib_infra::async_trait::async_trait;
use lib_infra::box_any::BoxAny;
@@ -178,10 +178,7 @@ where
}
#[instrument(level = "debug", skip_all)]
- async fn get_user_profile(
- &self,
- _credential: UserCredentials,
- ) -> Result<UserProfile, FlowyError> {
+ async fn get_user_profile(&self, _uid: i64) -> Result<UserProfile, FlowyError> {
let try_get_client = self.server.try_get_client();
let expected_workspace_id = self
.logged_user
diff --git a/frontend/rust-lib/flowy-server/src/local_server/impls/user.rs b/frontend/rust-lib/flowy-server/src/local_server/impls/user.rs
index d378765ebb..eec50b1480 100644
--- a/frontend/rust-lib/flowy-server/src/local_server/impls/user.rs
+++ b/frontend/rust-lib/flowy-server/src/local_server/impls/user.rs
@@ -15,7 +15,7 @@ use crate::local_server::uid::UserIDGenerator;
use flowy_error::FlowyError;
use flowy_user_pub::cloud::{UserCloudService, UserCollabParams};
use flowy_user_pub::entities::*;
-use flowy_user_pub::sql::select_all_user_workspace;
+use flowy_user_pub::sql::{select_all_user_workspace, select_user_profile, select_user_workspace};
use flowy_user_pub::DEFAULT_USER_NAME;
use lib_infra::async_trait::async_trait;
use lib_infra::box_any::BoxAny;
@@ -59,7 +59,7 @@ impl UserCloudService for LocalServerUserServiceImpl {
async fn sign_in(&self, params: BoxAny) -> Result<AuthResponse, FlowyError> {
let params: SignInParams = params.unbox_or_error::<SignInParams>()?;
let uid = ID_GEN.lock().await.next_id();
- let user_workspace = make_user_workspace();
+ let user_workspace = make_user_workspace("My Workspace");
Ok(AuthResponse {
user_id: uid,
user_uuid: Uuid::new_v4(),
@@ -122,15 +122,18 @@ impl UserCloudService for LocalServerUserServiceImpl {
Ok(())
}
- async fn get_user_profile(&self, credential: UserCredentials) -> Result<UserProfile, FlowyError> {
- Err(FlowyError::local_version_not_support().with_context("Not support"))
+ async fn get_user_profile(&self, uid: i64) -> Result<UserProfile, FlowyError> {
+ let conn = self.user.get_sqlite_db(uid)?;
+ let profile = select_user_profile(uid, conn)?;
+ Ok(profile)
}
async fn open_workspace(&self, workspace_id: &Uuid) -> Result<UserWorkspace, FlowyError> {
- Err(
- FlowyError::local_version_not_support()
- .with_context("local server doesn't support open workspace"),
- )
+ let uid = self.user.user_id()?;
+ let conn = self.user.get_sqlite_db(uid)?;
+
+ let workspace = select_user_workspace(&workspace_id.to_string(), conn)?;
+ Ok(UserWorkspace::from(workspace))
}
async fn get_all_workspace(&self, uid: i64) -> Result<Vec<UserWorkspace>, FlowyError> {
@@ -139,11 +142,8 @@ impl UserCloudService for LocalServerUserServiceImpl {
Ok(workspaces)
}
- async fn create_workspace(&self, _workspace_name: &str) -> Result<UserWorkspace, FlowyError> {
- Err(
- FlowyError::local_version_not_support()
- .with_context("local server doesn't support multiple workspaces"),
- )
+ async fn create_workspace(&self, workspace_name: &str) -> Result<UserWorkspace, FlowyError> {
+ Ok(make_user_workspace(workspace_name))
}
async fn patch_workspace(
@@ -193,12 +193,12 @@ impl UserCloudService for LocalServerUserServiceImpl {
}
}
-fn make_user_workspace() -> UserWorkspace {
+fn make_user_workspace(name: &str) -> UserWorkspace {
UserWorkspace {
- id: uuid::Uuid::new_v4().to_string(),
- name: "My Workspace".to_string(),
+ id: Uuid::new_v4().to_string(),
+ name: name.to_string(),
created_at: Default::default(),
- workspace_database_id: uuid::Uuid::new_v4().to_string(),
+ workspace_database_id: Uuid::new_v4().to_string(),
icon: "".to_string(),
member_count: 1,
role: None,
diff --git a/frontend/rust-lib/flowy-user-pub/src/cloud.rs b/frontend/rust-lib/flowy-user-pub/src/cloud.rs
index 00eaef8917..0964d80472 100644
--- a/frontend/rust-lib/flowy-user-pub/src/cloud.rs
+++ b/frontend/rust-lib/flowy-user-pub/src/cloud.rs
@@ -20,8 +20,8 @@ use tokio_stream::wrappers::WatchStream;
use uuid::Uuid;
use crate::entities::{
- AuthResponse, AuthType, Role, UpdateUserProfileParams, UserCredentials, UserProfile,
- UserTokenState, UserWorkspace, WorkspaceInvitation, WorkspaceInvitationStatus, WorkspaceMember,
+ AuthResponse, AuthType, Role, UpdateUserProfileParams, UserProfile, UserTokenState,
+ UserWorkspace, WorkspaceInvitation, WorkspaceInvitationStatus, WorkspaceMember,
};
#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -168,7 +168,7 @@ pub trait UserCloudService: Send + Sync + 'static {
/// Get the user information using the user's token or uid
/// return None if the user is not found
- async fn get_user_profile(&self, credential: UserCredentials) -> Result<UserProfile, FlowyError>;
+ async fn get_user_profile(&self, uid: i64) -> Result<UserProfile, FlowyError>;
async fn open_workspace(&self, workspace_id: &Uuid) -> Result<UserWorkspace, FlowyError>;
diff --git a/frontend/rust-lib/flowy-user-pub/src/entities.rs b/frontend/rust-lib/flowy-user-pub/src/entities.rs
index 6be5a9f64d..0d91f84b0e 100644
--- a/frontend/rust-lib/flowy-user-pub/src/entities.rs
+++ b/frontend/rust-lib/flowy-user-pub/src/entities.rs
@@ -100,40 +100,6 @@ impl UserAuthResponse for AuthResponse {
}
}
-#[derive(Clone, Debug)]
-pub struct UserCredentials {
- /// Currently, the token is only used when the [AuthType] is AppFlowyCloud
- pub token: Option<String>,
-
- /// The user id
- pub uid: Option<i64>,
-
- /// The user id
- pub uuid: Option<String>,
-}
-
-impl UserCredentials {
- pub fn from_uid(uid: i64) -> Self {
- Self {
- token: None,
- uid: Some(uid),
- uuid: None,
- }
- }
-
- pub fn from_uuid(uuid: String) -> Self {
- Self {
- token: None,
- uid: None,
- uuid: Some(uuid),
- }
- }
-
- pub fn new(token: Option<String>, uid: Option<i64>, uuid: Option<String>) -> Self {
- Self { token, uid, uuid }
- }
-}
-
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct UserWorkspace {
pub id: String,
diff --git a/frontend/rust-lib/flowy-user-pub/src/sql/workspace_sql.rs b/frontend/rust-lib/flowy-user-pub/src/sql/workspace_sql.rs
index bcac009527..a1165c9621 100644
--- a/frontend/rust-lib/flowy-user-pub/src/sql/workspace_sql.rs
+++ b/frontend/rust-lib/flowy-user-pub/src/sql/workspace_sql.rs
@@ -58,11 +58,11 @@ impl UserWorkspaceTable {
pub fn select_user_workspace(
workspace_id: &str,
mut conn: DBConnection,
-) -> Option<UserWorkspaceTable> {
- user_workspace_table::dsl::user_workspace_table
+) -> FlowyResult<UserWorkspaceTable> {
+ let row = user_workspace_table::dsl::user_workspace_table
.filter(user_workspace_table::id.eq(workspace_id))
- .first::<UserWorkspaceTable>(&mut *conn)
- .ok()
+ .first::<UserWorkspaceTable>(&mut *conn)?;
+ Ok(row)
}
pub fn select_all_user_workspace(
diff --git a/frontend/rust-lib/flowy-user/src/entities/auth.rs b/frontend/rust-lib/flowy-user/src/entities/auth.rs
index 6a889359c1..ddc0dc29f9 100644
--- a/frontend/rust-lib/flowy-user/src/entities/auth.rs
+++ b/frontend/rust-lib/flowy-user/src/entities/auth.rs
@@ -259,50 +259,6 @@ impl Default for AuthenticatorPB {
}
}
-#[derive(Debug, ProtoBuf, Default)]
-pub struct UserCredentialsPB {
- #[pb(index = 1, one_of)]
- pub uid: Option<i64>,
-
- #[pb(index = 2, one_of)]
- pub uuid: Option<String>,
-
- #[pb(index = 3, one_of)]
- pub token: Option<String>,
-}
-
-impl UserCredentialsPB {
- pub fn from_uid(uid: i64) -> Self {
- Self {
- uid: Some(uid),
- uuid: None,
- token: None,
- }
- }
-
- pub fn from_token(token: &str) -> Self {
- Self {
- uid: None,
- uuid: None,
- token: Some(token.to_owned()),
- }
- }
-
- pub fn from_uuid(uuid: &str) -> Self {
- Self {
- uid: None,
- uuid: Some(uuid.to_owned()),
- token: None,
- }
- }
-}
-
-impl From<UserCredentialsPB> for UserCredentials {
- fn from(value: UserCredentialsPB) -> Self {
- Self::new(value.token, value.uid, value.uuid)
- }
-}
-
#[derive(Default, ProtoBuf)]
pub struct UserStatePB {
#[pb(index = 1)]
diff --git a/frontend/rust-lib/flowy-user/src/event_handler.rs b/frontend/rust-lib/flowy-user/src/event_handler.rs
index 12dd1f3e93..bb38a9e0a0 100644
--- a/frontend/rust-lib/flowy-user/src/event_handler.rs
+++ b/frontend/rust-lib/flowy-user/src/event_handler.rs
@@ -469,9 +469,7 @@ pub async fn get_user_workspace_handler(
let params = data.try_into_inner()?;
let workspace_id = Uuid::from_str(&params.workspace_id)?;
let uid = manager.user_id()?;
- let user_workspace = manager
- .get_user_workspace_from_db(uid, &workspace_id)
- .ok_or_else(FlowyError::record_not_found)?;
+ let user_workspace = manager.get_user_workspace_from_db(uid, &workspace_id)?;
data_result_ok(UserWorkspacePB::from(user_workspace))
}
diff --git a/frontend/rust-lib/flowy-user/src/user_manager/manager.rs b/frontend/rust-lib/flowy-user/src/user_manager/manager.rs
index 86a3dfabce..6cfa8bf16f 100644
--- a/frontend/rust-lib/flowy-user/src/user_manager/manager.rs
+++ b/frontend/rust-lib/flowy-user/src/user_manager/manager.rs
@@ -585,7 +585,7 @@ impl UserManager {
let result: Result<UserProfile, FlowyError> = self
.cloud_service
.get_user_service()?
- .get_user_profile(UserCredentials::from_uid(uid))
+ .get_user_profile(uid)
.await;
match result {
diff --git a/frontend/rust-lib/flowy-user/src/user_manager/manager_user_workspace.rs b/frontend/rust-lib/flowy-user/src/user_manager/manager_user_workspace.rs
index cc884dc1d9..17565e83df 100644
--- a/frontend/rust-lib/flowy-user/src/user_manager/manager_user_workspace.rs
+++ b/frontend/rust-lib/flowy-user/src/user_manager/manager_user_workspace.rs
@@ -157,17 +157,21 @@ impl UserManager {
let uid = self.user_id()?;
let conn = self.db_connection(self.user_id()?)?;
let user_workspace = match select_user_workspace(&workspace_id.to_string(), conn) {
- None => {
- sync_workspace(
- workspace_id,
- self.cloud_service.get_user_service()?,
- uid,
- auth_type,
- self.db_pool(uid)?,
- )
- .await?
+ Err(err) => {
+ if err.is_record_not_found() {
+ sync_workspace(
+ workspace_id,
+ self.cloud_service.get_user_service()?,
+ uid,
+ auth_type,
+ self.db_pool(uid)?,
+ )
+ .await?
+ } else {
+ return Err(err);
+ }
},
- Some(row) => {
+ Ok(row) => {
let user_workspace = UserWorkspace::from(row);
let workspace_id = *workspace_id;
let user_service = self.cloud_service.get_user_service()?;
@@ -248,10 +252,7 @@ impl UserManager {
let conn = self.db_connection(uid)?;
update_user_workspace(conn, changeset)?;
- let row = self
- .get_user_workspace_from_db(uid, workspace_id)
- .ok_or_else(FlowyError::record_not_found)?;
-
+ let row = self.get_user_workspace_from_db(uid, workspace_id)?;
let payload = UserWorkspacePB::from(row);
send_notification(&uid.to_string(), UserNotification::DidUpdateUserWorkspace)
.payload(payload)
@@ -389,8 +390,8 @@ impl UserManager {
&self,
uid: i64,
workspace_id: &Uuid,
- ) -> Option<UserWorkspaceTable> {
- let conn = self.db_connection(uid).ok()?;
+ ) -> FlowyResult<UserWorkspaceTable> {
+ let conn = self.db_connection(uid)?;
select_user_workspace(workspace_id.to_string().as_str(), conn)
}