From b0df64138fe0c90864702f57d7f3022da93452eb Mon Sep 17 00:00:00 2001 From: appflowy Date: Sat, 24 Jul 2021 18:55:13 +0800 Subject: [PATCH] config doc bloc --- .../lib/startup/tasks/rust_sdk_init_task.dart | 3 +- .../welcome/infrastructure/deps_resolver.dart | 4 +- .../workspace/application/doc/doc_bloc.dart | 39 ++ .../application/doc/doc_bloc.freezed.dart | 498 ++++++++++++++++++ .../application/{ => home}/home_bloc.dart | 0 .../{ => home}/home_bloc.freezed.dart | 0 .../{watcher => home}/home_watcher_bloc.dart | 15 +- .../home_watcher_bloc.freezed.dart | 0 .../watcher/home_watcher_event.dart | 7 - .../watcher/home_watcher_state.dart | 7 - .../infrastructure/deps_resolver.dart | 4 + .../workspace/infrastructure/i_doc_impl.dart | 3 +- .../presentation/doc/editor_widget.dart | 33 +- .../presentation/home/home_layout.dart | 2 +- .../presentation/home/home_screen.dart | 4 +- .../presentation/view/view_widget.dart | 7 +- .../protobuf/flowy-user/errors.pbenum.dart | 2 + .../protobuf/flowy-user/errors.pbjson.dart | 3 +- rust-lib/flowy-database/src/macros.rs | 2 +- rust-lib/flowy-dispatch/src/data.rs | 4 +- rust-lib/flowy-dispatch/src/errors/errors.rs | 18 +- .../flowy-dispatch/src/response/builder.rs | 8 - .../flowy-dispatch/src/response/response.rs | 6 - .../flowy-editor/src/handlers/doc_handler.rs | 2 +- .../src/deps_resolve/workspace_deps_impl.rs | 3 +- rust-lib/flowy-sdk/src/flowy_server.rs | 10 +- rust-lib/flowy-user/Cargo.toml | 1 + rust-lib/flowy-user/src/errors.rs | 9 +- .../flowy-user/src/handlers/auth_handler.rs | 8 +- .../flowy-user/src/protobuf/model/errors.rs | 103 ++-- .../src/protobuf/proto/errors.proto | 1 + .../src/services/user_session/user_session.rs | 1 - .../src/services/workspace_controller.rs | 2 - 33 files changed, 676 insertions(+), 133 deletions(-) create mode 100644 app_flowy/lib/workspace/application/doc/doc_bloc.dart create mode 100644 app_flowy/lib/workspace/application/doc/doc_bloc.freezed.dart rename app_flowy/lib/workspace/application/{ => home}/home_bloc.dart (100%) rename app_flowy/lib/workspace/application/{ => home}/home_bloc.freezed.dart (100%) rename app_flowy/lib/workspace/application/{watcher => home}/home_watcher_bloc.dart (53%) rename app_flowy/lib/workspace/application/{watcher => home}/home_watcher_bloc.freezed.dart (100%) delete mode 100644 app_flowy/lib/workspace/application/watcher/home_watcher_event.dart delete mode 100644 app_flowy/lib/workspace/application/watcher/home_watcher_state.dart diff --git a/app_flowy/lib/startup/tasks/rust_sdk_init_task.dart b/app_flowy/lib/startup/tasks/rust_sdk_init_task.dart index 4f57190761..c5067b2cc9 100644 --- a/app_flowy/lib/startup/tasks/rust_sdk_init_task.dart +++ b/app_flowy/lib/startup/tasks/rust_sdk_init_task.dart @@ -38,8 +38,9 @@ class RustSDKInitTask extends LaunchTask { class ApplicationBlocObserver extends BlocObserver { @override + // ignore: unnecessary_overrides void onTransition(Bloc bloc, Transition transition) { - Log.debug(transition); + // Log.debug(transition); super.onTransition(bloc, transition); } diff --git a/app_flowy/lib/welcome/infrastructure/deps_resolver.dart b/app_flowy/lib/welcome/infrastructure/deps_resolver.dart index 070301e799..18024e9038 100644 --- a/app_flowy/lib/welcome/infrastructure/deps_resolver.dart +++ b/app_flowy/lib/welcome/infrastructure/deps_resolver.dart @@ -1,8 +1,8 @@ import 'package:app_flowy/workspace/application/edit_pannel/edit_pannel_bloc.dart'; -import 'package:app_flowy/workspace/application/home_bloc.dart'; -import 'package:app_flowy/workspace/application/watcher/home_watcher_bloc.dart'; import 'package:app_flowy/welcome/application/welcome_bloc.dart'; import 'package:app_flowy/welcome/infrastructure/i_welcome_impl.dart'; +import 'package:app_flowy/workspace/application/home/home_bloc.dart'; +import 'package:app_flowy/workspace/application/home/home_watcher_bloc.dart'; import 'package:get_it/get_it.dart'; class WelcomeDepsResolver { diff --git a/app_flowy/lib/workspace/application/doc/doc_bloc.dart b/app_flowy/lib/workspace/application/doc/doc_bloc.dart new file mode 100644 index 0000000000..27f3b0f5a0 --- /dev/null +++ b/app_flowy/lib/workspace/application/doc/doc_bloc.dart @@ -0,0 +1,39 @@ +import 'package:app_flowy/workspace/domain/i_doc.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:dartz/dartz.dart'; + +part 'doc_bloc.freezed.dart'; + +class DocBloc extends Bloc { + final IDoc iDocImpl; + + DocBloc(this.iDocImpl) : super(DocState.initial()); + + @override + Stream mapEventToState(DocEvent event) async* { + yield* event.map( + initial: (e) async* {}, + save: (Save value) async* {}, + close: (Close value) async* {}, + ); + } +} + +@freezed +abstract class DocEvent with _$DocEvent { + const factory DocEvent.initial() = Initial; + const factory DocEvent.save(String jsonStr) = Save; + const factory DocEvent.close() = Close; +} + +@freezed +abstract class DocState implements _$DocState { + const factory DocState({ + required bool isSaving, + }) = _DocState; + + factory DocState.initial() => const DocState( + isSaving: false, + ); +} diff --git a/app_flowy/lib/workspace/application/doc/doc_bloc.freezed.dart b/app_flowy/lib/workspace/application/doc/doc_bloc.freezed.dart new file mode 100644 index 0000000000..1e74f06c09 --- /dev/null +++ b/app_flowy/lib/workspace/application/doc/doc_bloc.freezed.dart @@ -0,0 +1,498 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides + +part of 'doc_bloc.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more informations: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + +/// @nodoc +class _$DocEventTearOff { + const _$DocEventTearOff(); + + Initial initial() { + return const Initial(); + } + + Save save(String jsonStr) { + return Save( + jsonStr, + ); + } + + Close close() { + return const Close(); + } +} + +/// @nodoc +const $DocEvent = _$DocEventTearOff(); + +/// @nodoc +mixin _$DocEvent { + @optionalTypeArgs + TResult when({ + required TResult Function() initial, + required TResult Function(String jsonStr) save, + required TResult Function() close, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? initial, + TResult Function(String jsonStr)? save, + TResult Function()? close, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult map({ + required TResult Function(Initial value) initial, + required TResult Function(Save value) save, + required TResult Function(Close value) close, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeMap({ + TResult Function(Initial value)? initial, + TResult Function(Save value)? save, + TResult Function(Close value)? close, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $DocEventCopyWith<$Res> { + factory $DocEventCopyWith(DocEvent value, $Res Function(DocEvent) then) = + _$DocEventCopyWithImpl<$Res>; +} + +/// @nodoc +class _$DocEventCopyWithImpl<$Res> implements $DocEventCopyWith<$Res> { + _$DocEventCopyWithImpl(this._value, this._then); + + final DocEvent _value; + // ignore: unused_field + final $Res Function(DocEvent) _then; +} + +/// @nodoc +abstract class $InitialCopyWith<$Res> { + factory $InitialCopyWith(Initial value, $Res Function(Initial) then) = + _$InitialCopyWithImpl<$Res>; +} + +/// @nodoc +class _$InitialCopyWithImpl<$Res> extends _$DocEventCopyWithImpl<$Res> + implements $InitialCopyWith<$Res> { + _$InitialCopyWithImpl(Initial _value, $Res Function(Initial) _then) + : super(_value, (v) => _then(v as Initial)); + + @override + Initial get _value => super._value as Initial; +} + +/// @nodoc + +class _$Initial implements Initial { + const _$Initial(); + + @override + String toString() { + return 'DocEvent.initial()'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || (other is Initial); + } + + @override + int get hashCode => runtimeType.hashCode; + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() initial, + required TResult Function(String jsonStr) save, + required TResult Function() close, + }) { + return initial(); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? initial, + TResult Function(String jsonStr)? save, + TResult Function()? close, + required TResult orElse(), + }) { + if (initial != null) { + return initial(); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(Initial value) initial, + required TResult Function(Save value) save, + required TResult Function(Close value) close, + }) { + return initial(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(Initial value)? initial, + TResult Function(Save value)? save, + TResult Function(Close value)? close, + required TResult orElse(), + }) { + if (initial != null) { + return initial(this); + } + return orElse(); + } +} + +abstract class Initial implements DocEvent { + const factory Initial() = _$Initial; +} + +/// @nodoc +abstract class $SaveCopyWith<$Res> { + factory $SaveCopyWith(Save value, $Res Function(Save) then) = + _$SaveCopyWithImpl<$Res>; + $Res call({String jsonStr}); +} + +/// @nodoc +class _$SaveCopyWithImpl<$Res> extends _$DocEventCopyWithImpl<$Res> + implements $SaveCopyWith<$Res> { + _$SaveCopyWithImpl(Save _value, $Res Function(Save) _then) + : super(_value, (v) => _then(v as Save)); + + @override + Save get _value => super._value as Save; + + @override + $Res call({ + Object? jsonStr = freezed, + }) { + return _then(Save( + jsonStr == freezed + ? _value.jsonStr + : jsonStr // ignore: cast_nullable_to_non_nullable + as String, + )); + } +} + +/// @nodoc + +class _$Save implements Save { + const _$Save(this.jsonStr); + + @override + final String jsonStr; + + @override + String toString() { + return 'DocEvent.save(jsonStr: $jsonStr)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other is Save && + (identical(other.jsonStr, jsonStr) || + const DeepCollectionEquality().equals(other.jsonStr, jsonStr))); + } + + @override + int get hashCode => + runtimeType.hashCode ^ const DeepCollectionEquality().hash(jsonStr); + + @JsonKey(ignore: true) + @override + $SaveCopyWith get copyWith => + _$SaveCopyWithImpl(this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() initial, + required TResult Function(String jsonStr) save, + required TResult Function() close, + }) { + return save(jsonStr); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? initial, + TResult Function(String jsonStr)? save, + TResult Function()? close, + required TResult orElse(), + }) { + if (save != null) { + return save(jsonStr); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(Initial value) initial, + required TResult Function(Save value) save, + required TResult Function(Close value) close, + }) { + return save(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(Initial value)? initial, + TResult Function(Save value)? save, + TResult Function(Close value)? close, + required TResult orElse(), + }) { + if (save != null) { + return save(this); + } + return orElse(); + } +} + +abstract class Save implements DocEvent { + const factory Save(String jsonStr) = _$Save; + + String get jsonStr => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + $SaveCopyWith get copyWith => throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $CloseCopyWith<$Res> { + factory $CloseCopyWith(Close value, $Res Function(Close) then) = + _$CloseCopyWithImpl<$Res>; +} + +/// @nodoc +class _$CloseCopyWithImpl<$Res> extends _$DocEventCopyWithImpl<$Res> + implements $CloseCopyWith<$Res> { + _$CloseCopyWithImpl(Close _value, $Res Function(Close) _then) + : super(_value, (v) => _then(v as Close)); + + @override + Close get _value => super._value as Close; +} + +/// @nodoc + +class _$Close implements Close { + const _$Close(); + + @override + String toString() { + return 'DocEvent.close()'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || (other is Close); + } + + @override + int get hashCode => runtimeType.hashCode; + + @override + @optionalTypeArgs + TResult when({ + required TResult Function() initial, + required TResult Function(String jsonStr) save, + required TResult Function() close, + }) { + return close(); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function()? initial, + TResult Function(String jsonStr)? save, + TResult Function()? close, + required TResult orElse(), + }) { + if (close != null) { + return close(); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(Initial value) initial, + required TResult Function(Save value) save, + required TResult Function(Close value) close, + }) { + return close(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(Initial value)? initial, + TResult Function(Save value)? save, + TResult Function(Close value)? close, + required TResult orElse(), + }) { + if (close != null) { + return close(this); + } + return orElse(); + } +} + +abstract class Close implements DocEvent { + const factory Close() = _$Close; +} + +/// @nodoc +class _$DocStateTearOff { + const _$DocStateTearOff(); + + _DocState call({required bool isSaving}) { + return _DocState( + isSaving: isSaving, + ); + } +} + +/// @nodoc +const $DocState = _$DocStateTearOff(); + +/// @nodoc +mixin _$DocState { + bool get isSaving => throw _privateConstructorUsedError; + + @JsonKey(ignore: true) + $DocStateCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $DocStateCopyWith<$Res> { + factory $DocStateCopyWith(DocState value, $Res Function(DocState) then) = + _$DocStateCopyWithImpl<$Res>; + $Res call({bool isSaving}); +} + +/// @nodoc +class _$DocStateCopyWithImpl<$Res> implements $DocStateCopyWith<$Res> { + _$DocStateCopyWithImpl(this._value, this._then); + + final DocState _value; + // ignore: unused_field + final $Res Function(DocState) _then; + + @override + $Res call({ + Object? isSaving = freezed, + }) { + return _then(_value.copyWith( + isSaving: isSaving == freezed + ? _value.isSaving + : isSaving // ignore: cast_nullable_to_non_nullable + as bool, + )); + } +} + +/// @nodoc +abstract class _$DocStateCopyWith<$Res> implements $DocStateCopyWith<$Res> { + factory _$DocStateCopyWith(_DocState value, $Res Function(_DocState) then) = + __$DocStateCopyWithImpl<$Res>; + @override + $Res call({bool isSaving}); +} + +/// @nodoc +class __$DocStateCopyWithImpl<$Res> extends _$DocStateCopyWithImpl<$Res> + implements _$DocStateCopyWith<$Res> { + __$DocStateCopyWithImpl(_DocState _value, $Res Function(_DocState) _then) + : super(_value, (v) => _then(v as _DocState)); + + @override + _DocState get _value => super._value as _DocState; + + @override + $Res call({ + Object? isSaving = freezed, + }) { + return _then(_DocState( + isSaving: isSaving == freezed + ? _value.isSaving + : isSaving // ignore: cast_nullable_to_non_nullable + as bool, + )); + } +} + +/// @nodoc + +class _$_DocState implements _DocState { + const _$_DocState({required this.isSaving}); + + @override + final bool isSaving; + + @override + String toString() { + return 'DocState(isSaving: $isSaving)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other is _DocState && + (identical(other.isSaving, isSaving) || + const DeepCollectionEquality() + .equals(other.isSaving, isSaving))); + } + + @override + int get hashCode => + runtimeType.hashCode ^ const DeepCollectionEquality().hash(isSaving); + + @JsonKey(ignore: true) + @override + _$DocStateCopyWith<_DocState> get copyWith => + __$DocStateCopyWithImpl<_DocState>(this, _$identity); +} + +abstract class _DocState implements DocState { + const factory _DocState({required bool isSaving}) = _$_DocState; + + @override + bool get isSaving => throw _privateConstructorUsedError; + @override + @JsonKey(ignore: true) + _$DocStateCopyWith<_DocState> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/app_flowy/lib/workspace/application/home_bloc.dart b/app_flowy/lib/workspace/application/home/home_bloc.dart similarity index 100% rename from app_flowy/lib/workspace/application/home_bloc.dart rename to app_flowy/lib/workspace/application/home/home_bloc.dart diff --git a/app_flowy/lib/workspace/application/home_bloc.freezed.dart b/app_flowy/lib/workspace/application/home/home_bloc.freezed.dart similarity index 100% rename from app_flowy/lib/workspace/application/home_bloc.freezed.dart rename to app_flowy/lib/workspace/application/home/home_bloc.freezed.dart diff --git a/app_flowy/lib/workspace/application/watcher/home_watcher_bloc.dart b/app_flowy/lib/workspace/application/home/home_watcher_bloc.dart similarity index 53% rename from app_flowy/lib/workspace/application/watcher/home_watcher_bloc.dart rename to app_flowy/lib/workspace/application/home/home_watcher_bloc.dart index afb787e980..d6d86c59de 100644 --- a/app_flowy/lib/workspace/application/watcher/home_watcher_bloc.dart +++ b/app_flowy/lib/workspace/application/home/home_watcher_bloc.dart @@ -1,10 +1,7 @@ import 'package:flutter/material.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; -// ignore: import_of_legacy_library_into_null_safe import 'package:flutter_bloc/flutter_bloc.dart'; -part 'home_watcher_event.dart'; -part 'home_watcher_state.dart'; part 'home_watcher_bloc.freezed.dart'; class HomeWatcherBloc extends Bloc { @@ -17,3 +14,15 @@ class HomeWatcherBloc extends Bloc { yield state; } } + +@freezed +abstract class HomeWatcherEvent with _$HomeWatcherEvent { + const factory HomeWatcherEvent.started(String workspaceId) = _Started; + const factory HomeWatcherEvent.stop(String workspaceId) = _Stop; +} + +@freezed +abstract class HomeWatcherState with _$HomeWatcherState { + const factory HomeWatcherState.initial() = _Initial; + const factory HomeWatcherState.loading() = _Loading; +} diff --git a/app_flowy/lib/workspace/application/watcher/home_watcher_bloc.freezed.dart b/app_flowy/lib/workspace/application/home/home_watcher_bloc.freezed.dart similarity index 100% rename from app_flowy/lib/workspace/application/watcher/home_watcher_bloc.freezed.dart rename to app_flowy/lib/workspace/application/home/home_watcher_bloc.freezed.dart diff --git a/app_flowy/lib/workspace/application/watcher/home_watcher_event.dart b/app_flowy/lib/workspace/application/watcher/home_watcher_event.dart deleted file mode 100644 index 0bae7a735c..0000000000 --- a/app_flowy/lib/workspace/application/watcher/home_watcher_event.dart +++ /dev/null @@ -1,7 +0,0 @@ -part of 'home_watcher_bloc.dart'; - -@freezed -abstract class HomeWatcherEvent with _$HomeWatcherEvent { - const factory HomeWatcherEvent.started(String workspaceId) = _Started; - const factory HomeWatcherEvent.stop(String workspaceId) = _Stop; -} diff --git a/app_flowy/lib/workspace/application/watcher/home_watcher_state.dart b/app_flowy/lib/workspace/application/watcher/home_watcher_state.dart deleted file mode 100644 index 5081f94af0..0000000000 --- a/app_flowy/lib/workspace/application/watcher/home_watcher_state.dart +++ /dev/null @@ -1,7 +0,0 @@ -part of 'home_watcher_bloc.dart'; - -@freezed -abstract class HomeWatcherState with _$HomeWatcherState { - const factory HomeWatcherState.initial() = _Initial; - const factory HomeWatcherState.loading() = _Loading; -} diff --git a/app_flowy/lib/workspace/infrastructure/deps_resolver.dart b/app_flowy/lib/workspace/infrastructure/deps_resolver.dart index 134033f8de..a01ec4ea24 100644 --- a/app_flowy/lib/workspace/infrastructure/deps_resolver.dart +++ b/app_flowy/lib/workspace/infrastructure/deps_resolver.dart @@ -1,5 +1,6 @@ import 'package:app_flowy/workspace/application/app/app_bloc.dart'; import 'package:app_flowy/workspace/application/app/app_watch_bloc.dart'; +import 'package:app_flowy/workspace/application/doc/doc_bloc.dart'; import 'package:app_flowy/workspace/application/menu/menu_bloc.dart'; import 'package:app_flowy/workspace/application/menu/menu_watch.dart'; import 'package:app_flowy/workspace/application/view/doc_watch_bloc.dart'; @@ -62,6 +63,9 @@ class HomeDepsResolver { getIt.registerFactoryParam( (docId, _) => DocWatchBloc(iDocImpl: getIt(param1: docId))); + getIt.registerFactoryParam( + (docId, _) => DocBloc(getIt(param1: docId))); + // getIt.registerFactoryParam( // (viewId, _) => ViewBloc(iViewImpl: getIt(param1: viewId))); } diff --git a/app_flowy/lib/workspace/infrastructure/i_doc_impl.dart b/app_flowy/lib/workspace/infrastructure/i_doc_impl.dart index 11fe1bd86e..2669f03ae0 100644 --- a/app_flowy/lib/workspace/infrastructure/i_doc_impl.dart +++ b/app_flowy/lib/workspace/infrastructure/i_doc_impl.dart @@ -30,7 +30,8 @@ class IDocImpl extends IDoc { @override Future> updateDoc( {String? name, String? desc, String? text}) { - return repo.updateDoc(name: name, desc: desc, text: text); + final json = jsonEncode(text ?? ""); + return repo.updateDoc(name: name, desc: desc, text: json); } Future> _loadDocument(String path) { diff --git a/app_flowy/lib/workspace/presentation/doc/editor_widget.dart b/app_flowy/lib/workspace/presentation/doc/editor_widget.dart index 51eb04fce3..6cfb809063 100644 --- a/app_flowy/lib/workspace/presentation/doc/editor_widget.dart +++ b/app_flowy/lib/workspace/presentation/doc/editor_widget.dart @@ -1,28 +1,35 @@ import 'dart:io'; +import 'package:app_flowy/startup/startup.dart'; +import 'package:app_flowy/workspace/application/doc/doc_bloc.dart'; import 'package:app_flowy/workspace/domain/i_doc.dart'; import 'package:flowy_editor/flowy_editor.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; class EditorWdiget extends StatelessWidget { final FocusNode _focusNode = FocusNode(); + late EditorController controller; final Doc doc; - EditorWdiget({Key? key, required this.doc}) : super(key: key); - - @override - Widget build(BuildContext context) { - final controller = EditorController( + EditorWdiget({Key? key, required this.doc}) : super(key: key) { + controller = EditorController( document: doc.data, selection: const TextSelection.collapsed(offset: 0), ); + } - return Column( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - _renderEditor(controller), - _renderToolbar(controller), - ], + @override + Widget build(BuildContext context) { + return BlocProvider( + create: (context) => getIt(param1: doc.info.id), + child: Column( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + _renderEditor(controller), + _renderToolbar(controller), + ], + ), ); } @@ -51,4 +58,8 @@ class EditorWdiget extends StatelessWidget { Future _onImageSelection(File file) { throw UnimplementedError(); } + + void save() { + final deltaJson = controller.document.toDelta().toJson(); + } } diff --git a/app_flowy/lib/workspace/presentation/home/home_layout.dart b/app_flowy/lib/workspace/presentation/home/home_layout.dart index c16adb3b0d..5b72593c9b 100644 --- a/app_flowy/lib/workspace/presentation/home/home_layout.dart +++ b/app_flowy/lib/workspace/presentation/home/home_layout.dart @@ -1,4 +1,4 @@ -import 'package:app_flowy/workspace/application/home_bloc.dart'; +import 'package:app_flowy/workspace/application/home/home_bloc.dart'; import 'package:flowy_infra/size.dart'; import 'package:flowy_infra/time/duration.dart'; import 'package:flutter/material.dart'; diff --git a/app_flowy/lib/workspace/presentation/home/home_screen.dart b/app_flowy/lib/workspace/presentation/home/home_screen.dart index 36adc49748..39dfc4e90a 100644 --- a/app_flowy/lib/workspace/presentation/home/home_screen.dart +++ b/app_flowy/lib/workspace/presentation/home/home_screen.dart @@ -1,5 +1,5 @@ -import 'package:app_flowy/workspace/application/home_bloc.dart'; -import 'package:app_flowy/workspace/application/watcher/home_watcher_bloc.dart'; +import 'package:app_flowy/workspace/application/home/home_bloc.dart'; +import 'package:app_flowy/workspace/application/home/home_watcher_bloc.dart'; import 'package:app_flowy/workspace/domain/page_stack/page_stack.dart'; import 'package:app_flowy/workspace/presentation/widgets/prelude.dart'; import 'package:app_flowy/startup/startup.dart'; diff --git a/app_flowy/lib/workspace/presentation/view/view_widget.dart b/app_flowy/lib/workspace/presentation/view/view_widget.dart index 3ecd19c194..5e70770038 100644 --- a/app_flowy/lib/workspace/presentation/view/view_widget.dart +++ b/app_flowy/lib/workspace/presentation/view/view_widget.dart @@ -11,12 +11,7 @@ class ViewWidget extends StatelessWidget { @override Widget build(BuildContext context) { - return InkWell( - onTap: _openView(context), - child: Container( - height: 30, - child: buildContent(), - )); + return InkWell(onTap: _openView(context), child: buildContent()); } Row buildContent() { diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user/errors.pbenum.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user/errors.pbenum.dart index 42ddf173b1..791039fce8 100644 --- a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user/errors.pbenum.dart +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user/errors.pbenum.dart @@ -16,6 +16,7 @@ class UserErrorCode extends $pb.ProtobufEnum { static const UserErrorCode UserDatabaseReadLocked = UserErrorCode._(3, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'UserDatabaseReadLocked'); static const UserErrorCode UserDatabaseDidNotMatch = UserErrorCode._(4, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'UserDatabaseDidNotMatch'); static const UserErrorCode UserDatabaseInternalError = UserErrorCode._(5, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'UserDatabaseInternalError'); + static const UserErrorCode SqlInternalError = UserErrorCode._(6, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'SqlInternalError'); static const UserErrorCode UserNotLoginYet = UserErrorCode._(10, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'UserNotLoginYet'); static const UserErrorCode ReadCurrentIdFailed = UserErrorCode._(11, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'ReadCurrentIdFailed'); static const UserErrorCode WriteCurrentIdFailed = UserErrorCode._(12, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'WriteCurrentIdFailed'); @@ -34,6 +35,7 @@ class UserErrorCode extends $pb.ProtobufEnum { UserDatabaseReadLocked, UserDatabaseDidNotMatch, UserDatabaseInternalError, + SqlInternalError, UserNotLoginYet, ReadCurrentIdFailed, WriteCurrentIdFailed, diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user/errors.pbjson.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user/errors.pbjson.dart index 3bf44c6ee6..9625ae9cff 100644 --- a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user/errors.pbjson.dart +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user/errors.pbjson.dart @@ -18,6 +18,7 @@ const UserErrorCode$json = const { const {'1': 'UserDatabaseReadLocked', '2': 3}, const {'1': 'UserDatabaseDidNotMatch', '2': 4}, const {'1': 'UserDatabaseInternalError', '2': 5}, + const {'1': 'SqlInternalError', '2': 6}, const {'1': 'UserNotLoginYet', '2': 10}, const {'1': 'ReadCurrentIdFailed', '2': 11}, const {'1': 'WriteCurrentIdFailed', '2': 12}, @@ -32,7 +33,7 @@ const UserErrorCode$json = const { }; /// Descriptor for `UserErrorCode`. Decode as a `google.protobuf.EnumDescriptorProto`. -final $typed_data.Uint8List userErrorCodeDescriptor = $convert.base64Decode('Cg1Vc2VyRXJyb3JDb2RlEgsKB1Vua25vd24QABIaChZVc2VyRGF0YWJhc2VJbml0RmFpbGVkEAESGwoXVXNlckRhdGFiYXNlV3JpdGVMb2NrZWQQAhIaChZVc2VyRGF0YWJhc2VSZWFkTG9ja2VkEAMSGwoXVXNlckRhdGFiYXNlRGlkTm90TWF0Y2gQBBIdChlVc2VyRGF0YWJhc2VJbnRlcm5hbEVycm9yEAUSEwoPVXNlck5vdExvZ2luWWV0EAoSFwoTUmVhZEN1cnJlbnRJZEZhaWxlZBALEhgKFFdyaXRlQ3VycmVudElkRmFpbGVkEAwSEAoMRW1haWxJbnZhbGlkEBQSEwoPUGFzc3dvcmRJbnZhbGlkEBUSEwoPVXNlck5hbWVJbnZhbGlkEBYSGAoUVXNlcldvcmtzcGFjZUludmFsaWQQFxIRCg1Vc2VySWRJbnZhbGlkEBgSIAocQ3JlYXRlRGVmYXVsdFdvcmtzcGFjZUZhaWxlZBAZEiAKHERlZmF1bHRXb3Jrc3BhY2VBbHJlYWR5RXhpc3QQGg=='); +final $typed_data.Uint8List userErrorCodeDescriptor = $convert.base64Decode('Cg1Vc2VyRXJyb3JDb2RlEgsKB1Vua25vd24QABIaChZVc2VyRGF0YWJhc2VJbml0RmFpbGVkEAESGwoXVXNlckRhdGFiYXNlV3JpdGVMb2NrZWQQAhIaChZVc2VyRGF0YWJhc2VSZWFkTG9ja2VkEAMSGwoXVXNlckRhdGFiYXNlRGlkTm90TWF0Y2gQBBIdChlVc2VyRGF0YWJhc2VJbnRlcm5hbEVycm9yEAUSFAoQU3FsSW50ZXJuYWxFcnJvchAGEhMKD1VzZXJOb3RMb2dpbllldBAKEhcKE1JlYWRDdXJyZW50SWRGYWlsZWQQCxIYChRXcml0ZUN1cnJlbnRJZEZhaWxlZBAMEhAKDEVtYWlsSW52YWxpZBAUEhMKD1Bhc3N3b3JkSW52YWxpZBAVEhMKD1VzZXJOYW1lSW52YWxpZBAWEhgKFFVzZXJXb3Jrc3BhY2VJbnZhbGlkEBcSEQoNVXNlcklkSW52YWxpZBAYEiAKHENyZWF0ZURlZmF1bHRXb3Jrc3BhY2VGYWlsZWQQGRIgChxEZWZhdWx0V29ya3NwYWNlQWxyZWFkeUV4aXN0EBo='); @$core.Deprecated('Use userErrorDescriptor instead') const UserError$json = const { '1': 'UserError', diff --git a/rust-lib/flowy-database/src/macros.rs b/rust-lib/flowy-database/src/macros.rs index 08ca0e85b8..456d1f2699 100644 --- a/rust-lib/flowy-database/src/macros.rs +++ b/rust-lib/flowy-database/src/macros.rs @@ -10,6 +10,6 @@ macro_rules! diesel_update_table { let affected_row = diesel::update(filter) .set($changeset) .execute(&*$connection)?; - debug_assert_eq!(affected_row, 1); + // debug_assert_eq!(affected_row, 1); }; } diff --git a/rust-lib/flowy-dispatch/src/data.rs b/rust-lib/flowy-dispatch/src/data.rs index 0aaa94d41c..6539a52769 100644 --- a/rust-lib/flowy-dispatch/src/data.rs +++ b/rust-lib/flowy-dispatch/src/data.rs @@ -36,7 +36,7 @@ where Payload::None => ready(Err(unexpected_none_payload(req))), Payload::Bytes(bytes) => match T::parse_from_bytes(bytes) { Ok(data) => ready(Ok(Data(data))), - Err(e) => ready(Err(InternalError::new(format!("{:?}", e)).into())), + Err(e) => ready(Err(InternalError::new(format!("{}", e)).into())), }, } } @@ -50,7 +50,7 @@ where match self.into_inner().into_bytes() { Ok(bytes) => ResponseBuilder::Ok().data(bytes.to_vec()).build(), Err(e) => { - let system_err: DispatchError = InternalError::new(format!("{:?}", e)).into(); + let system_err: DispatchError = InternalError::new(format!("{}", e)).into(); system_err.into() }, } diff --git a/rust-lib/flowy-dispatch/src/errors/errors.rs b/rust-lib/flowy-dispatch/src/errors/errors.rs index 344807b6b2..ae7b1e6ff9 100644 --- a/rust-lib/flowy-dispatch/src/errors/errors.rs +++ b/rust-lib/flowy-dispatch/src/errors/errors.rs @@ -1,4 +1,5 @@ use crate::{ + byte_trait::FromBytes, request::EventRequest, response::{EventResponse, ResponseBuilder, StatusCode}, }; @@ -8,7 +9,7 @@ use std::{fmt, option::NoneError}; use tokio::sync::mpsc::error::SendError; pub trait Error: fmt::Debug + DynClone + Send + Sync { - fn as_response(&self) -> EventResponse { EventResponse::new(StatusCode::Err) } + fn as_response(&self) -> EventResponse; } dyn_clone::clone_trait_object!(Error); @@ -66,6 +67,13 @@ impl From for DispatchError { fn from(s: String) -> Self { InternalError { inner: s }.into() } } +impl FromBytes for DispatchError { + fn parse_from_bytes(bytes: &Vec) -> Result { + let s = String::from_utf8(bytes.to_vec()).unwrap(); + Ok(InternalError { inner: s }.into()) + } +} + impl From for EventResponse { fn from(err: DispatchError) -> Self { err.inner_error().as_response() } } @@ -98,12 +106,8 @@ where T: fmt::Debug + fmt::Display + 'static + Clone + Send + Sync, { fn as_response(&self) -> EventResponse { - let error = InternalError { - inner: format!("{}", self.inner), - } - .into(); - - ResponseBuilder::Err().error(error).build() + let error = format!("{}", self.inner).into_bytes(); + ResponseBuilder::Err().data(error).build() } } diff --git a/rust-lib/flowy-dispatch/src/response/builder.rs b/rust-lib/flowy-dispatch/src/response/builder.rs index abfe55184a..2d56db4205 100644 --- a/rust-lib/flowy-dispatch/src/response/builder.rs +++ b/rust-lib/flowy-dispatch/src/response/builder.rs @@ -14,7 +14,6 @@ macro_rules! static_response { pub struct ResponseBuilder { pub payload: T, pub status: StatusCode, - pub error: Option, } impl ResponseBuilder { @@ -22,7 +21,6 @@ impl ResponseBuilder { ResponseBuilder { payload: Payload::None, status, - error: None, } } @@ -31,16 +29,10 @@ impl ResponseBuilder { self } - pub fn error(mut self, error: DispatchError) -> Self { - self.error = Some(error); - self - } - pub fn build(self) -> EventResponse { EventResponse { payload: self.payload, status_code: self.status, - error: self.error, } } diff --git a/rust-lib/flowy-dispatch/src/response/response.rs b/rust-lib/flowy-dispatch/src/response/response.rs index f0ed7c3fb6..593a3b4d3a 100644 --- a/rust-lib/flowy-dispatch/src/response/response.rs +++ b/rust-lib/flowy-dispatch/src/response/response.rs @@ -20,7 +20,6 @@ pub struct EventResponse { #[derivative(Debug = "ignore")] pub payload: Payload, pub status_code: StatusCode, - pub error: Option, } impl EventResponse { @@ -28,7 +27,6 @@ impl EventResponse { EventResponse { payload: Payload::None, status_code, - error: None, } } @@ -59,10 +57,6 @@ impl std::fmt::Display for EventResponse { Payload::Bytes(b) => f.write_fmt(format_args!("Data: {} bytes", b.len()))?, Payload::None => f.write_fmt(format_args!("Data: Empty"))?, } - match &self.error { - Some(e) => f.write_fmt(format_args!("Error: {:?}", e))?, - None => {}, - } Ok(()) } diff --git a/rust-lib/flowy-editor/src/handlers/doc_handler.rs b/rust-lib/flowy-editor/src/handlers/doc_handler.rs index ca8900e0ca..13ea1d641c 100644 --- a/rust-lib/flowy-editor/src/handlers/doc_handler.rs +++ b/rust-lib/flowy-editor/src/handlers/doc_handler.rs @@ -14,7 +14,7 @@ pub async fn create_doc( manager: Unit>, ) -> ResponseResult { let params: CreateDocParams = data.into_inner().try_into()?; - let dir = manager.read().await.user.user_doc_dir()?;CreateDocRequest + let dir = manager.read().await.user.user_doc_dir()?; let path = manager .write() .await diff --git a/rust-lib/flowy-sdk/src/deps_resolve/workspace_deps_impl.rs b/rust-lib/flowy-sdk/src/deps_resolve/workspace_deps_impl.rs index 8b65b80782..67666078c7 100644 --- a/rust-lib/flowy-sdk/src/deps_resolve/workspace_deps_impl.rs +++ b/rust-lib/flowy-sdk/src/deps_resolve/workspace_deps_impl.rs @@ -28,8 +28,7 @@ impl WorkspaceUser for WorkspaceUserImpl { ErrorBuilder::new(WorkspaceErrorCode::UserInternalError) .error(e) .build() - }); - + })?; Ok(()) }), } diff --git a/rust-lib/flowy-sdk/src/flowy_server.rs b/rust-lib/flowy-sdk/src/flowy_server.rs index 9fc7f577d7..3e3a2de9c8 100644 --- a/rust-lib/flowy-sdk/src/flowy_server.rs +++ b/rust-lib/flowy-sdk/src/flowy_server.rs @@ -1,4 +1,10 @@ -use flowy_dispatch::prelude::{DispatchFuture, EventDispatch, ModuleRequest, ToBytes}; +use flowy_dispatch::prelude::{ + DispatchError, + DispatchFuture, + EventDispatch, + ModuleRequest, + ToBytes, +}; use flowy_user::{ entities::{SignInParams, SignUpParams, UserDetail}, errors::{ErrorBuilder, UserError, UserErrorCode}, @@ -67,7 +73,7 @@ impl UserServer for FlowyServerMocker { fut: Box::pin(async move { let result = EventDispatch::async_send(request) .await - .parse::() + .parse::() .map_err(|e| { ErrorBuilder::new(UserErrorCode::CreateDefaultWorkspaceFailed) .error(e) diff --git a/rust-lib/flowy-user/Cargo.toml b/rust-lib/flowy-user/Cargo.toml index db0be3480b..0d3d1d5199 100644 --- a/rust-lib/flowy-user/Cargo.toml +++ b/rust-lib/flowy-user/Cargo.toml @@ -31,6 +31,7 @@ thread-id = "3.3.0" once_cell = "1.7.2" parking_lot = "0.11" + [dev-dependencies] quickcheck = "0.9.2" quickcheck_macros = "0.9.1" diff --git a/rust-lib/flowy-user/src/errors.rs b/rust-lib/flowy-user/src/errors.rs index 454cbf8ec3..a1ff441cc3 100644 --- a/rust-lib/flowy-user/src/errors.rs +++ b/rust-lib/flowy-user/src/errors.rs @@ -36,6 +36,9 @@ pub enum UserErrorCode { #[display(fmt = "Database internal error")] UserDatabaseInternalError = 5, + #[display(fmt = "Sql internal error")] + SqlInternalError = 6, + #[display(fmt = "User not login yet")] UserNotLoginYet = 10, #[display(fmt = "Get current id read lock failed")] @@ -71,7 +74,8 @@ impl std::convert::From for UserError { .build() } } - +// use diesel::result::{Error, DatabaseErrorKind}; +// use flowy_sqlite::ErrorKind; impl std::convert::From for UserError { fn from(error: flowy_sqlite::Error) -> Self { // match error.kind() { @@ -87,7 +91,6 @@ impl std::convert::From for UserError { // } // _ => {} // } - // // }, // Error::NotFound => {}, // Error::QueryBuilderError(_) => {}, @@ -103,7 +106,7 @@ impl std::convert::From for UserError { // ErrorKind::__Nonexhaustive { .. } => {}, // } - ErrorBuilder::new(UserErrorCode::UserDatabaseInternalError) + ErrorBuilder::new(UserErrorCode::SqlInternalError) .error(error) .build() } diff --git a/rust-lib/flowy-user/src/handlers/auth_handler.rs b/rust-lib/flowy-user/src/handlers/auth_handler.rs index f716e3233c..97073f4096 100644 --- a/rust-lib/flowy-user/src/handlers/auth_handler.rs +++ b/rust-lib/flowy-user/src/handlers/auth_handler.rs @@ -3,13 +3,7 @@ use flowy_dispatch::prelude::*; use std::{convert::TryInto, sync::Arc}; // tracing instrument 👉🏻 https://docs.rs/tracing/0.1.26/tracing/attr.instrument.html -#[tracing::instrument( - name = "user_sign_in", - skip(data, session), - fields( - email = %data.email, - ) -)] +#[tracing::instrument(name = "user_sign_in", skip(data, session), fields(email = %data.email))] pub async fn user_sign_in_handler( data: Data, session: Unit>, diff --git a/rust-lib/flowy-user/src/protobuf/model/errors.rs b/rust-lib/flowy-user/src/protobuf/model/errors.rs index 07209a5631..657a1837a7 100644 --- a/rust-lib/flowy-user/src/protobuf/model/errors.rs +++ b/rust-lib/flowy-user/src/protobuf/model/errors.rs @@ -221,6 +221,7 @@ pub enum UserErrorCode { UserDatabaseReadLocked = 3, UserDatabaseDidNotMatch = 4, UserDatabaseInternalError = 5, + SqlInternalError = 6, UserNotLoginYet = 10, ReadCurrentIdFailed = 11, WriteCurrentIdFailed = 12, @@ -246,6 +247,7 @@ impl ::protobuf::ProtobufEnum for UserErrorCode { 3 => ::std::option::Option::Some(UserErrorCode::UserDatabaseReadLocked), 4 => ::std::option::Option::Some(UserErrorCode::UserDatabaseDidNotMatch), 5 => ::std::option::Option::Some(UserErrorCode::UserDatabaseInternalError), + 6 => ::std::option::Option::Some(UserErrorCode::SqlInternalError), 10 => ::std::option::Option::Some(UserErrorCode::UserNotLoginYet), 11 => ::std::option::Option::Some(UserErrorCode::ReadCurrentIdFailed), 12 => ::std::option::Option::Some(UserErrorCode::WriteCurrentIdFailed), @@ -268,6 +270,7 @@ impl ::protobuf::ProtobufEnum for UserErrorCode { UserErrorCode::UserDatabaseReadLocked, UserErrorCode::UserDatabaseDidNotMatch, UserErrorCode::UserDatabaseInternalError, + UserErrorCode::SqlInternalError, UserErrorCode::UserNotLoginYet, UserErrorCode::ReadCurrentIdFailed, UserErrorCode::WriteCurrentIdFailed, @@ -308,57 +311,59 @@ impl ::protobuf::reflect::ProtobufValue for UserErrorCode { static file_descriptor_proto_data: &'static [u8] = b"\ \n\x0cerrors.proto\"A\n\tUserError\x12\"\n\x04code\x18\x01\x20\x01(\x0e2\ \x0e.UserErrorCodeR\x04code\x12\x10\n\x03msg\x18\x02\x20\x01(\tR\x03msg*\ - \xa2\x03\n\rUserErrorCode\x12\x0b\n\x07Unknown\x10\0\x12\x1a\n\x16UserDa\ + \xb8\x03\n\rUserErrorCode\x12\x0b\n\x07Unknown\x10\0\x12\x1a\n\x16UserDa\ tabaseInitFailed\x10\x01\x12\x1b\n\x17UserDatabaseWriteLocked\x10\x02\ \x12\x1a\n\x16UserDatabaseReadLocked\x10\x03\x12\x1b\n\x17UserDatabaseDi\ - dNotMatch\x10\x04\x12\x1d\n\x19UserDatabaseInternalError\x10\x05\x12\x13\ - \n\x0fUserNotLoginYet\x10\n\x12\x17\n\x13ReadCurrentIdFailed\x10\x0b\x12\ - \x18\n\x14WriteCurrentIdFailed\x10\x0c\x12\x10\n\x0cEmailInvalid\x10\x14\ - \x12\x13\n\x0fPasswordInvalid\x10\x15\x12\x13\n\x0fUserNameInvalid\x10\ - \x16\x12\x18\n\x14UserWorkspaceInvalid\x10\x17\x12\x11\n\rUserIdInvalid\ - \x10\x18\x12\x20\n\x1cCreateDefaultWorkspaceFailed\x10\x19\x12\x20\n\x1c\ - DefaultWorkspaceAlreadyExist\x10\x1aJ\xc0\x06\n\x06\x12\x04\0\0\x17\x01\ - \n\x08\n\x01\x0c\x12\x03\0\0\x12\n\n\n\x02\x04\0\x12\x04\x02\0\x05\x01\n\ - \n\n\x03\x04\0\x01\x12\x03\x02\x08\x11\n\x0b\n\x04\x04\0\x02\0\x12\x03\ - \x03\x04\x1b\n\x0c\n\x05\x04\0\x02\0\x06\x12\x03\x03\x04\x11\n\x0c\n\x05\ - \x04\0\x02\0\x01\x12\x03\x03\x12\x16\n\x0c\n\x05\x04\0\x02\0\x03\x12\x03\ - \x03\x19\x1a\n\x0b\n\x04\x04\0\x02\x01\x12\x03\x04\x04\x13\n\x0c\n\x05\ - \x04\0\x02\x01\x05\x12\x03\x04\x04\n\n\x0c\n\x05\x04\0\x02\x01\x01\x12\ - \x03\x04\x0b\x0e\n\x0c\n\x05\x04\0\x02\x01\x03\x12\x03\x04\x11\x12\n\n\n\ - \x02\x05\0\x12\x04\x06\0\x17\x01\n\n\n\x03\x05\0\x01\x12\x03\x06\x05\x12\ - \n\x0b\n\x04\x05\0\x02\0\x12\x03\x07\x04\x10\n\x0c\n\x05\x05\0\x02\0\x01\ - \x12\x03\x07\x04\x0b\n\x0c\n\x05\x05\0\x02\0\x02\x12\x03\x07\x0e\x0f\n\ - \x0b\n\x04\x05\0\x02\x01\x12\x03\x08\x04\x1f\n\x0c\n\x05\x05\0\x02\x01\ - \x01\x12\x03\x08\x04\x1a\n\x0c\n\x05\x05\0\x02\x01\x02\x12\x03\x08\x1d\ - \x1e\n\x0b\n\x04\x05\0\x02\x02\x12\x03\t\x04\x20\n\x0c\n\x05\x05\0\x02\ - \x02\x01\x12\x03\t\x04\x1b\n\x0c\n\x05\x05\0\x02\x02\x02\x12\x03\t\x1e\ - \x1f\n\x0b\n\x04\x05\0\x02\x03\x12\x03\n\x04\x1f\n\x0c\n\x05\x05\0\x02\ - \x03\x01\x12\x03\n\x04\x1a\n\x0c\n\x05\x05\0\x02\x03\x02\x12\x03\n\x1d\ - \x1e\n\x0b\n\x04\x05\0\x02\x04\x12\x03\x0b\x04\x20\n\x0c\n\x05\x05\0\x02\ - \x04\x01\x12\x03\x0b\x04\x1b\n\x0c\n\x05\x05\0\x02\x04\x02\x12\x03\x0b\ - \x1e\x1f\n\x0b\n\x04\x05\0\x02\x05\x12\x03\x0c\x04\"\n\x0c\n\x05\x05\0\ - \x02\x05\x01\x12\x03\x0c\x04\x1d\n\x0c\n\x05\x05\0\x02\x05\x02\x12\x03\ - \x0c\x20!\n\x0b\n\x04\x05\0\x02\x06\x12\x03\r\x04\x19\n\x0c\n\x05\x05\0\ - \x02\x06\x01\x12\x03\r\x04\x13\n\x0c\n\x05\x05\0\x02\x06\x02\x12\x03\r\ - \x16\x18\n\x0b\n\x04\x05\0\x02\x07\x12\x03\x0e\x04\x1d\n\x0c\n\x05\x05\0\ - \x02\x07\x01\x12\x03\x0e\x04\x17\n\x0c\n\x05\x05\0\x02\x07\x02\x12\x03\ - \x0e\x1a\x1c\n\x0b\n\x04\x05\0\x02\x08\x12\x03\x0f\x04\x1e\n\x0c\n\x05\ - \x05\0\x02\x08\x01\x12\x03\x0f\x04\x18\n\x0c\n\x05\x05\0\x02\x08\x02\x12\ - \x03\x0f\x1b\x1d\n\x0b\n\x04\x05\0\x02\t\x12\x03\x10\x04\x16\n\x0c\n\x05\ - \x05\0\x02\t\x01\x12\x03\x10\x04\x10\n\x0c\n\x05\x05\0\x02\t\x02\x12\x03\ - \x10\x13\x15\n\x0b\n\x04\x05\0\x02\n\x12\x03\x11\x04\x19\n\x0c\n\x05\x05\ - \0\x02\n\x01\x12\x03\x11\x04\x13\n\x0c\n\x05\x05\0\x02\n\x02\x12\x03\x11\ - \x16\x18\n\x0b\n\x04\x05\0\x02\x0b\x12\x03\x12\x04\x19\n\x0c\n\x05\x05\0\ - \x02\x0b\x01\x12\x03\x12\x04\x13\n\x0c\n\x05\x05\0\x02\x0b\x02\x12\x03\ - \x12\x16\x18\n\x0b\n\x04\x05\0\x02\x0c\x12\x03\x13\x04\x1e\n\x0c\n\x05\ - \x05\0\x02\x0c\x01\x12\x03\x13\x04\x18\n\x0c\n\x05\x05\0\x02\x0c\x02\x12\ - \x03\x13\x1b\x1d\n\x0b\n\x04\x05\0\x02\r\x12\x03\x14\x04\x17\n\x0c\n\x05\ - \x05\0\x02\r\x01\x12\x03\x14\x04\x11\n\x0c\n\x05\x05\0\x02\r\x02\x12\x03\ - \x14\x14\x16\n\x0b\n\x04\x05\0\x02\x0e\x12\x03\x15\x04&\n\x0c\n\x05\x05\ - \0\x02\x0e\x01\x12\x03\x15\x04\x20\n\x0c\n\x05\x05\0\x02\x0e\x02\x12\x03\ - \x15#%\n\x0b\n\x04\x05\0\x02\x0f\x12\x03\x16\x04&\n\x0c\n\x05\x05\0\x02\ - \x0f\x01\x12\x03\x16\x04\x20\n\x0c\n\x05\x05\0\x02\x0f\x02\x12\x03\x16#%\ - b\x06proto3\ + dNotMatch\x10\x04\x12\x1d\n\x19UserDatabaseInternalError\x10\x05\x12\x14\ + \n\x10SqlInternalError\x10\x06\x12\x13\n\x0fUserNotLoginYet\x10\n\x12\ + \x17\n\x13ReadCurrentIdFailed\x10\x0b\x12\x18\n\x14WriteCurrentIdFailed\ + \x10\x0c\x12\x10\n\x0cEmailInvalid\x10\x14\x12\x13\n\x0fPasswordInvalid\ + \x10\x15\x12\x13\n\x0fUserNameInvalid\x10\x16\x12\x18\n\x14UserWorkspace\ + Invalid\x10\x17\x12\x11\n\rUserIdInvalid\x10\x18\x12\x20\n\x1cCreateDefa\ + ultWorkspaceFailed\x10\x19\x12\x20\n\x1cDefaultWorkspaceAlreadyExist\x10\ + \x1aJ\xe9\x06\n\x06\x12\x04\0\0\x18\x01\n\x08\n\x01\x0c\x12\x03\0\0\x12\ + \n\n\n\x02\x04\0\x12\x04\x02\0\x05\x01\n\n\n\x03\x04\0\x01\x12\x03\x02\ + \x08\x11\n\x0b\n\x04\x04\0\x02\0\x12\x03\x03\x04\x1b\n\x0c\n\x05\x04\0\ + \x02\0\x06\x12\x03\x03\x04\x11\n\x0c\n\x05\x04\0\x02\0\x01\x12\x03\x03\ + \x12\x16\n\x0c\n\x05\x04\0\x02\0\x03\x12\x03\x03\x19\x1a\n\x0b\n\x04\x04\ + \0\x02\x01\x12\x03\x04\x04\x13\n\x0c\n\x05\x04\0\x02\x01\x05\x12\x03\x04\ + \x04\n\n\x0c\n\x05\x04\0\x02\x01\x01\x12\x03\x04\x0b\x0e\n\x0c\n\x05\x04\ + \0\x02\x01\x03\x12\x03\x04\x11\x12\n\n\n\x02\x05\0\x12\x04\x06\0\x18\x01\ + \n\n\n\x03\x05\0\x01\x12\x03\x06\x05\x12\n\x0b\n\x04\x05\0\x02\0\x12\x03\ + \x07\x04\x10\n\x0c\n\x05\x05\0\x02\0\x01\x12\x03\x07\x04\x0b\n\x0c\n\x05\ + \x05\0\x02\0\x02\x12\x03\x07\x0e\x0f\n\x0b\n\x04\x05\0\x02\x01\x12\x03\ + \x08\x04\x1f\n\x0c\n\x05\x05\0\x02\x01\x01\x12\x03\x08\x04\x1a\n\x0c\n\ + \x05\x05\0\x02\x01\x02\x12\x03\x08\x1d\x1e\n\x0b\n\x04\x05\0\x02\x02\x12\ + \x03\t\x04\x20\n\x0c\n\x05\x05\0\x02\x02\x01\x12\x03\t\x04\x1b\n\x0c\n\ + \x05\x05\0\x02\x02\x02\x12\x03\t\x1e\x1f\n\x0b\n\x04\x05\0\x02\x03\x12\ + \x03\n\x04\x1f\n\x0c\n\x05\x05\0\x02\x03\x01\x12\x03\n\x04\x1a\n\x0c\n\ + \x05\x05\0\x02\x03\x02\x12\x03\n\x1d\x1e\n\x0b\n\x04\x05\0\x02\x04\x12\ + \x03\x0b\x04\x20\n\x0c\n\x05\x05\0\x02\x04\x01\x12\x03\x0b\x04\x1b\n\x0c\ + \n\x05\x05\0\x02\x04\x02\x12\x03\x0b\x1e\x1f\n\x0b\n\x04\x05\0\x02\x05\ + \x12\x03\x0c\x04\"\n\x0c\n\x05\x05\0\x02\x05\x01\x12\x03\x0c\x04\x1d\n\ + \x0c\n\x05\x05\0\x02\x05\x02\x12\x03\x0c\x20!\n\x0b\n\x04\x05\0\x02\x06\ + \x12\x03\r\x04\x19\n\x0c\n\x05\x05\0\x02\x06\x01\x12\x03\r\x04\x14\n\x0c\ + \n\x05\x05\0\x02\x06\x02\x12\x03\r\x17\x18\n\x0b\n\x04\x05\0\x02\x07\x12\ + \x03\x0e\x04\x19\n\x0c\n\x05\x05\0\x02\x07\x01\x12\x03\x0e\x04\x13\n\x0c\ + \n\x05\x05\0\x02\x07\x02\x12\x03\x0e\x16\x18\n\x0b\n\x04\x05\0\x02\x08\ + \x12\x03\x0f\x04\x1d\n\x0c\n\x05\x05\0\x02\x08\x01\x12\x03\x0f\x04\x17\n\ + \x0c\n\x05\x05\0\x02\x08\x02\x12\x03\x0f\x1a\x1c\n\x0b\n\x04\x05\0\x02\t\ + \x12\x03\x10\x04\x1e\n\x0c\n\x05\x05\0\x02\t\x01\x12\x03\x10\x04\x18\n\ + \x0c\n\x05\x05\0\x02\t\x02\x12\x03\x10\x1b\x1d\n\x0b\n\x04\x05\0\x02\n\ + \x12\x03\x11\x04\x16\n\x0c\n\x05\x05\0\x02\n\x01\x12\x03\x11\x04\x10\n\ + \x0c\n\x05\x05\0\x02\n\x02\x12\x03\x11\x13\x15\n\x0b\n\x04\x05\0\x02\x0b\ + \x12\x03\x12\x04\x19\n\x0c\n\x05\x05\0\x02\x0b\x01\x12\x03\x12\x04\x13\n\ + \x0c\n\x05\x05\0\x02\x0b\x02\x12\x03\x12\x16\x18\n\x0b\n\x04\x05\0\x02\ + \x0c\x12\x03\x13\x04\x19\n\x0c\n\x05\x05\0\x02\x0c\x01\x12\x03\x13\x04\ + \x13\n\x0c\n\x05\x05\0\x02\x0c\x02\x12\x03\x13\x16\x18\n\x0b\n\x04\x05\0\ + \x02\r\x12\x03\x14\x04\x1e\n\x0c\n\x05\x05\0\x02\r\x01\x12\x03\x14\x04\ + \x18\n\x0c\n\x05\x05\0\x02\r\x02\x12\x03\x14\x1b\x1d\n\x0b\n\x04\x05\0\ + \x02\x0e\x12\x03\x15\x04\x17\n\x0c\n\x05\x05\0\x02\x0e\x01\x12\x03\x15\ + \x04\x11\n\x0c\n\x05\x05\0\x02\x0e\x02\x12\x03\x15\x14\x16\n\x0b\n\x04\ + \x05\0\x02\x0f\x12\x03\x16\x04&\n\x0c\n\x05\x05\0\x02\x0f\x01\x12\x03\ + \x16\x04\x20\n\x0c\n\x05\x05\0\x02\x0f\x02\x12\x03\x16#%\n\x0b\n\x04\x05\ + \0\x02\x10\x12\x03\x17\x04&\n\x0c\n\x05\x05\0\x02\x10\x01\x12\x03\x17\ + \x04\x20\n\x0c\n\x05\x05\0\x02\x10\x02\x12\x03\x17#%b\x06proto3\ "; static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT; diff --git a/rust-lib/flowy-user/src/protobuf/proto/errors.proto b/rust-lib/flowy-user/src/protobuf/proto/errors.proto index dfccb02b99..881ae87c12 100644 --- a/rust-lib/flowy-user/src/protobuf/proto/errors.proto +++ b/rust-lib/flowy-user/src/protobuf/proto/errors.proto @@ -11,6 +11,7 @@ enum UserErrorCode { UserDatabaseReadLocked = 3; UserDatabaseDidNotMatch = 4; UserDatabaseInternalError = 5; + SqlInternalError = 6; UserNotLoginYet = 10; ReadCurrentIdFailed = 11; WriteCurrentIdFailed = 12; diff --git a/rust-lib/flowy-user/src/services/user_session/user_session.rs b/rust-lib/flowy-user/src/services/user_session/user_session.rs index 92dc040098..b1715214d4 100644 --- a/rust-lib/flowy-user/src/services/user_session/user_session.rs +++ b/rust-lib/flowy-user/src/services/user_session/user_session.rs @@ -110,7 +110,6 @@ impl UserSession { let changeset = UserTableChangeset::new(params); let conn = self.get_db_connection()?; diesel_update_table!(user_table, changeset, conn); - let user_detail = self.user_detail()?; Ok(user_detail) } diff --git a/rust-lib/flowy-workspace/src/services/workspace_controller.rs b/rust-lib/flowy-workspace/src/services/workspace_controller.rs index 13564a173f..d98a9dfec7 100644 --- a/rust-lib/flowy-workspace/src/services/workspace_controller.rs +++ b/rust-lib/flowy-workspace/src/services/workspace_controller.rs @@ -36,8 +36,6 @@ impl WorkspaceController { let workspace_table = WorkspaceTable::new(params); let detail: Workspace = workspace_table.clone().into(); let _ = self.sql.create_workspace(workspace_table)?; - // let _ = self.user.set_cur_workspace_id(&detail.id).await?; - Ok(detail) }