From 931c638b9304308792189dda4b3e27a9f0db51b6 Mon Sep 17 00:00:00 2001 From: appflowy Date: Thu, 14 Oct 2021 14:34:22 +0800 Subject: [PATCH] [flutter]: config trash list --- app_flowy/lib/startup/tasks/sdk_task.dart | 2 +- .../application/app/app_listen_bloc.dart | 6 + .../application/trash/trash_bloc.dart | 35 +++- .../application/trash/trash_bloc.freezed.dart | 149 ++++++++++++++++-- app_flowy/lib/workspace/domain/i_trash.dart | 12 +- .../infrastructure/deps_resolver.dart | 40 +++-- .../workspace/infrastructure/i_app_impl.dart | 2 +- .../infrastructure/i_trash_impl.dart | 38 +++++ .../workspace/infrastructure/i_user_impl.dart | 18 +-- .../infrastructure/i_workspace_impl.dart | 2 +- .../infrastructure/repos/app_repo.dart | 16 +- .../infrastructure/repos/doc_repo.dart | 7 +- .../infrastructure/repos/helper.dart | 28 ++-- .../infrastructure/repos/trash_repo.dart | 40 +++++ .../infrastructure/repos/view_repo.dart | 12 +- .../infrastructure/repos/workspace_repo.dart | 18 +-- .../stack_page/trash/trash_page.dart | 69 ++++---- .../stack_page/trash/widget/list_body.dart | 0 .../stack_page/trash/widget/list_header.dart | 1 - .../stack_page/trash/widget/sizes.dart | 2 +- .../stack_page/trash/widget/trash_cell.dart | 38 +++++ .../stack_page/trash/widget/trash_header.dart | 71 +++++++++ .../widgets/menu/widget/menu_trash.dart | 2 +- .../flowy_infra_ui/lib/style_widget/text.dart | 13 +- .../flowy-dart-notify/subject.pb.dart | 46 +++--- .../flowy-dart-notify/subject.pbjson.dart | 10 +- .../flowy-user/observable.pbenum.dart | 18 +-- .../flowy-user/observable.pbjson.dart | 10 +- .../flowy-workspace/observable.pbenum.dart | 34 ++-- .../flowy-workspace/observable.pbjson.dart | 11 +- .../packages/flowy_sdk/lib/rust_stream.dart | 13 +- .../src/dart/stream_sender.rs | 6 +- .../flowy-dart-notify/src/entities/subject.rs | 6 +- rust-lib/flowy-dart-notify/src/lib.rs | 4 +- .../src/protobuf/model/subject.rs | 114 +++++++------- .../src/protobuf/proto/subject.proto | 2 +- .../src/derive_cache/derive_cache.rs | 6 +- rust-lib/flowy-user/src/notify/observable.rs | 10 +- .../src/protobuf/model/observable.rs | 40 ++--- .../src/protobuf/proto/observable.proto | 2 +- .../src/services/server/server_api.rs | 4 +- .../src/services/user/user_session.rs | 18 +-- .../flowy-workspace/src/notify/observable.rs | 19 ++- .../src/protobuf/model/observable.rs | 130 +++++++-------- .../src/protobuf/proto/observable.proto | 3 +- .../src/services/app_controller.rs | 8 +- .../src/services/server/middleware.rs | 4 +- .../flowy-workspace/src/services/trash_can.rs | 38 +++-- .../src/services/view_controller.rs | 12 +- .../src/services/workspace_controller.rs | 8 +- 50 files changed, 797 insertions(+), 400 deletions(-) create mode 100644 app_flowy/lib/workspace/infrastructure/i_trash_impl.dart delete mode 100644 app_flowy/lib/workspace/presentation/stack_page/trash/widget/list_body.dart delete mode 100644 app_flowy/lib/workspace/presentation/stack_page/trash/widget/list_header.dart create mode 100644 app_flowy/lib/workspace/presentation/stack_page/trash/widget/trash_cell.dart create mode 100644 app_flowy/lib/workspace/presentation/stack_page/trash/widget/trash_header.dart diff --git a/app_flowy/lib/startup/tasks/sdk_task.dart b/app_flowy/lib/startup/tasks/sdk_task.dart index df695241af..ce0dd1284b 100644 --- a/app_flowy/lib/startup/tasks/sdk_task.dart +++ b/app_flowy/lib/startup/tasks/sdk_task.dart @@ -40,7 +40,7 @@ class ApplicationBlocObserver extends BlocObserver { @override // ignore: unnecessary_overrides void onTransition(Bloc bloc, Transition transition) { - Log.debug("[current]: ${transition.currentState} \n[next]: ${transition.nextState}"); + // Log.debug("[current]: ${transition.currentState} \n[next]: ${transition.nextState}"); super.onTransition(bloc, transition); } diff --git a/app_flowy/lib/workspace/application/app/app_listen_bloc.dart b/app_flowy/lib/workspace/application/app/app_listen_bloc.dart index c06c460ba0..444439b687 100644 --- a/app_flowy/lib/workspace/application/app/app_listen_bloc.dart +++ b/app_flowy/lib/workspace/application/app/app_listen_bloc.dart @@ -33,6 +33,12 @@ class AppListenBloc extends Bloc { (error) => add(AppListenEvent.didReceiveViews(right(error))), ); } + + @override + Future close() async { + await listener.stop(); + return super.close(); + } } @freezed diff --git a/app_flowy/lib/workspace/application/trash/trash_bloc.dart b/app_flowy/lib/workspace/application/trash/trash_bloc.dart index d7dff18d6f..0059b3ff4d 100644 --- a/app_flowy/lib/workspace/application/trash/trash_bloc.dart +++ b/app_flowy/lib/workspace/application/trash/trash_bloc.dart @@ -1,33 +1,62 @@ import 'package:app_flowy/workspace/domain/i_trash.dart'; import 'package:dartz/dartz.dart'; +import 'package:flowy_log/flowy_log.dart'; import 'package:flowy_sdk/protobuf/flowy-workspace/errors.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-workspace/trash_create.pb.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; part 'trash_bloc.freezed.dart'; class TrashBloc extends Bloc { final ITrash iTrash; - TrashBloc(this.iTrash) : super(TrashState.init()); + final ITrashListener listener; + TrashBloc({required this.iTrash, required this.listener}) : super(TrashState.init()); @override Stream mapEventToState(TrashEvent event) async* { yield* event.map( initial: (e) async* { - yield state; + listener.start(_listenTrashUpdated); + final result = await iTrash.readTrash(); + yield result.fold( + (objects) => state.copyWith(objects: objects, successOrFailure: left(unit)), + (error) => state.copyWith(successOrFailure: right(error)), + ); + }, + didReceiveTrash: (e) async* { + yield state.copyWith(objects: e.trash); }, ); } + + void _listenTrashUpdated(Either, WorkspaceError> trashOrFailed) { + trashOrFailed.fold( + (trash) { + add(TrashEvent.didReceiveTrash(trash)); + }, + (error) { + Log.error(error); + }, + ); + } + + @override + Future close() async { + await listener.stop(); + return super.close(); + } } @freezed class TrashEvent with _$TrashEvent { const factory TrashEvent.initial() = Initial; + const factory TrashEvent.didReceiveTrash(List trash) = ReceiveTrash; } @freezed class TrashState with _$TrashState { const factory TrashState({ - required List objects, + required List objects, required Either successOrFailure, }) = _TrashState; diff --git a/app_flowy/lib/workspace/application/trash/trash_bloc.freezed.dart b/app_flowy/lib/workspace/application/trash/trash_bloc.freezed.dart index 6abc386ab1..eaac4ebd12 100644 --- a/app_flowy/lib/workspace/application/trash/trash_bloc.freezed.dart +++ b/app_flowy/lib/workspace/application/trash/trash_bloc.freezed.dart @@ -19,6 +19,12 @@ class _$TrashEventTearOff { Initial initial() { return const Initial(); } + + ReceiveTrash didReceiveTrash(List trash) { + return ReceiveTrash( + trash, + ); + } } /// @nodoc @@ -29,22 +35,26 @@ mixin _$TrashEvent { @optionalTypeArgs TResult when({ required TResult Function() initial, + required TResult Function(List trash) didReceiveTrash, }) => throw _privateConstructorUsedError; @optionalTypeArgs TResult maybeWhen({ TResult Function()? initial, + TResult Function(List trash)? didReceiveTrash, required TResult orElse(), }) => throw _privateConstructorUsedError; @optionalTypeArgs TResult map({ required TResult Function(Initial value) initial, + required TResult Function(ReceiveTrash value) didReceiveTrash, }) => throw _privateConstructorUsedError; @optionalTypeArgs TResult maybeMap({ TResult Function(Initial value)? initial, + TResult Function(ReceiveTrash value)? didReceiveTrash, required TResult orElse(), }) => throw _privateConstructorUsedError; @@ -104,6 +114,7 @@ class _$Initial implements Initial { @optionalTypeArgs TResult when({ required TResult Function() initial, + required TResult Function(List trash) didReceiveTrash, }) { return initial(); } @@ -112,6 +123,7 @@ class _$Initial implements Initial { @optionalTypeArgs TResult maybeWhen({ TResult Function()? initial, + TResult Function(List trash)? didReceiveTrash, required TResult orElse(), }) { if (initial != null) { @@ -124,6 +136,7 @@ class _$Initial implements Initial { @optionalTypeArgs TResult map({ required TResult Function(Initial value) initial, + required TResult Function(ReceiveTrash value) didReceiveTrash, }) { return initial(this); } @@ -132,6 +145,7 @@ class _$Initial implements Initial { @optionalTypeArgs TResult maybeMap({ TResult Function(Initial value)? initial, + TResult Function(ReceiveTrash value)? didReceiveTrash, required TResult orElse(), }) { if (initial != null) { @@ -145,12 +159,127 @@ abstract class Initial implements TrashEvent { const factory Initial() = _$Initial; } +/// @nodoc +abstract class $ReceiveTrashCopyWith<$Res> { + factory $ReceiveTrashCopyWith( + ReceiveTrash value, $Res Function(ReceiveTrash) then) = + _$ReceiveTrashCopyWithImpl<$Res>; + $Res call({List trash}); +} + +/// @nodoc +class _$ReceiveTrashCopyWithImpl<$Res> extends _$TrashEventCopyWithImpl<$Res> + implements $ReceiveTrashCopyWith<$Res> { + _$ReceiveTrashCopyWithImpl( + ReceiveTrash _value, $Res Function(ReceiveTrash) _then) + : super(_value, (v) => _then(v as ReceiveTrash)); + + @override + ReceiveTrash get _value => super._value as ReceiveTrash; + + @override + $Res call({ + Object? trash = freezed, + }) { + return _then(ReceiveTrash( + trash == freezed + ? _value.trash + : trash // ignore: cast_nullable_to_non_nullable + as List, + )); + } +} + +/// @nodoc + +class _$ReceiveTrash implements ReceiveTrash { + const _$ReceiveTrash(this.trash); + + @override + final List trash; + + @override + String toString() { + return 'TrashEvent.didReceiveTrash(trash: $trash)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other is ReceiveTrash && + (identical(other.trash, trash) || + const DeepCollectionEquality().equals(other.trash, trash))); + } + + @override + int get hashCode => + runtimeType.hashCode ^ const DeepCollectionEquality().hash(trash); + + @JsonKey(ignore: true) + @override + $ReceiveTrashCopyWith get copyWith => + _$ReceiveTrashCopyWithImpl(this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() initial, + required TResult Function(List trash) didReceiveTrash, + }) { + return didReceiveTrash(trash); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? initial, + TResult Function(List trash)? didReceiveTrash, + required TResult orElse(), + }) { + if (didReceiveTrash != null) { + return didReceiveTrash(trash); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(Initial value) initial, + required TResult Function(ReceiveTrash value) didReceiveTrash, + }) { + return didReceiveTrash(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(Initial value)? initial, + TResult Function(ReceiveTrash value)? didReceiveTrash, + required TResult orElse(), + }) { + if (didReceiveTrash != null) { + return didReceiveTrash(this); + } + return orElse(); + } +} + +abstract class ReceiveTrash implements TrashEvent { + const factory ReceiveTrash(List trash) = _$ReceiveTrash; + + List get trash => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + $ReceiveTrashCopyWith get copyWith => + throw _privateConstructorUsedError; +} + /// @nodoc class _$TrashStateTearOff { const _$TrashStateTearOff(); _TrashState call( - {required List objects, + {required List objects, required Either successOrFailure}) { return _TrashState( objects: objects, @@ -164,7 +293,7 @@ const $TrashState = _$TrashStateTearOff(); /// @nodoc mixin _$TrashState { - List get objects => throw _privateConstructorUsedError; + List get objects => throw _privateConstructorUsedError; Either get successOrFailure => throw _privateConstructorUsedError; @@ -179,8 +308,7 @@ abstract class $TrashStateCopyWith<$Res> { TrashState value, $Res Function(TrashState) then) = _$TrashStateCopyWithImpl<$Res>; $Res call( - {List objects, - Either successOrFailure}); + {List objects, Either successOrFailure}); } /// @nodoc @@ -200,7 +328,7 @@ class _$TrashStateCopyWithImpl<$Res> implements $TrashStateCopyWith<$Res> { objects: objects == freezed ? _value.objects : objects // ignore: cast_nullable_to_non_nullable - as List, + as List, successOrFailure: successOrFailure == freezed ? _value.successOrFailure : successOrFailure // ignore: cast_nullable_to_non_nullable @@ -216,8 +344,7 @@ abstract class _$TrashStateCopyWith<$Res> implements $TrashStateCopyWith<$Res> { __$TrashStateCopyWithImpl<$Res>; @override $Res call( - {List objects, - Either successOrFailure}); + {List objects, Either successOrFailure}); } /// @nodoc @@ -239,7 +366,7 @@ class __$TrashStateCopyWithImpl<$Res> extends _$TrashStateCopyWithImpl<$Res> objects: objects == freezed ? _value.objects : objects // ignore: cast_nullable_to_non_nullable - as List, + as List, successOrFailure: successOrFailure == freezed ? _value.successOrFailure : successOrFailure // ignore: cast_nullable_to_non_nullable @@ -254,7 +381,7 @@ class _$_TrashState implements _TrashState { const _$_TrashState({required this.objects, required this.successOrFailure}); @override - final List objects; + final List objects; @override final Either successOrFailure; @@ -289,11 +416,11 @@ class _$_TrashState implements _TrashState { abstract class _TrashState implements TrashState { const factory _TrashState( - {required List objects, + {required List objects, required Either successOrFailure}) = _$_TrashState; @override - List get objects => throw _privateConstructorUsedError; + List get objects => throw _privateConstructorUsedError; @override Either get successOrFailure => throw _privateConstructorUsedError; diff --git a/app_flowy/lib/workspace/domain/i_trash.dart b/app_flowy/lib/workspace/domain/i_trash.dart index f07374d799..f57514ae68 100644 --- a/app_flowy/lib/workspace/domain/i_trash.dart +++ b/app_flowy/lib/workspace/domain/i_trash.dart @@ -1,19 +1,15 @@ import 'dart:async'; import 'package:dartz/dartz.dart'; import 'package:flowy_sdk/protobuf/flowy-workspace/errors.pb.dart'; - -abstract class TrashObject { - String get id; -} +import 'package:flowy_sdk/protobuf/flowy-workspace/trash_create.pb.dart'; abstract class ITrash { - Future, WorkspaceError>> readTrash(); + Future, WorkspaceError>> readTrash(); } -typedef TrashUpdateCallback = void Function(List); +typedef TrashUpdatedCallback = void Function(Either, WorkspaceError> trashOrFailed); abstract class ITrashListener { - void start(); - void setTrashUpdateCallback(TrashUpdateCallback trashUpdateCallback); + void start(TrashUpdatedCallback updateCallback); Future stop(); } diff --git a/app_flowy/lib/workspace/infrastructure/deps_resolver.dart b/app_flowy/lib/workspace/infrastructure/deps_resolver.dart index 9466c89f21..b727a25eb6 100644 --- a/app_flowy/lib/workspace/infrastructure/deps_resolver.dart +++ b/app_flowy/lib/workspace/infrastructure/deps_resolver.dart @@ -5,17 +5,20 @@ import 'package:app_flowy/workspace/application/doc/doc_edit_bloc.dart'; import 'package:app_flowy/workspace/application/menu/menu_bloc.dart'; import 'package:app_flowy/workspace/application/menu/menu_user_bloc.dart'; import 'package:app_flowy/workspace/application/menu/menu_listen.dart'; +import 'package:app_flowy/workspace/application/trash/trash_bloc.dart'; import 'package:app_flowy/workspace/application/view/view_bloc.dart'; -import 'package:app_flowy/workspace/application/view/view_edit_bloc.dart'; import 'package:app_flowy/workspace/application/workspace/welcome_bloc.dart'; import 'package:app_flowy/workspace/domain/i_doc.dart'; +import 'package:app_flowy/workspace/domain/i_trash.dart'; import 'package:app_flowy/workspace/domain/i_view.dart'; import 'package:app_flowy/workspace/domain/page_stack/page_stack.dart'; import 'package:app_flowy/workspace/infrastructure/i_app_impl.dart'; import 'package:app_flowy/workspace/infrastructure/i_doc_impl.dart'; +import 'package:app_flowy/workspace/infrastructure/i_trash_impl.dart'; import 'package:app_flowy/workspace/infrastructure/i_workspace_impl.dart'; import 'package:app_flowy/workspace/infrastructure/repos/app_repo.dart'; import 'package:app_flowy/workspace/infrastructure/repos/doc_repo.dart'; +import 'package:app_flowy/workspace/infrastructure/repos/trash_repo.dart'; import 'package:app_flowy/workspace/infrastructure/repos/view_repo.dart'; import 'package:app_flowy/workspace/infrastructure/repos/workspace_repo.dart'; import 'package:flowy_sdk/protobuf/flowy-user/user_profile.pb.dart'; @@ -29,6 +32,12 @@ class HomeDepsResolver { static Future resolve(GetIt getIt) async { // getIt.registerLazySingleton(() => HomeStackManager()); + getIt.registerFactoryParam( + (user, _) => WelcomeBloc( + repo: UserRepo(user: user), + watch: getIt(param1: user), + ), + ); //App getIt.registerFactoryParam((appId, _) => IAppImpl(repo: AppRepository(appId: appId))); @@ -45,6 +54,12 @@ class HomeDepsResolver { getIt.registerFactoryParam((view, _) => IViewImpl(repo: ViewRepository(view: view))); getIt.registerFactoryParam( (view, _) => IViewListenerImpl(repo: ViewListenerRepository(view: view))); + getIt.registerFactoryParam( + (view, _) => ViewBloc( + iViewImpl: getIt(param1: view), + listener: getIt(param1: view), + ), + ); // Doc getIt.registerFactoryParam((docId, _) => IDocImpl(repo: DocRepository(docId: docId))); @@ -62,27 +77,20 @@ class HomeDepsResolver { getIt.registerFactoryParam( (user, _) => MenuUserBloc(getIt(param1: user), getIt(param1: user))); - // + // App getIt.registerFactoryParam((appId, _) => AppBloc(getIt(param1: appId))); getIt.registerFactoryParam( (appId, _) => AppListenBloc(getIt(param1: appId))); - getIt.registerFactoryParam( - (view, _) => ViewBloc( - iViewImpl: getIt(param1: view), - listener: getIt(param1: view), - ), - ); - + // Doc getIt.registerFactoryParam((docId, _) => DocBloc(iDocImpl: getIt(param1: docId))); - getIt.registerFactoryParam((docId, _) => DocEditBloc(getIt(param1: docId))); - getIt.registerFactoryParam( - (user, _) => WelcomeBloc( - repo: UserRepo(user: user), - watch: getIt(param1: user), - ), - ); + // trash + getIt.registerLazySingleton(() => TrashRepo()); + getIt.registerLazySingleton(() => TrashListenerRepo()); + getIt.registerFactory(() => ITrashImpl(repo: getIt())); + getIt.registerFactory(() => ITrashListenerImpl(repo: getIt())); + getIt.registerFactory(() => TrashBloc(iTrash: getIt(), listener: getIt())); } } diff --git a/app_flowy/lib/workspace/infrastructure/i_app_impl.dart b/app_flowy/lib/workspace/infrastructure/i_app_impl.dart index 109e8c6900..3cdbe3c34a 100644 --- a/app_flowy/lib/workspace/infrastructure/i_app_impl.dart +++ b/app_flowy/lib/workspace/infrastructure/i_app_impl.dart @@ -41,6 +41,6 @@ class IAppListenerhImpl extends IAppListenr { @override void start({AppViewsChangeCallback? viewsChangeCallback, AppUpdatedCallback? updatedCallback}) { - repo.startListen(viewsChanged: viewsChangeCallback, update: updatedCallback); + repo.startListening(viewsChanged: viewsChangeCallback, update: updatedCallback); } } diff --git a/app_flowy/lib/workspace/infrastructure/i_trash_impl.dart b/app_flowy/lib/workspace/infrastructure/i_trash_impl.dart new file mode 100644 index 0000000000..251dbcc1d8 --- /dev/null +++ b/app_flowy/lib/workspace/infrastructure/i_trash_impl.dart @@ -0,0 +1,38 @@ +import 'package:app_flowy/workspace/domain/i_trash.dart'; +import 'package:app_flowy/workspace/infrastructure/repos/trash_repo.dart'; +import 'package:flowy_sdk/protobuf/flowy-workspace/errors.pb.dart'; +import 'package:dartz/dartz.dart'; +import 'package:flowy_sdk/protobuf/flowy-workspace/trash_create.pb.dart'; + +class ITrashImpl implements ITrash { + TrashRepo repo; + + ITrashImpl({required this.repo}); + + @override + Future, WorkspaceError>> readTrash() { + return repo.readTrash().then((result) { + return result.fold( + (repeatedTrash) => left(repeatedTrash.items), + (err) => right(err), + ); + }); + } +} + +class ITrashListenerImpl extends ITrashListener { + TrashListenerRepo repo; + ITrashListenerImpl({ + required this.repo, + }); + + @override + Future stop() async { + await repo.close(); + } + + @override + void start(TrashUpdatedCallback updateCallback) { + repo.startListening(trashUpdated: updateCallback); + } +} diff --git a/app_flowy/lib/workspace/infrastructure/i_user_impl.dart b/app_flowy/lib/workspace/infrastructure/i_user_impl.dart index 36a2c796ab..c5d056e399 100644 --- a/app_flowy/lib/workspace/infrastructure/i_user_impl.dart +++ b/app_flowy/lib/workspace/infrastructure/i_user_impl.dart @@ -50,7 +50,7 @@ class IUserImpl extends IUser { } class IUserListenerImpl extends IUserListener { - StreamSubscription? _subscription; + StreamSubscription? _subscription; WorkspacesUpdatedCallback? _workspacesUpdated; AuthChangedCallback? _authChanged; UserProfileUpdateCallback? _profileUpdated; @@ -68,7 +68,7 @@ class IUserListenerImpl extends IUserListener { void start() { _workspaceParser = WorkspaceNotificationParser(id: _user.token, callback: _NotificationCallback); - _userParser = UserNotificationParser(id: _user.token, callback: _userObservableCallback); + _userParser = UserNotificationParser(id: _user.token, callback: _UserNotificationCallback); _subscription = RustStreamReceiver.listen((observable) { _workspaceParser.parse(observable); @@ -96,11 +96,11 @@ class IUserListenerImpl extends IUserListener { _workspacesUpdated = workspacesCallback; } - void _NotificationCallback(Notification ty, Either result) { + void _NotificationCallback(WorkspaceNotification ty, Either result) { switch (ty) { - case Notification.UserCreateWorkspace: - case Notification.UserDeleteWorkspace: - case Notification.WorkspaceListUpdated: + case WorkspaceNotification.UserCreateWorkspace: + case WorkspaceNotification.UserDeleteWorkspace: + case WorkspaceNotification.WorkspaceListUpdated: if (_workspacesUpdated != null) { result.fold( (payload) { @@ -111,7 +111,7 @@ class IUserListenerImpl extends IUserListener { ); } break; - case Notification.UserUnauthorized: + case WorkspaceNotification.UserUnauthorized: if (_authChanged != null) { result.fold( (_) {}, @@ -124,9 +124,9 @@ class IUserListenerImpl extends IUserListener { } } - void _userObservableCallback(user.UserObservable ty, Either result) { + void _UserNotificationCallback(user.UserNotification ty, Either result) { switch (ty) { - case user.UserObservable.UserUnauthorized: + case user.UserNotification.UserUnauthorized: if (_profileUpdated != null) { result.fold( (payload) { diff --git a/app_flowy/lib/workspace/infrastructure/i_workspace_impl.dart b/app_flowy/lib/workspace/infrastructure/i_workspace_impl.dart index 4606f956bc..6f45471601 100644 --- a/app_flowy/lib/workspace/infrastructure/i_workspace_impl.dart +++ b/app_flowy/lib/workspace/infrastructure/i_workspace_impl.dart @@ -36,7 +36,7 @@ class IWorkspaceListenerImpl extends IWorkspaceListener { @override void start({WorkspaceCreateAppCallback? addAppCallback, WorkspaceUpdatedCallback? updatedCallback}) { - repo.startListen(createApp: addAppCallback, update: updatedCallback); + repo.startListening(createApp: addAppCallback, update: updatedCallback); } @override diff --git a/app_flowy/lib/workspace/infrastructure/repos/app_repo.dart b/app_flowy/lib/workspace/infrastructure/repos/app_repo.dart index 0201f1b5a3..450bb997db 100644 --- a/app_flowy/lib/workspace/infrastructure/repos/app_repo.dart +++ b/app_flowy/lib/workspace/infrastructure/repos/app_repo.dart @@ -53,26 +53,26 @@ class AppRepository { } class AppListenerRepository { - StreamSubscription? _subscription; + StreamSubscription? _subscription; AppViewsChangeCallback? _viewsChanged; AppUpdatedCallback? _update; - late WorkspaceNotificationParser _extractor; + late WorkspaceNotificationParser _parser; String appId; AppListenerRepository({ required this.appId, }); - void startListen({AppViewsChangeCallback? viewsChanged, AppUpdatedCallback? update}) { + void startListening({AppViewsChangeCallback? viewsChanged, AppUpdatedCallback? update}) { _viewsChanged = viewsChanged; _update = update; - _extractor = WorkspaceNotificationParser(id: appId, callback: _bservableCallback); - _subscription = RustStreamReceiver.listen((observable) => _extractor.parse(observable)); + _parser = WorkspaceNotificationParser(id: appId, callback: _bservableCallback); + _subscription = RustStreamReceiver.listen((observable) => _parser.parse(observable)); } - void _bservableCallback(Notification ty, Either result) { + void _bservableCallback(WorkspaceNotification ty, Either result) { switch (ty) { - case Notification.AppViewsChanged: + case WorkspaceNotification.AppViewsChanged: if (_viewsChanged != null) { result.fold( (payload) { @@ -83,7 +83,7 @@ class AppListenerRepository { ); } break; - case Notification.AppUpdated: + case WorkspaceNotification.AppUpdated: if (_update != null) { result.fold( (payload) { diff --git a/app_flowy/lib/workspace/infrastructure/repos/doc_repo.dart b/app_flowy/lib/workspace/infrastructure/repos/doc_repo.dart index 33b9c4fe0d..ceab9cc333 100644 --- a/app_flowy/lib/workspace/infrastructure/repos/doc_repo.dart +++ b/app_flowy/lib/workspace/infrastructure/repos/doc_repo.dart @@ -16,17 +16,16 @@ class DocRepository { return WorkspaceEventOpenView(request).send(); } - Future> composeDelta( - {required String data}) { + Future> composeDelta({required String data}) { final request = DocDelta.create() ..docId = docId ..data = data; return WorkspaceEventApplyDocDelta(request).send(); } - Future> closeDoc( - {String? name, String? desc, String? text}) { + Future> closeDoc({String? name, String? desc, String? text}) { Log.error('Close the doc'); + return Future(() { return left(unit); }); diff --git a/app_flowy/lib/workspace/infrastructure/repos/helper.dart b/app_flowy/lib/workspace/infrastructure/repos/helper.dart index 3276734c33..66cda7166e 100644 --- a/app_flowy/lib/workspace/infrastructure/repos/helper.dart +++ b/app_flowy/lib/workspace/infrastructure/repos/helper.dart @@ -5,41 +5,43 @@ import 'package:flowy_sdk/protobuf/flowy-workspace/errors.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-workspace/observable.pb.dart'; import 'package:dartz/dartz.dart'; -typedef UserObservableCallback = void Function(UserObservable, Either); +typedef UserNotificationCallback = void Function(UserNotification, Either); -class UserNotificationParser extends NotificationParser { - UserNotificationParser({required String id, required UserObservableCallback callback}) +class UserNotificationParser extends NotificationParser { + UserNotificationParser({required String id, required UserNotificationCallback callback}) : super( id: id, callback: callback, - tyParser: (ty) => UserObservable.valueOf(ty), + tyParser: (ty) => UserNotification.valueOf(ty), errorParser: (bytes) => UserError.fromBuffer(bytes), ); } -typedef NotificationCallback = void Function(Notification, Either); +typedef NotificationCallback = void Function(WorkspaceNotification, Either); -class WorkspaceNotificationParser extends NotificationParser { - WorkspaceNotificationParser({required String id, required NotificationCallback callback}) +class WorkspaceNotificationParser extends NotificationParser { + WorkspaceNotificationParser({String? id, required NotificationCallback callback}) : super( id: id, callback: callback, - tyParser: (ty) => Notification.valueOf(ty), + tyParser: (ty) => WorkspaceNotification.valueOf(ty), errorParser: (bytes) => WorkspaceError.fromBuffer(bytes), ); } class NotificationParser { - String id; + String? id; void Function(T, Either) callback; T? Function(int) tyParser; E Function(Uint8List) errorParser; - NotificationParser({required this.id, required this.callback, required this.errorParser, required this.tyParser}); - void parse(ObservableSubject subject) { - if (subject.id != id) { - return; + NotificationParser({this.id, required this.callback, required this.errorParser, required this.tyParser}); + void parse(SubscribeObject subject) { + if (id != null) { + if (subject.id != id) { + return; + } } final ty = tyParser(subject.ty); diff --git a/app_flowy/lib/workspace/infrastructure/repos/trash_repo.dart b/app_flowy/lib/workspace/infrastructure/repos/trash_repo.dart index 0466eb81a0..80d73bbeea 100644 --- a/app_flowy/lib/workspace/infrastructure/repos/trash_repo.dart +++ b/app_flowy/lib/workspace/infrastructure/repos/trash_repo.dart @@ -1,9 +1,15 @@ import 'dart:async'; +import 'dart:typed_data'; +import 'package:app_flowy/workspace/domain/i_trash.dart'; +import 'package:app_flowy/workspace/infrastructure/repos/helper.dart'; import 'package:dartz/dartz.dart'; import 'package:flowy_sdk/dispatch/dispatch.dart'; +import 'package:flowy_sdk/protobuf/flowy-dart-notify/subject.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-workspace/errors.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-workspace/observable.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-workspace/trash_create.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-workspace/trash_delete.pb.dart'; +import 'package:flowy_sdk/rust_stream.dart'; class TrashRepo { Future> readTrash() { @@ -21,3 +27,37 @@ class TrashRepo { return WorkspaceEventDeleteTrash(id).send(); } } + +class TrashListenerRepo { + StreamSubscription? _subscription; + TrashUpdatedCallback? _trashUpdated; + late WorkspaceNotificationParser _parser; + + void startListening({TrashUpdatedCallback? trashUpdated}) { + _trashUpdated = trashUpdated; + _parser = WorkspaceNotificationParser(callback: _bservableCallback); + _subscription = RustStreamReceiver.listen((observable) => _parser.parse(observable)); + } + + void _bservableCallback(WorkspaceNotification ty, Either result) { + switch (ty) { + case WorkspaceNotification.TrashUpdated: + if (_trashUpdated != null) { + result.fold( + (payload) { + final repeatedTrash = RepeatedTrash.fromBuffer(payload); + _trashUpdated!(left(repeatedTrash.items)); + }, + (error) => _trashUpdated!(right(error)), + ); + } + break; + default: + break; + } + } + + Future close() async { + await _subscription?.cancel(); + } +} diff --git a/app_flowy/lib/workspace/infrastructure/repos/view_repo.dart b/app_flowy/lib/workspace/infrastructure/repos/view_repo.dart index 45357ec72e..0cafc66980 100644 --- a/app_flowy/lib/workspace/infrastructure/repos/view_repo.dart +++ b/app_flowy/lib/workspace/infrastructure/repos/view_repo.dart @@ -51,9 +51,9 @@ class ViewRepository { } class ViewListenerRepository { - StreamSubscription? _subscription; + StreamSubscription? _subscription; ViewUpdatedCallback? _update; - late WorkspaceNotificationParser _extractor; + late WorkspaceNotificationParser _parser; View view; ViewListenerRepository({ @@ -64,19 +64,19 @@ class ViewListenerRepository { ViewUpdatedCallback? update, }) { _update = update; - _extractor = WorkspaceNotificationParser( + _parser = WorkspaceNotificationParser( id: view.id, callback: (ty, result) { _handleObservableType(ty, result); }, ); - _subscription = RustStreamReceiver.listen((observable) => _extractor.parse(observable)); + _subscription = RustStreamReceiver.listen((observable) => _parser.parse(observable)); } - void _handleObservableType(Notification ty, Either result) { + void _handleObservableType(WorkspaceNotification ty, Either result) { switch (ty) { - case Notification.ViewUpdated: + case WorkspaceNotification.ViewUpdated: if (_update != null) { result.fold( (payload) { diff --git a/app_flowy/lib/workspace/infrastructure/repos/workspace_repo.dart b/app_flowy/lib/workspace/infrastructure/repos/workspace_repo.dart index 4f976e4b11..749379632a 100644 --- a/app_flowy/lib/workspace/infrastructure/repos/workspace_repo.dart +++ b/app_flowy/lib/workspace/infrastructure/repos/workspace_repo.dart @@ -63,11 +63,11 @@ class WorkspaceRepo { } class WorkspaceListenerRepo { - StreamSubscription? _subscription; + StreamSubscription? _subscription; WorkspaceCreateAppCallback? _createApp; WorkspaceDeleteAppCallback? _deleteApp; WorkspaceUpdatedCallback? _update; - late WorkspaceNotificationParser _extractor; + late WorkspaceNotificationParser _parser; final UserProfile user; final String workspaceId; @@ -76,7 +76,7 @@ class WorkspaceListenerRepo { required this.workspaceId, }); - void startListen({ + void startListening({ WorkspaceCreateAppCallback? createApp, WorkspaceDeleteAppCallback? deleteApp, WorkspaceUpdatedCallback? update, @@ -85,19 +85,19 @@ class WorkspaceListenerRepo { _deleteApp = deleteApp; _update = update; - _extractor = WorkspaceNotificationParser( + _parser = WorkspaceNotificationParser( id: workspaceId, callback: (ty, result) { _handleObservableType(ty, result); }, ); - _subscription = RustStreamReceiver.listen((observable) => _extractor.parse(observable)); + _subscription = RustStreamReceiver.listen((observable) => _parser.parse(observable)); } - void _handleObservableType(Notification ty, Either result) { + void _handleObservableType(WorkspaceNotification ty, Either result) { switch (ty) { - case Notification.WorkspaceUpdated: + case WorkspaceNotification.WorkspaceUpdated: if (_update != null) { result.fold( (payload) { @@ -108,7 +108,7 @@ class WorkspaceListenerRepo { ); } break; - case Notification.WorkspaceCreateApp: + case WorkspaceNotification.WorkspaceCreateApp: if (_createApp != null) { result.fold( (payload) => _createApp!( @@ -118,7 +118,7 @@ class WorkspaceListenerRepo { ); } break; - case Notification.WorkspaceDeleteApp: + case WorkspaceNotification.WorkspaceDeleteApp: if (_deleteApp != null) { result.fold( (payload) => _deleteApp!( diff --git a/app_flowy/lib/workspace/presentation/stack_page/trash/trash_page.dart b/app_flowy/lib/workspace/presentation/stack_page/trash/trash_page.dart index 357a04fde5..3ed125929f 100644 --- a/app_flowy/lib/workspace/presentation/stack_page/trash/trash_page.dart +++ b/app_flowy/lib/workspace/presentation/stack_page/trash/trash_page.dart @@ -1,14 +1,19 @@ +import 'package:app_flowy/startup/startup.dart'; +import 'package:app_flowy/workspace/application/trash/trash_bloc.dart'; import 'package:app_flowy/workspace/domain/page_stack/page_stack.dart'; +import 'package:app_flowy/workspace/presentation/stack_page/trash/widget/trash_cell.dart'; import 'package:flowy_infra/image.dart'; import 'package:flowy_infra/theme.dart'; -import 'package:flowy_infra_ui/style_widget/scrolling/styled_list.dart'; import 'package:flowy_infra_ui/style_widget/text.dart'; import 'package:flowy_infra_ui/style_widget/button.dart'; import 'package:flowy_infra_ui/widget/spacing.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:provider/provider.dart'; import 'package:styled_widget/styled_widget.dart'; +import 'widget/trash_header.dart'; + class TrashStackContext extends HomeStackContext { @override String get identifier => "TrashStackContext"; @@ -24,7 +29,7 @@ class TrashStackContext extends HomeStackContext { @override Widget render() { - return const TrashStackPage(); + return const TrashStackPage(key: ObjectKey('TrashStackPage')); } @override @@ -46,7 +51,16 @@ class _TrashStackPageState extends State { child: Column( children: [ _renderTopBar(theme), - _renderTrashList(context, theme), + const VSpace(32), + Expanded( + child: CustomScrollView( + controller: ScrollController(), + slivers: [ + _renderListHeader(context), + _renderListBody(context), + ], + ), + ), ], mainAxisAlignment: MainAxisAlignment.start, ).padding(horizontal: 80, vertical: 48), @@ -84,44 +98,35 @@ class _TrashStackPageState extends State { ); } - Widget _renderTrashList(BuildContext context, AppTheme theme) { - return Expanded( - child: CustomScrollView( - physics: StyledScrollPhysics(), - slivers: [ - _renderListHeader(context), - _renderListBody(context), - ], - ), - ); - } - Widget _renderListHeader(BuildContext context) { - return const SliverAppBar( - automaticallyImplyLeading: false, - backgroundColor: Colors.green, - title: Text('Have a nice day'), + return SliverPersistentHeader( + delegate: TrashHeaderDelegate(), floating: true, + pinned: true, ); } Widget _renderListBody(BuildContext context) { - return SliverList( - delegate: SliverChildBuilderDelegate( - (BuildContext context, int index) { - return Card( - child: Container( - color: Colors.blue[100 * (index % 9 + 1)], - height: 80, - alignment: Alignment.center, - child: Text( - "Item $index", - style: const TextStyle(fontSize: 30), - ), + return BlocProvider( + create: (context) => getIt()..add(const TrashEvent.initial()), + child: BlocBuilder( + builder: (context, state) { + return SliverList( + delegate: SliverChildBuilderDelegate( + (BuildContext context, int index) { + return SizedBox( + height: 42, + child: TrashCell( + object: state.objects[index], + onRestore: () {}, + onDelete: () {}, + ), + ); + }, + childCount: state.objects.length, ), ); }, - childCount: 3, ), ); } diff --git a/app_flowy/lib/workspace/presentation/stack_page/trash/widget/list_body.dart b/app_flowy/lib/workspace/presentation/stack_page/trash/widget/list_body.dart deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/app_flowy/lib/workspace/presentation/stack_page/trash/widget/list_header.dart b/app_flowy/lib/workspace/presentation/stack_page/trash/widget/list_header.dart deleted file mode 100644 index 8b13789179..0000000000 --- a/app_flowy/lib/workspace/presentation/stack_page/trash/widget/list_header.dart +++ /dev/null @@ -1 +0,0 @@ - diff --git a/app_flowy/lib/workspace/presentation/stack_page/trash/widget/sizes.dart b/app_flowy/lib/workspace/presentation/stack_page/trash/widget/sizes.dart index b906bbd0cc..107d0eb7f3 100644 --- a/app_flowy/lib/workspace/presentation/stack_page/trash/widget/sizes.dart +++ b/app_flowy/lib/workspace/presentation/stack_page/trash/widget/sizes.dart @@ -1,4 +1,4 @@ -class TrashListSizes { +class TrashSizes { static double scale = 1; static double get fileNameWidth => 320 * scale; static double get lashModifyWidth => 230 * scale; diff --git a/app_flowy/lib/workspace/presentation/stack_page/trash/widget/trash_cell.dart b/app_flowy/lib/workspace/presentation/stack_page/trash/widget/trash_cell.dart new file mode 100644 index 0000000000..94d1a70f62 --- /dev/null +++ b/app_flowy/lib/workspace/presentation/stack_page/trash/widget/trash_cell.dart @@ -0,0 +1,38 @@ +import 'package:flowy_infra/image.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-workspace/trash_create.pb.dart'; +import 'package:flutter/material.dart'; + +import 'sizes.dart'; + +class TrashCell extends StatelessWidget { + final VoidCallback onRestore; + final VoidCallback onDelete; + final Trash object; + const TrashCell({required this.object, required this.onRestore, required this.onDelete, Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + return Row( + children: [ + SizedBox(width: TrashSizes.fileNameWidth, child: FlowyText(object.name, fontSize: 12)), + SizedBox(width: TrashSizes.lashModifyWidth, child: FlowyText("${object.modifiedTime}", fontSize: 12)), + SizedBox(width: TrashSizes.createTimeWidth, child: FlowyText("${object.createTime}", fontSize: 12)), + const Spacer(), + FlowyIconButton( + width: 16, + onPressed: onRestore, + icon: svg("editor/restore"), + ), + const HSpace(20), + FlowyIconButton( + width: 16, + onPressed: onDelete, + icon: svg("editor/delete"), + ), + ], + ); + } +} diff --git a/app_flowy/lib/workspace/presentation/stack_page/trash/widget/trash_header.dart b/app_flowy/lib/workspace/presentation/stack_page/trash/widget/trash_header.dart new file mode 100644 index 0000000000..f20511b937 --- /dev/null +++ b/app_flowy/lib/workspace/presentation/stack_page/trash/widget/trash_header.dart @@ -0,0 +1,71 @@ +import 'package:flowy_infra/theme.dart'; +import 'package:flowy_infra_ui/style_widget/text.dart'; +import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; + +import 'sizes.dart'; + +class TrashHeaderDelegate extends SliverPersistentHeaderDelegate { + TrashHeaderDelegate(); + + @override + Widget build(BuildContext context, double shrinkOffset, bool overlapsContent) { + return TrashHeader(); + } + + @override + double get maxExtent => 60; + + @override + double get minExtent => 60; + + @override + bool shouldRebuild(covariant SliverPersistentHeaderDelegate oldDelegate) { + return false; + } +} + +class TrashHeaderItem { + double width; + String title; + + TrashHeaderItem({required this.width, required this.title}); +} + +class TrashHeader extends StatelessWidget { + final List items = [ + TrashHeaderItem(title: 'File name', width: TrashSizes.fileNameWidth), + TrashHeaderItem(title: 'Last modified', width: TrashSizes.lashModifyWidth), + TrashHeaderItem(title: 'Created', width: TrashSizes.createTimeWidth), + ]; + + TrashHeader({Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + final theme = context.watch(); + final headerItems = List.empty(growable: true); + items.asMap().forEach((index, item) { + headerItems.add( + SizedBox( + width: item.width, + child: FlowyText( + item.title, + fontSize: 12, + color: theme.shader3, + ), + ), + ); + }); + + return Container( + color: Colors.white, + child: Row( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + ...headerItems, + ], + ), + ); + } +} diff --git a/app_flowy/lib/workspace/presentation/widgets/menu/widget/menu_trash.dart b/app_flowy/lib/workspace/presentation/widgets/menu/widget/menu_trash.dart index 8d2e948b68..03eea9879c 100644 --- a/app_flowy/lib/workspace/presentation/widgets/menu/widget/menu_trash.dart +++ b/app_flowy/lib/workspace/presentation/widgets/menu/widget/menu_trash.dart @@ -1,6 +1,6 @@ import 'package:app_flowy/startup/startup.dart'; import 'package:app_flowy/workspace/domain/page_stack/page_stack.dart'; -import 'package:app_flowy/workspace/presentation/stack_page/trash_page.dart'; +import 'package:app_flowy/workspace/presentation/stack_page/trash/trash_page.dart'; import 'package:flowy_infra/image.dart'; import 'package:flowy_infra_ui/style_widget/text.dart'; import 'package:flowy_infra_ui/widget/spacing.dart'; diff --git a/app_flowy/packages/flowy_infra_ui/lib/style_widget/text.dart b/app_flowy/packages/flowy_infra_ui/lib/style_widget/text.dart index 5258447a4b..7fe6b48141 100644 --- a/app_flowy/packages/flowy_infra_ui/lib/style_widget/text.dart +++ b/app_flowy/packages/flowy_infra_ui/lib/style_widget/text.dart @@ -7,25 +7,27 @@ class FlowyText extends StatelessWidget { final TextOverflow overflow; final double fontSize; final FontWeight fontWeight; + final Color? color; const FlowyText( this.title, { Key? key, this.overflow = TextOverflow.ellipsis, this.fontSize = 16, - this.fontWeight = FontWeight.w500, + this.fontWeight = FontWeight.w400, + this.color, }) : super(key: key); - const FlowyText.semibold(this.title, {Key? key, this.fontSize = 16, TextOverflow? overflow}) + const FlowyText.semibold(this.title, {Key? key, this.fontSize = 16, TextOverflow? overflow, this.color}) : fontWeight = FontWeight.w600, overflow = overflow ?? TextOverflow.ellipsis, super(key: key); - const FlowyText.medium(this.title, {Key? key, this.fontSize = 16, TextOverflow? overflow}) + const FlowyText.medium(this.title, {Key? key, this.fontSize = 16, TextOverflow? overflow, this.color}) : fontWeight = FontWeight.w500, overflow = overflow ?? TextOverflow.ellipsis, super(key: key); - const FlowyText.regular(this.title, {Key? key, this.fontSize = 16, TextOverflow? overflow}) + const FlowyText.regular(this.title, {Key? key, this.fontSize = 16, TextOverflow? overflow, this.color}) : fontWeight = FontWeight.w400, overflow = overflow ?? TextOverflow.ellipsis, super(key: key); @@ -33,11 +35,12 @@ class FlowyText extends StatelessWidget { @override Widget build(BuildContext context) { final theme = context.watch(); + final textColor = color ?? theme.shader1; return Text(title, overflow: overflow, softWrap: false, style: TextStyle( - color: theme.shader1, + color: textColor, fontWeight: fontWeight, fontSize: fontSize + 2, )); diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-dart-notify/subject.pb.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-dart-notify/subject.pb.dart index fd5adde902..828600c49e 100644 --- a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-dart-notify/subject.pb.dart +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-dart-notify/subject.pb.dart @@ -9,26 +9,26 @@ import 'dart:core' as $core; import 'package:protobuf/protobuf.dart' as $pb; -enum ObservableSubject_OneOfPayload { +enum SubscribeObject_OneOfPayload { payload, notSet } -enum ObservableSubject_OneOfError { +enum SubscribeObject_OneOfError { error, notSet } -class ObservableSubject extends $pb.GeneratedMessage { - static const $core.Map<$core.int, ObservableSubject_OneOfPayload> _ObservableSubject_OneOfPayloadByTag = { - 4 : ObservableSubject_OneOfPayload.payload, - 0 : ObservableSubject_OneOfPayload.notSet +class SubscribeObject extends $pb.GeneratedMessage { + static const $core.Map<$core.int, SubscribeObject_OneOfPayload> _SubscribeObject_OneOfPayloadByTag = { + 4 : SubscribeObject_OneOfPayload.payload, + 0 : SubscribeObject_OneOfPayload.notSet }; - static const $core.Map<$core.int, ObservableSubject_OneOfError> _ObservableSubject_OneOfErrorByTag = { - 5 : ObservableSubject_OneOfError.error, - 0 : ObservableSubject_OneOfError.notSet + static const $core.Map<$core.int, SubscribeObject_OneOfError> _SubscribeObject_OneOfErrorByTag = { + 5 : SubscribeObject_OneOfError.error, + 0 : SubscribeObject_OneOfError.notSet }; - static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'ObservableSubject', createEmptyInstance: create) + static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'SubscribeObject', createEmptyInstance: create) ..oo(0, [4]) ..oo(1, [5]) ..aOS(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'source') @@ -39,8 +39,8 @@ class ObservableSubject extends $pb.GeneratedMessage { ..hasRequiredFields = false ; - ObservableSubject._() : super(); - factory ObservableSubject({ + SubscribeObject._() : super(); + factory SubscribeObject({ $core.String? source, $core.int? ty, $core.String? id, @@ -65,31 +65,31 @@ class ObservableSubject extends $pb.GeneratedMessage { } return _result; } - factory ObservableSubject.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r); - factory ObservableSubject.fromJson($core.String i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromJson(i, r); + factory SubscribeObject.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r); + factory SubscribeObject.fromJson($core.String i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromJson(i, r); @$core.Deprecated( 'Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' 'Will be removed in next major version') - ObservableSubject clone() => ObservableSubject()..mergeFromMessage(this); + SubscribeObject clone() => SubscribeObject()..mergeFromMessage(this); @$core.Deprecated( 'Using this can add significant overhead to your binary. ' 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' 'Will be removed in next major version') - ObservableSubject copyWith(void Function(ObservableSubject) updates) => super.copyWith((message) => updates(message as ObservableSubject)) as ObservableSubject; // ignore: deprecated_member_use + SubscribeObject copyWith(void Function(SubscribeObject) updates) => super.copyWith((message) => updates(message as SubscribeObject)) as SubscribeObject; // ignore: deprecated_member_use $pb.BuilderInfo get info_ => _i; @$core.pragma('dart2js:noInline') - static ObservableSubject create() => ObservableSubject._(); - ObservableSubject createEmptyInstance() => create(); - static $pb.PbList createRepeated() => $pb.PbList(); + static SubscribeObject create() => SubscribeObject._(); + SubscribeObject createEmptyInstance() => create(); + static $pb.PbList createRepeated() => $pb.PbList(); @$core.pragma('dart2js:noInline') - static ObservableSubject getDefault() => _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor(create); - static ObservableSubject? _defaultInstance; + static SubscribeObject getDefault() => _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor(create); + static SubscribeObject? _defaultInstance; - ObservableSubject_OneOfPayload whichOneOfPayload() => _ObservableSubject_OneOfPayloadByTag[$_whichOneof(0)]!; + SubscribeObject_OneOfPayload whichOneOfPayload() => _SubscribeObject_OneOfPayloadByTag[$_whichOneof(0)]!; void clearOneOfPayload() => clearField($_whichOneof(0)); - ObservableSubject_OneOfError whichOneOfError() => _ObservableSubject_OneOfErrorByTag[$_whichOneof(1)]!; + SubscribeObject_OneOfError whichOneOfError() => _SubscribeObject_OneOfErrorByTag[$_whichOneof(1)]!; void clearOneOfError() => clearField($_whichOneof(1)); @$pb.TagNumber(1) diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-dart-notify/subject.pbjson.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-dart-notify/subject.pbjson.dart index 701f6f979a..8d8b238ba4 100644 --- a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-dart-notify/subject.pbjson.dart +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-dart-notify/subject.pbjson.dart @@ -8,9 +8,9 @@ import 'dart:core' as $core; import 'dart:convert' as $convert; import 'dart:typed_data' as $typed_data; -@$core.Deprecated('Use observableSubjectDescriptor instead') -const ObservableSubject$json = const { - '1': 'ObservableSubject', +@$core.Deprecated('Use subscribeObjectDescriptor instead') +const SubscribeObject$json = const { + '1': 'SubscribeObject', '2': const [ const {'1': 'source', '3': 1, '4': 1, '5': 9, '10': 'source'}, const {'1': 'ty', '3': 2, '4': 1, '5': 5, '10': 'ty'}, @@ -24,5 +24,5 @@ const ObservableSubject$json = const { ], }; -/// Descriptor for `ObservableSubject`. Decode as a `google.protobuf.DescriptorProto`. -final $typed_data.Uint8List observableSubjectDescriptor = $convert.base64Decode('ChFPYnNlcnZhYmxlU3ViamVjdBIWCgZzb3VyY2UYASABKAlSBnNvdXJjZRIOCgJ0eRgCIAEoBVICdHkSDgoCaWQYAyABKAlSAmlkEhoKB3BheWxvYWQYBCABKAxIAFIHcGF5bG9hZBIWCgVlcnJvchgFIAEoDEgBUgVlcnJvckIQCg5vbmVfb2ZfcGF5bG9hZEIOCgxvbmVfb2ZfZXJyb3I='); +/// Descriptor for `SubscribeObject`. Decode as a `google.protobuf.DescriptorProto`. +final $typed_data.Uint8List subscribeObjectDescriptor = $convert.base64Decode('Cg9TdWJzY3JpYmVPYmplY3QSFgoGc291cmNlGAEgASgJUgZzb3VyY2USDgoCdHkYAiABKAVSAnR5Eg4KAmlkGAMgASgJUgJpZBIaCgdwYXlsb2FkGAQgASgMSABSB3BheWxvYWQSFgoFZXJyb3IYBSABKAxIAVIFZXJyb3JCEAoOb25lX29mX3BheWxvYWRCDgoMb25lX29mX2Vycm9y'); diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user/observable.pbenum.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user/observable.pbenum.dart index a9d5912f71..cc7f672a81 100644 --- a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user/observable.pbenum.dart +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user/observable.pbenum.dart @@ -9,22 +9,22 @@ import 'dart:core' as $core; import 'package:protobuf/protobuf.dart' as $pb; -class UserObservable extends $pb.ProtobufEnum { - static const UserObservable Unknown = UserObservable._(0, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'Unknown'); - static const UserObservable UserAuthChanged = UserObservable._(1, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'UserAuthChanged'); - static const UserObservable UserProfileUpdated = UserObservable._(2, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'UserProfileUpdated'); - static const UserObservable UserUnauthorized = UserObservable._(3, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'UserUnauthorized'); +class UserNotification extends $pb.ProtobufEnum { + static const UserNotification Unknown = UserNotification._(0, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'Unknown'); + static const UserNotification UserAuthChanged = UserNotification._(1, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'UserAuthChanged'); + static const UserNotification UserProfileUpdated = UserNotification._(2, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'UserProfileUpdated'); + static const UserNotification UserUnauthorized = UserNotification._(3, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'UserUnauthorized'); - static const $core.List values = [ + static const $core.List values = [ Unknown, UserAuthChanged, UserProfileUpdated, UserUnauthorized, ]; - static final $core.Map<$core.int, UserObservable> _byValue = $pb.ProtobufEnum.initByValue(values); - static UserObservable? valueOf($core.int value) => _byValue[value]; + static final $core.Map<$core.int, UserNotification> _byValue = $pb.ProtobufEnum.initByValue(values); + static UserNotification? valueOf($core.int value) => _byValue[value]; - const UserObservable._($core.int v, $core.String n) : super(v, n); + const UserNotification._($core.int v, $core.String n) : super(v, n); } diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user/observable.pbjson.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user/observable.pbjson.dart index 60948add38..d18524ac45 100644 --- a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user/observable.pbjson.dart +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user/observable.pbjson.dart @@ -8,9 +8,9 @@ import 'dart:core' as $core; import 'dart:convert' as $convert; import 'dart:typed_data' as $typed_data; -@$core.Deprecated('Use userObservableDescriptor instead') -const UserObservable$json = const { - '1': 'UserObservable', +@$core.Deprecated('Use userNotificationDescriptor instead') +const UserNotification$json = const { + '1': 'UserNotification', '2': const [ const {'1': 'Unknown', '2': 0}, const {'1': 'UserAuthChanged', '2': 1}, @@ -19,5 +19,5 @@ const UserObservable$json = const { ], }; -/// Descriptor for `UserObservable`. Decode as a `google.protobuf.EnumDescriptorProto`. -final $typed_data.Uint8List userObservableDescriptor = $convert.base64Decode('Cg5Vc2VyT2JzZXJ2YWJsZRILCgdVbmtub3duEAASEwoPVXNlckF1dGhDaGFuZ2VkEAESFgoSVXNlclByb2ZpbGVVcGRhdGVkEAISFAoQVXNlclVuYXV0aG9yaXplZBAD'); +/// Descriptor for `UserNotification`. Decode as a `google.protobuf.EnumDescriptorProto`. +final $typed_data.Uint8List userNotificationDescriptor = $convert.base64Decode('ChBVc2VyTm90aWZpY2F0aW9uEgsKB1Vua25vd24QABITCg9Vc2VyQXV0aENoYW5nZWQQARIWChJVc2VyUHJvZmlsZVVwZGF0ZWQQAhIUChBVc2VyVW5hdXRob3JpemVkEAM='); diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/observable.pbenum.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/observable.pbenum.dart index 179da81db3..a8c046d427 100644 --- a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/observable.pbenum.dart +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/observable.pbenum.dart @@ -9,20 +9,21 @@ import 'dart:core' as $core; import 'package:protobuf/protobuf.dart' as $pb; -class Notification extends $pb.ProtobufEnum { - static const Notification Unknown = Notification._(0, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'Unknown'); - static const Notification UserCreateWorkspace = Notification._(10, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'UserCreateWorkspace'); - static const Notification UserDeleteWorkspace = Notification._(11, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'UserDeleteWorkspace'); - static const Notification WorkspaceUpdated = Notification._(12, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'WorkspaceUpdated'); - static const Notification WorkspaceCreateApp = Notification._(13, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'WorkspaceCreateApp'); - static const Notification WorkspaceDeleteApp = Notification._(14, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'WorkspaceDeleteApp'); - static const Notification WorkspaceListUpdated = Notification._(15, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'WorkspaceListUpdated'); - static const Notification AppUpdated = Notification._(21, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'AppUpdated'); - static const Notification AppViewsChanged = Notification._(24, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'AppViewsChanged'); - static const Notification ViewUpdated = Notification._(31, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'ViewUpdated'); - static const Notification UserUnauthorized = Notification._(100, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'UserUnauthorized'); +class WorkspaceNotification extends $pb.ProtobufEnum { + static const WorkspaceNotification Unknown = WorkspaceNotification._(0, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'Unknown'); + static const WorkspaceNotification UserCreateWorkspace = WorkspaceNotification._(10, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'UserCreateWorkspace'); + static const WorkspaceNotification UserDeleteWorkspace = WorkspaceNotification._(11, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'UserDeleteWorkspace'); + static const WorkspaceNotification WorkspaceUpdated = WorkspaceNotification._(12, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'WorkspaceUpdated'); + static const WorkspaceNotification WorkspaceCreateApp = WorkspaceNotification._(13, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'WorkspaceCreateApp'); + static const WorkspaceNotification WorkspaceDeleteApp = WorkspaceNotification._(14, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'WorkspaceDeleteApp'); + static const WorkspaceNotification WorkspaceListUpdated = WorkspaceNotification._(15, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'WorkspaceListUpdated'); + static const WorkspaceNotification AppUpdated = WorkspaceNotification._(21, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'AppUpdated'); + static const WorkspaceNotification AppViewsChanged = WorkspaceNotification._(24, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'AppViewsChanged'); + static const WorkspaceNotification ViewUpdated = WorkspaceNotification._(31, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'ViewUpdated'); + static const WorkspaceNotification UserUnauthorized = WorkspaceNotification._(100, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'UserUnauthorized'); + static const WorkspaceNotification TrashUpdated = WorkspaceNotification._(1000, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'TrashUpdated'); - static const $core.List values = [ + static const $core.List values = [ Unknown, UserCreateWorkspace, UserDeleteWorkspace, @@ -34,11 +35,12 @@ class Notification extends $pb.ProtobufEnum { AppViewsChanged, ViewUpdated, UserUnauthorized, + TrashUpdated, ]; - static final $core.Map<$core.int, Notification> _byValue = $pb.ProtobufEnum.initByValue(values); - static Notification? valueOf($core.int value) => _byValue[value]; + static final $core.Map<$core.int, WorkspaceNotification> _byValue = $pb.ProtobufEnum.initByValue(values); + static WorkspaceNotification? valueOf($core.int value) => _byValue[value]; - const Notification._($core.int v, $core.String n) : super(v, n); + const WorkspaceNotification._($core.int v, $core.String n) : super(v, n); } diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/observable.pbjson.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/observable.pbjson.dart index 8e34ff0476..e3043755b4 100644 --- a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/observable.pbjson.dart +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/observable.pbjson.dart @@ -8,9 +8,9 @@ import 'dart:core' as $core; import 'dart:convert' as $convert; import 'dart:typed_data' as $typed_data; -@$core.Deprecated('Use notificationDescriptor instead') -const Notification$json = const { - '1': 'Notification', +@$core.Deprecated('Use workspaceNotificationDescriptor instead') +const WorkspaceNotification$json = const { + '1': 'WorkspaceNotification', '2': const [ const {'1': 'Unknown', '2': 0}, const {'1': 'UserCreateWorkspace', '2': 10}, @@ -23,8 +23,9 @@ const Notification$json = const { const {'1': 'AppViewsChanged', '2': 24}, const {'1': 'ViewUpdated', '2': 31}, const {'1': 'UserUnauthorized', '2': 100}, + const {'1': 'TrashUpdated', '2': 1000}, ], }; -/// Descriptor for `Notification`. Decode as a `google.protobuf.EnumDescriptorProto`. -final $typed_data.Uint8List notificationDescriptor = $convert.base64Decode('CgxOb3RpZmljYXRpb24SCwoHVW5rbm93bhAAEhcKE1VzZXJDcmVhdGVXb3Jrc3BhY2UQChIXChNVc2VyRGVsZXRlV29ya3NwYWNlEAsSFAoQV29ya3NwYWNlVXBkYXRlZBAMEhYKEldvcmtzcGFjZUNyZWF0ZUFwcBANEhYKEldvcmtzcGFjZURlbGV0ZUFwcBAOEhgKFFdvcmtzcGFjZUxpc3RVcGRhdGVkEA8SDgoKQXBwVXBkYXRlZBAVEhMKD0FwcFZpZXdzQ2hhbmdlZBAYEg8KC1ZpZXdVcGRhdGVkEB8SFAoQVXNlclVuYXV0aG9yaXplZBBk'); +/// Descriptor for `WorkspaceNotification`. Decode as a `google.protobuf.EnumDescriptorProto`. +final $typed_data.Uint8List workspaceNotificationDescriptor = $convert.base64Decode('ChVXb3Jrc3BhY2VOb3RpZmljYXRpb24SCwoHVW5rbm93bhAAEhcKE1VzZXJDcmVhdGVXb3Jrc3BhY2UQChIXChNVc2VyRGVsZXRlV29ya3NwYWNlEAsSFAoQV29ya3NwYWNlVXBkYXRlZBAMEhYKEldvcmtzcGFjZUNyZWF0ZUFwcBANEhYKEldvcmtzcGFjZURlbGV0ZUFwcBAOEhgKFFdvcmtzcGFjZUxpc3RVcGRhdGVkEA8SDgoKQXBwVXBkYXRlZBAVEhMKD0FwcFZpZXdzQ2hhbmdlZBAYEg8KC1ZpZXdVcGRhdGVkEB8SFAoQVXNlclVuYXV0aG9yaXplZBBkEhEKDFRyYXNoVXBkYXRlZBDoBw=='); diff --git a/app_flowy/packages/flowy_sdk/lib/rust_stream.dart b/app_flowy/packages/flowy_sdk/lib/rust_stream.dart index 459b1b106a..b301841601 100644 --- a/app_flowy/packages/flowy_sdk/lib/rust_stream.dart +++ b/app_flowy/packages/flowy_sdk/lib/rust_stream.dart @@ -5,17 +5,17 @@ import 'dart:ffi'; import 'package:flowy_log/flowy_log.dart'; import 'protobuf/flowy-dart-notify/subject.pb.dart'; -typedef ObserverCallback = void Function(ObservableSubject observable); +typedef ObserverCallback = void Function(SubscribeObject observable); class RustStreamReceiver { static RustStreamReceiver shared = RustStreamReceiver._internal(); late RawReceivePort _ffiPort; late StreamController _streamController; - late StreamController _observableController; + late StreamController _observableController; late StreamSubscription _ffiSubscription; int get port => _ffiPort.sendPort.nativePort; - StreamController get observable => _observableController; + StreamController get observable => _observableController; RustStreamReceiver._internal() { _ffiPort = RawReceivePort(); @@ -30,17 +30,16 @@ class RustStreamReceiver { return shared; } - static listen(void Function(ObservableSubject subject) callback) { + static listen(void Function(SubscribeObject subject) callback) { RustStreamReceiver.shared.observable.stream.listen(callback); } void streamCallback(Uint8List bytes) { try { - final observable = ObservableSubject.fromBuffer(bytes); + final observable = SubscribeObject.fromBuffer(bytes); _observableController.add(observable); } catch (e, s) { - Log.error( - 'RustStreamReceiver ObservableSubject deserialize error: ${e.runtimeType}'); + Log.error('RustStreamReceiver SubscribeObject deserialize error: ${e.runtimeType}'); Log.error('Stack trace \n $s'); rethrow; } diff --git a/rust-lib/flowy-dart-notify/src/dart/stream_sender.rs b/rust-lib/flowy-dart-notify/src/dart/stream_sender.rs index 4ffad8d7ed..274556b54e 100644 --- a/rust-lib/flowy-dart-notify/src/dart/stream_sender.rs +++ b/rust-lib/flowy-dart-notify/src/dart/stream_sender.rs @@ -1,4 +1,4 @@ -use crate::entities::ObservableSubject; +use crate::entities::SubscribeObject; use bytes::Bytes; use lazy_static::lazy_static; use std::{convert::TryInto, sync::RwLock}; @@ -21,7 +21,7 @@ impl DartStreamSender { } #[allow(dead_code)] - fn inner_post(&self, observable_subject: ObservableSubject) -> Result<(), String> { + fn inner_post(&self, observable_subject: SubscribeObject) -> Result<(), String> { match self.isolate { Some(ref isolate) => { let bytes: Bytes = observable_subject.try_into().unwrap(); @@ -42,7 +42,7 @@ impl DartStreamSender { } } - pub fn post(_observable_subject: ObservableSubject) -> Result<(), String> { + pub fn post(_observable_subject: SubscribeObject) -> Result<(), String> { #[cfg(feature = "dart")] match DART_STREAM_SENDER.read() { Ok(stream) => stream.inner_post(_observable_subject), diff --git a/rust-lib/flowy-dart-notify/src/entities/subject.rs b/rust-lib/flowy-dart-notify/src/entities/subject.rs index 3528009cf0..c413e37767 100644 --- a/rust-lib/flowy-dart-notify/src/entities/subject.rs +++ b/rust-lib/flowy-dart-notify/src/entities/subject.rs @@ -2,7 +2,7 @@ use flowy_derive::ProtoBuf; use std::{fmt, fmt::Formatter}; #[derive(Debug, Clone, ProtoBuf)] -pub struct ObservableSubject { +pub struct SubscribeObject { #[pb(index = 1)] pub source: String, @@ -19,7 +19,7 @@ pub struct ObservableSubject { pub error: Option>, } -impl std::fmt::Display for ObservableSubject { +impl std::fmt::Display for SubscribeObject { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { let _ = f.write_str(&format!("{} changed: ", &self.source))?; if let Some(payload) = &self.payload { @@ -34,7 +34,7 @@ impl std::fmt::Display for ObservableSubject { } } -impl std::default::Default for ObservableSubject { +impl std::default::Default for SubscribeObject { fn default() -> Self { Self { source: "".to_string(), diff --git a/rust-lib/flowy-dart-notify/src/lib.rs b/rust-lib/flowy-dart-notify/src/lib.rs index 588b3ccce2..d1bc22e145 100644 --- a/rust-lib/flowy-dart-notify/src/lib.rs +++ b/rust-lib/flowy-dart-notify/src/lib.rs @@ -4,7 +4,7 @@ pub mod dart; pub mod entities; mod protobuf; -use crate::{dart::DartStreamSender, entities::ObservableSubject}; +use crate::{dart::DartStreamSender, entities::SubscribeObject}; use flowy_dispatch::prelude::ToBytes; pub struct DartNotifyBuilder { @@ -64,7 +64,7 @@ impl DartNotifyBuilder { Some(bytes) => Some(bytes.to_vec()), }; - let subject = ObservableSubject { + let subject = SubscribeObject { source: self.source, ty: self.ty, id: self.id, diff --git a/rust-lib/flowy-dart-notify/src/protobuf/model/subject.rs b/rust-lib/flowy-dart-notify/src/protobuf/model/subject.rs index 03b4714a85..9b92b65e61 100644 --- a/rust-lib/flowy-dart-notify/src/protobuf/model/subject.rs +++ b/rust-lib/flowy-dart-notify/src/protobuf/model/subject.rs @@ -24,37 +24,37 @@ // const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_22_1; #[derive(PartialEq,Clone,Default)] -pub struct ObservableSubject { +pub struct SubscribeObject { // message fields pub source: ::std::string::String, pub ty: i32, pub id: ::std::string::String, // message oneof groups - pub one_of_payload: ::std::option::Option, - pub one_of_error: ::std::option::Option, + pub one_of_payload: ::std::option::Option, + pub one_of_error: ::std::option::Option, // special fields pub unknown_fields: ::protobuf::UnknownFields, pub cached_size: ::protobuf::CachedSize, } -impl<'a> ::std::default::Default for &'a ObservableSubject { - fn default() -> &'a ObservableSubject { - ::default_instance() +impl<'a> ::std::default::Default for &'a SubscribeObject { + fn default() -> &'a SubscribeObject { + ::default_instance() } } #[derive(Clone,PartialEq,Debug)] -pub enum ObservableSubject_oneof_one_of_payload { +pub enum SubscribeObject_oneof_one_of_payload { payload(::std::vec::Vec), } #[derive(Clone,PartialEq,Debug)] -pub enum ObservableSubject_oneof_one_of_error { +pub enum SubscribeObject_oneof_one_of_error { error(::std::vec::Vec), } -impl ObservableSubject { - pub fn new() -> ObservableSubject { +impl SubscribeObject { + pub fn new() -> SubscribeObject { ::std::default::Default::default() } @@ -130,7 +130,7 @@ impl ObservableSubject { pub fn get_payload(&self) -> &[u8] { match self.one_of_payload { - ::std::option::Option::Some(ObservableSubject_oneof_one_of_payload::payload(ref v)) => v, + ::std::option::Option::Some(SubscribeObject_oneof_one_of_payload::payload(ref v)) => v, _ => &[], } } @@ -140,24 +140,24 @@ impl ObservableSubject { pub fn has_payload(&self) -> bool { match self.one_of_payload { - ::std::option::Option::Some(ObservableSubject_oneof_one_of_payload::payload(..)) => true, + ::std::option::Option::Some(SubscribeObject_oneof_one_of_payload::payload(..)) => true, _ => false, } } // Param is passed by value, moved pub fn set_payload(&mut self, v: ::std::vec::Vec) { - self.one_of_payload = ::std::option::Option::Some(ObservableSubject_oneof_one_of_payload::payload(v)) + self.one_of_payload = ::std::option::Option::Some(SubscribeObject_oneof_one_of_payload::payload(v)) } // Mutable pointer to the field. pub fn mut_payload(&mut self) -> &mut ::std::vec::Vec { - if let ::std::option::Option::Some(ObservableSubject_oneof_one_of_payload::payload(_)) = self.one_of_payload { + if let ::std::option::Option::Some(SubscribeObject_oneof_one_of_payload::payload(_)) = self.one_of_payload { } else { - self.one_of_payload = ::std::option::Option::Some(ObservableSubject_oneof_one_of_payload::payload(::std::vec::Vec::new())); + self.one_of_payload = ::std::option::Option::Some(SubscribeObject_oneof_one_of_payload::payload(::std::vec::Vec::new())); } match self.one_of_payload { - ::std::option::Option::Some(ObservableSubject_oneof_one_of_payload::payload(ref mut v)) => v, + ::std::option::Option::Some(SubscribeObject_oneof_one_of_payload::payload(ref mut v)) => v, _ => panic!(), } } @@ -166,7 +166,7 @@ impl ObservableSubject { pub fn take_payload(&mut self) -> ::std::vec::Vec { if self.has_payload() { match self.one_of_payload.take() { - ::std::option::Option::Some(ObservableSubject_oneof_one_of_payload::payload(v)) => v, + ::std::option::Option::Some(SubscribeObject_oneof_one_of_payload::payload(v)) => v, _ => panic!(), } } else { @@ -179,7 +179,7 @@ impl ObservableSubject { pub fn get_error(&self) -> &[u8] { match self.one_of_error { - ::std::option::Option::Some(ObservableSubject_oneof_one_of_error::error(ref v)) => v, + ::std::option::Option::Some(SubscribeObject_oneof_one_of_error::error(ref v)) => v, _ => &[], } } @@ -189,24 +189,24 @@ impl ObservableSubject { pub fn has_error(&self) -> bool { match self.one_of_error { - ::std::option::Option::Some(ObservableSubject_oneof_one_of_error::error(..)) => true, + ::std::option::Option::Some(SubscribeObject_oneof_one_of_error::error(..)) => true, _ => false, } } // Param is passed by value, moved pub fn set_error(&mut self, v: ::std::vec::Vec) { - self.one_of_error = ::std::option::Option::Some(ObservableSubject_oneof_one_of_error::error(v)) + self.one_of_error = ::std::option::Option::Some(SubscribeObject_oneof_one_of_error::error(v)) } // Mutable pointer to the field. pub fn mut_error(&mut self) -> &mut ::std::vec::Vec { - if let ::std::option::Option::Some(ObservableSubject_oneof_one_of_error::error(_)) = self.one_of_error { + if let ::std::option::Option::Some(SubscribeObject_oneof_one_of_error::error(_)) = self.one_of_error { } else { - self.one_of_error = ::std::option::Option::Some(ObservableSubject_oneof_one_of_error::error(::std::vec::Vec::new())); + self.one_of_error = ::std::option::Option::Some(SubscribeObject_oneof_one_of_error::error(::std::vec::Vec::new())); } match self.one_of_error { - ::std::option::Option::Some(ObservableSubject_oneof_one_of_error::error(ref mut v)) => v, + ::std::option::Option::Some(SubscribeObject_oneof_one_of_error::error(ref mut v)) => v, _ => panic!(), } } @@ -215,7 +215,7 @@ impl ObservableSubject { pub fn take_error(&mut self) -> ::std::vec::Vec { if self.has_error() { match self.one_of_error.take() { - ::std::option::Option::Some(ObservableSubject_oneof_one_of_error::error(v)) => v, + ::std::option::Option::Some(SubscribeObject_oneof_one_of_error::error(v)) => v, _ => panic!(), } } else { @@ -224,7 +224,7 @@ impl ObservableSubject { } } -impl ::protobuf::Message for ObservableSubject { +impl ::protobuf::Message for SubscribeObject { fn is_initialized(&self) -> bool { true } @@ -250,13 +250,13 @@ impl ::protobuf::Message for ObservableSubject { if wire_type != ::protobuf::wire_format::WireTypeLengthDelimited { return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); } - self.one_of_payload = ::std::option::Option::Some(ObservableSubject_oneof_one_of_payload::payload(is.read_bytes()?)); + self.one_of_payload = ::std::option::Option::Some(SubscribeObject_oneof_one_of_payload::payload(is.read_bytes()?)); }, 5 => { if wire_type != ::protobuf::wire_format::WireTypeLengthDelimited { return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); } - self.one_of_error = ::std::option::Option::Some(ObservableSubject_oneof_one_of_error::error(is.read_bytes()?)); + self.one_of_error = ::std::option::Option::Some(SubscribeObject_oneof_one_of_error::error(is.read_bytes()?)); }, _ => { ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; @@ -281,14 +281,14 @@ impl ::protobuf::Message for ObservableSubject { } if let ::std::option::Option::Some(ref v) = self.one_of_payload { match v { - &ObservableSubject_oneof_one_of_payload::payload(ref v) => { + &SubscribeObject_oneof_one_of_payload::payload(ref v) => { my_size += ::protobuf::rt::bytes_size(4, &v); }, }; } if let ::std::option::Option::Some(ref v) = self.one_of_error { match v { - &ObservableSubject_oneof_one_of_error::error(ref v) => { + &SubscribeObject_oneof_one_of_error::error(ref v) => { my_size += ::protobuf::rt::bytes_size(5, &v); }, }; @@ -310,14 +310,14 @@ impl ::protobuf::Message for ObservableSubject { } if let ::std::option::Option::Some(ref v) = self.one_of_payload { match v { - &ObservableSubject_oneof_one_of_payload::payload(ref v) => { + &SubscribeObject_oneof_one_of_payload::payload(ref v) => { os.write_bytes(4, v)?; }, }; } if let ::std::option::Option::Some(ref v) = self.one_of_error { match v { - &ObservableSubject_oneof_one_of_error::error(ref v) => { + &SubscribeObject_oneof_one_of_error::error(ref v) => { os.write_bytes(5, v)?; }, }; @@ -352,8 +352,8 @@ impl ::protobuf::Message for ObservableSubject { Self::descriptor_static() } - fn new() -> ObservableSubject { - ObservableSubject::new() + fn new() -> SubscribeObject { + SubscribeObject::new() } fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { @@ -362,44 +362,44 @@ impl ::protobuf::Message for ObservableSubject { let mut fields = ::std::vec::Vec::new(); fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( "source", - |m: &ObservableSubject| { &m.source }, - |m: &mut ObservableSubject| { &mut m.source }, + |m: &SubscribeObject| { &m.source }, + |m: &mut SubscribeObject| { &mut m.source }, )); fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeInt32>( "ty", - |m: &ObservableSubject| { &m.ty }, - |m: &mut ObservableSubject| { &mut m.ty }, + |m: &SubscribeObject| { &m.ty }, + |m: &mut SubscribeObject| { &mut m.ty }, )); fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( "id", - |m: &ObservableSubject| { &m.id }, - |m: &mut ObservableSubject| { &mut m.id }, + |m: &SubscribeObject| { &m.id }, + |m: &mut SubscribeObject| { &mut m.id }, )); fields.push(::protobuf::reflect::accessor::make_singular_bytes_accessor::<_>( "payload", - ObservableSubject::has_payload, - ObservableSubject::get_payload, + SubscribeObject::has_payload, + SubscribeObject::get_payload, )); fields.push(::protobuf::reflect::accessor::make_singular_bytes_accessor::<_>( "error", - ObservableSubject::has_error, - ObservableSubject::get_error, + SubscribeObject::has_error, + SubscribeObject::get_error, )); - ::protobuf::reflect::MessageDescriptor::new_pb_name::( - "ObservableSubject", + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "SubscribeObject", fields, file_descriptor_proto() ) }) } - fn default_instance() -> &'static ObservableSubject { - static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; - instance.get(ObservableSubject::new) + fn default_instance() -> &'static SubscribeObject { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(SubscribeObject::new) } } -impl ::protobuf::Clear for ObservableSubject { +impl ::protobuf::Clear for SubscribeObject { fn clear(&mut self) { self.source.clear(); self.ty = 0; @@ -410,26 +410,26 @@ impl ::protobuf::Clear for ObservableSubject { } } -impl ::std::fmt::Debug for ObservableSubject { +impl ::std::fmt::Debug for SubscribeObject { fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { ::protobuf::text_format::fmt(self, f) } } -impl ::protobuf::reflect::ProtobufValue for ObservableSubject { +impl ::protobuf::reflect::ProtobufValue for SubscribeObject { fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { ::protobuf::reflect::ReflectValueRef::Message(self) } } static file_descriptor_proto_data: &'static [u8] = b"\ - \n\rsubject.proto\"\xa1\x01\n\x11ObservableSubject\x12\x16\n\x06source\ - \x18\x01\x20\x01(\tR\x06source\x12\x0e\n\x02ty\x18\x02\x20\x01(\x05R\x02\ - ty\x12\x0e\n\x02id\x18\x03\x20\x01(\tR\x02id\x12\x1a\n\x07payload\x18\ - \x04\x20\x01(\x0cH\0R\x07payload\x12\x16\n\x05error\x18\x05\x20\x01(\x0c\ - H\x01R\x05errorB\x10\n\x0eone_of_payloadB\x0e\n\x0cone_of_errorJ\xf3\x02\ + \n\rsubject.proto\"\x9f\x01\n\x0fSubscribeObject\x12\x16\n\x06source\x18\ + \x01\x20\x01(\tR\x06source\x12\x0e\n\x02ty\x18\x02\x20\x01(\x05R\x02ty\ + \x12\x0e\n\x02id\x18\x03\x20\x01(\tR\x02id\x12\x1a\n\x07payload\x18\x04\ + \x20\x01(\x0cH\0R\x07payload\x12\x16\n\x05error\x18\x05\x20\x01(\x0cH\ + \x01R\x05errorB\x10\n\x0eone_of_payloadB\x0e\n\x0cone_of_errorJ\xf3\x02\ \n\x06\x12\x04\0\0\x08\x01\n\x08\n\x01\x0c\x12\x03\0\0\x12\n\n\n\x02\x04\ - \0\x12\x04\x02\0\x08\x01\n\n\n\x03\x04\0\x01\x12\x03\x02\x08\x19\n\x0b\n\ + \0\x12\x04\x02\0\x08\x01\n\n\n\x03\x04\0\x01\x12\x03\x02\x08\x17\n\x0b\n\ \x04\x04\0\x02\0\x12\x03\x03\x04\x16\n\x0c\n\x05\x04\0\x02\0\x05\x12\x03\ \x03\x04\n\n\x0c\n\x05\x04\0\x02\0\x01\x12\x03\x03\x0b\x11\n\x0c\n\x05\ \x04\0\x02\0\x03\x12\x03\x03\x14\x15\n\x0b\n\x04\x04\0\x02\x01\x12\x03\ diff --git a/rust-lib/flowy-dart-notify/src/protobuf/proto/subject.proto b/rust-lib/flowy-dart-notify/src/protobuf/proto/subject.proto index 558041e1b8..ea7954ecb6 100644 --- a/rust-lib/flowy-dart-notify/src/protobuf/proto/subject.proto +++ b/rust-lib/flowy-dart-notify/src/protobuf/proto/subject.proto @@ -1,6 +1,6 @@ syntax = "proto3"; -message ObservableSubject { +message SubscribeObject { string source = 1; int32 ty = 2; string id = 3; diff --git a/rust-lib/flowy-derive/src/derive_cache/derive_cache.rs b/rust-lib/flowy-derive/src/derive_cache/derive_cache.rs index 9b4ad0b94f..760073d0cc 100644 --- a/rust-lib/flowy-derive/src/derive_cache/derive_cache.rs +++ b/rust-lib/flowy-derive/src/derive_cache/derive_cache.rs @@ -69,7 +69,7 @@ pub fn category_from_str(type_str: &str) -> TypeCategory { | "DocError" | "FFIRequest" | "FFIResponse" - | "ObservableSubject" + | "SubscribeObject" | "SignInRequest" | "SignInParams" | "SignInResponse" @@ -85,14 +85,14 @@ pub fn category_from_str(type_str: &str) -> TypeCategory { "ViewType" | "WorkspaceEvent" | "ErrorCode" - | "Notification" + | "WorkspaceNotification" | "WsModule" | "RevType" | "WsDataType" | "DocObservable" | "FFIStatusCode" | "UserEvent" - | "UserObservable" + | "UserNotification" => TypeCategory::Enum, "Option" => TypeCategory::Opt, diff --git a/rust-lib/flowy-user/src/notify/observable.rs b/rust-lib/flowy-user/src/notify/observable.rs index ea98cefc16..9fedc90fa4 100644 --- a/rust-lib/flowy-user/src/notify/observable.rs +++ b/rust-lib/flowy-user/src/notify/observable.rs @@ -5,21 +5,21 @@ use flowy_dart_notify::DartNotifyBuilder; const OBSERVABLE_CATEGORY: &'static str = "User"; #[derive(ProtoBuf_Enum, Debug)] -pub(crate) enum UserObservable { +pub(crate) enum UserNotification { Unknown = 0, UserAuthChanged = 1, UserProfileUpdated = 2, UserUnauthorized = 3, } -impl std::default::Default for UserObservable { - fn default() -> Self { UserObservable::Unknown } +impl std::default::Default for UserNotification { + fn default() -> Self { UserNotification::Unknown } } -impl std::convert::Into for UserObservable { +impl std::convert::Into for UserNotification { fn into(self) -> i32 { self as i32 } } -pub(crate) fn dart_notify(id: &str, ty: UserObservable) -> DartNotifyBuilder { +pub(crate) fn dart_notify(id: &str, ty: UserNotification) -> DartNotifyBuilder { DartNotifyBuilder::new(id, ty, OBSERVABLE_CATEGORY) } diff --git a/rust-lib/flowy-user/src/protobuf/model/observable.rs b/rust-lib/flowy-user/src/protobuf/model/observable.rs index 62f97b4e37..d495176460 100644 --- a/rust-lib/flowy-user/src/protobuf/model/observable.rs +++ b/rust-lib/flowy-user/src/protobuf/model/observable.rs @@ -24,34 +24,34 @@ // const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_22_1; #[derive(Clone,PartialEq,Eq,Debug,Hash)] -pub enum UserObservable { +pub enum UserNotification { Unknown = 0, UserAuthChanged = 1, UserProfileUpdated = 2, UserUnauthorized = 3, } -impl ::protobuf::ProtobufEnum for UserObservable { +impl ::protobuf::ProtobufEnum for UserNotification { fn value(&self) -> i32 { *self as i32 } - fn from_i32(value: i32) -> ::std::option::Option { + fn from_i32(value: i32) -> ::std::option::Option { match value { - 0 => ::std::option::Option::Some(UserObservable::Unknown), - 1 => ::std::option::Option::Some(UserObservable::UserAuthChanged), - 2 => ::std::option::Option::Some(UserObservable::UserProfileUpdated), - 3 => ::std::option::Option::Some(UserObservable::UserUnauthorized), + 0 => ::std::option::Option::Some(UserNotification::Unknown), + 1 => ::std::option::Option::Some(UserNotification::UserAuthChanged), + 2 => ::std::option::Option::Some(UserNotification::UserProfileUpdated), + 3 => ::std::option::Option::Some(UserNotification::UserUnauthorized), _ => ::std::option::Option::None } } fn values() -> &'static [Self] { - static values: &'static [UserObservable] = &[ - UserObservable::Unknown, - UserObservable::UserAuthChanged, - UserObservable::UserProfileUpdated, - UserObservable::UserUnauthorized, + static values: &'static [UserNotification] = &[ + UserNotification::Unknown, + UserNotification::UserAuthChanged, + UserNotification::UserProfileUpdated, + UserNotification::UserUnauthorized, ]; values } @@ -59,32 +59,32 @@ impl ::protobuf::ProtobufEnum for UserObservable { fn enum_descriptor_static() -> &'static ::protobuf::reflect::EnumDescriptor { static descriptor: ::protobuf::rt::LazyV2<::protobuf::reflect::EnumDescriptor> = ::protobuf::rt::LazyV2::INIT; descriptor.get(|| { - ::protobuf::reflect::EnumDescriptor::new_pb_name::("UserObservable", file_descriptor_proto()) + ::protobuf::reflect::EnumDescriptor::new_pb_name::("UserNotification", file_descriptor_proto()) }) } } -impl ::std::marker::Copy for UserObservable { +impl ::std::marker::Copy for UserNotification { } -impl ::std::default::Default for UserObservable { +impl ::std::default::Default for UserNotification { fn default() -> Self { - UserObservable::Unknown + UserNotification::Unknown } } -impl ::protobuf::reflect::ProtobufValue for UserObservable { +impl ::protobuf::reflect::ProtobufValue for UserNotification { fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { ::protobuf::reflect::ReflectValueRef::Enum(::protobuf::ProtobufEnum::descriptor(self)) } } static file_descriptor_proto_data: &'static [u8] = b"\ - \n\x10observable.proto*`\n\x0eUserObservable\x12\x0b\n\x07Unknown\x10\0\ - \x12\x13\n\x0fUserAuthChanged\x10\x01\x12\x16\n\x12UserProfileUpdated\ + \n\x10observable.proto*b\n\x10UserNotification\x12\x0b\n\x07Unknown\x10\ + \0\x12\x13\n\x0fUserAuthChanged\x10\x01\x12\x16\n\x12UserProfileUpdated\ \x10\x02\x12\x14\n\x10UserUnauthorized\x10\x03J\xce\x01\n\x06\x12\x04\0\ \0\x07\x01\n\x08\n\x01\x0c\x12\x03\0\0\x12\n\n\n\x02\x05\0\x12\x04\x02\0\ - \x07\x01\n\n\n\x03\x05\0\x01\x12\x03\x02\x05\x13\n\x0b\n\x04\x05\0\x02\0\ + \x07\x01\n\n\n\x03\x05\0\x01\x12\x03\x02\x05\x15\n\x0b\n\x04\x05\0\x02\0\ \x12\x03\x03\x04\x10\n\x0c\n\x05\x05\0\x02\0\x01\x12\x03\x03\x04\x0b\n\ \x0c\n\x05\x05\0\x02\0\x02\x12\x03\x03\x0e\x0f\n\x0b\n\x04\x05\0\x02\x01\ \x12\x03\x04\x04\x18\n\x0c\n\x05\x05\0\x02\x01\x01\x12\x03\x04\x04\x13\n\ diff --git a/rust-lib/flowy-user/src/protobuf/proto/observable.proto b/rust-lib/flowy-user/src/protobuf/proto/observable.proto index 88dda1b1d8..990a9ef93d 100644 --- a/rust-lib/flowy-user/src/protobuf/proto/observable.proto +++ b/rust-lib/flowy-user/src/protobuf/proto/observable.proto @@ -1,6 +1,6 @@ syntax = "proto3"; -enum UserObservable { +enum UserNotification { Unknown = 0; UserAuthChanged = 1; UserProfileUpdated = 2; diff --git a/rust-lib/flowy-user/src/services/server/server_api.rs b/rust-lib/flowy-user/src/services/server/server_api.rs index c923a04186..438ec0d361 100644 --- a/rust-lib/flowy-user/src/services/server/server_api.rs +++ b/rust-lib/flowy-user/src/services/server/server_api.rs @@ -70,7 +70,9 @@ impl ResponseMiddleware for Middleware { None => {}, Some(token) => { let error = UserError::new(ErrorCode::UserUnauthorized, ""); - dart_notify(token, UserObservable::UserUnauthorized).error(error).send() + dart_notify(token, UserNotification::UserUnauthorized) + .error(error) + .send() }, } } diff --git a/rust-lib/flowy-user/src/services/user/user_session.rs b/rust-lib/flowy-user/src/services/user/user_session.rs index db9dbe1be7..39d640c87a 100644 --- a/rust-lib/flowy-user/src/services/user/user_session.rs +++ b/rust-lib/flowy-user/src/services/user/user_session.rs @@ -194,12 +194,14 @@ impl UserSession { tokio::spawn(async move { match server.get_user(&token).await { Ok(profile) => { - dart_notify(&token, UserObservable::UserProfileUpdated) + dart_notify(&token, UserNotification::UserProfileUpdated) .payload(profile) .send(); }, Err(e) => { - dart_notify(&token, UserObservable::UserProfileUpdated).error(e).send(); + dart_notify(&token, UserNotification::UserProfileUpdated) + .error(e) + .send(); }, } }); @@ -299,13 +301,11 @@ impl UserSession { match state { WsState::Init => {}, WsState::Connected(_) => {}, - WsState::Disconnected(_) => { - match ws_controller.retry().await { - Ok(_) => {}, - Err(e) => { - log::error!("Retry websocket connect failed: {:?}", e); - } - } + WsState::Disconnected(_) => match ws_controller.retry().await { + Ok(_) => {}, + Err(e) => { + log::error!("Retry websocket connect failed: {:?}", e); + }, }, } }, diff --git a/rust-lib/flowy-workspace/src/notify/observable.rs b/rust-lib/flowy-workspace/src/notify/observable.rs index 41b7345381..5a786940bb 100644 --- a/rust-lib/flowy-workspace/src/notify/observable.rs +++ b/rust-lib/flowy-workspace/src/notify/observable.rs @@ -3,7 +3,7 @@ use flowy_derive::ProtoBuf_Enum; const OBSERVABLE_CATEGORY: &'static str = "Workspace"; #[derive(ProtoBuf_Enum, Debug)] -pub(crate) enum Notification { +pub(crate) enum WorkspaceNotification { Unknown = 0, UserCreateWorkspace = 10, UserDeleteWorkspace = 11, @@ -15,18 +15,23 @@ pub(crate) enum Notification { AppViewsChanged = 24, ViewUpdated = 31, UserUnauthorized = 100, + TrashUpdated = 1000, } -impl std::default::Default for Notification { - fn default() -> Self { Notification::Unknown } +impl std::default::Default for WorkspaceNotification { + fn default() -> Self { WorkspaceNotification::Unknown } } -impl std::convert::Into for Notification { +impl std::convert::Into for WorkspaceNotification { fn into(self) -> i32 { self as i32 } } -pub(crate) fn dart_notify(id: &str, ty: Notification) -> DartNotifyBuilder { - tracing::Span::current().record("dart_notify", &format!("{:?} => notify_id: {}", ty, id).as_str()); - +#[tracing::instrument(level = "debug")] +pub(crate) fn send_dart_notification(id: &str, ty: WorkspaceNotification) -> DartNotifyBuilder { DartNotifyBuilder::new(id, ty, OBSERVABLE_CATEGORY) } + +#[tracing::instrument(level = "debug")] +pub(crate) fn send_anonymous_dart_notification(ty: WorkspaceNotification) -> DartNotifyBuilder { + DartNotifyBuilder::new("", ty, OBSERVABLE_CATEGORY) +} diff --git a/rust-lib/flowy-workspace/src/protobuf/model/observable.rs b/rust-lib/flowy-workspace/src/protobuf/model/observable.rs index 3895aae8bb..7228954d1b 100644 --- a/rust-lib/flowy-workspace/src/protobuf/model/observable.rs +++ b/rust-lib/flowy-workspace/src/protobuf/model/observable.rs @@ -24,7 +24,7 @@ // const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_22_1; #[derive(Clone,PartialEq,Eq,Debug,Hash)] -pub enum Notification { +pub enum WorkspaceNotification { Unknown = 0, UserCreateWorkspace = 10, UserDeleteWorkspace = 11, @@ -36,43 +36,46 @@ pub enum Notification { AppViewsChanged = 24, ViewUpdated = 31, UserUnauthorized = 100, + TrashUpdated = 1000, } -impl ::protobuf::ProtobufEnum for Notification { +impl ::protobuf::ProtobufEnum for WorkspaceNotification { fn value(&self) -> i32 { *self as i32 } - fn from_i32(value: i32) -> ::std::option::Option { + fn from_i32(value: i32) -> ::std::option::Option { match value { - 0 => ::std::option::Option::Some(Notification::Unknown), - 10 => ::std::option::Option::Some(Notification::UserCreateWorkspace), - 11 => ::std::option::Option::Some(Notification::UserDeleteWorkspace), - 12 => ::std::option::Option::Some(Notification::WorkspaceUpdated), - 13 => ::std::option::Option::Some(Notification::WorkspaceCreateApp), - 14 => ::std::option::Option::Some(Notification::WorkspaceDeleteApp), - 15 => ::std::option::Option::Some(Notification::WorkspaceListUpdated), - 21 => ::std::option::Option::Some(Notification::AppUpdated), - 24 => ::std::option::Option::Some(Notification::AppViewsChanged), - 31 => ::std::option::Option::Some(Notification::ViewUpdated), - 100 => ::std::option::Option::Some(Notification::UserUnauthorized), + 0 => ::std::option::Option::Some(WorkspaceNotification::Unknown), + 10 => ::std::option::Option::Some(WorkspaceNotification::UserCreateWorkspace), + 11 => ::std::option::Option::Some(WorkspaceNotification::UserDeleteWorkspace), + 12 => ::std::option::Option::Some(WorkspaceNotification::WorkspaceUpdated), + 13 => ::std::option::Option::Some(WorkspaceNotification::WorkspaceCreateApp), + 14 => ::std::option::Option::Some(WorkspaceNotification::WorkspaceDeleteApp), + 15 => ::std::option::Option::Some(WorkspaceNotification::WorkspaceListUpdated), + 21 => ::std::option::Option::Some(WorkspaceNotification::AppUpdated), + 24 => ::std::option::Option::Some(WorkspaceNotification::AppViewsChanged), + 31 => ::std::option::Option::Some(WorkspaceNotification::ViewUpdated), + 100 => ::std::option::Option::Some(WorkspaceNotification::UserUnauthorized), + 1000 => ::std::option::Option::Some(WorkspaceNotification::TrashUpdated), _ => ::std::option::Option::None } } fn values() -> &'static [Self] { - static values: &'static [Notification] = &[ - Notification::Unknown, - Notification::UserCreateWorkspace, - Notification::UserDeleteWorkspace, - Notification::WorkspaceUpdated, - Notification::WorkspaceCreateApp, - Notification::WorkspaceDeleteApp, - Notification::WorkspaceListUpdated, - Notification::AppUpdated, - Notification::AppViewsChanged, - Notification::ViewUpdated, - Notification::UserUnauthorized, + static values: &'static [WorkspaceNotification] = &[ + WorkspaceNotification::Unknown, + WorkspaceNotification::UserCreateWorkspace, + WorkspaceNotification::UserDeleteWorkspace, + WorkspaceNotification::WorkspaceUpdated, + WorkspaceNotification::WorkspaceCreateApp, + WorkspaceNotification::WorkspaceDeleteApp, + WorkspaceNotification::WorkspaceListUpdated, + WorkspaceNotification::AppUpdated, + WorkspaceNotification::AppViewsChanged, + WorkspaceNotification::ViewUpdated, + WorkspaceNotification::UserUnauthorized, + WorkspaceNotification::TrashUpdated, ]; values } @@ -80,58 +83,61 @@ impl ::protobuf::ProtobufEnum for Notification { fn enum_descriptor_static() -> &'static ::protobuf::reflect::EnumDescriptor { static descriptor: ::protobuf::rt::LazyV2<::protobuf::reflect::EnumDescriptor> = ::protobuf::rt::LazyV2::INIT; descriptor.get(|| { - ::protobuf::reflect::EnumDescriptor::new_pb_name::("Notification", file_descriptor_proto()) + ::protobuf::reflect::EnumDescriptor::new_pb_name::("WorkspaceNotification", file_descriptor_proto()) }) } } -impl ::std::marker::Copy for Notification { +impl ::std::marker::Copy for WorkspaceNotification { } -impl ::std::default::Default for Notification { +impl ::std::default::Default for WorkspaceNotification { fn default() -> Self { - Notification::Unknown + WorkspaceNotification::Unknown } } -impl ::protobuf::reflect::ProtobufValue for Notification { +impl ::protobuf::reflect::ProtobufValue for WorkspaceNotification { fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { ::protobuf::reflect::ReflectValueRef::Enum(::protobuf::ProtobufEnum::descriptor(self)) } } static file_descriptor_proto_data: &'static [u8] = b"\ - \n\x10observable.proto*\xf9\x01\n\x0cNotification\x12\x0b\n\x07Unknown\ - \x10\0\x12\x17\n\x13UserCreateWorkspace\x10\n\x12\x17\n\x13UserDeleteWor\ - kspace\x10\x0b\x12\x14\n\x10WorkspaceUpdated\x10\x0c\x12\x16\n\x12Worksp\ - aceCreateApp\x10\r\x12\x16\n\x12WorkspaceDeleteApp\x10\x0e\x12\x18\n\x14\ - WorkspaceListUpdated\x10\x0f\x12\x0e\n\nAppUpdated\x10\x15\x12\x13\n\x0f\ - AppViewsChanged\x10\x18\x12\x0f\n\x0bViewUpdated\x10\x1f\x12\x14\n\x10Us\ - erUnauthorized\x10dJ\xed\x03\n\x06\x12\x04\0\0\x0e\x01\n\x08\n\x01\x0c\ - \x12\x03\0\0\x12\n\n\n\x02\x05\0\x12\x04\x02\0\x0e\x01\n\n\n\x03\x05\0\ - \x01\x12\x03\x02\x05\x11\n\x0b\n\x04\x05\0\x02\0\x12\x03\x03\x04\x10\n\ - \x0c\n\x05\x05\0\x02\0\x01\x12\x03\x03\x04\x0b\n\x0c\n\x05\x05\0\x02\0\ - \x02\x12\x03\x03\x0e\x0f\n\x0b\n\x04\x05\0\x02\x01\x12\x03\x04\x04\x1d\n\ - \x0c\n\x05\x05\0\x02\x01\x01\x12\x03\x04\x04\x17\n\x0c\n\x05\x05\0\x02\ - \x01\x02\x12\x03\x04\x1a\x1c\n\x0b\n\x04\x05\0\x02\x02\x12\x03\x05\x04\ - \x1d\n\x0c\n\x05\x05\0\x02\x02\x01\x12\x03\x05\x04\x17\n\x0c\n\x05\x05\0\ - \x02\x02\x02\x12\x03\x05\x1a\x1c\n\x0b\n\x04\x05\0\x02\x03\x12\x03\x06\ - \x04\x1a\n\x0c\n\x05\x05\0\x02\x03\x01\x12\x03\x06\x04\x14\n\x0c\n\x05\ - \x05\0\x02\x03\x02\x12\x03\x06\x17\x19\n\x0b\n\x04\x05\0\x02\x04\x12\x03\ - \x07\x04\x1c\n\x0c\n\x05\x05\0\x02\x04\x01\x12\x03\x07\x04\x16\n\x0c\n\ - \x05\x05\0\x02\x04\x02\x12\x03\x07\x19\x1b\n\x0b\n\x04\x05\0\x02\x05\x12\ - \x03\x08\x04\x1c\n\x0c\n\x05\x05\0\x02\x05\x01\x12\x03\x08\x04\x16\n\x0c\ - \n\x05\x05\0\x02\x05\x02\x12\x03\x08\x19\x1b\n\x0b\n\x04\x05\0\x02\x06\ - \x12\x03\t\x04\x1e\n\x0c\n\x05\x05\0\x02\x06\x01\x12\x03\t\x04\x18\n\x0c\ - \n\x05\x05\0\x02\x06\x02\x12\x03\t\x1b\x1d\n\x0b\n\x04\x05\0\x02\x07\x12\ - \x03\n\x04\x14\n\x0c\n\x05\x05\0\x02\x07\x01\x12\x03\n\x04\x0e\n\x0c\n\ - \x05\x05\0\x02\x07\x02\x12\x03\n\x11\x13\n\x0b\n\x04\x05\0\x02\x08\x12\ - \x03\x0b\x04\x19\n\x0c\n\x05\x05\0\x02\x08\x01\x12\x03\x0b\x04\x13\n\x0c\ - \n\x05\x05\0\x02\x08\x02\x12\x03\x0b\x16\x18\n\x0b\n\x04\x05\0\x02\t\x12\ - \x03\x0c\x04\x15\n\x0c\n\x05\x05\0\x02\t\x01\x12\x03\x0c\x04\x0f\n\x0c\n\ - \x05\x05\0\x02\t\x02\x12\x03\x0c\x12\x14\n\x0b\n\x04\x05\0\x02\n\x12\x03\ - \r\x04\x1b\n\x0c\n\x05\x05\0\x02\n\x01\x12\x03\r\x04\x14\n\x0c\n\x05\x05\ - \0\x02\n\x02\x12\x03\r\x17\x1ab\x06proto3\ + \n\x10observable.proto*\x95\x02\n\x15WorkspaceNotification\x12\x0b\n\x07\ + Unknown\x10\0\x12\x17\n\x13UserCreateWorkspace\x10\n\x12\x17\n\x13UserDe\ + leteWorkspace\x10\x0b\x12\x14\n\x10WorkspaceUpdated\x10\x0c\x12\x16\n\ + \x12WorkspaceCreateApp\x10\r\x12\x16\n\x12WorkspaceDeleteApp\x10\x0e\x12\ + \x18\n\x14WorkspaceListUpdated\x10\x0f\x12\x0e\n\nAppUpdated\x10\x15\x12\ + \x13\n\x0fAppViewsChanged\x10\x18\x12\x0f\n\x0bViewUpdated\x10\x1f\x12\ + \x14\n\x10UserUnauthorized\x10d\x12\x11\n\x0cTrashUpdated\x10\xe8\x07J\ + \x96\x04\n\x06\x12\x04\0\0\x0f\x01\n\x08\n\x01\x0c\x12\x03\0\0\x12\n\n\n\ + \x02\x05\0\x12\x04\x02\0\x0f\x01\n\n\n\x03\x05\0\x01\x12\x03\x02\x05\x1a\ + \n\x0b\n\x04\x05\0\x02\0\x12\x03\x03\x04\x10\n\x0c\n\x05\x05\0\x02\0\x01\ + \x12\x03\x03\x04\x0b\n\x0c\n\x05\x05\0\x02\0\x02\x12\x03\x03\x0e\x0f\n\ + \x0b\n\x04\x05\0\x02\x01\x12\x03\x04\x04\x1d\n\x0c\n\x05\x05\0\x02\x01\ + \x01\x12\x03\x04\x04\x17\n\x0c\n\x05\x05\0\x02\x01\x02\x12\x03\x04\x1a\ + \x1c\n\x0b\n\x04\x05\0\x02\x02\x12\x03\x05\x04\x1d\n\x0c\n\x05\x05\0\x02\ + \x02\x01\x12\x03\x05\x04\x17\n\x0c\n\x05\x05\0\x02\x02\x02\x12\x03\x05\ + \x1a\x1c\n\x0b\n\x04\x05\0\x02\x03\x12\x03\x06\x04\x1a\n\x0c\n\x05\x05\0\ + \x02\x03\x01\x12\x03\x06\x04\x14\n\x0c\n\x05\x05\0\x02\x03\x02\x12\x03\ + \x06\x17\x19\n\x0b\n\x04\x05\0\x02\x04\x12\x03\x07\x04\x1c\n\x0c\n\x05\ + \x05\0\x02\x04\x01\x12\x03\x07\x04\x16\n\x0c\n\x05\x05\0\x02\x04\x02\x12\ + \x03\x07\x19\x1b\n\x0b\n\x04\x05\0\x02\x05\x12\x03\x08\x04\x1c\n\x0c\n\ + \x05\x05\0\x02\x05\x01\x12\x03\x08\x04\x16\n\x0c\n\x05\x05\0\x02\x05\x02\ + \x12\x03\x08\x19\x1b\n\x0b\n\x04\x05\0\x02\x06\x12\x03\t\x04\x1e\n\x0c\n\ + \x05\x05\0\x02\x06\x01\x12\x03\t\x04\x18\n\x0c\n\x05\x05\0\x02\x06\x02\ + \x12\x03\t\x1b\x1d\n\x0b\n\x04\x05\0\x02\x07\x12\x03\n\x04\x14\n\x0c\n\ + \x05\x05\0\x02\x07\x01\x12\x03\n\x04\x0e\n\x0c\n\x05\x05\0\x02\x07\x02\ + \x12\x03\n\x11\x13\n\x0b\n\x04\x05\0\x02\x08\x12\x03\x0b\x04\x19\n\x0c\n\ + \x05\x05\0\x02\x08\x01\x12\x03\x0b\x04\x13\n\x0c\n\x05\x05\0\x02\x08\x02\ + \x12\x03\x0b\x16\x18\n\x0b\n\x04\x05\0\x02\t\x12\x03\x0c\x04\x15\n\x0c\n\ + \x05\x05\0\x02\t\x01\x12\x03\x0c\x04\x0f\n\x0c\n\x05\x05\0\x02\t\x02\x12\ + \x03\x0c\x12\x14\n\x0b\n\x04\x05\0\x02\n\x12\x03\r\x04\x1b\n\x0c\n\x05\ + \x05\0\x02\n\x01\x12\x03\r\x04\x14\n\x0c\n\x05\x05\0\x02\n\x02\x12\x03\r\ + \x17\x1a\n\x0b\n\x04\x05\0\x02\x0b\x12\x03\x0e\x04\x18\n\x0c\n\x05\x05\0\ + \x02\x0b\x01\x12\x03\x0e\x04\x10\n\x0c\n\x05\x05\0\x02\x0b\x02\x12\x03\ + \x0e\x13\x17b\x06proto3\ "; static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT; diff --git a/rust-lib/flowy-workspace/src/protobuf/proto/observable.proto b/rust-lib/flowy-workspace/src/protobuf/proto/observable.proto index 6c232a74e6..869c77efb8 100644 --- a/rust-lib/flowy-workspace/src/protobuf/proto/observable.proto +++ b/rust-lib/flowy-workspace/src/protobuf/proto/observable.proto @@ -1,6 +1,6 @@ syntax = "proto3"; -enum Notification { +enum WorkspaceNotification { Unknown = 0; UserCreateWorkspace = 10; UserDeleteWorkspace = 11; @@ -12,4 +12,5 @@ enum Notification { AppViewsChanged = 24; ViewUpdated = 31; UserUnauthorized = 100; + TrashUpdated = 1000; } diff --git a/rust-lib/flowy-workspace/src/services/app_controller.rs b/rust-lib/flowy-workspace/src/services/app_controller.rs index e22b86808b..205b79c50a 100644 --- a/rust-lib/flowy-workspace/src/services/app_controller.rs +++ b/rust-lib/flowy-workspace/src/services/app_controller.rs @@ -36,7 +36,7 @@ impl AppController { conn.immediate_transaction::<_, WorkspaceError, _>(|| { let _ = self.save_app(app.clone(), &*conn)?; let apps = self.read_local_apps(&app.workspace_id, &*conn)?; - dart_notify(&app.workspace_id, Notification::WorkspaceCreateApp) + send_dart_notification(&app.workspace_id, WorkspaceNotification::WorkspaceCreateApp) .payload(apps) .send(); Ok(()) @@ -65,7 +65,7 @@ impl AppController { conn.immediate_transaction::<_, WorkspaceError, _>(|| { let app = self.sql.delete_app(app_id, &*conn)?; let apps = self.read_local_apps(&app.workspace_id, &*conn)?; - dart_notify(&app.workspace_id, Notification::WorkspaceDeleteApp) + send_dart_notification(&app.workspace_id, WorkspaceNotification::WorkspaceDeleteApp) .payload(apps) .send(); Ok(()) @@ -88,7 +88,9 @@ impl AppController { conn.immediate_transaction::<_, WorkspaceError, _>(|| { let _ = self.sql.update_app(changeset, conn)?; let app: App = self.sql.read_app(&app_id, None, conn)?.into(); - dart_notify(&app_id, Notification::AppUpdated).payload(app).send(); + send_dart_notification(&app_id, WorkspaceNotification::AppUpdated) + .payload(app) + .send(); Ok(()) })?; diff --git a/rust-lib/flowy-workspace/src/services/server/middleware.rs b/rust-lib/flowy-workspace/src/services/server/middleware.rs index b5d9fccb7b..5cb6205f05 100644 --- a/rust-lib/flowy-workspace/src/services/server/middleware.rs +++ b/rust-lib/flowy-workspace/src/services/server/middleware.rs @@ -21,7 +21,9 @@ impl ResponseMiddleware for WorkspaceMiddleware { None => {}, Some(token) => { let error = WorkspaceError::new(ErrorCode::UserUnauthorized, ""); - dart_notify(token, Notification::UserUnauthorized).error(error).send() + send_dart_notification(token, WorkspaceNotification::UserUnauthorized) + .error(error) + .send() }, } } diff --git a/rust-lib/flowy-workspace/src/services/trash_can.rs b/rust-lib/flowy-workspace/src/services/trash_can.rs index b5c688f858..bccf8ffb5e 100644 --- a/rust-lib/flowy-workspace/src/services/trash_can.rs +++ b/rust-lib/flowy-workspace/src/services/trash_can.rs @@ -2,6 +2,7 @@ use crate::{ entities::trash::{RepeatedTrash, Trash}, errors::{WorkspaceError, WorkspaceResult}, module::WorkspaceDatabase, + notify::{send_anonymous_dart_notification, WorkspaceNotification}, sql_tables::trash::{TrashSource, TrashTable, TrashTableSql}, }; use flowy_database::SqliteConnection; @@ -60,16 +61,20 @@ impl TrashCan { #[tracing::instrument(level = "debug", skip(self), fields(putback) err)] pub fn putback(&self, trash_id: &str) -> WorkspaceResult<()> { let conn = self.database.db_connection()?; - // Opti: transaction - let trash_table = TrashTableSql::read(trash_id, &*conn)?; - let _ = TrashTableSql::delete_trash(trash_id, &*conn)?; - tracing::Span::current().record( - "putback", - &format!("{:?}: {}", &trash_table.source, trash_table.id).as_str(), - ); + let _ = conn.immediate_transaction::<_, WorkspaceError, _>(|| { + let trash_table = TrashTableSql::read(trash_id, &*conn)?; + let _ = TrashTableSql::delete_trash(trash_id, &*conn)?; + tracing::Span::current().record( + "putback", + &format!("{:?}: {}", &trash_table.source, trash_table.id).as_str(), + ); - self.notify - .send(TrashEvent::Putback(trash_table.source, trash_table.id)); + self.notify + .send(TrashEvent::Putback(trash_table.source, trash_table.id)); + + let _ = self.notify_dart_trash_did_update(&conn)?; + Ok(()) + })?; Ok(()) } @@ -80,7 +85,7 @@ impl TrashCan { let trash_table = TrashTableSql::read(trash_id, &*conn)?; let _ = TrashTableSql::delete_trash(trash_id, &*conn)?; - self.notify.send(TrashEvent::Delete(trash_table.source, trash_table.id)); + let _ = self.notify.send(TrashEvent::Delete(trash_table.source, trash_table.id)); Ok(()) } @@ -108,8 +113,19 @@ impl TrashCan { &format!("{:?}: {}", &trash_table.source, trash_table.id).as_str(), ); - let trash_id = trash_table.id.clone(); let _ = TrashTableSql::create_trash(trash_table, &*conn)?; + let _ = self.notify_dart_trash_did_update(&conn)?; + + Ok(()) + } + + fn notify_dart_trash_did_update(&self, conn: &SqliteConnection) -> WorkspaceResult<()> { + // Opti: only push the changeset + let repeated_trash = TrashTableSql::read_all(conn)?; + send_anonymous_dart_notification(WorkspaceNotification::TrashUpdated) + .payload(repeated_trash) + .send(); + Ok(()) } } diff --git a/rust-lib/flowy-workspace/src/services/view_controller.rs b/rust-lib/flowy-workspace/src/services/view_controller.rs index 25296e871b..85668ce010 100644 --- a/rust-lib/flowy-workspace/src/services/view_controller.rs +++ b/rust-lib/flowy-workspace/src/services/view_controller.rs @@ -2,7 +2,7 @@ use crate::{ entities::view::{CreateViewParams, UpdateViewParams, View}, errors::WorkspaceError, module::WorkspaceDatabase, - notify::dart_notify, + notify::send_dart_notification, services::{helper::spawn, server::Server}, sql_tables::view::{ViewTable, ViewTableChangeset, ViewTableSql}, }; @@ -14,7 +14,7 @@ use crate::{ }, errors::internal_error, module::WorkspaceUser, - notify::Notification, + notify::WorkspaceNotification, services::{TrashCan, TrashEvent}, sql_tables::trash::TrashSource, }; @@ -70,7 +70,7 @@ impl ViewController { self.document.create(CreateDocParams::new(&view.id, params.data))?; let repeated_view = ViewTableSql::read_views(&view.belong_to_id, conn)?; - dart_notify(&view.belong_to_id, Notification::AppViewsChanged) + send_dart_notification(&view.belong_to_id, WorkspaceNotification::AppViewsChanged) .payload(repeated_view) .send(); Ok(()) @@ -110,7 +110,7 @@ impl ViewController { let repeated_view = ViewTableSql::read_views(&view_table.belong_to_id, conn)?; - dart_notify(&view_table.belong_to_id, Notification::AppViewsChanged) + send_dart_notification(&view_table.belong_to_id, WorkspaceNotification::AppViewsChanged) .payload(repeated_view) .send(); Ok(()) @@ -139,7 +139,7 @@ impl ViewController { let view: View = ViewTableSql::read_view(&view_id, conn)?.into(); match params.is_trash { None => { - dart_notify(&view_id, Notification::ViewUpdated) + send_dart_notification(&view_id, WorkspaceNotification::ViewUpdated) .payload(view.clone()) .send(); }, @@ -245,7 +245,7 @@ impl ViewController { fn notify_view_num_did_change(belong_to_id: &str, conn: &SqliteConnection) -> WorkspaceResult<()> { let repeated_view = ViewTableSql::read_views(belong_to_id, conn)?; - dart_notify(belong_to_id, Notification::AppViewsChanged) + send_dart_notification(belong_to_id, WorkspaceNotification::AppViewsChanged) .payload(repeated_view) .send(); Ok(()) diff --git a/rust-lib/flowy-workspace/src/services/workspace_controller.rs b/rust-lib/flowy-workspace/src/services/workspace_controller.rs index a244877466..b49115d2c7 100644 --- a/rust-lib/flowy-workspace/src/services/workspace_controller.rs +++ b/rust-lib/flowy-workspace/src/services/workspace_controller.rs @@ -69,7 +69,7 @@ impl WorkspaceController { conn.immediate_transaction::<_, WorkspaceError, _>(|| { self.workspace_sql.create_workspace(workspace_table, conn)?; let repeated_workspace = self.read_local_workspaces(None, &user_id, conn)?; - dart_notify(&token, Notification::UserCreateWorkspace) + send_dart_notification(&token, WorkspaceNotification::UserCreateWorkspace) .payload(repeated_workspace) .send(); @@ -88,7 +88,7 @@ impl WorkspaceController { let _ = self.workspace_sql.update_workspace(changeset, conn)?; let user_id = self.user.user_id()?; let workspace = self.read_local_workspace(workspace_id.clone(), &user_id, conn)?; - dart_notify(&workspace_id, Notification::WorkspaceUpdated) + send_dart_notification(&workspace_id, WorkspaceNotification::WorkspaceUpdated) .payload(workspace) .send(); @@ -108,7 +108,7 @@ impl WorkspaceController { conn.immediate_transaction::<_, WorkspaceError, _>(|| { let _ = self.workspace_sql.delete_workspace(workspace_id, conn)?; let repeated_workspace = self.read_local_workspaces(None, &user_id, conn)?; - dart_notify(&token, Notification::UserDeleteWorkspace) + send_dart_notification(&token, WorkspaceNotification::UserDeleteWorkspace) .payload(repeated_workspace) .send(); @@ -297,7 +297,7 @@ impl WorkspaceController { Ok(()) })?; - dart_notify(&token, Notification::WorkspaceListUpdated) + send_dart_notification(&token, WorkspaceNotification::WorkspaceListUpdated) .payload(workspaces) .send(); Result::<(), WorkspaceError>::Ok(())