diff --git a/frontend/app_flowy/lib/startup/deps_resolver.dart b/frontend/app_flowy/lib/startup/deps_resolver.dart index bdb76996e9..1864a2aa62 100644 --- a/frontend/app_flowy/lib/startup/deps_resolver.dart +++ b/frontend/app_flowy/lib/startup/deps_resolver.dart @@ -51,14 +51,14 @@ void _resolveHomeDeps(GetIt getIt) { getIt.registerSingleton(MenuSharedState()); - getIt.registerFactoryParam( + getIt.registerFactoryParam( (user, _) => UserListener(userProfile: user), ); // getIt.registerLazySingleton(() => HomeStackManager()); - getIt.registerFactoryParam( + getIt.registerFactoryParam( (user, _) => WelcomeBloc( userService: UserService(userId: user.id), userWorkspaceListener: UserWorkspaceListener(userProfile: user), @@ -67,21 +67,21 @@ void _resolveHomeDeps(GetIt getIt) { // share getIt.registerLazySingleton(() => ShareService()); - getIt.registerFactoryParam( + getIt.registerFactoryParam( (view, _) => DocShareBloc(view: view, service: getIt())); } void _resolveFolderDeps(GetIt getIt) { //workspace - getIt.registerFactoryParam( + getIt.registerFactoryParam( (user, workspaceId) => WorkspaceListener(user: user, workspaceId: workspaceId)); - // View - getIt.registerFactoryParam( + // ViewPB + getIt.registerFactoryParam( (view, _) => ViewListener(view: view), ); - getIt.registerFactoryParam( + getIt.registerFactoryParam( (view, _) => ViewBloc( view: view, service: ViewService(), @@ -90,19 +90,19 @@ void _resolveFolderDeps(GetIt getIt) { ); //Menu - getIt.registerFactoryParam( + getIt.registerFactoryParam( (user, workspaceId) => MenuBloc( workspaceId: workspaceId, listener: getIt(param1: user, param2: workspaceId), ), ); - getIt.registerFactoryParam( + getIt.registerFactoryParam( (user, _) => MenuUserBloc(user), ); - // App - getIt.registerFactoryParam( + // AppPB + getIt.registerFactoryParam( (app, _) => AppBloc( app: app, appService: AppService(appId: app.id), @@ -123,7 +123,7 @@ void _resolveFolderDeps(GetIt getIt) { void _resolveDocDeps(GetIt getIt) { // Doc - getIt.registerFactoryParam( + getIt.registerFactoryParam( (view, _) => DocumentBloc( view: view, service: DocumentService(), @@ -135,7 +135,7 @@ void _resolveDocDeps(GetIt getIt) { void _resolveGridDeps(GetIt getIt) { // GridPB - getIt.registerFactoryParam( + getIt.registerFactoryParam( (view, _) => GridBloc(view: view), ); diff --git a/frontend/app_flowy/lib/user/application/auth_service.dart b/frontend/app_flowy/lib/user/application/auth_service.dart index 28f7dc5d0e..c2ce625ccf 100644 --- a/frontend/app_flowy/lib/user/application/auth_service.dart +++ b/frontend/app_flowy/lib/user/application/auth_service.dart @@ -1,21 +1,21 @@ import 'package:dartz/dartz.dart'; import 'package:flowy_sdk/dispatch/dispatch.dart'; -import 'package:flowy_sdk/protobuf/flowy-user/protobuf.dart' show SignInPayload, SignUpPayload, UserProfile; +import 'package:flowy_sdk/protobuf/flowy-user/protobuf.dart' show SignInPayloadPB, SignUpPayloadPB, UserProfilePB; import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; class AuthService { - Future> signIn({required String? email, required String? password}) { + Future> signIn({required String? email, required String? password}) { // - final request = SignInPayload.create() + final request = SignInPayloadPB.create() ..email = email ?? '' ..password = password ?? ''; return UserEventSignIn(request).send(); } - Future> signUp( + Future> signUp( {required String? name, required String? password, required String? email}) { - final request = SignUpPayload.create() + final request = SignUpPayloadPB.create() ..email = email ?? '' ..name = name ?? '' ..password = password ?? ''; diff --git a/frontend/app_flowy/lib/user/application/sign_in_bloc.dart b/frontend/app_flowy/lib/user/application/sign_in_bloc.dart index 45b6ee1eb5..1b5838d9c4 100644 --- a/frontend/app_flowy/lib/user/application/sign_in_bloc.dart +++ b/frontend/app_flowy/lib/user/application/sign_in_bloc.dart @@ -2,7 +2,7 @@ import 'package:app_flowy/user/application/auth_service.dart'; import 'package:dartz/dartz.dart'; import 'package:flowy_sdk/protobuf/flowy-error-code/code.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; -import 'package:flowy_sdk/protobuf/flowy-user/protobuf.dart' show UserProfile; +import 'package:flowy_sdk/protobuf/flowy-user/protobuf.dart' show UserProfilePB; import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; @@ -69,7 +69,7 @@ class SignInState with _$SignInState { required bool isSubmitting, required Option passwordError, required Option emailError, - required Option> successOrFail, + required Option> successOrFail, }) = _SignInState; factory SignInState.initial() => SignInState( diff --git a/frontend/app_flowy/lib/user/application/sign_up_bloc.dart b/frontend/app_flowy/lib/user/application/sign_up_bloc.dart index b94a02bf09..0c103fd4d7 100644 --- a/frontend/app_flowy/lib/user/application/sign_up_bloc.dart +++ b/frontend/app_flowy/lib/user/application/sign_up_bloc.dart @@ -2,7 +2,7 @@ import 'package:app_flowy/user/application/auth_service.dart'; import 'package:dartz/dartz.dart'; import 'package:easy_localization/easy_localization.dart'; import 'package:flowy_sdk/protobuf/flowy-error-code/code.pb.dart'; -import 'package:flowy_sdk/protobuf/flowy-user/protobuf.dart' show UserProfile; +import 'package:flowy_sdk/protobuf/flowy-user/protobuf.dart' show UserProfilePB; import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; @@ -120,7 +120,7 @@ class SignUpState with _$SignUpState { required Option passwordError, required Option repeatPasswordError, required Option emailError, - required Option> successOrFail, + required Option> successOrFail, }) = _SignUpState; factory SignUpState.initial() => SignUpState( diff --git a/frontend/app_flowy/lib/user/application/user_listener.dart b/frontend/app_flowy/lib/user/application/user_listener.dart index 89fc393e2d..5483926e71 100644 --- a/frontend/app_flowy/lib/user/application/user_listener.dart +++ b/frontend/app_flowy/lib/user/application/user_listener.dart @@ -13,7 +13,7 @@ import 'package:flowy_sdk/protobuf/flowy-user/user_profile.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-user/dart_notification.pb.dart' as user; import 'package:flowy_sdk/rust_stream.dart'; -typedef UserProfileNotifyValue = Either; +typedef UserProfileNotifyValue = Either; typedef AuthNotifyValue = Either; class UserListener { @@ -22,9 +22,9 @@ class UserListener { PublishNotifier? _profileNotifier = PublishNotifier(); UserNotificationParser? _userParser; - final UserProfile _userProfile; + final UserProfilePB _userProfile; UserListener({ - required UserProfile userProfile, + required UserProfilePB userProfile, }) : _userProfile = userProfile; void start({ @@ -65,7 +65,7 @@ class UserListener { break; case user.UserNotification.UserProfileUpdated: result.fold( - (payload) => _profileNotifier?.value = left(UserProfile.fromBuffer(payload)), + (payload) => _profileNotifier?.value = left(UserProfilePB.fromBuffer(payload)), (error) => _profileNotifier?.value = right(error), ); break; @@ -75,8 +75,8 @@ class UserListener { } } -typedef WorkspaceListNotifyValue = Either, FlowyError>; -typedef WorkspaceSettingNotifyValue = Either; +typedef WorkspaceListNotifyValue = Either, FlowyError>; +typedef WorkspaceSettingNotifyValue = Either; class UserWorkspaceListener { PublishNotifier? _authNotifier = PublishNotifier(); @@ -84,10 +84,10 @@ class UserWorkspaceListener { PublishNotifier? _settingChangedNotifier = PublishNotifier(); FolderNotificationListener? _listener; - final UserProfile _userProfile; + final UserProfilePB _userProfile; UserWorkspaceListener({ - required UserProfile userProfile, + required UserProfilePB userProfile, }) : _userProfile = userProfile; void start({ @@ -119,13 +119,13 @@ class UserWorkspaceListener { case FolderNotification.UserDeleteWorkspace: case FolderNotification.WorkspaceListUpdated: result.fold( - (payload) => _workspacesChangedNotifier?.value = left(RepeatedWorkspace.fromBuffer(payload).items), + (payload) => _workspacesChangedNotifier?.value = left(RepeatedWorkspacePB.fromBuffer(payload).items), (error) => _workspacesChangedNotifier?.value = right(error), ); break; case FolderNotification.WorkspaceSetting: result.fold( - (payload) => _settingChangedNotifier?.value = left(CurrentWorkspaceSetting.fromBuffer(payload)), + (payload) => _settingChangedNotifier?.value = left(CurrentWorkspaceSettingPB.fromBuffer(payload)), (error) => _settingChangedNotifier?.value = right(error), ); break; diff --git a/frontend/app_flowy/lib/user/application/user_service.dart b/frontend/app_flowy/lib/user/application/user_service.dart index 8417a069f9..48bea6aa41 100644 --- a/frontend/app_flowy/lib/user/application/user_service.dart +++ b/frontend/app_flowy/lib/user/application/user_service.dart @@ -11,7 +11,7 @@ class UserService { UserService({ required this.userId, }); - Future> getUserProfile({required String userId}) { + Future> getUserProfile({required String userId}) { return UserEventGetUserProfile().send(); } @@ -20,7 +20,7 @@ class UserService { String? password, String? email, }) { - var payload = UpdateUserProfilePayload.create()..id = userId; + var payload = UpdateUserProfilePayloadPB.create()..id = userId; if (name != null) { payload.name = name; @@ -49,8 +49,8 @@ class UserService { return UserEventInitUser().send(); } - Future, FlowyError>> getWorkspaces() { - final request = WorkspaceId.create(); + Future, FlowyError>> getWorkspaces() { + final request = WorkspaceIdPB.create(); return FolderEventReadWorkspaces(request).send().then((result) { return result.fold( @@ -60,8 +60,8 @@ class UserService { }); } - Future> openWorkspace(String workspaceId) { - final request = WorkspaceId.create()..value = workspaceId; + Future> openWorkspace(String workspaceId) { + final request = WorkspaceIdPB.create()..value = workspaceId; return FolderEventOpenWorkspace(request).send().then((result) { return result.fold( (workspace) => left(workspace), @@ -70,8 +70,8 @@ class UserService { }); } - Future> createWorkspace(String name, String desc) { - final request = CreateWorkspacePayload.create() + Future> createWorkspace(String name, String desc) { + final request = CreateWorkspacePayloadPB.create() ..name = name ..desc = desc; return FolderEventCreateWorkspace(request).send().then((result) { diff --git a/frontend/app_flowy/lib/user/application/user_settings_service.dart b/frontend/app_flowy/lib/user/application/user_settings_service.dart index eb93ab150d..28309d202c 100644 --- a/frontend/app_flowy/lib/user/application/user_settings_service.dart +++ b/frontend/app_flowy/lib/user/application/user_settings_service.dart @@ -5,11 +5,11 @@ import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-user/user_setting.pb.dart'; class UserSettingsService { - Future getAppearanceSettings() async { + Future getAppearanceSettings() async { final result = await UserEventGetAppearanceSetting().send(); return result.fold( - (AppearanceSettings setting) { + (AppearanceSettingsPB setting) { return setting; }, (error) { @@ -18,7 +18,7 @@ class UserSettingsService { ); } - Future> setAppearanceSettings(AppearanceSettings settings) { + Future> setAppearanceSettings(AppearanceSettingsPB settings) { return UserEventSetAppearanceSetting(settings).send(); } } diff --git a/frontend/app_flowy/lib/user/domain/auth_state.dart b/frontend/app_flowy/lib/user/domain/auth_state.dart index e2d3a33b09..ae0c259573 100644 --- a/frontend/app_flowy/lib/user/domain/auth_state.dart +++ b/frontend/app_flowy/lib/user/domain/auth_state.dart @@ -1,11 +1,11 @@ -import 'package:flowy_sdk/protobuf/flowy-user/protobuf.dart' show UserProfile; +import 'package:flowy_sdk/protobuf/flowy-user/protobuf.dart' show UserProfilePB; import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; part 'auth_state.freezed.dart'; @freezed class AuthState with _$AuthState { - const factory AuthState.authenticated(UserProfile userProfile) = Authenticated; + const factory AuthState.authenticated(UserProfilePB userProfile) = Authenticated; const factory AuthState.unauthenticated(FlowyError error) = Unauthenticated; const factory AuthState.initial() = _Initial; } diff --git a/frontend/app_flowy/lib/user/presentation/router.dart b/frontend/app_flowy/lib/user/presentation/router.dart index 3bcfa11502..2928154ebe 100644 --- a/frontend/app_flowy/lib/user/presentation/router.dart +++ b/frontend/app_flowy/lib/user/presentation/router.dart @@ -7,7 +7,7 @@ import 'package:app_flowy/user/presentation/welcome_screen.dart'; import 'package:app_flowy/workspace/presentation/home/home_screen.dart'; import 'package:flowy_infra/time/duration.dart'; import 'package:flowy_infra_ui/widget/route/animation.dart'; -import 'package:flowy_sdk/protobuf/flowy-user/protobuf.dart' show UserProfile; +import 'package:flowy_sdk/protobuf/flowy-user/protobuf.dart' show UserProfilePB; import 'package:flowy_sdk/protobuf/flowy-folder/protobuf.dart'; import 'package:flutter/material.dart'; @@ -16,7 +16,7 @@ class AuthRouter { // TODO: implement showForgetPasswordScreen } - void pushWelcomeScreen(BuildContext context, UserProfile userProfile) { + void pushWelcomeScreen(BuildContext context, UserProfilePB userProfile) { getIt().pushWelcomeScreen(context, userProfile); } @@ -28,7 +28,7 @@ class AuthRouter { ); } - void pushHomeScreen(BuildContext context, UserProfile profile, CurrentWorkspaceSetting workspaceSetting) { + void pushHomeScreen(BuildContext context, UserProfilePB profile, CurrentWorkspaceSettingPB workspaceSetting) { Navigator.push( context, PageRoutes.fade(() => HomeScreen(profile, workspaceSetting), RouteDurations.slow.inMilliseconds * .001), @@ -37,7 +37,7 @@ class AuthRouter { } class SplashRoute { - Future pushWelcomeScreen(BuildContext context, UserProfile userProfile) async { + Future pushWelcomeScreen(BuildContext context, UserProfilePB userProfile) async { final screen = WelcomeScreen(userProfile: userProfile); final workspaceId = await Navigator.of(context).push( PageRoutes.fade( @@ -49,7 +49,7 @@ class SplashRoute { pushHomeScreen(context, userProfile, workspaceId); } - void pushHomeScreen(BuildContext context, UserProfile userProfile, CurrentWorkspaceSetting workspaceSetting) { + void pushHomeScreen(BuildContext context, UserProfilePB userProfile, CurrentWorkspaceSettingPB workspaceSetting) { Navigator.push( context, PageRoutes.fade(() => HomeScreen(userProfile, workspaceSetting), RouteDurations.slow.inMilliseconds * .001), diff --git a/frontend/app_flowy/lib/user/presentation/sign_in_screen.dart b/frontend/app_flowy/lib/user/presentation/sign_in_screen.dart index baa8ef0ccb..ee3600e782 100644 --- a/frontend/app_flowy/lib/user/presentation/sign_in_screen.dart +++ b/frontend/app_flowy/lib/user/presentation/sign_in_screen.dart @@ -10,7 +10,7 @@ import 'package:flowy_infra_ui/widget/rounded_input_field.dart'; import 'package:flowy_infra_ui/widget/spacing.dart'; import 'package:flowy_infra_ui/style_widget/snap_bar.dart'; import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; -import 'package:flowy_sdk/protobuf/flowy-user/protobuf.dart' show UserProfile; +import 'package:flowy_sdk/protobuf/flowy-user/protobuf.dart' show UserProfilePB; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:dartz/dartz.dart'; @@ -39,7 +39,7 @@ class SignInScreen extends StatelessWidget { ); } - void _handleSuccessOrFail(Either result, BuildContext context) { + void _handleSuccessOrFail(Either result, BuildContext context) { result.fold( (user) => router.pushWelcomeScreen(context, user), (error) => showSnapBar(context, error.msg), diff --git a/frontend/app_flowy/lib/user/presentation/sign_up_screen.dart b/frontend/app_flowy/lib/user/presentation/sign_up_screen.dart index 6a0b8f1d85..d0cb7f8b90 100644 --- a/frontend/app_flowy/lib/user/presentation/sign_up_screen.dart +++ b/frontend/app_flowy/lib/user/presentation/sign_up_screen.dart @@ -8,7 +8,7 @@ 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:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; -import 'package:flowy_sdk/protobuf/flowy-user/protobuf.dart' show UserProfile; +import 'package:flowy_sdk/protobuf/flowy-user/protobuf.dart' show UserProfilePB; import 'package:flowy_infra_ui/style_widget/snap_bar.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; @@ -36,7 +36,7 @@ class SignUpScreen extends StatelessWidget { ); } - void _handleSuccessOrFail(BuildContext context, Either result) { + void _handleSuccessOrFail(BuildContext context, Either result) { result.fold( (user) => router.pushWelcomeScreen(context, user), (error) => showSnapBar(context, error.msg), diff --git a/frontend/app_flowy/lib/user/presentation/skip_log_in_screen.dart b/frontend/app_flowy/lib/user/presentation/skip_log_in_screen.dart index c8fb9ba06b..6e3ae5ea52 100644 --- a/frontend/app_flowy/lib/user/presentation/skip_log_in_screen.dart +++ b/frontend/app_flowy/lib/user/presentation/skip_log_in_screen.dart @@ -116,8 +116,8 @@ class _SkipLogInScreenState extends State { void _openCurrentWorkspace( BuildContext context, - UserProfile user, - dartz.Either workspacesOrError, + UserProfilePB user, + dartz.Either workspacesOrError, ) { workspacesOrError.fold( (workspaceSetting) { diff --git a/frontend/app_flowy/lib/user/presentation/welcome_screen.dart b/frontend/app_flowy/lib/user/presentation/welcome_screen.dart index 60ec3bf8a2..31b06d8bd1 100644 --- a/frontend/app_flowy/lib/user/presentation/welcome_screen.dart +++ b/frontend/app_flowy/lib/user/presentation/welcome_screen.dart @@ -12,7 +12,7 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:app_flowy/generated/locale_keys.g.dart'; class WelcomeScreen extends StatelessWidget { - final UserProfile userProfile; + final UserProfilePB userProfile; const WelcomeScreen({ Key? key, required this.userProfile, @@ -65,7 +65,7 @@ class WelcomeScreen extends StatelessWidget { ); } - Widget _renderList(List workspaces) { + Widget _renderList(List workspaces) { return Expanded( child: StyledListView( itemBuilder: (BuildContext context, int index) { @@ -80,7 +80,7 @@ class WelcomeScreen extends StatelessWidget { ); } - void _handleOnPress(BuildContext context, Workspace workspace) { + void _handleOnPress(BuildContext context, WorkspacePB workspace) { context.read().add(WelcomeEvent.openWorkspace(workspace)); Navigator.of(context).pop(workspace.id); @@ -88,8 +88,8 @@ class WelcomeScreen extends StatelessWidget { } class WorkspaceItem extends StatelessWidget { - final Workspace workspace; - final void Function(Workspace workspace) onPressed; + final WorkspacePB workspace; + final void Function(WorkspacePB workspace) onPressed; const WorkspaceItem({Key? key, required this.workspace, required this.onPressed}) : super(key: key); @override diff --git a/frontend/app_flowy/lib/workspace/application/app/app_bloc.dart b/frontend/app_flowy/lib/workspace/application/app/app_bloc.dart index 18f93abd6f..e8d2335168 100644 --- a/frontend/app_flowy/lib/workspace/application/app/app_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/app/app_bloc.dart @@ -18,7 +18,7 @@ import 'package:dartz/dartz.dart'; part 'app_bloc.freezed.dart'; class AppBloc extends Bloc { - final App app; + final AppPB app; final AppService appService; final AppListener appListener; @@ -103,7 +103,7 @@ class AppBloc extends Bloc { return super.close(); } - Future _didReceiveViewUpdated(List views, Emitter emit) async { + Future _didReceiveViewUpdated(List views, Emitter emit) async { final latestCreatedView = state.latestCreatedView; AppState newState = state.copyWith(views: views); if (latestCreatedView != null) { @@ -139,20 +139,20 @@ class AppEvent with _$AppEvent { ) = CreateView; const factory AppEvent.delete() = Delete; const factory AppEvent.rename(String newName) = Rename; - const factory AppEvent.didReceiveViewUpdated(List views) = ReceiveViews; - const factory AppEvent.appDidUpdate(App app) = AppDidUpdate; + const factory AppEvent.didReceiveViewUpdated(List views) = ReceiveViews; + const factory AppEvent.appDidUpdate(AppPB app) = AppDidUpdate; } @freezed class AppState with _$AppState { const factory AppState({ - required App app, - required List views, - View? latestCreatedView, + required AppPB app, + required List views, + ViewPB? latestCreatedView, required Either successOrFailure, }) = _AppState; - factory AppState.initial(App app) => AppState( + factory AppState.initial(AppPB app) => AppState( app: app, views: [], successOrFailure: left(unit), @@ -161,8 +161,8 @@ class AppState with _$AppState { class AppViewDataContext extends ChangeNotifier { final String appId; - final ValueNotifier> _viewsNotifier = ValueNotifier([]); - final ValueNotifier _selectedViewNotifier = ValueNotifier(null); + final ValueNotifier> _viewsNotifier = ValueNotifier([]); + final ValueNotifier _selectedViewNotifier = ValueNotifier(null); VoidCallback? _menuSharedStateListener; ExpandableController expandController = ExpandableController(initialExpanded: false); @@ -173,7 +173,7 @@ class AppViewDataContext extends ChangeNotifier { }); } - VoidCallback addSelectedViewChangeListener(void Function(View?) callback) { + VoidCallback addSelectedViewChangeListener(void Function(ViewPB?) callback) { listener() { callback(_selectedViewNotifier.value); } @@ -186,7 +186,7 @@ class AppViewDataContext extends ChangeNotifier { _selectedViewNotifier.removeListener(listener); } - void _setLatestView(View? view) { + void _setLatestView(ViewPB? view) { view?.freeze(); if (_selectedViewNotifier.value != view) { @@ -196,9 +196,9 @@ class AppViewDataContext extends ChangeNotifier { } } - View? get selectedView => _selectedViewNotifier.value; + ViewPB? get selectedView => _selectedViewNotifier.value; - set views(List views) { + set views(List views) { if (_viewsNotifier.value != views) { _viewsNotifier.value = views; _expandIfNeed(); @@ -206,9 +206,9 @@ class AppViewDataContext extends ChangeNotifier { } } - UnmodifiableListView get views => UnmodifiableListView(_viewsNotifier.value); + UnmodifiableListView get views => UnmodifiableListView(_viewsNotifier.value); - VoidCallback addViewsChangeListener(void Function(UnmodifiableListView) callback) { + VoidCallback addViewsChangeListener(void Function(UnmodifiableListView) callback) { listener() { callback(views); } diff --git a/frontend/app_flowy/lib/workspace/application/app/app_listener.dart b/frontend/app_flowy/lib/workspace/application/app/app_listener.dart index 6a30b270af..6edf1a4df2 100644 --- a/frontend/app_flowy/lib/workspace/application/app/app_listener.dart +++ b/frontend/app_flowy/lib/workspace/application/app/app_listener.dart @@ -10,8 +10,8 @@ import 'package:flowy_sdk/protobuf/flowy-folder/view.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-folder/dart_notification.pb.dart'; import 'package:flowy_sdk/rust_stream.dart'; -typedef AppDidUpdateCallback = void Function(App app); -typedef ViewsDidChangeCallback = void Function(Either, FlowyError> viewsOrFailed); +typedef AppDidUpdateCallback = void Function(AppPB app); +typedef ViewsDidChangeCallback = void Function(Either, FlowyError> viewsOrFailed); class AppListener { StreamSubscription? _subscription; @@ -37,7 +37,7 @@ class AppListener { if (_viewsChanged != null) { result.fold( (payload) { - final repeatedView = RepeatedView.fromBuffer(payload); + final repeatedView = RepeatedViewPB.fromBuffer(payload); _viewsChanged!(left(repeatedView.items)); }, (error) => _viewsChanged!(right(error)), @@ -48,7 +48,7 @@ class AppListener { if (_updated != null) { result.fold( (payload) { - final app = App.fromBuffer(payload); + final app = AppPB.fromBuffer(payload); _updated!(app); }, (error) => Log.error(error), diff --git a/frontend/app_flowy/lib/workspace/application/app/app_service.dart b/frontend/app_flowy/lib/workspace/application/app/app_service.dart index 51513a4032..cc75751e49 100644 --- a/frontend/app_flowy/lib/workspace/application/app/app_service.dart +++ b/frontend/app_flowy/lib/workspace/application/app/app_service.dart @@ -14,20 +14,20 @@ class AppService { required this.appId, }); - Future> getAppDesc({required String appId}) { - final payload = AppId.create()..value = appId; + Future> getAppDesc({required String appId}) { + final payload = AppIdPB.create()..value = appId; return FolderEventReadApp(payload).send(); } - Future> createView({ + Future> createView({ required String appId, required String name, required String desc, required PluginDataType dataType, required PluginType pluginType, }) { - final payload = CreateViewPayload.create() + final payload = CreateViewPayloadPB.create() ..belongToId = appId ..name = name ..desc = desc @@ -37,8 +37,8 @@ class AppService { return FolderEventCreateView(payload).send(); } - Future, FlowyError>> getViews({required String appId}) { - final payload = AppId.create()..value = appId; + Future, FlowyError>> getViews({required String appId}) { + final payload = AppIdPB.create()..value = appId; return FolderEventReadApp(payload).send().then((result) { return result.fold( @@ -49,12 +49,12 @@ class AppService { } Future> delete({required String appId}) { - final request = AppId.create()..value = appId; + final request = AppIdPB.create()..value = appId; return FolderEventDeleteApp(request).send(); } Future> updateApp({required String appId, String? name}) { - UpdateAppPayload payload = UpdateAppPayload.create()..appId = appId; + UpdateAppPayloadPB payload = UpdateAppPayloadPB.create()..appId = appId; if (name != null) { payload.name = name; @@ -67,7 +67,7 @@ class AppService { required int fromIndex, required int toIndex, }) { - final payload = MoveFolderItemPayload.create() + final payload = MoveFolderItemPayloadPB.create() ..itemId = viewId ..from = fromIndex ..to = toIndex diff --git a/frontend/app_flowy/lib/workspace/application/appearance.dart b/frontend/app_flowy/lib/workspace/application/appearance.dart index f3ff7801ce..0e47fa2be6 100644 --- a/frontend/app_flowy/lib/workspace/application/appearance.dart +++ b/frontend/app_flowy/lib/workspace/application/appearance.dart @@ -9,7 +9,7 @@ import 'package:flutter/material.dart'; import 'package:easy_localization/easy_localization.dart'; class AppearanceSettingModel extends ChangeNotifier with EquatableMixin { - AppearanceSettings setting; + AppearanceSettingsPB setting; AppTheme _theme; Locale _locale; Timer? _saveOperation; diff --git a/frontend/app_flowy/lib/workspace/application/doc/doc_bloc.dart b/frontend/app_flowy/lib/workspace/application/doc/doc_bloc.dart index 1c77fa1cbd..8be4c40d85 100644 --- a/frontend/app_flowy/lib/workspace/application/doc/doc_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/doc/doc_bloc.dart @@ -17,7 +17,7 @@ part 'doc_bloc.freezed.dart'; typedef FlutterQuillDocument = Document; class DocumentBloc extends Bloc { - final View view; + final ViewPB view; final DocumentService service; final ViewListener listener; diff --git a/frontend/app_flowy/lib/workspace/application/doc/doc_service.dart b/frontend/app_flowy/lib/workspace/application/doc/doc_service.dart index 7cf6d4412a..659a99e371 100644 --- a/frontend/app_flowy/lib/workspace/application/doc/doc_service.dart +++ b/frontend/app_flowy/lib/workspace/application/doc/doc_service.dart @@ -9,7 +9,7 @@ class DocumentService { Future> openDocument({ required String docId, }) async { - await FolderEventSetLatestView(ViewId(value: docId)).send(); + await FolderEventSetLatestView(ViewIdPB(value: docId)).send(); final payload = TextBlockIdPB(value: docId); return TextBlockEventGetBlockData(payload).send(); @@ -23,7 +23,7 @@ class DocumentService { } Future> closeDocument({required String docId}) { - final request = ViewId(value: docId); + final request = ViewIdPB(value: docId); return FolderEventCloseView(request).send(); } } diff --git a/frontend/app_flowy/lib/workspace/application/doc/share_bloc.dart b/frontend/app_flowy/lib/workspace/application/doc/share_bloc.dart index a940846f5a..ba3c7676c6 100644 --- a/frontend/app_flowy/lib/workspace/application/doc/share_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/doc/share_bloc.dart @@ -13,7 +13,7 @@ part 'share_bloc.freezed.dart'; class DocShareBloc extends Bloc { ShareService service; - View view; + ViewPB view; DocShareBloc({required this.view, required this.service}) : super(const DocShareState.initial()) { on((event, emit) async { await event.map( diff --git a/frontend/app_flowy/lib/workspace/application/grid/grid_bloc.dart b/frontend/app_flowy/lib/workspace/application/grid/grid_bloc.dart index 2129632338..19c4049224 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/grid_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/grid_bloc.dart @@ -30,7 +30,7 @@ class GridBloc extends Bloc { return rows; } - GridBloc({required View view}) + GridBloc({required ViewPB view}) : gridId = view.id, _blocks = LinkedHashMap.identity(), _gridService = GridService(gridId: view.id), diff --git a/frontend/app_flowy/lib/workspace/application/grid/grid_service.dart b/frontend/app_flowy/lib/workspace/application/grid/grid_service.dart index e270e32bac..1f8b4336fc 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/grid_service.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/grid_service.dart @@ -20,7 +20,7 @@ class GridService { }); Future> loadGrid() async { - await FolderEventSetLatestView(ViewId(value: gridId)).send(); + await FolderEventSetLatestView(ViewIdPB(value: gridId)).send(); final payload = GridIdPB(value: gridId); return GridEventGetGrid(payload).send(); @@ -40,7 +40,7 @@ class GridService { } Future> closeGrid() { - final request = ViewId(value: gridId); + final request = ViewIdPB(value: gridId); return FolderEventCloseView(request).send(); } } diff --git a/frontend/app_flowy/lib/workspace/application/home/home_bloc.dart b/frontend/app_flowy/lib/workspace/application/home/home_bloc.dart index 4b840634f5..a4ddef0945 100644 --- a/frontend/app_flowy/lib/workspace/application/home/home_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/home/home_bloc.dart @@ -3,7 +3,7 @@ import 'package:app_flowy/workspace/application/edit_pannel/edit_context.dart'; import 'package:flowy_sdk/log.dart'; import 'package:flowy_sdk/protobuf/flowy-error-code/code.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; -import 'package:flowy_sdk/protobuf/flowy-folder/workspace.pb.dart' show CurrentWorkspaceSetting; +import 'package:flowy_sdk/protobuf/flowy-folder/workspace.pb.dart' show CurrentWorkspaceSettingPB; import 'package:flowy_sdk/protobuf/flowy-user/user_profile.pb.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; @@ -13,7 +13,7 @@ part 'home_bloc.freezed.dart'; class HomeBloc extends Bloc { final UserWorkspaceListener _listener; - HomeBloc(UserProfile user, CurrentWorkspaceSetting workspaceSetting) + HomeBloc(UserProfilePB user, CurrentWorkspaceSettingPB workspaceSetting) : _listener = UserWorkspaceListener(userProfile: user), super(HomeState.initial(workspaceSetting)) { on((event, emit) async { @@ -76,7 +76,7 @@ class HomeEvent with _$HomeEvent { const factory HomeEvent.forceCollapse(bool forceCollapse) = _ForceCollapse; const factory HomeEvent.setEditPannel(EditPannelContext editContext) = _ShowEditPannel; const factory HomeEvent.dismissEditPannel() = _DismissEditPannel; - const factory HomeEvent.didReceiveWorkspaceSetting(CurrentWorkspaceSetting setting) = _DidReceiveWorkspaceSetting; + const factory HomeEvent.didReceiveWorkspaceSetting(CurrentWorkspaceSettingPB setting) = _DidReceiveWorkspaceSetting; const factory HomeEvent.unauthorized(String msg) = _Unauthorized; const factory HomeEvent.collapseMenu() = _CollapseMenu; } @@ -87,12 +87,12 @@ class HomeState with _$HomeState { required bool isLoading, required bool forceCollapse, required Option pannelContext, - required CurrentWorkspaceSetting workspaceSetting, + required CurrentWorkspaceSettingPB workspaceSetting, required bool unauthorized, required bool isMenuCollapsed, }) = _HomeState; - factory HomeState.initial(CurrentWorkspaceSetting workspaceSetting) => HomeState( + factory HomeState.initial(CurrentWorkspaceSettingPB workspaceSetting) => HomeState( isLoading: false, forceCollapse: false, pannelContext: none(), diff --git a/frontend/app_flowy/lib/workspace/application/menu/menu_bloc.dart b/frontend/app_flowy/lib/workspace/application/menu/menu_bloc.dart index b3885d7b6b..21d51f5a93 100644 --- a/frontend/app_flowy/lib/workspace/application/menu/menu_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/menu/menu_bloc.dart @@ -41,7 +41,7 @@ class MenuBloc extends Bloc { if (state.apps.length > value.fromIndex) { final app = state.apps[value.fromIndex]; _workspaceService.moveApp(appId: app.id, fromIndex: value.fromIndex, toIndex: value.toIndex); - final apps = List.from(state.apps); + final apps = List.from(state.apps); apps.insert(value.toIndex, apps.removeAt(value.fromIndex)); emit(state.copyWith(apps: apps)); } @@ -79,7 +79,7 @@ class MenuBloc extends Bloc { )); } - void _handleAppsOrFail(Either, FlowyError> appsOrFail) { + void _handleAppsOrFail(Either, FlowyError> appsOrFail) { appsOrFail.fold( (apps) => add(MenuEvent.didReceiveApps(left(apps))), (error) => add(MenuEvent.didReceiveApps(right(error))), @@ -93,13 +93,13 @@ class MenuEvent with _$MenuEvent { const factory MenuEvent.openPage(Plugin plugin) = _OpenPage; const factory MenuEvent.createApp(String name, {String? desc}) = _CreateApp; const factory MenuEvent.moveApp(int fromIndex, int toIndex) = _MoveApp; - const factory MenuEvent.didReceiveApps(Either, FlowyError> appsOrFail) = _ReceiveApps; + const factory MenuEvent.didReceiveApps(Either, FlowyError> appsOrFail) = _ReceiveApps; } @freezed class MenuState with _$MenuState { const factory MenuState({ - required List apps, + required List apps, required Either successOrFailure, required Plugin plugin, }) = _MenuState; 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 7433c758b0..0f30bb9d45 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 @@ -14,7 +14,7 @@ class MenuUserBloc extends Bloc { final UserService _userService; final UserListener _userListener; final UserWorkspaceListener _userWorkspaceListener; - final UserProfile userProfile; + final UserProfilePB userProfile; MenuUserBloc(this.userProfile) : _userListener = UserListener(userProfile: userProfile), @@ -31,7 +31,7 @@ class MenuUserBloc extends Bloc { fetchWorkspaces: () async { // }, - didReceiveUserProfile: (UserProfile newUserProfile) { + didReceiveUserProfile: (UserProfilePB newUserProfile) { emit(state.copyWith(userProfile: newUserProfile)); }, updateUserName: (String name) { @@ -58,14 +58,14 @@ 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) { + void _workspaceListUpdated(Either, FlowyError> workspacesOrFailed) { // Do nothing by now } } @@ -75,18 +75,18 @@ 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; + const factory MenuUserEvent.didReceiveUserProfile(UserProfilePB newUserProfile) = _DidReceiveUserProfile; } @freezed class MenuUserState with _$MenuUserState { const factory MenuUserState({ - required UserProfile userProfile, - required Option> workspaces, + required UserProfilePB userProfile, + required Option> workspaces, required Either successOrFailure, }) = _MenuUserState; - factory MenuUserState.initial(UserProfile userProfile) => MenuUserState( + factory MenuUserState.initial(UserProfilePB userProfile) => MenuUserState( userProfile: userProfile, workspaces: none(), successOrFailure: left(unit), diff --git a/frontend/app_flowy/lib/workspace/application/menu/menu_view_section_bloc.dart b/frontend/app_flowy/lib/workspace/application/menu/menu_view_section_bloc.dart index 6d9f4ce9ef..e70dfd179a 100644 --- a/frontend/app_flowy/lib/workspace/application/menu/menu_view_section_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/menu/menu_view_section_bloc.dart @@ -62,7 +62,7 @@ class ViewSectionBloc extends Bloc { Future _moveView(_MoveView value, Emitter emit) async { if (value.fromIndex < state.views.length) { final viewId = state.views[value.fromIndex].id; - final views = List.from(state.views); + final views = List.from(state.views); views.insert(value.toIndex, views.removeAt(value.fromIndex)); emit(state.copyWith(views: views)); @@ -92,16 +92,16 @@ class ViewSectionBloc extends Bloc { @freezed class ViewSectionEvent with _$ViewSectionEvent { const factory ViewSectionEvent.initial() = _Initial; - const factory ViewSectionEvent.setSelectedView(View? view) = _SetSelectedView; + const factory ViewSectionEvent.setSelectedView(ViewPB? view) = _SetSelectedView; const factory ViewSectionEvent.moveView(int fromIndex, int toIndex) = _MoveView; - const factory ViewSectionEvent.didReceiveViewUpdated(List views) = _DidReceiveViewUpdated; + const factory ViewSectionEvent.didReceiveViewUpdated(List views) = _DidReceiveViewUpdated; } @freezed class ViewSectionState with _$ViewSectionState { const factory ViewSectionState({ - required List views, - View? selectedView, + required List views, + ViewPB? selectedView, }) = _ViewSectionState; factory ViewSectionState.initial(AppViewDataContext appViewData) => ViewSectionState( diff --git a/frontend/app_flowy/lib/workspace/application/trash/trash_bloc.dart b/frontend/app_flowy/lib/workspace/application/trash/trash_bloc.dart index 8c83cd4d2f..a7bcf0588c 100644 --- a/frontend/app_flowy/lib/workspace/application/trash/trash_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/trash/trash_bloc.dart @@ -45,7 +45,7 @@ class TrashBloc extends Bloc { )); } - void _listenTrashUpdated(Either, FlowyError> trashOrFailed) { + void _listenTrashUpdated(Either, FlowyError> trashOrFailed) { trashOrFailed.fold( (trash) { add(TrashEvent.didReceiveTrash(trash)); @@ -66,9 +66,9 @@ class TrashBloc extends Bloc { @freezed class TrashEvent with _$TrashEvent { const factory TrashEvent.initial() = Initial; - const factory TrashEvent.didReceiveTrash(List trash) = ReceiveTrash; + const factory TrashEvent.didReceiveTrash(List trash) = ReceiveTrash; const factory TrashEvent.putback(String trashId) = Putback; - const factory TrashEvent.delete(Trash trash) = Delete; + const factory TrashEvent.delete(TrashPB trash) = Delete; const factory TrashEvent.restoreAll() = RestoreAll; const factory TrashEvent.deleteAll() = DeleteAll; } @@ -76,7 +76,7 @@ class TrashEvent with _$TrashEvent { @freezed class TrashState with _$TrashState { const factory TrashState({ - required List objects, + required List objects, required Either successOrFailure, }) = _TrashState; diff --git a/frontend/app_flowy/lib/workspace/application/trash/trash_listener.dart b/frontend/app_flowy/lib/workspace/application/trash/trash_listener.dart index 51244e23bb..0b4e142058 100644 --- a/frontend/app_flowy/lib/workspace/application/trash/trash_listener.dart +++ b/frontend/app_flowy/lib/workspace/application/trash/trash_listener.dart @@ -8,7 +8,7 @@ import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-folder/trash.pb.dart'; import 'package:flowy_sdk/rust_stream.dart'; -typedef TrashUpdatedCallback = void Function(Either, FlowyError> trashOrFailed); +typedef TrashUpdatedCallback = void Function(Either, FlowyError> trashOrFailed); class TrashListener { StreamSubscription? _subscription; @@ -27,7 +27,7 @@ class TrashListener { if (_trashUpdated != null) { result.fold( (payload) { - final repeatedTrash = RepeatedTrash.fromBuffer(payload); + final repeatedTrash = RepeatedTrashPB.fromBuffer(payload); _trashUpdated!(left(repeatedTrash.items)); }, (error) => _trashUpdated!(right(error)), diff --git a/frontend/app_flowy/lib/workspace/application/trash/trash_service.dart b/frontend/app_flowy/lib/workspace/application/trash/trash_service.dart index a2b6d47147..e782120a74 100644 --- a/frontend/app_flowy/lib/workspace/application/trash/trash_service.dart +++ b/frontend/app_flowy/lib/workspace/application/trash/trash_service.dart @@ -5,24 +5,24 @@ import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-folder/trash.pb.dart'; class TrashService { - Future> readTrash() { + Future> readTrash() { return FolderEventReadTrash().send(); } Future> putback(String trashId) { - final id = TrashId.create()..id = trashId; + final id = TrashIdPB.create()..id = trashId; return FolderEventPutbackTrash(id).send(); } Future> deleteViews(List> trashList) { final items = trashList.map((trash) { - return TrashId.create() + return TrashIdPB.create() ..id = trash.value1 ..ty = trash.value2; }); - final ids = RepeatedTrashId(items: items); + final ids = RepeatedTrashIdPB(items: items); return FolderEventDeleteTrash(ids).send(); } diff --git a/frontend/app_flowy/lib/workspace/application/view/view_bloc.dart b/frontend/app_flowy/lib/workspace/application/view/view_bloc.dart index f87e863d45..bf3cfee6e3 100644 --- a/frontend/app_flowy/lib/workspace/application/view/view_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/view/view_bloc.dart @@ -11,7 +11,7 @@ part 'view_bloc.freezed.dart'; class ViewBloc extends Bloc { final ViewService service; final ViewListener listener; - final View view; + final ViewPB view; ViewBloc({ required this.view, @@ -81,18 +81,18 @@ class ViewEvent with _$ViewEvent { const factory ViewEvent.rename(String newName) = Rename; const factory ViewEvent.delete() = Delete; const factory ViewEvent.duplicate() = Duplicate; - const factory ViewEvent.viewDidUpdate(Either result) = ViewDidUpdate; + const factory ViewEvent.viewDidUpdate(Either result) = ViewDidUpdate; } @freezed class ViewState with _$ViewState { const factory ViewState({ - required View view, + required ViewPB view, required bool isEditing, required Either successOrFailure, }) = _ViewState; - factory ViewState.init(View view) => ViewState( + factory ViewState.init(ViewPB view) => ViewState( view: view, isEditing: false, successOrFailure: left(unit), diff --git a/frontend/app_flowy/lib/workspace/application/view/view_ext.dart b/frontend/app_flowy/lib/workspace/application/view/view_ext.dart index 3987226a20..a54d5ecf40 100644 --- a/frontend/app_flowy/lib/workspace/application/view/view_ext.dart +++ b/frontend/app_flowy/lib/workspace/application/view/view_ext.dart @@ -32,7 +32,7 @@ extension FlowyPluginExtension on FlowyPlugin { } } -extension ViewExtension on View { +extension ViewExtension on ViewPB { Widget renderThumbnail({Color? iconColor}) { String thumbnail = "file_icon"; diff --git a/frontend/app_flowy/lib/workspace/application/view/view_listener.dart b/frontend/app_flowy/lib/workspace/application/view/view_listener.dart index 4acb5e021f..2b080ec194 100644 --- a/frontend/app_flowy/lib/workspace/application/view/view_listener.dart +++ b/frontend/app_flowy/lib/workspace/application/view/view_listener.dart @@ -9,9 +9,9 @@ import 'package:flowy_sdk/protobuf/flowy-folder/dart_notification.pb.dart'; import 'package:flowy_sdk/rust_stream.dart'; import 'package:flowy_infra/notifier.dart'; -typedef DeleteViewNotifyValue = Either; -typedef UpdateViewNotifiedValue = Either; -typedef RestoreViewNotifiedValue = Either; +typedef DeleteViewNotifyValue = Either; +typedef UpdateViewNotifiedValue = Either; +typedef RestoreViewNotifiedValue = Either; class ViewListener { StreamSubscription? _subscription; @@ -19,7 +19,7 @@ class ViewListener { final PublishNotifier _deletedNotifier = PublishNotifier(); final PublishNotifier _restoredNotifier = PublishNotifier(); FolderNotificationParser? _parser; - View view; + ViewPB view; ViewListener({ required this.view, @@ -62,19 +62,19 @@ class ViewListener { switch (ty) { case FolderNotification.ViewUpdated: result.fold( - (payload) => _updatedViewNotifier.value = left(View.fromBuffer(payload)), + (payload) => _updatedViewNotifier.value = left(ViewPB.fromBuffer(payload)), (error) => _updatedViewNotifier.value = right(error), ); break; case FolderNotification.ViewDeleted: result.fold( - (payload) => _deletedNotifier.value = left(View.fromBuffer(payload)), + (payload) => _deletedNotifier.value = left(ViewPB.fromBuffer(payload)), (error) => _deletedNotifier.value = right(error), ); break; case FolderNotification.ViewRestored: result.fold( - (payload) => _restoredNotifier.value = left(View.fromBuffer(payload)), + (payload) => _restoredNotifier.value = left(ViewPB.fromBuffer(payload)), (error) => _restoredNotifier.value = right(error), ); break; diff --git a/frontend/app_flowy/lib/workspace/application/view/view_service.dart b/frontend/app_flowy/lib/workspace/application/view/view_service.dart index c8edd37782..b73cf25cad 100644 --- a/frontend/app_flowy/lib/workspace/application/view/view_service.dart +++ b/frontend/app_flowy/lib/workspace/application/view/view_service.dart @@ -5,13 +5,13 @@ import 'package:flowy_sdk/protobuf/flowy-folder/view.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; class ViewService { - Future> readView({required String viewId}) { - final request = ViewId(value: viewId); + Future> readView({required String viewId}) { + final request = ViewIdPB(value: viewId); return FolderEventReadView(request).send(); } - Future> updateView({required String viewId, String? name, String? desc}) { - final request = UpdateViewPayload.create()..viewId = viewId; + Future> updateView({required String viewId, String? name, String? desc}) { + final request = UpdateViewPayloadPB.create()..viewId = viewId; if (name != null) { request.name = name; @@ -25,12 +25,12 @@ class ViewService { } Future> delete({required String viewId}) { - final request = RepeatedViewId.create()..items.add(viewId); + final request = RepeatedViewIdPB.create()..items.add(viewId); return FolderEventDeleteView(request).send(); } Future> duplicate({required String viewId}) { - final request = ViewId(value: viewId); + final request = ViewIdPB(value: viewId); return FolderEventDuplicateView(request).send(); } } diff --git a/frontend/app_flowy/lib/workspace/application/workspace/welcome_bloc.dart b/frontend/app_flowy/lib/workspace/application/workspace/welcome_bloc.dart index dd3edb27c1..49c3ba19be 100644 --- a/frontend/app_flowy/lib/workspace/application/workspace/welcome_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/workspace/welcome_bloc.dart @@ -52,7 +52,7 @@ class WelcomeBloc extends Bloc { )); } - Future _openWorkspace(Workspace workspace, Emitter emit) async { + Future _openWorkspace(WorkspacePB workspace, Emitter emit) async { final result = await userService.openWorkspace(workspace.id); emit(result.fold( (workspaces) => state.copyWith(successOrFailure: left(unit)), @@ -82,8 +82,8 @@ class WelcomeEvent with _$WelcomeEvent { const factory WelcomeEvent.initial() = Initial; // const factory WelcomeEvent.fetchWorkspaces() = FetchWorkspace; const factory WelcomeEvent.createWorkspace(String name, String desc) = CreateWorkspace; - const factory WelcomeEvent.openWorkspace(Workspace workspace) = OpenWorkspace; - const factory WelcomeEvent.workspacesReveived(Either, FlowyError> workspacesOrFail) = + const factory WelcomeEvent.openWorkspace(WorkspacePB workspace) = OpenWorkspace; + const factory WelcomeEvent.workspacesReveived(Either, FlowyError> workspacesOrFail) = WorkspacesReceived; } @@ -91,7 +91,7 @@ class WelcomeEvent with _$WelcomeEvent { class WelcomeState with _$WelcomeState { const factory WelcomeState({ required bool isLoading, - required List workspaces, + required List workspaces, required Either successOrFailure, }) = _WelcomeState; diff --git a/frontend/app_flowy/lib/workspace/application/workspace/workspace_listener.dart b/frontend/app_flowy/lib/workspace/application/workspace/workspace_listener.dart index 1ee8de94fd..2d7a100e8b 100644 --- a/frontend/app_flowy/lib/workspace/application/workspace/workspace_listener.dart +++ b/frontend/app_flowy/lib/workspace/application/workspace/workspace_listener.dart @@ -3,21 +3,21 @@ import 'dart:typed_data'; import 'package:app_flowy/core/folder_notification.dart'; import 'package:dartz/dartz.dart'; import 'package:flowy_infra/notifier.dart'; -import 'package:flowy_sdk/protobuf/flowy-user/protobuf.dart' show UserProfile; +import 'package:flowy_sdk/protobuf/flowy-user/protobuf.dart' show UserProfilePB; import 'package:flowy_sdk/protobuf/flowy-folder/app.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-folder/workspace.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-folder/dart_notification.pb.dart'; -typedef AppListNotifyValue = Either, FlowyError>; -typedef WorkspaceNotifyValue = Either; +typedef AppListNotifyValue = Either, FlowyError>; +typedef WorkspaceNotifyValue = Either; class WorkspaceListener { PublishNotifier? _appsChangedNotifier = PublishNotifier(); PublishNotifier? _workspaceUpdatedNotifier = PublishNotifier(); FolderNotificationListener? _listener; - final UserProfile user; + final UserProfilePB user; final String workspaceId; WorkspaceListener({ @@ -47,13 +47,13 @@ class WorkspaceListener { switch (ty) { case FolderNotification.WorkspaceUpdated: result.fold( - (payload) => _workspaceUpdatedNotifier?.value = left(Workspace.fromBuffer(payload)), + (payload) => _workspaceUpdatedNotifier?.value = left(WorkspacePB.fromBuffer(payload)), (error) => _workspaceUpdatedNotifier?.value = right(error), ); break; case FolderNotification.WorkspaceAppsChanged: result.fold( - (payload) => _appsChangedNotifier?.value = left(RepeatedApp.fromBuffer(payload).items), + (payload) => _appsChangedNotifier?.value = left(RepeatedAppPB.fromBuffer(payload).items), (error) => _appsChangedNotifier?.value = right(error), ); break; diff --git a/frontend/app_flowy/lib/workspace/application/workspace/workspace_service.dart b/frontend/app_flowy/lib/workspace/application/workspace/workspace_service.dart index 678794b594..4f68d4776a 100644 --- a/frontend/app_flowy/lib/workspace/application/workspace/workspace_service.dart +++ b/frontend/app_flowy/lib/workspace/application/workspace/workspace_service.dart @@ -5,7 +5,7 @@ import 'package:easy_localization/easy_localization.dart'; import 'package:flowy_sdk/dispatch/dispatch.dart'; import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-folder/app.pb.dart'; -import 'package:flowy_sdk/protobuf/flowy-folder/view.pb.dart' show MoveFolderItemPayload, MoveFolderItemType; +import 'package:flowy_sdk/protobuf/flowy-folder/view.pb.dart' show MoveFolderItemPayloadPB, MoveFolderItemType; import 'package:flowy_sdk/protobuf/flowy-folder/workspace.pb.dart'; import 'package:app_flowy/generated/locale_keys.g.dart'; @@ -15,16 +15,16 @@ class WorkspaceService { WorkspaceService({ required this.workspaceId, }); - Future> createApp({required String name, required String desc}) { - final payload = CreateAppPayload.create() + Future> createApp({required String name, required String desc}) { + final payload = CreateAppPayloadPB.create() ..name = name ..workspaceId = workspaceId ..desc = desc; return FolderEventCreateApp(payload).send(); } - Future> getWorkspace() { - final payload = WorkspaceId.create()..value = workspaceId; + Future> getWorkspace() { + final payload = WorkspaceIdPB.create()..value = workspaceId; return FolderEventReadWorkspaces(payload).send().then((result) { return result.fold( (workspaces) { @@ -41,8 +41,8 @@ class WorkspaceService { }); } - Future, FlowyError>> getApps() { - final payload = WorkspaceId.create()..value = workspaceId; + Future, FlowyError>> getApps() { + final payload = WorkspaceIdPB.create()..value = workspaceId; return FolderEventReadWorkspaceApps(payload).send().then((result) { return result.fold( (apps) => left(apps.items), @@ -56,7 +56,7 @@ class WorkspaceService { required int fromIndex, required int toIndex, }) { - final payload = MoveFolderItemPayload.create() + final payload = MoveFolderItemPayloadPB.create() ..itemId = appId ..from = fromIndex ..to = toIndex diff --git a/frontend/app_flowy/lib/workspace/presentation/home/home_screen.dart b/frontend/app_flowy/lib/workspace/presentation/home/home_screen.dart index f205daabac..f3a9f6773a 100644 --- a/frontend/app_flowy/lib/workspace/presentation/home/home_screen.dart +++ b/frontend/app_flowy/lib/workspace/presentation/home/home_screen.dart @@ -5,7 +5,7 @@ import 'package:app_flowy/workspace/presentation/widgets/float_bubble/question_b import 'package:app_flowy/startup/startup.dart'; import 'package:flowy_sdk/log.dart'; import 'package:flowy_infra_ui/style_widget/container.dart'; -import 'package:flowy_sdk/protobuf/flowy-user/protobuf.dart' show UserProfile; +import 'package:flowy_sdk/protobuf/flowy-user/protobuf.dart' show UserProfilePB; import 'package:flowy_sdk/protobuf/flowy-folder/protobuf.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; @@ -18,8 +18,8 @@ import 'home_stack.dart'; import 'menu/menu.dart'; class HomeScreen extends StatefulWidget { - final UserProfile user; - final CurrentWorkspaceSetting workspaceSetting; + final UserProfilePB user; + final CurrentWorkspaceSettingPB workspaceSetting; const HomeScreen(this.user, this.workspaceSetting, {Key? key}) : super(key: key); @override @@ -27,7 +27,7 @@ class HomeScreen extends StatefulWidget { } class _HomeScreenState extends State { - View? initialView; + ViewPB? initialView; @override void initState() { diff --git a/frontend/app_flowy/lib/workspace/presentation/home/menu/app/header/header.dart b/frontend/app_flowy/lib/workspace/presentation/home/menu/app/header/header.dart index 2d26aabc0b..dbeb2248cc 100644 --- a/frontend/app_flowy/lib/workspace/presentation/home/menu/app/header/header.dart +++ b/frontend/app_flowy/lib/workspace/presentation/home/menu/app/header/header.dart @@ -19,7 +19,7 @@ import 'add_button.dart'; import 'right_click_action.dart'; class MenuAppHeader extends StatelessWidget { - final App app; + final AppPB app; const MenuAppHeader( this.app, { Key? key, @@ -85,7 +85,7 @@ class MenuAppHeader extends StatelessWidget { anchorDirection: AnchorDirection.bottomWithCenterAligned, ); }, - child: BlocSelector( + child: BlocSelector( selector: (state) => state.app, builder: (context, app) => FlowyText.medium( app.name, diff --git a/frontend/app_flowy/lib/workspace/presentation/home/menu/app/menu_app.dart b/frontend/app_flowy/lib/workspace/presentation/home/menu/app/menu_app.dart index 462ce1ba8a..e636c87d9a 100644 --- a/frontend/app_flowy/lib/workspace/presentation/home/menu/app/menu_app.dart +++ b/frontend/app_flowy/lib/workspace/presentation/home/menu/app/menu_app.dart @@ -10,7 +10,7 @@ import 'package:provider/provider.dart'; import 'section/section.dart'; class MenuApp extends StatefulWidget { - final App app; + final AppPB app; const MenuApp(this.app, {Key? key}) : super(key: key); @override diff --git a/frontend/app_flowy/lib/workspace/presentation/home/menu/app/section/item.dart b/frontend/app_flowy/lib/workspace/presentation/home/menu/app/section/item.dart index f5de13892f..97ae1dae52 100644 --- a/frontend/app_flowy/lib/workspace/presentation/home/menu/app/section/item.dart +++ b/frontend/app_flowy/lib/workspace/presentation/home/menu/app/section/item.dart @@ -21,8 +21,8 @@ import 'disclosure_action.dart'; // ignore: must_be_immutable class ViewSectionItem extends StatelessWidget { final bool isSelected; - final View view; - final void Function(View) onSelected; + final ViewPB view; + final void Function(ViewPB) onSelected; ViewSectionItem({ Key? key, diff --git a/frontend/app_flowy/lib/workspace/presentation/home/menu/menu.dart b/frontend/app_flowy/lib/workspace/presentation/home/menu/menu.dart index 01debf6196..ef5e20bb6b 100644 --- a/frontend/app_flowy/lib/workspace/presentation/home/menu/menu.dart +++ b/frontend/app_flowy/lib/workspace/presentation/home/menu/menu.dart @@ -10,7 +10,7 @@ import 'package:flowy_infra/size.dart'; import 'package:flowy_infra/theme.dart'; import 'package:flowy_infra_ui/style_widget/scrolling/styled_list.dart'; import 'package:flowy_infra_ui/widget/spacing.dart'; -import 'package:flowy_sdk/protobuf/flowy-user/protobuf.dart' show UserProfile; +import 'package:flowy_sdk/protobuf/flowy-user/protobuf.dart' show UserProfilePB; import 'package:flowy_sdk/protobuf/flowy-folder/view.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-folder/workspace.pb.dart'; import 'package:flutter/material.dart'; @@ -32,8 +32,8 @@ import 'menu_user.dart'; class HomeMenu extends StatelessWidget { final PublishNotifier _collapsedNotifier; - final UserProfile user; - final CurrentWorkspaceSetting workspaceSetting; + final UserProfilePB user; + final CurrentWorkspaceSettingPB workspaceSetting; const HomeMenu({ Key? key, @@ -155,19 +155,19 @@ class HomeMenu extends StatelessWidget { } class MenuSharedState { - final ValueNotifier _latestOpenView = ValueNotifier(null); + final ValueNotifier _latestOpenView = ValueNotifier(null); - MenuSharedState({View? view}) { + MenuSharedState({ViewPB? view}) { _latestOpenView.value = view; } - View? get latestOpenView => _latestOpenView.value; + ViewPB? get latestOpenView => _latestOpenView.value; - set latestOpenView(View? view) { + set latestOpenView(ViewPB? view) { _latestOpenView.value = view; } - VoidCallback addLatestViewListener(void Function(View?) callback) { + VoidCallback addLatestViewListener(void Function(ViewPB?) callback) { listener() { callback(_latestOpenView.value); } diff --git a/frontend/app_flowy/lib/workspace/presentation/home/menu/menu_user.dart b/frontend/app_flowy/lib/workspace/presentation/home/menu/menu_user.dart index 6b75c9ef3f..6c9ffdece2 100644 --- a/frontend/app_flowy/lib/workspace/presentation/home/menu/menu_user.dart +++ b/frontend/app_flowy/lib/workspace/presentation/home/menu/menu_user.dart @@ -6,14 +6,14 @@ import 'package:flowy_infra/size.dart'; import 'package:flowy_infra/theme.dart'; import 'package:flowy_infra_ui/style_widget/text.dart'; import 'package:flowy_infra_ui/widget/spacing.dart'; -import 'package:flowy_sdk/protobuf/flowy-user/protobuf.dart' show UserProfile; +import 'package:flowy_sdk/protobuf/flowy-user/protobuf.dart' show UserProfilePB; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:app_flowy/generated/locale_keys.g.dart'; import 'package:easy_localization/easy_localization.dart'; class MenuUser extends StatelessWidget { - final UserProfile user; + final UserProfilePB user; MenuUser(this.user, {Key? key}) : super(key: ValueKey(user.id)); @override diff --git a/frontend/app_flowy/lib/workspace/presentation/plugins/board/board.dart b/frontend/app_flowy/lib/workspace/presentation/plugins/board/board.dart index b8692168c6..ab58176e50 100644 --- a/frontend/app_flowy/lib/workspace/presentation/plugins/board/board.dart +++ b/frontend/app_flowy/lib/workspace/presentation/plugins/board/board.dart @@ -9,7 +9,7 @@ import 'src/board_page.dart'; class BoardPluginBuilder implements PluginBuilder { @override Plugin build(dynamic data) { - if (data is View) { + if (data is ViewPB) { return BoardPlugin(pluginType: pluginType, view: data); } else { throw FlowyPluginException.invalidData; @@ -32,11 +32,11 @@ class BoardPluginConfig implements PluginConfig { } class BoardPlugin extends Plugin { - final View _view; + final ViewPB _view; final PluginType _pluginType; BoardPlugin({ - required View view, + required ViewPB view, required PluginType pluginType, }) : _pluginType = pluginType, _view = view; @@ -52,8 +52,8 @@ class BoardPlugin extends Plugin { } class GridPluginDisplay extends PluginDisplay { - final View _view; - GridPluginDisplay({required View view, Key? key}) : _view = view; + final ViewPB _view; + GridPluginDisplay({required ViewPB view, Key? key}) : _view = view; @override Widget get leftBarItem => ViewLeftBarItem(view: _view); diff --git a/frontend/app_flowy/lib/workspace/presentation/plugins/board/src/board_page.dart b/frontend/app_flowy/lib/workspace/presentation/plugins/board/src/board_page.dart index 1cdfea5480..612e7c6770 100644 --- a/frontend/app_flowy/lib/workspace/presentation/plugins/board/src/board_page.dart +++ b/frontend/app_flowy/lib/workspace/presentation/plugins/board/src/board_page.dart @@ -4,9 +4,9 @@ import 'package:flowy_sdk/protobuf/flowy-folder/view.pb.dart'; import 'package:flutter/material.dart'; class BoardPage extends StatelessWidget { - final View _view; + final ViewPB _view; - const BoardPage({required View view, Key? key}) + const BoardPage({required ViewPB view, Key? key}) : _view = view, super(key: key); diff --git a/frontend/app_flowy/lib/workspace/presentation/plugins/doc/document.dart b/frontend/app_flowy/lib/workspace/presentation/plugins/doc/document.dart index f5376f52fc..c09843873d 100644 --- a/frontend/app_flowy/lib/workspace/presentation/plugins/doc/document.dart +++ b/frontend/app_flowy/lib/workspace/presentation/plugins/doc/document.dart @@ -36,7 +36,7 @@ export './src/widget/toolbar/toolbar_icon_button.dart'; class DocumentPluginBuilder extends PluginBuilder { @override Plugin build(dynamic data) { - if (data is View) { + if (data is ViewPB) { return DocumentPlugin(pluginType: pluginType, view: data); } else { throw FlowyPluginException.invalidData; @@ -54,11 +54,11 @@ class DocumentPluginBuilder extends PluginBuilder { } class DocumentPlugin implements Plugin { - late View _view; + late ViewPB _view; ViewListener? _listener; late PluginType _pluginType; - DocumentPlugin({required PluginType pluginType, required View view, Key? key}) : _view = view { + DocumentPlugin({required PluginType pluginType, required ViewPB view, Key? key}) : _view = view { _pluginType = pluginType; _listener = getIt(param1: view); _listener?.start(onViewUpdated: (result) { @@ -90,9 +90,9 @@ class DocumentPlugin implements Plugin { class DocumentPluginDisplay extends PluginDisplay with NavigationItem { final PublishNotifier _displayNotifier = PublishNotifier(); - final View _view; + final ViewPB _view; - DocumentPluginDisplay({required View view, Key? key}) : _view = view; + DocumentPluginDisplay({required ViewPB view, Key? key}) : _view = view; @override Widget buildWidget() => DocumentPage(view: _view, key: ValueKey(_view.id)); @@ -111,7 +111,7 @@ class DocumentPluginDisplay extends PluginDisplay with NavigationItem { } class DocumentShareButton extends StatelessWidget { - final View view; + final ViewPB view; DocumentShareButton({Key? key, required this.view}) : super(key: ValueKey(view.hashCode)); @override diff --git a/frontend/app_flowy/lib/workspace/presentation/plugins/doc/src/document_page.dart b/frontend/app_flowy/lib/workspace/presentation/plugins/doc/src/document_page.dart index a02289a555..3598c5a5ac 100644 --- a/frontend/app_flowy/lib/workspace/presentation/plugins/doc/src/document_page.dart +++ b/frontend/app_flowy/lib/workspace/presentation/plugins/doc/src/document_page.dart @@ -14,7 +14,7 @@ import 'styles.dart'; import 'widget/banner.dart'; class DocumentPage extends StatefulWidget { - final View view; + final ViewPB view; DocumentPage({Key? key, required this.view}) : super(key: ValueKey(view.id)); diff --git a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/grid.dart b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/grid.dart index da634d8833..776dd833ea 100644 --- a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/grid.dart +++ b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/grid.dart @@ -11,7 +11,7 @@ import 'src/grid_page.dart'; class GridPluginBuilder implements PluginBuilder { @override Plugin build(dynamic data) { - if (data is View) { + if (data is ViewPB) { return GridPlugin(pluginType: pluginType, view: data); } else { throw FlowyPluginException.invalidData; @@ -34,11 +34,11 @@ class GridPluginConfig implements PluginConfig { } class GridPlugin extends Plugin { - final View _view; + final ViewPB _view; final PluginType _pluginType; GridPlugin({ - required View view, + required ViewPB view, required PluginType pluginType, }) : _pluginType = pluginType, _view = view; @@ -54,8 +54,8 @@ class GridPlugin extends Plugin { } class GridPluginDisplay extends PluginDisplay { - final View _view; - GridPluginDisplay({required View view, Key? key}) : _view = view; + final ViewPB _view; + GridPluginDisplay({required ViewPB view, Key? key}) : _view = view; @override Widget get leftBarItem => ViewLeftBarItem(view: _view); diff --git a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/grid_page.dart b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/grid_page.dart index 2ec27f3f3c..82b13867a4 100755 --- a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/grid_page.dart +++ b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/grid_page.dart @@ -19,7 +19,7 @@ import 'widgets/shortcuts.dart'; import 'widgets/toolbar/grid_toolbar.dart'; class GridPage extends StatefulWidget { - final View view; + final ViewPB view; GridPage({Key? key, required this.view}) : super(key: ValueKey(view.id)); diff --git a/frontend/app_flowy/lib/workspace/presentation/plugins/trash/src/trash_cell.dart b/frontend/app_flowy/lib/workspace/presentation/plugins/trash/src/trash_cell.dart index 92b1f61cd0..4d6604e4af 100644 --- a/frontend/app_flowy/lib/workspace/presentation/plugins/trash/src/trash_cell.dart +++ b/frontend/app_flowy/lib/workspace/presentation/plugins/trash/src/trash_cell.dart @@ -14,7 +14,7 @@ import 'sizes.dart'; class TrashCell extends StatelessWidget { final VoidCallback onRestore; final VoidCallback onDelete; - final Trash object; + final TrashPB object; const TrashCell({required this.object, required this.onRestore, required this.onDelete, Key? key}) : super(key: key); @override diff --git a/frontend/app_flowy/lib/workspace/presentation/plugins/trash/trash.dart b/frontend/app_flowy/lib/workspace/presentation/plugins/trash/trash.dart index 324b676fc3..e098eddf96 100644 --- a/frontend/app_flowy/lib/workspace/presentation/plugins/trash/trash.dart +++ b/frontend/app_flowy/lib/workspace/presentation/plugins/trash/trash.dart @@ -31,7 +31,7 @@ class TrashPluginBuilder extends PluginBuilder { } @override - String get menuName => "Trash"; + String get menuName => "TrashPB"; @override PluginType get pluginType => DefaultPlugin.trash.type(); diff --git a/frontend/app_flowy/lib/workspace/presentation/plugins/widgets/left_bar_item.dart b/frontend/app_flowy/lib/workspace/presentation/plugins/widgets/left_bar_item.dart index bd9f1441e8..0d06ec56ce 100644 --- a/frontend/app_flowy/lib/workspace/presentation/plugins/widgets/left_bar_item.dart +++ b/frontend/app_flowy/lib/workspace/presentation/plugins/widgets/left_bar_item.dart @@ -7,7 +7,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; class ViewLeftBarItem extends StatefulWidget { - final View view; + final ViewPB view; ViewLeftBarItem({required this.view, Key? key}) : super(key: ValueKey(view.hashCode)); @@ -20,7 +20,7 @@ class _ViewLeftBarItemState extends State { final _focusNode = FocusNode(); late ViewService _viewService; late ViewListener _viewListener; - late View view; + late ViewPB view; @override void initState() { diff --git a/frontend/app_flowy/test/util/test_env.dart b/frontend/app_flowy/test/util/test_env.dart index 40006295a4..1743e4b920 100644 --- a/frontend/app_flowy/test/util/test_env.dart +++ b/frontend/app_flowy/test/util/test_env.dart @@ -14,7 +14,7 @@ class FlowyTest { return FlowyTest(); } - Future signIn() async { + Future signIn() async { final authService = getIt(); const password = "AppFlowy123@"; final uid = uuid(); diff --git a/frontend/app_flowy/test/workspace_bloc_test.dart b/frontend/app_flowy/test/workspace_bloc_test.dart index 680726b401..d0b898cc42 100644 --- a/frontend/app_flowy/test/workspace_bloc_test.dart +++ b/frontend/app_flowy/test/workspace_bloc_test.dart @@ -7,7 +7,7 @@ import 'package:bloc_test/bloc_test.dart'; import 'util/test_env.dart'; void main() { - UserProfile? userInfo; + UserProfilePB? userInfo; setUpAll(() async { final flowyTest = await FlowyTest.setup(); userInfo = await flowyTest.signIn(); diff --git a/frontend/rust-lib/flowy-folder/src/entities/app.rs b/frontend/rust-lib/flowy-folder/src/entities/app.rs index 1c705d5b0e..3a5dc3099e 100644 --- a/frontend/rust-lib/flowy-folder/src/entities/app.rs +++ b/frontend/rust-lib/flowy-folder/src/entities/app.rs @@ -3,7 +3,7 @@ use crate::{ app::{AppColorStyle, AppIdentify, AppName}, workspace::WorkspaceIdentify, }, - entities::view::RepeatedView, + entities::view::RepeatedViewPB, errors::ErrorCode, impl_def_and_def_mut, }; @@ -12,7 +12,7 @@ use flowy_folder_data_model::revision::AppRevision; use std::convert::TryInto; #[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)] -pub struct App { +pub struct AppPB { #[pb(index = 1)] pub id: String, @@ -26,7 +26,7 @@ pub struct App { pub desc: String, #[pb(index = 5)] - pub belongings: RepeatedView, + pub belongings: RepeatedViewPB, #[pb(index = 6)] pub version: i64, @@ -38,9 +38,9 @@ pub struct App { pub create_time: i64, } -impl std::convert::From for App { +impl std::convert::From for AppPB { fn from(app_serde: AppRevision) -> Self { - App { + AppPB { id: app_serde.id, workspace_id: app_serde.workspace_id, name: app_serde.name, @@ -53,21 +53,21 @@ impl std::convert::From for App { } } #[derive(Eq, PartialEq, Debug, Default, ProtoBuf, Clone)] -pub struct RepeatedApp { +pub struct RepeatedAppPB { #[pb(index = 1)] - pub items: Vec, + pub items: Vec, } -impl_def_and_def_mut!(RepeatedApp, App); +impl_def_and_def_mut!(RepeatedAppPB, AppPB); -impl std::convert::From> for RepeatedApp { +impl std::convert::From> for RepeatedAppPB { fn from(values: Vec) -> Self { - let items = values.into_iter().map(|value| value.into()).collect::>(); - RepeatedApp { items } + let items = values.into_iter().map(|value| value.into()).collect::>(); + RepeatedAppPB { items } } } #[derive(ProtoBuf, Default)] -pub struct CreateAppPayload { +pub struct CreateAppPayloadPB { #[pb(index = 1)] pub workspace_id: String, @@ -78,31 +78,24 @@ pub struct CreateAppPayload { pub desc: String, #[pb(index = 4)] - pub color_style: ColorStyle, + pub color_style: ColorStylePB, } #[derive(ProtoBuf, Default, Debug, Clone)] -pub struct ColorStyle { +pub struct ColorStylePB { #[pb(index = 1)] pub theme_color: String, } -#[derive(ProtoBuf, Default, Debug)] +#[derive(Debug)] pub struct CreateAppParams { - #[pb(index = 1)] pub workspace_id: String, - - #[pb(index = 2)] pub name: String, - - #[pb(index = 3)] pub desc: String, - - #[pb(index = 4)] - pub color_style: ColorStyle, + pub color_style: ColorStylePB, } -impl TryInto for CreateAppPayload { +impl TryInto for CreateAppPayloadPB { type Error = ErrorCode; fn try_into(self) -> Result { @@ -119,21 +112,21 @@ impl TryInto for CreateAppPayload { } } -impl std::convert::From for ColorStyle { +impl std::convert::From for ColorStylePB { fn from(data: AppColorStyle) -> Self { - ColorStyle { + ColorStylePB { theme_color: data.theme_color, } } } #[derive(ProtoBuf, Default, Clone, Debug)] -pub struct AppId { +pub struct AppIdPB { #[pb(index = 1)] pub value: String, } -impl AppId { +impl AppIdPB { pub fn new(app_id: &str) -> Self { Self { value: app_id.to_string(), @@ -142,7 +135,7 @@ impl AppId { } #[derive(ProtoBuf, Default)] -pub struct UpdateAppPayload { +pub struct UpdateAppPayloadPB { #[pb(index = 1)] pub app_id: String, @@ -153,27 +146,22 @@ pub struct UpdateAppPayload { pub desc: Option, #[pb(index = 4, one_of)] - pub color_style: Option, + pub color_style: Option, #[pb(index = 5, one_of)] pub is_trash: Option, } -#[derive(ProtoBuf, Default, Clone, Debug)] +#[derive(Debug, Clone)] pub struct UpdateAppParams { - #[pb(index = 1)] pub app_id: String, - #[pb(index = 2, one_of)] pub name: Option, - #[pb(index = 3, one_of)] pub desc: Option, - #[pb(index = 4, one_of)] - pub color_style: Option, + pub color_style: Option, - #[pb(index = 5, one_of)] pub is_trash: Option, } @@ -181,7 +169,10 @@ impl UpdateAppParams { pub fn new(app_id: &str) -> Self { Self { app_id: app_id.to_string(), - ..Default::default() + name: None, + desc: None, + color_style: None, + is_trash: None, } } @@ -201,7 +192,7 @@ impl UpdateAppParams { } } -impl TryInto for UpdateAppPayload { +impl TryInto for UpdateAppPayloadPB { type Error = ErrorCode; fn try_into(self) -> Result { diff --git a/frontend/rust-lib/flowy-folder/src/entities/trash.rs b/frontend/rust-lib/flowy-folder/src/entities/trash.rs index c332dded18..15358ba3e5 100644 --- a/frontend/rust-lib/flowy-folder/src/entities/trash.rs +++ b/frontend/rust-lib/flowy-folder/src/entities/trash.rs @@ -5,7 +5,7 @@ use serde::{Deserialize, Serialize}; use std::fmt::Formatter; #[derive(Eq, PartialEq, ProtoBuf, Default, Debug, Clone)] -pub struct Trash { +pub struct TrashPB { #[pb(index = 1)] pub id: String, @@ -22,9 +22,9 @@ pub struct Trash { pub ty: TrashType, } -impl std::convert::From for Trash { +impl std::convert::From for TrashPB { fn from(trash_rev: TrashRevision) -> Self { - Trash { + TrashPB { id: trash_rev.id, name: trash_rev.name, modified_time: trash_rev.modified_time, @@ -34,8 +34,8 @@ impl std::convert::From for Trash { } } -impl std::convert::From for TrashRevision { - fn from(trash: Trash) -> Self { +impl std::convert::From for TrashRevision { + fn from(trash: TrashPB) -> Self { TrashRevision { id: trash.id, name: trash.name, @@ -46,16 +46,16 @@ impl std::convert::From for TrashRevision { } } #[derive(PartialEq, Debug, Default, ProtoBuf, Clone)] -pub struct RepeatedTrash { +pub struct RepeatedTrashPB { #[pb(index = 1)] - pub items: Vec, + pub items: Vec, } -impl_def_and_def_mut!(RepeatedTrash, Trash); -impl std::convert::From> for RepeatedTrash { +impl_def_and_def_mut!(RepeatedTrashPB, TrashPB); +impl std::convert::From> for RepeatedTrashPB { fn from(trash_revs: Vec) -> Self { - let items: Vec = trash_revs.into_iter().map(|trash_rev| trash_rev.into()).collect(); - RepeatedTrash { items } + let items: Vec = trash_revs.into_iter().map(|trash_rev| trash_rev.into()).collect(); + RepeatedTrashPB { items } } } @@ -106,15 +106,15 @@ impl std::default::Default for TrashType { } #[derive(PartialEq, ProtoBuf, Default, Debug, Clone)] -pub struct RepeatedTrashId { +pub struct RepeatedTrashIdPB { #[pb(index = 1)] - pub items: Vec, + pub items: Vec, #[pb(index = 2)] pub delete_all: bool, } -impl std::fmt::Display for RepeatedTrashId { +impl std::fmt::Display for RepeatedTrashIdPB { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { f.write_str(&format!( "{:?}", @@ -123,35 +123,35 @@ impl std::fmt::Display for RepeatedTrashId { } } -impl RepeatedTrashId { - pub fn all() -> RepeatedTrashId { - RepeatedTrashId { +impl RepeatedTrashIdPB { + pub fn all() -> RepeatedTrashIdPB { + RepeatedTrashIdPB { items: vec![], delete_all: true, } } } -impl std::convert::From> for RepeatedTrashId { - fn from(items: Vec) -> Self { - RepeatedTrashId { +impl std::convert::From> for RepeatedTrashIdPB { + fn from(items: Vec) -> Self { + RepeatedTrashIdPB { items, delete_all: false, } } } -impl std::convert::From> for RepeatedTrashId { +impl std::convert::From> for RepeatedTrashIdPB { fn from(trash: Vec) -> Self { let items = trash .into_iter() - .map(|t| TrashId { + .map(|t| TrashIdPB { id: t.id, ty: t.ty.into(), }) .collect::>(); - RepeatedTrashId { + RepeatedTrashIdPB { items, delete_all: false, } @@ -159,7 +159,7 @@ impl std::convert::From> for RepeatedTrashId { } #[derive(PartialEq, ProtoBuf, Default, Debug, Clone)] -pub struct TrashId { +pub struct TrashIdPB { #[pb(index = 1)] pub id: String, @@ -167,15 +167,15 @@ pub struct TrashId { pub ty: TrashType, } -impl std::fmt::Display for TrashId { +impl std::fmt::Display for TrashIdPB { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { f.write_str(&format!("{:?}:{}", self.ty, self.id)) } } -impl std::convert::From<&TrashRevision> for TrashId { +impl std::convert::From<&TrashRevision> for TrashIdPB { fn from(trash: &TrashRevision) -> Self { - TrashId { + TrashIdPB { id: trash.id.clone(), ty: trash.ty.clone().into(), } diff --git a/frontend/rust-lib/flowy-folder/src/entities/view.rs b/frontend/rust-lib/flowy-folder/src/entities/view.rs index ca54ec8cff..8f3a26c8fd 100644 --- a/frontend/rust-lib/flowy-folder/src/entities/view.rs +++ b/frontend/rust-lib/flowy-folder/src/entities/view.rs @@ -11,7 +11,7 @@ use flowy_folder_data_model::revision::{gen_view_id, ViewDataTypeRevision, ViewR use std::convert::TryInto; #[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)] -pub struct View { +pub struct ViewPB { #[pb(index = 1)] pub id: String, @@ -34,9 +34,9 @@ pub struct View { pub plugin_type: i32, } -impl std::convert::From for View { +impl std::convert::From for ViewPB { fn from(rev: ViewRevision) -> Self { - View { + ViewPB { id: rev.id, belong_to_id: rev.belong_to_id, name: rev.name, @@ -79,27 +79,27 @@ impl std::convert::From for ViewDataTypeRevision { } #[derive(Eq, PartialEq, Debug, Default, ProtoBuf, Clone)] -pub struct RepeatedView { +pub struct RepeatedViewPB { #[pb(index = 1)] - pub items: Vec, + pub items: Vec, } -impl_def_and_def_mut!(RepeatedView, View); +impl_def_and_def_mut!(RepeatedViewPB, ViewPB); -impl std::convert::From> for RepeatedView { +impl std::convert::From> for RepeatedViewPB { fn from(values: Vec) -> Self { - let items = values.into_iter().map(|value| value.into()).collect::>(); - RepeatedView { items } + let items = values.into_iter().map(|value| value.into()).collect::>(); + RepeatedViewPB { items } } } #[derive(Default, ProtoBuf)] -pub struct RepeatedViewId { +pub struct RepeatedViewIdPB { #[pb(index = 1)] pub items: Vec, } #[derive(Default, ProtoBuf)] -pub struct CreateViewPayload { +pub struct CreateViewPayloadPB { #[pb(index = 1)] pub belong_to_id: String, @@ -122,34 +122,19 @@ pub struct CreateViewPayload { pub data: Vec, } -#[derive(Default, ProtoBuf, Debug, Clone)] +#[derive(Debug, Clone)] pub struct CreateViewParams { - #[pb(index = 1)] pub belong_to_id: String, - - #[pb(index = 2)] pub name: String, - - #[pb(index = 3)] pub desc: String, - - #[pb(index = 4)] pub thumbnail: String, - - #[pb(index = 5)] pub data_type: ViewDataType, - - #[pb(index = 6)] pub view_id: String, - - #[pb(index = 7)] pub data: Vec, - - #[pb(index = 8)] pub plugin_type: i32, } -impl TryInto for CreateViewPayload { +impl TryInto for CreateViewPayloadPB { type Error = ErrorCode; fn try_into(self) -> Result { @@ -175,20 +160,20 @@ impl TryInto for CreateViewPayload { } #[derive(Default, ProtoBuf, Clone, Debug)] -pub struct ViewId { +pub struct ViewIdPB { #[pb(index = 1)] pub value: String, } -impl std::convert::From<&str> for ViewId { +impl std::convert::From<&str> for ViewIdPB { fn from(value: &str) -> Self { - ViewId { + ViewIdPB { value: value.to_string(), } } } -impl std::ops::Deref for ViewId { +impl std::ops::Deref for ViewIdPB { type Target = str; fn deref(&self) -> &Self::Target { @@ -197,7 +182,7 @@ impl std::ops::Deref for ViewId { } #[derive(Default, ProtoBuf)] -pub struct UpdateViewPayload { +pub struct UpdateViewPayloadPB { #[pb(index = 1)] pub view_id: String, @@ -211,22 +196,15 @@ pub struct UpdateViewPayload { pub thumbnail: Option, } -#[derive(Default, ProtoBuf, Clone, Debug)] +#[derive(Clone, Debug)] pub struct UpdateViewParams { - #[pb(index = 1)] pub view_id: String, - - #[pb(index = 2, one_of)] pub name: Option, - - #[pb(index = 3, one_of)] pub desc: Option, - - #[pb(index = 4, one_of)] pub thumbnail: Option, } -impl TryInto for UpdateViewPayload { +impl TryInto for UpdateViewPayloadPB { type Error = ErrorCode; fn try_into(self) -> Result { @@ -269,7 +247,7 @@ impl std::default::Default for MoveFolderItemType { } #[derive(Default, ProtoBuf)] -pub struct MoveFolderItemPayload { +pub struct MoveFolderItemPayloadPB { #[pb(index = 1)] pub item_id: String, @@ -290,7 +268,7 @@ pub struct MoveFolderItemParams { pub ty: MoveFolderItemType, } -impl TryInto for MoveFolderItemPayload { +impl TryInto for MoveFolderItemPayloadPB { type Error = ErrorCode; fn try_into(self) -> Result { diff --git a/frontend/rust-lib/flowy-folder/src/entities/view_info.rs b/frontend/rust-lib/flowy-folder/src/entities/view_info.rs index a772396e9f..92ec785821 100644 --- a/frontend/rust-lib/flowy-folder/src/entities/view_info.rs +++ b/frontend/rust-lib/flowy-folder/src/entities/view_info.rs @@ -1,8 +1,8 @@ -use crate::entities::{RepeatedView, ViewDataType}; +use crate::entities::{RepeatedViewPB, ViewDataType}; use flowy_derive::ProtoBuf; #[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)] -pub struct ViewInfo { +pub struct ViewInfoPB { #[pb(index = 1)] pub id: String, @@ -19,7 +19,7 @@ pub struct ViewInfo { pub data_type: ViewDataType, #[pb(index = 6)] - pub belongings: RepeatedView, + pub belongings: RepeatedViewPB, #[pb(index = 7)] pub ext_data: String, diff --git a/frontend/rust-lib/flowy-folder/src/entities/workspace.rs b/frontend/rust-lib/flowy-folder/src/entities/workspace.rs index a9f61b50c8..20c9750940 100644 --- a/frontend/rust-lib/flowy-folder/src/entities/workspace.rs +++ b/frontend/rust-lib/flowy-folder/src/entities/workspace.rs @@ -1,6 +1,6 @@ use crate::{ entities::parser::workspace::{WorkspaceDesc, WorkspaceIdentify, WorkspaceName}, - entities::{app::RepeatedApp, view::View}, + entities::{app::RepeatedAppPB, view::ViewPB}, errors::*, impl_def_and_def_mut, }; @@ -9,7 +9,7 @@ use flowy_folder_data_model::revision::WorkspaceRevision; use std::convert::TryInto; #[derive(Eq, PartialEq, ProtoBuf, Default, Debug, Clone)] -pub struct Workspace { +pub struct WorkspacePB { #[pb(index = 1)] pub id: String, @@ -20,7 +20,7 @@ pub struct Workspace { pub desc: String, #[pb(index = 4)] - pub apps: RepeatedApp, + pub apps: RepeatedAppPB, #[pb(index = 5)] pub modified_time: i64, @@ -29,9 +29,9 @@ pub struct Workspace { pub create_time: i64, } -impl std::convert::From for Workspace { +impl std::convert::From for WorkspacePB { fn from(workspace_serde: WorkspaceRevision) -> Self { - Workspace { + WorkspacePB { id: workspace_serde.id, name: workspace_serde.name, desc: workspace_serde.desc, @@ -42,15 +42,15 @@ impl std::convert::From for Workspace { } } #[derive(PartialEq, Debug, Default, ProtoBuf)] -pub struct RepeatedWorkspace { +pub struct RepeatedWorkspacePB { #[pb(index = 1)] - pub items: Vec, + pub items: Vec, } -impl_def_and_def_mut!(RepeatedWorkspace, Workspace); +impl_def_and_def_mut!(RepeatedWorkspacePB, WorkspacePB); #[derive(ProtoBuf, Default)] -pub struct CreateWorkspacePayload { +pub struct CreateWorkspacePayloadPB { #[pb(index = 1)] pub name: String, @@ -58,16 +58,13 @@ pub struct CreateWorkspacePayload { pub desc: String, } -#[derive(Clone, ProtoBuf, Default, Debug)] +#[derive(Clone, Debug)] pub struct CreateWorkspaceParams { - #[pb(index = 1)] pub name: String, - - #[pb(index = 2)] pub desc: String, } -impl TryInto for CreateWorkspacePayload { +impl TryInto for CreateWorkspacePayloadPB { type Error = ErrorCode; fn try_into(self) -> Result { @@ -83,28 +80,28 @@ impl TryInto for CreateWorkspacePayload { // Read all workspaces if the workspace_id is None #[derive(Clone, ProtoBuf, Default, Debug)] -pub struct WorkspaceId { +pub struct WorkspaceIdPB { #[pb(index = 1, one_of)] pub value: Option, } -impl WorkspaceId { +impl WorkspaceIdPB { pub fn new(workspace_id: Option) -> Self { Self { value: workspace_id } } } #[derive(Default, ProtoBuf, Clone)] -pub struct CurrentWorkspaceSetting { +pub struct CurrentWorkspaceSettingPB { #[pb(index = 1)] - pub workspace: Workspace, + pub workspace: WorkspacePB, #[pb(index = 2, one_of)] - pub latest_view: Option, + pub latest_view: Option, } #[derive(ProtoBuf, Default)] -pub struct UpdateWorkspaceRequest { +pub struct UpdateWorkspacePayloadPB { #[pb(index = 1)] pub id: String, @@ -115,19 +112,14 @@ pub struct UpdateWorkspaceRequest { pub desc: Option, } -#[derive(Clone, ProtoBuf, Default, Debug)] +#[derive(Clone, Debug)] pub struct UpdateWorkspaceParams { - #[pb(index = 1)] pub id: String, - - #[pb(index = 2, one_of)] pub name: Option, - - #[pb(index = 3, one_of)] pub desc: Option, } -impl TryInto for UpdateWorkspaceRequest { +impl TryInto for UpdateWorkspacePayloadPB { type Error = ErrorCode; fn try_into(self) -> Result { diff --git a/frontend/rust-lib/flowy-folder/src/event_map.rs b/frontend/rust-lib/flowy-folder/src/event_map.rs index abb168b5e3..71e436b848 100644 --- a/frontend/rust-lib/flowy-folder/src/event_map.rs +++ b/frontend/rust-lib/flowy-folder/src/event_map.rs @@ -1,9 +1,9 @@ use crate::{ entities::{ - app::{AppId, CreateAppParams, UpdateAppParams}, - trash::RepeatedTrashId, - view::{CreateViewParams, RepeatedViewId, UpdateViewParams, ViewId}, - workspace::{CreateWorkspaceParams, UpdateWorkspaceParams, WorkspaceId}, + app::{AppIdPB, CreateAppParams, UpdateAppParams}, + trash::RepeatedTrashIdPB, + view::{CreateViewParams, RepeatedViewIdPB, UpdateViewParams, ViewIdPB}, + workspace::{CreateWorkspaceParams, UpdateWorkspaceParams, WorkspaceIdPB}, }, errors::FlowyError, manager::FolderManager, @@ -84,73 +84,73 @@ pub fn create(folder: Arc) -> Module { #[derive(Clone, Copy, PartialEq, Eq, Debug, Display, Hash, ProtoBuf_Enum, Flowy_Event)] #[event_err = "FlowyError"] pub enum FolderEvent { - #[event(input = "CreateWorkspacePayload", output = "Workspace")] + #[event(input = "CreateWorkspacePayloadPB", output = "WorkspacePB")] CreateWorkspace = 0, - #[event(output = "CurrentWorkspaceSetting")] + #[event(output = "CurrentWorkspaceSettingPB")] ReadCurWorkspace = 1, - #[event(input = "WorkspaceId", output = "RepeatedWorkspace")] + #[event(input = "WorkspaceIdPB", output = "RepeatedWorkspacePB")] ReadWorkspaces = 2, - #[event(input = "WorkspaceId")] + #[event(input = "WorkspaceIdPB")] DeleteWorkspace = 3, - #[event(input = "WorkspaceId", output = "Workspace")] + #[event(input = "WorkspaceIdPB", output = "WorkspacePB")] OpenWorkspace = 4, - #[event(input = "WorkspaceId", output = "RepeatedApp")] + #[event(input = "WorkspaceIdPB", output = "RepeatedAppPB")] ReadWorkspaceApps = 5, - #[event(input = "CreateAppPayload", output = "App")] + #[event(input = "CreateAppPayloadPB", output = "AppPB")] CreateApp = 101, - #[event(input = "AppId")] + #[event(input = "AppIdPB")] DeleteApp = 102, - #[event(input = "AppId", output = "App")] + #[event(input = "AppIdPB", output = "AppPB")] ReadApp = 103, - #[event(input = "UpdateAppPayload")] + #[event(input = "UpdateAppPayloadPB")] UpdateApp = 104, - #[event(input = "CreateViewPayload", output = "View")] + #[event(input = "CreateViewPayloadPB", output = "ViewPB")] CreateView = 201, - #[event(input = "ViewId", output = "View")] + #[event(input = "ViewIdPB", output = "ViewPB")] ReadView = 202, - #[event(input = "UpdateViewPayload", output = "View")] + #[event(input = "UpdateViewPayloadPB", output = "ViewPB")] UpdateView = 203, - #[event(input = "RepeatedViewId")] + #[event(input = "RepeatedViewIdPB")] DeleteView = 204, - #[event(input = "ViewId")] + #[event(input = "ViewIdPB")] DuplicateView = 205, - #[event(input = "ViewId")] + #[event(input = "ViewIdPB")] CloseView = 206, - #[event(input = "ViewId", output = "ViewInfo")] + #[event(input = "ViewIdPB", output = "ViewInfoPB")] ReadViewInfo = 207, #[event()] CopyLink = 220, - #[event(input = "ViewId")] + #[event(input = "ViewIdPB")] SetLatestView = 221, - #[event(input = "MoveFolderItemPayload")] + #[event(input = "MoveFolderItemPayloadPB")] MoveFolderItem = 230, - #[event(output = "RepeatedTrash")] + #[event(output = "RepeatedTrashPB")] ReadTrash = 300, - #[event(input = "TrashId")] + #[event(input = "TrashIdPB")] PutbackTrash = 301, - #[event(input = "RepeatedTrashId")] + #[event(input = "RepeatedTrashIdPB")] DeleteTrash = 302, #[event()] @@ -170,34 +170,34 @@ pub trait FolderCouldServiceV1: Send + Sync { params: CreateWorkspaceParams, ) -> FutureResult; - fn read_workspace(&self, token: &str, params: WorkspaceId) -> FutureResult, FlowyError>; + fn read_workspace(&self, token: &str, params: WorkspaceIdPB) -> FutureResult, FlowyError>; fn update_workspace(&self, token: &str, params: UpdateWorkspaceParams) -> FutureResult<(), FlowyError>; - fn delete_workspace(&self, token: &str, params: WorkspaceId) -> FutureResult<(), FlowyError>; + fn delete_workspace(&self, token: &str, params: WorkspaceIdPB) -> FutureResult<(), FlowyError>; // View fn create_view(&self, token: &str, params: CreateViewParams) -> FutureResult; - fn read_view(&self, token: &str, params: ViewId) -> FutureResult, FlowyError>; + fn read_view(&self, token: &str, params: ViewIdPB) -> FutureResult, FlowyError>; - fn delete_view(&self, token: &str, params: RepeatedViewId) -> FutureResult<(), FlowyError>; + fn delete_view(&self, token: &str, params: RepeatedViewIdPB) -> FutureResult<(), FlowyError>; fn update_view(&self, token: &str, params: UpdateViewParams) -> FutureResult<(), FlowyError>; // App fn create_app(&self, token: &str, params: CreateAppParams) -> FutureResult; - fn read_app(&self, token: &str, params: AppId) -> FutureResult, FlowyError>; + fn read_app(&self, token: &str, params: AppIdPB) -> FutureResult, FlowyError>; fn update_app(&self, token: &str, params: UpdateAppParams) -> FutureResult<(), FlowyError>; - fn delete_app(&self, token: &str, params: AppId) -> FutureResult<(), FlowyError>; + fn delete_app(&self, token: &str, params: AppIdPB) -> FutureResult<(), FlowyError>; // Trash - fn create_trash(&self, token: &str, params: RepeatedTrashId) -> FutureResult<(), FlowyError>; + fn create_trash(&self, token: &str, params: RepeatedTrashIdPB) -> FutureResult<(), FlowyError>; - fn delete_trash(&self, token: &str, params: RepeatedTrashId) -> FutureResult<(), FlowyError>; + fn delete_trash(&self, token: &str, params: RepeatedTrashIdPB) -> FutureResult<(), FlowyError>; fn read_trash(&self, token: &str) -> FutureResult, FlowyError>; } diff --git a/frontend/rust-lib/flowy-folder/src/manager.rs b/frontend/rust-lib/flowy-folder/src/manager.rs index b6555035d3..826006e98c 100644 --- a/frontend/rust-lib/flowy-folder/src/manager.rs +++ b/frontend/rust-lib/flowy-folder/src/manager.rs @@ -1,7 +1,7 @@ use crate::entities::view::ViewDataType; use crate::{ dart_notification::{send_dart_notification, FolderNotification}, - entities::workspace::RepeatedWorkspace, + entities::workspace::RepeatedWorkspacePB, errors::FlowyResult, event_map::{FolderCouldServiceV1, WorkspaceDatabase, WorkspaceUser}, services::{ @@ -216,7 +216,7 @@ impl DefaultFolderBuilder { let folder = FolderPad::new(vec![workspace_rev.clone()], vec![])?; let folder_id = FolderId::new(user_id); let _ = persistence.save_folder(user_id, &folder_id, folder).await?; - let repeated_workspace = RepeatedWorkspace { + let repeated_workspace = RepeatedWorkspacePB { items: vec![workspace_rev.into()], }; send_dart_notification(token, FolderNotification::UserCreateWorkspace) diff --git a/frontend/rust-lib/flowy-folder/src/services/app/controller.rs b/frontend/rust-lib/flowy-folder/src/services/app/controller.rs index 481af85ccd..112ad052ce 100644 --- a/frontend/rust-lib/flowy-folder/src/services/app/controller.rs +++ b/frontend/rust-lib/flowy-folder/src/services/app/controller.rs @@ -1,7 +1,7 @@ use crate::{ dart_notification::*, entities::{ - app::{App, CreateAppParams, *}, + app::{AppPB, CreateAppParams, *}, trash::TrashType, }, errors::*, @@ -44,12 +44,12 @@ impl AppController { } #[tracing::instrument(level = "debug", skip(self, params), fields(name = %params.name) err)] - pub(crate) async fn create_app_from_params(&self, params: CreateAppParams) -> Result { + pub(crate) async fn create_app_from_params(&self, params: CreateAppParams) -> Result { let app = self.create_app_on_server(params).await?; self.create_app_on_local(app).await } - pub(crate) async fn create_app_on_local(&self, app: AppRevision) -> Result { + pub(crate) async fn create_app_on_local(&self, app: AppRevision) -> Result { let _ = self .persistence .begin_transaction(|transaction| { @@ -61,7 +61,7 @@ impl AppController { Ok(app.into()) } - pub(crate) async fn read_app(&self, params: AppId) -> Result { + pub(crate) async fn read_app(&self, params: AppIdPB) -> Result { let app = self .persistence .begin_transaction(|transaction| { @@ -81,7 +81,7 @@ impl AppController { let changeset = AppChangeset::new(params.clone()); let app_id = changeset.id.clone(); - let app: App = self + let app: AppPB = self .persistence .begin_transaction(|transaction| { let _ = transaction.update_app(changeset)?; @@ -150,7 +150,7 @@ impl AppController { } #[tracing::instrument(level = "trace", skip(self), err)] - fn read_app_on_server(&self, params: AppId) -> Result<(), FlowyError> { + fn read_app_on_server(&self, params: AppIdPB) -> Result<(), FlowyError> { let token = self.user.token()?; let server = self.cloud_service.clone(); let persistence = self.persistence.clone(); @@ -162,7 +162,7 @@ impl AppController { .await { Ok(_) => { - let app: App = app_rev.into(); + let app: AppPB = app_rev.into(); send_dart_notification(&app.id, FolderNotification::AppUpdated) .payload(app) .send(); @@ -247,7 +247,7 @@ fn notify_apps_changed<'a>( .into_iter() .map(|app_rev| app_rev.into()) .collect(); - let repeated_app = RepeatedApp { items }; + let repeated_app = RepeatedAppPB { items }; send_dart_notification(workspace_id, FolderNotification::WorkspaceAppsChanged) .payload(repeated_app) .send(); diff --git a/frontend/rust-lib/flowy-folder/src/services/app/event_handler.rs b/frontend/rust-lib/flowy-folder/src/services/app/event_handler.rs index 28885c69d7..e2087c167e 100644 --- a/frontend/rust-lib/flowy-folder/src/services/app/event_handler.rs +++ b/frontend/rust-lib/flowy-folder/src/services/app/event_handler.rs @@ -1,5 +1,5 @@ use crate::{ - entities::app::{App, AppId, CreateAppParams, CreateAppPayload, UpdateAppParams, UpdateAppPayload}, + entities::app::{AppIdPB, AppPB, CreateAppParams, CreateAppPayloadPB, UpdateAppParams, UpdateAppPayloadPB}, errors::FlowyError, services::{AppController, TrashController, ViewController}, }; @@ -8,9 +8,9 @@ use lib_dispatch::prelude::{data_result, AppData, Data, DataResult}; use std::{convert::TryInto, sync::Arc}; pub(crate) async fn create_app_handler( - data: Data, + data: Data, controller: AppData>, -) -> DataResult { +) -> DataResult { let params: CreateAppParams = data.into_inner().try_into()?; let detail = controller.create_app_from_params(params).await?; @@ -18,11 +18,11 @@ pub(crate) async fn create_app_handler( } pub(crate) async fn delete_app_handler( - data: Data, + data: Data, app_controller: AppData>, trash_controller: AppData>, ) -> Result<(), FlowyError> { - let params: AppId = data.into_inner(); + let params: AppIdPB = data.into_inner(); let trash = app_controller .read_local_apps(vec![params.value]) .await? @@ -36,7 +36,7 @@ pub(crate) async fn delete_app_handler( #[tracing::instrument(level = "debug", skip(data, controller))] pub(crate) async fn update_app_handler( - data: Data, + data: Data, controller: AppData>, ) -> Result<(), FlowyError> { let params: UpdateAppParams = data.into_inner().try_into()?; @@ -46,11 +46,11 @@ pub(crate) async fn update_app_handler( #[tracing::instrument(level = "trace", skip(data, app_controller, view_controller))] pub(crate) async fn read_app_handler( - data: Data, + data: Data, app_controller: AppData>, view_controller: AppData>, -) -> DataResult { - let params: AppId = data.into_inner(); +) -> DataResult { + let params: AppIdPB = data.into_inner(); let mut app_rev = app_controller.read_app(params.clone()).await?; app_rev.belongings = view_controller.read_views_belong_to(¶ms.value).await?; diff --git a/frontend/rust-lib/flowy-folder/src/services/persistence/version_1/app_sql.rs b/frontend/rust-lib/flowy-folder/src/services/persistence/version_1/app_sql.rs index 6b5f47c2b7..cf643e7dff 100644 --- a/frontend/rust-lib/flowy-folder/src/services/persistence/version_1/app_sql.rs +++ b/frontend/rust-lib/flowy-folder/src/services/persistence/version_1/app_sql.rs @@ -1,6 +1,6 @@ use crate::entities::{ app::UpdateAppParams, - trash::{Trash, TrashType}, + trash::{TrashPB, TrashType}, }; use crate::{errors::FlowyError, services::persistence::version_1::workspace_sql::WorkspaceTable}; use flowy_database::{ @@ -107,9 +107,9 @@ impl AppTable { } } -impl std::convert::From for Trash { +impl std::convert::From for TrashPB { fn from(table: AppTable) -> Self { - Trash { + TrashPB { id: table.id, name: table.name, modified_time: table.modified_time, diff --git a/frontend/rust-lib/flowy-folder/src/services/persistence/version_1/view_sql.rs b/frontend/rust-lib/flowy-folder/src/services/persistence/version_1/view_sql.rs index ec1bbf38bf..6223cd3366 100644 --- a/frontend/rust-lib/flowy-folder/src/services/persistence/version_1/view_sql.rs +++ b/frontend/rust-lib/flowy-folder/src/services/persistence/version_1/view_sql.rs @@ -1,6 +1,6 @@ use crate::{ entities::{ - trash::{Trash, TrashType}, + trash::{TrashPB, TrashType}, view::UpdateViewParams, }, errors::FlowyError, @@ -133,9 +133,9 @@ impl std::convert::From for ViewRevision { } } -impl std::convert::From for Trash { +impl std::convert::From for TrashPB { fn from(table: ViewTable) -> Self { - Trash { + TrashPB { id: table.id, name: table.name, modified_time: table.modified_time, diff --git a/frontend/rust-lib/flowy-folder/src/services/trash/controller.rs b/frontend/rust-lib/flowy-folder/src/services/trash/controller.rs index 134e8a0d84..8ac9618917 100644 --- a/frontend/rust-lib/flowy-folder/src/services/trash/controller.rs +++ b/frontend/rust-lib/flowy-folder/src/services/trash/controller.rs @@ -1,6 +1,6 @@ use crate::{ dart_notification::{send_anonymous_dart_notification, FolderNotification}, - entities::trash::{RepeatedTrash, RepeatedTrashId, Trash, TrashId, TrashType}, + entities::trash::{RepeatedTrashIdPB, RepeatedTrashPB, TrashIdPB, TrashPB, TrashType}, errors::{FlowyError, FlowyResult}, event_map::{FolderCouldServiceV1, WorkspaceUser}, services::persistence::{FolderPersistence, FolderPersistenceTransaction}, @@ -49,12 +49,12 @@ impl TrashController { }) .await?; - let identifier = TrashId { + let identifier = TrashIdPB { id: trash.id, ty: trash.ty.into(), }; - let _ = self.delete_trash_on_server(RepeatedTrashId { + let _ = self.delete_trash_on_server(RepeatedTrashIdPB { items: vec![identifier.clone()], delete_all: false, })?; @@ -67,7 +67,7 @@ impl TrashController { #[tracing::instrument(level = "debug", skip(self) err)] pub async fn restore_all_trash(&self) -> FlowyResult<()> { - let trash_identifier: RepeatedTrashId = self + let trash_identifier: RepeatedTrashIdPB = self .persistence .begin_transaction(|transaction| { let trash = transaction.read_trash(None); @@ -81,14 +81,14 @@ impl TrashController { let _ = self.notify.send(TrashEvent::Putback(trash_identifier, tx)); let _ = rx.recv().await; - notify_trash_changed(RepeatedTrash { items: vec![] }); + notify_trash_changed(RepeatedTrashPB { items: vec![] }); let _ = self.delete_all_trash_on_server().await?; Ok(()) } #[tracing::instrument(level = "debug", skip(self), err)] pub async fn delete_all_trash(&self) -> FlowyResult<()> { - let all_trash_identifiers: RepeatedTrashId = self + let all_trash_identifiers: RepeatedTrashIdPB = self .persistence .begin_transaction(|transaction| transaction.read_trash(None)) .await? @@ -96,13 +96,13 @@ impl TrashController { let _ = self.delete_with_identifiers(all_trash_identifiers).await?; - notify_trash_changed(RepeatedTrash { items: vec![] }); + notify_trash_changed(RepeatedTrashPB { items: vec![] }); let _ = self.delete_all_trash_on_server().await?; Ok(()) } #[tracing::instrument(level = "debug", skip(self), err)] - pub async fn delete(&self, trash_identifiers: RepeatedTrashId) -> FlowyResult<()> { + pub async fn delete(&self, trash_identifiers: RepeatedTrashIdPB) -> FlowyResult<()> { let _ = self.delete_with_identifiers(trash_identifiers.clone()).await?; let trash_revs = self .persistence @@ -116,7 +116,7 @@ impl TrashController { } #[tracing::instrument(level = "debug", skip(self), fields(delete_trash_ids), err)] - pub async fn delete_with_identifiers(&self, trash_identifiers: RepeatedTrashId) -> FlowyResult<()> { + pub async fn delete_with_identifiers(&self, trash_identifiers: RepeatedTrashIdPB) -> FlowyResult<()> { let (tx, mut rx) = mpsc::channel::>(1); tracing::Span::current().record("delete_trash_ids", &format!("{}", trash_identifiers).as_str()); let _ = self.notify.send(TrashEvent::Delete(trash_identifiers.clone(), tx)); @@ -153,7 +153,7 @@ impl TrashController { pub async fn add>(&self, trash: Vec) -> Result<(), FlowyError> { let (tx, mut rx) = mpsc::channel::>(1); let trash_revs: Vec = trash.into_iter().map(|t| t.into()).collect(); - let identifiers = trash_revs.iter().map(|t| t.into()).collect::>(); + let identifiers = trash_revs.iter().map(|t| t.into()).collect::>(); tracing::Span::current().record( "trash_ids", @@ -187,8 +187,8 @@ impl TrashController { self.notify.subscribe() } - pub async fn read_trash(&self) -> Result { - let items: Vec = self + pub async fn read_trash(&self) -> Result { + let items: Vec = self .persistence .begin_transaction(|transaction| transaction.read_trash(None)) .await? @@ -197,7 +197,7 @@ impl TrashController { .collect(); let _ = self.read_trash_on_server()?; - Ok(RepeatedTrash { items }) + Ok(RepeatedTrashPB { items }) } pub fn read_trash_ids<'a>( @@ -215,7 +215,7 @@ impl TrashController { impl TrashController { #[tracing::instrument(level = "trace", skip(self, trash), err)] - fn create_trash_on_server>(&self, trash: T) -> FlowyResult<()> { + fn create_trash_on_server>(&self, trash: T) -> FlowyResult<()> { let token = self.user.token()?; let trash_identifiers = trash.into(); let server = self.cloud_service.clone(); @@ -230,7 +230,7 @@ impl TrashController { } #[tracing::instrument(level = "trace", skip(self, trash), err)] - fn delete_trash_on_server>(&self, trash: T) -> FlowyResult<()> { + fn delete_trash_on_server>(&self, trash: T) -> FlowyResult<()> { let token = self.user.token()?; let trash_identifiers = trash.into(); let server = self.cloud_service.clone(); @@ -277,12 +277,12 @@ impl TrashController { async fn delete_all_trash_on_server(&self) -> FlowyResult<()> { let token = self.user.token()?; let server = self.cloud_service.clone(); - server.delete_trash(&token, RepeatedTrashId::all()).await + server.delete_trash(&token, RepeatedTrashIdPB::all()).await } } #[tracing::instrument(level = "debug", skip(repeated_trash), fields(n_trash))] -fn notify_trash_changed>(repeated_trash: T) { +fn notify_trash_changed>(repeated_trash: T) { let repeated_trash = repeated_trash.into(); tracing::Span::current().record("n_trash", &repeated_trash.len()); send_anonymous_dart_notification(FolderNotification::TrashUpdated) @@ -292,9 +292,9 @@ fn notify_trash_changed>(repeated_trash: T) { #[derive(Clone)] pub enum TrashEvent { - NewTrash(RepeatedTrashId, mpsc::Sender>), - Putback(RepeatedTrashId, mpsc::Sender>), - Delete(RepeatedTrashId, mpsc::Sender>), + NewTrash(RepeatedTrashIdPB, mpsc::Sender>), + Putback(RepeatedTrashIdPB, mpsc::Sender>), + Delete(RepeatedTrashIdPB, mpsc::Sender>), } impl std::fmt::Debug for TrashEvent { diff --git a/frontend/rust-lib/flowy-folder/src/services/trash/event_handler.rs b/frontend/rust-lib/flowy-folder/src/services/trash/event_handler.rs index b1853faaf5..0034745253 100644 --- a/frontend/rust-lib/flowy-folder/src/services/trash/event_handler.rs +++ b/frontend/rust-lib/flowy-folder/src/services/trash/event_handler.rs @@ -1,5 +1,5 @@ use crate::{ - entities::trash::{RepeatedTrash, RepeatedTrashId, TrashId}, + entities::trash::{RepeatedTrashIdPB, RepeatedTrashPB, TrashIdPB}, errors::FlowyError, services::TrashController, }; @@ -9,14 +9,14 @@ use std::sync::Arc; #[tracing::instrument(level = "debug", skip(controller), err)] pub(crate) async fn read_trash_handler( controller: AppData>, -) -> DataResult { +) -> DataResult { let repeated_trash = controller.read_trash().await?; data_result(repeated_trash) } #[tracing::instrument(level = "debug", skip(identifier, controller), err)] pub(crate) async fn putback_trash_handler( - identifier: Data, + identifier: Data, controller: AppData>, ) -> Result<(), FlowyError> { let _ = controller.putback(&identifier.id).await?; @@ -25,7 +25,7 @@ pub(crate) async fn putback_trash_handler( #[tracing::instrument(level = "debug", skip(identifiers, controller), err)] pub(crate) async fn delete_trash_handler( - identifiers: Data, + identifiers: Data, controller: AppData>, ) -> Result<(), FlowyError> { let _ = controller.delete(identifiers.into_inner()).await?; diff --git a/frontend/rust-lib/flowy-folder/src/services/view/controller.rs b/frontend/rust-lib/flowy-folder/src/services/view/controller.rs index 0df71c320f..df1f668941 100644 --- a/frontend/rust-lib/flowy-folder/src/services/view/controller.rs +++ b/frontend/rust-lib/flowy-folder/src/services/view/controller.rs @@ -1,11 +1,11 @@ pub use crate::entities::view::ViewDataType; -use crate::entities::ViewInfo; +use crate::entities::ViewInfoPB; use crate::manager::{ViewDataProcessor, ViewDataProcessorMap}; use crate::{ dart_notification::{send_dart_notification, FolderNotification}, entities::{ - trash::{RepeatedTrashId, TrashType}, - view::{CreateViewParams, RepeatedView, UpdateViewParams, View, ViewId}, + trash::{RepeatedTrashIdPB, TrashType}, + view::{CreateViewParams, RepeatedViewPB, UpdateViewParams, ViewIdPB, ViewPB}, }, errors::{FlowyError, FlowyResult}, event_map::{FolderCouldServiceV1, WorkspaceUser}, @@ -106,7 +106,7 @@ impl ViewController { } #[tracing::instrument(level = "debug", skip(self, view_id), fields(view_id = %view_id.value), err)] - pub(crate) async fn read_view(&self, view_id: ViewId) -> Result { + pub(crate) async fn read_view(&self, view_id: ViewIdPB) -> Result { let view_rev = self .persistence .begin_transaction(|transaction| { @@ -123,25 +123,25 @@ impl ViewController { } #[tracing::instrument(level = "debug", skip(self, view_id), fields(view_id = %view_id.value), err)] - pub(crate) async fn read_view_info(&self, view_id: ViewId) -> Result { + pub(crate) async fn read_view_info(&self, view_id: ViewIdPB) -> Result { let view_info = self .persistence .begin_transaction(|transaction| { let view_rev = transaction.read_view(&view_id.value)?; - let items: Vec = view_rev + let items: Vec = view_rev .belongings .into_iter() .map(|view_rev| view_rev.into()) .collect(); - let view_info = ViewInfo { + let view_info = ViewInfoPB { id: view_rev.id, belong_to_id: view_rev.belong_to_id, name: view_rev.name, desc: view_rev.desc, data_type: view_rev.data_type.into(), - belongings: RepeatedView { items }, + belongings: RepeatedViewPB { items }, ext_data: view_rev.ext_data, }; Ok(view_info) @@ -245,7 +245,7 @@ impl ViewController { .begin_transaction(|transaction| { let _ = transaction.update_view(changeset)?; let view_rev = transaction.read_view(&view_id)?; - let view: View = view_rev.clone().into(); + let view: ViewPB = view_rev.clone().into(); send_dart_notification(&view_id, FolderNotification::ViewUpdated) .payload(view) .send(); @@ -297,7 +297,7 @@ impl ViewController { } #[tracing::instrument(level = "debug", skip(self), err)] - fn read_view_on_server(&self, params: ViewId) -> Result<(), FlowyError> { + fn read_view_on_server(&self, params: ViewIdPB) -> Result<(), FlowyError> { let token = self.user.token()?; let server = self.cloud_service.clone(); let persistence = self.persistence.clone(); @@ -310,7 +310,7 @@ impl ViewController { .await { Ok(_) => { - let view: View = view_rev.into(); + let view: ViewPB = view_rev.into(); send_dart_notification(&view.id, FolderNotification::ViewUpdated) .payload(view) .send(); @@ -464,7 +464,7 @@ fn get_data_processor( } fn read_local_views_with_transaction<'a>( - identifiers: RepeatedTrashId, + identifiers: RepeatedTrashIdPB, transaction: &'a (dyn FolderPersistenceTransaction + 'a), ) -> Result, FlowyError> { let mut view_revs = vec![]; @@ -474,7 +474,7 @@ fn read_local_views_with_transaction<'a>( Ok(view_revs) } -fn notify_dart(view: View, notification: FolderNotification) { +fn notify_dart(view: ViewPB, notification: FolderNotification) { send_dart_notification(&view.id, notification).payload(view).send(); } @@ -489,13 +489,13 @@ fn notify_views_changed<'a>( trash_controller: Arc, transaction: &'a (dyn FolderPersistenceTransaction + 'a), ) -> FlowyResult<()> { - let items: Vec = read_belonging_views_on_local(belong_to_id, trash_controller.clone(), transaction)? + let items: Vec = read_belonging_views_on_local(belong_to_id, trash_controller.clone(), transaction)? .into_iter() .map(|view_rev| view_rev.into()) .collect(); tracing::Span::current().record("view_count", &format!("{}", items.len()).as_str()); - let repeated_view = RepeatedView { items }; + let repeated_view = RepeatedViewPB { items }; send_dart_notification(belong_to_id, FolderNotification::AppViewsChanged) .payload(repeated_view) .send(); diff --git a/frontend/rust-lib/flowy-folder/src/services/view/event_handler.rs b/frontend/rust-lib/flowy-folder/src/services/view/event_handler.rs index f970905f30..925ece6ba2 100644 --- a/frontend/rust-lib/flowy-folder/src/services/view/event_handler.rs +++ b/frontend/rust-lib/flowy-folder/src/services/view/event_handler.rs @@ -1,12 +1,13 @@ -use crate::entities::view::{MoveFolderItemParams, MoveFolderItemPayload, MoveFolderItemType}; -use crate::entities::ViewInfo; +use crate::entities::view::{MoveFolderItemParams, MoveFolderItemPayloadPB, MoveFolderItemType}; +use crate::entities::ViewInfoPB; use crate::manager::FolderManager; use crate::services::{notify_workspace_setting_did_change, AppController}; use crate::{ entities::{ - trash::Trash, + trash::TrashPB, view::{ - CreateViewParams, CreateViewPayload, RepeatedViewId, UpdateViewParams, UpdateViewPayload, View, ViewId, + CreateViewParams, CreateViewPayloadPB, RepeatedViewIdPB, UpdateViewParams, UpdateViewPayloadPB, ViewIdPB, + ViewPB, }, }, errors::FlowyError, @@ -17,35 +18,35 @@ use lib_dispatch::prelude::{data_result, AppData, Data, DataResult}; use std::{convert::TryInto, sync::Arc}; pub(crate) async fn create_view_handler( - data: Data, + data: Data, controller: AppData>, -) -> DataResult { +) -> DataResult { let params: CreateViewParams = data.into_inner().try_into()?; let view_rev = controller.create_view_from_params(params).await?; data_result(view_rev.into()) } pub(crate) async fn read_view_handler( - data: Data, + data: Data, controller: AppData>, -) -> DataResult { - let view_id: ViewId = data.into_inner(); +) -> DataResult { + let view_id: ViewIdPB = data.into_inner(); let view_rev = controller.read_view(view_id.clone()).await?; data_result(view_rev.into()) } pub(crate) async fn read_view_info_handler( - data: Data, + data: Data, controller: AppData>, -) -> DataResult { - let view_id: ViewId = data.into_inner(); +) -> DataResult { + let view_id: ViewIdPB = data.into_inner(); let view_info = controller.read_view_info(view_id.clone()).await?; data_result(view_info) } #[tracing::instrument(level = "debug", skip(data, controller), err)] pub(crate) async fn update_view_handler( - data: Data, + data: Data, controller: AppData>, ) -> Result<(), FlowyError> { let params: UpdateViewParams = data.into_inner().try_into()?; @@ -55,11 +56,11 @@ pub(crate) async fn update_view_handler( } pub(crate) async fn delete_view_handler( - data: Data, + data: Data, view_controller: AppData>, trash_controller: AppData>, ) -> Result<(), FlowyError> { - let params: RepeatedViewId = data.into_inner(); + let params: RepeatedViewIdPB = data.into_inner(); for view_id in ¶ms.items { let _ = view_controller.delete_view(view_id.into()).await; } @@ -72,35 +73,35 @@ pub(crate) async fn delete_view_handler( let trash_rev: TrashRevision = view.into(); trash_rev.into() }) - .collect::>(); + .collect::>(); let _ = trash_controller.add(trash).await?; Ok(()) } pub(crate) async fn set_latest_view_handler( - data: Data, + data: Data, folder: AppData>, controller: AppData>, ) -> Result<(), FlowyError> { - let view_id: ViewId = data.into_inner(); + let view_id: ViewIdPB = data.into_inner(); let _ = controller.set_latest_view(&view_id.value)?; let _ = notify_workspace_setting_did_change(&folder, &view_id).await?; Ok(()) } pub(crate) async fn close_view_handler( - data: Data, + data: Data, controller: AppData>, ) -> Result<(), FlowyError> { - let view_id: ViewId = data.into_inner(); + let view_id: ViewIdPB = data.into_inner(); let _ = controller.close_view(&view_id.value).await?; Ok(()) } #[tracing::instrument(level = "debug", skip_all, err)] pub(crate) async fn move_item_handler( - data: Data, + data: Data, view_controller: AppData>, app_controller: AppData>, ) -> Result<(), FlowyError> { @@ -120,10 +121,10 @@ pub(crate) async fn move_item_handler( #[tracing::instrument(level = "debug", skip(data, controller), err)] pub(crate) async fn duplicate_view_handler( - data: Data, + data: Data, controller: AppData>, ) -> Result<(), FlowyError> { - let view_id: ViewId = data.into_inner(); + let view_id: ViewIdPB = data.into_inner(); let _ = controller.duplicate_view(&view_id.value).await?; Ok(()) } diff --git a/frontend/rust-lib/flowy-folder/src/services/workspace/controller.rs b/frontend/rust-lib/flowy-folder/src/services/workspace/controller.rs index 9863cafdc5..42f3f65fa1 100644 --- a/frontend/rust-lib/flowy-folder/src/services/workspace/controller.rs +++ b/frontend/rust-lib/flowy-folder/src/services/workspace/controller.rs @@ -52,7 +52,7 @@ impl WorkspaceController { .into_iter() .map(|workspace_rev| workspace_rev.into()) .collect(); - let repeated_workspace = RepeatedWorkspace { items: workspaces }; + let repeated_workspace = RepeatedWorkspacePB { items: workspaces }; send_dart_notification(&token, FolderNotification::UserCreateWorkspace) .payload(repeated_workspace) .send(); @@ -99,7 +99,7 @@ impl WorkspaceController { Ok(()) } - pub(crate) async fn open_workspace(&self, params: WorkspaceId) -> Result { + pub(crate) async fn open_workspace(&self, params: WorkspaceIdPB) -> Result { let user_id = self.user.user_id()?; if let Some(workspace_id) = params.value { let workspace = self @@ -131,14 +131,14 @@ impl WorkspaceController { workspace_id: Option, user_id: &str, transaction: &'a (dyn FolderPersistenceTransaction + 'a), - ) -> Result { + ) -> Result { let workspace_id = workspace_id.to_owned(); let workspaces = transaction .read_workspaces(user_id, workspace_id)? .into_iter() .map(|workspace_rev| workspace_rev.into()) .collect(); - Ok(RepeatedWorkspace { items: workspaces }) + Ok(RepeatedWorkspacePB { items: workspaces }) } pub(crate) fn read_local_workspace<'a>( @@ -146,7 +146,7 @@ impl WorkspaceController { workspace_id: String, user_id: &str, transaction: &'a (dyn FolderPersistenceTransaction + 'a), - ) -> Result { + ) -> Result { let mut workspace_revs = transaction.read_workspaces(user_id, Some(workspace_id.clone()))?; if workspace_revs.is_empty() { return Err(FlowyError::record_not_found().context(format!("{} workspace not found", workspace_id))); @@ -155,7 +155,7 @@ impl WorkspaceController { let workspace = workspace_revs .drain(..1) .map(|workspace_rev| workspace_rev.into()) - .collect::>() + .collect::>() .pop() .unwrap(); Ok(workspace) @@ -186,7 +186,7 @@ impl WorkspaceController { #[tracing::instrument(level = "trace", skip(self), err)] fn delete_workspace_on_server(&self, workspace_id: &str) -> Result<(), FlowyError> { - let params = WorkspaceId { + let params = WorkspaceIdPB { value: Some(workspace_id.to_string()), }; let (token, server) = (self.user.token()?, self.cloud_service.clone()); @@ -221,11 +221,11 @@ pub async fn notify_workspace_setting_did_change( )?; let setting = match transaction.read_view(view_id) { - Ok(latest_view) => CurrentWorkspaceSetting { + Ok(latest_view) => CurrentWorkspaceSettingPB { workspace, latest_view: Some(latest_view.into()), }, - Err(_) => CurrentWorkspaceSetting { + Err(_) => CurrentWorkspaceSettingPB { workspace, latest_view: None, }, diff --git a/frontend/rust-lib/flowy-folder/src/services/workspace/event_handler.rs b/frontend/rust-lib/flowy-folder/src/services/workspace/event_handler.rs index 02fb37a12b..234fa3b7de 100644 --- a/frontend/rust-lib/flowy-folder/src/services/workspace/event_handler.rs +++ b/frontend/rust-lib/flowy-folder/src/services/workspace/event_handler.rs @@ -1,7 +1,7 @@ use crate::entities::{ - app::RepeatedApp, - view::View, - workspace::{CurrentWorkspaceSetting, RepeatedWorkspace, WorkspaceId, *}, + app::RepeatedAppPB, + view::ViewPB, + workspace::{CurrentWorkspaceSettingPB, RepeatedWorkspacePB, WorkspaceIdPB, *}, }; use crate::{ dart_notification::{send_dart_notification, FolderNotification}, @@ -14,9 +14,9 @@ use std::{convert::TryInto, sync::Arc}; #[tracing::instrument(level = "debug", skip(data, controller), err)] pub(crate) async fn create_workspace_handler( - data: Data, + data: Data, controller: AppData>, -) -> DataResult { +) -> DataResult { let controller = controller.get_ref().clone(); let params: CreateWorkspaceParams = data.into_inner().try_into()?; let workspace_rev = controller.create_workspace_from_params(params).await?; @@ -26,33 +26,33 @@ pub(crate) async fn create_workspace_handler( #[tracing::instrument(level = "debug", skip(controller), err)] pub(crate) async fn read_workspace_apps_handler( controller: AppData>, -) -> DataResult { +) -> DataResult { let items = controller .read_current_workspace_apps() .await? .into_iter() .map(|app_rev| app_rev.into()) .collect(); - let repeated_app = RepeatedApp { items }; + let repeated_app = RepeatedAppPB { items }; data_result(repeated_app) } #[tracing::instrument(level = "debug", skip(data, controller), err)] pub(crate) async fn open_workspace_handler( - data: Data, + data: Data, controller: AppData>, -) -> DataResult { - let params: WorkspaceId = data.into_inner(); +) -> DataResult { + let params: WorkspaceIdPB = data.into_inner(); let workspaces = controller.open_workspace(params).await?; data_result(workspaces) } #[tracing::instrument(level = "debug", skip(data, folder), err)] pub(crate) async fn read_workspaces_handler( - data: Data, + data: Data, folder: AppData>, -) -> DataResult { - let params: WorkspaceId = data.into_inner(); +) -> DataResult { + let params: WorkspaceIdPB = data.into_inner(); let user_id = folder.user.user_id()?; let workspace_controller = folder.workspace_controller.clone(); @@ -79,10 +79,10 @@ pub(crate) async fn read_workspaces_handler( #[tracing::instrument(level = "debug", skip(folder), err)] pub async fn read_cur_workspace_handler( folder: AppData>, -) -> DataResult { +) -> DataResult { let workspace_id = get_current_workspace()?; let user_id = folder.user.user_id()?; - let params = WorkspaceId { + let params = WorkspaceIdPB { value: Some(workspace_id.clone()), }; @@ -95,13 +95,13 @@ pub async fn read_cur_workspace_handler( }) .await?; - let latest_view: Option = folder + let latest_view: Option = folder .view_controller .latest_visit_view() .await .unwrap_or(None) .map(|view_rev| view_rev.into()); - let setting = CurrentWorkspaceSetting { workspace, latest_view }; + let setting = CurrentWorkspaceSettingPB { workspace, latest_view }; let _ = read_workspaces_on_server(folder, user_id, params); data_result(setting) } @@ -110,7 +110,7 @@ pub async fn read_cur_workspace_handler( fn read_workspaces_on_server( folder_manager: AppData>, user_id: String, - params: WorkspaceId, + params: WorkspaceIdPB, ) -> Result<(), FlowyError> { let (token, server) = (folder_manager.user.token()?, folder_manager.cloud_service.clone()); let persistence = folder_manager.persistence.clone(); @@ -145,7 +145,7 @@ fn read_workspaces_on_server( }) .await?; - let repeated_workspace = RepeatedWorkspace { + let repeated_workspace = RepeatedWorkspacePB { items: workspace_revs .into_iter() .map(|workspace_rev| workspace_rev.into()) diff --git a/frontend/rust-lib/flowy-folder/tests/workspace/folder_test.rs b/frontend/rust-lib/flowy-folder/tests/workspace/folder_test.rs index 86c3dc7478..f17986b484 100644 --- a/frontend/rust-lib/flowy-folder/tests/workspace/folder_test.rs +++ b/frontend/rust-lib/flowy-folder/tests/workspace/folder_test.rs @@ -1,6 +1,6 @@ use crate::script::{invalid_workspace_name_test_case, FolderScript::*, FolderTest}; use flowy_folder::entities::view::ViewDataType; -use flowy_folder::entities::workspace::CreateWorkspacePayload; +use flowy_folder::entities::workspace::CreateWorkspacePayloadPB; use flowy_revision::disk::RevisionState; use flowy_test::{event_builder::*, FlowySDKTest}; @@ -63,7 +63,7 @@ async fn workspace_create_with_apps() { async fn workspace_create_with_invalid_name() { for (name, code) in invalid_workspace_name_test_case() { let sdk = FlowySDKTest::default(); - let request = CreateWorkspacePayload { + let request = CreateWorkspacePayloadPB { name, desc: "".to_owned(), }; diff --git a/frontend/rust-lib/flowy-folder/tests/workspace/script.rs b/frontend/rust-lib/flowy-folder/tests/workspace/script.rs index 7b6091b7b5..ed16664d90 100644 --- a/frontend/rust-lib/flowy-folder/tests/workspace/script.rs +++ b/frontend/rust-lib/flowy-folder/tests/workspace/script.rs @@ -1,23 +1,23 @@ -use flowy_folder::entities::view::{RepeatedViewId, ViewId}; -use flowy_folder::entities::workspace::WorkspaceId; +use flowy_folder::entities::view::{RepeatedViewIdPB, ViewIdPB}; +use flowy_folder::entities::workspace::WorkspaceIdPB; use flowy_folder::entities::{ - app::{App, RepeatedApp}, - trash::Trash, - view::{RepeatedView, View, ViewDataType}, - workspace::Workspace, + app::{AppIdPB, CreateAppPayloadPB, UpdateAppPayloadPB}, + trash::{RepeatedTrashPB, TrashIdPB, TrashType}, + view::{CreateViewPayloadPB, UpdateViewPayloadPB}, + workspace::{CreateWorkspacePayloadPB, RepeatedWorkspacePB}, }; use flowy_folder::entities::{ - app::{AppId, CreateAppPayload, UpdateAppPayload}, - trash::{RepeatedTrash, TrashId, TrashType}, - view::{CreateViewPayload, UpdateViewPayload}, - workspace::{CreateWorkspacePayload, RepeatedWorkspace}, + app::{AppPB, RepeatedAppPB}, + trash::TrashPB, + view::{RepeatedViewPB, ViewDataType, ViewPB}, + workspace::WorkspacePB, }; use flowy_folder::event_map::FolderEvent::*; use flowy_folder::{errors::ErrorCode, services::folder_editor::FolderEditor}; use flowy_revision::disk::RevisionState; use flowy_revision::REVISION_WRITE_INTERVAL_IN_MILLIS; -use flowy_sync::entities::text_block::TextBlockInfoPB; +use flowy_sync::entities::text_block::DocumentPB; use flowy_test::{event_builder::*, FlowySDKTest}; use std::{sync::Arc, time::Duration}; use tokio::time::sleep; @@ -30,7 +30,7 @@ pub enum FolderScript { desc: String, }, // AssertWorkspaceRevisionJson(String), - AssertWorkspace(Workspace), + AssertWorkspace(WorkspacePB), ReadWorkspace(Option), // App @@ -39,7 +39,7 @@ pub enum FolderScript { desc: String, }, // AssertAppRevisionJson(String), - AssertApp(App), + AssertApp(AppPB), ReadApp(String), UpdateApp { name: Option, @@ -53,7 +53,7 @@ pub enum FolderScript { desc: String, data_type: ViewDataType, }, - AssertView(View), + AssertView(ViewPB), ReadView(String), UpdateView { name: Option, @@ -79,11 +79,11 @@ pub enum FolderScript { pub struct FolderTest { pub sdk: FlowySDKTest, - pub all_workspace: Vec, - pub workspace: Workspace, - pub app: App, - pub view: View, - pub trash: Vec, + pub all_workspace: Vec, + pub workspace: WorkspacePB, + pub app: AppPB, + pub view: ViewPB, + pub trash: Vec, // pub folder_editor: } @@ -101,11 +101,11 @@ impl FolderTest { ViewDataType::TextBlock, ) .await; - app.belongings = RepeatedView { + app.belongings = RepeatedViewPB { items: vec![view.clone()], }; - workspace.apps = RepeatedApp { + workspace.apps = RepeatedAppPB { items: vec![app.clone()], }; Self { @@ -247,8 +247,8 @@ pub fn invalid_workspace_name_test_case() -> Vec<(String, ErrorCode)> { ] } -pub async fn create_workspace(sdk: &FlowySDKTest, name: &str, desc: &str) -> Workspace { - let request = CreateWorkspacePayload { +pub async fn create_workspace(sdk: &FlowySDKTest, name: &str, desc: &str) -> WorkspacePB { + let request = CreateWorkspacePayloadPB { name: name.to_owned(), desc: desc.to_owned(), }; @@ -258,18 +258,18 @@ pub async fn create_workspace(sdk: &FlowySDKTest, name: &str, desc: &str) -> Wor .payload(request) .async_send() .await - .parse::(); + .parse::(); workspace } -pub async fn read_workspace(sdk: &FlowySDKTest, workspace_id: Option) -> Vec { - let request = WorkspaceId { value: workspace_id }; +pub async fn read_workspace(sdk: &FlowySDKTest, workspace_id: Option) -> Vec { + let request = WorkspaceIdPB { value: workspace_id }; let mut repeated_workspace = FolderEventBuilder::new(sdk.clone()) .event(ReadWorkspaces) .payload(request.clone()) .async_send() .await - .parse::(); + .parse::(); let workspaces; if let Some(workspace_id) = &request.value { @@ -277,7 +277,7 @@ pub async fn read_workspace(sdk: &FlowySDKTest, workspace_id: Option) -> .into_inner() .into_iter() .filter(|workspace| &workspace.id == workspace_id) - .collect::>(); + .collect::>(); debug_assert_eq!(workspaces.len(), 1); } else { workspaces = repeated_workspace.items; @@ -286,8 +286,8 @@ pub async fn read_workspace(sdk: &FlowySDKTest, workspace_id: Option) -> workspaces } -pub async fn create_app(sdk: &FlowySDKTest, workspace_id: &str, name: &str, desc: &str) -> App { - let create_app_request = CreateAppPayload { +pub async fn create_app(sdk: &FlowySDKTest, workspace_id: &str, name: &str, desc: &str) -> AppPB { + let create_app_request = CreateAppPayloadPB { workspace_id: workspace_id.to_owned(), name: name.to_string(), desc: desc.to_string(), @@ -299,12 +299,12 @@ pub async fn create_app(sdk: &FlowySDKTest, workspace_id: &str, name: &str, desc .payload(create_app_request) .async_send() .await - .parse::(); + .parse::(); app } -pub async fn read_app(sdk: &FlowySDKTest, app_id: &str) -> App { - let request = AppId { +pub async fn read_app(sdk: &FlowySDKTest, app_id: &str) -> AppPB { + let request = AppIdPB { value: app_id.to_owned(), }; @@ -313,13 +313,13 @@ pub async fn read_app(sdk: &FlowySDKTest, app_id: &str) -> App { .payload(request) .async_send() .await - .parse::(); + .parse::(); app } pub async fn update_app(sdk: &FlowySDKTest, app_id: &str, name: Option, desc: Option) { - let request = UpdateAppPayload { + let request = UpdateAppPayloadPB { app_id: app_id.to_string(), name, desc, @@ -335,7 +335,7 @@ pub async fn update_app(sdk: &FlowySDKTest, app_id: &str, name: Option, } pub async fn delete_app(sdk: &FlowySDKTest, app_id: &str) { - let request = AppId { + let request = AppIdPB { value: app_id.to_string(), }; @@ -346,8 +346,8 @@ pub async fn delete_app(sdk: &FlowySDKTest, app_id: &str) { .await; } -pub async fn create_view(sdk: &FlowySDKTest, app_id: &str, name: &str, desc: &str, data_type: ViewDataType) -> View { - let request = CreateViewPayload { +pub async fn create_view(sdk: &FlowySDKTest, app_id: &str, name: &str, desc: &str, data_type: ViewDataType) -> ViewPB { + let request = CreateViewPayloadPB { belong_to_id: app_id.to_string(), name: name.to_string(), desc: desc.to_string(), @@ -361,22 +361,22 @@ pub async fn create_view(sdk: &FlowySDKTest, app_id: &str, name: &str, desc: &st .payload(request) .async_send() .await - .parse::(); + .parse::(); view } -pub async fn read_view(sdk: &FlowySDKTest, view_id: &str) -> View { - let view_id: ViewId = view_id.into(); +pub async fn read_view(sdk: &FlowySDKTest, view_id: &str) -> ViewPB { + let view_id: ViewIdPB = view_id.into(); FolderEventBuilder::new(sdk.clone()) .event(ReadView) .payload(view_id) .async_send() .await - .parse::() + .parse::() } pub async fn update_view(sdk: &FlowySDKTest, view_id: &str, name: Option, desc: Option) { - let request = UpdateViewPayload { + let request = UpdateViewPayloadPB { view_id: view_id.to_string(), name, desc, @@ -390,7 +390,7 @@ pub async fn update_view(sdk: &FlowySDKTest, view_id: &str, name: Option } pub async fn delete_view(sdk: &FlowySDKTest, view_ids: Vec) { - let request = RepeatedViewId { items: view_ids }; + let request = RepeatedViewIdPB { items: view_ids }; FolderEventBuilder::new(sdk.clone()) .event(DeleteView) .payload(request) @@ -399,26 +399,26 @@ pub async fn delete_view(sdk: &FlowySDKTest, view_ids: Vec) { } #[allow(dead_code)] -pub async fn set_latest_view(sdk: &FlowySDKTest, view_id: &str) -> TextBlockInfoPB { - let view_id: ViewId = view_id.into(); +pub async fn set_latest_view(sdk: &FlowySDKTest, view_id: &str) -> DocumentPB { + let view_id: ViewIdPB = view_id.into(); FolderEventBuilder::new(sdk.clone()) .event(SetLatestView) .payload(view_id) .async_send() .await - .parse::() + .parse::() } -pub async fn read_trash(sdk: &FlowySDKTest) -> RepeatedTrash { +pub async fn read_trash(sdk: &FlowySDKTest) -> RepeatedTrashPB { FolderEventBuilder::new(sdk.clone()) .event(ReadTrash) .async_send() .await - .parse::() + .parse::() } pub async fn restore_app_from_trash(sdk: &FlowySDKTest, app_id: &str) { - let id = TrashId { + let id = TrashIdPB { id: app_id.to_owned(), ty: TrashType::TrashApp, }; @@ -430,7 +430,7 @@ pub async fn restore_app_from_trash(sdk: &FlowySDKTest, app_id: &str) { } pub async fn restore_view_from_trash(sdk: &FlowySDKTest, view_id: &str) { - let id = TrashId { + let id = TrashIdPB { id: view_id.to_owned(), ty: TrashType::TrashView, }; diff --git a/frontend/rust-lib/flowy-net/src/http_server/document.rs b/frontend/rust-lib/flowy-net/src/http_server/document.rs index c8d18b07b2..ca9cb47955 100644 --- a/frontend/rust-lib/flowy-net/src/http_server/document.rs +++ b/frontend/rust-lib/flowy-net/src/http_server/document.rs @@ -3,7 +3,7 @@ use crate::{ request::{HttpRequestBuilder, ResponseMiddleware}, }; use flowy_error::FlowyError; -use flowy_sync::entities::text_block::{CreateTextBlockParams, ResetTextBlockParams, TextBlockIdPB, TextBlockInfoPB}; +use flowy_sync::entities::text_block::{CreateTextBlockParams, DocumentPB, ResetTextBlockParams, TextBlockIdPB}; use flowy_text_block::BlockCloudService; use http_flowy::response::FlowyResponse; use lazy_static::lazy_static; @@ -27,7 +27,7 @@ impl BlockCloudService for BlockHttpCloudService { FutureResult::new(async move { create_document_request(&token, params, &url).await }) } - fn read_block(&self, token: &str, params: TextBlockIdPB) -> FutureResult, FlowyError> { + fn read_block(&self, token: &str, params: TextBlockIdPB) -> FutureResult, FlowyError> { let token = token.to_owned(); let url = self.config.doc_url(); FutureResult::new(async move { read_document_request(&token, params, &url).await }) @@ -54,7 +54,7 @@ pub async fn read_document_request( token: &str, params: TextBlockIdPB, url: &str, -) -> Result, FlowyError> { +) -> Result, FlowyError> { let doc = request_builder() .get(&url.to_owned()) .header(HEADER_TOKEN, token) diff --git a/frontend/rust-lib/flowy-net/src/http_server/folder.rs b/frontend/rust-lib/flowy-net/src/http_server/folder.rs index 788f7fa462..e600d617a9 100644 --- a/frontend/rust-lib/flowy-net/src/http_server/folder.rs +++ b/frontend/rust-lib/flowy-net/src/http_server/folder.rs @@ -1,15 +1,14 @@ use crate::{ - configuration::{ClientServerConfiguration, HEADER_TOKEN}, + configuration::ClientServerConfiguration, request::{HttpRequestBuilder, ResponseMiddleware}, }; use flowy_error::FlowyError; use flowy_folder::entities::{ - trash::RepeatedTrashId, - view::{CreateViewParams, RepeatedViewId, UpdateViewParams, ViewId}, - workspace::{CreateWorkspaceParams, UpdateWorkspaceParams, WorkspaceId}, - {AppId, CreateAppParams, UpdateAppParams}, + trash::RepeatedTrashIdPB, + view::{CreateViewParams, RepeatedViewIdPB, UpdateViewParams, ViewIdPB}, + workspace::{CreateWorkspaceParams, UpdateWorkspaceParams, WorkspaceIdPB}, + {AppIdPB, CreateAppParams, UpdateAppParams}, }; - use flowy_folder::event_map::FolderCouldServiceV1; use flowy_folder_data_model::revision::{AppRevision, TrashRevision, ViewRevision, WorkspaceRevision}; use http_flowy::errors::ServerError; @@ -45,7 +44,7 @@ impl FolderCouldServiceV1 for FolderHttpCloudService { }) } - fn read_workspace(&self, token: &str, params: WorkspaceId) -> FutureResult, FlowyError> { + fn read_workspace(&self, token: &str, params: WorkspaceIdPB) -> FutureResult, FlowyError> { let token = token.to_owned(); let url = self.config.workspace_url(); FutureResult::new(async move { @@ -63,7 +62,7 @@ impl FolderCouldServiceV1 for FolderHttpCloudService { }) } - fn delete_workspace(&self, token: &str, params: WorkspaceId) -> FutureResult<(), FlowyError> { + fn delete_workspace(&self, token: &str, params: WorkspaceIdPB) -> FutureResult<(), FlowyError> { let token = token.to_owned(); let url = self.config.workspace_url(); FutureResult::new(async move { @@ -81,7 +80,7 @@ impl FolderCouldServiceV1 for FolderHttpCloudService { }) } - fn read_view(&self, token: &str, params: ViewId) -> FutureResult, FlowyError> { + fn read_view(&self, token: &str, params: ViewIdPB) -> FutureResult, FlowyError> { let token = token.to_owned(); let url = self.config.view_url(); FutureResult::new(async move { @@ -90,7 +89,7 @@ impl FolderCouldServiceV1 for FolderHttpCloudService { }) } - fn delete_view(&self, token: &str, params: RepeatedViewId) -> FutureResult<(), FlowyError> { + fn delete_view(&self, token: &str, params: RepeatedViewIdPB) -> FutureResult<(), FlowyError> { let token = token.to_owned(); let url = self.config.view_url(); FutureResult::new(async move { @@ -117,7 +116,7 @@ impl FolderCouldServiceV1 for FolderHttpCloudService { }) } - fn read_app(&self, token: &str, params: AppId) -> FutureResult, FlowyError> { + fn read_app(&self, token: &str, params: AppIdPB) -> FutureResult, FlowyError> { let token = token.to_owned(); let url = self.config.app_url(); FutureResult::new(async move { @@ -135,7 +134,7 @@ impl FolderCouldServiceV1 for FolderHttpCloudService { }) } - fn delete_app(&self, token: &str, params: AppId) -> FutureResult<(), FlowyError> { + fn delete_app(&self, token: &str, params: AppIdPB) -> FutureResult<(), FlowyError> { let token = token.to_owned(); let url = self.config.app_url(); FutureResult::new(async move { @@ -144,7 +143,7 @@ impl FolderCouldServiceV1 for FolderHttpCloudService { }) } - fn create_trash(&self, token: &str, params: RepeatedTrashId) -> FutureResult<(), FlowyError> { + fn create_trash(&self, token: &str, params: RepeatedTrashIdPB) -> FutureResult<(), FlowyError> { let token = token.to_owned(); let url = self.config.trash_url(); FutureResult::new(async move { @@ -153,7 +152,7 @@ impl FolderCouldServiceV1 for FolderHttpCloudService { }) } - fn delete_trash(&self, token: &str, params: RepeatedTrashId) -> FutureResult<(), FlowyError> { + fn delete_trash(&self, token: &str, params: RepeatedTrashIdPB) -> FutureResult<(), FlowyError> { let token = token.to_owned(); let url = self.config.trash_url(); FutureResult::new(async move { @@ -172,6 +171,7 @@ impl FolderCouldServiceV1 for FolderHttpCloudService { } } +#[allow(dead_code)] fn request_builder() -> HttpRequestBuilder { HttpRequestBuilder::new().middleware(MIDDLEWARE.clone()) } @@ -193,7 +193,7 @@ pub async fn create_workspace_request( pub async fn read_workspaces_request( _token: &str, - _params: WorkspaceId, + _params: WorkspaceIdPB, _url: &str, ) -> Result, ServerError> { // let repeated_workspace = request_builder() @@ -208,26 +208,26 @@ pub async fn read_workspaces_request( } pub async fn update_workspace_request( - token: &str, - params: UpdateWorkspaceParams, - url: &str, + _token: &str, + _params: UpdateWorkspaceParams, + _url: &str, ) -> Result<(), ServerError> { - let _ = request_builder() - .patch(&url.to_owned()) - .header(HEADER_TOKEN, token) - .protobuf(params)? - .send() - .await?; + // let _ = request_builder() + // .patch(&url.to_owned()) + // .header(HEADER_TOKEN, token) + // .protobuf(params)? + // .send() + // .await?; Ok(()) } -pub async fn delete_workspace_request(token: &str, params: WorkspaceId, url: &str) -> Result<(), ServerError> { - let _ = request_builder() - .delete(url) - .header(HEADER_TOKEN, token) - .protobuf(params)? - .send() - .await?; +pub async fn delete_workspace_request(_token: &str, _params: WorkspaceIdPB, _url: &str) -> Result<(), ServerError> { + // let _ = request_builder() + // .delete(url) + // .header(HEADER_TOKEN, token) + // .protobuf(params)? + // .send() + // .await?; Ok(()) } @@ -247,7 +247,7 @@ pub async fn create_app_request( unimplemented!() } -pub async fn read_app_request(_token: &str, _params: AppId, _url: &str) -> Result, ServerError> { +pub async fn read_app_request(_token: &str, _params: AppIdPB, _url: &str) -> Result, ServerError> { // let app = request_builder() // .get(&url.to_owned()) // .header(HEADER_TOKEN, token) @@ -259,23 +259,23 @@ pub async fn read_app_request(_token: &str, _params: AppId, _url: &str) -> Resul unimplemented!() } -pub async fn update_app_request(token: &str, params: UpdateAppParams, url: &str) -> Result<(), ServerError> { - let _ = request_builder() - .patch(&url.to_owned()) - .header(HEADER_TOKEN, token) - .protobuf(params)? - .send() - .await?; +pub async fn update_app_request(_token: &str, _params: UpdateAppParams, _url: &str) -> Result<(), ServerError> { + // let _ = request_builder() + // .patch(&url.to_owned()) + // .header(HEADER_TOKEN, token) + // .protobuf(params)? + // .send() + // .await?; Ok(()) } -pub async fn delete_app_request(token: &str, params: AppId, url: &str) -> Result<(), ServerError> { - let _ = request_builder() - .delete(&url.to_owned()) - .header(HEADER_TOKEN, token) - .protobuf(params)? - .send() - .await?; +pub async fn delete_app_request(_token: &str, _params: AppIdPB, _url: &str) -> Result<(), ServerError> { + // let _ = request_builder() + // .delete(&url.to_owned()) + // .header(HEADER_TOKEN, token) + // .protobuf(params)? + // .send() + // .await?; Ok(()) } @@ -295,7 +295,11 @@ pub async fn create_view_request( unimplemented!() } -pub async fn read_view_request(_token: &str, _params: ViewId, _url: &str) -> Result, ServerError> { +pub async fn read_view_request( + _token: &str, + _params: ViewIdPB, + _url: &str, +) -> Result, ServerError> { // let view = request_builder() // .get(&url.to_owned()) // .header(HEADER_TOKEN, token) @@ -307,43 +311,43 @@ pub async fn read_view_request(_token: &str, _params: ViewId, _url: &str) -> Res unimplemented!() } -pub async fn update_view_request(token: &str, params: UpdateViewParams, url: &str) -> Result<(), ServerError> { - let _ = request_builder() - .patch(&url.to_owned()) - .header(HEADER_TOKEN, token) - .protobuf(params)? - .send() - .await?; +pub async fn update_view_request(_token: &str, _params: UpdateViewParams, _url: &str) -> Result<(), ServerError> { + // let _ = request_builder() + // .patch(&url.to_owned()) + // .header(HEADER_TOKEN, token) + // .protobuf(params)? + // .send() + // .await?; Ok(()) } -pub async fn delete_view_request(token: &str, params: RepeatedViewId, url: &str) -> Result<(), ServerError> { - let _ = request_builder() - .delete(&url.to_owned()) - .header(HEADER_TOKEN, token) - .protobuf(params)? - .send() - .await?; +pub async fn delete_view_request(_token: &str, _params: RepeatedViewIdPB, _url: &str) -> Result<(), ServerError> { + // let _ = request_builder() + // .delete(&url.to_owned()) + // .header(HEADER_TOKEN, token) + // .protobuf(params)? + // .send() + // .await?; Ok(()) } -pub async fn create_trash_request(token: &str, params: RepeatedTrashId, url: &str) -> Result<(), ServerError> { - let _ = request_builder() - .post(&url.to_owned()) - .header(HEADER_TOKEN, token) - .protobuf(params)? - .send() - .await?; +pub async fn create_trash_request(_token: &str, _params: RepeatedTrashIdPB, _url: &str) -> Result<(), ServerError> { + // let _ = request_builder() + // .post(&url.to_owned()) + // .header(HEADER_TOKEN, token) + // .protobuf(params)? + // .send() + // .await?; Ok(()) } -pub async fn delete_trash_request(token: &str, params: RepeatedTrashId, url: &str) -> Result<(), ServerError> { - let _ = request_builder() - .delete(&url.to_owned()) - .header(HEADER_TOKEN, token) - .protobuf(params)? - .send() - .await?; +pub async fn delete_trash_request(_token: &str, _params: RepeatedTrashIdPB, _url: &str) -> Result<(), ServerError> { + // let _ = request_builder() + // .delete(&url.to_owned()) + // .header(HEADER_TOKEN, token) + // .protobuf(params)? + // .send() + // .await?; Ok(()) } diff --git a/frontend/rust-lib/flowy-net/src/http_server/user.rs b/frontend/rust-lib/flowy-net/src/http_server/user.rs index faf5621161..7768c91bb6 100644 --- a/frontend/rust-lib/flowy-net/src/http_server/user.rs +++ b/frontend/rust-lib/flowy-net/src/http_server/user.rs @@ -1,7 +1,7 @@ use crate::{configuration::*, request::HttpRequestBuilder}; use flowy_error::FlowyError; use flowy_user::entities::{ - SignInParams, SignInResponse, SignUpParams, SignUpResponse, UpdateUserProfileParams, UserProfile, + SignInParams, SignInResponse, SignUpParams, SignUpResponse, UpdateUserProfileParams, UserProfilePB, }; use flowy_user::event_map::UserCloudService; use http_flowy::errors::ServerError; @@ -51,7 +51,7 @@ impl UserCloudService for UserHttpCloudService { }) } - fn get_user(&self, token: &str) -> FutureResult { + fn get_user(&self, token: &str) -> FutureResult { let token = token.to_owned(); let url = self.config.user_profile_url(); FutureResult::new(async move { @@ -92,7 +92,7 @@ pub async fn user_sign_out_request(token: &str, url: &str) -> Result<(), ServerE Ok(()) } -pub async fn get_user_profile_request(token: &str, url: &str) -> Result { +pub async fn get_user_profile_request(token: &str, url: &str) -> Result { let user_profile = request_builder() .get(&url.to_owned()) .header(HEADER_TOKEN, token) diff --git a/frontend/rust-lib/flowy-net/src/local_server/persistence.rs b/frontend/rust-lib/flowy-net/src/local_server/persistence.rs index d8bae35401..17008481b5 100644 --- a/frontend/rust-lib/flowy-net/src/local_server/persistence.rs +++ b/frontend/rust-lib/flowy-net/src/local_server/persistence.rs @@ -1,10 +1,10 @@ +use flowy_sync::entities::revision::{RepeatedRevision, Revision}; use flowy_sync::{ - entities::{folder::FolderInfo, text_block::TextBlockInfoPB}, + entities::{folder::FolderInfo, text_block::DocumentPB}, errors::CollaborateError, - protobuf::{RepeatedRevision as RepeatedRevisionPB, Revision as RevisionPB}, server_document::*, server_folder::FolderCloudPersistence, - util::{make_document_info_from_revisions_pb, make_folder_from_revisions_pb}, + util::{make_document_from_revision_pbs, make_folder_from_revisions_pb}, }; use lib_infra::future::BoxResultFuture; use std::{ @@ -15,17 +15,17 @@ use std::{ // For the moment, we use memory to cache the data, it will be implemented with // other storage. Like the Firestore,Dropbox.etc. pub trait RevisionCloudStorage: Send + Sync { - fn set_revisions(&self, repeated_revision: RepeatedRevisionPB) -> BoxResultFuture<(), CollaborateError>; + fn set_revisions(&self, repeated_revision: RepeatedRevision) -> BoxResultFuture<(), CollaborateError>; fn get_revisions( &self, object_id: &str, rev_ids: Option>, - ) -> BoxResultFuture; + ) -> BoxResultFuture; fn reset_object( &self, object_id: &str, - repeated_revision: RepeatedRevisionPB, + repeated_revision: RepeatedRevision, ) -> BoxResultFuture<(), CollaborateError>; } @@ -64,7 +64,7 @@ impl FolderCloudPersistence for LocalTextBlockCloudPersistence { &self, _user_id: &str, folder_id: &str, - repeated_revision: RepeatedRevisionPB, + repeated_revision: RepeatedRevision, ) -> BoxResultFuture, CollaborateError> { let folder_id = folder_id.to_owned(); let storage = self.storage.clone(); @@ -74,7 +74,7 @@ impl FolderCloudPersistence for LocalTextBlockCloudPersistence { }) } - fn save_folder_revisions(&self, repeated_revision: RepeatedRevisionPB) -> BoxResultFuture<(), CollaborateError> { + fn save_folder_revisions(&self, repeated_revision: RepeatedRevision) -> BoxResultFuture<(), CollaborateError> { let storage = self.storage.clone(); Box::pin(async move { let _ = storage.set_revisions(repeated_revision).await?; @@ -86,20 +86,19 @@ impl FolderCloudPersistence for LocalTextBlockCloudPersistence { &self, folder_id: &str, rev_ids: Option>, - ) -> BoxResultFuture, CollaborateError> { + ) -> BoxResultFuture, CollaborateError> { let folder_id = folder_id.to_owned(); let storage = self.storage.clone(); Box::pin(async move { - let mut repeated_revision = storage.get_revisions(&folder_id, rev_ids).await?; - let revisions: Vec = repeated_revision.take_items().into(); - Ok(revisions) + let repeated_revision = storage.get_revisions(&folder_id, rev_ids).await?; + Ok(repeated_revision.into_inner()) }) } fn reset_folder( &self, folder_id: &str, - repeated_revision: RepeatedRevisionPB, + repeated_revision: RepeatedRevision, ) -> BoxResultFuture<(), CollaborateError> { let storage = self.storage.clone(); let folder_id = folder_id.to_owned(); @@ -111,12 +110,12 @@ impl FolderCloudPersistence for LocalTextBlockCloudPersistence { } impl TextBlockCloudPersistence for LocalTextBlockCloudPersistence { - fn read_text_block(&self, doc_id: &str) -> BoxResultFuture { + fn read_text_block(&self, doc_id: &str) -> BoxResultFuture { let storage = self.storage.clone(); let doc_id = doc_id.to_owned(); Box::pin(async move { let repeated_revision = storage.get_revisions(&doc_id, None).await?; - match make_document_info_from_revisions_pb(&doc_id, repeated_revision)? { + match make_document_from_revision_pbs(&doc_id, repeated_revision)? { Some(document_info) => Ok(document_info), None => Err(CollaborateError::record_not_found()), } @@ -126,13 +125,13 @@ impl TextBlockCloudPersistence for LocalTextBlockCloudPersistence { fn create_text_block( &self, doc_id: &str, - repeated_revision: RepeatedRevisionPB, - ) -> BoxResultFuture, CollaborateError> { + repeated_revision: RepeatedRevision, + ) -> BoxResultFuture, CollaborateError> { let doc_id = doc_id.to_owned(); let storage = self.storage.clone(); Box::pin(async move { let _ = storage.set_revisions(repeated_revision.clone()).await?; - make_document_info_from_revisions_pb(&doc_id, repeated_revision) + make_document_from_revision_pbs(&doc_id, repeated_revision) }) } @@ -140,20 +139,16 @@ impl TextBlockCloudPersistence for LocalTextBlockCloudPersistence { &self, doc_id: &str, rev_ids: Option>, - ) -> BoxResultFuture, CollaborateError> { + ) -> BoxResultFuture, CollaborateError> { let doc_id = doc_id.to_owned(); let storage = self.storage.clone(); Box::pin(async move { - let mut repeated_revision = storage.get_revisions(&doc_id, rev_ids).await?; - let revisions: Vec = repeated_revision.take_items().into(); - Ok(revisions) + let repeated_revision = storage.get_revisions(&doc_id, rev_ids).await?; + Ok(repeated_revision.into_inner()) }) } - fn save_text_block_revisions( - &self, - repeated_revision: RepeatedRevisionPB, - ) -> BoxResultFuture<(), CollaborateError> { + fn save_text_block_revisions(&self, repeated_revision: RepeatedRevision) -> BoxResultFuture<(), CollaborateError> { let storage = self.storage.clone(); Box::pin(async move { let _ = storage.set_revisions(repeated_revision).await?; @@ -161,7 +156,7 @@ impl TextBlockCloudPersistence for LocalTextBlockCloudPersistence { }) } - fn reset_text_block(&self, doc_id: &str, revisions: RepeatedRevisionPB) -> BoxResultFuture<(), CollaborateError> { + fn reset_text_block(&self, doc_id: &str, revisions: RepeatedRevision) -> BoxResultFuture<(), CollaborateError> { let storage = self.storage.clone(); let doc_id = doc_id.to_owned(); Box::pin(async move { @@ -174,7 +169,7 @@ impl TextBlockCloudPersistence for LocalTextBlockCloudPersistence { #[derive(Default)] struct MemoryDocumentCloudStorage {} impl RevisionCloudStorage for MemoryDocumentCloudStorage { - fn set_revisions(&self, _repeated_revision: RepeatedRevisionPB) -> BoxResultFuture<(), CollaborateError> { + fn set_revisions(&self, _repeated_revision: RepeatedRevision) -> BoxResultFuture<(), CollaborateError> { Box::pin(async move { Ok(()) }) } @@ -182,9 +177,9 @@ impl RevisionCloudStorage for MemoryDocumentCloudStorage { &self, _doc_id: &str, _rev_ids: Option>, - ) -> BoxResultFuture { + ) -> BoxResultFuture { Box::pin(async move { - let repeated_revisions = RepeatedRevisionPB::new(); + let repeated_revisions = RepeatedRevision::default(); Ok(repeated_revisions) }) } @@ -192,7 +187,7 @@ impl RevisionCloudStorage for MemoryDocumentCloudStorage { fn reset_object( &self, _doc_id: &str, - _repeated_revision: RepeatedRevisionPB, + _repeated_revision: RepeatedRevision, ) -> BoxResultFuture<(), CollaborateError> { Box::pin(async move { Ok(()) }) } diff --git a/frontend/rust-lib/flowy-net/src/local_server/server.rs b/frontend/rust-lib/flowy-net/src/local_server/server.rs index 66a7682584..338697f432 100644 --- a/frontend/rust-lib/flowy-net/src/local_server/server.rs +++ b/frontend/rust-lib/flowy-net/src/local_server/server.rs @@ -6,7 +6,7 @@ use flowy_folder::event_map::FolderCouldServiceV1; use flowy_sync::{ client_document::default::initial_quill_delta_string, entities::{ - text_block::{CreateTextBlockParams, ResetTextBlockParams, TextBlockIdPB, TextBlockInfoPB}, + text_block::{CreateTextBlockParams, DocumentPB, ResetTextBlockParams, TextBlockIdPB}, ws_data::{ClientRevisionWSData, ClientRevisionWSDataType}, }, errors::CollaborateError, @@ -253,17 +253,17 @@ impl RevisionUser for LocalRevisionUser { } use flowy_folder::entities::{ - app::{AppId, CreateAppParams, UpdateAppParams}, - trash::RepeatedTrashId, - view::{CreateViewParams, RepeatedViewId, UpdateViewParams, ViewId}, - workspace::{CreateWorkspaceParams, UpdateWorkspaceParams, WorkspaceId}, + app::{AppIdPB, CreateAppParams, UpdateAppParams}, + trash::RepeatedTrashIdPB, + view::{CreateViewParams, RepeatedViewIdPB, UpdateViewParams, ViewIdPB}, + workspace::{CreateWorkspaceParams, UpdateWorkspaceParams, WorkspaceIdPB}, }; use flowy_folder_data_model::revision::{ gen_app_id, gen_workspace_id, AppRevision, TrashRevision, ViewRevision, WorkspaceRevision, }; use flowy_text_block::BlockCloudService; use flowy_user::entities::{ - SignInParams, SignInResponse, SignUpParams, SignUpResponse, UpdateUserProfileParams, UserProfile, + SignInParams, SignInResponse, SignUpParams, SignUpResponse, UpdateUserProfileParams, UserProfilePB, }; use flowy_user::event_map::UserCloudService; use lib_infra::{future::FutureResult, util::timestamp}; @@ -289,7 +289,7 @@ impl FolderCouldServiceV1 for LocalServer { FutureResult::new(async { Ok(workspace) }) } - fn read_workspace(&self, _token: &str, _params: WorkspaceId) -> FutureResult, FlowyError> { + fn read_workspace(&self, _token: &str, _params: WorkspaceIdPB) -> FutureResult, FlowyError> { FutureResult::new(async { Ok(vec![]) }) } @@ -297,7 +297,7 @@ impl FolderCouldServiceV1 for LocalServer { FutureResult::new(async { Ok(()) }) } - fn delete_workspace(&self, _token: &str, _params: WorkspaceId) -> FutureResult<(), FlowyError> { + fn delete_workspace(&self, _token: &str, _params: WorkspaceIdPB) -> FutureResult<(), FlowyError> { FutureResult::new(async { Ok(()) }) } @@ -320,11 +320,11 @@ impl FolderCouldServiceV1 for LocalServer { FutureResult::new(async { Ok(view) }) } - fn read_view(&self, _token: &str, _params: ViewId) -> FutureResult, FlowyError> { + fn read_view(&self, _token: &str, _params: ViewIdPB) -> FutureResult, FlowyError> { FutureResult::new(async { Ok(None) }) } - fn delete_view(&self, _token: &str, _params: RepeatedViewId) -> FutureResult<(), FlowyError> { + fn delete_view(&self, _token: &str, _params: RepeatedViewIdPB) -> FutureResult<(), FlowyError> { FutureResult::new(async { Ok(()) }) } @@ -347,7 +347,7 @@ impl FolderCouldServiceV1 for LocalServer { FutureResult::new(async { Ok(app) }) } - fn read_app(&self, _token: &str, _params: AppId) -> FutureResult, FlowyError> { + fn read_app(&self, _token: &str, _params: AppIdPB) -> FutureResult, FlowyError> { FutureResult::new(async { Ok(None) }) } @@ -355,15 +355,15 @@ impl FolderCouldServiceV1 for LocalServer { FutureResult::new(async { Ok(()) }) } - fn delete_app(&self, _token: &str, _params: AppId) -> FutureResult<(), FlowyError> { + fn delete_app(&self, _token: &str, _params: AppIdPB) -> FutureResult<(), FlowyError> { FutureResult::new(async { Ok(()) }) } - fn create_trash(&self, _token: &str, _params: RepeatedTrashId) -> FutureResult<(), FlowyError> { + fn create_trash(&self, _token: &str, _params: RepeatedTrashIdPB) -> FutureResult<(), FlowyError> { FutureResult::new(async { Ok(()) }) } - fn delete_trash(&self, _token: &str, _params: RepeatedTrashId) -> FutureResult<(), FlowyError> { + fn delete_trash(&self, _token: &str, _params: RepeatedTrashIdPB) -> FutureResult<(), FlowyError> { FutureResult::new(async { Ok(()) }) } @@ -405,8 +405,8 @@ impl UserCloudService for LocalServer { FutureResult::new(async { Ok(()) }) } - fn get_user(&self, _token: &str) -> FutureResult { - FutureResult::new(async { Ok(UserProfile::default()) }) + fn get_user(&self, _token: &str) -> FutureResult { + FutureResult::new(async { Ok(UserProfilePB::default()) }) } fn ws_addr(&self) -> String { @@ -419,8 +419,8 @@ impl BlockCloudService for LocalServer { FutureResult::new(async { Ok(()) }) } - fn read_block(&self, _token: &str, params: TextBlockIdPB) -> FutureResult, FlowyError> { - let doc = TextBlockInfoPB { + fn read_block(&self, _token: &str, params: TextBlockIdPB) -> FutureResult, FlowyError> { + let doc = DocumentPB { block_id: params.value, text: initial_quill_delta_string(), rev_id: 0, diff --git a/frontend/rust-lib/flowy-test/src/event_builder.rs b/frontend/rust-lib/flowy-test/src/event_builder.rs index ed6f3c3bc8..d9841d6b4a 100644 --- a/frontend/rust-lib/flowy-test/src/event_builder.rs +++ b/frontend/rust-lib/flowy-test/src/event_builder.rs @@ -1,5 +1,5 @@ use crate::FlowySDKTest; -use flowy_user::{entities::UserProfile, errors::FlowyError}; +use flowy_user::{entities::UserProfilePB, errors::FlowyError}; use lib_dispatch::prelude::{EventDispatcher, EventResponse, FromBytes, ModuleRequest, StatusCode, ToBytes, *}; use std::{ convert::TryFrom, @@ -14,7 +14,7 @@ impl FolderEventBuilder { pub fn new(sdk: FlowySDKTest) -> Self { EventBuilder::test(TestContext::new(sdk)) } - pub fn user_profile(&self) -> &Option { + pub fn user_profile(&self) -> &Option { &self.user_profile } } @@ -24,7 +24,7 @@ pub type UserModuleEventBuilder = FolderEventBuilder; #[derive(Clone)] pub struct EventBuilder { context: TestContext, - user_profile: Option, + user_profile: Option, err_phantom: PhantomData, } diff --git a/frontend/rust-lib/flowy-test/src/helper.rs b/frontend/rust-lib/flowy-test/src/helper.rs index efc4282386..1265bd695c 100644 --- a/frontend/rust-lib/flowy-test/src/helper.rs +++ b/frontend/rust-lib/flowy-test/src/helper.rs @@ -1,15 +1,15 @@ use crate::prelude::*; -use flowy_folder::entities::WorkspaceId; +use flowy_folder::entities::WorkspaceIdPB; use flowy_folder::{ entities::{ app::*, view::*, - workspace::{CreateWorkspacePayload, Workspace}, + workspace::{CreateWorkspacePayloadPB, WorkspacePB}, }, event_map::FolderEvent::{CreateWorkspace, OpenWorkspace, *}, }; use flowy_user::{ - entities::{SignInPayload, SignUpPayload, UserProfile}, + entities::{SignInPayloadPB, SignUpPayloadPB, UserProfilePB}, errors::FlowyError, event_map::UserEvent::{InitUser, SignIn, SignOut, SignUp}, }; @@ -18,9 +18,9 @@ use std::{fs, path::PathBuf, sync::Arc}; pub struct ViewTest { pub sdk: FlowySDKTest, - pub workspace: Workspace, - pub app: App, - pub view: View, + pub workspace: WorkspacePB, + pub app: AppPB, + pub view: ViewPB, } impl ViewTest { @@ -47,8 +47,8 @@ impl ViewTest { } } -async fn create_workspace(sdk: &FlowySDKTest, name: &str, desc: &str) -> Workspace { - let request = CreateWorkspacePayload { +async fn create_workspace(sdk: &FlowySDKTest, name: &str, desc: &str) -> WorkspacePB { + let request = CreateWorkspacePayloadPB { name: name.to_owned(), desc: desc.to_owned(), }; @@ -58,12 +58,12 @@ async fn create_workspace(sdk: &FlowySDKTest, name: &str, desc: &str) -> Workspa .payload(request) .async_send() .await - .parse::(); + .parse::(); workspace } async fn open_workspace(sdk: &FlowySDKTest, workspace_id: &str) { - let payload = WorkspaceId { + let payload = WorkspaceIdPB { value: Some(workspace_id.to_owned()), }; let _ = FolderEventBuilder::new(sdk.clone()) @@ -73,8 +73,8 @@ async fn open_workspace(sdk: &FlowySDKTest, workspace_id: &str) { .await; } -async fn create_app(sdk: &FlowySDKTest, name: &str, desc: &str, workspace_id: &str) -> App { - let create_app_request = CreateAppPayload { +async fn create_app(sdk: &FlowySDKTest, name: &str, desc: &str, workspace_id: &str) -> AppPB { + let create_app_request = CreateAppPayloadPB { workspace_id: workspace_id.to_owned(), name: name.to_string(), desc: desc.to_string(), @@ -86,12 +86,12 @@ async fn create_app(sdk: &FlowySDKTest, name: &str, desc: &str, workspace_id: &s .payload(create_app_request) .async_send() .await - .parse::(); + .parse::(); app } -async fn create_view(sdk: &FlowySDKTest, app_id: &str, data_type: ViewDataType, data: Vec) -> View { - let request = CreateViewPayload { +async fn create_view(sdk: &FlowySDKTest, app_id: &str, data_type: ViewDataType, data: Vec) -> ViewPB { + let request = CreateViewPayloadPB { belong_to_id: app_id.to_string(), name: "View A".to_string(), desc: "".to_string(), @@ -106,7 +106,7 @@ async fn create_view(sdk: &FlowySDKTest, app_id: &str, data_type: ViewDataType, .payload(request) .async_send() .await - .parse::(); + .parse::(); view } @@ -138,13 +138,13 @@ pub fn login_password() -> String { } pub struct SignUpContext { - pub user_profile: UserProfile, + pub user_profile: UserProfilePB, pub password: String, } pub fn sign_up(dispatch: Arc) -> SignUpContext { let password = login_password(); - let payload = SignUpPayload { + let payload = SignUpPayloadPB { email: random_email(), name: "app flowy".to_string(), password: password.clone(), @@ -154,7 +154,7 @@ pub fn sign_up(dispatch: Arc) -> SignUpContext { let request = ModuleRequest::new(SignUp).payload(payload); let user_profile = EventDispatcher::sync_send(dispatch, request) - .parse::() + .parse::() .unwrap() .unwrap(); @@ -164,7 +164,7 @@ pub fn sign_up(dispatch: Arc) -> SignUpContext { pub async fn async_sign_up(dispatch: Arc) -> SignUpContext { let password = login_password(); let email = random_email(); - let payload = SignUpPayload { + let payload = SignUpPayloadPB { email, name: "app flowy".to_string(), password: password.clone(), @@ -175,7 +175,7 @@ pub async fn async_sign_up(dispatch: Arc) -> SignUpContext { let request = ModuleRequest::new(SignUp).payload(payload); let user_profile = EventDispatcher::async_send(dispatch.clone(), request) .await - .parse::() + .parse::() .unwrap() .unwrap(); @@ -189,8 +189,8 @@ pub async fn init_user_setting(dispatch: Arc) { } #[allow(dead_code)] -fn sign_in(dispatch: Arc) -> UserProfile { - let payload = SignInPayload { +fn sign_in(dispatch: Arc) -> UserProfilePB { + let payload = SignInPayloadPB { email: login_email(), password: login_password(), name: "rust".to_owned(), @@ -200,7 +200,7 @@ fn sign_in(dispatch: Arc) -> UserProfile { let request = ModuleRequest::new(SignIn).payload(payload); EventDispatcher::sync_send(dispatch, request) - .parse::() + .parse::() .unwrap() .unwrap() } diff --git a/frontend/rust-lib/flowy-test/src/lib.rs b/frontend/rust-lib/flowy-test/src/lib.rs index 70159edf19..8f6aacb44d 100644 --- a/frontend/rust-lib/flowy-test/src/lib.rs +++ b/frontend/rust-lib/flowy-test/src/lib.rs @@ -4,7 +4,7 @@ pub mod helper; use crate::helper::*; use flowy_net::{get_client_server_configuration, ClientServerConfiguration}; use flowy_sdk::{FlowySDK, FlowySDKConfig}; -use flowy_user::entities::UserProfile; +use flowy_user::entities::UserProfilePB; use nanoid::nanoid; pub mod prelude { @@ -47,7 +47,7 @@ impl FlowySDKTest { context } - pub async fn init_user(&self) -> UserProfile { + pub async fn init_user(&self) -> UserProfilePB { let context = async_sign_up(self.inner.dispatcher()).await; init_user_setting(self.inner.dispatcher()).await; context.user_profile diff --git a/frontend/rust-lib/flowy-text-block/src/editor.rs b/frontend/rust-lib/flowy-text-block/src/editor.rs index 84b30a0047..6fed85c913 100644 --- a/frontend/rust-lib/flowy-text-block/src/editor.rs +++ b/frontend/rust-lib/flowy-text-block/src/editor.rs @@ -9,7 +9,7 @@ use flowy_error::{internal_error, FlowyResult}; use flowy_revision::{RevisionCloudService, RevisionManager, RevisionObjectBuilder, RevisionWebSocket}; use flowy_sync::entities::ws_data::ServerRevisionWSData; use flowy_sync::{ - entities::{revision::Revision, text_block::TextBlockInfoPB}, + entities::{revision::Revision, text_block::DocumentPB}, errors::CollaborateResult, util::make_delta_from_revisions, }; @@ -229,14 +229,14 @@ impl TextBlockEditor { struct TextBlockInfoBuilder(); impl RevisionObjectBuilder for TextBlockInfoBuilder { - type Output = TextBlockInfoPB; + type Output = DocumentPB; fn build_object(object_id: &str, revisions: Vec) -> FlowyResult { let (base_rev_id, rev_id) = revisions.last().unwrap().pair_rev_id(); let mut delta = make_delta_from_revisions(revisions)?; correct_delta(&mut delta); - Result::::Ok(TextBlockInfoPB { + Result::::Ok(DocumentPB { block_id: object_id.to_owned(), text: delta.to_delta_str(), rev_id, diff --git a/frontend/rust-lib/flowy-text-block/src/lib.rs b/frontend/rust-lib/flowy-text-block/src/lib.rs index 808bc2d6f9..37ddf6ea1e 100644 --- a/frontend/rust-lib/flowy-text-block/src/lib.rs +++ b/frontend/rust-lib/flowy-text-block/src/lib.rs @@ -15,13 +15,13 @@ pub mod errors { pub const TEXT_BLOCK_SYNC_INTERVAL_IN_MILLIS: u64 = 1000; use crate::errors::FlowyError; -use flowy_sync::entities::text_block::{CreateTextBlockParams, ResetTextBlockParams, TextBlockIdPB, TextBlockInfoPB}; +use flowy_sync::entities::text_block::{CreateTextBlockParams, DocumentPB, ResetTextBlockParams, TextBlockIdPB}; use lib_infra::future::FutureResult; pub trait BlockCloudService: Send + Sync { fn create_block(&self, token: &str, params: CreateTextBlockParams) -> FutureResult<(), FlowyError>; - fn read_block(&self, token: &str, params: TextBlockIdPB) -> FutureResult, FlowyError>; + fn read_block(&self, token: &str, params: TextBlockIdPB) -> FutureResult, FlowyError>; fn update_block(&self, token: &str, params: ResetTextBlockParams) -> FutureResult<(), FlowyError>; } diff --git a/frontend/rust-lib/flowy-user/src/entities/auth.rs b/frontend/rust-lib/flowy-user/src/entities/auth.rs index 14224ae231..f7625b37d7 100644 --- a/frontend/rust-lib/flowy-user/src/entities/auth.rs +++ b/frontend/rust-lib/flowy-user/src/entities/auth.rs @@ -4,7 +4,7 @@ use flowy_derive::ProtoBuf; use std::convert::TryInto; #[derive(ProtoBuf, Default)] -pub struct SignInPayload { +pub struct SignInPayloadPB { #[pb(index = 1)] pub email: String, @@ -42,7 +42,7 @@ pub struct SignInResponse { pub token: String, } -impl TryInto for SignInPayload { +impl TryInto for SignInPayloadPB { type Error = ErrorCode; fn try_into(self) -> Result { @@ -58,7 +58,7 @@ impl TryInto for SignInPayload { } #[derive(ProtoBuf, Default)] -pub struct SignUpPayload { +pub struct SignUpPayloadPB { #[pb(index = 1)] pub email: String, @@ -68,7 +68,7 @@ pub struct SignUpPayload { #[pb(index = 3)] pub password: String, } -impl TryInto for SignUpPayload { +impl TryInto for SignUpPayloadPB { type Error = ErrorCode; fn try_into(self) -> Result { diff --git a/frontend/rust-lib/flowy-user/src/entities/user_profile.rs b/frontend/rust-lib/flowy-user/src/entities/user_profile.rs index 82553e8050..276894ffc8 100644 --- a/frontend/rust-lib/flowy-user/src/entities/user_profile.rs +++ b/frontend/rust-lib/flowy-user/src/entities/user_profile.rs @@ -7,13 +7,13 @@ use crate::{ }; #[derive(Default, ProtoBuf)] -pub struct UserToken { +pub struct UserTokenPB { #[pb(index = 1)] pub token: String, } #[derive(ProtoBuf, Default, Debug, PartialEq, Eq, Clone)] -pub struct UserProfile { +pub struct UserProfilePB { #[pb(index = 1)] pub id: String, @@ -28,7 +28,7 @@ pub struct UserProfile { } #[derive(ProtoBuf, Default)] -pub struct UpdateUserProfilePayload { +pub struct UpdateUserProfilePayloadPB { #[pb(index = 1)] pub id: String, @@ -42,7 +42,7 @@ pub struct UpdateUserProfilePayload { pub password: Option, } -impl UpdateUserProfilePayload { +impl UpdateUserProfilePayloadPB { pub fn new(id: &str) -> Self { Self { id: id.to_owned(), @@ -85,7 +85,9 @@ impl UpdateUserProfileParams { pub fn new(user_id: &str) -> Self { Self { id: user_id.to_owned(), - ..Default::default() + name: None, + email: None, + password: None, } } @@ -105,7 +107,7 @@ impl UpdateUserProfileParams { } } -impl TryInto for UpdateUserProfilePayload { +impl TryInto for UpdateUserProfilePayloadPB { type Error = ErrorCode; fn try_into(self) -> Result { diff --git a/frontend/rust-lib/flowy-user/src/entities/user_setting.rs b/frontend/rust-lib/flowy-user/src/entities/user_setting.rs index 8f7beadb4a..23c74b6d5f 100644 --- a/frontend/rust-lib/flowy-user/src/entities/user_setting.rs +++ b/frontend/rust-lib/flowy-user/src/entities/user_setting.rs @@ -2,22 +2,22 @@ use flowy_derive::ProtoBuf; use serde::{Deserialize, Serialize}; #[derive(ProtoBuf, Default, Debug, Clone)] -pub struct UserPreferences { +pub struct UserPreferencesPB { #[pb(index = 1)] user_id: String, #[pb(index = 2)] - appearance_setting: AppearanceSettings, + appearance_setting: AppearanceSettingsPB, } #[derive(ProtoBuf, Serialize, Deserialize, Debug, Clone)] -pub struct AppearanceSettings { +pub struct AppearanceSettingsPB { #[pb(index = 1)] pub theme: String, #[pb(index = 2)] #[serde(default)] - pub locale: LocaleSettings, + pub locale: LocaleSettingsPB, #[pb(index = 3)] #[serde(default = "DEFAULT_RESET_VALUE")] @@ -27,7 +27,7 @@ pub struct AppearanceSettings { const DEFAULT_RESET_VALUE: fn() -> bool = || APPEARANCE_RESET_AS_DEFAULT; #[derive(ProtoBuf, Serialize, Deserialize, Debug, Clone)] -pub struct LocaleSettings { +pub struct LocaleSettingsPB { #[pb(index = 1)] pub language_code: String, @@ -35,7 +35,7 @@ pub struct LocaleSettings { pub country_code: String, } -impl std::default::Default for LocaleSettings { +impl std::default::Default for LocaleSettingsPB { fn default() -> Self { Self { language_code: "en".to_owned(), @@ -47,11 +47,11 @@ impl std::default::Default for LocaleSettings { pub const APPEARANCE_DEFAULT_THEME: &str = "light"; const APPEARANCE_RESET_AS_DEFAULT: bool = true; -impl std::default::Default for AppearanceSettings { +impl std::default::Default for AppearanceSettingsPB { fn default() -> Self { - AppearanceSettings { + AppearanceSettingsPB { theme: APPEARANCE_DEFAULT_THEME.to_owned(), - locale: LocaleSettings::default(), + locale: LocaleSettingsPB::default(), reset_as_default: APPEARANCE_RESET_AS_DEFAULT, } } diff --git a/frontend/rust-lib/flowy-user/src/event_map.rs b/frontend/rust-lib/flowy-user/src/event_map.rs index 348da177d3..ced1ede179 100644 --- a/frontend/rust-lib/flowy-user/src/event_map.rs +++ b/frontend/rust-lib/flowy-user/src/event_map.rs @@ -1,5 +1,5 @@ use crate::entities::{ - SignInParams, SignInResponse, SignUpParams, SignUpResponse, UpdateUserProfileParams, UserProfile, + SignInParams, SignInResponse, SignUpParams, SignUpResponse, UpdateUserProfileParams, UserProfilePB, }; use crate::{errors::FlowyError, handlers::*, services::UserSession}; use lib_dispatch::prelude::*; @@ -26,7 +26,7 @@ pub trait UserCloudService: Send + Sync { fn sign_in(&self, params: SignInParams) -> FutureResult; fn sign_out(&self, token: &str) -> FutureResult<(), FlowyError>; fn update_user(&self, token: &str, params: UpdateUserProfileParams) -> FutureResult<(), FlowyError>; - fn get_user(&self, token: &str) -> FutureResult; + fn get_user(&self, token: &str) -> FutureResult; fn ws_addr(&self) -> String; } @@ -39,27 +39,27 @@ pub enum UserEvent { #[event()] InitUser = 0, - #[event(input = "SignInPayload", output = "UserProfile")] + #[event(input = "SignInPayloadPB", output = "UserProfilePB")] SignIn = 1, - #[event(input = "SignUpPayload", output = "UserProfile")] + #[event(input = "SignUpPayloadPB", output = "UserProfilePB")] SignUp = 2, #[event(passthrough)] SignOut = 3, - #[event(input = "UpdateUserProfilePayload")] + #[event(input = "UpdateUserProfilePayloadPB")] UpdateUserProfile = 4, - #[event(output = "UserProfile")] + #[event(output = "UserProfilePB")] GetUserProfile = 5, - #[event(output = "UserProfile")] + #[event(output = "UserProfilePB")] CheckUser = 6, - #[event(input = "AppearanceSettings")] + #[event(input = "AppearanceSettingsPB")] SetAppearanceSetting = 7, - #[event(output = "AppearanceSettings")] + #[event(output = "AppearanceSettingsPB")] GetAppearanceSetting = 8, } diff --git a/frontend/rust-lib/flowy-user/src/handlers/auth_handler.rs b/frontend/rust-lib/flowy-user/src/handlers/auth_handler.rs index 22a17d887c..8ff5bdb7e2 100644 --- a/frontend/rust-lib/flowy-user/src/handlers/auth_handler.rs +++ b/frontend/rust-lib/flowy-user/src/handlers/auth_handler.rs @@ -7,9 +7,9 @@ use std::{convert::TryInto, sync::Arc}; // tracing instrument 👉🏻 https://docs.rs/tracing/0.1.26/tracing/attr.instrument.html #[tracing::instrument(level = "debug", name = "sign_in", skip(data, session), fields(email = %data.email), err)] pub async fn sign_in( - data: Data, + data: Data, session: AppData>, -) -> DataResult { +) -> DataResult { let params: SignInParams = data.into_inner().try_into()?; let user_profile = session.sign_in(params).await?; data_result(user_profile) @@ -26,9 +26,9 @@ pub async fn sign_in( err )] pub async fn sign_up( - data: Data, + data: Data, session: AppData>, -) -> DataResult { +) -> DataResult { let params: SignUpParams = data.into_inner().try_into()?; let user_profile = session.sign_up(params).await?; diff --git a/frontend/rust-lib/flowy-user/src/handlers/user_handler.rs b/frontend/rust-lib/flowy-user/src/handlers/user_handler.rs index 6ee62519e7..8a10dd89e2 100644 --- a/frontend/rust-lib/flowy-user/src/handlers/user_handler.rs +++ b/frontend/rust-lib/flowy-user/src/handlers/user_handler.rs @@ -1,5 +1,5 @@ use crate::entities::{ - AppearanceSettings, UpdateUserProfileParams, UpdateUserProfilePayload, UserProfile, APPEARANCE_DEFAULT_THEME, + AppearanceSettingsPB, UpdateUserProfileParams, UpdateUserProfilePayloadPB, UserProfilePB, APPEARANCE_DEFAULT_THEME, }; use crate::{errors::FlowyError, services::UserSession}; use flowy_database::kv::KV; @@ -13,13 +13,13 @@ pub async fn init_user_handler(session: AppData>) -> Result<(), } #[tracing::instrument(level = "debug", skip(session))] -pub async fn check_user_handler(session: AppData>) -> DataResult { +pub async fn check_user_handler(session: AppData>) -> DataResult { let user_profile = session.check_user().await?; data_result(user_profile) } #[tracing::instrument(level = "debug", skip(session))] -pub async fn get_user_profile_handler(session: AppData>) -> DataResult { +pub async fn get_user_profile_handler(session: AppData>) -> DataResult { let user_profile = session.get_user_profile().await?; data_result(user_profile) } @@ -32,7 +32,7 @@ pub async fn sign_out(session: AppData>) -> Result<(), FlowyErr #[tracing::instrument(level = "debug", skip(data, session))] pub async fn update_user_profile_handler( - data: Data, + data: Data, session: AppData>, ) -> Result<(), FlowyError> { let params: UpdateUserProfileParams = data.into_inner().try_into()?; @@ -43,7 +43,7 @@ pub async fn update_user_profile_handler( const APPEARANCE_SETTING_CACHE_KEY: &str = "appearance_settings"; #[tracing::instrument(level = "debug", skip(data), err)] -pub async fn set_appearance_setting(data: Data) -> Result<(), FlowyError> { +pub async fn set_appearance_setting(data: Data) -> Result<(), FlowyError> { let mut setting = data.into_inner(); if setting.theme.is_empty() { setting.theme = APPEARANCE_DEFAULT_THEME.to_string(); @@ -55,15 +55,15 @@ pub async fn set_appearance_setting(data: Data) -> Result<() } #[tracing::instrument(err)] -pub async fn get_appearance_setting() -> DataResult { +pub async fn get_appearance_setting() -> DataResult { match KV::get_str(APPEARANCE_SETTING_CACHE_KEY) { - None => data_result(AppearanceSettings::default()), + None => data_result(AppearanceSettingsPB::default()), Some(s) => { let setting = match serde_json::from_str(&s) { Ok(setting) => setting, Err(e) => { tracing::error!("Deserialize AppearanceSettings failed: {:?}, fallback to default", e); - AppearanceSettings::default() + AppearanceSettingsPB::default() } }; data_result(setting) diff --git a/frontend/rust-lib/flowy-user/src/services/database.rs b/frontend/rust-lib/flowy-user/src/services/database.rs index eaf5b7f6cb..64ebd705a7 100644 --- a/frontend/rust-lib/flowy-user/src/services/database.rs +++ b/frontend/rust-lib/flowy-user/src/services/database.rs @@ -1,4 +1,4 @@ -use crate::entities::{SignInResponse, SignUpResponse, UpdateUserProfileParams, UserProfile}; +use crate::entities::{SignInResponse, SignUpResponse, UpdateUserProfileParams, UserProfilePB}; use flowy_database::ConnectionPool; use flowy_database::{schema::user_table, DBConnection, Database}; use flowy_error::{ErrorCode, FlowyError}; @@ -113,9 +113,9 @@ impl std::convert::From for UserTable { } } -impl std::convert::From for UserProfile { +impl std::convert::From for UserProfilePB { fn from(table: UserTable) -> Self { - UserProfile { + UserProfilePB { id: table.id, email: table.email, name: table.name, diff --git a/frontend/rust-lib/flowy-user/src/services/notifier.rs b/frontend/rust-lib/flowy-user/src/services/notifier.rs index 9500988d99..4efdc301ac 100644 --- a/frontend/rust-lib/flowy-user/src/services/notifier.rs +++ b/frontend/rust-lib/flowy-user/src/services/notifier.rs @@ -1,4 +1,4 @@ -use crate::entities::UserProfile; +use crate::entities::UserProfilePB; use tokio::sync::{broadcast, mpsc}; #[derive(Clone)] @@ -14,7 +14,7 @@ pub enum UserStatus { token: String, }, SignUp { - profile: UserProfile, + profile: UserProfilePB, ret: mpsc::Sender<()>, }, } @@ -42,7 +42,7 @@ impl UserNotifier { }); } - pub(crate) fn notify_sign_up(&self, ret: mpsc::Sender<()>, user_profile: &UserProfile) { + pub(crate) fn notify_sign_up(&self, ret: mpsc::Sender<()>, user_profile: &UserProfilePB) { let _ = self.user_status_notifier.send(UserStatus::SignUp { profile: user_profile.clone(), ret, 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 48e6ef9661..3822a8a0db 100644 --- a/frontend/rust-lib/flowy-user/src/services/user_session.rs +++ b/frontend/rust-lib/flowy-user/src/services/user_session.rs @@ -1,5 +1,5 @@ use crate::entities::{ - SignInParams, SignInResponse, SignUpParams, SignUpResponse, UpdateUserProfileParams, UserProfile, + SignInParams, SignInResponse, SignUpParams, SignUpResponse, UpdateUserProfileParams, UserProfilePB, }; use crate::{ dart_notification::*, @@ -80,7 +80,7 @@ impl UserSession { } #[tracing::instrument(level = "debug", skip(self))] - pub async fn sign_in(&self, params: SignInParams) -> Result { + pub async fn sign_in(&self, params: SignInParams) -> Result { if self.is_user_login(¶ms.email) { self.get_user_profile().await } else { @@ -88,14 +88,14 @@ impl UserSession { let session: Session = resp.clone().into(); let _ = self.set_session(Some(session))?; let user_table = self.save_user(resp.into()).await?; - let user_profile: UserProfile = user_table.into(); + let user_profile: UserProfilePB = user_table.into(); self.notifier.notify_login(&user_profile.token, &user_profile.id); Ok(user_profile) } } #[tracing::instrument(level = "debug", skip(self))] - pub async fn sign_up(&self, params: SignUpParams) -> Result { + pub async fn sign_up(&self, params: SignUpParams) -> Result { if self.is_user_login(¶ms.email) { self.get_user_profile().await } else { @@ -103,7 +103,7 @@ impl UserSession { let session: Session = resp.clone().into(); let _ = self.set_session(Some(session))?; let user_table = self.save_user(resp.into()).await?; - let user_profile: UserProfile = user_table.into(); + let user_profile: UserProfilePB = user_table.into(); let (ret, mut tx) = mpsc::channel(1); self.notifier.notify_sign_up(ret, &user_profile); @@ -143,7 +143,7 @@ impl UserSession { Ok(()) } - pub async fn check_user(&self) -> Result { + pub async fn check_user(&self) -> Result { let (user_id, token) = self.get_session()?.into_part(); let user = dsl::user_table @@ -154,7 +154,7 @@ impl UserSession { Ok(user.into()) } - pub async fn get_user_profile(&self) -> Result { + pub async fn get_user_profile(&self) -> Result { let (user_id, token) = self.get_session()?.into_part(); let user = dsl::user_table .filter(user_table::id.eq(&user_id)) diff --git a/frontend/rust-lib/flowy-user/tests/event/auth_test.rs b/frontend/rust-lib/flowy-user/tests/event/auth_test.rs index 39b22a9af0..288b9d8b08 100644 --- a/frontend/rust-lib/flowy-user/tests/event/auth_test.rs +++ b/frontend/rust-lib/flowy-user/tests/event/auth_test.rs @@ -1,13 +1,13 @@ use crate::helper::*; use flowy_test::{event_builder::UserModuleEventBuilder, FlowySDKTest}; -use flowy_user::entities::{SignInPayload, SignUpPayload, UserProfile}; +use flowy_user::entities::{SignInPayloadPB, SignUpPayloadPB, UserProfilePB}; use flowy_user::{errors::ErrorCode, event_map::UserEvent::*}; #[tokio::test] async fn sign_up_with_invalid_email() { for email in invalid_email_test_case() { let sdk = FlowySDKTest::default(); - let request = SignUpPayload { + let request = SignUpPayloadPB { email: email.to_string(), name: valid_name(), password: login_password(), @@ -29,7 +29,7 @@ async fn sign_up_with_invalid_email() { async fn sign_up_with_invalid_password() { for password in invalid_password_test_case() { let sdk = FlowySDKTest::default(); - let request = SignUpPayload { + let request = SignUpPayloadPB { email: random_email(), name: valid_name(), password, @@ -50,7 +50,7 @@ async fn sign_in_success() { let _ = UserModuleEventBuilder::new(test.clone()).event(SignOut).sync_send(); let sign_up_context = test.sign_up().await; - let request = SignInPayload { + let request = SignInPayloadPB { email: sign_up_context.user_profile.email.clone(), password: sign_up_context.password.clone(), name: "".to_string(), @@ -61,7 +61,7 @@ async fn sign_in_success() { .payload(request) .async_send() .await - .parse::(); + .parse::(); dbg!(&response); } @@ -69,7 +69,7 @@ async fn sign_in_success() { async fn sign_in_with_invalid_email() { for email in invalid_email_test_case() { let sdk = FlowySDKTest::default(); - let request = SignInPayload { + let request = SignInPayloadPB { email: email.to_string(), password: login_password(), name: "".to_string(), @@ -93,7 +93,7 @@ async fn sign_in_with_invalid_password() { for password in invalid_password_test_case() { let sdk = FlowySDKTest::default(); - let request = SignInPayload { + let request = SignInPayloadPB { email: random_email(), password, name: "".to_string(), diff --git a/frontend/rust-lib/flowy-user/tests/event/user_profile_test.rs b/frontend/rust-lib/flowy-user/tests/event/user_profile_test.rs index b01a533336..fa77b69509 100644 --- a/frontend/rust-lib/flowy-user/tests/event/user_profile_test.rs +++ b/frontend/rust-lib/flowy-user/tests/event/user_profile_test.rs @@ -1,6 +1,6 @@ use crate::helper::*; use flowy_test::{event_builder::UserModuleEventBuilder, FlowySDKTest}; -use flowy_user::entities::{UpdateUserProfilePayload, UserProfile}; +use flowy_user::entities::{UpdateUserProfilePayloadPB, UserProfilePB}; use flowy_user::{errors::ErrorCode, event_map::UserEvent::*}; use nanoid::nanoid; @@ -24,7 +24,7 @@ async fn user_profile_get() { let user = UserModuleEventBuilder::new(test.clone()) .event(GetUserProfile) .sync_send() - .parse::(); + .parse::(); assert_eq!(user_profile, user); } @@ -33,7 +33,7 @@ async fn user_update_with_name() { let sdk = FlowySDKTest::default(); let user = sdk.init_user().await; let new_name = "hello_world".to_owned(); - let request = UpdateUserProfilePayload::new(&user.id).name(&new_name); + let request = UpdateUserProfilePayloadPB::new(&user.id).name(&new_name); let _ = UserModuleEventBuilder::new(sdk.clone()) .event(UpdateUserProfile) .payload(request) @@ -43,7 +43,7 @@ async fn user_update_with_name() { .event(GetUserProfile) .assert_error() .sync_send() - .parse::(); + .parse::(); assert_eq!(user_profile.name, new_name,); } @@ -53,7 +53,7 @@ async fn user_update_with_email() { let sdk = FlowySDKTest::default(); let user = sdk.init_user().await; let new_email = format!("{}@gmail.com", nanoid!(6)); - let request = UpdateUserProfilePayload::new(&user.id).email(&new_email); + let request = UpdateUserProfilePayloadPB::new(&user.id).email(&new_email); let _ = UserModuleEventBuilder::new(sdk.clone()) .event(UpdateUserProfile) .payload(request) @@ -62,7 +62,7 @@ async fn user_update_with_email() { .event(GetUserProfile) .assert_error() .sync_send() - .parse::(); + .parse::(); assert_eq!(user_profile.email, new_email,); } @@ -72,7 +72,7 @@ async fn user_update_with_password() { let sdk = FlowySDKTest::default(); let user = sdk.init_user().await; let new_password = "H123world!".to_owned(); - let request = UpdateUserProfilePayload::new(&user.id).password(&new_password); + let request = UpdateUserProfilePayloadPB::new(&user.id).password(&new_password); let _ = UserModuleEventBuilder::new(sdk.clone()) .event(UpdateUserProfile) @@ -86,7 +86,7 @@ async fn user_update_with_invalid_email() { let test = FlowySDKTest::default(); let user = test.init_user().await; for email in invalid_email_test_case() { - let request = UpdateUserProfilePayload::new(&user.id).email(&email); + let request = UpdateUserProfilePayloadPB::new(&user.id).email(&email); assert_eq!( UserModuleEventBuilder::new(test.clone()) .event(UpdateUserProfile) @@ -104,7 +104,7 @@ async fn user_update_with_invalid_password() { let test = FlowySDKTest::default(); let user = test.init_user().await; for password in invalid_password_test_case() { - let request = UpdateUserProfilePayload::new(&user.id).password(&password); + let request = UpdateUserProfilePayloadPB::new(&user.id).password(&password); UserModuleEventBuilder::new(test.clone()) .event(UpdateUserProfile) @@ -118,7 +118,7 @@ async fn user_update_with_invalid_password() { async fn user_update_with_invalid_name() { let test = FlowySDKTest::default(); let user = test.init_user().await; - let request = UpdateUserProfilePayload::new(&user.id).name(""); + let request = UpdateUserProfilePayloadPB::new(&user.id).name(""); UserModuleEventBuilder::new(test.clone()) .event(UpdateUserProfile) .payload(request) diff --git a/shared-lib/flowy-derive/src/proto_buf/deserialize.rs b/shared-lib/flowy-derive/src/proto_buf/deserialize.rs index f0325db3b0..4fbbb1b3a7 100644 --- a/shared-lib/flowy-derive/src/proto_buf/deserialize.rs +++ b/shared-lib/flowy-derive/src/proto_buf/deserialize.rs @@ -25,8 +25,15 @@ pub fn make_de_token_steam(ctxt: &Ctxt, ast: &ASTContainer) -> Option for #struct_ident { type Error = ::protobuf::ProtobufError; fn try_from(bytes: bytes::Bytes) -> Result { - let pb: crate::protobuf::#pb_ty = ::protobuf::Message::parse_from_bytes(&bytes)?; - #struct_ident::try_from(pb) + Self::try_from(&bytes) + } + } + + impl std::convert::TryFrom<&bytes::Bytes> for #struct_ident { + type Error = ::protobuf::ProtobufError; + fn try_from(bytes: &bytes::Bytes) -> Result { + let pb: crate::protobuf::#pb_ty = ::protobuf::Message::parse_from_bytes(bytes)?; + Ok(#struct_ident::from(pb)) } } @@ -34,16 +41,15 @@ pub fn make_de_token_steam(ctxt: &Ctxt, ast: &ASTContainer) -> Option Result { let pb: crate::protobuf::#pb_ty = ::protobuf::Message::parse_from_bytes(bytes)?; - #struct_ident::try_from(pb) + Ok(#struct_ident::from(pb)) } } - impl std::convert::TryFrom for #struct_ident { - type Error = ::protobuf::ProtobufError; - fn try_from(mut pb: crate::protobuf::#pb_ty) -> Result { + impl std::convert::From for #struct_ident { + fn from(mut pb: crate::protobuf::#pb_ty) -> Self { let mut o = Self::default(); #(#build_take_fields)* - Ok(o) + o } } }; @@ -70,7 +76,7 @@ fn token_stream_for_one_of(ctxt: &Ctxt, field: &ASTField) -> Option let ty = bracketed_ty_info.unwrap().ty; Some(quote! { if pb.#has_func() { - let enum_de_from_pb = #ty::try_from(&pb.#get_func()).unwrap(); + let enum_de_from_pb = #ty::from(&pb.#get_func()); o.#member = Some(enum_de_from_pb); } }) @@ -104,7 +110,7 @@ fn token_stream_for_one_of(ctxt: &Ctxt, field: &ASTField) -> Option let ty = bracketed_ty_info.unwrap().ty; Some(quote! { if pb.#has_func() { - let val = #ty::try_from(pb.#take_func()).unwrap(); + let val = #ty::from(pb.#take_func()); o.#member=Some(val); } }) @@ -138,7 +144,7 @@ fn token_stream_for_field(ctxt: &Ctxt, member: &syn::Member, ty: &syn::Type, is_ Some(quote! { let some_value = pb.#member.#take(); if some_value.is_some() { - let struct_de_from_pb = #ty::try_from(some_value.unwrap()).unwrap(); + let struct_de_from_pb = #ty::from(some_value.unwrap()); o.#member = struct_de_from_pb; } }) @@ -147,7 +153,7 @@ fn token_stream_for_field(ctxt: &Ctxt, member: &syn::Member, ty: &syn::Type, is_ TypeCategory::Enum => { let ty = ty_info.ty; Some(quote! { - let enum_de_from_pb = #ty::try_from(&pb.#member).unwrap(); + let enum_de_from_pb = #ty::from(&pb.#member); o.#member = enum_de_from_pb; }) @@ -192,7 +198,7 @@ fn token_stream_for_vec(ctxt: &Ctxt, member: &syn::Member, bracketed_type: &TyIn Some(quote! { o.#member = pb.#take_ident() .into_iter() - .map(|m| #ty::try_from(m).unwrap()) + .map(|m| #ty::from(m)) .collect(); }) } @@ -221,7 +227,7 @@ fn token_stream_for_map(ctxt: &Ctxt, member: &syn::Member, ty_info: &TyInfo) -> TypeCategory::Protobuf => Some(quote! { let mut m: std::collections::HashMap = std::collections::HashMap::new(); pb.#take_ident().into_iter().for_each(|(k,v)| { - m.insert(k.clone(), #ty::try_from(v).unwrap()); + m.insert(k.clone(), #ty::from(v)); }); o.#member = m; }), diff --git a/shared-lib/flowy-derive/src/proto_buf/enum_serde.rs b/shared-lib/flowy-derive/src/proto_buf/enum_serde.rs index 498be05e51..fb0870fde8 100644 --- a/shared-lib/flowy-derive/src/proto_buf/enum_serde.rs +++ b/shared-lib/flowy-derive/src/proto_buf/enum_serde.rs @@ -20,21 +20,19 @@ pub fn make_enum_token_stream(_ctxt: &Ctxt, cont: &ASTContainer) -> Option for #enum_ident { - type Error = String; - fn try_from(pb:&crate::protobuf::#pb_enum) -> Result { - Ok(match pb { + impl std::convert::From<&crate::protobuf::#pb_enum> for #enum_ident { + fn from(pb:&crate::protobuf::#pb_enum) -> Self { + match pb { #(#build_from_pb_enum)* - }) + } } } - impl std::convert::TryInto for #enum_ident { - type Error = String; - fn try_into(self) -> Result { - Ok(match self { + impl std::convert::From<#enum_ident> for crate::protobuf::#pb_enum{ + fn from(o: #enum_ident) -> crate::protobuf::#pb_enum { + match o { #(#build_to_pb_enum)* - }) + } } } }) diff --git a/shared-lib/flowy-derive/src/proto_buf/serialize.rs b/shared-lib/flowy-derive/src/proto_buf/serialize.rs index 324c26651b..a43f337f8f 100644 --- a/shared-lib/flowy-derive/src/proto_buf/serialize.rs +++ b/shared-lib/flowy-derive/src/proto_buf/serialize.rs @@ -19,18 +19,17 @@ pub fn make_se_token_stream(ctxt: &Ctxt, ast: &ASTContainer) -> Option Result { use protobuf::Message; - let pb: crate::protobuf::#pb_ty = self.try_into()?; + let pb: crate::protobuf::#pb_ty = self.into(); let bytes = pb.write_to_bytes()?; Ok(bytes::Bytes::from(bytes)) } } - impl std::convert::TryInto for #struct_ident { - type Error = ::protobuf::ProtobufError; - fn try_into(self) -> Result { + impl std::convert::From<#struct_ident> for crate::protobuf::#pb_ty { + fn from(mut o: #struct_ident) -> crate::protobuf::#pb_ty { let mut pb = crate::protobuf::#pb_ty::new(); #(#build_set_pb_fields)* - Ok(pb) + pb } } }; @@ -41,7 +40,7 @@ pub fn make_se_token_stream(ctxt: &Ctxt, ast: &ASTContainer) -> Option Option { if let Some(func) = &field.attrs.serialize_with() { let member = &field.member; - Some(quote! { pb.#member=self.#func(); }) + Some(quote! { pb.#member=o.#func(); }) } else if field.attrs.is_one_of() { token_stream_for_one_of(ctxt, field) } else { @@ -66,19 +65,19 @@ fn token_stream_for_one_of(ctxt: &Ctxt, field: &ASTField) -> Option match ident_category(bracketed_ty_info.unwrap().ident) { TypeCategory::Protobuf => Some(quote! { - match self.#member { - Some(s) => { pb.#set_func(s.try_into().unwrap()) } + match o.#member { + Some(s) => { pb.#set_func(s.into()) } None => {} } }), TypeCategory::Enum => Some(quote! { - match self.#member { - Some(s) => { pb.#set_func(s.try_into().unwrap()) } + match o.#member { + Some(s) => { pb.#set_func(s.into()) } None => {} } }), _ => Some(quote! { - match self.#member { + match o.#member { Some(ref s) => { pb.#set_func(s.clone()) } None => {} } @@ -100,18 +99,16 @@ fn gen_token_stream(ctxt: &Ctxt, member: &syn::Member, ty: &syn::Type, is_option TypeCategory::Str => { if is_option { Some(quote! { - match self.#member { + match o.#member { Some(ref s) => { pb.#member = s.to_string().clone(); } None => { pb.#member = String::new(); } } }) } else { - Some(quote! { pb.#member = self.#member.clone(); }) + Some(quote! { pb.#member = o.#member.clone(); }) } } - TypeCategory::Protobuf => { - Some(quote! { pb.#member = ::protobuf::SingularPtrField::some(self.#member.try_into().unwrap()); }) - } + TypeCategory::Protobuf => Some(quote! { pb.#member = ::protobuf::SingularPtrField::some(o.#member.into()); }), TypeCategory::Opt => gen_token_stream(ctxt, member, ty_info.bracket_ty_info.unwrap().ty, true), TypeCategory::Enum => { // let pb_enum_ident = format_ident!("{}", ty_info.ident.to_string()); @@ -119,10 +116,10 @@ fn gen_token_stream(ctxt: &Ctxt, member: &syn::Member, ty: &syn::Type, is_option // flowy_protobuf::#pb_enum_ident::from_i32(self.#member.value()).unwrap(); // }) Some(quote! { - pb.#member = self.#member.try_into().unwrap(); + pb.#member = o.#member.into(); }) } - _ => Some(quote! { pb.#member = self.#member; }), + _ => Some(quote! { pb.#member = o.#member; }), } } @@ -139,15 +136,15 @@ fn token_stream_for_vec(ctxt: &Ctxt, member: &syn::Member, ty: &syn::Type) -> Op match ident_category(ty_info.ident) { TypeCategory::Protobuf => Some(quote! { pb.#member = ::protobuf::RepeatedField::from_vec( - self.#member + o.#member .into_iter() - .map(|m| m.try_into().unwrap()) + .map(|m| m.into()) .collect()); }), - TypeCategory::Bytes => Some(quote! { pb.#member = self.#member.clone(); }), + TypeCategory::Bytes => Some(quote! { pb.#member = o.#member.clone(); }), _ => Some(quote! { - pb.#member = ::protobuf::RepeatedField::from_vec(self.#member.clone()); + pb.#member = ::protobuf::RepeatedField::from_vec(o.#member.clone()); }), } } @@ -166,14 +163,14 @@ fn token_stream_for_map(ctxt: &Ctxt, member: &syn::Member, ty: &syn::Type) -> Op match ident_category(ty_info.ident) { TypeCategory::Protobuf => Some(quote! { let mut m: std::collections::HashMap = std::collections::HashMap::new(); - self.#member.into_iter().for_each(|(k,v)| { - m.insert(k.clone(), v.try_into().unwrap()); + o.#member.into_iter().for_each(|(k,v)| { + m.insert(k.clone(), v.into()); }); pb.#member = m; }), _ => Some(quote! { let mut m: std::collections::HashMap = std::collections::HashMap::new(); - self.#member.iter().for_each(|(k,v)| { + o.#member.iter().for_each(|(k,v)| { m.insert(k.clone(), v.clone()); }); pb.#member = m; diff --git a/shared-lib/flowy-sync/src/entities/revision.rs b/shared-lib/flowy-sync/src/entities/revision.rs index 57276bba1b..d909efa3d5 100644 --- a/shared-lib/flowy-sync/src/entities/revision.rs +++ b/shared-lib/flowy-sync/src/entities/revision.rs @@ -125,6 +125,12 @@ impl std::convert::From for RepeatedRevision { } } +impl std::convert::From> for RepeatedRevision { + fn from(revisions: Vec) -> Self { + Self { items: revisions } + } +} + impl RepeatedRevision { pub fn new(mut items: Vec) -> Self { items.sort_by(|a, b| a.rev_id.cmp(&b.rev_id)); diff --git a/shared-lib/flowy-sync/src/entities/text_block.rs b/shared-lib/flowy-sync/src/entities/text_block.rs index cef3cd30f7..8753103369 100644 --- a/shared-lib/flowy-sync/src/entities/text_block.rs +++ b/shared-lib/flowy-sync/src/entities/text_block.rs @@ -15,7 +15,7 @@ pub struct CreateTextBlockParams { } #[derive(ProtoBuf, Default, Debug, Clone, Eq, PartialEq)] -pub struct TextBlockInfoPB { +pub struct DocumentPB { #[pb(index = 1)] pub block_id: String, @@ -29,14 +29,14 @@ pub struct TextBlockInfoPB { pub base_rev_id: i64, } -impl TextBlockInfoPB { +impl DocumentPB { pub fn delta(&self) -> Result { let delta = RichTextDelta::from_bytes(&self.text)?; Ok(delta) } } -impl std::convert::TryFrom for TextBlockInfoPB { +impl std::convert::TryFrom for DocumentPB { type Error = CollaborateError; fn try_from(revision: Revision) -> Result { @@ -48,7 +48,7 @@ impl std::convert::TryFrom for TextBlockInfoPB { let delta = RichTextDelta::from_bytes(&revision.delta_data)?; let doc_json = delta.to_delta_str(); - Ok(TextBlockInfoPB { + Ok(DocumentPB { block_id: revision.object_id, text: doc_json, rev_id: revision.rev_id, diff --git a/shared-lib/flowy-sync/src/server_document/document_manager.rs b/shared-lib/flowy-sync/src/server_document/document_manager.rs index 8aed39e993..59d3dd3c97 100644 --- a/shared-lib/flowy-sync/src/server_document/document_manager.rs +++ b/shared-lib/flowy-sync/src/server_document/document_manager.rs @@ -1,7 +1,8 @@ +use crate::entities::revision::{RepeatedRevision, Revision}; use crate::{ - entities::{text_block::TextBlockInfoPB, ws_data::ServerRevisionWSDataBuilder}, + entities::{text_block::DocumentPB, ws_data::ServerRevisionWSDataBuilder}, errors::{internal_error, CollaborateError, CollaborateResult}, - protobuf::{ClientRevisionWSData, RepeatedRevision as RepeatedRevisionPB, Revision as RevisionPB}, + protobuf::ClientRevisionWSData, server_document::document_pad::ServerDocument, synchronizer::{RevisionSyncPersistence, RevisionSyncResponse, RevisionSynchronizer, RevisionUser}, util::rev_id_from_str, @@ -18,27 +19,26 @@ use tokio::{ }; pub trait TextBlockCloudPersistence: Send + Sync + Debug { - fn read_text_block(&self, doc_id: &str) -> BoxResultFuture; + fn read_text_block(&self, doc_id: &str) -> BoxResultFuture; fn create_text_block( &self, doc_id: &str, - repeated_revision: RepeatedRevisionPB, - ) -> BoxResultFuture, CollaborateError>; + repeated_revision: RepeatedRevision, + ) -> BoxResultFuture, CollaborateError>; fn read_text_block_revisions( &self, doc_id: &str, rev_ids: Option>, - ) -> BoxResultFuture, CollaborateError>; + ) -> BoxResultFuture, CollaborateError>; - fn save_text_block_revisions(&self, repeated_revision: RepeatedRevisionPB) - -> BoxResultFuture<(), CollaborateError>; + fn save_text_block_revisions(&self, repeated_revision: RepeatedRevision) -> BoxResultFuture<(), CollaborateError>; fn reset_text_block( &self, doc_id: &str, - repeated_revision: RepeatedRevisionPB, + repeated_revision: RepeatedRevision, ) -> BoxResultFuture<(), CollaborateError>; } @@ -47,18 +47,18 @@ impl RevisionSyncPersistence for Arc { &self, object_id: &str, rev_ids: Option>, - ) -> BoxResultFuture, CollaborateError> { + ) -> BoxResultFuture, CollaborateError> { (**self).read_text_block_revisions(object_id, rev_ids) } - fn save_revisions(&self, repeated_revision: RepeatedRevisionPB) -> BoxResultFuture<(), CollaborateError> { + fn save_revisions(&self, repeated_revision: RepeatedRevision) -> BoxResultFuture<(), CollaborateError> { (**self).save_text_block_revisions(repeated_revision) } fn reset_object( &self, object_id: &str, - repeated_revision: RepeatedRevisionPB, + repeated_revision: RepeatedRevision, ) -> BoxResultFuture<(), CollaborateError> { (**self).reset_text_block(object_id, repeated_revision) } @@ -82,7 +82,7 @@ impl ServerDocumentManager { user: Arc, mut client_data: ClientRevisionWSData, ) -> Result<(), CollaborateError> { - let repeated_revision = client_data.take_revisions(); + let repeated_revision: RepeatedRevision = client_data.take_revisions().into(); let cloned_user = user.clone(); let ack_id = rev_id_from_str(&client_data.data_id)?; let object_id = client_data.object_id; @@ -131,9 +131,10 @@ impl ServerDocumentManager { pub async fn handle_document_reset( &self, doc_id: &str, - mut repeated_revision: RepeatedRevisionPB, + mut repeated_revision: RepeatedRevision, ) -> Result<(), CollaborateError> { - repeated_revision.mut_items().sort_by(|a, b| a.rev_id.cmp(&b.rev_id)); + repeated_revision.sort_by(|a, b| a.rev_id.cmp(&b.rev_id)); + match self.get_document_handler(doc_id).await { None => { tracing::warn!("Document:{} doesn't exist, ignore document reset", doc_id); @@ -166,7 +167,7 @@ impl ServerDocumentManager { async fn create_document( &self, doc_id: &str, - repeated_revision: RepeatedRevisionPB, + repeated_revision: RepeatedRevision, ) -> Result, CollaborateError> { match self.persistence.create_text_block(doc_id, repeated_revision).await? { None => Err(CollaborateError::internal().context("Create document info from revisions failed")), @@ -182,10 +183,7 @@ impl ServerDocumentManager { } #[tracing::instrument(level = "debug", skip(self, doc), err)] - async fn create_document_handler( - &self, - doc: TextBlockInfoPB, - ) -> Result, CollaborateError> { + async fn create_document_handler(&self, doc: DocumentPB) -> Result, CollaborateError> { let persistence = self.persistence.clone(); let handle = spawn_blocking(|| OpenDocumentHandler::new(doc, persistence)) .await @@ -209,7 +207,7 @@ struct OpenDocumentHandler { } impl OpenDocumentHandler { - fn new(doc: TextBlockInfoPB, persistence: Arc) -> Result { + fn new(doc: DocumentPB, persistence: Arc) -> Result { let doc_id = doc.block_id.clone(); let (sender, receiver) = mpsc::channel(1000); let users = DashMap::new(); @@ -232,7 +230,7 @@ impl OpenDocumentHandler { async fn apply_revisions( &self, user: Arc, - repeated_revision: RepeatedRevisionPB, + repeated_revision: RepeatedRevision, ) -> Result<(), CollaborateError> { let (ret, rx) = oneshot::channel(); self.users.insert(user.user_id(), user.clone()); @@ -255,7 +253,7 @@ impl OpenDocumentHandler { } #[tracing::instrument(level = "debug", skip(self, repeated_revision), err)] - async fn apply_document_reset(&self, repeated_revision: RepeatedRevisionPB) -> Result<(), CollaborateError> { + async fn apply_document_reset(&self, repeated_revision: RepeatedRevision) -> Result<(), CollaborateError> { let (ret, rx) = oneshot::channel(); let msg = DocumentCommand::Reset { repeated_revision, ret }; let result = self.send(msg, rx).await?; @@ -282,7 +280,7 @@ impl std::ops::Drop for OpenDocumentHandler { enum DocumentCommand { ApplyRevisions { user: Arc, - repeated_revision: RepeatedRevisionPB, + repeated_revision: RepeatedRevision, ret: oneshot::Sender>, }, Ping { @@ -291,7 +289,7 @@ enum DocumentCommand { ret: oneshot::Sender>, }, Reset { - repeated_revision: RepeatedRevisionPB, + repeated_revision: RepeatedRevision, ret: oneshot::Sender>, }, } diff --git a/shared-lib/flowy-sync/src/server_folder/folder_manager.rs b/shared-lib/flowy-sync/src/server_folder/folder_manager.rs index 0a1a5e117a..16b753f50b 100644 --- a/shared-lib/flowy-sync/src/server_folder/folder_manager.rs +++ b/shared-lib/flowy-sync/src/server_folder/folder_manager.rs @@ -1,10 +1,11 @@ +use crate::entities::revision::{RepeatedRevision, Revision}; use crate::{ entities::{ folder::{FolderDelta, FolderInfo}, ws_data::ServerRevisionWSDataBuilder, }, errors::{internal_error, CollaborateError, CollaborateResult}, - protobuf::{ClientRevisionWSData, RepeatedRevision as RepeatedRevisionPB, Revision as RevisionPB}, + protobuf::ClientRevisionWSData, server_folder::folder_pad::ServerFolder, synchronizer::{RevisionSyncPersistence, RevisionSyncResponse, RevisionSynchronizer, RevisionUser}, util::rev_id_from_str, @@ -26,21 +27,21 @@ pub trait FolderCloudPersistence: Send + Sync + Debug { &self, user_id: &str, folder_id: &str, - repeated_revision: RepeatedRevisionPB, + repeated_revision: RepeatedRevision, ) -> BoxResultFuture, CollaborateError>; - fn save_folder_revisions(&self, repeated_revision: RepeatedRevisionPB) -> BoxResultFuture<(), CollaborateError>; + fn save_folder_revisions(&self, repeated_revision: RepeatedRevision) -> BoxResultFuture<(), CollaborateError>; fn read_folder_revisions( &self, folder_id: &str, rev_ids: Option>, - ) -> BoxResultFuture, CollaborateError>; + ) -> BoxResultFuture, CollaborateError>; fn reset_folder( &self, folder_id: &str, - repeated_revision: RepeatedRevisionPB, + repeated_revision: RepeatedRevision, ) -> BoxResultFuture<(), CollaborateError>; } @@ -49,18 +50,18 @@ impl RevisionSyncPersistence for Arc { &self, object_id: &str, rev_ids: Option>, - ) -> BoxResultFuture, CollaborateError> { + ) -> BoxResultFuture, CollaborateError> { (**self).read_folder_revisions(object_id, rev_ids) } - fn save_revisions(&self, repeated_revision: RepeatedRevisionPB) -> BoxResultFuture<(), CollaborateError> { + fn save_revisions(&self, repeated_revision: RepeatedRevision) -> BoxResultFuture<(), CollaborateError> { (**self).save_folder_revisions(repeated_revision) } fn reset_object( &self, object_id: &str, - repeated_revision: RepeatedRevisionPB, + repeated_revision: RepeatedRevision, ) -> BoxResultFuture<(), CollaborateError> { (**self).reset_folder(object_id, repeated_revision) } @@ -84,7 +85,7 @@ impl ServerFolderManager { user: Arc, mut client_data: ClientRevisionWSData, ) -> Result<(), CollaborateError> { - let repeated_revision = client_data.take_revisions(); + let repeated_revision: RepeatedRevision = client_data.take_revisions().into(); let cloned_user = user.clone(); let ack_id = rev_id_from_str(&client_data.data_id)?; let folder_id = client_data.object_id; @@ -167,7 +168,7 @@ impl ServerFolderManager { &self, user_id: &str, folder_id: &str, - repeated_revision: RepeatedRevisionPB, + repeated_revision: RepeatedRevision, ) -> Result, CollaborateError> { match self .persistence @@ -221,7 +222,7 @@ impl OpenFolderHandler { async fn apply_revisions( &self, user: Arc, - repeated_revision: RepeatedRevisionPB, + repeated_revision: RepeatedRevision, ) -> CollaborateResult<()> { let (ret, rx) = oneshot::channel(); let msg = FolderCommand::ApplyRevisions { @@ -258,7 +259,7 @@ impl std::ops::Drop for OpenFolderHandler { enum FolderCommand { ApplyRevisions { user: Arc, - repeated_revision: RepeatedRevisionPB, + repeated_revision: RepeatedRevision, ret: oneshot::Sender>, }, Ping { diff --git a/shared-lib/flowy-sync/src/synchronizer.rs b/shared-lib/flowy-sync/src/synchronizer.rs index 1305c471b2..eca422296a 100644 --- a/shared-lib/flowy-sync/src/synchronizer.rs +++ b/shared-lib/flowy-sync/src/synchronizer.rs @@ -1,10 +1,11 @@ +use crate::entities::revision::{RepeatedRevision, Revision}; use crate::{ entities::{ revision::RevisionRange, ws_data::{ServerRevisionWSData, ServerRevisionWSDataBuilder}, }, errors::CollaborateError, - protobuf::{RepeatedRevision as RepeatedRevisionPB, Revision as RevisionPB}, + protobuf::Revision as RevisionPB, util::*, }; use lib_infra::future::BoxResultFuture; @@ -31,14 +32,14 @@ pub trait RevisionSyncPersistence: Send + Sync + 'static { &self, object_id: &str, rev_ids: Option>, - ) -> BoxResultFuture, CollaborateError>; + ) -> BoxResultFuture, CollaborateError>; - fn save_revisions(&self, repeated_revision: RepeatedRevisionPB) -> BoxResultFuture<(), CollaborateError>; + fn save_revisions(&self, repeated_revision: RepeatedRevision) -> BoxResultFuture<(), CollaborateError>; fn reset_object( &self, object_id: &str, - repeated_revision: RepeatedRevisionPB, + repeated_revision: RepeatedRevision, ) -> BoxResultFuture<(), CollaborateError>; } @@ -87,20 +88,20 @@ where pub async fn sync_revisions( &self, user: Arc, - repeated_revision: RepeatedRevisionPB, + repeated_revision: RepeatedRevision, ) -> Result<(), CollaborateError> { let object_id = self.object_id.clone(); - if repeated_revision.get_items().is_empty() { + if repeated_revision.is_empty() { // Return all the revisions to client let revisions = self.persistence.read_revisions(&object_id, None).await?; - let repeated_revision = repeated_revision_from_revision_pbs(revisions)?; + let repeated_revision = RepeatedRevision::from(revisions); let data = ServerRevisionWSDataBuilder::build_push_message(&object_id, repeated_revision); user.receive(RevisionSyncResponse::Push(data)); return Ok(()); } let server_base_rev_id = self.rev_id.load(SeqCst); - let first_revision = repeated_revision.get_items().first().unwrap().clone(); + let first_revision = repeated_revision.first().unwrap().clone(); if self.is_applied_before(&first_revision, &self.persistence).await { // Server has received this revision before, so ignore the following revisions return Ok(()); @@ -111,7 +112,7 @@ where let server_rev_id = next(server_base_rev_id); if server_base_rev_id == first_revision.base_rev_id || server_rev_id == first_revision.rev_id { // The rev is in the right order, just compose it. - for revision in repeated_revision.get_items() { + for revision in repeated_revision.iter() { let _ = self.compose_revision(revision)?; } let _ = self.persistence.save_revisions(repeated_revision).await?; @@ -165,10 +166,10 @@ where } #[tracing::instrument(level = "debug", skip(self, repeated_revision), fields(object_id), err)] - pub async fn reset(&self, repeated_revision: RepeatedRevisionPB) -> Result<(), CollaborateError> { + pub async fn reset(&self, repeated_revision: RepeatedRevision) -> Result<(), CollaborateError> { let object_id = self.object_id.clone(); tracing::Span::current().record("object_id", &object_id.as_str()); - let revisions: Vec = repeated_revision.get_items().to_vec(); + let revisions: Vec = repeated_revision.clone().into_inner(); let (_, rev_id) = pair_rev_id_from_revision_pbs(&revisions); let delta = make_delta_from_revision_pb(revisions)?; let _ = self.persistence.reset_object(&object_id, repeated_revision).await?; @@ -181,7 +182,7 @@ where self.object.read().to_json() } - fn compose_revision(&self, revision: &RevisionPB) -> Result<(), CollaborateError> { + fn compose_revision(&self, revision: &Revision) -> Result<(), CollaborateError> { let delta = Delta::::from_bytes(&revision.delta_data)?; let _ = self.compose_delta(delta)?; let _ = self.rev_id.fetch_update(SeqCst, SeqCst, |_e| Some(revision.rev_id)); @@ -213,11 +214,7 @@ where self.rev_id.load(SeqCst) } - async fn is_applied_before( - &self, - new_revision: &RevisionPB, - persistence: &Arc, - ) -> bool { + async fn is_applied_before(&self, new_revision: &Revision, persistence: &Arc) -> bool { let rev_ids = Some(vec![new_revision.rev_id]); if let Ok(revisions) = persistence.read_revisions(&self.object_id, rev_ids).await { if let Some(revision) = revisions.first() { @@ -243,13 +240,10 @@ where tracing::trace!("{}: can not read the revisions in range {:?}", self.object_id, rev_ids); // assert_eq!(revisions.is_empty(), rev_ids.is_empty(),); } - match repeated_revision_from_revision_pbs(revisions) { - Ok(repeated_revision) => { - let data = ServerRevisionWSDataBuilder::build_push_message(&self.object_id, repeated_revision); - user.receive(RevisionSyncResponse::Push(data)); - } - Err(e) => tracing::error!("{}", e), - } + + let repeated_revision = RepeatedRevision::from(revisions); + let data = ServerRevisionWSDataBuilder::build_push_message(&self.object_id, repeated_revision); + user.receive(RevisionSyncResponse::Push(data)); } Err(e) => { tracing::error!("{}", e); diff --git a/shared-lib/flowy-sync/src/util.rs b/shared-lib/flowy-sync/src/util.rs index 824f1f945b..c4504a806a 100644 --- a/shared-lib/flowy-sync/src/util.rs +++ b/shared-lib/flowy-sync/src/util.rs @@ -2,10 +2,9 @@ use crate::{ entities::{ folder::{FolderDelta, FolderInfo}, revision::{RepeatedRevision, Revision}, - text_block::TextBlockInfoPB, + text_block::DocumentPB, }, errors::{CollaborateError, CollaborateResult}, - protobuf::{FolderInfo as FolderInfoPB, RepeatedRevision as RepeatedRevisionPB, Revision as RevisionPB}, }; use dissimilar::Chunk; use lib_ot::core::{DeltaBuilder, FlowyStr}; @@ -14,10 +13,7 @@ use lib_ot::{ rich_text::RichTextDelta, }; use serde::de::DeserializeOwned; -use std::{ - convert::TryInto, - sync::atomic::{AtomicI64, Ordering::SeqCst}, -}; +use std::sync::atomic::{AtomicI64, Ordering::SeqCst}; #[inline] pub fn find_newline(s: &str) -> Option { @@ -85,7 +81,7 @@ where Ok(delta) } -pub fn make_delta_from_revision_pb(revisions: Vec) -> CollaborateResult> +pub fn make_delta_from_revision_pb(revisions: Vec) -> CollaborateResult> where T: Attributes + DeserializeOwned, { @@ -100,26 +96,7 @@ where Ok(new_delta) } -pub fn repeated_revision_from_revision_pbs(revisions: Vec) -> CollaborateResult { - let repeated_revision_pb = repeated_revision_pb_from_revisions(revisions); - repeated_revision_from_repeated_revision_pb(repeated_revision_pb) -} - -pub fn repeated_revision_pb_from_revisions(revisions: Vec) -> RepeatedRevisionPB { - let mut repeated_revision_pb = RepeatedRevisionPB::new(); - repeated_revision_pb.set_items(revisions.into()); - repeated_revision_pb -} - -pub fn repeated_revision_from_repeated_revision_pb( - repeated_revision: RepeatedRevisionPB, -) -> CollaborateResult { - repeated_revision - .try_into() - .map_err(|e| CollaborateError::internal().context(format!("Cast repeated revision failed: {:?}", e))) -} - -pub fn pair_rev_id_from_revision_pbs(revisions: &[RevisionPB]) -> (i64, i64) { +pub fn pair_rev_id_from_revision_pbs(revisions: &[Revision]) -> (i64, i64) { let mut rev_id = 0; revisions.iter().for_each(|revision| { if rev_id < revision.rev_id { @@ -152,23 +129,9 @@ pub fn pair_rev_id_from_revisions(revisions: &[Revision]) -> (i64, i64) { #[inline] pub fn make_folder_from_revisions_pb( folder_id: &str, - revisions: RepeatedRevisionPB, + revisions: RepeatedRevision, ) -> Result, CollaborateError> { - match make_folder_pb_from_revisions_pb(folder_id, revisions)? { - None => Ok(None), - Some(pb) => { - let folder_info: FolderInfo = pb.try_into().map_err(|e| CollaborateError::internal().context(e))?; - Ok(Some(folder_info)) - } - } -} - -#[inline] -pub fn make_folder_pb_from_revisions_pb( - folder_id: &str, - mut revisions: RepeatedRevisionPB, -) -> Result, CollaborateError> { - let revisions = revisions.take_items(); + let revisions = revisions.into_inner(); if revisions.is_empty() { return Ok(None); } @@ -187,41 +150,25 @@ pub fn make_folder_pb_from_revisions_pb( } let text = folder_delta.to_delta_str(); - let mut folder_info = FolderInfoPB::new(); - folder_info.set_folder_id(folder_id.to_owned()); - folder_info.set_text(text); - folder_info.set_base_rev_id(base_rev_id); - folder_info.set_rev_id(rev_id); - Ok(Some(folder_info)) + Ok(Some(FolderInfo { + folder_id: folder_id.to_string(), + text, + rev_id, + base_rev_id, + })) } #[inline] -pub fn make_document_info_from_revisions_pb( +pub fn make_document_from_revision_pbs( doc_id: &str, - revisions: RepeatedRevisionPB, -) -> Result, CollaborateError> { - match make_document_info_pb_from_revisions_pb(doc_id, revisions)? { - None => Ok(None), - Some(pb) => { - let document_info: TextBlockInfoPB = pb.try_into().map_err(|e| { - CollaborateError::internal().context(format!("Deserialize document info from pb failed: {}", e)) - })?; - Ok(Some(document_info)) - } - } -} - -#[inline] -pub fn make_document_info_pb_from_revisions_pb( - doc_id: &str, - mut revisions: RepeatedRevisionPB, -) -> Result, CollaborateError> { - let revisions = revisions.take_items(); + revisions: RepeatedRevision, +) -> Result, CollaborateError> { + let revisions = revisions.into_inner(); if revisions.is_empty() { return Ok(None); } - let mut document_delta = RichTextDelta::new(); + let mut delta = RichTextDelta::new(); let mut base_rev_id = 0; let mut rev_id = 0; for revision in revisions { @@ -232,17 +179,18 @@ pub fn make_document_info_pb_from_revisions_pb( tracing::warn!("revision delta_data is empty"); } - let delta = RichTextDelta::from_bytes(revision.delta_data)?; - document_delta = document_delta.compose(&delta)?; + let new_delta = RichTextDelta::from_bytes(revision.delta_data)?; + delta = delta.compose(&new_delta)?; } - let text = document_delta.to_delta_str(); - let mut block_info = crate::protobuf::TextBlockInfoPB::new(); - block_info.set_block_id(doc_id.to_owned()); - block_info.set_text(text); - block_info.set_base_rev_id(base_rev_id); - block_info.set_rev_id(rev_id); - Ok(Some(block_info)) + let text = delta.to_delta_str(); + + Ok(Some(DocumentPB { + block_id: doc_id.to_owned(), + text, + rev_id, + base_rev_id, + })) } #[inline]