diff --git a/frontend/.vscode/launch.json b/frontend/.vscode/launch.json index 315e208317..036b5ab35c 100644 --- a/frontend/.vscode/launch.json +++ b/frontend/.vscode/launch.json @@ -62,8 +62,10 @@ { "name": "AF: app_flowy (profile mode)", "request": "launch", + "program": "./lib/main.dart", "type": "dart", - "flutterMode": "profile" + "flutterMode": "profile", + "cwd": "${workspaceRoot}/app_flowy" }, ] } \ No newline at end of file diff --git a/frontend/Makefile.toml b/frontend/Makefile.toml index 42708d7c32..8418c30141 100644 --- a/frontend/Makefile.toml +++ b/frontend/Makefile.toml @@ -52,6 +52,7 @@ RUST_COMPILE_TARGET = "aarch64-apple-darwin" BUILD_FLAG = "debug" FLUTTER_OUTPUT_DIR = "Debug" PRODUCT_EXT = "app" +BUILD_ARCHS = "arm64" [env.development-mac-x86_64] RUST_LOG = "info" @@ -60,6 +61,7 @@ RUST_COMPILE_TARGET = "x86_64-apple-darwin" BUILD_FLAG = "debug" FLUTTER_OUTPUT_DIR = "Debug" PRODUCT_EXT = "app" +BUILD_ARCHS = "x86_64" [env.production-mac-arm64] BUILD_FLAG = "release" diff --git a/frontend/app_flowy/lib/core/folder_notification.dart b/frontend/app_flowy/lib/core/folder_notification.dart new file mode 100644 index 0000000000..1f9d7751ce --- /dev/null +++ b/frontend/app_flowy/lib/core/folder_notification.dart @@ -0,0 +1,39 @@ +import 'dart:async'; +import 'dart:typed_data'; +import 'package:flowy_sdk/protobuf/dart-notify/protobuf.dart'; +import 'package:dartz/dartz.dart'; +import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-folder/dart_notification.pb.dart'; +import 'package:flowy_sdk/rust_stream.dart'; + +import 'notification_helper.dart'; + +// Folder +typedef FolderNotificationCallback = void Function(FolderNotification, Either); + +class FolderNotificationParser extends NotificationParser { + FolderNotificationParser({String? id, required FolderNotificationCallback callback}) + : super( + id: id, + callback: callback, + tyParser: (ty) => FolderNotification.valueOf(ty), + errorParser: (bytes) => FlowyError.fromBuffer(bytes), + ); +} + +typedef FolderNotificationHandler = Function(FolderNotification ty, Either result); + +class FolderNotificationListener { + StreamSubscription? _subscription; + FolderNotificationParser? _parser; + + FolderNotificationListener({required String objectId, required FolderNotificationHandler handler}) + : _parser = FolderNotificationParser(id: objectId, callback: handler) { + _subscription = RustStreamReceiver.listen((observable) => _parser?.parse(observable)); + } + + Future stop() async { + _parser = null; + await _subscription?.cancel(); + } +} diff --git a/frontend/app_flowy/lib/core/grid_notification.dart b/frontend/app_flowy/lib/core/grid_notification.dart new file mode 100644 index 0000000000..e45bf5efe2 --- /dev/null +++ b/frontend/app_flowy/lib/core/grid_notification.dart @@ -0,0 +1,39 @@ +import 'dart:async'; +import 'dart:typed_data'; +import 'package:flowy_sdk/protobuf/dart-notify/protobuf.dart'; +import 'package:dartz/dartz.dart'; +import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-grid/dart_notification.pb.dart'; +import 'package:flowy_sdk/rust_stream.dart'; + +import 'notification_helper.dart'; + +// Grid +typedef GridNotificationCallback = void Function(GridNotification, Either); + +class GridNotificationParser extends NotificationParser { + GridNotificationParser({String? id, required GridNotificationCallback callback}) + : super( + id: id, + callback: callback, + tyParser: (ty) => GridNotification.valueOf(ty), + errorParser: (bytes) => FlowyError.fromBuffer(bytes), + ); +} + +typedef GridNotificationHandler = Function(GridNotification ty, Either result); + +class GridNotificationListener { + StreamSubscription? _subscription; + GridNotificationParser? _parser; + + GridNotificationListener({required String objectId, required GridNotificationHandler handler}) + : _parser = GridNotificationParser(id: objectId, callback: handler) { + _subscription = RustStreamReceiver.listen((observable) => _parser?.parse(observable)); + } + + Future stop() async { + _parser = null; + await _subscription?.cancel(); + } +} diff --git a/frontend/app_flowy/lib/core/notification_helper.dart b/frontend/app_flowy/lib/core/notification_helper.dart index 650abc544c..ba99c8bab0 100644 --- a/frontend/app_flowy/lib/core/notification_helper.dart +++ b/frontend/app_flowy/lib/core/notification_helper.dart @@ -1,68 +1,6 @@ -import 'dart:async'; import 'dart:typed_data'; import 'package:flowy_sdk/protobuf/dart-notify/protobuf.dart'; -import 'package:flowy_sdk/protobuf/flowy-user/protobuf.dart'; import 'package:dartz/dartz.dart'; -import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; -import 'package:flowy_sdk/protobuf/flowy-folder/dart_notification.pb.dart'; -import 'package:flowy_sdk/protobuf/flowy-grid/dart_notification.pb.dart'; -import 'package:flowy_sdk/rust_stream.dart'; - -// User -typedef UserNotificationCallback = void Function(UserNotification, Either); - -class UserNotificationParser extends NotificationParser { - UserNotificationParser({required String id, required UserNotificationCallback callback}) - : super( - id: id, - callback: callback, - tyParser: (ty) => UserNotification.valueOf(ty), - errorParser: (bytes) => FlowyError.fromBuffer(bytes), - ); -} - -// Folder -typedef FolderNotificationCallback = void Function(FolderNotification, Either); - -class FolderNotificationParser extends NotificationParser { - FolderNotificationParser({String? id, required FolderNotificationCallback callback}) - : super( - id: id, - callback: callback, - tyParser: (ty) => FolderNotification.valueOf(ty), - errorParser: (bytes) => FlowyError.fromBuffer(bytes), - ); -} - -// Grid -typedef GridNotificationCallback = void Function(GridNotification, Either); - -class GridNotificationParser extends NotificationParser { - GridNotificationParser({String? id, required GridNotificationCallback callback}) - : super( - id: id, - callback: callback, - tyParser: (ty) => GridNotification.valueOf(ty), - errorParser: (bytes) => FlowyError.fromBuffer(bytes), - ); -} - -typedef GridNotificationHandler = Function(GridNotification ty, Either result); - -class GridNotificationListener { - StreamSubscription? _subscription; - GridNotificationParser? _parser; - - GridNotificationListener({required String objectId, required GridNotificationHandler handler}) - : _parser = GridNotificationParser(id: objectId, callback: handler) { - _subscription = RustStreamReceiver.listen((observable) => _parser?.parse(observable)); - } - - Future stop() async { - _parser = null; - await _subscription?.cancel(); - } -} class NotificationParser { String? id; diff --git a/frontend/app_flowy/lib/core/user_notification.dart b/frontend/app_flowy/lib/core/user_notification.dart new file mode 100644 index 0000000000..8e43d4b824 --- /dev/null +++ b/frontend/app_flowy/lib/core/user_notification.dart @@ -0,0 +1,39 @@ +import 'dart:async'; +import 'dart:typed_data'; +import 'package:flowy_sdk/protobuf/dart-notify/protobuf.dart'; +import 'package:flowy_sdk/protobuf/flowy-user/protobuf.dart'; +import 'package:dartz/dartz.dart'; +import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; +import 'package:flowy_sdk/rust_stream.dart'; + +import 'notification_helper.dart'; + +// User +typedef UserNotificationCallback = void Function(UserNotification, Either); + +class UserNotificationParser extends NotificationParser { + UserNotificationParser({required String id, required UserNotificationCallback callback}) + : super( + id: id, + callback: callback, + tyParser: (ty) => UserNotification.valueOf(ty), + errorParser: (bytes) => FlowyError.fromBuffer(bytes), + ); +} + +typedef UserNotificationHandler = Function(UserNotification ty, Either result); + +class UserNotificationListener { + StreamSubscription? _subscription; + UserNotificationParser? _parser; + + UserNotificationListener({required String objectId, required UserNotificationHandler handler}) + : _parser = UserNotificationParser(id: objectId, callback: handler) { + _subscription = RustStreamReceiver.listen((observable) => _parser?.parse(observable)); + } + + Future stop() async { + _parser = null; + await _subscription?.cancel(); + } +} diff --git a/frontend/app_flowy/lib/plugin/plugin.dart b/frontend/app_flowy/lib/plugin/plugin.dart index 3d21756605..e05a3ad862 100644 --- a/frontend/app_flowy/lib/plugin/plugin.dart +++ b/frontend/app_flowy/lib/plugin/plugin.dart @@ -4,7 +4,7 @@ import 'package:app_flowy/plugin/plugin.dart'; import 'package:app_flowy/startup/startup.dart'; import 'package:app_flowy/workspace/presentation/home/home_stack.dart'; import 'package:flowy_infra/notifier.dart'; -import 'package:flowy_sdk/protobuf/flowy-folder-data-model/view.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-folder/view.pb.dart'; import 'package:flutter/widgets.dart'; export "./src/sandbox.dart"; diff --git a/frontend/app_flowy/lib/startup/deps_resolver.dart b/frontend/app_flowy/lib/startup/deps_resolver.dart index 56d28bbfe4..b146fd04e7 100644 --- a/frontend/app_flowy/lib/startup/deps_resolver.dart +++ b/frontend/app_flowy/lib/startup/deps_resolver.dart @@ -13,8 +13,8 @@ import 'package:app_flowy/user/application/prelude.dart'; import 'package:app_flowy/user/presentation/router.dart'; import 'package:app_flowy/workspace/presentation/home/home_stack.dart'; import 'package:app_flowy/workspace/presentation/home/menu/menu.dart'; -import 'package:flowy_sdk/protobuf/flowy-folder-data-model/app.pb.dart'; -import 'package:flowy_sdk/protobuf/flowy-folder-data-model/view.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-folder/app.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-folder/view.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-user-data-model/user_profile.pb.dart'; import 'package:fluttertoast/fluttertoast.dart'; import 'package:get_it/get_it.dart'; @@ -52,7 +52,7 @@ void _resolveHomeDeps(GetIt getIt) { getIt.registerSingleton(MenuSharedState()); getIt.registerFactoryParam( - (user, _) => UserListener(user: user), + (user, _) => UserListener(userProfile: user), ); // @@ -61,7 +61,7 @@ void _resolveHomeDeps(GetIt getIt) { getIt.registerFactoryParam( (user, _) => WelcomeBloc( userService: UserService(userId: user.id), - userListener: getIt(param1: user), + userWorkspaceListener: UserWorkspaceListener(userProfile: user), ), ); @@ -73,8 +73,8 @@ void _resolveHomeDeps(GetIt getIt) { void _resolveFolderDeps(GetIt getIt) { //workspace - getIt.registerFactoryParam((user, workspaceId) => - WorkspaceListener(service: WorkspaceListenerService(user: user, workspaceId: workspaceId))); + getIt.registerFactoryParam( + (user, workspaceId) => WorkspaceListener(user: user, workspaceId: workspaceId)); // View getIt.registerFactoryParam( @@ -98,10 +98,7 @@ void _resolveFolderDeps(GetIt getIt) { ); getIt.registerFactoryParam( - (user, _) => MenuUserBloc( - user, - getIt(param1: user), - ), + (user, _) => MenuUserBloc(user), ); // App diff --git a/frontend/app_flowy/lib/user/application/user_listener.dart b/frontend/app_flowy/lib/user/application/user_listener.dart index 291e955745..6d05a9252d 100644 --- a/frontend/app_flowy/lib/user/application/user_listener.dart +++ b/frontend/app_flowy/lib/user/application/user_listener.dart @@ -1,10 +1,11 @@ import 'dart:async'; +import 'package:app_flowy/core/folder_notification.dart'; +import 'package:app_flowy/core/user_notification.dart'; import 'package:dartz/dartz.dart'; import 'package:flowy_sdk/protobuf/flowy-error-code/code.pb.dart'; -import 'package:flowy_sdk/protobuf/flowy-folder-data-model/workspace.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-folder/workspace.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; import 'dart:typed_data'; -import 'package:app_flowy/core/notification_helper.dart'; import 'package:flowy_infra/notifier.dart'; import 'package:flowy_sdk/protobuf/dart-notify/protobuf.dart'; import 'package:flowy_sdk/protobuf/flowy-folder/dart_notification.pb.dart'; @@ -14,104 +15,58 @@ import 'package:flowy_sdk/rust_stream.dart'; typedef UserProfileNotifyValue = Either; typedef AuthNotifyValue = Either; -typedef WorkspaceListNotifyValue = Either, FlowyError>; -typedef WorkspaceSettingNotifyValue = Either; class UserListener { StreamSubscription? _subscription; - final _profileNotifier = PublishNotifier(); - final _authNotifier = PublishNotifier(); - final _workspaceListNotifier = PublishNotifier(); - final _workSettingNotifier = PublishNotifier(); + PublishNotifier? _authNotifier = PublishNotifier(); + PublishNotifier? _profileNotifier = PublishNotifier(); - FolderNotificationParser? _workspaceParser; UserNotificationParser? _userParser; - final UserProfile _user; + final UserProfile _userProfile; UserListener({ - required UserProfile user, - }) : _user = user; + required UserProfile userProfile, + }) : _userProfile = userProfile; void start({ void Function(AuthNotifyValue)? onAuthChanged, void Function(UserProfileNotifyValue)? onProfileUpdated, - void Function(WorkspaceListNotifyValue)? onWorkspaceListUpdated, - void Function(WorkspaceSettingNotifyValue)? onWorkspaceSettingUpdated, }) { - if (onAuthChanged != null) { - _authNotifier.addListener(() { - onAuthChanged(_authNotifier.currentValue!); - }); - } - if (onProfileUpdated != null) { - _profileNotifier.addListener(() { - onProfileUpdated(_profileNotifier.currentValue!); - }); + _profileNotifier?.addPublishListener(onProfileUpdated); } - if (onWorkspaceListUpdated != null) { - _workspaceListNotifier.addListener(() { - onWorkspaceListUpdated(_workspaceListNotifier.currentValue!); - }); + if (onAuthChanged != null) { + _authNotifier?.addPublishListener(onAuthChanged); } - if (onWorkspaceSettingUpdated != null) { - _workSettingNotifier.addListener(() { - onWorkspaceSettingUpdated(_workSettingNotifier.currentValue!); - }); - } - - _workspaceParser = FolderNotificationParser(id: _user.token, callback: _notificationCallback); - _userParser = UserNotificationParser(id: _user.token, callback: _userNotificationCallback); + _userParser = UserNotificationParser(id: _userProfile.token, callback: _userNotificationCallback); _subscription = RustStreamReceiver.listen((observable) { - _workspaceParser?.parse(observable); _userParser?.parse(observable); }); } Future stop() async { - _workspaceParser = null; _userParser = null; await _subscription?.cancel(); - _profileNotifier.dispose(); - _authNotifier.dispose(); - _workspaceListNotifier.dispose(); - } + _profileNotifier?.dispose(); + _profileNotifier = null; - void _notificationCallback(FolderNotification ty, Either result) { - switch (ty) { - case FolderNotification.UserCreateWorkspace: - case FolderNotification.UserDeleteWorkspace: - case FolderNotification.WorkspaceListUpdated: - result.fold( - (payload) => _workspaceListNotifier.value = left(RepeatedWorkspace.fromBuffer(payload).items), - (error) => _workspaceListNotifier.value = right(error), - ); - break; - case FolderNotification.WorkspaceSetting: - result.fold( - (payload) => _workSettingNotifier.value = left(CurrentWorkspaceSetting.fromBuffer(payload)), - (error) => _workSettingNotifier.value = right(error), - ); - break; - case FolderNotification.UserUnauthorized: - result.fold( - (_) {}, - (error) => _authNotifier.value = right(FlowyError.create()..code = ErrorCode.UserUnauthorized.value), - ); - break; - - default: - break; - } + _authNotifier?.dispose(); + _authNotifier = null; } void _userNotificationCallback(user.UserNotification ty, Either result) { switch (ty) { case user.UserNotification.UserUnauthorized: result.fold( - (payload) => _profileNotifier.value = left(UserProfile.fromBuffer(payload)), - (error) => _profileNotifier.value = right(error), + (_) {}, + (error) => _authNotifier?.value = right(error), + ); + break; + case user.UserNotification.UserProfileUpdated: + result.fold( + (payload) => _profileNotifier?.value = left(UserProfile.fromBuffer(payload)), + (error) => _profileNotifier?.value = right(error), ); break; default: @@ -119,3 +74,81 @@ class UserListener { } } } + +typedef WorkspaceListNotifyValue = Either, FlowyError>; +typedef WorkspaceSettingNotifyValue = Either; + +class UserWorkspaceListener { + PublishNotifier? _authNotifier = PublishNotifier(); + PublishNotifier? _workspacesChangedNotifier = PublishNotifier(); + PublishNotifier? _settingChangedNotifier = PublishNotifier(); + + FolderNotificationListener? _listener; + final UserProfile _userProfile; + + UserWorkspaceListener({ + required UserProfile userProfile, + }) : _userProfile = userProfile; + + void start({ + void Function(AuthNotifyValue)? onAuthChanged, + void Function(WorkspaceListNotifyValue)? onWorkspacesUpdated, + void Function(WorkspaceSettingNotifyValue)? onSettingUpdated, + }) { + if (onAuthChanged != null) { + _authNotifier?.addPublishListener(onAuthChanged); + } + + if (onWorkspacesUpdated != null) { + _workspacesChangedNotifier?.addPublishListener(onWorkspacesUpdated); + } + + if (onSettingUpdated != null) { + _settingChangedNotifier?.addPublishListener(onSettingUpdated); + } + + _listener = FolderNotificationListener( + objectId: _userProfile.token, + handler: _handleObservableType, + ); + } + + void _handleObservableType(FolderNotification ty, Either result) { + switch (ty) { + case FolderNotification.UserCreateWorkspace: + case FolderNotification.UserDeleteWorkspace: + case FolderNotification.WorkspaceListUpdated: + result.fold( + (payload) => _workspacesChangedNotifier?.value = left(RepeatedWorkspace.fromBuffer(payload).items), + (error) => _workspacesChangedNotifier?.value = right(error), + ); + break; + case FolderNotification.WorkspaceSetting: + result.fold( + (payload) => _settingChangedNotifier?.value = left(CurrentWorkspaceSetting.fromBuffer(payload)), + (error) => _settingChangedNotifier?.value = right(error), + ); + break; + case FolderNotification.UserUnauthorized: + result.fold( + (_) {}, + (error) => _authNotifier?.value = right(FlowyError.create()..code = ErrorCode.UserUnauthorized.value), + ); + break; + default: + break; + } + } + + Future stop() async { + await _listener?.stop(); + _workspacesChangedNotifier?.dispose(); + _workspacesChangedNotifier = null; + + _settingChangedNotifier?.dispose(); + _settingChangedNotifier = null; + + _authNotifier?.dispose(); + _authNotifier = null; + } +} diff --git a/frontend/app_flowy/lib/user/application/user_service.dart b/frontend/app_flowy/lib/user/application/user_service.dart index 627083d72f..5c953dc2cc 100644 --- a/frontend/app_flowy/lib/user/application/user_service.dart +++ b/frontend/app_flowy/lib/user/application/user_service.dart @@ -3,7 +3,7 @@ import 'dart:async'; import 'package:dartz/dartz.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-data-model/workspace.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-folder/workspace.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-user-data-model/user_profile.pb.dart'; class UserService { diff --git a/frontend/app_flowy/lib/user/presentation/router.dart b/frontend/app_flowy/lib/user/presentation/router.dart index efe03b56f9..a0b6cd4f06 100644 --- a/frontend/app_flowy/lib/user/presentation/router.dart +++ b/frontend/app_flowy/lib/user/presentation/router.dart @@ -8,7 +8,7 @@ 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-data-model/protobuf.dart' show UserProfile; -import 'package:flowy_sdk/protobuf/flowy-folder-data-model/protobuf.dart'; +import 'package:flowy_sdk/protobuf/flowy-folder/protobuf.dart'; import 'package:flutter/material.dart'; class AuthRouter { 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 4a78815beb..719d5b52d4 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 @@ -1,5 +1,4 @@ import 'package:app_flowy/user/application/auth_service.dart'; -import 'package:app_flowy/user/application/user_listener.dart'; import 'package:app_flowy/user/presentation/router.dart'; import 'package:app_flowy/user/presentation/widgets/background.dart'; import 'package:easy_localization/easy_localization.dart'; @@ -10,7 +9,7 @@ import 'package:flowy_infra_ui/widget/rounded_button.dart'; import 'package:flowy_infra_ui/widget/spacing.dart'; import 'package:flowy_sdk/log.dart'; import 'package:flowy_sdk/dispatch/dispatch.dart'; -import 'package:flowy_sdk/protobuf/flowy-folder-data-model/protobuf.dart'; +import 'package:flowy_sdk/protobuf/flowy-folder/protobuf.dart'; import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-user-data-model/user_profile.pb.dart'; import 'package:flutter/material.dart'; @@ -34,8 +33,6 @@ class SkipLogInScreen extends StatefulWidget { } class _SkipLogInScreenState extends State { - UserListener? userListener; - @override Widget build(BuildContext context) { return Scaffold( diff --git a/frontend/app_flowy/lib/user/presentation/welcome_screen.dart b/frontend/app_flowy/lib/user/presentation/welcome_screen.dart index 81f7cfb50f..6d5a4c30c6 100644 --- a/frontend/app_flowy/lib/user/presentation/welcome_screen.dart +++ b/frontend/app_flowy/lib/user/presentation/welcome_screen.dart @@ -5,7 +5,7 @@ import 'package:flowy_infra/theme.dart'; import 'package:flowy_infra_ui/style_widget/scrolling/styled_list.dart'; import 'package:flowy_infra_ui/style_widget/button.dart'; import 'package:flowy_infra_ui/widget/error_page.dart'; -import 'package:flowy_sdk/protobuf/flowy-folder-data-model/workspace.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-folder/workspace.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-user-data-model/user_profile.pb.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; 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 e5eabe98e4..18f93abd6f 100644 --- a/frontend/app_flowy/lib/workspace/application/app/app_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/app/app_bloc.dart @@ -7,8 +7,8 @@ import 'package:app_flowy/workspace/application/app/app_service.dart'; import 'package:app_flowy/workspace/presentation/home/menu/menu.dart'; import 'package:expandable/expandable.dart'; import 'package:flowy_sdk/log.dart'; -import 'package:flowy_sdk/protobuf/flowy-folder-data-model/app.pb.dart'; -import 'package:flowy_sdk/protobuf/flowy-folder-data-model/view.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-folder/app.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-folder/view.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; import 'package:flutter/foundation.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; 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 c1696e55f2..6a30b270af 100644 --- a/frontend/app_flowy/lib/workspace/application/app/app_listener.dart +++ b/frontend/app_flowy/lib/workspace/application/app/app_listener.dart @@ -1,12 +1,12 @@ import 'dart:async'; import 'dart:typed_data'; +import 'package:app_flowy/core/folder_notification.dart'; import 'package:dartz/dartz.dart'; -import 'package:app_flowy/core/notification_helper.dart'; import 'package:flowy_sdk/log.dart'; import 'package:flowy_sdk/protobuf/dart-notify/subject.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; -import 'package:flowy_sdk/protobuf/flowy-folder-data-model/app.pb.dart'; -import 'package:flowy_sdk/protobuf/flowy-folder-data-model/view.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-folder/app.pb.dart'; +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'; 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 d99bb6b524..51513a4032 100644 --- a/frontend/app_flowy/lib/workspace/application/app/app_service.dart +++ b/frontend/app_flowy/lib/workspace/application/app/app_service.dart @@ -3,8 +3,8 @@ import 'dart:async'; import 'package:dartz/dartz.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-data-model/app.pb.dart'; -import 'package:flowy_sdk/protobuf/flowy-folder-data-model/view.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-folder/app.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-folder/view.pb.dart'; import 'package:app_flowy/plugin/plugin.dart'; 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 20d232f07b..1c77fa1cbd 100644 --- a/frontend/app_flowy/lib/workspace/application/doc/doc_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/doc/doc_bloc.dart @@ -2,9 +2,9 @@ import 'dart:convert'; import 'package:app_flowy/workspace/application/doc/doc_service.dart'; import 'package:app_flowy/workspace/application/trash/trash_service.dart'; import 'package:app_flowy/workspace/application/view/view_listener.dart'; -import 'package:flowy_sdk/protobuf/flowy-folder-data-model/trash.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-folder/trash.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; -import 'package:flowy_sdk/protobuf/flowy-folder-data-model/view.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-folder/view.pb.dart'; import 'package:flutter_quill/flutter_quill.dart' show Document, Delta; import 'package:flowy_sdk/log.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; 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 930e01ff22..992dfdeb63 100644 --- a/frontend/app_flowy/lib/workspace/application/doc/doc_service.dart +++ b/frontend/app_flowy/lib/workspace/application/doc/doc_service.dart @@ -1,7 +1,7 @@ import 'package:dartz/dartz.dart'; import 'package:flowy_sdk/dispatch/dispatch.dart'; -import 'package:flowy_sdk/protobuf/flowy-folder-data-model/view.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-folder/view.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-sync/text_block.pb.dart'; 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 e24411fdc0..90c041eb75 100644 --- a/frontend/app_flowy/lib/workspace/application/doc/share_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/doc/share_bloc.dart @@ -4,7 +4,7 @@ import 'package:app_flowy/startup/tasks/rust_sdk.dart'; import 'package:app_flowy/workspace/application/doc/share_service.dart'; import 'package:app_flowy/workspace/application/markdown/delta_markdown.dart'; import 'package:flowy_sdk/protobuf/flowy-text-block/entities.pb.dart'; -import 'package:flowy_sdk/protobuf/flowy-folder-data-model/view.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-folder/view.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; diff --git a/frontend/app_flowy/lib/workspace/application/grid/block/block_listener.dart b/frontend/app_flowy/lib/workspace/application/grid/block/block_listener.dart index bdcecb0324..63accc38d0 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/block/block_listener.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/block/block_listener.dart @@ -1,7 +1,6 @@ import 'dart:async'; import 'dart:typed_data'; - -import 'package:app_flowy/core/notification_helper.dart'; +import 'package:app_flowy/core/grid_notification.dart'; import 'package:dartz/dartz.dart'; import 'package:flowy_infra/notifier.dart'; import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; diff --git a/frontend/app_flowy/lib/workspace/application/grid/cell/cell_listener.dart b/frontend/app_flowy/lib/workspace/application/grid/cell/cell_listener.dart index 05289fee03..5da5fce86d 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/cell/cell_listener.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/cell/cell_listener.dart @@ -1,10 +1,10 @@ +import 'package:app_flowy/core/grid_notification.dart'; import 'package:dartz/dartz.dart'; import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-grid/dart_notification.pb.dart'; import 'package:flowy_infra/notifier.dart'; import 'dart:async'; import 'dart:typed_data'; -import 'package:app_flowy/core/notification_helper.dart'; typedef UpdateFieldNotifiedValue = Either; diff --git a/frontend/app_flowy/lib/workspace/application/grid/field/field_listener.dart b/frontend/app_flowy/lib/workspace/application/grid/field/field_listener.dart index c6dd832973..21bd5befeb 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/field/field_listener.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/field/field_listener.dart @@ -1,10 +1,10 @@ +import 'package:app_flowy/core/grid_notification.dart'; import 'package:dartz/dartz.dart'; import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-grid/dart_notification.pb.dart'; import 'package:flowy_infra/notifier.dart'; import 'dart:async'; import 'dart:typed_data'; -import 'package:app_flowy/core/notification_helper.dart'; import 'package:flowy_sdk/protobuf/flowy-grid/field_entities.pb.dart'; typedef UpdateFieldNotifiedValue = Either; diff --git a/frontend/app_flowy/lib/workspace/application/grid/field/grid_listenr.dart b/frontend/app_flowy/lib/workspace/application/grid/field/grid_listenr.dart index 869ade19c0..00e94bb3e1 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/field/grid_listenr.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/field/grid_listenr.dart @@ -1,10 +1,10 @@ +import 'package:app_flowy/core/grid_notification.dart'; import 'package:dartz/dartz.dart'; import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-grid/dart_notification.pb.dart'; import 'package:flowy_infra/notifier.dart'; import 'dart:async'; import 'dart:typed_data'; -import 'package:app_flowy/core/notification_helper.dart'; import 'package:flowy_sdk/protobuf/flowy-grid/field_entities.pb.dart'; typedef UpdateFieldNotifiedValue = Either; 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 3423dc34a4..49e90b6a9e 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/grid_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/grid_bloc.dart @@ -3,7 +3,7 @@ import 'package:dartz/dartz.dart'; import 'package:equatable/equatable.dart'; import 'package:flowy_sdk/log.dart'; import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; -import 'package:flowy_sdk/protobuf/flowy-folder-data-model/view.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-folder/view.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-grid/protobuf.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; 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 798db9c1e7..391a5d13a2 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/grid_service.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/grid_service.dart @@ -5,7 +5,7 @@ import 'package:dartz/dartz.dart'; import 'package:flowy_sdk/dispatch/dispatch.dart'; import 'package:flowy_sdk/log.dart'; import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; -import 'package:flowy_sdk/protobuf/flowy-folder-data-model/view.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-folder/view.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-grid/block_entities.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-grid/field_entities.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-grid/grid_entities.pb.dart'; diff --git a/frontend/app_flowy/lib/workspace/application/grid/row/row_listener.dart b/frontend/app_flowy/lib/workspace/application/grid/row/row_listener.dart index 5cf46acd11..98fddaeccf 100644 --- a/frontend/app_flowy/lib/workspace/application/grid/row/row_listener.dart +++ b/frontend/app_flowy/lib/workspace/application/grid/row/row_listener.dart @@ -1,10 +1,10 @@ +import 'package:app_flowy/core/grid_notification.dart'; import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-grid/block_entities.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-grid/dart_notification.pb.dart'; import 'package:flowy_infra/notifier.dart'; import 'dart:async'; import 'dart:typed_data'; -import 'package:app_flowy/core/notification_helper.dart'; import 'package:dartz/dartz.dart'; import 'package:flowy_sdk/protobuf/flowy-grid/field_entities.pb.dart'; 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 19a1e6787d..01ef2dba57 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-data-model/workspace.pb.dart' show CurrentWorkspaceSetting; +import 'package:flowy_sdk/protobuf/flowy-folder/workspace.pb.dart' show CurrentWorkspaceSetting; import 'package:flowy_sdk/protobuf/flowy-user-data-model/user_profile.pb.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; @@ -11,19 +11,17 @@ import 'package:dartz/dartz.dart'; part 'home_bloc.freezed.dart'; class HomeBloc extends Bloc { - final UserListener _listener; + final UserWorkspaceListener _listener; HomeBloc(UserProfile user, CurrentWorkspaceSetting workspaceSetting) - : _listener = UserListener(user: user), + : _listener = UserWorkspaceListener(userProfile: user), super(HomeState.initial(workspaceSetting)) { on((event, emit) async { await event.map( initial: (_Initial value) { _listener.start( - onAuthChanged: (result) { - _authDidChanged(result); - }, - onWorkspaceSettingUpdated: (result) { + onAuthChanged: (result) => _authDidChanged(result), + onSettingUpdated: (result) { result.fold( (setting) => add(HomeEvent.didReceiveWorkspaceSetting(setting)), (r) => Log.error(r), 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 db8f2c534b..b3885d7b6b 100644 --- a/frontend/app_flowy/lib/workspace/application/menu/menu_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/menu/menu_bloc.dart @@ -4,7 +4,7 @@ import 'package:app_flowy/workspace/application/workspace/workspace_listener.dar import 'package:app_flowy/workspace/application/workspace/workspace_service.dart'; import 'package:dartz/dartz.dart'; import 'package:flowy_sdk/log.dart'; -import 'package:flowy_sdk/protobuf/flowy-folder-data-model/app.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-folder/app.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; @@ -22,7 +22,7 @@ class MenuBloc extends Bloc { on((event, emit) async { await event.map( initial: (e) async { - listener.start(addAppCallback: _handleAppsOrFail); + listener.start(appsChanged: _handleAppsOrFail); await _fetchApps(emit); }, openPage: (e) async { 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 7016c2d74c..1baa5c2354 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 @@ -1,7 +1,7 @@ import 'package:app_flowy/user/application/user_listener.dart'; import 'package:app_flowy/user/application/user_service.dart'; import 'package:flowy_sdk/log.dart'; -import 'package:flowy_sdk/protobuf/flowy-folder-data-model/workspace.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-user-data-model/user_profile.pb.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; @@ -12,29 +12,44 @@ part 'menu_user_bloc.freezed.dart'; class MenuUserBloc extends Bloc { final UserService _userService; - final UserListener userListener; + final UserListener _userListener; + final UserWorkspaceListener _userWorkspaceListener; final UserProfile userProfile; - MenuUserBloc(this.userProfile, this.userListener) - : _userService = UserService(userId: userProfile.id), + MenuUserBloc(this.userProfile) + : _userListener = UserListener(userProfile: userProfile), + _userWorkspaceListener = UserWorkspaceListener(userProfile: userProfile), + _userService = UserService(userId: userProfile.id), super(MenuUserState.initial(userProfile)) { on((event, emit) async { - await event.map( - initial: (_) async { - userListener.start( - onProfileUpdated: _profileUpdated, - onWorkspaceListUpdated: _workspaceListUpdated, - ); + await event.when( + initial: () async { + _userListener.start(onProfileUpdated: _profileUpdated); + _userWorkspaceListener.start(onWorkspacesUpdated: _workspaceListUpdated); await _initUser(); }, - fetchWorkspaces: (_FetchWorkspaces value) async {}, + fetchWorkspaces: () async { + // + }, + didReceiveUserProfile: (UserProfile newUserProfile) { + emit(state.copyWith(userProfile: newUserProfile)); + }, + updateUserName: (String name) { + _userService.updateUserProfile(name: name).then((result) { + result.fold( + (l) => null, + (err) => Log.error(err), + ); + }); + }, ); }); } @override Future close() async { - await userListener.stop(); + await _userListener.stop(); + await _userWorkspaceListener.stop(); super.close(); } @@ -43,19 +58,15 @@ class MenuUserBloc extends Bloc { result.fold((l) => null, (error) => Log.error(error)); } - void _profileUpdated(Either userOrFailed) {} + void _profileUpdated(Either userProfileOrFailed) { + userProfileOrFailed.fold( + (newUserProfile) => add(MenuUserEvent.didReceiveUserProfile(newUserProfile)), + (err) => Log.error(err), + ); + } + void _workspaceListUpdated(Either, FlowyError> workspacesOrFailed) { - // fetch workspaces - // iUserImpl.fetchWorkspaces().then((result) { - // result.fold( - // (workspaces) async* { - // yield state.copyWith(workspaces: some(workspaces)); - // }, - // (error) async* { - // yield state.copyWith(successOrFailure: right(error.msg)); - // }, - // ); - // }); + // Do nothing by now } } @@ -63,18 +74,20 @@ class MenuUserBloc extends Bloc { class MenuUserEvent with _$MenuUserEvent { const factory MenuUserEvent.initial() = _Initial; const factory MenuUserEvent.fetchWorkspaces() = _FetchWorkspaces; + const factory MenuUserEvent.updateUserName(String name) = _UpdateUserName; + const factory MenuUserEvent.didReceiveUserProfile(UserProfile newUserProfile) = _DidReceiveUserProfile; } @freezed class MenuUserState with _$MenuUserState { const factory MenuUserState({ - required UserProfile user, + required UserProfile userProfile, required Option> workspaces, required Either successOrFailure, }) = _MenuUserState; - factory MenuUserState.initial(UserProfile user) => MenuUserState( - user: user, + factory MenuUserState.initial(UserProfile 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 c74472aa5d..6d9f4ce9ef 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 @@ -3,7 +3,7 @@ import 'dart:async'; import 'package:app_flowy/workspace/application/app/app_bloc.dart'; import 'package:app_flowy/workspace/application/app/app_service.dart'; import 'package:flowy_sdk/log.dart'; -import 'package:flowy_sdk/protobuf/flowy-folder-data-model/view.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-folder/view.pb.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; 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 e6b61af3e2..8c83cd4d2f 100644 --- a/frontend/app_flowy/lib/workspace/application/trash/trash_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/trash/trash_bloc.dart @@ -1,6 +1,6 @@ import 'package:dartz/dartz.dart'; import 'package:flowy_sdk/log.dart'; -import 'package:flowy_sdk/protobuf/flowy-folder-data-model/trash.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-folder/trash.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; 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 36dc982466..51244e23bb 100644 --- a/frontend/app_flowy/lib/workspace/application/trash/trash_listener.dart +++ b/frontend/app_flowy/lib/workspace/application/trash/trash_listener.dart @@ -1,11 +1,11 @@ import 'dart:async'; import 'dart:typed_data'; +import 'package:app_flowy/core/folder_notification.dart'; import 'package:dartz/dartz.dart'; -import 'package:app_flowy/core/notification_helper.dart'; import 'package:flowy_sdk/protobuf/dart-notify/subject.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-folder/dart_notification.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; -import 'package:flowy_sdk/protobuf/flowy-folder-data-model/trash.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); 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 0e7149050a..a2b6d47147 100644 --- a/frontend/app_flowy/lib/workspace/application/trash/trash_service.dart +++ b/frontend/app_flowy/lib/workspace/application/trash/trash_service.dart @@ -2,7 +2,7 @@ import 'dart:async'; import 'package:dartz/dartz.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-data-model/trash.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-folder/trash.pb.dart'; class TrashService { Future> readTrash() { @@ -34,4 +34,3 @@ class TrashService { return FolderEventDeleteAllTrash().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 c33f44a8c1..f87e863d45 100644 --- a/frontend/app_flowy/lib/workspace/application/view/view_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/view/view_bloc.dart @@ -1,7 +1,7 @@ import 'package:app_flowy/workspace/application/view/view_listener.dart'; import 'package:app_flowy/workspace/application/view/view_service.dart'; import 'package:dartz/dartz.dart'; -import 'package:flowy_sdk/protobuf/flowy-folder-data-model/view.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-folder/view.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; 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 1fb36125e9..3987226a20 100644 --- a/frontend/app_flowy/lib/workspace/application/view/view_ext.dart +++ b/frontend/app_flowy/lib/workspace/application/view/view_ext.dart @@ -1,6 +1,6 @@ import 'package:app_flowy/plugin/plugin.dart'; import 'package:flowy_infra/image.dart'; -import 'package:flowy_sdk/protobuf/flowy-folder-data-model/view.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-folder/view.pb.dart'; import 'package:flutter/material.dart'; enum FlowyPlugin { 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 9a2d913941..4acb5e021f 100644 --- a/frontend/app_flowy/lib/workspace/application/view/view_listener.dart +++ b/frontend/app_flowy/lib/workspace/application/view/view_listener.dart @@ -1,9 +1,9 @@ import 'dart:async'; import 'dart:typed_data'; -import 'package:app_flowy/core/notification_helper.dart'; +import 'package:app_flowy/core/folder_notification.dart'; import 'package:dartz/dartz.dart'; import 'package:flowy_sdk/protobuf/dart-notify/subject.pb.dart'; -import 'package:flowy_sdk/protobuf/flowy-folder-data-model/view.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-folder/view.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-folder/dart_notification.pb.dart'; import 'package:flowy_sdk/rust_stream.dart'; 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 d3d08b0709..c8edd37782 100644 --- a/frontend/app_flowy/lib/workspace/application/view/view_service.dart +++ b/frontend/app_flowy/lib/workspace/application/view/view_service.dart @@ -1,7 +1,7 @@ import 'dart:async'; import 'package:dartz/dartz.dart'; import 'package:flowy_sdk/dispatch/dispatch.dart'; -import 'package:flowy_sdk/protobuf/flowy-folder-data-model/view.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-folder/view.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; class ViewService { 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 a743a3316f..dd3edb27c1 100644 --- a/frontend/app_flowy/lib/workspace/application/workspace/welcome_bloc.dart +++ b/frontend/app_flowy/lib/workspace/application/workspace/welcome_bloc.dart @@ -1,7 +1,7 @@ import 'package:app_flowy/user/application/user_listener.dart'; import 'package:app_flowy/user/application/user_service.dart'; import 'package:flowy_sdk/log.dart'; -import 'package:flowy_sdk/protobuf/flowy-folder-data-model/workspace.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-folder/workspace.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; @@ -11,13 +11,13 @@ part 'welcome_bloc.freezed.dart'; class WelcomeBloc extends Bloc { final UserService userService; - final UserListener userListener; - WelcomeBloc({required this.userService, required this.userListener}) : super(WelcomeState.initial()) { + final UserWorkspaceListener userWorkspaceListener; + WelcomeBloc({required this.userService, required this.userWorkspaceListener}) : super(WelcomeState.initial()) { on( (event, emit) async { await event.map(initial: (e) async { - userListener.start( - onWorkspaceListUpdated: (result) => add(WelcomeEvent.workspacesReveived(result)), + userWorkspaceListener.start( + onWorkspacesUpdated: (result) => add(WelcomeEvent.workspacesReveived(result)), ); // await _fetchWorkspaces(emit); @@ -37,7 +37,7 @@ class WelcomeBloc extends Bloc { @override Future close() async { - await userListener.stop(); + await userWorkspaceListener.stop(); super.close(); } 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 9ac51e36f8..bf2abf1a6a 100644 --- a/frontend/app_flowy/lib/workspace/application/workspace/workspace_listener.dart +++ b/frontend/app_flowy/lib/workspace/application/workspace/workspace_listener.dart @@ -1,97 +1,73 @@ import 'dart:async'; import 'dart:typed_data'; - -import 'package:app_flowy/core/notification_helper.dart'; +import 'package:app_flowy/core/folder_notification.dart'; import 'package:dartz/dartz.dart'; -import 'package:flowy_sdk/log.dart'; -import 'package:flowy_sdk/protobuf/dart-notify/subject.pb.dart'; +import 'package:flowy_infra/notifier.dart'; import 'package:flowy_sdk/protobuf/flowy-user-data-model/protobuf.dart' show UserProfile; -import 'package:flowy_sdk/protobuf/flowy-folder-data-model/app.pb.dart'; -import 'package:flowy_sdk/protobuf/flowy-folder-data-model/workspace.pb.dart'; +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'; -import 'package:flowy_sdk/rust_stream.dart'; -typedef WorkspaceAppsChangedCallback = void Function(Either, FlowyError> appsOrFail); -typedef WorkspaceUpdatedCallback = void Function(String name, String desc); +typedef AppListNotifyValue = Either, FlowyError>; +typedef WorkspaceNotifyValue = Either; class WorkspaceListener { - WorkspaceListenerService service; - WorkspaceListener({ - required this.service, - }); + PublishNotifier? _appsChangedNotifier = PublishNotifier(); + PublishNotifier? _workspaceUpdatedNotifier = PublishNotifier(); - void start({WorkspaceAppsChangedCallback? addAppCallback, WorkspaceUpdatedCallback? updatedCallback}) { - service.startListening(appsChanged: addAppCallback, update: updatedCallback); - } - - Future stop() async { - await service.close(); - } -} - -class WorkspaceListenerService { - StreamSubscription? _subscription; - WorkspaceAppsChangedCallback? _appsChanged; - WorkspaceUpdatedCallback? _update; - FolderNotificationParser? _parser; + FolderNotificationListener? _listener; final UserProfile user; final String workspaceId; - WorkspaceListenerService({ + WorkspaceListener({ required this.user, required this.workspaceId, }); - void startListening({ - WorkspaceAppsChangedCallback? appsChanged, - WorkspaceUpdatedCallback? update, + void start({ + void Function(AppListNotifyValue)? appsChanged, + void Function(WorkspaceNotifyValue)? onWorkspaceUpdated, }) { - _appsChanged = appsChanged; - _update = update; + if (appsChanged != null) { + _appsChangedNotifier?.addPublishListener(appsChanged); + } - _parser = FolderNotificationParser( - id: workspaceId, - callback: (ty, result) { - _handleObservableType(ty, result); - }, + if (onWorkspaceUpdated != null) { + _workspaceUpdatedNotifier?.addPublishListener(onWorkspaceUpdated); + } + + _listener = FolderNotificationListener( + objectId: workspaceId, + handler: _handleObservableType, ); - - _subscription = RustStreamReceiver.listen((observable) => _parser?.parse(observable)); } void _handleObservableType(FolderNotification ty, Either result) { switch (ty) { case FolderNotification.WorkspaceUpdated: - if (_update != null) { - result.fold( - (payload) { - final workspace = Workspace.fromBuffer(payload); - _update!(workspace.name, workspace.desc); - }, - (error) => Log.error(error), - ); - } + result.fold( + (payload) => _workspaceUpdatedNotifier?.value = left(Workspace.fromBuffer(payload)), + (error) => _workspaceUpdatedNotifier?.value = right(error), + ); break; case FolderNotification.WorkspaceAppsChanged: - if (_appsChanged != null) { - result.fold( - (payload) => _appsChanged!( - left(RepeatedApp.fromBuffer(payload).items), - ), - (error) => _appsChanged!(right(error)), - ); - } + result.fold( + (payload) => _appsChangedNotifier?.value = left(RepeatedApp.fromBuffer(payload).items), + (error) => _appsChangedNotifier?.value = right(error), + ); break; default: break; } } - Future close() async { - _parser = null; - await _subscription?.cancel(); - // _appsChanged = null; - // _update = null; + Future stop() async { + await _listener?.stop(); + _appsChangedNotifier?.dispose(); + _appsChangedNotifier = null; + + _workspaceUpdatedNotifier?.dispose(); + _workspaceUpdatedNotifier = null; } } 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 54183497c9..678794b594 100644 --- a/frontend/app_flowy/lib/workspace/application/workspace/workspace_service.dart +++ b/frontend/app_flowy/lib/workspace/application/workspace/workspace_service.dart @@ -4,9 +4,9 @@ import 'package:dartz/dartz.dart'; 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-data-model/app.pb.dart'; -import 'package:flowy_sdk/protobuf/flowy-folder-data-model/view.pb.dart' show MoveFolderItemPayload, MoveFolderItemType; -import 'package:flowy_sdk/protobuf/flowy-folder-data-model/workspace.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/workspace.pb.dart'; import 'package:app_flowy/generated/locale_keys.g.dart'; 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 df232b71e0..e11906ece4 100644 --- a/frontend/app_flowy/lib/workspace/presentation/home/home_screen.dart +++ b/frontend/app_flowy/lib/workspace/presentation/home/home_screen.dart @@ -6,7 +6,7 @@ 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-data-model/protobuf.dart' show UserProfile; -import 'package:flowy_sdk/protobuf/flowy-folder-data-model/protobuf.dart'; +import 'package:flowy_sdk/protobuf/flowy-folder/protobuf.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:styled_widget/styled_widget.dart'; diff --git a/frontend/app_flowy/lib/workspace/presentation/home/menu/app/header/add_button.dart b/frontend/app_flowy/lib/workspace/presentation/home/menu/app/header/add_button.dart index 39c13c1c12..5b15fecc52 100644 --- a/frontend/app_flowy/lib/workspace/presentation/home/menu/app/header/add_button.dart +++ b/frontend/app_flowy/lib/workspace/presentation/home/menu/app/header/add_button.dart @@ -83,6 +83,7 @@ class CreateItem extends StatelessWidget { return FlowyHover( style: config, child: GestureDetector( + behavior: HitTestBehavior.opaque, onTap: () => onSelected(pluginBuilder), child: FlowyText.medium( pluginBuilder.menuName, 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 ff1d6e6822..2d26aabc0b 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 @@ -5,7 +5,7 @@ import 'package:flowy_infra/icon_data.dart'; import 'package:flowy_infra/theme.dart'; import 'package:flowy_infra_ui/flowy_infra_ui.dart'; import 'package:flowy_infra_ui/style_widget/text.dart'; -import 'package:flowy_sdk/protobuf/flowy-folder-data-model/app.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-folder/app.pb.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:app_flowy/workspace/application/app/app_bloc.dart'; 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 ae7345612a..462ce1ba8a 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 @@ -1,7 +1,7 @@ import 'package:app_flowy/workspace/application/appearance.dart'; import 'package:app_flowy/workspace/presentation/home/menu/menu.dart'; import 'package:expandable/expandable.dart'; -import 'package:flowy_sdk/protobuf/flowy-folder-data-model/app.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-folder/app.pb.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:app_flowy/startup/startup.dart'; 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 d2bc81472c..f5de13892f 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 @@ -9,7 +9,7 @@ import 'package:flowy_infra/theme.dart'; import 'package:flowy_infra_ui/style_widget/hover.dart'; import 'package:flowy_infra_ui/style_widget/text.dart'; import 'package:flowy_infra_ui/widget/spacing.dart'; -import 'package:flowy_sdk/protobuf/flowy-folder-data-model/view.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-folder/view.pb.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:styled_widget/styled_widget.dart'; 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 0eb22e3d1f..f53ebd1bf0 100644 --- a/frontend/app_flowy/lib/workspace/presentation/home/menu/menu.dart +++ b/frontend/app_flowy/lib/workspace/presentation/home/menu/menu.dart @@ -11,8 +11,8 @@ 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-data-model/protobuf.dart' show UserProfile; -import 'package:flowy_sdk/protobuf/flowy-folder-data-model/view.pb.dart'; -import 'package:flowy_sdk/protobuf/flowy-folder-data-model/workspace.pb.dart'; +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'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:styled_widget/styled_widget.dart'; 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 3a1674e486..6b6849e43d 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 @@ -58,9 +58,9 @@ class MenuUser extends StatelessWidget { } Widget _renderUserName(BuildContext context) { - String name = context.read().state.user.name; + String name = context.read().state.userProfile.name; if (name.isEmpty) { - name = context.read().state.user.email; + name = context.read().state.userProfile.email; } return FlowyText(name, fontSize: 12); } 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 041f1c4713..b8692168c6 100644 --- a/frontend/app_flowy/lib/workspace/presentation/plugins/board/board.dart +++ b/frontend/app_flowy/lib/workspace/presentation/plugins/board/board.dart @@ -1,6 +1,6 @@ import 'package:app_flowy/workspace/presentation/home/home_stack.dart'; import 'package:app_flowy/workspace/presentation/plugins/widgets/left_bar_item.dart'; -import 'package:flowy_sdk/protobuf/flowy-folder-data-model/view.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-folder/view.pb.dart'; import 'package:app_flowy/plugin/plugin.dart'; import 'package:flutter/material.dart'; 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 5a74ddd4f4..1cdfea5480 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 @@ -1,6 +1,6 @@ // ignore_for_file: unused_field -import 'package:flowy_sdk/protobuf/flowy-folder-data-model/view.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-folder/view.pb.dart'; import 'package:flutter/material.dart'; class BoardPage extends StatelessWidget { 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 111e103796..0759894844 100644 --- a/frontend/app_flowy/lib/workspace/presentation/plugins/doc/document.dart +++ b/frontend/app_flowy/lib/workspace/presentation/plugins/doc/document.dart @@ -20,7 +20,7 @@ import 'package:flowy_infra_ui/flowy_infra_ui.dart'; import 'package:flowy_infra_ui/widget/rounded_button.dart'; import 'package:flowy_sdk/log.dart'; import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; -import 'package:flowy_sdk/protobuf/flowy-folder-data-model/view.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-folder/view.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-text-block/entities.pb.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; 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 5983102047..a02289a555 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 @@ -6,7 +6,7 @@ import 'package:flowy_infra_ui/style_widget/scrolling/styled_scroll_bar.dart'; import 'package:flowy_infra_ui/widget/spacing.dart'; import 'package:flutter_quill/flutter_quill.dart' as quill; import 'package:flowy_infra_ui/widget/error_page.dart'; -import 'package:flowy_sdk/protobuf/flowy-folder-data-model/view.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-folder/view.pb.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:provider/provider.dart'; 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 d566223de9..da634d8833 100644 --- a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/grid.dart +++ b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/grid.dart @@ -3,7 +3,7 @@ import 'package:app_flowy/plugin/plugin.dart'; import 'package:app_flowy/workspace/presentation/home/home_stack.dart'; import 'package:app_flowy/workspace/presentation/plugins/widgets/left_bar_item.dart'; import 'package:easy_localization/easy_localization.dart'; -import 'package:flowy_sdk/protobuf/flowy-folder-data-model/view.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-folder/view.pb.dart'; import 'package:flutter/material.dart'; import 'src/grid_page.dart'; 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 dbf24fdfa5..6daf2c50fa 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 @@ -5,7 +5,7 @@ import 'package:flowy_infra_ui/style_widget/scrolling/styled_list.dart'; import 'package:flowy_infra_ui/style_widget/scrolling/styled_scroll_bar.dart'; import 'package:flowy_infra_ui/style_widget/scrolling/styled_scrollview.dart'; import 'package:flowy_infra_ui/widget/error_page.dart'; -import 'package:flowy_sdk/protobuf/flowy-folder-data-model/view.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-folder/view.pb.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter/material.dart'; import 'package:linked_scroll_controller/linked_scroll_controller.dart'; 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 2c9679d97d..92b1f61cd0 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 @@ -3,7 +3,7 @@ import 'package:flowy_infra/theme.dart'; import 'package:flowy_infra_ui/style_widget/icon_button.dart'; import 'package:flowy_infra_ui/style_widget/text.dart'; import 'package:flowy_infra_ui/widget/spacing.dart'; -import 'package:flowy_sdk/protobuf/flowy-folder-data-model/trash.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-folder/trash.pb.dart'; import 'package:flutter/material.dart'; import 'package:intl/intl.dart'; import 'package:fixnum/fixnum.dart' as $fixnum; 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 e81fc3e45d..bd9f1441e8 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 @@ -2,7 +2,7 @@ import 'package:app_flowy/workspace/application/view/view_listener.dart'; import 'package:app_flowy/workspace/application/view/view_service.dart'; import 'package:flowy_infra/theme.dart'; import 'package:flowy_sdk/log.dart'; -import 'package:flowy_sdk/protobuf/flowy-folder-data-model/view.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-folder/view.pb.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; diff --git a/frontend/app_flowy/macos/Runner.xcodeproj/project.pbxproj b/frontend/app_flowy/macos/Runner.xcodeproj/project.pbxproj index 61cb05b101..219b81efe0 100644 --- a/frontend/app_flowy/macos/Runner.xcodeproj/project.pbxproj +++ b/frontend/app_flowy/macos/Runner.xcodeproj/project.pbxproj @@ -427,6 +427,7 @@ "$(inherited)", "@executable_path/../Frameworks", ); + ONLY_ACTIVE_ARCH = YES; PRODUCT_BUNDLE_IDENTIFIER = com.appflowy.macos; PRODUCT_NAME = AppFlowy; PROVISIONING_PROFILE_SPECIFIER = ""; diff --git a/frontend/app_flowy/packages/flowy_sdk/lib/dispatch/dispatch.dart b/frontend/app_flowy/packages/flowy_sdk/lib/dispatch/dispatch.dart index 3e168b05f3..6b1bc579e4 100644 --- a/frontend/app_flowy/packages/flowy_sdk/lib/dispatch/dispatch.dart +++ b/frontend/app_flowy/packages/flowy_sdk/lib/dispatch/dispatch.dart @@ -6,7 +6,6 @@ import 'package:flowy_sdk/protobuf/dart-ffi/ffi_response.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-net/network_state.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-user/event_map.pb.dart'; -import 'package:flowy_sdk/protobuf/flowy-folder/event_map.pb.dart'; import 'package:isolates/isolates.dart'; import 'package:isolates/ports.dart'; import 'package:ffi/ffi.dart'; @@ -17,7 +16,7 @@ import 'dart:typed_data'; import 'package:flowy_sdk/ffi.dart' as ffi; import 'package:flowy_sdk/protobuf/flowy-user-data-model/protobuf.dart'; import 'package:flowy_sdk/protobuf/dart-ffi/protobuf.dart'; -import 'package:flowy_sdk/protobuf/flowy-folder-data-model/protobuf.dart'; +import 'package:flowy_sdk/protobuf/flowy-folder/protobuf.dart'; import 'package:flowy_sdk/protobuf/flowy-text-block/protobuf.dart'; import 'package:flowy_sdk/protobuf/flowy-grid/protobuf.dart'; import 'package:flowy_sdk/protobuf/flowy-sync/protobuf.dart'; diff --git a/frontend/rust-lib/Cargo.lock b/frontend/rust-lib/Cargo.lock index fa89ab3137..b3916ec2ec 100644 --- a/frontend/rust-lib/Cargo.lock +++ b/frontend/rust-lib/Cargo.lock @@ -904,6 +904,7 @@ dependencies = [ "strum_macros", "tokio", "tracing", + "unicode-segmentation", ] [[package]] diff --git a/frontend/rust-lib/flowy-folder/Cargo.toml b/frontend/rust-lib/flowy-folder/Cargo.toml index ddc6f1f586..de149a4d9b 100644 --- a/frontend/rust-lib/flowy-folder/Cargo.toml +++ b/frontend/rust-lib/flowy-folder/Cargo.toml @@ -34,6 +34,7 @@ serde = { version = "1.0", features = ["derive"] } tracing = { version = "0.1", features = ["log"] } bytes = { version = "1.0" } +unicode-segmentation = "1.8" [dev-dependencies] serde_json = "1.0" flowy-folder = { path = "../flowy-folder", features = ["flowy_unit_test"]} diff --git a/shared-lib/flowy-folder-data-model/src/entities/app.rs b/frontend/rust-lib/flowy-folder/src/entities/app.rs similarity index 84% rename from shared-lib/flowy-folder-data-model/src/entities/app.rs rename to frontend/rust-lib/flowy-folder/src/entities/app.rs index 87983320d2..1c705d5b0e 100644 --- a/shared-lib/flowy-folder-data-model/src/entities/app.rs +++ b/frontend/rust-lib/flowy-folder/src/entities/app.rs @@ -1,20 +1,16 @@ use crate::{ - entities::view::RepeatedView, - errors::ErrorCode, - impl_def_and_def_mut, - parser::{ + entities::parser::{ app::{AppColorStyle, AppIdentify, AppName}, workspace::WorkspaceIdentify, }, + entities::view::RepeatedView, + errors::ErrorCode, + impl_def_and_def_mut, }; use flowy_derive::ProtoBuf; -use nanoid::nanoid; - +use flowy_folder_data_model::revision::AppRevision; use std::convert::TryInto; -pub fn gen_app_id() -> String { - nanoid!(10) -} #[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)] pub struct App { #[pb(index = 1)] @@ -42,6 +38,20 @@ pub struct App { pub create_time: i64, } +impl std::convert::From for App { + fn from(app_serde: AppRevision) -> Self { + App { + id: app_serde.id, + workspace_id: app_serde.workspace_id, + name: app_serde.name, + desc: app_serde.desc, + belongings: app_serde.belongings.into(), + version: app_serde.version, + modified_time: app_serde.modified_time, + create_time: app_serde.create_time, + } + } +} #[derive(Eq, PartialEq, Debug, Default, ProtoBuf, Clone)] pub struct RepeatedApp { #[pb(index = 1)] @@ -50,6 +60,12 @@ pub struct RepeatedApp { impl_def_and_def_mut!(RepeatedApp, App); +impl std::convert::From> for RepeatedApp { + fn from(values: Vec) -> Self { + let items = values.into_iter().map(|value| value.into()).collect::>(); + RepeatedApp { items } + } +} #[derive(ProtoBuf, Default)] pub struct CreateAppPayload { #[pb(index = 1)] diff --git a/shared-lib/flowy-folder-data-model/src/entities/mod.rs b/frontend/rust-lib/flowy-folder/src/entities/mod.rs similarity index 93% rename from shared-lib/flowy-folder-data-model/src/entities/mod.rs rename to frontend/rust-lib/flowy-folder/src/entities/mod.rs index ed6954739c..e75c8c13bd 100644 --- a/shared-lib/flowy-folder-data-model/src/entities/mod.rs +++ b/frontend/rust-lib/flowy-folder/src/entities/mod.rs @@ -1,4 +1,5 @@ pub mod app; +mod parser; pub mod trash; pub mod view; mod view_info; diff --git a/shared-lib/flowy-folder-data-model/src/parser/app/app_color_style.rs b/frontend/rust-lib/flowy-folder/src/entities/parser/app/app_color_style.rs similarity index 100% rename from shared-lib/flowy-folder-data-model/src/parser/app/app_color_style.rs rename to frontend/rust-lib/flowy-folder/src/entities/parser/app/app_color_style.rs diff --git a/shared-lib/flowy-folder-data-model/src/parser/app/app_desc.rs b/frontend/rust-lib/flowy-folder/src/entities/parser/app/app_desc.rs similarity index 94% rename from shared-lib/flowy-folder-data-model/src/parser/app/app_desc.rs rename to frontend/rust-lib/flowy-folder/src/entities/parser/app/app_desc.rs index 047542d809..7f8e64808b 100644 --- a/shared-lib/flowy-folder-data-model/src/parser/app/app_desc.rs +++ b/frontend/rust-lib/flowy-folder/src/entities/parser/app/app_desc.rs @@ -3,6 +3,7 @@ use unicode_segmentation::UnicodeSegmentation; pub struct AppDesc(pub String); impl AppDesc { + #[allow(dead_code)] pub fn parse(s: String) -> Result { if s.graphemes(true).count() > 1024 { return Err("Workspace description too long".to_string()); diff --git a/shared-lib/flowy-folder-data-model/src/parser/app/app_id.rs b/frontend/rust-lib/flowy-folder/src/entities/parser/app/app_id.rs similarity index 100% rename from shared-lib/flowy-folder-data-model/src/parser/app/app_id.rs rename to frontend/rust-lib/flowy-folder/src/entities/parser/app/app_id.rs diff --git a/shared-lib/flowy-folder-data-model/src/parser/app/app_name.rs b/frontend/rust-lib/flowy-folder/src/entities/parser/app/app_name.rs similarity index 100% rename from shared-lib/flowy-folder-data-model/src/parser/app/app_name.rs rename to frontend/rust-lib/flowy-folder/src/entities/parser/app/app_name.rs diff --git a/shared-lib/flowy-folder-data-model/src/parser/app/mod.rs b/frontend/rust-lib/flowy-folder/src/entities/parser/app/mod.rs similarity index 100% rename from shared-lib/flowy-folder-data-model/src/parser/app/mod.rs rename to frontend/rust-lib/flowy-folder/src/entities/parser/app/mod.rs diff --git a/shared-lib/flowy-folder-data-model/src/parser/mod.rs b/frontend/rust-lib/flowy-folder/src/entities/parser/mod.rs similarity index 100% rename from shared-lib/flowy-folder-data-model/src/parser/mod.rs rename to frontend/rust-lib/flowy-folder/src/entities/parser/mod.rs diff --git a/shared-lib/flowy-folder-data-model/src/parser/trash/mod.rs b/frontend/rust-lib/flowy-folder/src/entities/parser/trash/mod.rs similarity index 100% rename from shared-lib/flowy-folder-data-model/src/parser/trash/mod.rs rename to frontend/rust-lib/flowy-folder/src/entities/parser/trash/mod.rs diff --git a/shared-lib/flowy-folder-data-model/src/parser/trash/trash_id.rs b/frontend/rust-lib/flowy-folder/src/entities/parser/trash/trash_id.rs similarity index 93% rename from shared-lib/flowy-folder-data-model/src/parser/trash/trash_id.rs rename to frontend/rust-lib/flowy-folder/src/entities/parser/trash/trash_id.rs index 3b1c0646b2..2b629e33ec 100644 --- a/shared-lib/flowy-folder-data-model/src/parser/trash/trash_id.rs +++ b/frontend/rust-lib/flowy-folder/src/entities/parser/trash/trash_id.rs @@ -2,6 +2,7 @@ pub struct TrashIdentify(pub String); impl TrashIdentify { + #[allow(dead_code)] pub fn parse(s: String) -> Result { if s.trim().is_empty() { return Err("Trash id can not be empty or whitespace".to_string()); @@ -21,6 +22,7 @@ impl AsRef for TrashIdentify { pub struct TrashIds(pub Vec); impl TrashIds { + #[allow(dead_code)] pub fn parse(ids: Vec) -> Result { let mut trash_ids = vec![]; for id in ids { diff --git a/shared-lib/flowy-folder-data-model/src/parser/view/mod.rs b/frontend/rust-lib/flowy-folder/src/entities/parser/view/mod.rs similarity index 67% rename from shared-lib/flowy-folder-data-model/src/parser/view/mod.rs rename to frontend/rust-lib/flowy-folder/src/entities/parser/view/mod.rs index 39d7b2385a..399cc44c45 100644 --- a/shared-lib/flowy-folder-data-model/src/parser/view/mod.rs +++ b/frontend/rust-lib/flowy-folder/src/entities/parser/view/mod.rs @@ -1,13 +1,9 @@ -mod delta_data; mod view_desc; -mod view_ext; mod view_id; mod view_name; mod view_thumbnail; -pub use delta_data::*; pub use view_desc::*; -pub use view_ext::*; pub use view_id::*; pub use view_name::*; pub use view_thumbnail::*; diff --git a/shared-lib/flowy-folder-data-model/src/parser/view/view_desc.rs b/frontend/rust-lib/flowy-folder/src/entities/parser/view/view_desc.rs similarity index 100% rename from shared-lib/flowy-folder-data-model/src/parser/view/view_desc.rs rename to frontend/rust-lib/flowy-folder/src/entities/parser/view/view_desc.rs diff --git a/shared-lib/flowy-folder-data-model/src/parser/view/view_id.rs b/frontend/rust-lib/flowy-folder/src/entities/parser/view/view_id.rs similarity index 100% rename from shared-lib/flowy-folder-data-model/src/parser/view/view_id.rs rename to frontend/rust-lib/flowy-folder/src/entities/parser/view/view_id.rs diff --git a/shared-lib/flowy-folder-data-model/src/parser/view/view_name.rs b/frontend/rust-lib/flowy-folder/src/entities/parser/view/view_name.rs similarity index 100% rename from shared-lib/flowy-folder-data-model/src/parser/view/view_name.rs rename to frontend/rust-lib/flowy-folder/src/entities/parser/view/view_name.rs diff --git a/shared-lib/flowy-folder-data-model/src/parser/view/view_thumbnail.rs b/frontend/rust-lib/flowy-folder/src/entities/parser/view/view_thumbnail.rs similarity index 100% rename from shared-lib/flowy-folder-data-model/src/parser/view/view_thumbnail.rs rename to frontend/rust-lib/flowy-folder/src/entities/parser/view/view_thumbnail.rs diff --git a/shared-lib/flowy-folder-data-model/src/parser/workspace/mod.rs b/frontend/rust-lib/flowy-folder/src/entities/parser/workspace/mod.rs similarity index 100% rename from shared-lib/flowy-folder-data-model/src/parser/workspace/mod.rs rename to frontend/rust-lib/flowy-folder/src/entities/parser/workspace/mod.rs diff --git a/shared-lib/flowy-folder-data-model/src/parser/workspace/workspace_desc.rs b/frontend/rust-lib/flowy-folder/src/entities/parser/workspace/workspace_desc.rs similarity index 100% rename from shared-lib/flowy-folder-data-model/src/parser/workspace/workspace_desc.rs rename to frontend/rust-lib/flowy-folder/src/entities/parser/workspace/workspace_desc.rs diff --git a/shared-lib/flowy-folder-data-model/src/parser/workspace/workspace_id.rs b/frontend/rust-lib/flowy-folder/src/entities/parser/workspace/workspace_id.rs similarity index 100% rename from shared-lib/flowy-folder-data-model/src/parser/workspace/workspace_id.rs rename to frontend/rust-lib/flowy-folder/src/entities/parser/workspace/workspace_id.rs diff --git a/shared-lib/flowy-folder-data-model/src/parser/workspace/workspace_name.rs b/frontend/rust-lib/flowy-folder/src/entities/parser/workspace/workspace_name.rs similarity index 100% rename from shared-lib/flowy-folder-data-model/src/parser/workspace/workspace_name.rs rename to frontend/rust-lib/flowy-folder/src/entities/parser/workspace/workspace_name.rs diff --git a/shared-lib/flowy-folder-data-model/src/entities/trash.rs b/frontend/rust-lib/flowy-folder/src/entities/trash.rs similarity index 55% rename from shared-lib/flowy-folder-data-model/src/entities/trash.rs rename to frontend/rust-lib/flowy-folder/src/entities/trash.rs index 68b3d0a26e..c332dded18 100644 --- a/shared-lib/flowy-folder-data-model/src/entities/trash.rs +++ b/frontend/rust-lib/flowy-folder/src/entities/trash.rs @@ -1,6 +1,6 @@ use crate::impl_def_and_def_mut; -use crate::revision::TrashRevision; use flowy_derive::{ProtoBuf, ProtoBuf_Enum}; +use flowy_folder_data_model::revision::{TrashRevision, TrashTypeRevision}; use serde::{Deserialize, Serialize}; use std::fmt::Formatter; @@ -22,6 +22,29 @@ pub struct Trash { pub ty: TrashType, } +impl std::convert::From for Trash { + fn from(trash_rev: TrashRevision) -> Self { + Trash { + id: trash_rev.id, + name: trash_rev.name, + modified_time: trash_rev.modified_time, + create_time: trash_rev.create_time, + ty: trash_rev.ty.into(), + } + } +} + +impl std::convert::From for TrashRevision { + fn from(trash: Trash) -> Self { + TrashRevision { + id: trash.id, + name: trash.name, + modified_time: trash.modified_time, + create_time: trash.create_time, + ty: trash.ty.into(), + } + } +} #[derive(PartialEq, Debug, Default, ProtoBuf, Clone)] pub struct RepeatedTrash { #[pb(index = 1)] @@ -29,10 +52,16 @@ pub struct RepeatedTrash { } impl_def_and_def_mut!(RepeatedTrash, Trash); +impl std::convert::From> for RepeatedTrash { + fn from(trash_revs: Vec) -> Self { + let items: Vec = trash_revs.into_iter().map(|trash_rev| trash_rev.into()).collect(); + RepeatedTrash { items } + } +} #[derive(Eq, PartialEq, Debug, ProtoBuf_Enum, Clone, Serialize, Deserialize)] pub enum TrashType { - Unknown = 0, + TrashUnknown = 0, TrashView = 1, TrashApp = 2, } @@ -42,7 +71,7 @@ impl std::convert::TryFrom for TrashType { fn try_from(value: i32) -> Result { match value { - 0 => Ok(TrashType::Unknown), + 0 => Ok(TrashType::TrashUnknown), 1 => Ok(TrashType::TrashView), 2 => Ok(TrashType::TrashApp), _ => Err(format!("Invalid trash type: {}", value)), @@ -50,9 +79,29 @@ impl std::convert::TryFrom for TrashType { } } +impl std::convert::From for TrashType { + fn from(rev: TrashTypeRevision) -> Self { + match rev { + TrashTypeRevision::Unknown => TrashType::TrashUnknown, + TrashTypeRevision::TrashView => TrashType::TrashView, + TrashTypeRevision::TrashApp => TrashType::TrashApp, + } + } +} + +impl std::convert::From for TrashTypeRevision { + fn from(rev: TrashType) -> Self { + match rev { + TrashType::TrashUnknown => TrashTypeRevision::Unknown, + TrashType::TrashView => TrashTypeRevision::TrashView, + TrashType::TrashApp => TrashTypeRevision::TrashApp, + } + } +} + impl std::default::Default for TrashType { fn default() -> Self { - TrashType::Unknown + TrashType::TrashUnknown } } @@ -96,7 +145,10 @@ impl std::convert::From> for RepeatedTrashId { fn from(trash: Vec) -> Self { let items = trash .into_iter() - .map(|t| TrashId { id: t.id, ty: t.ty }) + .map(|t| TrashId { + id: t.id, + ty: t.ty.into(), + }) .collect::>(); RepeatedTrashId { @@ -120,3 +172,12 @@ impl std::fmt::Display for TrashId { f.write_str(&format!("{:?}:{}", self.ty, self.id)) } } + +impl std::convert::From<&TrashRevision> for TrashId { + fn from(trash: &TrashRevision) -> Self { + TrashId { + id: trash.id.clone(), + ty: trash.ty.clone().into(), + } + } +} diff --git a/shared-lib/flowy-folder-data-model/src/entities/view.rs b/frontend/rust-lib/flowy-folder/src/entities/view.rs similarity index 84% rename from shared-lib/flowy-folder-data-model/src/entities/view.rs rename to frontend/rust-lib/flowy-folder/src/entities/view.rs index 445aa6544a..ca54ec8cff 100644 --- a/shared-lib/flowy-folder-data-model/src/entities/view.rs +++ b/frontend/rust-lib/flowy-folder/src/entities/view.rs @@ -1,20 +1,15 @@ use crate::{ - errors::ErrorCode, - impl_def_and_def_mut, - parser::{ + entities::parser::{ app::AppIdentify, view::{ViewDesc, ViewIdentify, ViewName, ViewThumbnail}, }, + errors::ErrorCode, + impl_def_and_def_mut, }; use flowy_derive::{ProtoBuf, ProtoBuf_Enum}; -use nanoid::nanoid; -use serde_repr::*; +use flowy_folder_data_model::revision::{gen_view_id, ViewDataTypeRevision, ViewRevision}; use std::convert::TryInto; -pub fn gen_view_id() -> String { - nanoid!(10) -} - #[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)] pub struct View { #[pb(index = 1)] @@ -39,8 +34,21 @@ pub struct View { pub plugin_type: i32, } -#[derive(Eq, PartialEq, Hash, Debug, ProtoBuf_Enum, Clone, Serialize_repr, Deserialize_repr)] -#[repr(u8)] +impl std::convert::From for View { + fn from(rev: ViewRevision) -> Self { + View { + id: rev.id, + belong_to_id: rev.belong_to_id, + name: rev.name, + data_type: rev.data_type.into(), + modified_time: rev.modified_time, + create_time: rev.create_time, + plugin_type: rev.plugin_type, + } + } +} + +#[derive(Eq, PartialEq, Hash, Debug, ProtoBuf_Enum, Clone)] pub enum ViewDataType { TextBlock = 0, Grid = 1, @@ -48,19 +56,24 @@ pub enum ViewDataType { impl std::default::Default for ViewDataType { fn default() -> Self { - ViewDataType::TextBlock + ViewDataTypeRevision::default().into() } } -impl std::convert::From for ViewDataType { - fn from(val: i32) -> Self { - match val { - 0 => ViewDataType::TextBlock, - 1 => ViewDataType::Grid, - _ => { - log::error!("Invalid view type: {}", val); - ViewDataType::TextBlock - } +impl std::convert::From for ViewDataType { + fn from(rev: ViewDataTypeRevision) -> Self { + match rev { + ViewDataTypeRevision::TextBlock => ViewDataType::TextBlock, + ViewDataTypeRevision::Grid => ViewDataType::Grid, + } + } +} + +impl std::convert::From for ViewDataTypeRevision { + fn from(ty: ViewDataType) -> Self { + match ty { + ViewDataType::TextBlock => ViewDataTypeRevision::TextBlock, + ViewDataType::Grid => ViewDataTypeRevision::Grid, } } } @@ -73,6 +86,12 @@ pub struct RepeatedView { impl_def_and_def_mut!(RepeatedView, View); +impl std::convert::From> for RepeatedView { + fn from(values: Vec) -> Self { + let items = values.into_iter().map(|value| value.into()).collect::>(); + RepeatedView { items } + } +} #[derive(Default, ProtoBuf)] pub struct RepeatedViewId { #[pb(index = 1)] diff --git a/shared-lib/flowy-folder-data-model/src/entities/view_info.rs b/frontend/rust-lib/flowy-folder/src/entities/view_info.rs similarity index 100% rename from shared-lib/flowy-folder-data-model/src/entities/view_info.rs rename to frontend/rust-lib/flowy-folder/src/entities/view_info.rs diff --git a/shared-lib/flowy-folder-data-model/src/entities/workspace.rs b/frontend/rust-lib/flowy-folder/src/entities/workspace.rs similarity index 83% rename from shared-lib/flowy-folder-data-model/src/entities/workspace.rs rename to frontend/rust-lib/flowy-folder/src/entities/workspace.rs index 66f11ab9b0..a9f61b50c8 100644 --- a/shared-lib/flowy-folder-data-model/src/entities/workspace.rs +++ b/frontend/rust-lib/flowy-folder/src/entities/workspace.rs @@ -1,17 +1,13 @@ use crate::{ + entities::parser::workspace::{WorkspaceDesc, WorkspaceIdentify, WorkspaceName}, entities::{app::RepeatedApp, view::View}, errors::*, impl_def_and_def_mut, - parser::workspace::{WorkspaceDesc, WorkspaceIdentify, WorkspaceName}, }; use flowy_derive::ProtoBuf; -use nanoid::nanoid; - +use flowy_folder_data_model::revision::WorkspaceRevision; use std::convert::TryInto; -pub fn gen_workspace_id() -> String { - nanoid!(10) -} #[derive(Eq, PartialEq, ProtoBuf, Default, Debug, Clone)] pub struct Workspace { #[pb(index = 1)] @@ -33,6 +29,18 @@ pub struct Workspace { pub create_time: i64, } +impl std::convert::From for Workspace { + fn from(workspace_serde: WorkspaceRevision) -> Self { + Workspace { + id: workspace_serde.id, + name: workspace_serde.name, + desc: workspace_serde.desc, + apps: workspace_serde.apps.into(), + modified_time: workspace_serde.modified_time, + create_time: workspace_serde.create_time, + } + } +} #[derive(PartialEq, Debug, Default, ProtoBuf)] pub struct RepeatedWorkspace { #[pb(index = 1)] diff --git a/frontend/rust-lib/flowy-folder/src/lib.rs b/frontend/rust-lib/flowy-folder/src/lib.rs index 0137664274..5b7e625b0c 100644 --- a/frontend/rust-lib/flowy-folder/src/lib.rs +++ b/frontend/rust-lib/flowy-folder/src/lib.rs @@ -1,4 +1,4 @@ -pub use flowy_folder_data_model::entities; +pub mod entities; pub mod event_map; pub mod services; @@ -14,8 +14,6 @@ pub mod protobuf; mod util; pub mod prelude { - pub use flowy_folder_data_model::entities::{app::*, trash::*, view::*, workspace::*}; - pub use crate::{errors::*, event_map::*}; } diff --git a/frontend/rust-lib/flowy-folder/src/manager.rs b/frontend/rust-lib/flowy-folder/src/manager.rs index f2b871475d..b6555035d3 100644 --- a/frontend/rust-lib/flowy-folder/src/manager.rs +++ b/frontend/rust-lib/flowy-folder/src/manager.rs @@ -1,3 +1,4 @@ +use crate::entities::view::ViewDataType; use crate::{ dart_notification::{send_dart_notification, FolderNotification}, entities::workspace::RepeatedWorkspace, @@ -10,7 +11,6 @@ use crate::{ }; use bytes::Bytes; use flowy_error::FlowyError; -use flowy_folder_data_model::entities::view::ViewDataType; use flowy_folder_data_model::user_default; use flowy_revision::disk::SQLiteTextBlockRevisionPersistence; use flowy_revision::{RevisionManager, RevisionPersistence, RevisionWebSocket}; diff --git a/frontend/rust-lib/flowy-folder/src/services/persistence/version_1/trash_sql.rs b/frontend/rust-lib/flowy-folder/src/services/persistence/version_1/trash_sql.rs index c4f6fff365..2e69a4ba1c 100644 --- a/frontend/rust-lib/flowy-folder/src/services/persistence/version_1/trash_sql.rs +++ b/frontend/rust-lib/flowy-folder/src/services/persistence/version_1/trash_sql.rs @@ -1,14 +1,11 @@ -use crate::{ - entities::trash::{Trash, TrashType}, - errors::FlowyError, -}; +use crate::errors::FlowyError; use diesel::sql_types::Integer; use flowy_database::{ prelude::*, schema::{trash_table, trash_table::dsl}, SqliteConnection, }; -use flowy_folder_data_model::revision::TrashRevision; +use flowy_folder_data_model::revision::{TrashRevision, TrashTypeRevision}; pub struct TrashTableSql(); impl TrashTableSql { @@ -64,18 +61,18 @@ pub(crate) struct TrashTable { pub create_time: i64, pub ty: SqlTrashType, } -impl std::convert::From for Trash { - fn from(table: TrashTable) -> Self { - Trash { - id: table.id, - name: table.name, - modified_time: table.modified_time, - create_time: table.create_time, - ty: table.ty.into(), - } - } -} - +// impl std::convert::From for Trash { +// fn from(table: TrashTable) -> Self { +// Trash { +// id: table.id, +// name: table.name, +// modified_time: table.modified_time, +// create_time: table.create_time, +// ty: table.ty.into(), +// } +// } +// } +// impl std::convert::From for TrashRevision { fn from(trash: TrashTable) -> Self { TrashRevision { @@ -141,22 +138,22 @@ impl std::convert::From for SqlTrashType { impl_sql_integer_expression!(SqlTrashType); -impl std::convert::From for TrashType { +impl std::convert::From for TrashTypeRevision { fn from(ty: SqlTrashType) -> Self { match ty { - SqlTrashType::Unknown => TrashType::Unknown, - SqlTrashType::View => TrashType::TrashView, - SqlTrashType::App => TrashType::TrashApp, + SqlTrashType::Unknown => TrashTypeRevision::Unknown, + SqlTrashType::View => TrashTypeRevision::TrashView, + SqlTrashType::App => TrashTypeRevision::TrashApp, } } } -impl std::convert::From for SqlTrashType { - fn from(ty: TrashType) -> Self { +impl std::convert::From for SqlTrashType { + fn from(ty: TrashTypeRevision) -> Self { match ty { - TrashType::Unknown => SqlTrashType::Unknown, - TrashType::TrashView => SqlTrashType::View, - TrashType::TrashApp => SqlTrashType::App, + TrashTypeRevision::Unknown => SqlTrashType::Unknown, + TrashTypeRevision::TrashView => SqlTrashType::View, + TrashTypeRevision::TrashApp => SqlTrashType::App, } } } 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 08c96ac90c..ec1bbf38bf 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,7 +1,7 @@ use crate::{ entities::{ trash::{Trash, TrashType}, - view::{UpdateViewParams, ViewDataType}, + view::UpdateViewParams, }, errors::FlowyError, services::persistence::version_1::app_sql::AppTable, @@ -13,7 +13,7 @@ use flowy_database::{ SqliteConnection, }; -use flowy_folder_data_model::revision::ViewRevision; +use flowy_folder_data_model::revision::{ViewDataTypeRevision, ViewRevision}; use lib_infra::util::timestamp; pub struct ViewTableSql(); @@ -87,8 +87,8 @@ pub(crate) struct ViewTable { impl ViewTable { pub fn new(view_rev: ViewRevision) -> Self { let data_type = match view_rev.data_type { - ViewDataType::TextBlock => SqlViewDataType::Block, - ViewDataType::Grid => SqlViewDataType::Grid, + ViewDataTypeRevision::TextBlock => SqlViewDataType::Block, + ViewDataTypeRevision::Grid => SqlViewDataType::Grid, }; ViewTable { @@ -110,8 +110,8 @@ impl ViewTable { impl std::convert::From for ViewRevision { fn from(table: ViewTable) -> Self { let data_type = match table.view_type { - SqlViewDataType::Block => ViewDataType::TextBlock, - SqlViewDataType::Grid => ViewDataType::Grid, + SqlViewDataType::Block => ViewDataTypeRevision::TextBlock, + SqlViewDataType::Grid => ViewDataTypeRevision::Grid, }; ViewRevision { 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 5fe144e81f..134e8a0d84 100644 --- a/frontend/rust-lib/flowy-folder/src/services/trash/controller.rs +++ b/frontend/rust-lib/flowy-folder/src/services/trash/controller.rs @@ -51,7 +51,7 @@ impl TrashController { let identifier = TrashId { id: trash.id, - ty: trash.ty, + ty: trash.ty.into(), }; let _ = self.delete_trash_on_server(RepeatedTrashId { 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 1491373b20..d573b096f6 100644 --- a/frontend/rust-lib/flowy-folder/src/services/view/controller.rs +++ b/frontend/rust-lib/flowy-folder/src/services/view/controller.rs @@ -1,3 +1,5 @@ +pub use crate::entities::view::ViewDataType; +use crate::entities::ViewInfo; use crate::manager::{ViewDataProcessor, ViewDataProcessorMap}; use crate::{ dart_notification::{send_dart_notification, FolderNotification}, @@ -14,9 +16,7 @@ use crate::{ }; use bytes::Bytes; use flowy_database::kv::KV; -use flowy_folder_data_model::entities::view::{gen_view_id, ViewDataType}; -use flowy_folder_data_model::entities::ViewInfo; -use flowy_folder_data_model::revision::ViewRevision; +use flowy_folder_data_model::revision::{gen_view_id, ViewRevision}; use flowy_sync::entities::text_block::TextBlockId; use futures::{FutureExt, StreamExt}; use std::{collections::HashSet, sync::Arc}; @@ -58,7 +58,7 @@ impl ViewController { &self, mut params: CreateViewParams, ) -> Result { - let processor = self.get_data_processor(¶ms.data_type)?; + let processor = self.get_data_processor(params.data_type.clone())?; let user_id = self.user.user_id()?; if params.data.is_empty() { let view_data = processor.create_default_view(&user_id, ¶ms.view_id).await?; @@ -88,7 +88,7 @@ impl ViewController { return Err(FlowyError::internal().context("The content of the view should not be empty")); } let user_id = self.user.user_id()?; - let processor = self.get_data_processor(&data_type)?; + let processor = self.get_data_processor(data_type)?; let _ = processor.create_container(&user_id, view_id, delta_data).await?; Ok(()) } @@ -140,7 +140,7 @@ impl ViewController { belong_to_id: view_rev.belong_to_id, name: view_rev.name, desc: view_rev.desc, - data_type: view_rev.data_type, + data_type: view_rev.data_type.into(), belongings: RepeatedView { items }, ext_data: view_rev.ext_data, }; @@ -209,14 +209,14 @@ impl ViewController { .begin_transaction(|transaction| transaction.read_view(view_id)) .await?; - let processor = self.get_data_processor(&view_rev.data_type)?; + let processor = self.get_data_processor(view_rev.data_type.clone())?; let delta_bytes = processor.get_delta_data(view_id).await?; let duplicate_params = CreateViewParams { belong_to_id: view_rev.belong_to_id.clone(), name: format!("{} (copy)", &view_rev.name), desc: view_rev.desc, thumbnail: view_rev.thumbnail, - data_type: view_rev.data_type, + data_type: view_rev.data_type.into(), data: delta_bytes.to_vec(), view_id: gen_view_id(), plugin_type: view_rev.plugin_type, @@ -360,12 +360,16 @@ impl ViewController { .persistence .begin_transaction(|transaction| transaction.read_view(view_id)) .await?; - self.get_data_processor(&view.data_type) + self.get_data_processor(view.data_type) } #[inline] - fn get_data_processor(&self, data_type: &ViewDataType) -> FlowyResult> { - match self.data_processors.get(data_type) { + fn get_data_processor>( + &self, + data_type: T, + ) -> FlowyResult> { + let data_type = data_type.into(); + match self.data_processors.get(&data_type) { None => Err(FlowyError::internal().context(format!( "Get data processor failed. Unknown view data type: {:?}", data_type @@ -429,7 +433,8 @@ async fn handle_trash_event( .await?; for view in views { - match get_data_processor(data_processors.clone(), &view.data_type) { + let data_type = view.data_type.clone().into(); + match get_data_processor(data_processors.clone(), &data_type) { Ok(processor) => { let _ = processor.close_container(&view.id).await?; } 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 cfacc23e0e..f970905f30 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,3 +1,5 @@ +use crate::entities::view::{MoveFolderItemParams, MoveFolderItemPayload, MoveFolderItemType}; +use crate::entities::ViewInfo; use crate::manager::FolderManager; use crate::services::{notify_workspace_setting_did_change, AppController}; use crate::{ @@ -10,8 +12,6 @@ use crate::{ errors::FlowyError, services::{TrashController, ViewController}, }; -use flowy_folder_data_model::entities::view::{MoveFolderItemParams, MoveFolderItemPayload, MoveFolderItemType}; -use flowy_folder_data_model::entities::ViewInfo; use flowy_folder_data_model::revision::TrashRevision; use lib_dispatch::prelude::{data_result, AppData, Data, DataResult}; use std::{convert::TryInto, sync::Arc}; 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 f1b4ab5289..9863cafdc5 100644 --- a/frontend/rust-lib/flowy-folder/src/services/workspace/controller.rs +++ b/frontend/rust-lib/flowy-folder/src/services/workspace/controller.rs @@ -1,3 +1,4 @@ +use crate::entities::workspace::*; use crate::manager::FolderManager; use crate::{ dart_notification::*, @@ -9,7 +10,6 @@ use crate::{ }, }; use flowy_database::kv::KV; -use flowy_folder_data_model::entities::workspace::*; use flowy_folder_data_model::revision::{AppRevision, WorkspaceRevision}; use std::sync::Arc; 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 3760d06bf6..02fb37a12b 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,14 +1,14 @@ +use crate::entities::{ + app::RepeatedApp, + view::View, + workspace::{CurrentWorkspaceSetting, RepeatedWorkspace, WorkspaceId, *}, +}; use crate::{ dart_notification::{send_dart_notification, FolderNotification}, errors::FlowyError, manager::FolderManager, services::{get_current_workspace, read_local_workspace_apps, WorkspaceController}, }; -use flowy_folder_data_model::entities::{ - app::RepeatedApp, - view::View, - workspace::{CurrentWorkspaceSetting, RepeatedWorkspace, WorkspaceId, *}, -}; use lib_dispatch::prelude::{data_result, AppData, Data, DataResult}; use std::{convert::TryInto, sync::Arc}; 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 9eaee19b61..86c3dc7478 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_data_model::entities::view::ViewDataType; use flowy_revision::disk::RevisionState; use flowy_test::{event_builder::*, FlowySDKTest}; diff --git a/frontend/rust-lib/flowy-folder/tests/workspace/script.rs b/frontend/rust-lib/flowy-folder/tests/workspace/script.rs index 5d62e31d9e..b461730cf9 100644 --- a/frontend/rust-lib/flowy-folder/tests/workspace/script.rs +++ b/frontend/rust-lib/flowy-folder/tests/workspace/script.rs @@ -1,19 +1,19 @@ -use flowy_folder::event_map::FolderEvent::*; -use flowy_folder::{errors::ErrorCode, services::folder_editor::FolderEditor}; -use flowy_folder_data_model::entities::view::{RepeatedViewId, ViewId}; -use flowy_folder_data_model::entities::workspace::WorkspaceId; -use flowy_folder_data_model::entities::{ +use flowy_folder::entities::view::{RepeatedViewId, ViewId}; +use flowy_folder::entities::workspace::WorkspaceId; +use flowy_folder::entities::{ app::{App, RepeatedApp}, trash::Trash, view::{RepeatedView, View, ViewDataType}, workspace::Workspace, }; -use flowy_folder_data_model::entities::{ +use flowy_folder::entities::{ app::{AppId, CreateAppPayload, UpdateAppPayload}, trash::{RepeatedTrash, TrashId, TrashType}, view::{CreateViewPayload, UpdateViewPayload}, workspace::{CreateWorkspacePayload, RepeatedWorkspace}, }; +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; @@ -205,7 +205,7 @@ impl FolderTest { restore_view_from_trash(sdk, &self.view.id).await; } FolderScript::ReadTrash => { - let trash = read_trash(sdk).await; + let mut trash = read_trash(sdk).await; self.trash = trash.into_inner(); } FolderScript::DeleteAllTrash => { @@ -264,7 +264,7 @@ pub async fn create_workspace(sdk: &FlowySDKTest, name: &str, desc: &str) -> Wor pub async fn read_workspace(sdk: &FlowySDKTest, workspace_id: Option) -> Vec { let request = WorkspaceId { value: workspace_id }; - let repeated_workspace = FolderEventBuilder::new(sdk.clone()) + let mut repeated_workspace = FolderEventBuilder::new(sdk.clone()) .event(ReadWorkspaces) .payload(request.clone()) .async_send() 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 9781ea727a..788f7fa462 100644 --- a/frontend/rust-lib/flowy-net/src/http_server/folder.rs +++ b/frontend/rust-lib/flowy-net/src/http_server/folder.rs @@ -3,7 +3,7 @@ use crate::{ request::{HttpRequestBuilder, ResponseMiddleware}, }; use flowy_error::FlowyError; -use flowy_folder_data_model::entities::{ +use flowy_folder::entities::{ trash::RepeatedTrashId, view::{CreateViewParams, RepeatedViewId, UpdateViewParams, ViewId}, workspace::{CreateWorkspaceParams, UpdateWorkspaceParams, WorkspaceId}, 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 79a9a1963b..ec7b9db0cd 100644 --- a/frontend/rust-lib/flowy-net/src/local_server/server.rs +++ b/frontend/rust-lib/flowy-net/src/local_server/server.rs @@ -252,15 +252,15 @@ impl RevisionUser for LocalRevisionUser { } } -use flowy_folder_data_model::entities::app::gen_app_id; -use flowy_folder_data_model::entities::workspace::gen_workspace_id; -use flowy_folder_data_model::entities::{ +use flowy_folder::entities::{ app::{AppId, CreateAppParams, UpdateAppParams}, trash::RepeatedTrashId, view::{CreateViewParams, RepeatedViewId, UpdateViewParams, ViewId}, workspace::{CreateWorkspaceParams, UpdateWorkspaceParams, WorkspaceId}, }; -use flowy_folder_data_model::revision::{AppRevision, TrashRevision, ViewRevision, WorkspaceRevision}; +use flowy_folder_data_model::revision::{ + gen_app_id, gen_workspace_id, AppRevision, TrashRevision, ViewRevision, WorkspaceRevision, +}; use flowy_text_block::BlockCloudService; use flowy_user::event_map::UserCloudService; use flowy_user_data_model::entities::{ @@ -308,7 +308,7 @@ impl FolderCouldServiceV1 for LocalServer { belong_to_id: params.belong_to_id, name: params.name, desc: params.desc, - data_type: params.data_type, + data_type: params.data_type.into(), version: 0, belongings: vec![], modified_time: time, diff --git a/frontend/rust-lib/flowy-sdk/src/deps_resolve/folder_deps.rs b/frontend/rust-lib/flowy-sdk/src/deps_resolve/folder_deps.rs index f1257dc3ad..24bb71d89c 100644 --- a/frontend/rust-lib/flowy-sdk/src/deps_resolve/folder_deps.rs +++ b/frontend/rust-lib/flowy-sdk/src/deps_resolve/folder_deps.rs @@ -1,7 +1,7 @@ use bytes::Bytes; use flowy_database::ConnectionPool; +use flowy_folder::entities::ViewDataType; use flowy_folder::manager::{ViewDataProcessor, ViewDataProcessorMap}; -use flowy_folder::prelude::ViewDataType; use flowy_folder::{ errors::{internal_error, FlowyError}, event_map::{FolderCouldServiceV1, WorkspaceDatabase, WorkspaceUser}, diff --git a/frontend/rust-lib/flowy-test/src/helper.rs b/frontend/rust-lib/flowy-test/src/helper.rs index 2bb9622914..efc4282386 100644 --- a/frontend/rust-lib/flowy-test/src/helper.rs +++ b/frontend/rust-lib/flowy-test/src/helper.rs @@ -1,5 +1,5 @@ use crate::prelude::*; -use flowy_folder::prelude::WorkspaceId; +use flowy_folder::entities::WorkspaceId; use flowy_folder::{ entities::{ app::*, 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 0db37ea984..c635f326c1 100644 --- a/frontend/rust-lib/flowy-user/src/handlers/user_handler.rs +++ b/frontend/rust-lib/flowy-user/src/handlers/user_handler.rs @@ -20,7 +20,7 @@ pub async fn check_user_handler(session: AppData>) -> DataResul #[tracing::instrument(level = "debug", skip(session))] pub async fn get_user_profile_handler(session: AppData>) -> DataResult { - let user_profile = session.user_profile().await?; + let user_profile = session.get_user_profile().await?; data_result(user_profile) } 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 97b3d3f5c5..8167b05a19 100644 --- a/frontend/rust-lib/flowy-user/src/services/user_session.rs +++ b/frontend/rust-lib/flowy-user/src/services/user_session.rs @@ -82,7 +82,7 @@ impl UserSession { #[tracing::instrument(level = "debug", skip(self))] pub async fn sign_in(&self, params: SignInParams) -> Result { if self.is_user_login(¶ms.email) { - self.user_profile().await + self.get_user_profile().await } else { let resp = self.cloud_service.sign_in(params).await?; let session: Session = resp.clone().into(); @@ -97,7 +97,7 @@ impl UserSession { #[tracing::instrument(level = "debug", skip(self))] pub async fn sign_up(&self, params: SignUpParams) -> Result { if self.is_user_login(¶ms.email) { - self.user_profile().await + self.get_user_profile().await } else { let resp = self.cloud_service.sign_up(params).await?; let session: Session = resp.clone().into(); @@ -131,6 +131,10 @@ impl UserSession { let changeset = UserTableChangeset::new(params.clone()); diesel_update_table!(user_table, changeset, &*self.db_connection()?); + let user_profile = self.get_user_profile().await?; + dart_notify(&session.token, UserNotification::UserProfileUpdated) + .payload(user_profile) + .send(); let _ = self.update_user_on_server(&session.token, params).await?; Ok(()) } @@ -150,7 +154,7 @@ impl UserSession { Ok(user.into()) } - pub async fn 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)) @@ -179,23 +183,23 @@ impl UserSession { } impl UserSession { - fn read_user_profile_on_server(&self, token: &str) -> Result<(), FlowyError> { - let server = self.cloud_service.clone(); - let token = token.to_owned(); - tokio::spawn(async move { - match server.get_user(&token).await { - Ok(profile) => { - dart_notify(&token, UserNotification::UserProfileUpdated) - .payload(profile) - .send(); - } - Err(e) => { - dart_notify(&token, UserNotification::UserProfileUpdated) - .error(e) - .send(); - } - } - }); + fn read_user_profile_on_server(&self, _token: &str) -> Result<(), FlowyError> { + // let server = self.cloud_service.clone(); + // let token = token.to_owned(); + // tokio::spawn(async move { + // match server.get_user(&token).await { + // Ok(profile) => { + // dart_notify(&token, UserNotification::UserProfileUpdated) + // .payload(profile) + // .send(); + // } + // Err(e) => { + // dart_notify(&token, UserNotification::UserProfileUpdated) + // .error(e) + // .send(); + // } + // } + // }); Ok(()) } diff --git a/shared-lib/flowy-folder-data-model/Flowy.toml b/shared-lib/flowy-folder-data-model/Flowy.toml deleted file mode 100644 index e98441c877..0000000000 --- a/shared-lib/flowy-folder-data-model/Flowy.toml +++ /dev/null @@ -1,2 +0,0 @@ -# Check out the FlowyConfig (located in flowy_toml.rs) for more details. -proto_input = ["src/entities",] diff --git a/shared-lib/flowy-folder-data-model/build.rs b/shared-lib/flowy-folder-data-model/build.rs deleted file mode 100644 index e897c3690d..0000000000 --- a/shared-lib/flowy-folder-data-model/build.rs +++ /dev/null @@ -1,5 +0,0 @@ -use lib_infra::code_gen; - -fn main() { - code_gen::protobuf_file::gen(env!("CARGO_PKG_NAME")); -} diff --git a/shared-lib/flowy-folder-data-model/src/lib.rs b/shared-lib/flowy-folder-data-model/src/lib.rs index e1f796b672..783eab5f75 100644 --- a/shared-lib/flowy-folder-data-model/src/lib.rs +++ b/shared-lib/flowy-folder-data-model/src/lib.rs @@ -1,11 +1,6 @@ -pub mod entities; -pub mod parser; - #[macro_use] mod macros; -// #[cfg(feature = "backend")] -pub mod protobuf; pub mod revision; pub mod user_default; diff --git a/shared-lib/flowy-folder-data-model/src/parser/view/delta_data.rs b/shared-lib/flowy-folder-data-model/src/parser/view/delta_data.rs deleted file mode 100644 index 00986383b7..0000000000 --- a/shared-lib/flowy-folder-data-model/src/parser/view/delta_data.rs +++ /dev/null @@ -1,10 +0,0 @@ -#[derive(Debug)] -pub struct DeltaData(pub Vec); - -impl DeltaData { - pub fn parse(data: Vec) -> Result { - // let _ = Delta::from_bytes(data.clone()).map_err(|e| format!("{:?}", e))?; - - Ok(Self(data)) - } -} diff --git a/shared-lib/flowy-folder-data-model/src/parser/view/view_ext.rs b/shared-lib/flowy-folder-data-model/src/parser/view/view_ext.rs deleted file mode 100644 index 1bb48711bc..0000000000 --- a/shared-lib/flowy-folder-data-model/src/parser/view/view_ext.rs +++ /dev/null @@ -1,16 +0,0 @@ -use crate::errors::ErrorCode; - -#[derive(Debug)] -pub struct ViewExtensionData(pub String); - -impl ViewExtensionData { - pub fn parse(s: String) -> Result { - Ok(Self(s)) - } -} - -impl AsRef for ViewExtensionData { - fn as_ref(&self) -> &str { - &self.0 - } -} diff --git a/shared-lib/flowy-folder-data-model/src/revision/app_rev.rs b/shared-lib/flowy-folder-data-model/src/revision/app_rev.rs index 82b9af3812..015cb70427 100644 --- a/shared-lib/flowy-folder-data-model/src/revision/app_rev.rs +++ b/shared-lib/flowy-folder-data-model/src/revision/app_rev.rs @@ -1,8 +1,10 @@ -use crate::entities::app::App; -use crate::entities::{RepeatedApp, TrashType}; -use crate::revision::{TrashRevision, ViewRevision}; +use crate::revision::{TrashRevision, TrashTypeRevision, ViewRevision}; +use nanoid::nanoid; use serde::{Deserialize, Serialize}; +pub fn gen_app_id() -> String { + nanoid!(10) +} #[derive(Default, Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] pub struct AppRevision { pub id: String, @@ -22,21 +24,6 @@ pub struct AppRevision { pub create_time: i64, } -impl std::convert::From for App { - fn from(app_serde: AppRevision) -> Self { - App { - id: app_serde.id, - workspace_id: app_serde.workspace_id, - name: app_serde.name, - desc: app_serde.desc, - belongings: app_serde.belongings.into(), - version: app_serde.version, - modified_time: app_serde.modified_time, - create_time: app_serde.create_time, - } - } -} - impl std::convert::From for TrashRevision { fn from(app_rev: AppRevision) -> Self { TrashRevision { @@ -44,14 +31,7 @@ impl std::convert::From for TrashRevision { name: app_rev.name, modified_time: app_rev.modified_time, create_time: app_rev.create_time, - ty: TrashType::TrashApp, + ty: TrashTypeRevision::TrashApp, } } } - -impl std::convert::From> for RepeatedApp { - fn from(values: Vec) -> Self { - let items = values.into_iter().map(|value| value.into()).collect::>(); - RepeatedApp { items } - } -} diff --git a/shared-lib/flowy-folder-data-model/src/revision/trash_rev.rs b/shared-lib/flowy-folder-data-model/src/revision/trash_rev.rs index 08f3bb27a1..c72fc61dad 100644 --- a/shared-lib/flowy-folder-data-model/src/revision/trash_rev.rs +++ b/shared-lib/flowy-folder-data-model/src/revision/trash_rev.rs @@ -1,7 +1,7 @@ -use crate::entities::trash::{Trash, TrashType}; -use crate::entities::{RepeatedTrash, TrashId}; +use serde::de::Visitor; use serde::{Deserialize, Serialize}; - +use serde_repr::*; +use std::fmt; #[derive(Default, Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] pub struct TrashRevision { pub id: String, @@ -12,45 +12,122 @@ pub struct TrashRevision { pub create_time: i64, - pub ty: TrashType, + pub ty: TrashTypeRevision, } -impl std::convert::From> for RepeatedTrash { - fn from(trash_revs: Vec) -> Self { - let items: Vec = trash_revs.into_iter().map(|trash_rev| trash_rev.into()).collect(); - RepeatedTrash { items } +#[derive(Eq, PartialEq, Debug, Clone, Serialize_repr)] +#[repr(u8)] +pub enum TrashTypeRevision { + Unknown = 0, + TrashView = 1, + TrashApp = 2, +} +impl<'de> serde::Deserialize<'de> for TrashTypeRevision { + fn deserialize(deserializer: D) -> core::result::Result + where + D: serde::Deserializer<'de>, + { + struct TrashTypeVisitor(); + + impl<'de> Visitor<'de> for TrashTypeVisitor { + type Value = TrashTypeRevision; + + fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { + formatter.write_str("u8") + } + + fn visit_i8(self, v: i8) -> Result + where + E: serde::de::Error, + { + self.visit_u8(v as u8) + } + + fn visit_i16(self, v: i16) -> Result + where + E: serde::de::Error, + { + self.visit_u8(v as u8) + } + + fn visit_i32(self, v: i32) -> Result + where + E: serde::de::Error, + { + self.visit_u8(v as u8) + } + + fn visit_i64(self, v: i64) -> Result + where + E: serde::de::Error, + { + self.visit_u8(v as u8) + } + + fn visit_u8(self, v: u8) -> Result + where + E: serde::de::Error, + { + let ty = match v { + 0 => TrashTypeRevision::Unknown, + 1 => TrashTypeRevision::TrashView, + 2 => TrashTypeRevision::TrashApp, + _ => TrashTypeRevision::Unknown, + }; + + Ok(ty) + } + + fn visit_u16(self, v: u16) -> Result + where + E: serde::de::Error, + { + self.visit_u8(v as u8) + } + + fn visit_u32(self, v: u32) -> Result + where + E: serde::de::Error, + { + self.visit_u8(v as u8) + } + + fn visit_u64(self, v: u64) -> Result + where + E: serde::de::Error, + { + self.visit_u8(v as u8) + } + + fn visit_str(self, s: &str) -> Result + where + E: serde::de::Error, + { + let value = match s { + "Unknown" => TrashTypeRevision::Unknown, + "TrashView" => TrashTypeRevision::TrashView, + "TrashApp" => TrashTypeRevision::TrashApp, + _ => TrashTypeRevision::Unknown, + }; + Ok(value) + } + } + + deserializer.deserialize_any(TrashTypeVisitor()) + } +} +impl std::default::Default for TrashTypeRevision { + fn default() -> Self { + TrashTypeRevision::Unknown } } -impl std::convert::From for Trash { - fn from(trash_rev: TrashRevision) -> Self { - Trash { - id: trash_rev.id, - name: trash_rev.name, - modified_time: trash_rev.modified_time, - create_time: trash_rev.create_time, - ty: trash_rev.ty, - } - } -} - -impl std::convert::From for TrashRevision { - fn from(trash: Trash) -> Self { - TrashRevision { - id: trash.id, - name: trash.name, - modified_time: trash.modified_time, - create_time: trash.create_time, - ty: trash.ty, - } - } -} - -impl std::convert::From<&TrashRevision> for TrashId { - fn from(trash: &TrashRevision) -> Self { - TrashId { - id: trash.id.clone(), - ty: trash.ty.clone(), +impl std::convert::From for u8 { + fn from(rev: TrashTypeRevision) -> Self { + match rev { + TrashTypeRevision::Unknown => 0, + TrashTypeRevision::TrashView => 1, + TrashTypeRevision::TrashApp => 2, } } } diff --git a/shared-lib/flowy-folder-data-model/src/revision/view_rev.rs b/shared-lib/flowy-folder-data-model/src/revision/view_rev.rs index 72ab0079b5..7a81bbb191 100644 --- a/shared-lib/flowy-folder-data-model/src/revision/view_rev.rs +++ b/shared-lib/flowy-folder-data-model/src/revision/view_rev.rs @@ -1,8 +1,10 @@ -use crate::entities::view::{View, ViewDataType}; -use crate::entities::{RepeatedView, TrashType}; -use crate::revision::TrashRevision; +use crate::revision::{TrashRevision, TrashTypeRevision}; +use nanoid::nanoid; use serde::{Deserialize, Serialize}; - +use serde_repr::*; +pub fn gen_view_id() -> String { + nanoid!(10) +} #[derive(Default, Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] pub struct ViewRevision { pub id: String, @@ -14,7 +16,7 @@ pub struct ViewRevision { pub desc: String, #[serde(default)] - pub data_type: ViewDataType, + pub data_type: ViewDataTypeRevision, pub version: i64, @@ -35,20 +37,6 @@ pub struct ViewRevision { } const DEFAULT_PLUGIN_TYPE: fn() -> i32 = || 0; -impl std::convert::From for View { - fn from(view_serde: ViewRevision) -> Self { - View { - id: view_serde.id, - belong_to_id: view_serde.belong_to_id, - name: view_serde.name, - data_type: view_serde.data_type, - modified_time: view_serde.modified_time, - create_time: view_serde.create_time, - plugin_type: view_serde.plugin_type, - } - } -} - impl std::convert::From for TrashRevision { fn from(view_rev: ViewRevision) -> Self { TrashRevision { @@ -56,13 +44,20 @@ impl std::convert::From for TrashRevision { name: view_rev.name, modified_time: view_rev.modified_time, create_time: view_rev.create_time, - ty: TrashType::TrashView, + ty: TrashTypeRevision::TrashView, } } } -impl std::convert::From> for RepeatedView { - fn from(values: Vec) -> Self { - let items = values.into_iter().map(|value| value.into()).collect::>(); - RepeatedView { items } + +#[derive(Eq, PartialEq, Debug, Clone, Serialize_repr, Deserialize_repr)] +#[repr(u8)] +pub enum ViewDataTypeRevision { + TextBlock = 0, + Grid = 1, +} + +impl std::default::Default for ViewDataTypeRevision { + fn default() -> Self { + ViewDataTypeRevision::TextBlock } } diff --git a/shared-lib/flowy-folder-data-model/src/revision/workspace_rev.rs b/shared-lib/flowy-folder-data-model/src/revision/workspace_rev.rs index 5070041211..d975663931 100644 --- a/shared-lib/flowy-folder-data-model/src/revision/workspace_rev.rs +++ b/shared-lib/flowy-folder-data-model/src/revision/workspace_rev.rs @@ -1,7 +1,9 @@ -use crate::entities::workspace::Workspace; use crate::revision::AppRevision; +use nanoid::nanoid; use serde::{Deserialize, Serialize}; - +pub fn gen_workspace_id() -> String { + nanoid!(10) +} #[derive(Default, Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] pub struct WorkspaceRevision { pub id: String, @@ -16,16 +18,3 @@ pub struct WorkspaceRevision { pub create_time: i64, } - -impl std::convert::From for Workspace { - fn from(workspace_serde: WorkspaceRevision) -> Self { - Workspace { - id: workspace_serde.id, - name: workspace_serde.name, - desc: workspace_serde.desc, - apps: workspace_serde.apps.into(), - modified_time: workspace_serde.modified_time, - create_time: workspace_serde.create_time, - } - } -} diff --git a/shared-lib/flowy-folder-data-model/src/user_default.rs b/shared-lib/flowy-folder-data-model/src/user_default.rs index 7e8023067c..166bc32508 100644 --- a/shared-lib/flowy-folder-data-model/src/user_default.rs +++ b/shared-lib/flowy-folder-data-model/src/user_default.rs @@ -1,8 +1,6 @@ -use crate::entities::app::gen_app_id; -use crate::entities::view::gen_view_id; -use crate::entities::view::ViewDataType; -use crate::entities::workspace::gen_workspace_id; -use crate::revision::{AppRevision, ViewRevision, WorkspaceRevision}; +use crate::revision::{ + gen_app_id, gen_view_id, gen_workspace_id, AppRevision, ViewDataTypeRevision, ViewRevision, WorkspaceRevision, +}; use chrono::Utc; pub fn create_default_workspace() -> WorkspaceRevision { @@ -45,14 +43,13 @@ fn create_default_app(workspace_id: String, time: chrono::DateTime) -> AppR fn create_default_view(app_id: String, time: chrono::DateTime) -> ViewRevision { let view_id = gen_view_id(); let name = "Read me".to_string(); - let data_type = ViewDataType::TextBlock; ViewRevision { id: view_id, belong_to_id: app_id, name, desc: "".to_string(), - data_type, + data_type: ViewDataTypeRevision::TextBlock, version: 0, belongings: vec![], modified_time: time.timestamp(), diff --git a/shared-lib/flowy-sync/src/client_folder/folder_pad.rs b/shared-lib/flowy-sync/src/client_folder/folder_pad.rs index 5743bfdb84..f821c03e6f 100644 --- a/shared-lib/flowy-sync/src/client_folder/folder_pad.rs +++ b/shared-lib/flowy-sync/src/client_folder/folder_pad.rs @@ -8,7 +8,6 @@ use crate::{ }, errors::{CollaborateError, CollaborateResult}, }; - use flowy_folder_data_model::revision::{AppRevision, TrashRevision, ViewRevision, WorkspaceRevision}; use lib_infra::util::move_vec_element; use lib_ot::core::*; @@ -724,7 +723,7 @@ mod tests { "name": "🚽 my first trash", "modified_time": 0, "create_time": 0, - "ty": "Unknown" + "ty": 0 } ] }