mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
Merge pull request #643 from AppFlowy-IO/refactor/add_PB_suffix
Refactor/add pb suffix
This commit is contained in:
commit
26c5dcd182
@ -51,14 +51,14 @@ void _resolveHomeDeps(GetIt getIt) {
|
||||
|
||||
getIt.registerSingleton(MenuSharedState());
|
||||
|
||||
getIt.registerFactoryParam<UserListener, UserProfile, void>(
|
||||
getIt.registerFactoryParam<UserListener, UserProfilePB, void>(
|
||||
(user, _) => UserListener(userProfile: user),
|
||||
);
|
||||
|
||||
//
|
||||
getIt.registerLazySingleton<HomeStackManager>(() => HomeStackManager());
|
||||
|
||||
getIt.registerFactoryParam<WelcomeBloc, UserProfile, void>(
|
||||
getIt.registerFactoryParam<WelcomeBloc, UserProfilePB, void>(
|
||||
(user, _) => WelcomeBloc(
|
||||
userService: UserService(userId: user.id),
|
||||
userWorkspaceListener: UserWorkspaceListener(userProfile: user),
|
||||
@ -67,21 +67,21 @@ void _resolveHomeDeps(GetIt getIt) {
|
||||
|
||||
// share
|
||||
getIt.registerLazySingleton<ShareService>(() => ShareService());
|
||||
getIt.registerFactoryParam<DocShareBloc, View, void>(
|
||||
getIt.registerFactoryParam<DocShareBloc, ViewPB, void>(
|
||||
(view, _) => DocShareBloc(view: view, service: getIt<ShareService>()));
|
||||
}
|
||||
|
||||
void _resolveFolderDeps(GetIt getIt) {
|
||||
//workspace
|
||||
getIt.registerFactoryParam<WorkspaceListener, UserProfile, String>(
|
||||
getIt.registerFactoryParam<WorkspaceListener, UserProfilePB, String>(
|
||||
(user, workspaceId) => WorkspaceListener(user: user, workspaceId: workspaceId));
|
||||
|
||||
// View
|
||||
getIt.registerFactoryParam<ViewListener, View, void>(
|
||||
// ViewPB
|
||||
getIt.registerFactoryParam<ViewListener, ViewPB, void>(
|
||||
(view, _) => ViewListener(view: view),
|
||||
);
|
||||
|
||||
getIt.registerFactoryParam<ViewBloc, View, void>(
|
||||
getIt.registerFactoryParam<ViewBloc, ViewPB, void>(
|
||||
(view, _) => ViewBloc(
|
||||
view: view,
|
||||
service: ViewService(),
|
||||
@ -90,19 +90,19 @@ void _resolveFolderDeps(GetIt getIt) {
|
||||
);
|
||||
|
||||
//Menu
|
||||
getIt.registerFactoryParam<MenuBloc, UserProfile, String>(
|
||||
getIt.registerFactoryParam<MenuBloc, UserProfilePB, String>(
|
||||
(user, workspaceId) => MenuBloc(
|
||||
workspaceId: workspaceId,
|
||||
listener: getIt<WorkspaceListener>(param1: user, param2: workspaceId),
|
||||
),
|
||||
);
|
||||
|
||||
getIt.registerFactoryParam<MenuUserBloc, UserProfile, void>(
|
||||
getIt.registerFactoryParam<MenuUserBloc, UserProfilePB, void>(
|
||||
(user, _) => MenuUserBloc(user),
|
||||
);
|
||||
|
||||
// App
|
||||
getIt.registerFactoryParam<AppBloc, App, void>(
|
||||
// AppPB
|
||||
getIt.registerFactoryParam<AppBloc, AppPB, void>(
|
||||
(app, _) => AppBloc(
|
||||
app: app,
|
||||
appService: AppService(appId: app.id),
|
||||
@ -123,7 +123,7 @@ void _resolveFolderDeps(GetIt getIt) {
|
||||
|
||||
void _resolveDocDeps(GetIt getIt) {
|
||||
// Doc
|
||||
getIt.registerFactoryParam<DocumentBloc, View, void>(
|
||||
getIt.registerFactoryParam<DocumentBloc, ViewPB, void>(
|
||||
(view, _) => DocumentBloc(
|
||||
view: view,
|
||||
service: DocumentService(),
|
||||
@ -135,7 +135,7 @@ void _resolveDocDeps(GetIt getIt) {
|
||||
|
||||
void _resolveGridDeps(GetIt getIt) {
|
||||
// GridPB
|
||||
getIt.registerFactoryParam<GridBloc, View, void>(
|
||||
getIt.registerFactoryParam<GridBloc, ViewPB, void>(
|
||||
(view, _) => GridBloc(view: view),
|
||||
);
|
||||
|
||||
|
@ -1,21 +1,21 @@
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:flowy_sdk/dispatch/dispatch.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-user/protobuf.dart' show SignInPayload, SignUpPayload, UserProfile;
|
||||
import 'package:flowy_sdk/protobuf/flowy-user/protobuf.dart' show SignInPayloadPB, SignUpPayloadPB, UserProfilePB;
|
||||
import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart';
|
||||
|
||||
class AuthService {
|
||||
Future<Either<UserProfile, FlowyError>> signIn({required String? email, required String? password}) {
|
||||
Future<Either<UserProfilePB, FlowyError>> signIn({required String? email, required String? password}) {
|
||||
//
|
||||
final request = SignInPayload.create()
|
||||
final request = SignInPayloadPB.create()
|
||||
..email = email ?? ''
|
||||
..password = password ?? '';
|
||||
|
||||
return UserEventSignIn(request).send();
|
||||
}
|
||||
|
||||
Future<Either<UserProfile, FlowyError>> signUp(
|
||||
Future<Either<UserProfilePB, FlowyError>> signUp(
|
||||
{required String? name, required String? password, required String? email}) {
|
||||
final request = SignUpPayload.create()
|
||||
final request = SignUpPayloadPB.create()
|
||||
..email = email ?? ''
|
||||
..name = name ?? ''
|
||||
..password = password ?? '';
|
||||
|
@ -2,7 +2,7 @@ import 'package:app_flowy/user/application/auth_service.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-error-code/code.pb.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-user/protobuf.dart' show UserProfile;
|
||||
import 'package:flowy_sdk/protobuf/flowy-user/protobuf.dart' show UserProfilePB;
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
@ -69,7 +69,7 @@ class SignInState with _$SignInState {
|
||||
required bool isSubmitting,
|
||||
required Option<String> passwordError,
|
||||
required Option<String> emailError,
|
||||
required Option<Either<UserProfile, FlowyError>> successOrFail,
|
||||
required Option<Either<UserProfilePB, FlowyError>> successOrFail,
|
||||
}) = _SignInState;
|
||||
|
||||
factory SignInState.initial() => SignInState(
|
||||
|
@ -2,7 +2,7 @@ import 'package:app_flowy/user/application/auth_service.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:easy_localization/easy_localization.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-error-code/code.pb.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-user/protobuf.dart' show UserProfile;
|
||||
import 'package:flowy_sdk/protobuf/flowy-user/protobuf.dart' show UserProfilePB;
|
||||
import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
@ -120,7 +120,7 @@ class SignUpState with _$SignUpState {
|
||||
required Option<String> passwordError,
|
||||
required Option<String> repeatPasswordError,
|
||||
required Option<String> emailError,
|
||||
required Option<Either<UserProfile, FlowyError>> successOrFail,
|
||||
required Option<Either<UserProfilePB, FlowyError>> successOrFail,
|
||||
}) = _SignUpState;
|
||||
|
||||
factory SignUpState.initial() => SignUpState(
|
||||
|
@ -13,7 +13,7 @@ import 'package:flowy_sdk/protobuf/flowy-user/user_profile.pb.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-user/dart_notification.pb.dart' as user;
|
||||
import 'package:flowy_sdk/rust_stream.dart';
|
||||
|
||||
typedef UserProfileNotifyValue = Either<UserProfile, FlowyError>;
|
||||
typedef UserProfileNotifyValue = Either<UserProfilePB, FlowyError>;
|
||||
typedef AuthNotifyValue = Either<Unit, FlowyError>;
|
||||
|
||||
class UserListener {
|
||||
@ -22,9 +22,9 @@ class UserListener {
|
||||
PublishNotifier<UserProfileNotifyValue>? _profileNotifier = PublishNotifier();
|
||||
|
||||
UserNotificationParser? _userParser;
|
||||
final UserProfile _userProfile;
|
||||
final UserProfilePB _userProfile;
|
||||
UserListener({
|
||||
required UserProfile userProfile,
|
||||
required UserProfilePB userProfile,
|
||||
}) : _userProfile = userProfile;
|
||||
|
||||
void start({
|
||||
@ -65,7 +65,7 @@ class UserListener {
|
||||
break;
|
||||
case user.UserNotification.UserProfileUpdated:
|
||||
result.fold(
|
||||
(payload) => _profileNotifier?.value = left(UserProfile.fromBuffer(payload)),
|
||||
(payload) => _profileNotifier?.value = left(UserProfilePB.fromBuffer(payload)),
|
||||
(error) => _profileNotifier?.value = right(error),
|
||||
);
|
||||
break;
|
||||
@ -75,8 +75,8 @@ class UserListener {
|
||||
}
|
||||
}
|
||||
|
||||
typedef WorkspaceListNotifyValue = Either<List<Workspace>, FlowyError>;
|
||||
typedef WorkspaceSettingNotifyValue = Either<CurrentWorkspaceSetting, FlowyError>;
|
||||
typedef WorkspaceListNotifyValue = Either<List<WorkspacePB>, FlowyError>;
|
||||
typedef WorkspaceSettingNotifyValue = Either<CurrentWorkspaceSettingPB, FlowyError>;
|
||||
|
||||
class UserWorkspaceListener {
|
||||
PublishNotifier<AuthNotifyValue>? _authNotifier = PublishNotifier();
|
||||
@ -84,10 +84,10 @@ class UserWorkspaceListener {
|
||||
PublishNotifier<WorkspaceSettingNotifyValue>? _settingChangedNotifier = PublishNotifier();
|
||||
|
||||
FolderNotificationListener? _listener;
|
||||
final UserProfile _userProfile;
|
||||
final UserProfilePB _userProfile;
|
||||
|
||||
UserWorkspaceListener({
|
||||
required UserProfile userProfile,
|
||||
required UserProfilePB userProfile,
|
||||
}) : _userProfile = userProfile;
|
||||
|
||||
void start({
|
||||
@ -119,13 +119,13 @@ class UserWorkspaceListener {
|
||||
case FolderNotification.UserDeleteWorkspace:
|
||||
case FolderNotification.WorkspaceListUpdated:
|
||||
result.fold(
|
||||
(payload) => _workspacesChangedNotifier?.value = left(RepeatedWorkspace.fromBuffer(payload).items),
|
||||
(payload) => _workspacesChangedNotifier?.value = left(RepeatedWorkspacePB.fromBuffer(payload).items),
|
||||
(error) => _workspacesChangedNotifier?.value = right(error),
|
||||
);
|
||||
break;
|
||||
case FolderNotification.WorkspaceSetting:
|
||||
result.fold(
|
||||
(payload) => _settingChangedNotifier?.value = left(CurrentWorkspaceSetting.fromBuffer(payload)),
|
||||
(payload) => _settingChangedNotifier?.value = left(CurrentWorkspaceSettingPB.fromBuffer(payload)),
|
||||
(error) => _settingChangedNotifier?.value = right(error),
|
||||
);
|
||||
break;
|
||||
|
@ -11,7 +11,7 @@ class UserService {
|
||||
UserService({
|
||||
required this.userId,
|
||||
});
|
||||
Future<Either<UserProfile, FlowyError>> getUserProfile({required String userId}) {
|
||||
Future<Either<UserProfilePB, FlowyError>> getUserProfile({required String userId}) {
|
||||
return UserEventGetUserProfile().send();
|
||||
}
|
||||
|
||||
@ -20,7 +20,7 @@ class UserService {
|
||||
String? password,
|
||||
String? email,
|
||||
}) {
|
||||
var payload = UpdateUserProfilePayload.create()..id = userId;
|
||||
var payload = UpdateUserProfilePayloadPB.create()..id = userId;
|
||||
|
||||
if (name != null) {
|
||||
payload.name = name;
|
||||
@ -49,8 +49,8 @@ class UserService {
|
||||
return UserEventInitUser().send();
|
||||
}
|
||||
|
||||
Future<Either<List<Workspace>, FlowyError>> getWorkspaces() {
|
||||
final request = WorkspaceId.create();
|
||||
Future<Either<List<WorkspacePB>, FlowyError>> getWorkspaces() {
|
||||
final request = WorkspaceIdPB.create();
|
||||
|
||||
return FolderEventReadWorkspaces(request).send().then((result) {
|
||||
return result.fold(
|
||||
@ -60,8 +60,8 @@ class UserService {
|
||||
});
|
||||
}
|
||||
|
||||
Future<Either<Workspace, FlowyError>> openWorkspace(String workspaceId) {
|
||||
final request = WorkspaceId.create()..value = workspaceId;
|
||||
Future<Either<WorkspacePB, FlowyError>> openWorkspace(String workspaceId) {
|
||||
final request = WorkspaceIdPB.create()..value = workspaceId;
|
||||
return FolderEventOpenWorkspace(request).send().then((result) {
|
||||
return result.fold(
|
||||
(workspace) => left(workspace),
|
||||
@ -70,8 +70,8 @@ class UserService {
|
||||
});
|
||||
}
|
||||
|
||||
Future<Either<Workspace, FlowyError>> createWorkspace(String name, String desc) {
|
||||
final request = CreateWorkspacePayload.create()
|
||||
Future<Either<WorkspacePB, FlowyError>> createWorkspace(String name, String desc) {
|
||||
final request = CreateWorkspacePayloadPB.create()
|
||||
..name = name
|
||||
..desc = desc;
|
||||
return FolderEventCreateWorkspace(request).send().then((result) {
|
||||
|
@ -5,11 +5,11 @@ import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-user/user_setting.pb.dart';
|
||||
|
||||
class UserSettingsService {
|
||||
Future<AppearanceSettings> getAppearanceSettings() async {
|
||||
Future<AppearanceSettingsPB> getAppearanceSettings() async {
|
||||
final result = await UserEventGetAppearanceSetting().send();
|
||||
|
||||
return result.fold(
|
||||
(AppearanceSettings setting) {
|
||||
(AppearanceSettingsPB setting) {
|
||||
return setting;
|
||||
},
|
||||
(error) {
|
||||
@ -18,7 +18,7 @@ class UserSettingsService {
|
||||
);
|
||||
}
|
||||
|
||||
Future<Either<Unit, FlowyError>> setAppearanceSettings(AppearanceSettings settings) {
|
||||
Future<Either<Unit, FlowyError>> setAppearanceSettings(AppearanceSettingsPB settings) {
|
||||
return UserEventSetAppearanceSetting(settings).send();
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,11 @@
|
||||
import 'package:flowy_sdk/protobuf/flowy-user/protobuf.dart' show UserProfile;
|
||||
import 'package:flowy_sdk/protobuf/flowy-user/protobuf.dart' show UserProfilePB;
|
||||
import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
part 'auth_state.freezed.dart';
|
||||
|
||||
@freezed
|
||||
class AuthState with _$AuthState {
|
||||
const factory AuthState.authenticated(UserProfile userProfile) = Authenticated;
|
||||
const factory AuthState.authenticated(UserProfilePB userProfile) = Authenticated;
|
||||
const factory AuthState.unauthenticated(FlowyError error) = Unauthenticated;
|
||||
const factory AuthState.initial() = _Initial;
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ import 'package:app_flowy/user/presentation/welcome_screen.dart';
|
||||
import 'package:app_flowy/workspace/presentation/home/home_screen.dart';
|
||||
import 'package:flowy_infra/time/duration.dart';
|
||||
import 'package:flowy_infra_ui/widget/route/animation.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-user/protobuf.dart' show UserProfile;
|
||||
import 'package:flowy_sdk/protobuf/flowy-user/protobuf.dart' show UserProfilePB;
|
||||
import 'package:flowy_sdk/protobuf/flowy-folder/protobuf.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
@ -16,7 +16,7 @@ class AuthRouter {
|
||||
// TODO: implement showForgetPasswordScreen
|
||||
}
|
||||
|
||||
void pushWelcomeScreen(BuildContext context, UserProfile userProfile) {
|
||||
void pushWelcomeScreen(BuildContext context, UserProfilePB userProfile) {
|
||||
getIt<SplashRoute>().pushWelcomeScreen(context, userProfile);
|
||||
}
|
||||
|
||||
@ -28,7 +28,7 @@ class AuthRouter {
|
||||
);
|
||||
}
|
||||
|
||||
void pushHomeScreen(BuildContext context, UserProfile profile, CurrentWorkspaceSetting workspaceSetting) {
|
||||
void pushHomeScreen(BuildContext context, UserProfilePB profile, CurrentWorkspaceSettingPB workspaceSetting) {
|
||||
Navigator.push(
|
||||
context,
|
||||
PageRoutes.fade(() => HomeScreen(profile, workspaceSetting), RouteDurations.slow.inMilliseconds * .001),
|
||||
@ -37,7 +37,7 @@ class AuthRouter {
|
||||
}
|
||||
|
||||
class SplashRoute {
|
||||
Future<void> pushWelcomeScreen(BuildContext context, UserProfile userProfile) async {
|
||||
Future<void> pushWelcomeScreen(BuildContext context, UserProfilePB userProfile) async {
|
||||
final screen = WelcomeScreen(userProfile: userProfile);
|
||||
final workspaceId = await Navigator.of(context).push(
|
||||
PageRoutes.fade(
|
||||
@ -49,7 +49,7 @@ class SplashRoute {
|
||||
pushHomeScreen(context, userProfile, workspaceId);
|
||||
}
|
||||
|
||||
void pushHomeScreen(BuildContext context, UserProfile userProfile, CurrentWorkspaceSetting workspaceSetting) {
|
||||
void pushHomeScreen(BuildContext context, UserProfilePB userProfile, CurrentWorkspaceSettingPB workspaceSetting) {
|
||||
Navigator.push(
|
||||
context,
|
||||
PageRoutes.fade(() => HomeScreen(userProfile, workspaceSetting), RouteDurations.slow.inMilliseconds * .001),
|
||||
|
@ -10,7 +10,7 @@ import 'package:flowy_infra_ui/widget/rounded_input_field.dart';
|
||||
import 'package:flowy_infra_ui/widget/spacing.dart';
|
||||
import 'package:flowy_infra_ui/style_widget/snap_bar.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-user/protobuf.dart' show UserProfile;
|
||||
import 'package:flowy_sdk/protobuf/flowy-user/protobuf.dart' show UserProfilePB;
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
@ -39,7 +39,7 @@ class SignInScreen extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
void _handleSuccessOrFail(Either<UserProfile, FlowyError> result, BuildContext context) {
|
||||
void _handleSuccessOrFail(Either<UserProfilePB, FlowyError> result, BuildContext context) {
|
||||
result.fold(
|
||||
(user) => router.pushWelcomeScreen(context, user),
|
||||
(error) => showSnapBar(context, error.msg),
|
||||
|
@ -8,7 +8,7 @@ import 'package:flowy_infra_ui/widget/rounded_button.dart';
|
||||
import 'package:flowy_infra_ui/widget/rounded_input_field.dart';
|
||||
import 'package:flowy_infra_ui/widget/spacing.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-user/protobuf.dart' show UserProfile;
|
||||
import 'package:flowy_sdk/protobuf/flowy-user/protobuf.dart' show UserProfilePB;
|
||||
import 'package:flowy_infra_ui/style_widget/snap_bar.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
@ -36,7 +36,7 @@ class SignUpScreen extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
void _handleSuccessOrFail(BuildContext context, Either<UserProfile, FlowyError> result) {
|
||||
void _handleSuccessOrFail(BuildContext context, Either<UserProfilePB, FlowyError> result) {
|
||||
result.fold(
|
||||
(user) => router.pushWelcomeScreen(context, user),
|
||||
(error) => showSnapBar(context, error.msg),
|
||||
|
@ -116,8 +116,8 @@ class _SkipLogInScreenState extends State<SkipLogInScreen> {
|
||||
|
||||
void _openCurrentWorkspace(
|
||||
BuildContext context,
|
||||
UserProfile user,
|
||||
dartz.Either<CurrentWorkspaceSetting, FlowyError> workspacesOrError,
|
||||
UserProfilePB user,
|
||||
dartz.Either<CurrentWorkspaceSettingPB, FlowyError> workspacesOrError,
|
||||
) {
|
||||
workspacesOrError.fold(
|
||||
(workspaceSetting) {
|
||||
|
@ -12,7 +12,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:app_flowy/generated/locale_keys.g.dart';
|
||||
|
||||
class WelcomeScreen extends StatelessWidget {
|
||||
final UserProfile userProfile;
|
||||
final UserProfilePB userProfile;
|
||||
const WelcomeScreen({
|
||||
Key? key,
|
||||
required this.userProfile,
|
||||
@ -65,7 +65,7 @@ class WelcomeScreen extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _renderList(List<Workspace> workspaces) {
|
||||
Widget _renderList(List<WorkspacePB> workspaces) {
|
||||
return Expanded(
|
||||
child: StyledListView(
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
@ -80,7 +80,7 @@ class WelcomeScreen extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
void _handleOnPress(BuildContext context, Workspace workspace) {
|
||||
void _handleOnPress(BuildContext context, WorkspacePB workspace) {
|
||||
context.read<WelcomeBloc>().add(WelcomeEvent.openWorkspace(workspace));
|
||||
|
||||
Navigator.of(context).pop(workspace.id);
|
||||
@ -88,8 +88,8 @@ class WelcomeScreen extends StatelessWidget {
|
||||
}
|
||||
|
||||
class WorkspaceItem extends StatelessWidget {
|
||||
final Workspace workspace;
|
||||
final void Function(Workspace workspace) onPressed;
|
||||
final WorkspacePB workspace;
|
||||
final void Function(WorkspacePB workspace) onPressed;
|
||||
const WorkspaceItem({Key? key, required this.workspace, required this.onPressed}) : super(key: key);
|
||||
|
||||
@override
|
||||
|
@ -18,7 +18,7 @@ import 'package:dartz/dartz.dart';
|
||||
part 'app_bloc.freezed.dart';
|
||||
|
||||
class AppBloc extends Bloc<AppEvent, AppState> {
|
||||
final App app;
|
||||
final AppPB app;
|
||||
final AppService appService;
|
||||
final AppListener appListener;
|
||||
|
||||
@ -103,7 +103,7 @@ class AppBloc extends Bloc<AppEvent, AppState> {
|
||||
return super.close();
|
||||
}
|
||||
|
||||
Future<void> _didReceiveViewUpdated(List<View> views, Emitter<AppState> emit) async {
|
||||
Future<void> _didReceiveViewUpdated(List<ViewPB> views, Emitter<AppState> emit) async {
|
||||
final latestCreatedView = state.latestCreatedView;
|
||||
AppState newState = state.copyWith(views: views);
|
||||
if (latestCreatedView != null) {
|
||||
@ -139,20 +139,20 @@ class AppEvent with _$AppEvent {
|
||||
) = CreateView;
|
||||
const factory AppEvent.delete() = Delete;
|
||||
const factory AppEvent.rename(String newName) = Rename;
|
||||
const factory AppEvent.didReceiveViewUpdated(List<View> views) = ReceiveViews;
|
||||
const factory AppEvent.appDidUpdate(App app) = AppDidUpdate;
|
||||
const factory AppEvent.didReceiveViewUpdated(List<ViewPB> views) = ReceiveViews;
|
||||
const factory AppEvent.appDidUpdate(AppPB app) = AppDidUpdate;
|
||||
}
|
||||
|
||||
@freezed
|
||||
class AppState with _$AppState {
|
||||
const factory AppState({
|
||||
required App app,
|
||||
required List<View> views,
|
||||
View? latestCreatedView,
|
||||
required AppPB app,
|
||||
required List<ViewPB> views,
|
||||
ViewPB? latestCreatedView,
|
||||
required Either<Unit, FlowyError> successOrFailure,
|
||||
}) = _AppState;
|
||||
|
||||
factory AppState.initial(App app) => AppState(
|
||||
factory AppState.initial(AppPB app) => AppState(
|
||||
app: app,
|
||||
views: [],
|
||||
successOrFailure: left(unit),
|
||||
@ -161,8 +161,8 @@ class AppState with _$AppState {
|
||||
|
||||
class AppViewDataContext extends ChangeNotifier {
|
||||
final String appId;
|
||||
final ValueNotifier<List<View>> _viewsNotifier = ValueNotifier([]);
|
||||
final ValueNotifier<View?> _selectedViewNotifier = ValueNotifier(null);
|
||||
final ValueNotifier<List<ViewPB>> _viewsNotifier = ValueNotifier([]);
|
||||
final ValueNotifier<ViewPB?> _selectedViewNotifier = ValueNotifier(null);
|
||||
VoidCallback? _menuSharedStateListener;
|
||||
ExpandableController expandController = ExpandableController(initialExpanded: false);
|
||||
|
||||
@ -173,7 +173,7 @@ class AppViewDataContext extends ChangeNotifier {
|
||||
});
|
||||
}
|
||||
|
||||
VoidCallback addSelectedViewChangeListener(void Function(View?) callback) {
|
||||
VoidCallback addSelectedViewChangeListener(void Function(ViewPB?) callback) {
|
||||
listener() {
|
||||
callback(_selectedViewNotifier.value);
|
||||
}
|
||||
@ -186,7 +186,7 @@ class AppViewDataContext extends ChangeNotifier {
|
||||
_selectedViewNotifier.removeListener(listener);
|
||||
}
|
||||
|
||||
void _setLatestView(View? view) {
|
||||
void _setLatestView(ViewPB? view) {
|
||||
view?.freeze();
|
||||
|
||||
if (_selectedViewNotifier.value != view) {
|
||||
@ -196,9 +196,9 @@ class AppViewDataContext extends ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
View? get selectedView => _selectedViewNotifier.value;
|
||||
ViewPB? get selectedView => _selectedViewNotifier.value;
|
||||
|
||||
set views(List<View> views) {
|
||||
set views(List<ViewPB> views) {
|
||||
if (_viewsNotifier.value != views) {
|
||||
_viewsNotifier.value = views;
|
||||
_expandIfNeed();
|
||||
@ -206,9 +206,9 @@ class AppViewDataContext extends ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
UnmodifiableListView<View> get views => UnmodifiableListView(_viewsNotifier.value);
|
||||
UnmodifiableListView<ViewPB> get views => UnmodifiableListView(_viewsNotifier.value);
|
||||
|
||||
VoidCallback addViewsChangeListener(void Function(UnmodifiableListView<View>) callback) {
|
||||
VoidCallback addViewsChangeListener(void Function(UnmodifiableListView<ViewPB>) callback) {
|
||||
listener() {
|
||||
callback(views);
|
||||
}
|
||||
|
@ -10,8 +10,8 @@ import 'package:flowy_sdk/protobuf/flowy-folder/view.pb.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-folder/dart_notification.pb.dart';
|
||||
import 'package:flowy_sdk/rust_stream.dart';
|
||||
|
||||
typedef AppDidUpdateCallback = void Function(App app);
|
||||
typedef ViewsDidChangeCallback = void Function(Either<List<View>, FlowyError> viewsOrFailed);
|
||||
typedef AppDidUpdateCallback = void Function(AppPB app);
|
||||
typedef ViewsDidChangeCallback = void Function(Either<List<ViewPB>, FlowyError> viewsOrFailed);
|
||||
|
||||
class AppListener {
|
||||
StreamSubscription<SubscribeObject>? _subscription;
|
||||
@ -37,7 +37,7 @@ class AppListener {
|
||||
if (_viewsChanged != null) {
|
||||
result.fold(
|
||||
(payload) {
|
||||
final repeatedView = RepeatedView.fromBuffer(payload);
|
||||
final repeatedView = RepeatedViewPB.fromBuffer(payload);
|
||||
_viewsChanged!(left(repeatedView.items));
|
||||
},
|
||||
(error) => _viewsChanged!(right(error)),
|
||||
@ -48,7 +48,7 @@ class AppListener {
|
||||
if (_updated != null) {
|
||||
result.fold(
|
||||
(payload) {
|
||||
final app = App.fromBuffer(payload);
|
||||
final app = AppPB.fromBuffer(payload);
|
||||
_updated!(app);
|
||||
},
|
||||
(error) => Log.error(error),
|
||||
|
@ -14,20 +14,20 @@ class AppService {
|
||||
required this.appId,
|
||||
});
|
||||
|
||||
Future<Either<App, FlowyError>> getAppDesc({required String appId}) {
|
||||
final payload = AppId.create()..value = appId;
|
||||
Future<Either<AppPB, FlowyError>> getAppDesc({required String appId}) {
|
||||
final payload = AppIdPB.create()..value = appId;
|
||||
|
||||
return FolderEventReadApp(payload).send();
|
||||
}
|
||||
|
||||
Future<Either<View, FlowyError>> createView({
|
||||
Future<Either<ViewPB, FlowyError>> createView({
|
||||
required String appId,
|
||||
required String name,
|
||||
required String desc,
|
||||
required PluginDataType dataType,
|
||||
required PluginType pluginType,
|
||||
}) {
|
||||
final payload = CreateViewPayload.create()
|
||||
final payload = CreateViewPayloadPB.create()
|
||||
..belongToId = appId
|
||||
..name = name
|
||||
..desc = desc
|
||||
@ -37,8 +37,8 @@ class AppService {
|
||||
return FolderEventCreateView(payload).send();
|
||||
}
|
||||
|
||||
Future<Either<List<View>, FlowyError>> getViews({required String appId}) {
|
||||
final payload = AppId.create()..value = appId;
|
||||
Future<Either<List<ViewPB>, FlowyError>> getViews({required String appId}) {
|
||||
final payload = AppIdPB.create()..value = appId;
|
||||
|
||||
return FolderEventReadApp(payload).send().then((result) {
|
||||
return result.fold(
|
||||
@ -49,12 +49,12 @@ class AppService {
|
||||
}
|
||||
|
||||
Future<Either<Unit, FlowyError>> delete({required String appId}) {
|
||||
final request = AppId.create()..value = appId;
|
||||
final request = AppIdPB.create()..value = appId;
|
||||
return FolderEventDeleteApp(request).send();
|
||||
}
|
||||
|
||||
Future<Either<Unit, FlowyError>> updateApp({required String appId, String? name}) {
|
||||
UpdateAppPayload payload = UpdateAppPayload.create()..appId = appId;
|
||||
UpdateAppPayloadPB payload = UpdateAppPayloadPB.create()..appId = appId;
|
||||
|
||||
if (name != null) {
|
||||
payload.name = name;
|
||||
@ -67,7 +67,7 @@ class AppService {
|
||||
required int fromIndex,
|
||||
required int toIndex,
|
||||
}) {
|
||||
final payload = MoveFolderItemPayload.create()
|
||||
final payload = MoveFolderItemPayloadPB.create()
|
||||
..itemId = viewId
|
||||
..from = fromIndex
|
||||
..to = toIndex
|
||||
|
@ -9,7 +9,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:easy_localization/easy_localization.dart';
|
||||
|
||||
class AppearanceSettingModel extends ChangeNotifier with EquatableMixin {
|
||||
AppearanceSettings setting;
|
||||
AppearanceSettingsPB setting;
|
||||
AppTheme _theme;
|
||||
Locale _locale;
|
||||
Timer? _saveOperation;
|
||||
|
@ -17,7 +17,7 @@ part 'doc_bloc.freezed.dart';
|
||||
typedef FlutterQuillDocument = Document;
|
||||
|
||||
class DocumentBloc extends Bloc<DocumentEvent, DocumentState> {
|
||||
final View view;
|
||||
final ViewPB view;
|
||||
final DocumentService service;
|
||||
|
||||
final ViewListener listener;
|
||||
|
@ -9,7 +9,7 @@ class DocumentService {
|
||||
Future<Either<TextBlockDeltaPB, FlowyError>> openDocument({
|
||||
required String docId,
|
||||
}) async {
|
||||
await FolderEventSetLatestView(ViewId(value: docId)).send();
|
||||
await FolderEventSetLatestView(ViewIdPB(value: docId)).send();
|
||||
|
||||
final payload = TextBlockIdPB(value: docId);
|
||||
return TextBlockEventGetBlockData(payload).send();
|
||||
@ -23,7 +23,7 @@ class DocumentService {
|
||||
}
|
||||
|
||||
Future<Either<Unit, FlowyError>> closeDocument({required String docId}) {
|
||||
final request = ViewId(value: docId);
|
||||
final request = ViewIdPB(value: docId);
|
||||
return FolderEventCloseView(request).send();
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ part 'share_bloc.freezed.dart';
|
||||
|
||||
class DocShareBloc extends Bloc<DocShareEvent, DocShareState> {
|
||||
ShareService service;
|
||||
View view;
|
||||
ViewPB view;
|
||||
DocShareBloc({required this.view, required this.service}) : super(const DocShareState.initial()) {
|
||||
on<DocShareEvent>((event, emit) async {
|
||||
await event.map(
|
||||
|
@ -30,7 +30,7 @@ class GridBloc extends Bloc<GridEvent, GridState> {
|
||||
return rows;
|
||||
}
|
||||
|
||||
GridBloc({required View view})
|
||||
GridBloc({required ViewPB view})
|
||||
: gridId = view.id,
|
||||
_blocks = LinkedHashMap.identity(),
|
||||
_gridService = GridService(gridId: view.id),
|
||||
|
@ -20,7 +20,7 @@ class GridService {
|
||||
});
|
||||
|
||||
Future<Either<GridPB, FlowyError>> loadGrid() async {
|
||||
await FolderEventSetLatestView(ViewId(value: gridId)).send();
|
||||
await FolderEventSetLatestView(ViewIdPB(value: gridId)).send();
|
||||
|
||||
final payload = GridIdPB(value: gridId);
|
||||
return GridEventGetGrid(payload).send();
|
||||
@ -40,7 +40,7 @@ class GridService {
|
||||
}
|
||||
|
||||
Future<Either<Unit, FlowyError>> closeGrid() {
|
||||
final request = ViewId(value: gridId);
|
||||
final request = ViewIdPB(value: gridId);
|
||||
return FolderEventCloseView(request).send();
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ import 'package:app_flowy/workspace/application/edit_pannel/edit_context.dart';
|
||||
import 'package:flowy_sdk/log.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-error-code/code.pb.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-folder/workspace.pb.dart' show CurrentWorkspaceSetting;
|
||||
import 'package:flowy_sdk/protobuf/flowy-folder/workspace.pb.dart' show CurrentWorkspaceSettingPB;
|
||||
import 'package:flowy_sdk/protobuf/flowy-user/user_profile.pb.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
@ -13,7 +13,7 @@ part 'home_bloc.freezed.dart';
|
||||
class HomeBloc extends Bloc<HomeEvent, HomeState> {
|
||||
final UserWorkspaceListener _listener;
|
||||
|
||||
HomeBloc(UserProfile user, CurrentWorkspaceSetting workspaceSetting)
|
||||
HomeBloc(UserProfilePB user, CurrentWorkspaceSettingPB workspaceSetting)
|
||||
: _listener = UserWorkspaceListener(userProfile: user),
|
||||
super(HomeState.initial(workspaceSetting)) {
|
||||
on<HomeEvent>((event, emit) async {
|
||||
@ -76,7 +76,7 @@ class HomeEvent with _$HomeEvent {
|
||||
const factory HomeEvent.forceCollapse(bool forceCollapse) = _ForceCollapse;
|
||||
const factory HomeEvent.setEditPannel(EditPannelContext editContext) = _ShowEditPannel;
|
||||
const factory HomeEvent.dismissEditPannel() = _DismissEditPannel;
|
||||
const factory HomeEvent.didReceiveWorkspaceSetting(CurrentWorkspaceSetting setting) = _DidReceiveWorkspaceSetting;
|
||||
const factory HomeEvent.didReceiveWorkspaceSetting(CurrentWorkspaceSettingPB setting) = _DidReceiveWorkspaceSetting;
|
||||
const factory HomeEvent.unauthorized(String msg) = _Unauthorized;
|
||||
const factory HomeEvent.collapseMenu() = _CollapseMenu;
|
||||
}
|
||||
@ -87,12 +87,12 @@ class HomeState with _$HomeState {
|
||||
required bool isLoading,
|
||||
required bool forceCollapse,
|
||||
required Option<EditPannelContext> pannelContext,
|
||||
required CurrentWorkspaceSetting workspaceSetting,
|
||||
required CurrentWorkspaceSettingPB workspaceSetting,
|
||||
required bool unauthorized,
|
||||
required bool isMenuCollapsed,
|
||||
}) = _HomeState;
|
||||
|
||||
factory HomeState.initial(CurrentWorkspaceSetting workspaceSetting) => HomeState(
|
||||
factory HomeState.initial(CurrentWorkspaceSettingPB workspaceSetting) => HomeState(
|
||||
isLoading: false,
|
||||
forceCollapse: false,
|
||||
pannelContext: none(),
|
||||
|
@ -41,7 +41,7 @@ class MenuBloc extends Bloc<MenuEvent, MenuState> {
|
||||
if (state.apps.length > value.fromIndex) {
|
||||
final app = state.apps[value.fromIndex];
|
||||
_workspaceService.moveApp(appId: app.id, fromIndex: value.fromIndex, toIndex: value.toIndex);
|
||||
final apps = List<App>.from(state.apps);
|
||||
final apps = List<AppPB>.from(state.apps);
|
||||
apps.insert(value.toIndex, apps.removeAt(value.fromIndex));
|
||||
emit(state.copyWith(apps: apps));
|
||||
}
|
||||
@ -79,7 +79,7 @@ class MenuBloc extends Bloc<MenuEvent, MenuState> {
|
||||
));
|
||||
}
|
||||
|
||||
void _handleAppsOrFail(Either<List<App>, FlowyError> appsOrFail) {
|
||||
void _handleAppsOrFail(Either<List<AppPB>, FlowyError> appsOrFail) {
|
||||
appsOrFail.fold(
|
||||
(apps) => add(MenuEvent.didReceiveApps(left(apps))),
|
||||
(error) => add(MenuEvent.didReceiveApps(right(error))),
|
||||
@ -93,13 +93,13 @@ class MenuEvent with _$MenuEvent {
|
||||
const factory MenuEvent.openPage(Plugin plugin) = _OpenPage;
|
||||
const factory MenuEvent.createApp(String name, {String? desc}) = _CreateApp;
|
||||
const factory MenuEvent.moveApp(int fromIndex, int toIndex) = _MoveApp;
|
||||
const factory MenuEvent.didReceiveApps(Either<List<App>, FlowyError> appsOrFail) = _ReceiveApps;
|
||||
const factory MenuEvent.didReceiveApps(Either<List<AppPB>, FlowyError> appsOrFail) = _ReceiveApps;
|
||||
}
|
||||
|
||||
@freezed
|
||||
class MenuState with _$MenuState {
|
||||
const factory MenuState({
|
||||
required List<App> apps,
|
||||
required List<AppPB> apps,
|
||||
required Either<Unit, FlowyError> successOrFailure,
|
||||
required Plugin plugin,
|
||||
}) = _MenuState;
|
||||
|
@ -14,7 +14,7 @@ class MenuUserBloc extends Bloc<MenuUserEvent, MenuUserState> {
|
||||
final UserService _userService;
|
||||
final UserListener _userListener;
|
||||
final UserWorkspaceListener _userWorkspaceListener;
|
||||
final UserProfile userProfile;
|
||||
final UserProfilePB userProfile;
|
||||
|
||||
MenuUserBloc(this.userProfile)
|
||||
: _userListener = UserListener(userProfile: userProfile),
|
||||
@ -31,7 +31,7 @@ class MenuUserBloc extends Bloc<MenuUserEvent, MenuUserState> {
|
||||
fetchWorkspaces: () async {
|
||||
//
|
||||
},
|
||||
didReceiveUserProfile: (UserProfile newUserProfile) {
|
||||
didReceiveUserProfile: (UserProfilePB newUserProfile) {
|
||||
emit(state.copyWith(userProfile: newUserProfile));
|
||||
},
|
||||
updateUserName: (String name) {
|
||||
@ -58,14 +58,14 @@ class MenuUserBloc extends Bloc<MenuUserEvent, MenuUserState> {
|
||||
result.fold((l) => null, (error) => Log.error(error));
|
||||
}
|
||||
|
||||
void _profileUpdated(Either<UserProfile, FlowyError> userProfileOrFailed) {
|
||||
void _profileUpdated(Either<UserProfilePB, FlowyError> userProfileOrFailed) {
|
||||
userProfileOrFailed.fold(
|
||||
(newUserProfile) => add(MenuUserEvent.didReceiveUserProfile(newUserProfile)),
|
||||
(err) => Log.error(err),
|
||||
);
|
||||
}
|
||||
|
||||
void _workspaceListUpdated(Either<List<Workspace>, FlowyError> workspacesOrFailed) {
|
||||
void _workspaceListUpdated(Either<List<WorkspacePB>, FlowyError> workspacesOrFailed) {
|
||||
// Do nothing by now
|
||||
}
|
||||
}
|
||||
@ -75,18 +75,18 @@ class MenuUserEvent with _$MenuUserEvent {
|
||||
const factory MenuUserEvent.initial() = _Initial;
|
||||
const factory MenuUserEvent.fetchWorkspaces() = _FetchWorkspaces;
|
||||
const factory MenuUserEvent.updateUserName(String name) = _UpdateUserName;
|
||||
const factory MenuUserEvent.didReceiveUserProfile(UserProfile newUserProfile) = _DidReceiveUserProfile;
|
||||
const factory MenuUserEvent.didReceiveUserProfile(UserProfilePB newUserProfile) = _DidReceiveUserProfile;
|
||||
}
|
||||
|
||||
@freezed
|
||||
class MenuUserState with _$MenuUserState {
|
||||
const factory MenuUserState({
|
||||
required UserProfile userProfile,
|
||||
required Option<List<Workspace>> workspaces,
|
||||
required UserProfilePB userProfile,
|
||||
required Option<List<WorkspacePB>> workspaces,
|
||||
required Either<Unit, String> successOrFailure,
|
||||
}) = _MenuUserState;
|
||||
|
||||
factory MenuUserState.initial(UserProfile userProfile) => MenuUserState(
|
||||
factory MenuUserState.initial(UserProfilePB userProfile) => MenuUserState(
|
||||
userProfile: userProfile,
|
||||
workspaces: none(),
|
||||
successOrFailure: left(unit),
|
||||
|
@ -62,7 +62,7 @@ class ViewSectionBloc extends Bloc<ViewSectionEvent, ViewSectionState> {
|
||||
Future<void> _moveView(_MoveView value, Emitter<ViewSectionState> emit) async {
|
||||
if (value.fromIndex < state.views.length) {
|
||||
final viewId = state.views[value.fromIndex].id;
|
||||
final views = List<View>.from(state.views);
|
||||
final views = List<ViewPB>.from(state.views);
|
||||
views.insert(value.toIndex, views.removeAt(value.fromIndex));
|
||||
emit(state.copyWith(views: views));
|
||||
|
||||
@ -92,16 +92,16 @@ class ViewSectionBloc extends Bloc<ViewSectionEvent, ViewSectionState> {
|
||||
@freezed
|
||||
class ViewSectionEvent with _$ViewSectionEvent {
|
||||
const factory ViewSectionEvent.initial() = _Initial;
|
||||
const factory ViewSectionEvent.setSelectedView(View? view) = _SetSelectedView;
|
||||
const factory ViewSectionEvent.setSelectedView(ViewPB? view) = _SetSelectedView;
|
||||
const factory ViewSectionEvent.moveView(int fromIndex, int toIndex) = _MoveView;
|
||||
const factory ViewSectionEvent.didReceiveViewUpdated(List<View> views) = _DidReceiveViewUpdated;
|
||||
const factory ViewSectionEvent.didReceiveViewUpdated(List<ViewPB> views) = _DidReceiveViewUpdated;
|
||||
}
|
||||
|
||||
@freezed
|
||||
class ViewSectionState with _$ViewSectionState {
|
||||
const factory ViewSectionState({
|
||||
required List<View> views,
|
||||
View? selectedView,
|
||||
required List<ViewPB> views,
|
||||
ViewPB? selectedView,
|
||||
}) = _ViewSectionState;
|
||||
|
||||
factory ViewSectionState.initial(AppViewDataContext appViewData) => ViewSectionState(
|
||||
|
@ -45,7 +45,7 @@ class TrashBloc extends Bloc<TrashEvent, TrashState> {
|
||||
));
|
||||
}
|
||||
|
||||
void _listenTrashUpdated(Either<List<Trash>, FlowyError> trashOrFailed) {
|
||||
void _listenTrashUpdated(Either<List<TrashPB>, FlowyError> trashOrFailed) {
|
||||
trashOrFailed.fold(
|
||||
(trash) {
|
||||
add(TrashEvent.didReceiveTrash(trash));
|
||||
@ -66,9 +66,9 @@ class TrashBloc extends Bloc<TrashEvent, TrashState> {
|
||||
@freezed
|
||||
class TrashEvent with _$TrashEvent {
|
||||
const factory TrashEvent.initial() = Initial;
|
||||
const factory TrashEvent.didReceiveTrash(List<Trash> trash) = ReceiveTrash;
|
||||
const factory TrashEvent.didReceiveTrash(List<TrashPB> trash) = ReceiveTrash;
|
||||
const factory TrashEvent.putback(String trashId) = Putback;
|
||||
const factory TrashEvent.delete(Trash trash) = Delete;
|
||||
const factory TrashEvent.delete(TrashPB trash) = Delete;
|
||||
const factory TrashEvent.restoreAll() = RestoreAll;
|
||||
const factory TrashEvent.deleteAll() = DeleteAll;
|
||||
}
|
||||
@ -76,7 +76,7 @@ class TrashEvent with _$TrashEvent {
|
||||
@freezed
|
||||
class TrashState with _$TrashState {
|
||||
const factory TrashState({
|
||||
required List<Trash> objects,
|
||||
required List<TrashPB> objects,
|
||||
required Either<Unit, FlowyError> successOrFailure,
|
||||
}) = _TrashState;
|
||||
|
||||
|
@ -8,7 +8,7 @@ import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-folder/trash.pb.dart';
|
||||
import 'package:flowy_sdk/rust_stream.dart';
|
||||
|
||||
typedef TrashUpdatedCallback = void Function(Either<List<Trash>, FlowyError> trashOrFailed);
|
||||
typedef TrashUpdatedCallback = void Function(Either<List<TrashPB>, FlowyError> trashOrFailed);
|
||||
|
||||
class TrashListener {
|
||||
StreamSubscription<SubscribeObject>? _subscription;
|
||||
@ -27,7 +27,7 @@ class TrashListener {
|
||||
if (_trashUpdated != null) {
|
||||
result.fold(
|
||||
(payload) {
|
||||
final repeatedTrash = RepeatedTrash.fromBuffer(payload);
|
||||
final repeatedTrash = RepeatedTrashPB.fromBuffer(payload);
|
||||
_trashUpdated!(left(repeatedTrash.items));
|
||||
},
|
||||
(error) => _trashUpdated!(right(error)),
|
||||
|
@ -5,24 +5,24 @@ import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-folder/trash.pb.dart';
|
||||
|
||||
class TrashService {
|
||||
Future<Either<RepeatedTrash, FlowyError>> readTrash() {
|
||||
Future<Either<RepeatedTrashPB, FlowyError>> readTrash() {
|
||||
return FolderEventReadTrash().send();
|
||||
}
|
||||
|
||||
Future<Either<Unit, FlowyError>> putback(String trashId) {
|
||||
final id = TrashId.create()..id = trashId;
|
||||
final id = TrashIdPB.create()..id = trashId;
|
||||
|
||||
return FolderEventPutbackTrash(id).send();
|
||||
}
|
||||
|
||||
Future<Either<Unit, FlowyError>> deleteViews(List<Tuple2<String, TrashType>> trashList) {
|
||||
final items = trashList.map((trash) {
|
||||
return TrashId.create()
|
||||
return TrashIdPB.create()
|
||||
..id = trash.value1
|
||||
..ty = trash.value2;
|
||||
});
|
||||
|
||||
final ids = RepeatedTrashId(items: items);
|
||||
final ids = RepeatedTrashIdPB(items: items);
|
||||
return FolderEventDeleteTrash(ids).send();
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,7 @@ part 'view_bloc.freezed.dart';
|
||||
class ViewBloc extends Bloc<ViewEvent, ViewState> {
|
||||
final ViewService service;
|
||||
final ViewListener listener;
|
||||
final View view;
|
||||
final ViewPB view;
|
||||
|
||||
ViewBloc({
|
||||
required this.view,
|
||||
@ -81,18 +81,18 @@ class ViewEvent with _$ViewEvent {
|
||||
const factory ViewEvent.rename(String newName) = Rename;
|
||||
const factory ViewEvent.delete() = Delete;
|
||||
const factory ViewEvent.duplicate() = Duplicate;
|
||||
const factory ViewEvent.viewDidUpdate(Either<View, FlowyError> result) = ViewDidUpdate;
|
||||
const factory ViewEvent.viewDidUpdate(Either<ViewPB, FlowyError> result) = ViewDidUpdate;
|
||||
}
|
||||
|
||||
@freezed
|
||||
class ViewState with _$ViewState {
|
||||
const factory ViewState({
|
||||
required View view,
|
||||
required ViewPB view,
|
||||
required bool isEditing,
|
||||
required Either<Unit, FlowyError> successOrFailure,
|
||||
}) = _ViewState;
|
||||
|
||||
factory ViewState.init(View view) => ViewState(
|
||||
factory ViewState.init(ViewPB view) => ViewState(
|
||||
view: view,
|
||||
isEditing: false,
|
||||
successOrFailure: left(unit),
|
||||
|
@ -32,7 +32,7 @@ extension FlowyPluginExtension on FlowyPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
extension ViewExtension on View {
|
||||
extension ViewExtension on ViewPB {
|
||||
Widget renderThumbnail({Color? iconColor}) {
|
||||
String thumbnail = "file_icon";
|
||||
|
||||
|
@ -9,9 +9,9 @@ import 'package:flowy_sdk/protobuf/flowy-folder/dart_notification.pb.dart';
|
||||
import 'package:flowy_sdk/rust_stream.dart';
|
||||
import 'package:flowy_infra/notifier.dart';
|
||||
|
||||
typedef DeleteViewNotifyValue = Either<View, FlowyError>;
|
||||
typedef UpdateViewNotifiedValue = Either<View, FlowyError>;
|
||||
typedef RestoreViewNotifiedValue = Either<View, FlowyError>;
|
||||
typedef DeleteViewNotifyValue = Either<ViewPB, FlowyError>;
|
||||
typedef UpdateViewNotifiedValue = Either<ViewPB, FlowyError>;
|
||||
typedef RestoreViewNotifiedValue = Either<ViewPB, FlowyError>;
|
||||
|
||||
class ViewListener {
|
||||
StreamSubscription<SubscribeObject>? _subscription;
|
||||
@ -19,7 +19,7 @@ class ViewListener {
|
||||
final PublishNotifier<DeleteViewNotifyValue> _deletedNotifier = PublishNotifier();
|
||||
final PublishNotifier<RestoreViewNotifiedValue> _restoredNotifier = PublishNotifier();
|
||||
FolderNotificationParser? _parser;
|
||||
View view;
|
||||
ViewPB view;
|
||||
|
||||
ViewListener({
|
||||
required this.view,
|
||||
@ -62,19 +62,19 @@ class ViewListener {
|
||||
switch (ty) {
|
||||
case FolderNotification.ViewUpdated:
|
||||
result.fold(
|
||||
(payload) => _updatedViewNotifier.value = left(View.fromBuffer(payload)),
|
||||
(payload) => _updatedViewNotifier.value = left(ViewPB.fromBuffer(payload)),
|
||||
(error) => _updatedViewNotifier.value = right(error),
|
||||
);
|
||||
break;
|
||||
case FolderNotification.ViewDeleted:
|
||||
result.fold(
|
||||
(payload) => _deletedNotifier.value = left(View.fromBuffer(payload)),
|
||||
(payload) => _deletedNotifier.value = left(ViewPB.fromBuffer(payload)),
|
||||
(error) => _deletedNotifier.value = right(error),
|
||||
);
|
||||
break;
|
||||
case FolderNotification.ViewRestored:
|
||||
result.fold(
|
||||
(payload) => _restoredNotifier.value = left(View.fromBuffer(payload)),
|
||||
(payload) => _restoredNotifier.value = left(ViewPB.fromBuffer(payload)),
|
||||
(error) => _restoredNotifier.value = right(error),
|
||||
);
|
||||
break;
|
||||
|
@ -5,13 +5,13 @@ import 'package:flowy_sdk/protobuf/flowy-folder/view.pb.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart';
|
||||
|
||||
class ViewService {
|
||||
Future<Either<View, FlowyError>> readView({required String viewId}) {
|
||||
final request = ViewId(value: viewId);
|
||||
Future<Either<ViewPB, FlowyError>> readView({required String viewId}) {
|
||||
final request = ViewIdPB(value: viewId);
|
||||
return FolderEventReadView(request).send();
|
||||
}
|
||||
|
||||
Future<Either<View, FlowyError>> updateView({required String viewId, String? name, String? desc}) {
|
||||
final request = UpdateViewPayload.create()..viewId = viewId;
|
||||
Future<Either<ViewPB, FlowyError>> updateView({required String viewId, String? name, String? desc}) {
|
||||
final request = UpdateViewPayloadPB.create()..viewId = viewId;
|
||||
|
||||
if (name != null) {
|
||||
request.name = name;
|
||||
@ -25,12 +25,12 @@ class ViewService {
|
||||
}
|
||||
|
||||
Future<Either<Unit, FlowyError>> delete({required String viewId}) {
|
||||
final request = RepeatedViewId.create()..items.add(viewId);
|
||||
final request = RepeatedViewIdPB.create()..items.add(viewId);
|
||||
return FolderEventDeleteView(request).send();
|
||||
}
|
||||
|
||||
Future<Either<Unit, FlowyError>> duplicate({required String viewId}) {
|
||||
final request = ViewId(value: viewId);
|
||||
final request = ViewIdPB(value: viewId);
|
||||
return FolderEventDuplicateView(request).send();
|
||||
}
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ class WelcomeBloc extends Bloc<WelcomeEvent, WelcomeState> {
|
||||
));
|
||||
}
|
||||
|
||||
Future<void> _openWorkspace(Workspace workspace, Emitter<WelcomeState> emit) async {
|
||||
Future<void> _openWorkspace(WorkspacePB workspace, Emitter<WelcomeState> emit) async {
|
||||
final result = await userService.openWorkspace(workspace.id);
|
||||
emit(result.fold(
|
||||
(workspaces) => state.copyWith(successOrFailure: left(unit)),
|
||||
@ -82,8 +82,8 @@ class WelcomeEvent with _$WelcomeEvent {
|
||||
const factory WelcomeEvent.initial() = Initial;
|
||||
// const factory WelcomeEvent.fetchWorkspaces() = FetchWorkspace;
|
||||
const factory WelcomeEvent.createWorkspace(String name, String desc) = CreateWorkspace;
|
||||
const factory WelcomeEvent.openWorkspace(Workspace workspace) = OpenWorkspace;
|
||||
const factory WelcomeEvent.workspacesReveived(Either<List<Workspace>, FlowyError> workspacesOrFail) =
|
||||
const factory WelcomeEvent.openWorkspace(WorkspacePB workspace) = OpenWorkspace;
|
||||
const factory WelcomeEvent.workspacesReveived(Either<List<WorkspacePB>, FlowyError> workspacesOrFail) =
|
||||
WorkspacesReceived;
|
||||
}
|
||||
|
||||
@ -91,7 +91,7 @@ class WelcomeEvent with _$WelcomeEvent {
|
||||
class WelcomeState with _$WelcomeState {
|
||||
const factory WelcomeState({
|
||||
required bool isLoading,
|
||||
required List<Workspace> workspaces,
|
||||
required List<WorkspacePB> workspaces,
|
||||
required Either<Unit, FlowyError> successOrFailure,
|
||||
}) = _WelcomeState;
|
||||
|
||||
|
@ -3,21 +3,21 @@ import 'dart:typed_data';
|
||||
import 'package:app_flowy/core/folder_notification.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:flowy_infra/notifier.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-user/protobuf.dart' show UserProfile;
|
||||
import 'package:flowy_sdk/protobuf/flowy-user/protobuf.dart' show UserProfilePB;
|
||||
import 'package:flowy_sdk/protobuf/flowy-folder/app.pb.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-folder/workspace.pb.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-folder/dart_notification.pb.dart';
|
||||
|
||||
typedef AppListNotifyValue = Either<List<App>, FlowyError>;
|
||||
typedef WorkspaceNotifyValue = Either<Workspace, FlowyError>;
|
||||
typedef AppListNotifyValue = Either<List<AppPB>, FlowyError>;
|
||||
typedef WorkspaceNotifyValue = Either<WorkspacePB, FlowyError>;
|
||||
|
||||
class WorkspaceListener {
|
||||
PublishNotifier<AppListNotifyValue>? _appsChangedNotifier = PublishNotifier();
|
||||
PublishNotifier<WorkspaceNotifyValue>? _workspaceUpdatedNotifier = PublishNotifier();
|
||||
|
||||
FolderNotificationListener? _listener;
|
||||
final UserProfile user;
|
||||
final UserProfilePB user;
|
||||
final String workspaceId;
|
||||
|
||||
WorkspaceListener({
|
||||
@ -47,13 +47,13 @@ class WorkspaceListener {
|
||||
switch (ty) {
|
||||
case FolderNotification.WorkspaceUpdated:
|
||||
result.fold(
|
||||
(payload) => _workspaceUpdatedNotifier?.value = left(Workspace.fromBuffer(payload)),
|
||||
(payload) => _workspaceUpdatedNotifier?.value = left(WorkspacePB.fromBuffer(payload)),
|
||||
(error) => _workspaceUpdatedNotifier?.value = right(error),
|
||||
);
|
||||
break;
|
||||
case FolderNotification.WorkspaceAppsChanged:
|
||||
result.fold(
|
||||
(payload) => _appsChangedNotifier?.value = left(RepeatedApp.fromBuffer(payload).items),
|
||||
(payload) => _appsChangedNotifier?.value = left(RepeatedAppPB.fromBuffer(payload).items),
|
||||
(error) => _appsChangedNotifier?.value = right(error),
|
||||
);
|
||||
break;
|
||||
|
@ -5,7 +5,7 @@ import 'package:easy_localization/easy_localization.dart';
|
||||
import 'package:flowy_sdk/dispatch/dispatch.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-folder/app.pb.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-folder/view.pb.dart' show MoveFolderItemPayload, MoveFolderItemType;
|
||||
import 'package:flowy_sdk/protobuf/flowy-folder/view.pb.dart' show MoveFolderItemPayloadPB, MoveFolderItemType;
|
||||
import 'package:flowy_sdk/protobuf/flowy-folder/workspace.pb.dart';
|
||||
|
||||
import 'package:app_flowy/generated/locale_keys.g.dart';
|
||||
@ -15,16 +15,16 @@ class WorkspaceService {
|
||||
WorkspaceService({
|
||||
required this.workspaceId,
|
||||
});
|
||||
Future<Either<App, FlowyError>> createApp({required String name, required String desc}) {
|
||||
final payload = CreateAppPayload.create()
|
||||
Future<Either<AppPB, FlowyError>> createApp({required String name, required String desc}) {
|
||||
final payload = CreateAppPayloadPB.create()
|
||||
..name = name
|
||||
..workspaceId = workspaceId
|
||||
..desc = desc;
|
||||
return FolderEventCreateApp(payload).send();
|
||||
}
|
||||
|
||||
Future<Either<Workspace, FlowyError>> getWorkspace() {
|
||||
final payload = WorkspaceId.create()..value = workspaceId;
|
||||
Future<Either<WorkspacePB, FlowyError>> getWorkspace() {
|
||||
final payload = WorkspaceIdPB.create()..value = workspaceId;
|
||||
return FolderEventReadWorkspaces(payload).send().then((result) {
|
||||
return result.fold(
|
||||
(workspaces) {
|
||||
@ -41,8 +41,8 @@ class WorkspaceService {
|
||||
});
|
||||
}
|
||||
|
||||
Future<Either<List<App>, FlowyError>> getApps() {
|
||||
final payload = WorkspaceId.create()..value = workspaceId;
|
||||
Future<Either<List<AppPB>, FlowyError>> getApps() {
|
||||
final payload = WorkspaceIdPB.create()..value = workspaceId;
|
||||
return FolderEventReadWorkspaceApps(payload).send().then((result) {
|
||||
return result.fold(
|
||||
(apps) => left(apps.items),
|
||||
@ -56,7 +56,7 @@ class WorkspaceService {
|
||||
required int fromIndex,
|
||||
required int toIndex,
|
||||
}) {
|
||||
final payload = MoveFolderItemPayload.create()
|
||||
final payload = MoveFolderItemPayloadPB.create()
|
||||
..itemId = appId
|
||||
..from = fromIndex
|
||||
..to = toIndex
|
||||
|
@ -5,7 +5,7 @@ import 'package:app_flowy/workspace/presentation/widgets/float_bubble/question_b
|
||||
import 'package:app_flowy/startup/startup.dart';
|
||||
import 'package:flowy_sdk/log.dart';
|
||||
import 'package:flowy_infra_ui/style_widget/container.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-user/protobuf.dart' show UserProfile;
|
||||
import 'package:flowy_sdk/protobuf/flowy-user/protobuf.dart' show UserProfilePB;
|
||||
import 'package:flowy_sdk/protobuf/flowy-folder/protobuf.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
@ -18,8 +18,8 @@ import 'home_stack.dart';
|
||||
import 'menu/menu.dart';
|
||||
|
||||
class HomeScreen extends StatefulWidget {
|
||||
final UserProfile user;
|
||||
final CurrentWorkspaceSetting workspaceSetting;
|
||||
final UserProfilePB user;
|
||||
final CurrentWorkspaceSettingPB workspaceSetting;
|
||||
const HomeScreen(this.user, this.workspaceSetting, {Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
@ -27,7 +27,7 @@ class HomeScreen extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _HomeScreenState extends State<HomeScreen> {
|
||||
View? initialView;
|
||||
ViewPB? initialView;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
|
@ -19,7 +19,7 @@ import 'add_button.dart';
|
||||
import 'right_click_action.dart';
|
||||
|
||||
class MenuAppHeader extends StatelessWidget {
|
||||
final App app;
|
||||
final AppPB app;
|
||||
const MenuAppHeader(
|
||||
this.app, {
|
||||
Key? key,
|
||||
@ -85,7 +85,7 @@ class MenuAppHeader extends StatelessWidget {
|
||||
anchorDirection: AnchorDirection.bottomWithCenterAligned,
|
||||
);
|
||||
},
|
||||
child: BlocSelector<AppBloc, AppState, App>(
|
||||
child: BlocSelector<AppBloc, AppState, AppPB>(
|
||||
selector: (state) => state.app,
|
||||
builder: (context, app) => FlowyText.medium(
|
||||
app.name,
|
||||
|
@ -10,7 +10,7 @@ import 'package:provider/provider.dart';
|
||||
import 'section/section.dart';
|
||||
|
||||
class MenuApp extends StatefulWidget {
|
||||
final App app;
|
||||
final AppPB app;
|
||||
const MenuApp(this.app, {Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
|
@ -21,8 +21,8 @@ import 'disclosure_action.dart';
|
||||
// ignore: must_be_immutable
|
||||
class ViewSectionItem extends StatelessWidget {
|
||||
final bool isSelected;
|
||||
final View view;
|
||||
final void Function(View) onSelected;
|
||||
final ViewPB view;
|
||||
final void Function(ViewPB) onSelected;
|
||||
|
||||
ViewSectionItem({
|
||||
Key? key,
|
||||
|
@ -10,7 +10,7 @@ import 'package:flowy_infra/size.dart';
|
||||
import 'package:flowy_infra/theme.dart';
|
||||
import 'package:flowy_infra_ui/style_widget/scrolling/styled_list.dart';
|
||||
import 'package:flowy_infra_ui/widget/spacing.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-user/protobuf.dart' show UserProfile;
|
||||
import 'package:flowy_sdk/protobuf/flowy-user/protobuf.dart' show UserProfilePB;
|
||||
import 'package:flowy_sdk/protobuf/flowy-folder/view.pb.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-folder/workspace.pb.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@ -32,8 +32,8 @@ import 'menu_user.dart';
|
||||
|
||||
class HomeMenu extends StatelessWidget {
|
||||
final PublishNotifier<bool> _collapsedNotifier;
|
||||
final UserProfile user;
|
||||
final CurrentWorkspaceSetting workspaceSetting;
|
||||
final UserProfilePB user;
|
||||
final CurrentWorkspaceSettingPB workspaceSetting;
|
||||
|
||||
const HomeMenu({
|
||||
Key? key,
|
||||
@ -155,19 +155,19 @@ class HomeMenu extends StatelessWidget {
|
||||
}
|
||||
|
||||
class MenuSharedState {
|
||||
final ValueNotifier<View?> _latestOpenView = ValueNotifier<View?>(null);
|
||||
final ValueNotifier<ViewPB?> _latestOpenView = ValueNotifier<ViewPB?>(null);
|
||||
|
||||
MenuSharedState({View? view}) {
|
||||
MenuSharedState({ViewPB? view}) {
|
||||
_latestOpenView.value = view;
|
||||
}
|
||||
|
||||
View? get latestOpenView => _latestOpenView.value;
|
||||
ViewPB? get latestOpenView => _latestOpenView.value;
|
||||
|
||||
set latestOpenView(View? view) {
|
||||
set latestOpenView(ViewPB? view) {
|
||||
_latestOpenView.value = view;
|
||||
}
|
||||
|
||||
VoidCallback addLatestViewListener(void Function(View?) callback) {
|
||||
VoidCallback addLatestViewListener(void Function(ViewPB?) callback) {
|
||||
listener() {
|
||||
callback(_latestOpenView.value);
|
||||
}
|
||||
|
@ -6,14 +6,14 @@ import 'package:flowy_infra/size.dart';
|
||||
import 'package:flowy_infra/theme.dart';
|
||||
import 'package:flowy_infra_ui/style_widget/text.dart';
|
||||
import 'package:flowy_infra_ui/widget/spacing.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-user/protobuf.dart' show UserProfile;
|
||||
import 'package:flowy_sdk/protobuf/flowy-user/protobuf.dart' show UserProfilePB;
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:app_flowy/generated/locale_keys.g.dart';
|
||||
import 'package:easy_localization/easy_localization.dart';
|
||||
|
||||
class MenuUser extends StatelessWidget {
|
||||
final UserProfile user;
|
||||
final UserProfilePB user;
|
||||
MenuUser(this.user, {Key? key}) : super(key: ValueKey(user.id));
|
||||
|
||||
@override
|
||||
|
@ -9,7 +9,7 @@ import 'src/board_page.dart';
|
||||
class BoardPluginBuilder implements PluginBuilder {
|
||||
@override
|
||||
Plugin build(dynamic data) {
|
||||
if (data is View) {
|
||||
if (data is ViewPB) {
|
||||
return BoardPlugin(pluginType: pluginType, view: data);
|
||||
} else {
|
||||
throw FlowyPluginException.invalidData;
|
||||
@ -32,11 +32,11 @@ class BoardPluginConfig implements PluginConfig {
|
||||
}
|
||||
|
||||
class BoardPlugin extends Plugin {
|
||||
final View _view;
|
||||
final ViewPB _view;
|
||||
final PluginType _pluginType;
|
||||
|
||||
BoardPlugin({
|
||||
required View view,
|
||||
required ViewPB view,
|
||||
required PluginType pluginType,
|
||||
}) : _pluginType = pluginType,
|
||||
_view = view;
|
||||
@ -52,8 +52,8 @@ class BoardPlugin extends Plugin {
|
||||
}
|
||||
|
||||
class GridPluginDisplay extends PluginDisplay {
|
||||
final View _view;
|
||||
GridPluginDisplay({required View view, Key? key}) : _view = view;
|
||||
final ViewPB _view;
|
||||
GridPluginDisplay({required ViewPB view, Key? key}) : _view = view;
|
||||
|
||||
@override
|
||||
Widget get leftBarItem => ViewLeftBarItem(view: _view);
|
||||
|
@ -4,9 +4,9 @@ import 'package:flowy_sdk/protobuf/flowy-folder/view.pb.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class BoardPage extends StatelessWidget {
|
||||
final View _view;
|
||||
final ViewPB _view;
|
||||
|
||||
const BoardPage({required View view, Key? key})
|
||||
const BoardPage({required ViewPB view, Key? key})
|
||||
: _view = view,
|
||||
super(key: key);
|
||||
|
||||
|
@ -36,7 +36,7 @@ export './src/widget/toolbar/toolbar_icon_button.dart';
|
||||
class DocumentPluginBuilder extends PluginBuilder {
|
||||
@override
|
||||
Plugin build(dynamic data) {
|
||||
if (data is View) {
|
||||
if (data is ViewPB) {
|
||||
return DocumentPlugin(pluginType: pluginType, view: data);
|
||||
} else {
|
||||
throw FlowyPluginException.invalidData;
|
||||
@ -54,11 +54,11 @@ class DocumentPluginBuilder extends PluginBuilder {
|
||||
}
|
||||
|
||||
class DocumentPlugin implements Plugin {
|
||||
late View _view;
|
||||
late ViewPB _view;
|
||||
ViewListener? _listener;
|
||||
late PluginType _pluginType;
|
||||
|
||||
DocumentPlugin({required PluginType pluginType, required View view, Key? key}) : _view = view {
|
||||
DocumentPlugin({required PluginType pluginType, required ViewPB view, Key? key}) : _view = view {
|
||||
_pluginType = pluginType;
|
||||
_listener = getIt<ViewListener>(param1: view);
|
||||
_listener?.start(onViewUpdated: (result) {
|
||||
@ -90,9 +90,9 @@ class DocumentPlugin implements Plugin {
|
||||
|
||||
class DocumentPluginDisplay extends PluginDisplay<int> with NavigationItem {
|
||||
final PublishNotifier<int> _displayNotifier = PublishNotifier<int>();
|
||||
final View _view;
|
||||
final ViewPB _view;
|
||||
|
||||
DocumentPluginDisplay({required View view, Key? key}) : _view = view;
|
||||
DocumentPluginDisplay({required ViewPB view, Key? key}) : _view = view;
|
||||
|
||||
@override
|
||||
Widget buildWidget() => DocumentPage(view: _view, key: ValueKey(_view.id));
|
||||
@ -111,7 +111,7 @@ class DocumentPluginDisplay extends PluginDisplay<int> with NavigationItem {
|
||||
}
|
||||
|
||||
class DocumentShareButton extends StatelessWidget {
|
||||
final View view;
|
||||
final ViewPB view;
|
||||
DocumentShareButton({Key? key, required this.view}) : super(key: ValueKey(view.hashCode));
|
||||
|
||||
@override
|
||||
|
@ -14,7 +14,7 @@ import 'styles.dart';
|
||||
import 'widget/banner.dart';
|
||||
|
||||
class DocumentPage extends StatefulWidget {
|
||||
final View view;
|
||||
final ViewPB view;
|
||||
|
||||
DocumentPage({Key? key, required this.view}) : super(key: ValueKey(view.id));
|
||||
|
||||
|
@ -11,7 +11,7 @@ import 'src/grid_page.dart';
|
||||
class GridPluginBuilder implements PluginBuilder {
|
||||
@override
|
||||
Plugin build(dynamic data) {
|
||||
if (data is View) {
|
||||
if (data is ViewPB) {
|
||||
return GridPlugin(pluginType: pluginType, view: data);
|
||||
} else {
|
||||
throw FlowyPluginException.invalidData;
|
||||
@ -34,11 +34,11 @@ class GridPluginConfig implements PluginConfig {
|
||||
}
|
||||
|
||||
class GridPlugin extends Plugin {
|
||||
final View _view;
|
||||
final ViewPB _view;
|
||||
final PluginType _pluginType;
|
||||
|
||||
GridPlugin({
|
||||
required View view,
|
||||
required ViewPB view,
|
||||
required PluginType pluginType,
|
||||
}) : _pluginType = pluginType,
|
||||
_view = view;
|
||||
@ -54,8 +54,8 @@ class GridPlugin extends Plugin {
|
||||
}
|
||||
|
||||
class GridPluginDisplay extends PluginDisplay {
|
||||
final View _view;
|
||||
GridPluginDisplay({required View view, Key? key}) : _view = view;
|
||||
final ViewPB _view;
|
||||
GridPluginDisplay({required ViewPB view, Key? key}) : _view = view;
|
||||
|
||||
@override
|
||||
Widget get leftBarItem => ViewLeftBarItem(view: _view);
|
||||
|
@ -19,7 +19,7 @@ import 'widgets/shortcuts.dart';
|
||||
import 'widgets/toolbar/grid_toolbar.dart';
|
||||
|
||||
class GridPage extends StatefulWidget {
|
||||
final View view;
|
||||
final ViewPB view;
|
||||
|
||||
GridPage({Key? key, required this.view}) : super(key: ValueKey(view.id));
|
||||
|
||||
|
@ -14,7 +14,7 @@ import 'sizes.dart';
|
||||
class TrashCell extends StatelessWidget {
|
||||
final VoidCallback onRestore;
|
||||
final VoidCallback onDelete;
|
||||
final Trash object;
|
||||
final TrashPB object;
|
||||
const TrashCell({required this.object, required this.onRestore, required this.onDelete, Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
|
@ -31,7 +31,7 @@ class TrashPluginBuilder extends PluginBuilder {
|
||||
}
|
||||
|
||||
@override
|
||||
String get menuName => "Trash";
|
||||
String get menuName => "TrashPB";
|
||||
|
||||
@override
|
||||
PluginType get pluginType => DefaultPlugin.trash.type();
|
||||
|
@ -7,7 +7,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
class ViewLeftBarItem extends StatefulWidget {
|
||||
final View view;
|
||||
final ViewPB view;
|
||||
|
||||
ViewLeftBarItem({required this.view, Key? key}) : super(key: ValueKey(view.hashCode));
|
||||
|
||||
@ -20,7 +20,7 @@ class _ViewLeftBarItemState extends State<ViewLeftBarItem> {
|
||||
final _focusNode = FocusNode();
|
||||
late ViewService _viewService;
|
||||
late ViewListener _viewListener;
|
||||
late View view;
|
||||
late ViewPB view;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
|
@ -14,7 +14,7 @@ class FlowyTest {
|
||||
return FlowyTest();
|
||||
}
|
||||
|
||||
Future<UserProfile> signIn() async {
|
||||
Future<UserProfilePB> signIn() async {
|
||||
final authService = getIt<AuthService>();
|
||||
const password = "AppFlowy123@";
|
||||
final uid = uuid();
|
||||
|
@ -7,7 +7,7 @@ import 'package:bloc_test/bloc_test.dart';
|
||||
import 'util/test_env.dart';
|
||||
|
||||
void main() {
|
||||
UserProfile? userInfo;
|
||||
UserProfilePB? userInfo;
|
||||
setUpAll(() async {
|
||||
final flowyTest = await FlowyTest.setup();
|
||||
userInfo = await flowyTest.signIn();
|
||||
|
@ -3,7 +3,7 @@ use crate::{
|
||||
app::{AppColorStyle, AppIdentify, AppName},
|
||||
workspace::WorkspaceIdentify,
|
||||
},
|
||||
entities::view::RepeatedView,
|
||||
entities::view::RepeatedViewPB,
|
||||
errors::ErrorCode,
|
||||
impl_def_and_def_mut,
|
||||
};
|
||||
@ -12,7 +12,7 @@ use flowy_folder_data_model::revision::AppRevision;
|
||||
use std::convert::TryInto;
|
||||
|
||||
#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]
|
||||
pub struct App {
|
||||
pub struct AppPB {
|
||||
#[pb(index = 1)]
|
||||
pub id: String,
|
||||
|
||||
@ -26,7 +26,7 @@ pub struct App {
|
||||
pub desc: String,
|
||||
|
||||
#[pb(index = 5)]
|
||||
pub belongings: RepeatedView,
|
||||
pub belongings: RepeatedViewPB,
|
||||
|
||||
#[pb(index = 6)]
|
||||
pub version: i64,
|
||||
@ -38,9 +38,9 @@ pub struct App {
|
||||
pub create_time: i64,
|
||||
}
|
||||
|
||||
impl std::convert::From<AppRevision> for App {
|
||||
impl std::convert::From<AppRevision> for AppPB {
|
||||
fn from(app_serde: AppRevision) -> Self {
|
||||
App {
|
||||
AppPB {
|
||||
id: app_serde.id,
|
||||
workspace_id: app_serde.workspace_id,
|
||||
name: app_serde.name,
|
||||
@ -53,21 +53,21 @@ impl std::convert::From<AppRevision> for App {
|
||||
}
|
||||
}
|
||||
#[derive(Eq, PartialEq, Debug, Default, ProtoBuf, Clone)]
|
||||
pub struct RepeatedApp {
|
||||
pub struct RepeatedAppPB {
|
||||
#[pb(index = 1)]
|
||||
pub items: Vec<App>,
|
||||
pub items: Vec<AppPB>,
|
||||
}
|
||||
|
||||
impl_def_and_def_mut!(RepeatedApp, App);
|
||||
impl_def_and_def_mut!(RepeatedAppPB, AppPB);
|
||||
|
||||
impl std::convert::From<Vec<AppRevision>> for RepeatedApp {
|
||||
impl std::convert::From<Vec<AppRevision>> for RepeatedAppPB {
|
||||
fn from(values: Vec<AppRevision>) -> Self {
|
||||
let items = values.into_iter().map(|value| value.into()).collect::<Vec<App>>();
|
||||
RepeatedApp { items }
|
||||
let items = values.into_iter().map(|value| value.into()).collect::<Vec<AppPB>>();
|
||||
RepeatedAppPB { items }
|
||||
}
|
||||
}
|
||||
#[derive(ProtoBuf, Default)]
|
||||
pub struct CreateAppPayload {
|
||||
pub struct CreateAppPayloadPB {
|
||||
#[pb(index = 1)]
|
||||
pub workspace_id: String,
|
||||
|
||||
@ -78,31 +78,24 @@ pub struct CreateAppPayload {
|
||||
pub desc: String,
|
||||
|
||||
#[pb(index = 4)]
|
||||
pub color_style: ColorStyle,
|
||||
pub color_style: ColorStylePB,
|
||||
}
|
||||
|
||||
#[derive(ProtoBuf, Default, Debug, Clone)]
|
||||
pub struct ColorStyle {
|
||||
pub struct ColorStylePB {
|
||||
#[pb(index = 1)]
|
||||
pub theme_color: String,
|
||||
}
|
||||
|
||||
#[derive(ProtoBuf, Default, Debug)]
|
||||
#[derive(Debug)]
|
||||
pub struct CreateAppParams {
|
||||
#[pb(index = 1)]
|
||||
pub workspace_id: String,
|
||||
|
||||
#[pb(index = 2)]
|
||||
pub name: String,
|
||||
|
||||
#[pb(index = 3)]
|
||||
pub desc: String,
|
||||
|
||||
#[pb(index = 4)]
|
||||
pub color_style: ColorStyle,
|
||||
pub color_style: ColorStylePB,
|
||||
}
|
||||
|
||||
impl TryInto<CreateAppParams> for CreateAppPayload {
|
||||
impl TryInto<CreateAppParams> for CreateAppPayloadPB {
|
||||
type Error = ErrorCode;
|
||||
|
||||
fn try_into(self) -> Result<CreateAppParams, Self::Error> {
|
||||
@ -119,21 +112,21 @@ impl TryInto<CreateAppParams> for CreateAppPayload {
|
||||
}
|
||||
}
|
||||
|
||||
impl std::convert::From<AppColorStyle> for ColorStyle {
|
||||
impl std::convert::From<AppColorStyle> for ColorStylePB {
|
||||
fn from(data: AppColorStyle) -> Self {
|
||||
ColorStyle {
|
||||
ColorStylePB {
|
||||
theme_color: data.theme_color,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(ProtoBuf, Default, Clone, Debug)]
|
||||
pub struct AppId {
|
||||
pub struct AppIdPB {
|
||||
#[pb(index = 1)]
|
||||
pub value: String,
|
||||
}
|
||||
|
||||
impl AppId {
|
||||
impl AppIdPB {
|
||||
pub fn new(app_id: &str) -> Self {
|
||||
Self {
|
||||
value: app_id.to_string(),
|
||||
@ -142,7 +135,7 @@ impl AppId {
|
||||
}
|
||||
|
||||
#[derive(ProtoBuf, Default)]
|
||||
pub struct UpdateAppPayload {
|
||||
pub struct UpdateAppPayloadPB {
|
||||
#[pb(index = 1)]
|
||||
pub app_id: String,
|
||||
|
||||
@ -153,27 +146,22 @@ pub struct UpdateAppPayload {
|
||||
pub desc: Option<String>,
|
||||
|
||||
#[pb(index = 4, one_of)]
|
||||
pub color_style: Option<ColorStyle>,
|
||||
pub color_style: Option<ColorStylePB>,
|
||||
|
||||
#[pb(index = 5, one_of)]
|
||||
pub is_trash: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(ProtoBuf, Default, Clone, Debug)]
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct UpdateAppParams {
|
||||
#[pb(index = 1)]
|
||||
pub app_id: String,
|
||||
|
||||
#[pb(index = 2, one_of)]
|
||||
pub name: Option<String>,
|
||||
|
||||
#[pb(index = 3, one_of)]
|
||||
pub desc: Option<String>,
|
||||
|
||||
#[pb(index = 4, one_of)]
|
||||
pub color_style: Option<ColorStyle>,
|
||||
pub color_style: Option<ColorStylePB>,
|
||||
|
||||
#[pb(index = 5, one_of)]
|
||||
pub is_trash: Option<bool>,
|
||||
}
|
||||
|
||||
@ -181,7 +169,10 @@ impl UpdateAppParams {
|
||||
pub fn new(app_id: &str) -> Self {
|
||||
Self {
|
||||
app_id: app_id.to_string(),
|
||||
..Default::default()
|
||||
name: None,
|
||||
desc: None,
|
||||
color_style: None,
|
||||
is_trash: None,
|
||||
}
|
||||
}
|
||||
|
||||
@ -201,7 +192,7 @@ impl UpdateAppParams {
|
||||
}
|
||||
}
|
||||
|
||||
impl TryInto<UpdateAppParams> for UpdateAppPayload {
|
||||
impl TryInto<UpdateAppParams> for UpdateAppPayloadPB {
|
||||
type Error = ErrorCode;
|
||||
|
||||
fn try_into(self) -> Result<UpdateAppParams, Self::Error> {
|
||||
|
@ -5,7 +5,7 @@ use serde::{Deserialize, Serialize};
|
||||
use std::fmt::Formatter;
|
||||
|
||||
#[derive(Eq, PartialEq, ProtoBuf, Default, Debug, Clone)]
|
||||
pub struct Trash {
|
||||
pub struct TrashPB {
|
||||
#[pb(index = 1)]
|
||||
pub id: String,
|
||||
|
||||
@ -22,9 +22,9 @@ pub struct Trash {
|
||||
pub ty: TrashType,
|
||||
}
|
||||
|
||||
impl std::convert::From<TrashRevision> for Trash {
|
||||
impl std::convert::From<TrashRevision> for TrashPB {
|
||||
fn from(trash_rev: TrashRevision) -> Self {
|
||||
Trash {
|
||||
TrashPB {
|
||||
id: trash_rev.id,
|
||||
name: trash_rev.name,
|
||||
modified_time: trash_rev.modified_time,
|
||||
@ -34,8 +34,8 @@ impl std::convert::From<TrashRevision> for Trash {
|
||||
}
|
||||
}
|
||||
|
||||
impl std::convert::From<Trash> for TrashRevision {
|
||||
fn from(trash: Trash) -> Self {
|
||||
impl std::convert::From<TrashPB> for TrashRevision {
|
||||
fn from(trash: TrashPB) -> Self {
|
||||
TrashRevision {
|
||||
id: trash.id,
|
||||
name: trash.name,
|
||||
@ -46,16 +46,16 @@ impl std::convert::From<Trash> for TrashRevision {
|
||||
}
|
||||
}
|
||||
#[derive(PartialEq, Debug, Default, ProtoBuf, Clone)]
|
||||
pub struct RepeatedTrash {
|
||||
pub struct RepeatedTrashPB {
|
||||
#[pb(index = 1)]
|
||||
pub items: Vec<Trash>,
|
||||
pub items: Vec<TrashPB>,
|
||||
}
|
||||
|
||||
impl_def_and_def_mut!(RepeatedTrash, Trash);
|
||||
impl std::convert::From<Vec<TrashRevision>> for RepeatedTrash {
|
||||
impl_def_and_def_mut!(RepeatedTrashPB, TrashPB);
|
||||
impl std::convert::From<Vec<TrashRevision>> for RepeatedTrashPB {
|
||||
fn from(trash_revs: Vec<TrashRevision>) -> Self {
|
||||
let items: Vec<Trash> = trash_revs.into_iter().map(|trash_rev| trash_rev.into()).collect();
|
||||
RepeatedTrash { items }
|
||||
let items: Vec<TrashPB> = trash_revs.into_iter().map(|trash_rev| trash_rev.into()).collect();
|
||||
RepeatedTrashPB { items }
|
||||
}
|
||||
}
|
||||
|
||||
@ -106,15 +106,15 @@ impl std::default::Default for TrashType {
|
||||
}
|
||||
|
||||
#[derive(PartialEq, ProtoBuf, Default, Debug, Clone)]
|
||||
pub struct RepeatedTrashId {
|
||||
pub struct RepeatedTrashIdPB {
|
||||
#[pb(index = 1)]
|
||||
pub items: Vec<TrashId>,
|
||||
pub items: Vec<TrashIdPB>,
|
||||
|
||||
#[pb(index = 2)]
|
||||
pub delete_all: bool,
|
||||
}
|
||||
|
||||
impl std::fmt::Display for RepeatedTrashId {
|
||||
impl std::fmt::Display for RepeatedTrashIdPB {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
f.write_str(&format!(
|
||||
"{:?}",
|
||||
@ -123,35 +123,35 @@ impl std::fmt::Display for RepeatedTrashId {
|
||||
}
|
||||
}
|
||||
|
||||
impl RepeatedTrashId {
|
||||
pub fn all() -> RepeatedTrashId {
|
||||
RepeatedTrashId {
|
||||
impl RepeatedTrashIdPB {
|
||||
pub fn all() -> RepeatedTrashIdPB {
|
||||
RepeatedTrashIdPB {
|
||||
items: vec![],
|
||||
delete_all: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::convert::From<Vec<TrashId>> for RepeatedTrashId {
|
||||
fn from(items: Vec<TrashId>) -> Self {
|
||||
RepeatedTrashId {
|
||||
impl std::convert::From<Vec<TrashIdPB>> for RepeatedTrashIdPB {
|
||||
fn from(items: Vec<TrashIdPB>) -> Self {
|
||||
RepeatedTrashIdPB {
|
||||
items,
|
||||
delete_all: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::convert::From<Vec<TrashRevision>> for RepeatedTrashId {
|
||||
impl std::convert::From<Vec<TrashRevision>> for RepeatedTrashIdPB {
|
||||
fn from(trash: Vec<TrashRevision>) -> Self {
|
||||
let items = trash
|
||||
.into_iter()
|
||||
.map(|t| TrashId {
|
||||
.map(|t| TrashIdPB {
|
||||
id: t.id,
|
||||
ty: t.ty.into(),
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
RepeatedTrashId {
|
||||
RepeatedTrashIdPB {
|
||||
items,
|
||||
delete_all: false,
|
||||
}
|
||||
@ -159,7 +159,7 @@ impl std::convert::From<Vec<TrashRevision>> for RepeatedTrashId {
|
||||
}
|
||||
|
||||
#[derive(PartialEq, ProtoBuf, Default, Debug, Clone)]
|
||||
pub struct TrashId {
|
||||
pub struct TrashIdPB {
|
||||
#[pb(index = 1)]
|
||||
pub id: String,
|
||||
|
||||
@ -167,15 +167,15 @@ pub struct TrashId {
|
||||
pub ty: TrashType,
|
||||
}
|
||||
|
||||
impl std::fmt::Display for TrashId {
|
||||
impl std::fmt::Display for TrashIdPB {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
f.write_str(&format!("{:?}:{}", self.ty, self.id))
|
||||
}
|
||||
}
|
||||
|
||||
impl std::convert::From<&TrashRevision> for TrashId {
|
||||
impl std::convert::From<&TrashRevision> for TrashIdPB {
|
||||
fn from(trash: &TrashRevision) -> Self {
|
||||
TrashId {
|
||||
TrashIdPB {
|
||||
id: trash.id.clone(),
|
||||
ty: trash.ty.clone().into(),
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ use flowy_folder_data_model::revision::{gen_view_id, ViewDataTypeRevision, ViewR
|
||||
use std::convert::TryInto;
|
||||
|
||||
#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]
|
||||
pub struct View {
|
||||
pub struct ViewPB {
|
||||
#[pb(index = 1)]
|
||||
pub id: String,
|
||||
|
||||
@ -34,9 +34,9 @@ pub struct View {
|
||||
pub plugin_type: i32,
|
||||
}
|
||||
|
||||
impl std::convert::From<ViewRevision> for View {
|
||||
impl std::convert::From<ViewRevision> for ViewPB {
|
||||
fn from(rev: ViewRevision) -> Self {
|
||||
View {
|
||||
ViewPB {
|
||||
id: rev.id,
|
||||
belong_to_id: rev.belong_to_id,
|
||||
name: rev.name,
|
||||
@ -79,27 +79,27 @@ impl std::convert::From<ViewDataType> for ViewDataTypeRevision {
|
||||
}
|
||||
|
||||
#[derive(Eq, PartialEq, Debug, Default, ProtoBuf, Clone)]
|
||||
pub struct RepeatedView {
|
||||
pub struct RepeatedViewPB {
|
||||
#[pb(index = 1)]
|
||||
pub items: Vec<View>,
|
||||
pub items: Vec<ViewPB>,
|
||||
}
|
||||
|
||||
impl_def_and_def_mut!(RepeatedView, View);
|
||||
impl_def_and_def_mut!(RepeatedViewPB, ViewPB);
|
||||
|
||||
impl std::convert::From<Vec<ViewRevision>> for RepeatedView {
|
||||
impl std::convert::From<Vec<ViewRevision>> for RepeatedViewPB {
|
||||
fn from(values: Vec<ViewRevision>) -> Self {
|
||||
let items = values.into_iter().map(|value| value.into()).collect::<Vec<View>>();
|
||||
RepeatedView { items }
|
||||
let items = values.into_iter().map(|value| value.into()).collect::<Vec<ViewPB>>();
|
||||
RepeatedViewPB { items }
|
||||
}
|
||||
}
|
||||
#[derive(Default, ProtoBuf)]
|
||||
pub struct RepeatedViewId {
|
||||
pub struct RepeatedViewIdPB {
|
||||
#[pb(index = 1)]
|
||||
pub items: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Default, ProtoBuf)]
|
||||
pub struct CreateViewPayload {
|
||||
pub struct CreateViewPayloadPB {
|
||||
#[pb(index = 1)]
|
||||
pub belong_to_id: String,
|
||||
|
||||
@ -122,34 +122,19 @@ pub struct CreateViewPayload {
|
||||
pub data: Vec<u8>,
|
||||
}
|
||||
|
||||
#[derive(Default, ProtoBuf, Debug, Clone)]
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct CreateViewParams {
|
||||
#[pb(index = 1)]
|
||||
pub belong_to_id: String,
|
||||
|
||||
#[pb(index = 2)]
|
||||
pub name: String,
|
||||
|
||||
#[pb(index = 3)]
|
||||
pub desc: String,
|
||||
|
||||
#[pb(index = 4)]
|
||||
pub thumbnail: String,
|
||||
|
||||
#[pb(index = 5)]
|
||||
pub data_type: ViewDataType,
|
||||
|
||||
#[pb(index = 6)]
|
||||
pub view_id: String,
|
||||
|
||||
#[pb(index = 7)]
|
||||
pub data: Vec<u8>,
|
||||
|
||||
#[pb(index = 8)]
|
||||
pub plugin_type: i32,
|
||||
}
|
||||
|
||||
impl TryInto<CreateViewParams> for CreateViewPayload {
|
||||
impl TryInto<CreateViewParams> for CreateViewPayloadPB {
|
||||
type Error = ErrorCode;
|
||||
|
||||
fn try_into(self) -> Result<CreateViewParams, Self::Error> {
|
||||
@ -175,20 +160,20 @@ impl TryInto<CreateViewParams> for CreateViewPayload {
|
||||
}
|
||||
|
||||
#[derive(Default, ProtoBuf, Clone, Debug)]
|
||||
pub struct ViewId {
|
||||
pub struct ViewIdPB {
|
||||
#[pb(index = 1)]
|
||||
pub value: String,
|
||||
}
|
||||
|
||||
impl std::convert::From<&str> for ViewId {
|
||||
impl std::convert::From<&str> for ViewIdPB {
|
||||
fn from(value: &str) -> Self {
|
||||
ViewId {
|
||||
ViewIdPB {
|
||||
value: value.to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::Deref for ViewId {
|
||||
impl std::ops::Deref for ViewIdPB {
|
||||
type Target = str;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
@ -197,7 +182,7 @@ impl std::ops::Deref for ViewId {
|
||||
}
|
||||
|
||||
#[derive(Default, ProtoBuf)]
|
||||
pub struct UpdateViewPayload {
|
||||
pub struct UpdateViewPayloadPB {
|
||||
#[pb(index = 1)]
|
||||
pub view_id: String,
|
||||
|
||||
@ -211,22 +196,15 @@ pub struct UpdateViewPayload {
|
||||
pub thumbnail: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Default, ProtoBuf, Clone, Debug)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct UpdateViewParams {
|
||||
#[pb(index = 1)]
|
||||
pub view_id: String,
|
||||
|
||||
#[pb(index = 2, one_of)]
|
||||
pub name: Option<String>,
|
||||
|
||||
#[pb(index = 3, one_of)]
|
||||
pub desc: Option<String>,
|
||||
|
||||
#[pb(index = 4, one_of)]
|
||||
pub thumbnail: Option<String>,
|
||||
}
|
||||
|
||||
impl TryInto<UpdateViewParams> for UpdateViewPayload {
|
||||
impl TryInto<UpdateViewParams> for UpdateViewPayloadPB {
|
||||
type Error = ErrorCode;
|
||||
|
||||
fn try_into(self) -> Result<UpdateViewParams, Self::Error> {
|
||||
@ -269,7 +247,7 @@ impl std::default::Default for MoveFolderItemType {
|
||||
}
|
||||
|
||||
#[derive(Default, ProtoBuf)]
|
||||
pub struct MoveFolderItemPayload {
|
||||
pub struct MoveFolderItemPayloadPB {
|
||||
#[pb(index = 1)]
|
||||
pub item_id: String,
|
||||
|
||||
@ -290,7 +268,7 @@ pub struct MoveFolderItemParams {
|
||||
pub ty: MoveFolderItemType,
|
||||
}
|
||||
|
||||
impl TryInto<MoveFolderItemParams> for MoveFolderItemPayload {
|
||||
impl TryInto<MoveFolderItemParams> for MoveFolderItemPayloadPB {
|
||||
type Error = ErrorCode;
|
||||
|
||||
fn try_into(self) -> Result<MoveFolderItemParams, Self::Error> {
|
||||
|
@ -1,8 +1,8 @@
|
||||
use crate::entities::{RepeatedView, ViewDataType};
|
||||
use crate::entities::{RepeatedViewPB, ViewDataType};
|
||||
use flowy_derive::ProtoBuf;
|
||||
|
||||
#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]
|
||||
pub struct ViewInfo {
|
||||
pub struct ViewInfoPB {
|
||||
#[pb(index = 1)]
|
||||
pub id: String,
|
||||
|
||||
@ -19,7 +19,7 @@ pub struct ViewInfo {
|
||||
pub data_type: ViewDataType,
|
||||
|
||||
#[pb(index = 6)]
|
||||
pub belongings: RepeatedView,
|
||||
pub belongings: RepeatedViewPB,
|
||||
|
||||
#[pb(index = 7)]
|
||||
pub ext_data: String,
|
||||
|
@ -1,6 +1,6 @@
|
||||
use crate::{
|
||||
entities::parser::workspace::{WorkspaceDesc, WorkspaceIdentify, WorkspaceName},
|
||||
entities::{app::RepeatedApp, view::View},
|
||||
entities::{app::RepeatedAppPB, view::ViewPB},
|
||||
errors::*,
|
||||
impl_def_and_def_mut,
|
||||
};
|
||||
@ -9,7 +9,7 @@ use flowy_folder_data_model::revision::WorkspaceRevision;
|
||||
use std::convert::TryInto;
|
||||
|
||||
#[derive(Eq, PartialEq, ProtoBuf, Default, Debug, Clone)]
|
||||
pub struct Workspace {
|
||||
pub struct WorkspacePB {
|
||||
#[pb(index = 1)]
|
||||
pub id: String,
|
||||
|
||||
@ -20,7 +20,7 @@ pub struct Workspace {
|
||||
pub desc: String,
|
||||
|
||||
#[pb(index = 4)]
|
||||
pub apps: RepeatedApp,
|
||||
pub apps: RepeatedAppPB,
|
||||
|
||||
#[pb(index = 5)]
|
||||
pub modified_time: i64,
|
||||
@ -29,9 +29,9 @@ pub struct Workspace {
|
||||
pub create_time: i64,
|
||||
}
|
||||
|
||||
impl std::convert::From<WorkspaceRevision> for Workspace {
|
||||
impl std::convert::From<WorkspaceRevision> for WorkspacePB {
|
||||
fn from(workspace_serde: WorkspaceRevision) -> Self {
|
||||
Workspace {
|
||||
WorkspacePB {
|
||||
id: workspace_serde.id,
|
||||
name: workspace_serde.name,
|
||||
desc: workspace_serde.desc,
|
||||
@ -42,15 +42,15 @@ impl std::convert::From<WorkspaceRevision> for Workspace {
|
||||
}
|
||||
}
|
||||
#[derive(PartialEq, Debug, Default, ProtoBuf)]
|
||||
pub struct RepeatedWorkspace {
|
||||
pub struct RepeatedWorkspacePB {
|
||||
#[pb(index = 1)]
|
||||
pub items: Vec<Workspace>,
|
||||
pub items: Vec<WorkspacePB>,
|
||||
}
|
||||
|
||||
impl_def_and_def_mut!(RepeatedWorkspace, Workspace);
|
||||
impl_def_and_def_mut!(RepeatedWorkspacePB, WorkspacePB);
|
||||
|
||||
#[derive(ProtoBuf, Default)]
|
||||
pub struct CreateWorkspacePayload {
|
||||
pub struct CreateWorkspacePayloadPB {
|
||||
#[pb(index = 1)]
|
||||
pub name: String,
|
||||
|
||||
@ -58,16 +58,13 @@ pub struct CreateWorkspacePayload {
|
||||
pub desc: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, ProtoBuf, Default, Debug)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct CreateWorkspaceParams {
|
||||
#[pb(index = 1)]
|
||||
pub name: String,
|
||||
|
||||
#[pb(index = 2)]
|
||||
pub desc: String,
|
||||
}
|
||||
|
||||
impl TryInto<CreateWorkspaceParams> for CreateWorkspacePayload {
|
||||
impl TryInto<CreateWorkspaceParams> for CreateWorkspacePayloadPB {
|
||||
type Error = ErrorCode;
|
||||
|
||||
fn try_into(self) -> Result<CreateWorkspaceParams, Self::Error> {
|
||||
@ -83,28 +80,28 @@ impl TryInto<CreateWorkspaceParams> for CreateWorkspacePayload {
|
||||
|
||||
// Read all workspaces if the workspace_id is None
|
||||
#[derive(Clone, ProtoBuf, Default, Debug)]
|
||||
pub struct WorkspaceId {
|
||||
pub struct WorkspaceIdPB {
|
||||
#[pb(index = 1, one_of)]
|
||||
pub value: Option<String>,
|
||||
}
|
||||
|
||||
impl WorkspaceId {
|
||||
impl WorkspaceIdPB {
|
||||
pub fn new(workspace_id: Option<String>) -> Self {
|
||||
Self { value: workspace_id }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default, ProtoBuf, Clone)]
|
||||
pub struct CurrentWorkspaceSetting {
|
||||
pub struct CurrentWorkspaceSettingPB {
|
||||
#[pb(index = 1)]
|
||||
pub workspace: Workspace,
|
||||
pub workspace: WorkspacePB,
|
||||
|
||||
#[pb(index = 2, one_of)]
|
||||
pub latest_view: Option<View>,
|
||||
pub latest_view: Option<ViewPB>,
|
||||
}
|
||||
|
||||
#[derive(ProtoBuf, Default)]
|
||||
pub struct UpdateWorkspaceRequest {
|
||||
pub struct UpdateWorkspacePayloadPB {
|
||||
#[pb(index = 1)]
|
||||
pub id: String,
|
||||
|
||||
@ -115,19 +112,14 @@ pub struct UpdateWorkspaceRequest {
|
||||
pub desc: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Clone, ProtoBuf, Default, Debug)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct UpdateWorkspaceParams {
|
||||
#[pb(index = 1)]
|
||||
pub id: String,
|
||||
|
||||
#[pb(index = 2, one_of)]
|
||||
pub name: Option<String>,
|
||||
|
||||
#[pb(index = 3, one_of)]
|
||||
pub desc: Option<String>,
|
||||
}
|
||||
|
||||
impl TryInto<UpdateWorkspaceParams> for UpdateWorkspaceRequest {
|
||||
impl TryInto<UpdateWorkspaceParams> for UpdateWorkspacePayloadPB {
|
||||
type Error = ErrorCode;
|
||||
|
||||
fn try_into(self) -> Result<UpdateWorkspaceParams, Self::Error> {
|
||||
|
@ -1,9 +1,9 @@
|
||||
use crate::{
|
||||
entities::{
|
||||
app::{AppId, CreateAppParams, UpdateAppParams},
|
||||
trash::RepeatedTrashId,
|
||||
view::{CreateViewParams, RepeatedViewId, UpdateViewParams, ViewId},
|
||||
workspace::{CreateWorkspaceParams, UpdateWorkspaceParams, WorkspaceId},
|
||||
app::{AppIdPB, CreateAppParams, UpdateAppParams},
|
||||
trash::RepeatedTrashIdPB,
|
||||
view::{CreateViewParams, RepeatedViewIdPB, UpdateViewParams, ViewIdPB},
|
||||
workspace::{CreateWorkspaceParams, UpdateWorkspaceParams, WorkspaceIdPB},
|
||||
},
|
||||
errors::FlowyError,
|
||||
manager::FolderManager,
|
||||
@ -84,73 +84,73 @@ pub fn create(folder: Arc<FolderManager>) -> Module {
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Debug, Display, Hash, ProtoBuf_Enum, Flowy_Event)]
|
||||
#[event_err = "FlowyError"]
|
||||
pub enum FolderEvent {
|
||||
#[event(input = "CreateWorkspacePayload", output = "Workspace")]
|
||||
#[event(input = "CreateWorkspacePayloadPB", output = "WorkspacePB")]
|
||||
CreateWorkspace = 0,
|
||||
|
||||
#[event(output = "CurrentWorkspaceSetting")]
|
||||
#[event(output = "CurrentWorkspaceSettingPB")]
|
||||
ReadCurWorkspace = 1,
|
||||
|
||||
#[event(input = "WorkspaceId", output = "RepeatedWorkspace")]
|
||||
#[event(input = "WorkspaceIdPB", output = "RepeatedWorkspacePB")]
|
||||
ReadWorkspaces = 2,
|
||||
|
||||
#[event(input = "WorkspaceId")]
|
||||
#[event(input = "WorkspaceIdPB")]
|
||||
DeleteWorkspace = 3,
|
||||
|
||||
#[event(input = "WorkspaceId", output = "Workspace")]
|
||||
#[event(input = "WorkspaceIdPB", output = "WorkspacePB")]
|
||||
OpenWorkspace = 4,
|
||||
|
||||
#[event(input = "WorkspaceId", output = "RepeatedApp")]
|
||||
#[event(input = "WorkspaceIdPB", output = "RepeatedAppPB")]
|
||||
ReadWorkspaceApps = 5,
|
||||
|
||||
#[event(input = "CreateAppPayload", output = "App")]
|
||||
#[event(input = "CreateAppPayloadPB", output = "AppPB")]
|
||||
CreateApp = 101,
|
||||
|
||||
#[event(input = "AppId")]
|
||||
#[event(input = "AppIdPB")]
|
||||
DeleteApp = 102,
|
||||
|
||||
#[event(input = "AppId", output = "App")]
|
||||
#[event(input = "AppIdPB", output = "AppPB")]
|
||||
ReadApp = 103,
|
||||
|
||||
#[event(input = "UpdateAppPayload")]
|
||||
#[event(input = "UpdateAppPayloadPB")]
|
||||
UpdateApp = 104,
|
||||
|
||||
#[event(input = "CreateViewPayload", output = "View")]
|
||||
#[event(input = "CreateViewPayloadPB", output = "ViewPB")]
|
||||
CreateView = 201,
|
||||
|
||||
#[event(input = "ViewId", output = "View")]
|
||||
#[event(input = "ViewIdPB", output = "ViewPB")]
|
||||
ReadView = 202,
|
||||
|
||||
#[event(input = "UpdateViewPayload", output = "View")]
|
||||
#[event(input = "UpdateViewPayloadPB", output = "ViewPB")]
|
||||
UpdateView = 203,
|
||||
|
||||
#[event(input = "RepeatedViewId")]
|
||||
#[event(input = "RepeatedViewIdPB")]
|
||||
DeleteView = 204,
|
||||
|
||||
#[event(input = "ViewId")]
|
||||
#[event(input = "ViewIdPB")]
|
||||
DuplicateView = 205,
|
||||
|
||||
#[event(input = "ViewId")]
|
||||
#[event(input = "ViewIdPB")]
|
||||
CloseView = 206,
|
||||
|
||||
#[event(input = "ViewId", output = "ViewInfo")]
|
||||
#[event(input = "ViewIdPB", output = "ViewInfoPB")]
|
||||
ReadViewInfo = 207,
|
||||
|
||||
#[event()]
|
||||
CopyLink = 220,
|
||||
|
||||
#[event(input = "ViewId")]
|
||||
#[event(input = "ViewIdPB")]
|
||||
SetLatestView = 221,
|
||||
|
||||
#[event(input = "MoveFolderItemPayload")]
|
||||
#[event(input = "MoveFolderItemPayloadPB")]
|
||||
MoveFolderItem = 230,
|
||||
|
||||
#[event(output = "RepeatedTrash")]
|
||||
#[event(output = "RepeatedTrashPB")]
|
||||
ReadTrash = 300,
|
||||
|
||||
#[event(input = "TrashId")]
|
||||
#[event(input = "TrashIdPB")]
|
||||
PutbackTrash = 301,
|
||||
|
||||
#[event(input = "RepeatedTrashId")]
|
||||
#[event(input = "RepeatedTrashIdPB")]
|
||||
DeleteTrash = 302,
|
||||
|
||||
#[event()]
|
||||
@ -170,34 +170,34 @@ pub trait FolderCouldServiceV1: Send + Sync {
|
||||
params: CreateWorkspaceParams,
|
||||
) -> FutureResult<WorkspaceRevision, FlowyError>;
|
||||
|
||||
fn read_workspace(&self, token: &str, params: WorkspaceId) -> FutureResult<Vec<WorkspaceRevision>, FlowyError>;
|
||||
fn read_workspace(&self, token: &str, params: WorkspaceIdPB) -> FutureResult<Vec<WorkspaceRevision>, FlowyError>;
|
||||
|
||||
fn update_workspace(&self, token: &str, params: UpdateWorkspaceParams) -> FutureResult<(), FlowyError>;
|
||||
|
||||
fn delete_workspace(&self, token: &str, params: WorkspaceId) -> FutureResult<(), FlowyError>;
|
||||
fn delete_workspace(&self, token: &str, params: WorkspaceIdPB) -> FutureResult<(), FlowyError>;
|
||||
|
||||
// View
|
||||
fn create_view(&self, token: &str, params: CreateViewParams) -> FutureResult<ViewRevision, FlowyError>;
|
||||
|
||||
fn read_view(&self, token: &str, params: ViewId) -> FutureResult<Option<ViewRevision>, FlowyError>;
|
||||
fn read_view(&self, token: &str, params: ViewIdPB) -> FutureResult<Option<ViewRevision>, FlowyError>;
|
||||
|
||||
fn delete_view(&self, token: &str, params: RepeatedViewId) -> FutureResult<(), FlowyError>;
|
||||
fn delete_view(&self, token: &str, params: RepeatedViewIdPB) -> FutureResult<(), FlowyError>;
|
||||
|
||||
fn update_view(&self, token: &str, params: UpdateViewParams) -> FutureResult<(), FlowyError>;
|
||||
|
||||
// App
|
||||
fn create_app(&self, token: &str, params: CreateAppParams) -> FutureResult<AppRevision, FlowyError>;
|
||||
|
||||
fn read_app(&self, token: &str, params: AppId) -> FutureResult<Option<AppRevision>, FlowyError>;
|
||||
fn read_app(&self, token: &str, params: AppIdPB) -> FutureResult<Option<AppRevision>, FlowyError>;
|
||||
|
||||
fn update_app(&self, token: &str, params: UpdateAppParams) -> FutureResult<(), FlowyError>;
|
||||
|
||||
fn delete_app(&self, token: &str, params: AppId) -> FutureResult<(), FlowyError>;
|
||||
fn delete_app(&self, token: &str, params: AppIdPB) -> FutureResult<(), FlowyError>;
|
||||
|
||||
// Trash
|
||||
fn create_trash(&self, token: &str, params: RepeatedTrashId) -> FutureResult<(), FlowyError>;
|
||||
fn create_trash(&self, token: &str, params: RepeatedTrashIdPB) -> FutureResult<(), FlowyError>;
|
||||
|
||||
fn delete_trash(&self, token: &str, params: RepeatedTrashId) -> FutureResult<(), FlowyError>;
|
||||
fn delete_trash(&self, token: &str, params: RepeatedTrashIdPB) -> FutureResult<(), FlowyError>;
|
||||
|
||||
fn read_trash(&self, token: &str) -> FutureResult<Vec<TrashRevision>, FlowyError>;
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
use crate::entities::view::ViewDataType;
|
||||
use crate::{
|
||||
dart_notification::{send_dart_notification, FolderNotification},
|
||||
entities::workspace::RepeatedWorkspace,
|
||||
entities::workspace::RepeatedWorkspacePB,
|
||||
errors::FlowyResult,
|
||||
event_map::{FolderCouldServiceV1, WorkspaceDatabase, WorkspaceUser},
|
||||
services::{
|
||||
@ -216,7 +216,7 @@ impl DefaultFolderBuilder {
|
||||
let folder = FolderPad::new(vec![workspace_rev.clone()], vec![])?;
|
||||
let folder_id = FolderId::new(user_id);
|
||||
let _ = persistence.save_folder(user_id, &folder_id, folder).await?;
|
||||
let repeated_workspace = RepeatedWorkspace {
|
||||
let repeated_workspace = RepeatedWorkspacePB {
|
||||
items: vec![workspace_rev.into()],
|
||||
};
|
||||
send_dart_notification(token, FolderNotification::UserCreateWorkspace)
|
||||
|
@ -1,7 +1,7 @@
|
||||
use crate::{
|
||||
dart_notification::*,
|
||||
entities::{
|
||||
app::{App, CreateAppParams, *},
|
||||
app::{AppPB, CreateAppParams, *},
|
||||
trash::TrashType,
|
||||
},
|
||||
errors::*,
|
||||
@ -44,12 +44,12 @@ impl AppController {
|
||||
}
|
||||
|
||||
#[tracing::instrument(level = "debug", skip(self, params), fields(name = %params.name) err)]
|
||||
pub(crate) async fn create_app_from_params(&self, params: CreateAppParams) -> Result<App, FlowyError> {
|
||||
pub(crate) async fn create_app_from_params(&self, params: CreateAppParams) -> Result<AppPB, FlowyError> {
|
||||
let app = self.create_app_on_server(params).await?;
|
||||
self.create_app_on_local(app).await
|
||||
}
|
||||
|
||||
pub(crate) async fn create_app_on_local(&self, app: AppRevision) -> Result<App, FlowyError> {
|
||||
pub(crate) async fn create_app_on_local(&self, app: AppRevision) -> Result<AppPB, FlowyError> {
|
||||
let _ = self
|
||||
.persistence
|
||||
.begin_transaction(|transaction| {
|
||||
@ -61,7 +61,7 @@ impl AppController {
|
||||
Ok(app.into())
|
||||
}
|
||||
|
||||
pub(crate) async fn read_app(&self, params: AppId) -> Result<AppRevision, FlowyError> {
|
||||
pub(crate) async fn read_app(&self, params: AppIdPB) -> Result<AppRevision, FlowyError> {
|
||||
let app = self
|
||||
.persistence
|
||||
.begin_transaction(|transaction| {
|
||||
@ -81,7 +81,7 @@ impl AppController {
|
||||
let changeset = AppChangeset::new(params.clone());
|
||||
let app_id = changeset.id.clone();
|
||||
|
||||
let app: App = self
|
||||
let app: AppPB = self
|
||||
.persistence
|
||||
.begin_transaction(|transaction| {
|
||||
let _ = transaction.update_app(changeset)?;
|
||||
@ -150,7 +150,7 @@ impl AppController {
|
||||
}
|
||||
|
||||
#[tracing::instrument(level = "trace", skip(self), err)]
|
||||
fn read_app_on_server(&self, params: AppId) -> Result<(), FlowyError> {
|
||||
fn read_app_on_server(&self, params: AppIdPB) -> Result<(), FlowyError> {
|
||||
let token = self.user.token()?;
|
||||
let server = self.cloud_service.clone();
|
||||
let persistence = self.persistence.clone();
|
||||
@ -162,7 +162,7 @@ impl AppController {
|
||||
.await
|
||||
{
|
||||
Ok(_) => {
|
||||
let app: App = app_rev.into();
|
||||
let app: AppPB = app_rev.into();
|
||||
send_dart_notification(&app.id, FolderNotification::AppUpdated)
|
||||
.payload(app)
|
||||
.send();
|
||||
@ -247,7 +247,7 @@ fn notify_apps_changed<'a>(
|
||||
.into_iter()
|
||||
.map(|app_rev| app_rev.into())
|
||||
.collect();
|
||||
let repeated_app = RepeatedApp { items };
|
||||
let repeated_app = RepeatedAppPB { items };
|
||||
send_dart_notification(workspace_id, FolderNotification::WorkspaceAppsChanged)
|
||||
.payload(repeated_app)
|
||||
.send();
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::{
|
||||
entities::app::{App, AppId, CreateAppParams, CreateAppPayload, UpdateAppParams, UpdateAppPayload},
|
||||
entities::app::{AppIdPB, AppPB, CreateAppParams, CreateAppPayloadPB, UpdateAppParams, UpdateAppPayloadPB},
|
||||
errors::FlowyError,
|
||||
services::{AppController, TrashController, ViewController},
|
||||
};
|
||||
@ -8,9 +8,9 @@ use lib_dispatch::prelude::{data_result, AppData, Data, DataResult};
|
||||
use std::{convert::TryInto, sync::Arc};
|
||||
|
||||
pub(crate) async fn create_app_handler(
|
||||
data: Data<CreateAppPayload>,
|
||||
data: Data<CreateAppPayloadPB>,
|
||||
controller: AppData<Arc<AppController>>,
|
||||
) -> DataResult<App, FlowyError> {
|
||||
) -> DataResult<AppPB, FlowyError> {
|
||||
let params: CreateAppParams = data.into_inner().try_into()?;
|
||||
let detail = controller.create_app_from_params(params).await?;
|
||||
|
||||
@ -18,11 +18,11 @@ pub(crate) async fn create_app_handler(
|
||||
}
|
||||
|
||||
pub(crate) async fn delete_app_handler(
|
||||
data: Data<AppId>,
|
||||
data: Data<AppIdPB>,
|
||||
app_controller: AppData<Arc<AppController>>,
|
||||
trash_controller: AppData<Arc<TrashController>>,
|
||||
) -> Result<(), FlowyError> {
|
||||
let params: AppId = data.into_inner();
|
||||
let params: AppIdPB = data.into_inner();
|
||||
let trash = app_controller
|
||||
.read_local_apps(vec![params.value])
|
||||
.await?
|
||||
@ -36,7 +36,7 @@ pub(crate) async fn delete_app_handler(
|
||||
|
||||
#[tracing::instrument(level = "debug", skip(data, controller))]
|
||||
pub(crate) async fn update_app_handler(
|
||||
data: Data<UpdateAppPayload>,
|
||||
data: Data<UpdateAppPayloadPB>,
|
||||
controller: AppData<Arc<AppController>>,
|
||||
) -> Result<(), FlowyError> {
|
||||
let params: UpdateAppParams = data.into_inner().try_into()?;
|
||||
@ -46,11 +46,11 @@ pub(crate) async fn update_app_handler(
|
||||
|
||||
#[tracing::instrument(level = "trace", skip(data, app_controller, view_controller))]
|
||||
pub(crate) async fn read_app_handler(
|
||||
data: Data<AppId>,
|
||||
data: Data<AppIdPB>,
|
||||
app_controller: AppData<Arc<AppController>>,
|
||||
view_controller: AppData<Arc<ViewController>>,
|
||||
) -> DataResult<App, FlowyError> {
|
||||
let params: AppId = data.into_inner();
|
||||
) -> DataResult<AppPB, FlowyError> {
|
||||
let params: AppIdPB = data.into_inner();
|
||||
let mut app_rev = app_controller.read_app(params.clone()).await?;
|
||||
app_rev.belongings = view_controller.read_views_belong_to(¶ms.value).await?;
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
use crate::entities::{
|
||||
app::UpdateAppParams,
|
||||
trash::{Trash, TrashType},
|
||||
trash::{TrashPB, TrashType},
|
||||
};
|
||||
use crate::{errors::FlowyError, services::persistence::version_1::workspace_sql::WorkspaceTable};
|
||||
use flowy_database::{
|
||||
@ -107,9 +107,9 @@ impl AppTable {
|
||||
}
|
||||
}
|
||||
|
||||
impl std::convert::From<AppTable> for Trash {
|
||||
impl std::convert::From<AppTable> for TrashPB {
|
||||
fn from(table: AppTable) -> Self {
|
||||
Trash {
|
||||
TrashPB {
|
||||
id: table.id,
|
||||
name: table.name,
|
||||
modified_time: table.modified_time,
|
||||
|
@ -1,6 +1,6 @@
|
||||
use crate::{
|
||||
entities::{
|
||||
trash::{Trash, TrashType},
|
||||
trash::{TrashPB, TrashType},
|
||||
view::UpdateViewParams,
|
||||
},
|
||||
errors::FlowyError,
|
||||
@ -133,9 +133,9 @@ impl std::convert::From<ViewTable> for ViewRevision {
|
||||
}
|
||||
}
|
||||
|
||||
impl std::convert::From<ViewTable> for Trash {
|
||||
impl std::convert::From<ViewTable> for TrashPB {
|
||||
fn from(table: ViewTable) -> Self {
|
||||
Trash {
|
||||
TrashPB {
|
||||
id: table.id,
|
||||
name: table.name,
|
||||
modified_time: table.modified_time,
|
||||
|
@ -1,6 +1,6 @@
|
||||
use crate::{
|
||||
dart_notification::{send_anonymous_dart_notification, FolderNotification},
|
||||
entities::trash::{RepeatedTrash, RepeatedTrashId, Trash, TrashId, TrashType},
|
||||
entities::trash::{RepeatedTrashIdPB, RepeatedTrashPB, TrashIdPB, TrashPB, TrashType},
|
||||
errors::{FlowyError, FlowyResult},
|
||||
event_map::{FolderCouldServiceV1, WorkspaceUser},
|
||||
services::persistence::{FolderPersistence, FolderPersistenceTransaction},
|
||||
@ -49,12 +49,12 @@ impl TrashController {
|
||||
})
|
||||
.await?;
|
||||
|
||||
let identifier = TrashId {
|
||||
let identifier = TrashIdPB {
|
||||
id: trash.id,
|
||||
ty: trash.ty.into(),
|
||||
};
|
||||
|
||||
let _ = self.delete_trash_on_server(RepeatedTrashId {
|
||||
let _ = self.delete_trash_on_server(RepeatedTrashIdPB {
|
||||
items: vec![identifier.clone()],
|
||||
delete_all: false,
|
||||
})?;
|
||||
@ -67,7 +67,7 @@ impl TrashController {
|
||||
|
||||
#[tracing::instrument(level = "debug", skip(self) err)]
|
||||
pub async fn restore_all_trash(&self) -> FlowyResult<()> {
|
||||
let trash_identifier: RepeatedTrashId = self
|
||||
let trash_identifier: RepeatedTrashIdPB = self
|
||||
.persistence
|
||||
.begin_transaction(|transaction| {
|
||||
let trash = transaction.read_trash(None);
|
||||
@ -81,14 +81,14 @@ impl TrashController {
|
||||
let _ = self.notify.send(TrashEvent::Putback(trash_identifier, tx));
|
||||
let _ = rx.recv().await;
|
||||
|
||||
notify_trash_changed(RepeatedTrash { items: vec![] });
|
||||
notify_trash_changed(RepeatedTrashPB { items: vec![] });
|
||||
let _ = self.delete_all_trash_on_server().await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(level = "debug", skip(self), err)]
|
||||
pub async fn delete_all_trash(&self) -> FlowyResult<()> {
|
||||
let all_trash_identifiers: RepeatedTrashId = self
|
||||
let all_trash_identifiers: RepeatedTrashIdPB = self
|
||||
.persistence
|
||||
.begin_transaction(|transaction| transaction.read_trash(None))
|
||||
.await?
|
||||
@ -96,13 +96,13 @@ impl TrashController {
|
||||
|
||||
let _ = self.delete_with_identifiers(all_trash_identifiers).await?;
|
||||
|
||||
notify_trash_changed(RepeatedTrash { items: vec![] });
|
||||
notify_trash_changed(RepeatedTrashPB { items: vec![] });
|
||||
let _ = self.delete_all_trash_on_server().await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(level = "debug", skip(self), err)]
|
||||
pub async fn delete(&self, trash_identifiers: RepeatedTrashId) -> FlowyResult<()> {
|
||||
pub async fn delete(&self, trash_identifiers: RepeatedTrashIdPB) -> FlowyResult<()> {
|
||||
let _ = self.delete_with_identifiers(trash_identifiers.clone()).await?;
|
||||
let trash_revs = self
|
||||
.persistence
|
||||
@ -116,7 +116,7 @@ impl TrashController {
|
||||
}
|
||||
|
||||
#[tracing::instrument(level = "debug", skip(self), fields(delete_trash_ids), err)]
|
||||
pub async fn delete_with_identifiers(&self, trash_identifiers: RepeatedTrashId) -> FlowyResult<()> {
|
||||
pub async fn delete_with_identifiers(&self, trash_identifiers: RepeatedTrashIdPB) -> FlowyResult<()> {
|
||||
let (tx, mut rx) = mpsc::channel::<FlowyResult<()>>(1);
|
||||
tracing::Span::current().record("delete_trash_ids", &format!("{}", trash_identifiers).as_str());
|
||||
let _ = self.notify.send(TrashEvent::Delete(trash_identifiers.clone(), tx));
|
||||
@ -153,7 +153,7 @@ impl TrashController {
|
||||
pub async fn add<T: Into<TrashRevision>>(&self, trash: Vec<T>) -> Result<(), FlowyError> {
|
||||
let (tx, mut rx) = mpsc::channel::<FlowyResult<()>>(1);
|
||||
let trash_revs: Vec<TrashRevision> = trash.into_iter().map(|t| t.into()).collect();
|
||||
let identifiers = trash_revs.iter().map(|t| t.into()).collect::<Vec<TrashId>>();
|
||||
let identifiers = trash_revs.iter().map(|t| t.into()).collect::<Vec<TrashIdPB>>();
|
||||
|
||||
tracing::Span::current().record(
|
||||
"trash_ids",
|
||||
@ -187,8 +187,8 @@ impl TrashController {
|
||||
self.notify.subscribe()
|
||||
}
|
||||
|
||||
pub async fn read_trash(&self) -> Result<RepeatedTrash, FlowyError> {
|
||||
let items: Vec<Trash> = self
|
||||
pub async fn read_trash(&self) -> Result<RepeatedTrashPB, FlowyError> {
|
||||
let items: Vec<TrashPB> = self
|
||||
.persistence
|
||||
.begin_transaction(|transaction| transaction.read_trash(None))
|
||||
.await?
|
||||
@ -197,7 +197,7 @@ impl TrashController {
|
||||
.collect();
|
||||
|
||||
let _ = self.read_trash_on_server()?;
|
||||
Ok(RepeatedTrash { items })
|
||||
Ok(RepeatedTrashPB { items })
|
||||
}
|
||||
|
||||
pub fn read_trash_ids<'a>(
|
||||
@ -215,7 +215,7 @@ impl TrashController {
|
||||
|
||||
impl TrashController {
|
||||
#[tracing::instrument(level = "trace", skip(self, trash), err)]
|
||||
fn create_trash_on_server<T: Into<RepeatedTrashId>>(&self, trash: T) -> FlowyResult<()> {
|
||||
fn create_trash_on_server<T: Into<RepeatedTrashIdPB>>(&self, trash: T) -> FlowyResult<()> {
|
||||
let token = self.user.token()?;
|
||||
let trash_identifiers = trash.into();
|
||||
let server = self.cloud_service.clone();
|
||||
@ -230,7 +230,7 @@ impl TrashController {
|
||||
}
|
||||
|
||||
#[tracing::instrument(level = "trace", skip(self, trash), err)]
|
||||
fn delete_trash_on_server<T: Into<RepeatedTrashId>>(&self, trash: T) -> FlowyResult<()> {
|
||||
fn delete_trash_on_server<T: Into<RepeatedTrashIdPB>>(&self, trash: T) -> FlowyResult<()> {
|
||||
let token = self.user.token()?;
|
||||
let trash_identifiers = trash.into();
|
||||
let server = self.cloud_service.clone();
|
||||
@ -277,12 +277,12 @@ impl TrashController {
|
||||
async fn delete_all_trash_on_server(&self) -> FlowyResult<()> {
|
||||
let token = self.user.token()?;
|
||||
let server = self.cloud_service.clone();
|
||||
server.delete_trash(&token, RepeatedTrashId::all()).await
|
||||
server.delete_trash(&token, RepeatedTrashIdPB::all()).await
|
||||
}
|
||||
}
|
||||
|
||||
#[tracing::instrument(level = "debug", skip(repeated_trash), fields(n_trash))]
|
||||
fn notify_trash_changed<T: Into<RepeatedTrash>>(repeated_trash: T) {
|
||||
fn notify_trash_changed<T: Into<RepeatedTrashPB>>(repeated_trash: T) {
|
||||
let repeated_trash = repeated_trash.into();
|
||||
tracing::Span::current().record("n_trash", &repeated_trash.len());
|
||||
send_anonymous_dart_notification(FolderNotification::TrashUpdated)
|
||||
@ -292,9 +292,9 @@ fn notify_trash_changed<T: Into<RepeatedTrash>>(repeated_trash: T) {
|
||||
|
||||
#[derive(Clone)]
|
||||
pub enum TrashEvent {
|
||||
NewTrash(RepeatedTrashId, mpsc::Sender<FlowyResult<()>>),
|
||||
Putback(RepeatedTrashId, mpsc::Sender<FlowyResult<()>>),
|
||||
Delete(RepeatedTrashId, mpsc::Sender<FlowyResult<()>>),
|
||||
NewTrash(RepeatedTrashIdPB, mpsc::Sender<FlowyResult<()>>),
|
||||
Putback(RepeatedTrashIdPB, mpsc::Sender<FlowyResult<()>>),
|
||||
Delete(RepeatedTrashIdPB, mpsc::Sender<FlowyResult<()>>),
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for TrashEvent {
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::{
|
||||
entities::trash::{RepeatedTrash, RepeatedTrashId, TrashId},
|
||||
entities::trash::{RepeatedTrashIdPB, RepeatedTrashPB, TrashIdPB},
|
||||
errors::FlowyError,
|
||||
services::TrashController,
|
||||
};
|
||||
@ -9,14 +9,14 @@ use std::sync::Arc;
|
||||
#[tracing::instrument(level = "debug", skip(controller), err)]
|
||||
pub(crate) async fn read_trash_handler(
|
||||
controller: AppData<Arc<TrashController>>,
|
||||
) -> DataResult<RepeatedTrash, FlowyError> {
|
||||
) -> DataResult<RepeatedTrashPB, FlowyError> {
|
||||
let repeated_trash = controller.read_trash().await?;
|
||||
data_result(repeated_trash)
|
||||
}
|
||||
|
||||
#[tracing::instrument(level = "debug", skip(identifier, controller), err)]
|
||||
pub(crate) async fn putback_trash_handler(
|
||||
identifier: Data<TrashId>,
|
||||
identifier: Data<TrashIdPB>,
|
||||
controller: AppData<Arc<TrashController>>,
|
||||
) -> Result<(), FlowyError> {
|
||||
let _ = controller.putback(&identifier.id).await?;
|
||||
@ -25,7 +25,7 @@ pub(crate) async fn putback_trash_handler(
|
||||
|
||||
#[tracing::instrument(level = "debug", skip(identifiers, controller), err)]
|
||||
pub(crate) async fn delete_trash_handler(
|
||||
identifiers: Data<RepeatedTrashId>,
|
||||
identifiers: Data<RepeatedTrashIdPB>,
|
||||
controller: AppData<Arc<TrashController>>,
|
||||
) -> Result<(), FlowyError> {
|
||||
let _ = controller.delete(identifiers.into_inner()).await?;
|
||||
|
@ -1,11 +1,11 @@
|
||||
pub use crate::entities::view::ViewDataType;
|
||||
use crate::entities::ViewInfo;
|
||||
use crate::entities::ViewInfoPB;
|
||||
use crate::manager::{ViewDataProcessor, ViewDataProcessorMap};
|
||||
use crate::{
|
||||
dart_notification::{send_dart_notification, FolderNotification},
|
||||
entities::{
|
||||
trash::{RepeatedTrashId, TrashType},
|
||||
view::{CreateViewParams, RepeatedView, UpdateViewParams, View, ViewId},
|
||||
trash::{RepeatedTrashIdPB, TrashType},
|
||||
view::{CreateViewParams, RepeatedViewPB, UpdateViewParams, ViewIdPB, ViewPB},
|
||||
},
|
||||
errors::{FlowyError, FlowyResult},
|
||||
event_map::{FolderCouldServiceV1, WorkspaceUser},
|
||||
@ -106,7 +106,7 @@ impl ViewController {
|
||||
}
|
||||
|
||||
#[tracing::instrument(level = "debug", skip(self, view_id), fields(view_id = %view_id.value), err)]
|
||||
pub(crate) async fn read_view(&self, view_id: ViewId) -> Result<ViewRevision, FlowyError> {
|
||||
pub(crate) async fn read_view(&self, view_id: ViewIdPB) -> Result<ViewRevision, FlowyError> {
|
||||
let view_rev = self
|
||||
.persistence
|
||||
.begin_transaction(|transaction| {
|
||||
@ -123,25 +123,25 @@ impl ViewController {
|
||||
}
|
||||
|
||||
#[tracing::instrument(level = "debug", skip(self, view_id), fields(view_id = %view_id.value), err)]
|
||||
pub(crate) async fn read_view_info(&self, view_id: ViewId) -> Result<ViewInfo, FlowyError> {
|
||||
pub(crate) async fn read_view_info(&self, view_id: ViewIdPB) -> Result<ViewInfoPB, FlowyError> {
|
||||
let view_info = self
|
||||
.persistence
|
||||
.begin_transaction(|transaction| {
|
||||
let view_rev = transaction.read_view(&view_id.value)?;
|
||||
|
||||
let items: Vec<View> = view_rev
|
||||
let items: Vec<ViewPB> = view_rev
|
||||
.belongings
|
||||
.into_iter()
|
||||
.map(|view_rev| view_rev.into())
|
||||
.collect();
|
||||
|
||||
let view_info = ViewInfo {
|
||||
let view_info = ViewInfoPB {
|
||||
id: view_rev.id,
|
||||
belong_to_id: view_rev.belong_to_id,
|
||||
name: view_rev.name,
|
||||
desc: view_rev.desc,
|
||||
data_type: view_rev.data_type.into(),
|
||||
belongings: RepeatedView { items },
|
||||
belongings: RepeatedViewPB { items },
|
||||
ext_data: view_rev.ext_data,
|
||||
};
|
||||
Ok(view_info)
|
||||
@ -245,7 +245,7 @@ impl ViewController {
|
||||
.begin_transaction(|transaction| {
|
||||
let _ = transaction.update_view(changeset)?;
|
||||
let view_rev = transaction.read_view(&view_id)?;
|
||||
let view: View = view_rev.clone().into();
|
||||
let view: ViewPB = view_rev.clone().into();
|
||||
send_dart_notification(&view_id, FolderNotification::ViewUpdated)
|
||||
.payload(view)
|
||||
.send();
|
||||
@ -297,7 +297,7 @@ impl ViewController {
|
||||
}
|
||||
|
||||
#[tracing::instrument(level = "debug", skip(self), err)]
|
||||
fn read_view_on_server(&self, params: ViewId) -> Result<(), FlowyError> {
|
||||
fn read_view_on_server(&self, params: ViewIdPB) -> Result<(), FlowyError> {
|
||||
let token = self.user.token()?;
|
||||
let server = self.cloud_service.clone();
|
||||
let persistence = self.persistence.clone();
|
||||
@ -310,7 +310,7 @@ impl ViewController {
|
||||
.await
|
||||
{
|
||||
Ok(_) => {
|
||||
let view: View = view_rev.into();
|
||||
let view: ViewPB = view_rev.into();
|
||||
send_dart_notification(&view.id, FolderNotification::ViewUpdated)
|
||||
.payload(view)
|
||||
.send();
|
||||
@ -464,7 +464,7 @@ fn get_data_processor(
|
||||
}
|
||||
|
||||
fn read_local_views_with_transaction<'a>(
|
||||
identifiers: RepeatedTrashId,
|
||||
identifiers: RepeatedTrashIdPB,
|
||||
transaction: &'a (dyn FolderPersistenceTransaction + 'a),
|
||||
) -> Result<Vec<ViewRevision>, FlowyError> {
|
||||
let mut view_revs = vec![];
|
||||
@ -474,7 +474,7 @@ fn read_local_views_with_transaction<'a>(
|
||||
Ok(view_revs)
|
||||
}
|
||||
|
||||
fn notify_dart(view: View, notification: FolderNotification) {
|
||||
fn notify_dart(view: ViewPB, notification: FolderNotification) {
|
||||
send_dart_notification(&view.id, notification).payload(view).send();
|
||||
}
|
||||
|
||||
@ -489,13 +489,13 @@ fn notify_views_changed<'a>(
|
||||
trash_controller: Arc<TrashController>,
|
||||
transaction: &'a (dyn FolderPersistenceTransaction + 'a),
|
||||
) -> FlowyResult<()> {
|
||||
let items: Vec<View> = read_belonging_views_on_local(belong_to_id, trash_controller.clone(), transaction)?
|
||||
let items: Vec<ViewPB> = read_belonging_views_on_local(belong_to_id, trash_controller.clone(), transaction)?
|
||||
.into_iter()
|
||||
.map(|view_rev| view_rev.into())
|
||||
.collect();
|
||||
tracing::Span::current().record("view_count", &format!("{}", items.len()).as_str());
|
||||
|
||||
let repeated_view = RepeatedView { items };
|
||||
let repeated_view = RepeatedViewPB { items };
|
||||
send_dart_notification(belong_to_id, FolderNotification::AppViewsChanged)
|
||||
.payload(repeated_view)
|
||||
.send();
|
||||
|
@ -1,12 +1,13 @@
|
||||
use crate::entities::view::{MoveFolderItemParams, MoveFolderItemPayload, MoveFolderItemType};
|
||||
use crate::entities::ViewInfo;
|
||||
use crate::entities::view::{MoveFolderItemParams, MoveFolderItemPayloadPB, MoveFolderItemType};
|
||||
use crate::entities::ViewInfoPB;
|
||||
use crate::manager::FolderManager;
|
||||
use crate::services::{notify_workspace_setting_did_change, AppController};
|
||||
use crate::{
|
||||
entities::{
|
||||
trash::Trash,
|
||||
trash::TrashPB,
|
||||
view::{
|
||||
CreateViewParams, CreateViewPayload, RepeatedViewId, UpdateViewParams, UpdateViewPayload, View, ViewId,
|
||||
CreateViewParams, CreateViewPayloadPB, RepeatedViewIdPB, UpdateViewParams, UpdateViewPayloadPB, ViewIdPB,
|
||||
ViewPB,
|
||||
},
|
||||
},
|
||||
errors::FlowyError,
|
||||
@ -17,35 +18,35 @@ use lib_dispatch::prelude::{data_result, AppData, Data, DataResult};
|
||||
use std::{convert::TryInto, sync::Arc};
|
||||
|
||||
pub(crate) async fn create_view_handler(
|
||||
data: Data<CreateViewPayload>,
|
||||
data: Data<CreateViewPayloadPB>,
|
||||
controller: AppData<Arc<ViewController>>,
|
||||
) -> DataResult<View, FlowyError> {
|
||||
) -> DataResult<ViewPB, FlowyError> {
|
||||
let params: CreateViewParams = data.into_inner().try_into()?;
|
||||
let view_rev = controller.create_view_from_params(params).await?;
|
||||
data_result(view_rev.into())
|
||||
}
|
||||
|
||||
pub(crate) async fn read_view_handler(
|
||||
data: Data<ViewId>,
|
||||
data: Data<ViewIdPB>,
|
||||
controller: AppData<Arc<ViewController>>,
|
||||
) -> DataResult<View, FlowyError> {
|
||||
let view_id: ViewId = data.into_inner();
|
||||
) -> DataResult<ViewPB, FlowyError> {
|
||||
let view_id: ViewIdPB = data.into_inner();
|
||||
let view_rev = controller.read_view(view_id.clone()).await?;
|
||||
data_result(view_rev.into())
|
||||
}
|
||||
|
||||
pub(crate) async fn read_view_info_handler(
|
||||
data: Data<ViewId>,
|
||||
data: Data<ViewIdPB>,
|
||||
controller: AppData<Arc<ViewController>>,
|
||||
) -> DataResult<ViewInfo, FlowyError> {
|
||||
let view_id: ViewId = data.into_inner();
|
||||
) -> DataResult<ViewInfoPB, FlowyError> {
|
||||
let view_id: ViewIdPB = data.into_inner();
|
||||
let view_info = controller.read_view_info(view_id.clone()).await?;
|
||||
data_result(view_info)
|
||||
}
|
||||
|
||||
#[tracing::instrument(level = "debug", skip(data, controller), err)]
|
||||
pub(crate) async fn update_view_handler(
|
||||
data: Data<UpdateViewPayload>,
|
||||
data: Data<UpdateViewPayloadPB>,
|
||||
controller: AppData<Arc<ViewController>>,
|
||||
) -> Result<(), FlowyError> {
|
||||
let params: UpdateViewParams = data.into_inner().try_into()?;
|
||||
@ -55,11 +56,11 @@ pub(crate) async fn update_view_handler(
|
||||
}
|
||||
|
||||
pub(crate) async fn delete_view_handler(
|
||||
data: Data<RepeatedViewId>,
|
||||
data: Data<RepeatedViewIdPB>,
|
||||
view_controller: AppData<Arc<ViewController>>,
|
||||
trash_controller: AppData<Arc<TrashController>>,
|
||||
) -> Result<(), FlowyError> {
|
||||
let params: RepeatedViewId = data.into_inner();
|
||||
let params: RepeatedViewIdPB = data.into_inner();
|
||||
for view_id in ¶ms.items {
|
||||
let _ = view_controller.delete_view(view_id.into()).await;
|
||||
}
|
||||
@ -72,35 +73,35 @@ pub(crate) async fn delete_view_handler(
|
||||
let trash_rev: TrashRevision = view.into();
|
||||
trash_rev.into()
|
||||
})
|
||||
.collect::<Vec<Trash>>();
|
||||
.collect::<Vec<TrashPB>>();
|
||||
|
||||
let _ = trash_controller.add(trash).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) async fn set_latest_view_handler(
|
||||
data: Data<ViewId>,
|
||||
data: Data<ViewIdPB>,
|
||||
folder: AppData<Arc<FolderManager>>,
|
||||
controller: AppData<Arc<ViewController>>,
|
||||
) -> Result<(), FlowyError> {
|
||||
let view_id: ViewId = data.into_inner();
|
||||
let view_id: ViewIdPB = data.into_inner();
|
||||
let _ = controller.set_latest_view(&view_id.value)?;
|
||||
let _ = notify_workspace_setting_did_change(&folder, &view_id).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) async fn close_view_handler(
|
||||
data: Data<ViewId>,
|
||||
data: Data<ViewIdPB>,
|
||||
controller: AppData<Arc<ViewController>>,
|
||||
) -> Result<(), FlowyError> {
|
||||
let view_id: ViewId = data.into_inner();
|
||||
let view_id: ViewIdPB = data.into_inner();
|
||||
let _ = controller.close_view(&view_id.value).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(level = "debug", skip_all, err)]
|
||||
pub(crate) async fn move_item_handler(
|
||||
data: Data<MoveFolderItemPayload>,
|
||||
data: Data<MoveFolderItemPayloadPB>,
|
||||
view_controller: AppData<Arc<ViewController>>,
|
||||
app_controller: AppData<Arc<AppController>>,
|
||||
) -> Result<(), FlowyError> {
|
||||
@ -120,10 +121,10 @@ pub(crate) async fn move_item_handler(
|
||||
|
||||
#[tracing::instrument(level = "debug", skip(data, controller), err)]
|
||||
pub(crate) async fn duplicate_view_handler(
|
||||
data: Data<ViewId>,
|
||||
data: Data<ViewIdPB>,
|
||||
controller: AppData<Arc<ViewController>>,
|
||||
) -> Result<(), FlowyError> {
|
||||
let view_id: ViewId = data.into_inner();
|
||||
let view_id: ViewIdPB = data.into_inner();
|
||||
let _ = controller.duplicate_view(&view_id.value).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ impl WorkspaceController {
|
||||
.into_iter()
|
||||
.map(|workspace_rev| workspace_rev.into())
|
||||
.collect();
|
||||
let repeated_workspace = RepeatedWorkspace { items: workspaces };
|
||||
let repeated_workspace = RepeatedWorkspacePB { items: workspaces };
|
||||
send_dart_notification(&token, FolderNotification::UserCreateWorkspace)
|
||||
.payload(repeated_workspace)
|
||||
.send();
|
||||
@ -99,7 +99,7 @@ impl WorkspaceController {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) async fn open_workspace(&self, params: WorkspaceId) -> Result<Workspace, FlowyError> {
|
||||
pub(crate) async fn open_workspace(&self, params: WorkspaceIdPB) -> Result<WorkspacePB, FlowyError> {
|
||||
let user_id = self.user.user_id()?;
|
||||
if let Some(workspace_id) = params.value {
|
||||
let workspace = self
|
||||
@ -131,14 +131,14 @@ impl WorkspaceController {
|
||||
workspace_id: Option<String>,
|
||||
user_id: &str,
|
||||
transaction: &'a (dyn FolderPersistenceTransaction + 'a),
|
||||
) -> Result<RepeatedWorkspace, FlowyError> {
|
||||
) -> Result<RepeatedWorkspacePB, FlowyError> {
|
||||
let workspace_id = workspace_id.to_owned();
|
||||
let workspaces = transaction
|
||||
.read_workspaces(user_id, workspace_id)?
|
||||
.into_iter()
|
||||
.map(|workspace_rev| workspace_rev.into())
|
||||
.collect();
|
||||
Ok(RepeatedWorkspace { items: workspaces })
|
||||
Ok(RepeatedWorkspacePB { items: workspaces })
|
||||
}
|
||||
|
||||
pub(crate) fn read_local_workspace<'a>(
|
||||
@ -146,7 +146,7 @@ impl WorkspaceController {
|
||||
workspace_id: String,
|
||||
user_id: &str,
|
||||
transaction: &'a (dyn FolderPersistenceTransaction + 'a),
|
||||
) -> Result<Workspace, FlowyError> {
|
||||
) -> Result<WorkspacePB, FlowyError> {
|
||||
let mut workspace_revs = transaction.read_workspaces(user_id, Some(workspace_id.clone()))?;
|
||||
if workspace_revs.is_empty() {
|
||||
return Err(FlowyError::record_not_found().context(format!("{} workspace not found", workspace_id)));
|
||||
@ -155,7 +155,7 @@ impl WorkspaceController {
|
||||
let workspace = workspace_revs
|
||||
.drain(..1)
|
||||
.map(|workspace_rev| workspace_rev.into())
|
||||
.collect::<Vec<Workspace>>()
|
||||
.collect::<Vec<WorkspacePB>>()
|
||||
.pop()
|
||||
.unwrap();
|
||||
Ok(workspace)
|
||||
@ -186,7 +186,7 @@ impl WorkspaceController {
|
||||
|
||||
#[tracing::instrument(level = "trace", skip(self), err)]
|
||||
fn delete_workspace_on_server(&self, workspace_id: &str) -> Result<(), FlowyError> {
|
||||
let params = WorkspaceId {
|
||||
let params = WorkspaceIdPB {
|
||||
value: Some(workspace_id.to_string()),
|
||||
};
|
||||
let (token, server) = (self.user.token()?, self.cloud_service.clone());
|
||||
@ -221,11 +221,11 @@ pub async fn notify_workspace_setting_did_change(
|
||||
)?;
|
||||
|
||||
let setting = match transaction.read_view(view_id) {
|
||||
Ok(latest_view) => CurrentWorkspaceSetting {
|
||||
Ok(latest_view) => CurrentWorkspaceSettingPB {
|
||||
workspace,
|
||||
latest_view: Some(latest_view.into()),
|
||||
},
|
||||
Err(_) => CurrentWorkspaceSetting {
|
||||
Err(_) => CurrentWorkspaceSettingPB {
|
||||
workspace,
|
||||
latest_view: None,
|
||||
},
|
||||
|
@ -1,7 +1,7 @@
|
||||
use crate::entities::{
|
||||
app::RepeatedApp,
|
||||
view::View,
|
||||
workspace::{CurrentWorkspaceSetting, RepeatedWorkspace, WorkspaceId, *},
|
||||
app::RepeatedAppPB,
|
||||
view::ViewPB,
|
||||
workspace::{CurrentWorkspaceSettingPB, RepeatedWorkspacePB, WorkspaceIdPB, *},
|
||||
};
|
||||
use crate::{
|
||||
dart_notification::{send_dart_notification, FolderNotification},
|
||||
@ -14,9 +14,9 @@ use std::{convert::TryInto, sync::Arc};
|
||||
|
||||
#[tracing::instrument(level = "debug", skip(data, controller), err)]
|
||||
pub(crate) async fn create_workspace_handler(
|
||||
data: Data<CreateWorkspacePayload>,
|
||||
data: Data<CreateWorkspacePayloadPB>,
|
||||
controller: AppData<Arc<WorkspaceController>>,
|
||||
) -> DataResult<Workspace, FlowyError> {
|
||||
) -> DataResult<WorkspacePB, FlowyError> {
|
||||
let controller = controller.get_ref().clone();
|
||||
let params: CreateWorkspaceParams = data.into_inner().try_into()?;
|
||||
let workspace_rev = controller.create_workspace_from_params(params).await?;
|
||||
@ -26,33 +26,33 @@ pub(crate) async fn create_workspace_handler(
|
||||
#[tracing::instrument(level = "debug", skip(controller), err)]
|
||||
pub(crate) async fn read_workspace_apps_handler(
|
||||
controller: AppData<Arc<WorkspaceController>>,
|
||||
) -> DataResult<RepeatedApp, FlowyError> {
|
||||
) -> DataResult<RepeatedAppPB, FlowyError> {
|
||||
let items = controller
|
||||
.read_current_workspace_apps()
|
||||
.await?
|
||||
.into_iter()
|
||||
.map(|app_rev| app_rev.into())
|
||||
.collect();
|
||||
let repeated_app = RepeatedApp { items };
|
||||
let repeated_app = RepeatedAppPB { items };
|
||||
data_result(repeated_app)
|
||||
}
|
||||
|
||||
#[tracing::instrument(level = "debug", skip(data, controller), err)]
|
||||
pub(crate) async fn open_workspace_handler(
|
||||
data: Data<WorkspaceId>,
|
||||
data: Data<WorkspaceIdPB>,
|
||||
controller: AppData<Arc<WorkspaceController>>,
|
||||
) -> DataResult<Workspace, FlowyError> {
|
||||
let params: WorkspaceId = data.into_inner();
|
||||
) -> DataResult<WorkspacePB, FlowyError> {
|
||||
let params: WorkspaceIdPB = data.into_inner();
|
||||
let workspaces = controller.open_workspace(params).await?;
|
||||
data_result(workspaces)
|
||||
}
|
||||
|
||||
#[tracing::instrument(level = "debug", skip(data, folder), err)]
|
||||
pub(crate) async fn read_workspaces_handler(
|
||||
data: Data<WorkspaceId>,
|
||||
data: Data<WorkspaceIdPB>,
|
||||
folder: AppData<Arc<FolderManager>>,
|
||||
) -> DataResult<RepeatedWorkspace, FlowyError> {
|
||||
let params: WorkspaceId = data.into_inner();
|
||||
) -> DataResult<RepeatedWorkspacePB, FlowyError> {
|
||||
let params: WorkspaceIdPB = data.into_inner();
|
||||
let user_id = folder.user.user_id()?;
|
||||
let workspace_controller = folder.workspace_controller.clone();
|
||||
|
||||
@ -79,10 +79,10 @@ pub(crate) async fn read_workspaces_handler(
|
||||
#[tracing::instrument(level = "debug", skip(folder), err)]
|
||||
pub async fn read_cur_workspace_handler(
|
||||
folder: AppData<Arc<FolderManager>>,
|
||||
) -> DataResult<CurrentWorkspaceSetting, FlowyError> {
|
||||
) -> DataResult<CurrentWorkspaceSettingPB, FlowyError> {
|
||||
let workspace_id = get_current_workspace()?;
|
||||
let user_id = folder.user.user_id()?;
|
||||
let params = WorkspaceId {
|
||||
let params = WorkspaceIdPB {
|
||||
value: Some(workspace_id.clone()),
|
||||
};
|
||||
|
||||
@ -95,13 +95,13 @@ pub async fn read_cur_workspace_handler(
|
||||
})
|
||||
.await?;
|
||||
|
||||
let latest_view: Option<View> = folder
|
||||
let latest_view: Option<ViewPB> = folder
|
||||
.view_controller
|
||||
.latest_visit_view()
|
||||
.await
|
||||
.unwrap_or(None)
|
||||
.map(|view_rev| view_rev.into());
|
||||
let setting = CurrentWorkspaceSetting { workspace, latest_view };
|
||||
let setting = CurrentWorkspaceSettingPB { workspace, latest_view };
|
||||
let _ = read_workspaces_on_server(folder, user_id, params);
|
||||
data_result(setting)
|
||||
}
|
||||
@ -110,7 +110,7 @@ pub async fn read_cur_workspace_handler(
|
||||
fn read_workspaces_on_server(
|
||||
folder_manager: AppData<Arc<FolderManager>>,
|
||||
user_id: String,
|
||||
params: WorkspaceId,
|
||||
params: WorkspaceIdPB,
|
||||
) -> Result<(), FlowyError> {
|
||||
let (token, server) = (folder_manager.user.token()?, folder_manager.cloud_service.clone());
|
||||
let persistence = folder_manager.persistence.clone();
|
||||
@ -145,7 +145,7 @@ fn read_workspaces_on_server(
|
||||
})
|
||||
.await?;
|
||||
|
||||
let repeated_workspace = RepeatedWorkspace {
|
||||
let repeated_workspace = RepeatedWorkspacePB {
|
||||
items: workspace_revs
|
||||
.into_iter()
|
||||
.map(|workspace_rev| workspace_rev.into())
|
||||
|
@ -1,6 +1,6 @@
|
||||
use crate::script::{invalid_workspace_name_test_case, FolderScript::*, FolderTest};
|
||||
use flowy_folder::entities::view::ViewDataType;
|
||||
use flowy_folder::entities::workspace::CreateWorkspacePayload;
|
||||
use flowy_folder::entities::workspace::CreateWorkspacePayloadPB;
|
||||
|
||||
use flowy_revision::disk::RevisionState;
|
||||
use flowy_test::{event_builder::*, FlowySDKTest};
|
||||
@ -63,7 +63,7 @@ async fn workspace_create_with_apps() {
|
||||
async fn workspace_create_with_invalid_name() {
|
||||
for (name, code) in invalid_workspace_name_test_case() {
|
||||
let sdk = FlowySDKTest::default();
|
||||
let request = CreateWorkspacePayload {
|
||||
let request = CreateWorkspacePayloadPB {
|
||||
name,
|
||||
desc: "".to_owned(),
|
||||
};
|
||||
|
@ -1,23 +1,23 @@
|
||||
use flowy_folder::entities::view::{RepeatedViewId, ViewId};
|
||||
use flowy_folder::entities::workspace::WorkspaceId;
|
||||
use flowy_folder::entities::view::{RepeatedViewIdPB, ViewIdPB};
|
||||
use flowy_folder::entities::workspace::WorkspaceIdPB;
|
||||
use flowy_folder::entities::{
|
||||
app::{App, RepeatedApp},
|
||||
trash::Trash,
|
||||
view::{RepeatedView, View, ViewDataType},
|
||||
workspace::Workspace,
|
||||
app::{AppIdPB, CreateAppPayloadPB, UpdateAppPayloadPB},
|
||||
trash::{RepeatedTrashPB, TrashIdPB, TrashType},
|
||||
view::{CreateViewPayloadPB, UpdateViewPayloadPB},
|
||||
workspace::{CreateWorkspacePayloadPB, RepeatedWorkspacePB},
|
||||
};
|
||||
use flowy_folder::entities::{
|
||||
app::{AppId, CreateAppPayload, UpdateAppPayload},
|
||||
trash::{RepeatedTrash, TrashId, TrashType},
|
||||
view::{CreateViewPayload, UpdateViewPayload},
|
||||
workspace::{CreateWorkspacePayload, RepeatedWorkspace},
|
||||
app::{AppPB, RepeatedAppPB},
|
||||
trash::TrashPB,
|
||||
view::{RepeatedViewPB, ViewDataType, ViewPB},
|
||||
workspace::WorkspacePB,
|
||||
};
|
||||
use flowy_folder::event_map::FolderEvent::*;
|
||||
use flowy_folder::{errors::ErrorCode, services::folder_editor::FolderEditor};
|
||||
|
||||
use flowy_revision::disk::RevisionState;
|
||||
use flowy_revision::REVISION_WRITE_INTERVAL_IN_MILLIS;
|
||||
use flowy_sync::entities::text_block::TextBlockInfoPB;
|
||||
use flowy_sync::entities::text_block::DocumentPB;
|
||||
use flowy_test::{event_builder::*, FlowySDKTest};
|
||||
use std::{sync::Arc, time::Duration};
|
||||
use tokio::time::sleep;
|
||||
@ -30,7 +30,7 @@ pub enum FolderScript {
|
||||
desc: String,
|
||||
},
|
||||
// AssertWorkspaceRevisionJson(String),
|
||||
AssertWorkspace(Workspace),
|
||||
AssertWorkspace(WorkspacePB),
|
||||
ReadWorkspace(Option<String>),
|
||||
|
||||
// App
|
||||
@ -39,7 +39,7 @@ pub enum FolderScript {
|
||||
desc: String,
|
||||
},
|
||||
// AssertAppRevisionJson(String),
|
||||
AssertApp(App),
|
||||
AssertApp(AppPB),
|
||||
ReadApp(String),
|
||||
UpdateApp {
|
||||
name: Option<String>,
|
||||
@ -53,7 +53,7 @@ pub enum FolderScript {
|
||||
desc: String,
|
||||
data_type: ViewDataType,
|
||||
},
|
||||
AssertView(View),
|
||||
AssertView(ViewPB),
|
||||
ReadView(String),
|
||||
UpdateView {
|
||||
name: Option<String>,
|
||||
@ -79,11 +79,11 @@ pub enum FolderScript {
|
||||
|
||||
pub struct FolderTest {
|
||||
pub sdk: FlowySDKTest,
|
||||
pub all_workspace: Vec<Workspace>,
|
||||
pub workspace: Workspace,
|
||||
pub app: App,
|
||||
pub view: View,
|
||||
pub trash: Vec<Trash>,
|
||||
pub all_workspace: Vec<WorkspacePB>,
|
||||
pub workspace: WorkspacePB,
|
||||
pub app: AppPB,
|
||||
pub view: ViewPB,
|
||||
pub trash: Vec<TrashPB>,
|
||||
// pub folder_editor:
|
||||
}
|
||||
|
||||
@ -101,11 +101,11 @@ impl FolderTest {
|
||||
ViewDataType::TextBlock,
|
||||
)
|
||||
.await;
|
||||
app.belongings = RepeatedView {
|
||||
app.belongings = RepeatedViewPB {
|
||||
items: vec![view.clone()],
|
||||
};
|
||||
|
||||
workspace.apps = RepeatedApp {
|
||||
workspace.apps = RepeatedAppPB {
|
||||
items: vec![app.clone()],
|
||||
};
|
||||
Self {
|
||||
@ -247,8 +247,8 @@ pub fn invalid_workspace_name_test_case() -> Vec<(String, ErrorCode)> {
|
||||
]
|
||||
}
|
||||
|
||||
pub async fn create_workspace(sdk: &FlowySDKTest, name: &str, desc: &str) -> Workspace {
|
||||
let request = CreateWorkspacePayload {
|
||||
pub async fn create_workspace(sdk: &FlowySDKTest, name: &str, desc: &str) -> WorkspacePB {
|
||||
let request = CreateWorkspacePayloadPB {
|
||||
name: name.to_owned(),
|
||||
desc: desc.to_owned(),
|
||||
};
|
||||
@ -258,18 +258,18 @@ pub async fn create_workspace(sdk: &FlowySDKTest, name: &str, desc: &str) -> Wor
|
||||
.payload(request)
|
||||
.async_send()
|
||||
.await
|
||||
.parse::<Workspace>();
|
||||
.parse::<WorkspacePB>();
|
||||
workspace
|
||||
}
|
||||
|
||||
pub async fn read_workspace(sdk: &FlowySDKTest, workspace_id: Option<String>) -> Vec<Workspace> {
|
||||
let request = WorkspaceId { value: workspace_id };
|
||||
pub async fn read_workspace(sdk: &FlowySDKTest, workspace_id: Option<String>) -> Vec<WorkspacePB> {
|
||||
let request = WorkspaceIdPB { value: workspace_id };
|
||||
let mut repeated_workspace = FolderEventBuilder::new(sdk.clone())
|
||||
.event(ReadWorkspaces)
|
||||
.payload(request.clone())
|
||||
.async_send()
|
||||
.await
|
||||
.parse::<RepeatedWorkspace>();
|
||||
.parse::<RepeatedWorkspacePB>();
|
||||
|
||||
let workspaces;
|
||||
if let Some(workspace_id) = &request.value {
|
||||
@ -277,7 +277,7 @@ pub async fn read_workspace(sdk: &FlowySDKTest, workspace_id: Option<String>) ->
|
||||
.into_inner()
|
||||
.into_iter()
|
||||
.filter(|workspace| &workspace.id == workspace_id)
|
||||
.collect::<Vec<Workspace>>();
|
||||
.collect::<Vec<WorkspacePB>>();
|
||||
debug_assert_eq!(workspaces.len(), 1);
|
||||
} else {
|
||||
workspaces = repeated_workspace.items;
|
||||
@ -286,8 +286,8 @@ pub async fn read_workspace(sdk: &FlowySDKTest, workspace_id: Option<String>) ->
|
||||
workspaces
|
||||
}
|
||||
|
||||
pub async fn create_app(sdk: &FlowySDKTest, workspace_id: &str, name: &str, desc: &str) -> App {
|
||||
let create_app_request = CreateAppPayload {
|
||||
pub async fn create_app(sdk: &FlowySDKTest, workspace_id: &str, name: &str, desc: &str) -> AppPB {
|
||||
let create_app_request = CreateAppPayloadPB {
|
||||
workspace_id: workspace_id.to_owned(),
|
||||
name: name.to_string(),
|
||||
desc: desc.to_string(),
|
||||
@ -299,12 +299,12 @@ pub async fn create_app(sdk: &FlowySDKTest, workspace_id: &str, name: &str, desc
|
||||
.payload(create_app_request)
|
||||
.async_send()
|
||||
.await
|
||||
.parse::<App>();
|
||||
.parse::<AppPB>();
|
||||
app
|
||||
}
|
||||
|
||||
pub async fn read_app(sdk: &FlowySDKTest, app_id: &str) -> App {
|
||||
let request = AppId {
|
||||
pub async fn read_app(sdk: &FlowySDKTest, app_id: &str) -> AppPB {
|
||||
let request = AppIdPB {
|
||||
value: app_id.to_owned(),
|
||||
};
|
||||
|
||||
@ -313,13 +313,13 @@ pub async fn read_app(sdk: &FlowySDKTest, app_id: &str) -> App {
|
||||
.payload(request)
|
||||
.async_send()
|
||||
.await
|
||||
.parse::<App>();
|
||||
.parse::<AppPB>();
|
||||
|
||||
app
|
||||
}
|
||||
|
||||
pub async fn update_app(sdk: &FlowySDKTest, app_id: &str, name: Option<String>, desc: Option<String>) {
|
||||
let request = UpdateAppPayload {
|
||||
let request = UpdateAppPayloadPB {
|
||||
app_id: app_id.to_string(),
|
||||
name,
|
||||
desc,
|
||||
@ -335,7 +335,7 @@ pub async fn update_app(sdk: &FlowySDKTest, app_id: &str, name: Option<String>,
|
||||
}
|
||||
|
||||
pub async fn delete_app(sdk: &FlowySDKTest, app_id: &str) {
|
||||
let request = AppId {
|
||||
let request = AppIdPB {
|
||||
value: app_id.to_string(),
|
||||
};
|
||||
|
||||
@ -346,8 +346,8 @@ pub async fn delete_app(sdk: &FlowySDKTest, app_id: &str) {
|
||||
.await;
|
||||
}
|
||||
|
||||
pub async fn create_view(sdk: &FlowySDKTest, app_id: &str, name: &str, desc: &str, data_type: ViewDataType) -> View {
|
||||
let request = CreateViewPayload {
|
||||
pub async fn create_view(sdk: &FlowySDKTest, app_id: &str, name: &str, desc: &str, data_type: ViewDataType) -> ViewPB {
|
||||
let request = CreateViewPayloadPB {
|
||||
belong_to_id: app_id.to_string(),
|
||||
name: name.to_string(),
|
||||
desc: desc.to_string(),
|
||||
@ -361,22 +361,22 @@ pub async fn create_view(sdk: &FlowySDKTest, app_id: &str, name: &str, desc: &st
|
||||
.payload(request)
|
||||
.async_send()
|
||||
.await
|
||||
.parse::<View>();
|
||||
.parse::<ViewPB>();
|
||||
view
|
||||
}
|
||||
|
||||
pub async fn read_view(sdk: &FlowySDKTest, view_id: &str) -> View {
|
||||
let view_id: ViewId = view_id.into();
|
||||
pub async fn read_view(sdk: &FlowySDKTest, view_id: &str) -> ViewPB {
|
||||
let view_id: ViewIdPB = view_id.into();
|
||||
FolderEventBuilder::new(sdk.clone())
|
||||
.event(ReadView)
|
||||
.payload(view_id)
|
||||
.async_send()
|
||||
.await
|
||||
.parse::<View>()
|
||||
.parse::<ViewPB>()
|
||||
}
|
||||
|
||||
pub async fn update_view(sdk: &FlowySDKTest, view_id: &str, name: Option<String>, desc: Option<String>) {
|
||||
let request = UpdateViewPayload {
|
||||
let request = UpdateViewPayloadPB {
|
||||
view_id: view_id.to_string(),
|
||||
name,
|
||||
desc,
|
||||
@ -390,7 +390,7 @@ pub async fn update_view(sdk: &FlowySDKTest, view_id: &str, name: Option<String>
|
||||
}
|
||||
|
||||
pub async fn delete_view(sdk: &FlowySDKTest, view_ids: Vec<String>) {
|
||||
let request = RepeatedViewId { items: view_ids };
|
||||
let request = RepeatedViewIdPB { items: view_ids };
|
||||
FolderEventBuilder::new(sdk.clone())
|
||||
.event(DeleteView)
|
||||
.payload(request)
|
||||
@ -399,26 +399,26 @@ pub async fn delete_view(sdk: &FlowySDKTest, view_ids: Vec<String>) {
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub async fn set_latest_view(sdk: &FlowySDKTest, view_id: &str) -> TextBlockInfoPB {
|
||||
let view_id: ViewId = view_id.into();
|
||||
pub async fn set_latest_view(sdk: &FlowySDKTest, view_id: &str) -> DocumentPB {
|
||||
let view_id: ViewIdPB = view_id.into();
|
||||
FolderEventBuilder::new(sdk.clone())
|
||||
.event(SetLatestView)
|
||||
.payload(view_id)
|
||||
.async_send()
|
||||
.await
|
||||
.parse::<TextBlockInfoPB>()
|
||||
.parse::<DocumentPB>()
|
||||
}
|
||||
|
||||
pub async fn read_trash(sdk: &FlowySDKTest) -> RepeatedTrash {
|
||||
pub async fn read_trash(sdk: &FlowySDKTest) -> RepeatedTrashPB {
|
||||
FolderEventBuilder::new(sdk.clone())
|
||||
.event(ReadTrash)
|
||||
.async_send()
|
||||
.await
|
||||
.parse::<RepeatedTrash>()
|
||||
.parse::<RepeatedTrashPB>()
|
||||
}
|
||||
|
||||
pub async fn restore_app_from_trash(sdk: &FlowySDKTest, app_id: &str) {
|
||||
let id = TrashId {
|
||||
let id = TrashIdPB {
|
||||
id: app_id.to_owned(),
|
||||
ty: TrashType::TrashApp,
|
||||
};
|
||||
@ -430,7 +430,7 @@ pub async fn restore_app_from_trash(sdk: &FlowySDKTest, app_id: &str) {
|
||||
}
|
||||
|
||||
pub async fn restore_view_from_trash(sdk: &FlowySDKTest, view_id: &str) {
|
||||
let id = TrashId {
|
||||
let id = TrashIdPB {
|
||||
id: view_id.to_owned(),
|
||||
ty: TrashType::TrashView,
|
||||
};
|
||||
|
@ -3,7 +3,7 @@ use crate::{
|
||||
request::{HttpRequestBuilder, ResponseMiddleware},
|
||||
};
|
||||
use flowy_error::FlowyError;
|
||||
use flowy_sync::entities::text_block::{CreateTextBlockParams, ResetTextBlockParams, TextBlockIdPB, TextBlockInfoPB};
|
||||
use flowy_sync::entities::text_block::{CreateTextBlockParams, DocumentPB, ResetTextBlockParams, TextBlockIdPB};
|
||||
use flowy_text_block::BlockCloudService;
|
||||
use http_flowy::response::FlowyResponse;
|
||||
use lazy_static::lazy_static;
|
||||
@ -27,7 +27,7 @@ impl BlockCloudService for BlockHttpCloudService {
|
||||
FutureResult::new(async move { create_document_request(&token, params, &url).await })
|
||||
}
|
||||
|
||||
fn read_block(&self, token: &str, params: TextBlockIdPB) -> FutureResult<Option<TextBlockInfoPB>, FlowyError> {
|
||||
fn read_block(&self, token: &str, params: TextBlockIdPB) -> FutureResult<Option<DocumentPB>, FlowyError> {
|
||||
let token = token.to_owned();
|
||||
let url = self.config.doc_url();
|
||||
FutureResult::new(async move { read_document_request(&token, params, &url).await })
|
||||
@ -54,7 +54,7 @@ pub async fn read_document_request(
|
||||
token: &str,
|
||||
params: TextBlockIdPB,
|
||||
url: &str,
|
||||
) -> Result<Option<TextBlockInfoPB>, FlowyError> {
|
||||
) -> Result<Option<DocumentPB>, FlowyError> {
|
||||
let doc = request_builder()
|
||||
.get(&url.to_owned())
|
||||
.header(HEADER_TOKEN, token)
|
||||
|
@ -1,15 +1,14 @@
|
||||
use crate::{
|
||||
configuration::{ClientServerConfiguration, HEADER_TOKEN},
|
||||
configuration::ClientServerConfiguration,
|
||||
request::{HttpRequestBuilder, ResponseMiddleware},
|
||||
};
|
||||
use flowy_error::FlowyError;
|
||||
use flowy_folder::entities::{
|
||||
trash::RepeatedTrashId,
|
||||
view::{CreateViewParams, RepeatedViewId, UpdateViewParams, ViewId},
|
||||
workspace::{CreateWorkspaceParams, UpdateWorkspaceParams, WorkspaceId},
|
||||
{AppId, CreateAppParams, UpdateAppParams},
|
||||
trash::RepeatedTrashIdPB,
|
||||
view::{CreateViewParams, RepeatedViewIdPB, UpdateViewParams, ViewIdPB},
|
||||
workspace::{CreateWorkspaceParams, UpdateWorkspaceParams, WorkspaceIdPB},
|
||||
{AppIdPB, CreateAppParams, UpdateAppParams},
|
||||
};
|
||||
|
||||
use flowy_folder::event_map::FolderCouldServiceV1;
|
||||
use flowy_folder_data_model::revision::{AppRevision, TrashRevision, ViewRevision, WorkspaceRevision};
|
||||
use http_flowy::errors::ServerError;
|
||||
@ -45,7 +44,7 @@ impl FolderCouldServiceV1 for FolderHttpCloudService {
|
||||
})
|
||||
}
|
||||
|
||||
fn read_workspace(&self, token: &str, params: WorkspaceId) -> FutureResult<Vec<WorkspaceRevision>, FlowyError> {
|
||||
fn read_workspace(&self, token: &str, params: WorkspaceIdPB) -> FutureResult<Vec<WorkspaceRevision>, FlowyError> {
|
||||
let token = token.to_owned();
|
||||
let url = self.config.workspace_url();
|
||||
FutureResult::new(async move {
|
||||
@ -63,7 +62,7 @@ impl FolderCouldServiceV1 for FolderHttpCloudService {
|
||||
})
|
||||
}
|
||||
|
||||
fn delete_workspace(&self, token: &str, params: WorkspaceId) -> FutureResult<(), FlowyError> {
|
||||
fn delete_workspace(&self, token: &str, params: WorkspaceIdPB) -> FutureResult<(), FlowyError> {
|
||||
let token = token.to_owned();
|
||||
let url = self.config.workspace_url();
|
||||
FutureResult::new(async move {
|
||||
@ -81,7 +80,7 @@ impl FolderCouldServiceV1 for FolderHttpCloudService {
|
||||
})
|
||||
}
|
||||
|
||||
fn read_view(&self, token: &str, params: ViewId) -> FutureResult<Option<ViewRevision>, FlowyError> {
|
||||
fn read_view(&self, token: &str, params: ViewIdPB) -> FutureResult<Option<ViewRevision>, FlowyError> {
|
||||
let token = token.to_owned();
|
||||
let url = self.config.view_url();
|
||||
FutureResult::new(async move {
|
||||
@ -90,7 +89,7 @@ impl FolderCouldServiceV1 for FolderHttpCloudService {
|
||||
})
|
||||
}
|
||||
|
||||
fn delete_view(&self, token: &str, params: RepeatedViewId) -> FutureResult<(), FlowyError> {
|
||||
fn delete_view(&self, token: &str, params: RepeatedViewIdPB) -> FutureResult<(), FlowyError> {
|
||||
let token = token.to_owned();
|
||||
let url = self.config.view_url();
|
||||
FutureResult::new(async move {
|
||||
@ -117,7 +116,7 @@ impl FolderCouldServiceV1 for FolderHttpCloudService {
|
||||
})
|
||||
}
|
||||
|
||||
fn read_app(&self, token: &str, params: AppId) -> FutureResult<Option<AppRevision>, FlowyError> {
|
||||
fn read_app(&self, token: &str, params: AppIdPB) -> FutureResult<Option<AppRevision>, FlowyError> {
|
||||
let token = token.to_owned();
|
||||
let url = self.config.app_url();
|
||||
FutureResult::new(async move {
|
||||
@ -135,7 +134,7 @@ impl FolderCouldServiceV1 for FolderHttpCloudService {
|
||||
})
|
||||
}
|
||||
|
||||
fn delete_app(&self, token: &str, params: AppId) -> FutureResult<(), FlowyError> {
|
||||
fn delete_app(&self, token: &str, params: AppIdPB) -> FutureResult<(), FlowyError> {
|
||||
let token = token.to_owned();
|
||||
let url = self.config.app_url();
|
||||
FutureResult::new(async move {
|
||||
@ -144,7 +143,7 @@ impl FolderCouldServiceV1 for FolderHttpCloudService {
|
||||
})
|
||||
}
|
||||
|
||||
fn create_trash(&self, token: &str, params: RepeatedTrashId) -> FutureResult<(), FlowyError> {
|
||||
fn create_trash(&self, token: &str, params: RepeatedTrashIdPB) -> FutureResult<(), FlowyError> {
|
||||
let token = token.to_owned();
|
||||
let url = self.config.trash_url();
|
||||
FutureResult::new(async move {
|
||||
@ -153,7 +152,7 @@ impl FolderCouldServiceV1 for FolderHttpCloudService {
|
||||
})
|
||||
}
|
||||
|
||||
fn delete_trash(&self, token: &str, params: RepeatedTrashId) -> FutureResult<(), FlowyError> {
|
||||
fn delete_trash(&self, token: &str, params: RepeatedTrashIdPB) -> FutureResult<(), FlowyError> {
|
||||
let token = token.to_owned();
|
||||
let url = self.config.trash_url();
|
||||
FutureResult::new(async move {
|
||||
@ -172,6 +171,7 @@ impl FolderCouldServiceV1 for FolderHttpCloudService {
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
fn request_builder() -> HttpRequestBuilder {
|
||||
HttpRequestBuilder::new().middleware(MIDDLEWARE.clone())
|
||||
}
|
||||
@ -193,7 +193,7 @@ pub async fn create_workspace_request(
|
||||
|
||||
pub async fn read_workspaces_request(
|
||||
_token: &str,
|
||||
_params: WorkspaceId,
|
||||
_params: WorkspaceIdPB,
|
||||
_url: &str,
|
||||
) -> Result<Vec<WorkspaceRevision>, ServerError> {
|
||||
// let repeated_workspace = request_builder()
|
||||
@ -208,26 +208,26 @@ pub async fn read_workspaces_request(
|
||||
}
|
||||
|
||||
pub async fn update_workspace_request(
|
||||
token: &str,
|
||||
params: UpdateWorkspaceParams,
|
||||
url: &str,
|
||||
_token: &str,
|
||||
_params: UpdateWorkspaceParams,
|
||||
_url: &str,
|
||||
) -> Result<(), ServerError> {
|
||||
let _ = request_builder()
|
||||
.patch(&url.to_owned())
|
||||
.header(HEADER_TOKEN, token)
|
||||
.protobuf(params)?
|
||||
.send()
|
||||
.await?;
|
||||
// let _ = request_builder()
|
||||
// .patch(&url.to_owned())
|
||||
// .header(HEADER_TOKEN, token)
|
||||
// .protobuf(params)?
|
||||
// .send()
|
||||
// .await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn delete_workspace_request(token: &str, params: WorkspaceId, url: &str) -> Result<(), ServerError> {
|
||||
let _ = request_builder()
|
||||
.delete(url)
|
||||
.header(HEADER_TOKEN, token)
|
||||
.protobuf(params)?
|
||||
.send()
|
||||
.await?;
|
||||
pub async fn delete_workspace_request(_token: &str, _params: WorkspaceIdPB, _url: &str) -> Result<(), ServerError> {
|
||||
// let _ = request_builder()
|
||||
// .delete(url)
|
||||
// .header(HEADER_TOKEN, token)
|
||||
// .protobuf(params)?
|
||||
// .send()
|
||||
// .await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -247,7 +247,7 @@ pub async fn create_app_request(
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub async fn read_app_request(_token: &str, _params: AppId, _url: &str) -> Result<Option<AppRevision>, ServerError> {
|
||||
pub async fn read_app_request(_token: &str, _params: AppIdPB, _url: &str) -> Result<Option<AppRevision>, ServerError> {
|
||||
// let app = request_builder()
|
||||
// .get(&url.to_owned())
|
||||
// .header(HEADER_TOKEN, token)
|
||||
@ -259,23 +259,23 @@ pub async fn read_app_request(_token: &str, _params: AppId, _url: &str) -> Resul
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub async fn update_app_request(token: &str, params: UpdateAppParams, url: &str) -> Result<(), ServerError> {
|
||||
let _ = request_builder()
|
||||
.patch(&url.to_owned())
|
||||
.header(HEADER_TOKEN, token)
|
||||
.protobuf(params)?
|
||||
.send()
|
||||
.await?;
|
||||
pub async fn update_app_request(_token: &str, _params: UpdateAppParams, _url: &str) -> Result<(), ServerError> {
|
||||
// let _ = request_builder()
|
||||
// .patch(&url.to_owned())
|
||||
// .header(HEADER_TOKEN, token)
|
||||
// .protobuf(params)?
|
||||
// .send()
|
||||
// .await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn delete_app_request(token: &str, params: AppId, url: &str) -> Result<(), ServerError> {
|
||||
let _ = request_builder()
|
||||
.delete(&url.to_owned())
|
||||
.header(HEADER_TOKEN, token)
|
||||
.protobuf(params)?
|
||||
.send()
|
||||
.await?;
|
||||
pub async fn delete_app_request(_token: &str, _params: AppIdPB, _url: &str) -> Result<(), ServerError> {
|
||||
// let _ = request_builder()
|
||||
// .delete(&url.to_owned())
|
||||
// .header(HEADER_TOKEN, token)
|
||||
// .protobuf(params)?
|
||||
// .send()
|
||||
// .await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -295,7 +295,11 @@ pub async fn create_view_request(
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub async fn read_view_request(_token: &str, _params: ViewId, _url: &str) -> Result<Option<ViewRevision>, ServerError> {
|
||||
pub async fn read_view_request(
|
||||
_token: &str,
|
||||
_params: ViewIdPB,
|
||||
_url: &str,
|
||||
) -> Result<Option<ViewRevision>, ServerError> {
|
||||
// let view = request_builder()
|
||||
// .get(&url.to_owned())
|
||||
// .header(HEADER_TOKEN, token)
|
||||
@ -307,43 +311,43 @@ pub async fn read_view_request(_token: &str, _params: ViewId, _url: &str) -> Res
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub async fn update_view_request(token: &str, params: UpdateViewParams, url: &str) -> Result<(), ServerError> {
|
||||
let _ = request_builder()
|
||||
.patch(&url.to_owned())
|
||||
.header(HEADER_TOKEN, token)
|
||||
.protobuf(params)?
|
||||
.send()
|
||||
.await?;
|
||||
pub async fn update_view_request(_token: &str, _params: UpdateViewParams, _url: &str) -> Result<(), ServerError> {
|
||||
// let _ = request_builder()
|
||||
// .patch(&url.to_owned())
|
||||
// .header(HEADER_TOKEN, token)
|
||||
// .protobuf(params)?
|
||||
// .send()
|
||||
// .await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn delete_view_request(token: &str, params: RepeatedViewId, url: &str) -> Result<(), ServerError> {
|
||||
let _ = request_builder()
|
||||
.delete(&url.to_owned())
|
||||
.header(HEADER_TOKEN, token)
|
||||
.protobuf(params)?
|
||||
.send()
|
||||
.await?;
|
||||
pub async fn delete_view_request(_token: &str, _params: RepeatedViewIdPB, _url: &str) -> Result<(), ServerError> {
|
||||
// let _ = request_builder()
|
||||
// .delete(&url.to_owned())
|
||||
// .header(HEADER_TOKEN, token)
|
||||
// .protobuf(params)?
|
||||
// .send()
|
||||
// .await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn create_trash_request(token: &str, params: RepeatedTrashId, url: &str) -> Result<(), ServerError> {
|
||||
let _ = request_builder()
|
||||
.post(&url.to_owned())
|
||||
.header(HEADER_TOKEN, token)
|
||||
.protobuf(params)?
|
||||
.send()
|
||||
.await?;
|
||||
pub async fn create_trash_request(_token: &str, _params: RepeatedTrashIdPB, _url: &str) -> Result<(), ServerError> {
|
||||
// let _ = request_builder()
|
||||
// .post(&url.to_owned())
|
||||
// .header(HEADER_TOKEN, token)
|
||||
// .protobuf(params)?
|
||||
// .send()
|
||||
// .await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn delete_trash_request(token: &str, params: RepeatedTrashId, url: &str) -> Result<(), ServerError> {
|
||||
let _ = request_builder()
|
||||
.delete(&url.to_owned())
|
||||
.header(HEADER_TOKEN, token)
|
||||
.protobuf(params)?
|
||||
.send()
|
||||
.await?;
|
||||
pub async fn delete_trash_request(_token: &str, _params: RepeatedTrashIdPB, _url: &str) -> Result<(), ServerError> {
|
||||
// let _ = request_builder()
|
||||
// .delete(&url.to_owned())
|
||||
// .header(HEADER_TOKEN, token)
|
||||
// .protobuf(params)?
|
||||
// .send()
|
||||
// .await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
use crate::{configuration::*, request::HttpRequestBuilder};
|
||||
use flowy_error::FlowyError;
|
||||
use flowy_user::entities::{
|
||||
SignInParams, SignInResponse, SignUpParams, SignUpResponse, UpdateUserProfileParams, UserProfile,
|
||||
SignInParams, SignInResponse, SignUpParams, SignUpResponse, UpdateUserProfileParams, UserProfilePB,
|
||||
};
|
||||
use flowy_user::event_map::UserCloudService;
|
||||
use http_flowy::errors::ServerError;
|
||||
@ -51,7 +51,7 @@ impl UserCloudService for UserHttpCloudService {
|
||||
})
|
||||
}
|
||||
|
||||
fn get_user(&self, token: &str) -> FutureResult<UserProfile, FlowyError> {
|
||||
fn get_user(&self, token: &str) -> FutureResult<UserProfilePB, FlowyError> {
|
||||
let token = token.to_owned();
|
||||
let url = self.config.user_profile_url();
|
||||
FutureResult::new(async move {
|
||||
@ -92,7 +92,7 @@ pub async fn user_sign_out_request(token: &str, url: &str) -> Result<(), ServerE
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn get_user_profile_request(token: &str, url: &str) -> Result<UserProfile, ServerError> {
|
||||
pub async fn get_user_profile_request(token: &str, url: &str) -> Result<UserProfilePB, ServerError> {
|
||||
let user_profile = request_builder()
|
||||
.get(&url.to_owned())
|
||||
.header(HEADER_TOKEN, token)
|
||||
|
@ -1,10 +1,10 @@
|
||||
use flowy_sync::entities::revision::{RepeatedRevision, Revision};
|
||||
use flowy_sync::{
|
||||
entities::{folder::FolderInfo, text_block::TextBlockInfoPB},
|
||||
entities::{folder::FolderInfo, text_block::DocumentPB},
|
||||
errors::CollaborateError,
|
||||
protobuf::{RepeatedRevision as RepeatedRevisionPB, Revision as RevisionPB},
|
||||
server_document::*,
|
||||
server_folder::FolderCloudPersistence,
|
||||
util::{make_document_info_from_revisions_pb, make_folder_from_revisions_pb},
|
||||
util::{make_document_from_revision_pbs, make_folder_from_revisions_pb},
|
||||
};
|
||||
use lib_infra::future::BoxResultFuture;
|
||||
use std::{
|
||||
@ -15,17 +15,17 @@ use std::{
|
||||
// For the moment, we use memory to cache the data, it will be implemented with
|
||||
// other storage. Like the Firestore,Dropbox.etc.
|
||||
pub trait RevisionCloudStorage: Send + Sync {
|
||||
fn set_revisions(&self, repeated_revision: RepeatedRevisionPB) -> BoxResultFuture<(), CollaborateError>;
|
||||
fn set_revisions(&self, repeated_revision: RepeatedRevision) -> BoxResultFuture<(), CollaborateError>;
|
||||
fn get_revisions(
|
||||
&self,
|
||||
object_id: &str,
|
||||
rev_ids: Option<Vec<i64>>,
|
||||
) -> BoxResultFuture<RepeatedRevisionPB, CollaborateError>;
|
||||
) -> BoxResultFuture<RepeatedRevision, CollaborateError>;
|
||||
|
||||
fn reset_object(
|
||||
&self,
|
||||
object_id: &str,
|
||||
repeated_revision: RepeatedRevisionPB,
|
||||
repeated_revision: RepeatedRevision,
|
||||
) -> BoxResultFuture<(), CollaborateError>;
|
||||
}
|
||||
|
||||
@ -64,7 +64,7 @@ impl FolderCloudPersistence for LocalTextBlockCloudPersistence {
|
||||
&self,
|
||||
_user_id: &str,
|
||||
folder_id: &str,
|
||||
repeated_revision: RepeatedRevisionPB,
|
||||
repeated_revision: RepeatedRevision,
|
||||
) -> BoxResultFuture<Option<FolderInfo>, CollaborateError> {
|
||||
let folder_id = folder_id.to_owned();
|
||||
let storage = self.storage.clone();
|
||||
@ -74,7 +74,7 @@ impl FolderCloudPersistence for LocalTextBlockCloudPersistence {
|
||||
})
|
||||
}
|
||||
|
||||
fn save_folder_revisions(&self, repeated_revision: RepeatedRevisionPB) -> BoxResultFuture<(), CollaborateError> {
|
||||
fn save_folder_revisions(&self, repeated_revision: RepeatedRevision) -> BoxResultFuture<(), CollaborateError> {
|
||||
let storage = self.storage.clone();
|
||||
Box::pin(async move {
|
||||
let _ = storage.set_revisions(repeated_revision).await?;
|
||||
@ -86,20 +86,19 @@ impl FolderCloudPersistence for LocalTextBlockCloudPersistence {
|
||||
&self,
|
||||
folder_id: &str,
|
||||
rev_ids: Option<Vec<i64>>,
|
||||
) -> BoxResultFuture<Vec<RevisionPB>, CollaborateError> {
|
||||
) -> BoxResultFuture<Vec<Revision>, CollaborateError> {
|
||||
let folder_id = folder_id.to_owned();
|
||||
let storage = self.storage.clone();
|
||||
Box::pin(async move {
|
||||
let mut repeated_revision = storage.get_revisions(&folder_id, rev_ids).await?;
|
||||
let revisions: Vec<RevisionPB> = repeated_revision.take_items().into();
|
||||
Ok(revisions)
|
||||
let repeated_revision = storage.get_revisions(&folder_id, rev_ids).await?;
|
||||
Ok(repeated_revision.into_inner())
|
||||
})
|
||||
}
|
||||
|
||||
fn reset_folder(
|
||||
&self,
|
||||
folder_id: &str,
|
||||
repeated_revision: RepeatedRevisionPB,
|
||||
repeated_revision: RepeatedRevision,
|
||||
) -> BoxResultFuture<(), CollaborateError> {
|
||||
let storage = self.storage.clone();
|
||||
let folder_id = folder_id.to_owned();
|
||||
@ -111,12 +110,12 @@ impl FolderCloudPersistence for LocalTextBlockCloudPersistence {
|
||||
}
|
||||
|
||||
impl TextBlockCloudPersistence for LocalTextBlockCloudPersistence {
|
||||
fn read_text_block(&self, doc_id: &str) -> BoxResultFuture<TextBlockInfoPB, CollaborateError> {
|
||||
fn read_text_block(&self, doc_id: &str) -> BoxResultFuture<DocumentPB, CollaborateError> {
|
||||
let storage = self.storage.clone();
|
||||
let doc_id = doc_id.to_owned();
|
||||
Box::pin(async move {
|
||||
let repeated_revision = storage.get_revisions(&doc_id, None).await?;
|
||||
match make_document_info_from_revisions_pb(&doc_id, repeated_revision)? {
|
||||
match make_document_from_revision_pbs(&doc_id, repeated_revision)? {
|
||||
Some(document_info) => Ok(document_info),
|
||||
None => Err(CollaborateError::record_not_found()),
|
||||
}
|
||||
@ -126,13 +125,13 @@ impl TextBlockCloudPersistence for LocalTextBlockCloudPersistence {
|
||||
fn create_text_block(
|
||||
&self,
|
||||
doc_id: &str,
|
||||
repeated_revision: RepeatedRevisionPB,
|
||||
) -> BoxResultFuture<Option<TextBlockInfoPB>, CollaborateError> {
|
||||
repeated_revision: RepeatedRevision,
|
||||
) -> BoxResultFuture<Option<DocumentPB>, CollaborateError> {
|
||||
let doc_id = doc_id.to_owned();
|
||||
let storage = self.storage.clone();
|
||||
Box::pin(async move {
|
||||
let _ = storage.set_revisions(repeated_revision.clone()).await?;
|
||||
make_document_info_from_revisions_pb(&doc_id, repeated_revision)
|
||||
make_document_from_revision_pbs(&doc_id, repeated_revision)
|
||||
})
|
||||
}
|
||||
|
||||
@ -140,20 +139,16 @@ impl TextBlockCloudPersistence for LocalTextBlockCloudPersistence {
|
||||
&self,
|
||||
doc_id: &str,
|
||||
rev_ids: Option<Vec<i64>>,
|
||||
) -> BoxResultFuture<Vec<RevisionPB>, CollaborateError> {
|
||||
) -> BoxResultFuture<Vec<Revision>, CollaborateError> {
|
||||
let doc_id = doc_id.to_owned();
|
||||
let storage = self.storage.clone();
|
||||
Box::pin(async move {
|
||||
let mut repeated_revision = storage.get_revisions(&doc_id, rev_ids).await?;
|
||||
let revisions: Vec<RevisionPB> = repeated_revision.take_items().into();
|
||||
Ok(revisions)
|
||||
let repeated_revision = storage.get_revisions(&doc_id, rev_ids).await?;
|
||||
Ok(repeated_revision.into_inner())
|
||||
})
|
||||
}
|
||||
|
||||
fn save_text_block_revisions(
|
||||
&self,
|
||||
repeated_revision: RepeatedRevisionPB,
|
||||
) -> BoxResultFuture<(), CollaborateError> {
|
||||
fn save_text_block_revisions(&self, repeated_revision: RepeatedRevision) -> BoxResultFuture<(), CollaborateError> {
|
||||
let storage = self.storage.clone();
|
||||
Box::pin(async move {
|
||||
let _ = storage.set_revisions(repeated_revision).await?;
|
||||
@ -161,7 +156,7 @@ impl TextBlockCloudPersistence for LocalTextBlockCloudPersistence {
|
||||
})
|
||||
}
|
||||
|
||||
fn reset_text_block(&self, doc_id: &str, revisions: RepeatedRevisionPB) -> BoxResultFuture<(), CollaborateError> {
|
||||
fn reset_text_block(&self, doc_id: &str, revisions: RepeatedRevision) -> BoxResultFuture<(), CollaborateError> {
|
||||
let storage = self.storage.clone();
|
||||
let doc_id = doc_id.to_owned();
|
||||
Box::pin(async move {
|
||||
@ -174,7 +169,7 @@ impl TextBlockCloudPersistence for LocalTextBlockCloudPersistence {
|
||||
#[derive(Default)]
|
||||
struct MemoryDocumentCloudStorage {}
|
||||
impl RevisionCloudStorage for MemoryDocumentCloudStorage {
|
||||
fn set_revisions(&self, _repeated_revision: RepeatedRevisionPB) -> BoxResultFuture<(), CollaborateError> {
|
||||
fn set_revisions(&self, _repeated_revision: RepeatedRevision) -> BoxResultFuture<(), CollaborateError> {
|
||||
Box::pin(async move { Ok(()) })
|
||||
}
|
||||
|
||||
@ -182,9 +177,9 @@ impl RevisionCloudStorage for MemoryDocumentCloudStorage {
|
||||
&self,
|
||||
_doc_id: &str,
|
||||
_rev_ids: Option<Vec<i64>>,
|
||||
) -> BoxResultFuture<RepeatedRevisionPB, CollaborateError> {
|
||||
) -> BoxResultFuture<RepeatedRevision, CollaborateError> {
|
||||
Box::pin(async move {
|
||||
let repeated_revisions = RepeatedRevisionPB::new();
|
||||
let repeated_revisions = RepeatedRevision::default();
|
||||
Ok(repeated_revisions)
|
||||
})
|
||||
}
|
||||
@ -192,7 +187,7 @@ impl RevisionCloudStorage for MemoryDocumentCloudStorage {
|
||||
fn reset_object(
|
||||
&self,
|
||||
_doc_id: &str,
|
||||
_repeated_revision: RepeatedRevisionPB,
|
||||
_repeated_revision: RepeatedRevision,
|
||||
) -> BoxResultFuture<(), CollaborateError> {
|
||||
Box::pin(async move { Ok(()) })
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ use flowy_folder::event_map::FolderCouldServiceV1;
|
||||
use flowy_sync::{
|
||||
client_document::default::initial_quill_delta_string,
|
||||
entities::{
|
||||
text_block::{CreateTextBlockParams, ResetTextBlockParams, TextBlockIdPB, TextBlockInfoPB},
|
||||
text_block::{CreateTextBlockParams, DocumentPB, ResetTextBlockParams, TextBlockIdPB},
|
||||
ws_data::{ClientRevisionWSData, ClientRevisionWSDataType},
|
||||
},
|
||||
errors::CollaborateError,
|
||||
@ -253,17 +253,17 @@ impl RevisionUser for LocalRevisionUser {
|
||||
}
|
||||
|
||||
use flowy_folder::entities::{
|
||||
app::{AppId, CreateAppParams, UpdateAppParams},
|
||||
trash::RepeatedTrashId,
|
||||
view::{CreateViewParams, RepeatedViewId, UpdateViewParams, ViewId},
|
||||
workspace::{CreateWorkspaceParams, UpdateWorkspaceParams, WorkspaceId},
|
||||
app::{AppIdPB, CreateAppParams, UpdateAppParams},
|
||||
trash::RepeatedTrashIdPB,
|
||||
view::{CreateViewParams, RepeatedViewIdPB, UpdateViewParams, ViewIdPB},
|
||||
workspace::{CreateWorkspaceParams, UpdateWorkspaceParams, WorkspaceIdPB},
|
||||
};
|
||||
use flowy_folder_data_model::revision::{
|
||||
gen_app_id, gen_workspace_id, AppRevision, TrashRevision, ViewRevision, WorkspaceRevision,
|
||||
};
|
||||
use flowy_text_block::BlockCloudService;
|
||||
use flowy_user::entities::{
|
||||
SignInParams, SignInResponse, SignUpParams, SignUpResponse, UpdateUserProfileParams, UserProfile,
|
||||
SignInParams, SignInResponse, SignUpParams, SignUpResponse, UpdateUserProfileParams, UserProfilePB,
|
||||
};
|
||||
use flowy_user::event_map::UserCloudService;
|
||||
use lib_infra::{future::FutureResult, util::timestamp};
|
||||
@ -289,7 +289,7 @@ impl FolderCouldServiceV1 for LocalServer {
|
||||
FutureResult::new(async { Ok(workspace) })
|
||||
}
|
||||
|
||||
fn read_workspace(&self, _token: &str, _params: WorkspaceId) -> FutureResult<Vec<WorkspaceRevision>, FlowyError> {
|
||||
fn read_workspace(&self, _token: &str, _params: WorkspaceIdPB) -> FutureResult<Vec<WorkspaceRevision>, FlowyError> {
|
||||
FutureResult::new(async { Ok(vec![]) })
|
||||
}
|
||||
|
||||
@ -297,7 +297,7 @@ impl FolderCouldServiceV1 for LocalServer {
|
||||
FutureResult::new(async { Ok(()) })
|
||||
}
|
||||
|
||||
fn delete_workspace(&self, _token: &str, _params: WorkspaceId) -> FutureResult<(), FlowyError> {
|
||||
fn delete_workspace(&self, _token: &str, _params: WorkspaceIdPB) -> FutureResult<(), FlowyError> {
|
||||
FutureResult::new(async { Ok(()) })
|
||||
}
|
||||
|
||||
@ -320,11 +320,11 @@ impl FolderCouldServiceV1 for LocalServer {
|
||||
FutureResult::new(async { Ok(view) })
|
||||
}
|
||||
|
||||
fn read_view(&self, _token: &str, _params: ViewId) -> FutureResult<Option<ViewRevision>, FlowyError> {
|
||||
fn read_view(&self, _token: &str, _params: ViewIdPB) -> FutureResult<Option<ViewRevision>, FlowyError> {
|
||||
FutureResult::new(async { Ok(None) })
|
||||
}
|
||||
|
||||
fn delete_view(&self, _token: &str, _params: RepeatedViewId) -> FutureResult<(), FlowyError> {
|
||||
fn delete_view(&self, _token: &str, _params: RepeatedViewIdPB) -> FutureResult<(), FlowyError> {
|
||||
FutureResult::new(async { Ok(()) })
|
||||
}
|
||||
|
||||
@ -347,7 +347,7 @@ impl FolderCouldServiceV1 for LocalServer {
|
||||
FutureResult::new(async { Ok(app) })
|
||||
}
|
||||
|
||||
fn read_app(&self, _token: &str, _params: AppId) -> FutureResult<Option<AppRevision>, FlowyError> {
|
||||
fn read_app(&self, _token: &str, _params: AppIdPB) -> FutureResult<Option<AppRevision>, FlowyError> {
|
||||
FutureResult::new(async { Ok(None) })
|
||||
}
|
||||
|
||||
@ -355,15 +355,15 @@ impl FolderCouldServiceV1 for LocalServer {
|
||||
FutureResult::new(async { Ok(()) })
|
||||
}
|
||||
|
||||
fn delete_app(&self, _token: &str, _params: AppId) -> FutureResult<(), FlowyError> {
|
||||
fn delete_app(&self, _token: &str, _params: AppIdPB) -> FutureResult<(), FlowyError> {
|
||||
FutureResult::new(async { Ok(()) })
|
||||
}
|
||||
|
||||
fn create_trash(&self, _token: &str, _params: RepeatedTrashId) -> FutureResult<(), FlowyError> {
|
||||
fn create_trash(&self, _token: &str, _params: RepeatedTrashIdPB) -> FutureResult<(), FlowyError> {
|
||||
FutureResult::new(async { Ok(()) })
|
||||
}
|
||||
|
||||
fn delete_trash(&self, _token: &str, _params: RepeatedTrashId) -> FutureResult<(), FlowyError> {
|
||||
fn delete_trash(&self, _token: &str, _params: RepeatedTrashIdPB) -> FutureResult<(), FlowyError> {
|
||||
FutureResult::new(async { Ok(()) })
|
||||
}
|
||||
|
||||
@ -405,8 +405,8 @@ impl UserCloudService for LocalServer {
|
||||
FutureResult::new(async { Ok(()) })
|
||||
}
|
||||
|
||||
fn get_user(&self, _token: &str) -> FutureResult<UserProfile, FlowyError> {
|
||||
FutureResult::new(async { Ok(UserProfile::default()) })
|
||||
fn get_user(&self, _token: &str) -> FutureResult<UserProfilePB, FlowyError> {
|
||||
FutureResult::new(async { Ok(UserProfilePB::default()) })
|
||||
}
|
||||
|
||||
fn ws_addr(&self) -> String {
|
||||
@ -419,8 +419,8 @@ impl BlockCloudService for LocalServer {
|
||||
FutureResult::new(async { Ok(()) })
|
||||
}
|
||||
|
||||
fn read_block(&self, _token: &str, params: TextBlockIdPB) -> FutureResult<Option<TextBlockInfoPB>, FlowyError> {
|
||||
let doc = TextBlockInfoPB {
|
||||
fn read_block(&self, _token: &str, params: TextBlockIdPB) -> FutureResult<Option<DocumentPB>, FlowyError> {
|
||||
let doc = DocumentPB {
|
||||
block_id: params.value,
|
||||
text: initial_quill_delta_string(),
|
||||
rev_id: 0,
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::FlowySDKTest;
|
||||
use flowy_user::{entities::UserProfile, errors::FlowyError};
|
||||
use flowy_user::{entities::UserProfilePB, errors::FlowyError};
|
||||
use lib_dispatch::prelude::{EventDispatcher, EventResponse, FromBytes, ModuleRequest, StatusCode, ToBytes, *};
|
||||
use std::{
|
||||
convert::TryFrom,
|
||||
@ -14,7 +14,7 @@ impl FolderEventBuilder {
|
||||
pub fn new(sdk: FlowySDKTest) -> Self {
|
||||
EventBuilder::test(TestContext::new(sdk))
|
||||
}
|
||||
pub fn user_profile(&self) -> &Option<UserProfile> {
|
||||
pub fn user_profile(&self) -> &Option<UserProfilePB> {
|
||||
&self.user_profile
|
||||
}
|
||||
}
|
||||
@ -24,7 +24,7 @@ pub type UserModuleEventBuilder = FolderEventBuilder;
|
||||
#[derive(Clone)]
|
||||
pub struct EventBuilder<E> {
|
||||
context: TestContext,
|
||||
user_profile: Option<UserProfile>,
|
||||
user_profile: Option<UserProfilePB>,
|
||||
err_phantom: PhantomData<E>,
|
||||
}
|
||||
|
||||
|
@ -1,15 +1,15 @@
|
||||
use crate::prelude::*;
|
||||
use flowy_folder::entities::WorkspaceId;
|
||||
use flowy_folder::entities::WorkspaceIdPB;
|
||||
use flowy_folder::{
|
||||
entities::{
|
||||
app::*,
|
||||
view::*,
|
||||
workspace::{CreateWorkspacePayload, Workspace},
|
||||
workspace::{CreateWorkspacePayloadPB, WorkspacePB},
|
||||
},
|
||||
event_map::FolderEvent::{CreateWorkspace, OpenWorkspace, *},
|
||||
};
|
||||
use flowy_user::{
|
||||
entities::{SignInPayload, SignUpPayload, UserProfile},
|
||||
entities::{SignInPayloadPB, SignUpPayloadPB, UserProfilePB},
|
||||
errors::FlowyError,
|
||||
event_map::UserEvent::{InitUser, SignIn, SignOut, SignUp},
|
||||
};
|
||||
@ -18,9 +18,9 @@ use std::{fs, path::PathBuf, sync::Arc};
|
||||
|
||||
pub struct ViewTest {
|
||||
pub sdk: FlowySDKTest,
|
||||
pub workspace: Workspace,
|
||||
pub app: App,
|
||||
pub view: View,
|
||||
pub workspace: WorkspacePB,
|
||||
pub app: AppPB,
|
||||
pub view: ViewPB,
|
||||
}
|
||||
|
||||
impl ViewTest {
|
||||
@ -47,8 +47,8 @@ impl ViewTest {
|
||||
}
|
||||
}
|
||||
|
||||
async fn create_workspace(sdk: &FlowySDKTest, name: &str, desc: &str) -> Workspace {
|
||||
let request = CreateWorkspacePayload {
|
||||
async fn create_workspace(sdk: &FlowySDKTest, name: &str, desc: &str) -> WorkspacePB {
|
||||
let request = CreateWorkspacePayloadPB {
|
||||
name: name.to_owned(),
|
||||
desc: desc.to_owned(),
|
||||
};
|
||||
@ -58,12 +58,12 @@ async fn create_workspace(sdk: &FlowySDKTest, name: &str, desc: &str) -> Workspa
|
||||
.payload(request)
|
||||
.async_send()
|
||||
.await
|
||||
.parse::<Workspace>();
|
||||
.parse::<WorkspacePB>();
|
||||
workspace
|
||||
}
|
||||
|
||||
async fn open_workspace(sdk: &FlowySDKTest, workspace_id: &str) {
|
||||
let payload = WorkspaceId {
|
||||
let payload = WorkspaceIdPB {
|
||||
value: Some(workspace_id.to_owned()),
|
||||
};
|
||||
let _ = FolderEventBuilder::new(sdk.clone())
|
||||
@ -73,8 +73,8 @@ async fn open_workspace(sdk: &FlowySDKTest, workspace_id: &str) {
|
||||
.await;
|
||||
}
|
||||
|
||||
async fn create_app(sdk: &FlowySDKTest, name: &str, desc: &str, workspace_id: &str) -> App {
|
||||
let create_app_request = CreateAppPayload {
|
||||
async fn create_app(sdk: &FlowySDKTest, name: &str, desc: &str, workspace_id: &str) -> AppPB {
|
||||
let create_app_request = CreateAppPayloadPB {
|
||||
workspace_id: workspace_id.to_owned(),
|
||||
name: name.to_string(),
|
||||
desc: desc.to_string(),
|
||||
@ -86,12 +86,12 @@ async fn create_app(sdk: &FlowySDKTest, name: &str, desc: &str, workspace_id: &s
|
||||
.payload(create_app_request)
|
||||
.async_send()
|
||||
.await
|
||||
.parse::<App>();
|
||||
.parse::<AppPB>();
|
||||
app
|
||||
}
|
||||
|
||||
async fn create_view(sdk: &FlowySDKTest, app_id: &str, data_type: ViewDataType, data: Vec<u8>) -> View {
|
||||
let request = CreateViewPayload {
|
||||
async fn create_view(sdk: &FlowySDKTest, app_id: &str, data_type: ViewDataType, data: Vec<u8>) -> ViewPB {
|
||||
let request = CreateViewPayloadPB {
|
||||
belong_to_id: app_id.to_string(),
|
||||
name: "View A".to_string(),
|
||||
desc: "".to_string(),
|
||||
@ -106,7 +106,7 @@ async fn create_view(sdk: &FlowySDKTest, app_id: &str, data_type: ViewDataType,
|
||||
.payload(request)
|
||||
.async_send()
|
||||
.await
|
||||
.parse::<View>();
|
||||
.parse::<ViewPB>();
|
||||
view
|
||||
}
|
||||
|
||||
@ -138,13 +138,13 @@ pub fn login_password() -> String {
|
||||
}
|
||||
|
||||
pub struct SignUpContext {
|
||||
pub user_profile: UserProfile,
|
||||
pub user_profile: UserProfilePB,
|
||||
pub password: String,
|
||||
}
|
||||
|
||||
pub fn sign_up(dispatch: Arc<EventDispatcher>) -> SignUpContext {
|
||||
let password = login_password();
|
||||
let payload = SignUpPayload {
|
||||
let payload = SignUpPayloadPB {
|
||||
email: random_email(),
|
||||
name: "app flowy".to_string(),
|
||||
password: password.clone(),
|
||||
@ -154,7 +154,7 @@ pub fn sign_up(dispatch: Arc<EventDispatcher>) -> SignUpContext {
|
||||
|
||||
let request = ModuleRequest::new(SignUp).payload(payload);
|
||||
let user_profile = EventDispatcher::sync_send(dispatch, request)
|
||||
.parse::<UserProfile, FlowyError>()
|
||||
.parse::<UserProfilePB, FlowyError>()
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
|
||||
@ -164,7 +164,7 @@ pub fn sign_up(dispatch: Arc<EventDispatcher>) -> SignUpContext {
|
||||
pub async fn async_sign_up(dispatch: Arc<EventDispatcher>) -> SignUpContext {
|
||||
let password = login_password();
|
||||
let email = random_email();
|
||||
let payload = SignUpPayload {
|
||||
let payload = SignUpPayloadPB {
|
||||
email,
|
||||
name: "app flowy".to_string(),
|
||||
password: password.clone(),
|
||||
@ -175,7 +175,7 @@ pub async fn async_sign_up(dispatch: Arc<EventDispatcher>) -> SignUpContext {
|
||||
let request = ModuleRequest::new(SignUp).payload(payload);
|
||||
let user_profile = EventDispatcher::async_send(dispatch.clone(), request)
|
||||
.await
|
||||
.parse::<UserProfile, FlowyError>()
|
||||
.parse::<UserProfilePB, FlowyError>()
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
|
||||
@ -189,8 +189,8 @@ pub async fn init_user_setting(dispatch: Arc<EventDispatcher>) {
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
fn sign_in(dispatch: Arc<EventDispatcher>) -> UserProfile {
|
||||
let payload = SignInPayload {
|
||||
fn sign_in(dispatch: Arc<EventDispatcher>) -> UserProfilePB {
|
||||
let payload = SignInPayloadPB {
|
||||
email: login_email(),
|
||||
password: login_password(),
|
||||
name: "rust".to_owned(),
|
||||
@ -200,7 +200,7 @@ fn sign_in(dispatch: Arc<EventDispatcher>) -> UserProfile {
|
||||
|
||||
let request = ModuleRequest::new(SignIn).payload(payload);
|
||||
EventDispatcher::sync_send(dispatch, request)
|
||||
.parse::<UserProfile, FlowyError>()
|
||||
.parse::<UserProfilePB, FlowyError>()
|
||||
.unwrap()
|
||||
.unwrap()
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ pub mod helper;
|
||||
use crate::helper::*;
|
||||
use flowy_net::{get_client_server_configuration, ClientServerConfiguration};
|
||||
use flowy_sdk::{FlowySDK, FlowySDKConfig};
|
||||
use flowy_user::entities::UserProfile;
|
||||
use flowy_user::entities::UserProfilePB;
|
||||
use nanoid::nanoid;
|
||||
|
||||
pub mod prelude {
|
||||
@ -47,7 +47,7 @@ impl FlowySDKTest {
|
||||
context
|
||||
}
|
||||
|
||||
pub async fn init_user(&self) -> UserProfile {
|
||||
pub async fn init_user(&self) -> UserProfilePB {
|
||||
let context = async_sign_up(self.inner.dispatcher()).await;
|
||||
init_user_setting(self.inner.dispatcher()).await;
|
||||
context.user_profile
|
||||
|
@ -9,7 +9,7 @@ use flowy_error::{internal_error, FlowyResult};
|
||||
use flowy_revision::{RevisionCloudService, RevisionManager, RevisionObjectBuilder, RevisionWebSocket};
|
||||
use flowy_sync::entities::ws_data::ServerRevisionWSData;
|
||||
use flowy_sync::{
|
||||
entities::{revision::Revision, text_block::TextBlockInfoPB},
|
||||
entities::{revision::Revision, text_block::DocumentPB},
|
||||
errors::CollaborateResult,
|
||||
util::make_delta_from_revisions,
|
||||
};
|
||||
@ -229,14 +229,14 @@ impl TextBlockEditor {
|
||||
|
||||
struct TextBlockInfoBuilder();
|
||||
impl RevisionObjectBuilder for TextBlockInfoBuilder {
|
||||
type Output = TextBlockInfoPB;
|
||||
type Output = DocumentPB;
|
||||
|
||||
fn build_object(object_id: &str, revisions: Vec<Revision>) -> FlowyResult<Self::Output> {
|
||||
let (base_rev_id, rev_id) = revisions.last().unwrap().pair_rev_id();
|
||||
let mut delta = make_delta_from_revisions(revisions)?;
|
||||
correct_delta(&mut delta);
|
||||
|
||||
Result::<TextBlockInfoPB, FlowyError>::Ok(TextBlockInfoPB {
|
||||
Result::<DocumentPB, FlowyError>::Ok(DocumentPB {
|
||||
block_id: object_id.to_owned(),
|
||||
text: delta.to_delta_str(),
|
||||
rev_id,
|
||||
|
@ -15,13 +15,13 @@ pub mod errors {
|
||||
pub const TEXT_BLOCK_SYNC_INTERVAL_IN_MILLIS: u64 = 1000;
|
||||
|
||||
use crate::errors::FlowyError;
|
||||
use flowy_sync::entities::text_block::{CreateTextBlockParams, ResetTextBlockParams, TextBlockIdPB, TextBlockInfoPB};
|
||||
use flowy_sync::entities::text_block::{CreateTextBlockParams, DocumentPB, ResetTextBlockParams, TextBlockIdPB};
|
||||
use lib_infra::future::FutureResult;
|
||||
|
||||
pub trait BlockCloudService: Send + Sync {
|
||||
fn create_block(&self, token: &str, params: CreateTextBlockParams) -> FutureResult<(), FlowyError>;
|
||||
|
||||
fn read_block(&self, token: &str, params: TextBlockIdPB) -> FutureResult<Option<TextBlockInfoPB>, FlowyError>;
|
||||
fn read_block(&self, token: &str, params: TextBlockIdPB) -> FutureResult<Option<DocumentPB>, FlowyError>;
|
||||
|
||||
fn update_block(&self, token: &str, params: ResetTextBlockParams) -> FutureResult<(), FlowyError>;
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ use flowy_derive::ProtoBuf;
|
||||
use std::convert::TryInto;
|
||||
|
||||
#[derive(ProtoBuf, Default)]
|
||||
pub struct SignInPayload {
|
||||
pub struct SignInPayloadPB {
|
||||
#[pb(index = 1)]
|
||||
pub email: String,
|
||||
|
||||
@ -42,7 +42,7 @@ pub struct SignInResponse {
|
||||
pub token: String,
|
||||
}
|
||||
|
||||
impl TryInto<SignInParams> for SignInPayload {
|
||||
impl TryInto<SignInParams> for SignInPayloadPB {
|
||||
type Error = ErrorCode;
|
||||
|
||||
fn try_into(self) -> Result<SignInParams, Self::Error> {
|
||||
@ -58,7 +58,7 @@ impl TryInto<SignInParams> for SignInPayload {
|
||||
}
|
||||
|
||||
#[derive(ProtoBuf, Default)]
|
||||
pub struct SignUpPayload {
|
||||
pub struct SignUpPayloadPB {
|
||||
#[pb(index = 1)]
|
||||
pub email: String,
|
||||
|
||||
@ -68,7 +68,7 @@ pub struct SignUpPayload {
|
||||
#[pb(index = 3)]
|
||||
pub password: String,
|
||||
}
|
||||
impl TryInto<SignUpParams> for SignUpPayload {
|
||||
impl TryInto<SignUpParams> for SignUpPayloadPB {
|
||||
type Error = ErrorCode;
|
||||
|
||||
fn try_into(self) -> Result<SignUpParams, Self::Error> {
|
||||
|
@ -7,13 +7,13 @@ use crate::{
|
||||
};
|
||||
|
||||
#[derive(Default, ProtoBuf)]
|
||||
pub struct UserToken {
|
||||
pub struct UserTokenPB {
|
||||
#[pb(index = 1)]
|
||||
pub token: String,
|
||||
}
|
||||
|
||||
#[derive(ProtoBuf, Default, Debug, PartialEq, Eq, Clone)]
|
||||
pub struct UserProfile {
|
||||
pub struct UserProfilePB {
|
||||
#[pb(index = 1)]
|
||||
pub id: String,
|
||||
|
||||
@ -28,7 +28,7 @@ pub struct UserProfile {
|
||||
}
|
||||
|
||||
#[derive(ProtoBuf, Default)]
|
||||
pub struct UpdateUserProfilePayload {
|
||||
pub struct UpdateUserProfilePayloadPB {
|
||||
#[pb(index = 1)]
|
||||
pub id: String,
|
||||
|
||||
@ -42,7 +42,7 @@ pub struct UpdateUserProfilePayload {
|
||||
pub password: Option<String>,
|
||||
}
|
||||
|
||||
impl UpdateUserProfilePayload {
|
||||
impl UpdateUserProfilePayloadPB {
|
||||
pub fn new(id: &str) -> Self {
|
||||
Self {
|
||||
id: id.to_owned(),
|
||||
@ -85,7 +85,9 @@ impl UpdateUserProfileParams {
|
||||
pub fn new(user_id: &str) -> Self {
|
||||
Self {
|
||||
id: user_id.to_owned(),
|
||||
..Default::default()
|
||||
name: None,
|
||||
email: None,
|
||||
password: None,
|
||||
}
|
||||
}
|
||||
|
||||
@ -105,7 +107,7 @@ impl UpdateUserProfileParams {
|
||||
}
|
||||
}
|
||||
|
||||
impl TryInto<UpdateUserProfileParams> for UpdateUserProfilePayload {
|
||||
impl TryInto<UpdateUserProfileParams> for UpdateUserProfilePayloadPB {
|
||||
type Error = ErrorCode;
|
||||
|
||||
fn try_into(self) -> Result<UpdateUserProfileParams, Self::Error> {
|
||||
|
@ -2,22 +2,22 @@ use flowy_derive::ProtoBuf;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(ProtoBuf, Default, Debug, Clone)]
|
||||
pub struct UserPreferences {
|
||||
pub struct UserPreferencesPB {
|
||||
#[pb(index = 1)]
|
||||
user_id: String,
|
||||
|
||||
#[pb(index = 2)]
|
||||
appearance_setting: AppearanceSettings,
|
||||
appearance_setting: AppearanceSettingsPB,
|
||||
}
|
||||
|
||||
#[derive(ProtoBuf, Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct AppearanceSettings {
|
||||
pub struct AppearanceSettingsPB {
|
||||
#[pb(index = 1)]
|
||||
pub theme: String,
|
||||
|
||||
#[pb(index = 2)]
|
||||
#[serde(default)]
|
||||
pub locale: LocaleSettings,
|
||||
pub locale: LocaleSettingsPB,
|
||||
|
||||
#[pb(index = 3)]
|
||||
#[serde(default = "DEFAULT_RESET_VALUE")]
|
||||
@ -27,7 +27,7 @@ pub struct AppearanceSettings {
|
||||
const DEFAULT_RESET_VALUE: fn() -> bool = || APPEARANCE_RESET_AS_DEFAULT;
|
||||
|
||||
#[derive(ProtoBuf, Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct LocaleSettings {
|
||||
pub struct LocaleSettingsPB {
|
||||
#[pb(index = 1)]
|
||||
pub language_code: String,
|
||||
|
||||
@ -35,7 +35,7 @@ pub struct LocaleSettings {
|
||||
pub country_code: String,
|
||||
}
|
||||
|
||||
impl std::default::Default for LocaleSettings {
|
||||
impl std::default::Default for LocaleSettingsPB {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
language_code: "en".to_owned(),
|
||||
@ -47,11 +47,11 @@ impl std::default::Default for LocaleSettings {
|
||||
pub const APPEARANCE_DEFAULT_THEME: &str = "light";
|
||||
const APPEARANCE_RESET_AS_DEFAULT: bool = true;
|
||||
|
||||
impl std::default::Default for AppearanceSettings {
|
||||
impl std::default::Default for AppearanceSettingsPB {
|
||||
fn default() -> Self {
|
||||
AppearanceSettings {
|
||||
AppearanceSettingsPB {
|
||||
theme: APPEARANCE_DEFAULT_THEME.to_owned(),
|
||||
locale: LocaleSettings::default(),
|
||||
locale: LocaleSettingsPB::default(),
|
||||
reset_as_default: APPEARANCE_RESET_AS_DEFAULT,
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::entities::{
|
||||
SignInParams, SignInResponse, SignUpParams, SignUpResponse, UpdateUserProfileParams, UserProfile,
|
||||
SignInParams, SignInResponse, SignUpParams, SignUpResponse, UpdateUserProfileParams, UserProfilePB,
|
||||
};
|
||||
use crate::{errors::FlowyError, handlers::*, services::UserSession};
|
||||
use lib_dispatch::prelude::*;
|
||||
@ -26,7 +26,7 @@ pub trait UserCloudService: Send + Sync {
|
||||
fn sign_in(&self, params: SignInParams) -> FutureResult<SignInResponse, FlowyError>;
|
||||
fn sign_out(&self, token: &str) -> FutureResult<(), FlowyError>;
|
||||
fn update_user(&self, token: &str, params: UpdateUserProfileParams) -> FutureResult<(), FlowyError>;
|
||||
fn get_user(&self, token: &str) -> FutureResult<UserProfile, FlowyError>;
|
||||
fn get_user(&self, token: &str) -> FutureResult<UserProfilePB, FlowyError>;
|
||||
fn ws_addr(&self) -> String;
|
||||
}
|
||||
|
||||
@ -39,27 +39,27 @@ pub enum UserEvent {
|
||||
#[event()]
|
||||
InitUser = 0,
|
||||
|
||||
#[event(input = "SignInPayload", output = "UserProfile")]
|
||||
#[event(input = "SignInPayloadPB", output = "UserProfilePB")]
|
||||
SignIn = 1,
|
||||
|
||||
#[event(input = "SignUpPayload", output = "UserProfile")]
|
||||
#[event(input = "SignUpPayloadPB", output = "UserProfilePB")]
|
||||
SignUp = 2,
|
||||
|
||||
#[event(passthrough)]
|
||||
SignOut = 3,
|
||||
|
||||
#[event(input = "UpdateUserProfilePayload")]
|
||||
#[event(input = "UpdateUserProfilePayloadPB")]
|
||||
UpdateUserProfile = 4,
|
||||
|
||||
#[event(output = "UserProfile")]
|
||||
#[event(output = "UserProfilePB")]
|
||||
GetUserProfile = 5,
|
||||
|
||||
#[event(output = "UserProfile")]
|
||||
#[event(output = "UserProfilePB")]
|
||||
CheckUser = 6,
|
||||
|
||||
#[event(input = "AppearanceSettings")]
|
||||
#[event(input = "AppearanceSettingsPB")]
|
||||
SetAppearanceSetting = 7,
|
||||
|
||||
#[event(output = "AppearanceSettings")]
|
||||
#[event(output = "AppearanceSettingsPB")]
|
||||
GetAppearanceSetting = 8,
|
||||
}
|
||||
|
@ -7,9 +7,9 @@ use std::{convert::TryInto, sync::Arc};
|
||||
// tracing instrument 👉🏻 https://docs.rs/tracing/0.1.26/tracing/attr.instrument.html
|
||||
#[tracing::instrument(level = "debug", name = "sign_in", skip(data, session), fields(email = %data.email), err)]
|
||||
pub async fn sign_in(
|
||||
data: Data<SignInPayload>,
|
||||
data: Data<SignInPayloadPB>,
|
||||
session: AppData<Arc<UserSession>>,
|
||||
) -> DataResult<UserProfile, FlowyError> {
|
||||
) -> DataResult<UserProfilePB, FlowyError> {
|
||||
let params: SignInParams = data.into_inner().try_into()?;
|
||||
let user_profile = session.sign_in(params).await?;
|
||||
data_result(user_profile)
|
||||
@ -26,9 +26,9 @@ pub async fn sign_in(
|
||||
err
|
||||
)]
|
||||
pub async fn sign_up(
|
||||
data: Data<SignUpPayload>,
|
||||
data: Data<SignUpPayloadPB>,
|
||||
session: AppData<Arc<UserSession>>,
|
||||
) -> DataResult<UserProfile, FlowyError> {
|
||||
) -> DataResult<UserProfilePB, FlowyError> {
|
||||
let params: SignUpParams = data.into_inner().try_into()?;
|
||||
let user_profile = session.sign_up(params).await?;
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::entities::{
|
||||
AppearanceSettings, UpdateUserProfileParams, UpdateUserProfilePayload, UserProfile, APPEARANCE_DEFAULT_THEME,
|
||||
AppearanceSettingsPB, UpdateUserProfileParams, UpdateUserProfilePayloadPB, UserProfilePB, APPEARANCE_DEFAULT_THEME,
|
||||
};
|
||||
use crate::{errors::FlowyError, services::UserSession};
|
||||
use flowy_database::kv::KV;
|
||||
@ -13,13 +13,13 @@ pub async fn init_user_handler(session: AppData<Arc<UserSession>>) -> Result<(),
|
||||
}
|
||||
|
||||
#[tracing::instrument(level = "debug", skip(session))]
|
||||
pub async fn check_user_handler(session: AppData<Arc<UserSession>>) -> DataResult<UserProfile, FlowyError> {
|
||||
pub async fn check_user_handler(session: AppData<Arc<UserSession>>) -> DataResult<UserProfilePB, FlowyError> {
|
||||
let user_profile = session.check_user().await?;
|
||||
data_result(user_profile)
|
||||
}
|
||||
|
||||
#[tracing::instrument(level = "debug", skip(session))]
|
||||
pub async fn get_user_profile_handler(session: AppData<Arc<UserSession>>) -> DataResult<UserProfile, FlowyError> {
|
||||
pub async fn get_user_profile_handler(session: AppData<Arc<UserSession>>) -> DataResult<UserProfilePB, FlowyError> {
|
||||
let user_profile = session.get_user_profile().await?;
|
||||
data_result(user_profile)
|
||||
}
|
||||
@ -32,7 +32,7 @@ pub async fn sign_out(session: AppData<Arc<UserSession>>) -> Result<(), FlowyErr
|
||||
|
||||
#[tracing::instrument(level = "debug", skip(data, session))]
|
||||
pub async fn update_user_profile_handler(
|
||||
data: Data<UpdateUserProfilePayload>,
|
||||
data: Data<UpdateUserProfilePayloadPB>,
|
||||
session: AppData<Arc<UserSession>>,
|
||||
) -> Result<(), FlowyError> {
|
||||
let params: UpdateUserProfileParams = data.into_inner().try_into()?;
|
||||
@ -43,7 +43,7 @@ pub async fn update_user_profile_handler(
|
||||
const APPEARANCE_SETTING_CACHE_KEY: &str = "appearance_settings";
|
||||
|
||||
#[tracing::instrument(level = "debug", skip(data), err)]
|
||||
pub async fn set_appearance_setting(data: Data<AppearanceSettings>) -> Result<(), FlowyError> {
|
||||
pub async fn set_appearance_setting(data: Data<AppearanceSettingsPB>) -> Result<(), FlowyError> {
|
||||
let mut setting = data.into_inner();
|
||||
if setting.theme.is_empty() {
|
||||
setting.theme = APPEARANCE_DEFAULT_THEME.to_string();
|
||||
@ -55,15 +55,15 @@ pub async fn set_appearance_setting(data: Data<AppearanceSettings>) -> Result<()
|
||||
}
|
||||
|
||||
#[tracing::instrument(err)]
|
||||
pub async fn get_appearance_setting() -> DataResult<AppearanceSettings, FlowyError> {
|
||||
pub async fn get_appearance_setting() -> DataResult<AppearanceSettingsPB, FlowyError> {
|
||||
match KV::get_str(APPEARANCE_SETTING_CACHE_KEY) {
|
||||
None => data_result(AppearanceSettings::default()),
|
||||
None => data_result(AppearanceSettingsPB::default()),
|
||||
Some(s) => {
|
||||
let setting = match serde_json::from_str(&s) {
|
||||
Ok(setting) => setting,
|
||||
Err(e) => {
|
||||
tracing::error!("Deserialize AppearanceSettings failed: {:?}, fallback to default", e);
|
||||
AppearanceSettings::default()
|
||||
AppearanceSettingsPB::default()
|
||||
}
|
||||
};
|
||||
data_result(setting)
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::entities::{SignInResponse, SignUpResponse, UpdateUserProfileParams, UserProfile};
|
||||
use crate::entities::{SignInResponse, SignUpResponse, UpdateUserProfileParams, UserProfilePB};
|
||||
use flowy_database::ConnectionPool;
|
||||
use flowy_database::{schema::user_table, DBConnection, Database};
|
||||
use flowy_error::{ErrorCode, FlowyError};
|
||||
@ -113,9 +113,9 @@ impl std::convert::From<SignInResponse> for UserTable {
|
||||
}
|
||||
}
|
||||
|
||||
impl std::convert::From<UserTable> for UserProfile {
|
||||
impl std::convert::From<UserTable> for UserProfilePB {
|
||||
fn from(table: UserTable) -> Self {
|
||||
UserProfile {
|
||||
UserProfilePB {
|
||||
id: table.id,
|
||||
email: table.email,
|
||||
name: table.name,
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::entities::UserProfile;
|
||||
use crate::entities::UserProfilePB;
|
||||
use tokio::sync::{broadcast, mpsc};
|
||||
|
||||
#[derive(Clone)]
|
||||
@ -14,7 +14,7 @@ pub enum UserStatus {
|
||||
token: String,
|
||||
},
|
||||
SignUp {
|
||||
profile: UserProfile,
|
||||
profile: UserProfilePB,
|
||||
ret: mpsc::Sender<()>,
|
||||
},
|
||||
}
|
||||
@ -42,7 +42,7 @@ impl UserNotifier {
|
||||
});
|
||||
}
|
||||
|
||||
pub(crate) fn notify_sign_up(&self, ret: mpsc::Sender<()>, user_profile: &UserProfile) {
|
||||
pub(crate) fn notify_sign_up(&self, ret: mpsc::Sender<()>, user_profile: &UserProfilePB) {
|
||||
let _ = self.user_status_notifier.send(UserStatus::SignUp {
|
||||
profile: user_profile.clone(),
|
||||
ret,
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::entities::{
|
||||
SignInParams, SignInResponse, SignUpParams, SignUpResponse, UpdateUserProfileParams, UserProfile,
|
||||
SignInParams, SignInResponse, SignUpParams, SignUpResponse, UpdateUserProfileParams, UserProfilePB,
|
||||
};
|
||||
use crate::{
|
||||
dart_notification::*,
|
||||
@ -80,7 +80,7 @@ impl UserSession {
|
||||
}
|
||||
|
||||
#[tracing::instrument(level = "debug", skip(self))]
|
||||
pub async fn sign_in(&self, params: SignInParams) -> Result<UserProfile, FlowyError> {
|
||||
pub async fn sign_in(&self, params: SignInParams) -> Result<UserProfilePB, FlowyError> {
|
||||
if self.is_user_login(¶ms.email) {
|
||||
self.get_user_profile().await
|
||||
} else {
|
||||
@ -88,14 +88,14 @@ impl UserSession {
|
||||
let session: Session = resp.clone().into();
|
||||
let _ = self.set_session(Some(session))?;
|
||||
let user_table = self.save_user(resp.into()).await?;
|
||||
let user_profile: UserProfile = user_table.into();
|
||||
let user_profile: UserProfilePB = user_table.into();
|
||||
self.notifier.notify_login(&user_profile.token, &user_profile.id);
|
||||
Ok(user_profile)
|
||||
}
|
||||
}
|
||||
|
||||
#[tracing::instrument(level = "debug", skip(self))]
|
||||
pub async fn sign_up(&self, params: SignUpParams) -> Result<UserProfile, FlowyError> {
|
||||
pub async fn sign_up(&self, params: SignUpParams) -> Result<UserProfilePB, FlowyError> {
|
||||
if self.is_user_login(¶ms.email) {
|
||||
self.get_user_profile().await
|
||||
} else {
|
||||
@ -103,7 +103,7 @@ impl UserSession {
|
||||
let session: Session = resp.clone().into();
|
||||
let _ = self.set_session(Some(session))?;
|
||||
let user_table = self.save_user(resp.into()).await?;
|
||||
let user_profile: UserProfile = user_table.into();
|
||||
let user_profile: UserProfilePB = user_table.into();
|
||||
let (ret, mut tx) = mpsc::channel(1);
|
||||
self.notifier.notify_sign_up(ret, &user_profile);
|
||||
|
||||
@ -143,7 +143,7 @@ impl UserSession {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn check_user(&self) -> Result<UserProfile, FlowyError> {
|
||||
pub async fn check_user(&self) -> Result<UserProfilePB, FlowyError> {
|
||||
let (user_id, token) = self.get_session()?.into_part();
|
||||
|
||||
let user = dsl::user_table
|
||||
@ -154,7 +154,7 @@ impl UserSession {
|
||||
Ok(user.into())
|
||||
}
|
||||
|
||||
pub async fn get_user_profile(&self) -> Result<UserProfile, FlowyError> {
|
||||
pub async fn get_user_profile(&self) -> Result<UserProfilePB, FlowyError> {
|
||||
let (user_id, token) = self.get_session()?.into_part();
|
||||
let user = dsl::user_table
|
||||
.filter(user_table::id.eq(&user_id))
|
||||
|
@ -1,13 +1,13 @@
|
||||
use crate::helper::*;
|
||||
use flowy_test::{event_builder::UserModuleEventBuilder, FlowySDKTest};
|
||||
use flowy_user::entities::{SignInPayload, SignUpPayload, UserProfile};
|
||||
use flowy_user::entities::{SignInPayloadPB, SignUpPayloadPB, UserProfilePB};
|
||||
use flowy_user::{errors::ErrorCode, event_map::UserEvent::*};
|
||||
|
||||
#[tokio::test]
|
||||
async fn sign_up_with_invalid_email() {
|
||||
for email in invalid_email_test_case() {
|
||||
let sdk = FlowySDKTest::default();
|
||||
let request = SignUpPayload {
|
||||
let request = SignUpPayloadPB {
|
||||
email: email.to_string(),
|
||||
name: valid_name(),
|
||||
password: login_password(),
|
||||
@ -29,7 +29,7 @@ async fn sign_up_with_invalid_email() {
|
||||
async fn sign_up_with_invalid_password() {
|
||||
for password in invalid_password_test_case() {
|
||||
let sdk = FlowySDKTest::default();
|
||||
let request = SignUpPayload {
|
||||
let request = SignUpPayloadPB {
|
||||
email: random_email(),
|
||||
name: valid_name(),
|
||||
password,
|
||||
@ -50,7 +50,7 @@ async fn sign_in_success() {
|
||||
let _ = UserModuleEventBuilder::new(test.clone()).event(SignOut).sync_send();
|
||||
let sign_up_context = test.sign_up().await;
|
||||
|
||||
let request = SignInPayload {
|
||||
let request = SignInPayloadPB {
|
||||
email: sign_up_context.user_profile.email.clone(),
|
||||
password: sign_up_context.password.clone(),
|
||||
name: "".to_string(),
|
||||
@ -61,7 +61,7 @@ async fn sign_in_success() {
|
||||
.payload(request)
|
||||
.async_send()
|
||||
.await
|
||||
.parse::<UserProfile>();
|
||||
.parse::<UserProfilePB>();
|
||||
dbg!(&response);
|
||||
}
|
||||
|
||||
@ -69,7 +69,7 @@ async fn sign_in_success() {
|
||||
async fn sign_in_with_invalid_email() {
|
||||
for email in invalid_email_test_case() {
|
||||
let sdk = FlowySDKTest::default();
|
||||
let request = SignInPayload {
|
||||
let request = SignInPayloadPB {
|
||||
email: email.to_string(),
|
||||
password: login_password(),
|
||||
name: "".to_string(),
|
||||
@ -93,7 +93,7 @@ async fn sign_in_with_invalid_password() {
|
||||
for password in invalid_password_test_case() {
|
||||
let sdk = FlowySDKTest::default();
|
||||
|
||||
let request = SignInPayload {
|
||||
let request = SignInPayloadPB {
|
||||
email: random_email(),
|
||||
password,
|
||||
name: "".to_string(),
|
||||
|
@ -1,6 +1,6 @@
|
||||
use crate::helper::*;
|
||||
use flowy_test::{event_builder::UserModuleEventBuilder, FlowySDKTest};
|
||||
use flowy_user::entities::{UpdateUserProfilePayload, UserProfile};
|
||||
use flowy_user::entities::{UpdateUserProfilePayloadPB, UserProfilePB};
|
||||
use flowy_user::{errors::ErrorCode, event_map::UserEvent::*};
|
||||
use nanoid::nanoid;
|
||||
|
||||
@ -24,7 +24,7 @@ async fn user_profile_get() {
|
||||
let user = UserModuleEventBuilder::new(test.clone())
|
||||
.event(GetUserProfile)
|
||||
.sync_send()
|
||||
.parse::<UserProfile>();
|
||||
.parse::<UserProfilePB>();
|
||||
assert_eq!(user_profile, user);
|
||||
}
|
||||
|
||||
@ -33,7 +33,7 @@ async fn user_update_with_name() {
|
||||
let sdk = FlowySDKTest::default();
|
||||
let user = sdk.init_user().await;
|
||||
let new_name = "hello_world".to_owned();
|
||||
let request = UpdateUserProfilePayload::new(&user.id).name(&new_name);
|
||||
let request = UpdateUserProfilePayloadPB::new(&user.id).name(&new_name);
|
||||
let _ = UserModuleEventBuilder::new(sdk.clone())
|
||||
.event(UpdateUserProfile)
|
||||
.payload(request)
|
||||
@ -43,7 +43,7 @@ async fn user_update_with_name() {
|
||||
.event(GetUserProfile)
|
||||
.assert_error()
|
||||
.sync_send()
|
||||
.parse::<UserProfile>();
|
||||
.parse::<UserProfilePB>();
|
||||
|
||||
assert_eq!(user_profile.name, new_name,);
|
||||
}
|
||||
@ -53,7 +53,7 @@ async fn user_update_with_email() {
|
||||
let sdk = FlowySDKTest::default();
|
||||
let user = sdk.init_user().await;
|
||||
let new_email = format!("{}@gmail.com", nanoid!(6));
|
||||
let request = UpdateUserProfilePayload::new(&user.id).email(&new_email);
|
||||
let request = UpdateUserProfilePayloadPB::new(&user.id).email(&new_email);
|
||||
let _ = UserModuleEventBuilder::new(sdk.clone())
|
||||
.event(UpdateUserProfile)
|
||||
.payload(request)
|
||||
@ -62,7 +62,7 @@ async fn user_update_with_email() {
|
||||
.event(GetUserProfile)
|
||||
.assert_error()
|
||||
.sync_send()
|
||||
.parse::<UserProfile>();
|
||||
.parse::<UserProfilePB>();
|
||||
|
||||
assert_eq!(user_profile.email, new_email,);
|
||||
}
|
||||
@ -72,7 +72,7 @@ async fn user_update_with_password() {
|
||||
let sdk = FlowySDKTest::default();
|
||||
let user = sdk.init_user().await;
|
||||
let new_password = "H123world!".to_owned();
|
||||
let request = UpdateUserProfilePayload::new(&user.id).password(&new_password);
|
||||
let request = UpdateUserProfilePayloadPB::new(&user.id).password(&new_password);
|
||||
|
||||
let _ = UserModuleEventBuilder::new(sdk.clone())
|
||||
.event(UpdateUserProfile)
|
||||
@ -86,7 +86,7 @@ async fn user_update_with_invalid_email() {
|
||||
let test = FlowySDKTest::default();
|
||||
let user = test.init_user().await;
|
||||
for email in invalid_email_test_case() {
|
||||
let request = UpdateUserProfilePayload::new(&user.id).email(&email);
|
||||
let request = UpdateUserProfilePayloadPB::new(&user.id).email(&email);
|
||||
assert_eq!(
|
||||
UserModuleEventBuilder::new(test.clone())
|
||||
.event(UpdateUserProfile)
|
||||
@ -104,7 +104,7 @@ async fn user_update_with_invalid_password() {
|
||||
let test = FlowySDKTest::default();
|
||||
let user = test.init_user().await;
|
||||
for password in invalid_password_test_case() {
|
||||
let request = UpdateUserProfilePayload::new(&user.id).password(&password);
|
||||
let request = UpdateUserProfilePayloadPB::new(&user.id).password(&password);
|
||||
|
||||
UserModuleEventBuilder::new(test.clone())
|
||||
.event(UpdateUserProfile)
|
||||
@ -118,7 +118,7 @@ async fn user_update_with_invalid_password() {
|
||||
async fn user_update_with_invalid_name() {
|
||||
let test = FlowySDKTest::default();
|
||||
let user = test.init_user().await;
|
||||
let request = UpdateUserProfilePayload::new(&user.id).name("");
|
||||
let request = UpdateUserProfilePayloadPB::new(&user.id).name("");
|
||||
UserModuleEventBuilder::new(test.clone())
|
||||
.event(UpdateUserProfile)
|
||||
.payload(request)
|
||||
|
@ -25,8 +25,15 @@ pub fn make_de_token_steam(ctxt: &Ctxt, ast: &ASTContainer) -> Option<TokenStrea
|
||||
impl std::convert::TryFrom<bytes::Bytes> for #struct_ident {
|
||||
type Error = ::protobuf::ProtobufError;
|
||||
fn try_from(bytes: bytes::Bytes) -> Result<Self, Self::Error> {
|
||||
let pb: crate::protobuf::#pb_ty = ::protobuf::Message::parse_from_bytes(&bytes)?;
|
||||
#struct_ident::try_from(pb)
|
||||
Self::try_from(&bytes)
|
||||
}
|
||||
}
|
||||
|
||||
impl std::convert::TryFrom<&bytes::Bytes> for #struct_ident {
|
||||
type Error = ::protobuf::ProtobufError;
|
||||
fn try_from(bytes: &bytes::Bytes) -> Result<Self, Self::Error> {
|
||||
let pb: crate::protobuf::#pb_ty = ::protobuf::Message::parse_from_bytes(bytes)?;
|
||||
Ok(#struct_ident::from(pb))
|
||||
}
|
||||
}
|
||||
|
||||
@ -34,16 +41,15 @@ pub fn make_de_token_steam(ctxt: &Ctxt, ast: &ASTContainer) -> Option<TokenStrea
|
||||
type Error = ::protobuf::ProtobufError;
|
||||
fn try_from(bytes: &[u8]) -> Result<Self, Self::Error> {
|
||||
let pb: crate::protobuf::#pb_ty = ::protobuf::Message::parse_from_bytes(bytes)?;
|
||||
#struct_ident::try_from(pb)
|
||||
Ok(#struct_ident::from(pb))
|
||||
}
|
||||
}
|
||||
|
||||
impl std::convert::TryFrom<crate::protobuf::#pb_ty> for #struct_ident {
|
||||
type Error = ::protobuf::ProtobufError;
|
||||
fn try_from(mut pb: crate::protobuf::#pb_ty) -> Result<Self, Self::Error> {
|
||||
impl std::convert::From<crate::protobuf::#pb_ty> for #struct_ident {
|
||||
fn from(mut pb: crate::protobuf::#pb_ty) -> Self {
|
||||
let mut o = Self::default();
|
||||
#(#build_take_fields)*
|
||||
Ok(o)
|
||||
o
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -70,7 +76,7 @@ fn token_stream_for_one_of(ctxt: &Ctxt, field: &ASTField) -> Option<TokenStream>
|
||||
let ty = bracketed_ty_info.unwrap().ty;
|
||||
Some(quote! {
|
||||
if pb.#has_func() {
|
||||
let enum_de_from_pb = #ty::try_from(&pb.#get_func()).unwrap();
|
||||
let enum_de_from_pb = #ty::from(&pb.#get_func());
|
||||
o.#member = Some(enum_de_from_pb);
|
||||
}
|
||||
})
|
||||
@ -104,7 +110,7 @@ fn token_stream_for_one_of(ctxt: &Ctxt, field: &ASTField) -> Option<TokenStream>
|
||||
let ty = bracketed_ty_info.unwrap().ty;
|
||||
Some(quote! {
|
||||
if pb.#has_func() {
|
||||
let val = #ty::try_from(pb.#take_func()).unwrap();
|
||||
let val = #ty::from(pb.#take_func());
|
||||
o.#member=Some(val);
|
||||
}
|
||||
})
|
||||
@ -138,7 +144,7 @@ fn token_stream_for_field(ctxt: &Ctxt, member: &syn::Member, ty: &syn::Type, is_
|
||||
Some(quote! {
|
||||
let some_value = pb.#member.#take();
|
||||
if some_value.is_some() {
|
||||
let struct_de_from_pb = #ty::try_from(some_value.unwrap()).unwrap();
|
||||
let struct_de_from_pb = #ty::from(some_value.unwrap());
|
||||
o.#member = struct_de_from_pb;
|
||||
}
|
||||
})
|
||||
@ -147,7 +153,7 @@ fn token_stream_for_field(ctxt: &Ctxt, member: &syn::Member, ty: &syn::Type, is_
|
||||
TypeCategory::Enum => {
|
||||
let ty = ty_info.ty;
|
||||
Some(quote! {
|
||||
let enum_de_from_pb = #ty::try_from(&pb.#member).unwrap();
|
||||
let enum_de_from_pb = #ty::from(&pb.#member);
|
||||
o.#member = enum_de_from_pb;
|
||||
|
||||
})
|
||||
@ -192,7 +198,7 @@ fn token_stream_for_vec(ctxt: &Ctxt, member: &syn::Member, bracketed_type: &TyIn
|
||||
Some(quote! {
|
||||
o.#member = pb.#take_ident()
|
||||
.into_iter()
|
||||
.map(|m| #ty::try_from(m).unwrap())
|
||||
.map(|m| #ty::from(m))
|
||||
.collect();
|
||||
})
|
||||
}
|
||||
@ -221,7 +227,7 @@ fn token_stream_for_map(ctxt: &Ctxt, member: &syn::Member, ty_info: &TyInfo) ->
|
||||
TypeCategory::Protobuf => Some(quote! {
|
||||
let mut m: std::collections::HashMap<String, #ty> = std::collections::HashMap::new();
|
||||
pb.#take_ident().into_iter().for_each(|(k,v)| {
|
||||
m.insert(k.clone(), #ty::try_from(v).unwrap());
|
||||
m.insert(k.clone(), #ty::from(v));
|
||||
});
|
||||
o.#member = m;
|
||||
}),
|
||||
|
@ -20,21 +20,19 @@ pub fn make_enum_token_stream(_ctxt: &Ctxt, cont: &ASTContainer) -> Option<Token
|
||||
});
|
||||
|
||||
Some(quote! {
|
||||
impl std::convert::TryFrom<&crate::protobuf::#pb_enum> for #enum_ident {
|
||||
type Error = String;
|
||||
fn try_from(pb:&crate::protobuf::#pb_enum) -> Result<Self, Self::Error> {
|
||||
Ok(match pb {
|
||||
impl std::convert::From<&crate::protobuf::#pb_enum> for #enum_ident {
|
||||
fn from(pb:&crate::protobuf::#pb_enum) -> Self {
|
||||
match pb {
|
||||
#(#build_from_pb_enum)*
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::convert::TryInto<crate::protobuf::#pb_enum> for #enum_ident {
|
||||
type Error = String;
|
||||
fn try_into(self) -> Result<crate::protobuf::#pb_enum, Self::Error> {
|
||||
Ok(match self {
|
||||
impl std::convert::From<#enum_ident> for crate::protobuf::#pb_enum{
|
||||
fn from(o: #enum_ident) -> crate::protobuf::#pb_enum {
|
||||
match o {
|
||||
#(#build_to_pb_enum)*
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
@ -19,18 +19,17 @@ pub fn make_se_token_stream(ctxt: &Ctxt, ast: &ASTContainer) -> Option<TokenStre
|
||||
type Error = ::protobuf::ProtobufError;
|
||||
fn try_into(self) -> Result<bytes::Bytes, Self::Error> {
|
||||
use protobuf::Message;
|
||||
let pb: crate::protobuf::#pb_ty = self.try_into()?;
|
||||
let pb: crate::protobuf::#pb_ty = self.into();
|
||||
let bytes = pb.write_to_bytes()?;
|
||||
Ok(bytes::Bytes::from(bytes))
|
||||
}
|
||||
}
|
||||
|
||||
impl std::convert::TryInto<crate::protobuf::#pb_ty> for #struct_ident {
|
||||
type Error = ::protobuf::ProtobufError;
|
||||
fn try_into(self) -> Result<crate::protobuf::#pb_ty, Self::Error> {
|
||||
impl std::convert::From<#struct_ident> for crate::protobuf::#pb_ty {
|
||||
fn from(mut o: #struct_ident) -> crate::protobuf::#pb_ty {
|
||||
let mut pb = crate::protobuf::#pb_ty::new();
|
||||
#(#build_set_pb_fields)*
|
||||
Ok(pb)
|
||||
pb
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -41,7 +40,7 @@ pub fn make_se_token_stream(ctxt: &Ctxt, ast: &ASTContainer) -> Option<TokenStre
|
||||
fn se_token_stream_for_field(ctxt: &Ctxt, field: &ASTField, _take: bool) -> Option<TokenStream> {
|
||||
if let Some(func) = &field.attrs.serialize_with() {
|
||||
let member = &field.member;
|
||||
Some(quote! { pb.#member=self.#func(); })
|
||||
Some(quote! { pb.#member=o.#func(); })
|
||||
} else if field.attrs.is_one_of() {
|
||||
token_stream_for_one_of(ctxt, field)
|
||||
} else {
|
||||
@ -66,19 +65,19 @@ fn token_stream_for_one_of(ctxt: &Ctxt, field: &ASTField) -> Option<TokenStream>
|
||||
|
||||
match ident_category(bracketed_ty_info.unwrap().ident) {
|
||||
TypeCategory::Protobuf => Some(quote! {
|
||||
match self.#member {
|
||||
Some(s) => { pb.#set_func(s.try_into().unwrap()) }
|
||||
match o.#member {
|
||||
Some(s) => { pb.#set_func(s.into()) }
|
||||
None => {}
|
||||
}
|
||||
}),
|
||||
TypeCategory::Enum => Some(quote! {
|
||||
match self.#member {
|
||||
Some(s) => { pb.#set_func(s.try_into().unwrap()) }
|
||||
match o.#member {
|
||||
Some(s) => { pb.#set_func(s.into()) }
|
||||
None => {}
|
||||
}
|
||||
}),
|
||||
_ => Some(quote! {
|
||||
match self.#member {
|
||||
match o.#member {
|
||||
Some(ref s) => { pb.#set_func(s.clone()) }
|
||||
None => {}
|
||||
}
|
||||
@ -100,18 +99,16 @@ fn gen_token_stream(ctxt: &Ctxt, member: &syn::Member, ty: &syn::Type, is_option
|
||||
TypeCategory::Str => {
|
||||
if is_option {
|
||||
Some(quote! {
|
||||
match self.#member {
|
||||
match o.#member {
|
||||
Some(ref s) => { pb.#member = s.to_string().clone(); }
|
||||
None => { pb.#member = String::new(); }
|
||||
}
|
||||
})
|
||||
} else {
|
||||
Some(quote! { pb.#member = self.#member.clone(); })
|
||||
Some(quote! { pb.#member = o.#member.clone(); })
|
||||
}
|
||||
}
|
||||
TypeCategory::Protobuf => {
|
||||
Some(quote! { pb.#member = ::protobuf::SingularPtrField::some(self.#member.try_into().unwrap()); })
|
||||
}
|
||||
TypeCategory::Protobuf => Some(quote! { pb.#member = ::protobuf::SingularPtrField::some(o.#member.into()); }),
|
||||
TypeCategory::Opt => gen_token_stream(ctxt, member, ty_info.bracket_ty_info.unwrap().ty, true),
|
||||
TypeCategory::Enum => {
|
||||
// let pb_enum_ident = format_ident!("{}", ty_info.ident.to_string());
|
||||
@ -119,10 +116,10 @@ fn gen_token_stream(ctxt: &Ctxt, member: &syn::Member, ty: &syn::Type, is_option
|
||||
// flowy_protobuf::#pb_enum_ident::from_i32(self.#member.value()).unwrap();
|
||||
// })
|
||||
Some(quote! {
|
||||
pb.#member = self.#member.try_into().unwrap();
|
||||
pb.#member = o.#member.into();
|
||||
})
|
||||
}
|
||||
_ => Some(quote! { pb.#member = self.#member; }),
|
||||
_ => Some(quote! { pb.#member = o.#member; }),
|
||||
}
|
||||
}
|
||||
|
||||
@ -139,15 +136,15 @@ fn token_stream_for_vec(ctxt: &Ctxt, member: &syn::Member, ty: &syn::Type) -> Op
|
||||
match ident_category(ty_info.ident) {
|
||||
TypeCategory::Protobuf => Some(quote! {
|
||||
pb.#member = ::protobuf::RepeatedField::from_vec(
|
||||
self.#member
|
||||
o.#member
|
||||
.into_iter()
|
||||
.map(|m| m.try_into().unwrap())
|
||||
.map(|m| m.into())
|
||||
.collect());
|
||||
}),
|
||||
TypeCategory::Bytes => Some(quote! { pb.#member = self.#member.clone(); }),
|
||||
TypeCategory::Bytes => Some(quote! { pb.#member = o.#member.clone(); }),
|
||||
|
||||
_ => Some(quote! {
|
||||
pb.#member = ::protobuf::RepeatedField::from_vec(self.#member.clone());
|
||||
pb.#member = ::protobuf::RepeatedField::from_vec(o.#member.clone());
|
||||
}),
|
||||
}
|
||||
}
|
||||
@ -166,14 +163,14 @@ fn token_stream_for_map(ctxt: &Ctxt, member: &syn::Member, ty: &syn::Type) -> Op
|
||||
match ident_category(ty_info.ident) {
|
||||
TypeCategory::Protobuf => Some(quote! {
|
||||
let mut m: std::collections::HashMap<String, crate::protobuf::#value_ty> = std::collections::HashMap::new();
|
||||
self.#member.into_iter().for_each(|(k,v)| {
|
||||
m.insert(k.clone(), v.try_into().unwrap());
|
||||
o.#member.into_iter().for_each(|(k,v)| {
|
||||
m.insert(k.clone(), v.into());
|
||||
});
|
||||
pb.#member = m;
|
||||
}),
|
||||
_ => Some(quote! {
|
||||
let mut m: std::collections::HashMap<String, #value_ty> = std::collections::HashMap::new();
|
||||
self.#member.iter().for_each(|(k,v)| {
|
||||
o.#member.iter().for_each(|(k,v)| {
|
||||
m.insert(k.clone(), v.clone());
|
||||
});
|
||||
pb.#member = m;
|
||||
|
@ -125,6 +125,12 @@ impl std::convert::From<Revision> for RepeatedRevision {
|
||||
}
|
||||
}
|
||||
|
||||
impl std::convert::From<Vec<Revision>> for RepeatedRevision {
|
||||
fn from(revisions: Vec<Revision>) -> Self {
|
||||
Self { items: revisions }
|
||||
}
|
||||
}
|
||||
|
||||
impl RepeatedRevision {
|
||||
pub fn new(mut items: Vec<Revision>) -> Self {
|
||||
items.sort_by(|a, b| a.rev_id.cmp(&b.rev_id));
|
||||
|
@ -15,7 +15,7 @@ pub struct CreateTextBlockParams {
|
||||
}
|
||||
|
||||
#[derive(ProtoBuf, Default, Debug, Clone, Eq, PartialEq)]
|
||||
pub struct TextBlockInfoPB {
|
||||
pub struct DocumentPB {
|
||||
#[pb(index = 1)]
|
||||
pub block_id: String,
|
||||
|
||||
@ -29,14 +29,14 @@ pub struct TextBlockInfoPB {
|
||||
pub base_rev_id: i64,
|
||||
}
|
||||
|
||||
impl TextBlockInfoPB {
|
||||
impl DocumentPB {
|
||||
pub fn delta(&self) -> Result<RichTextDelta, OTError> {
|
||||
let delta = RichTextDelta::from_bytes(&self.text)?;
|
||||
Ok(delta)
|
||||
}
|
||||
}
|
||||
|
||||
impl std::convert::TryFrom<Revision> for TextBlockInfoPB {
|
||||
impl std::convert::TryFrom<Revision> for DocumentPB {
|
||||
type Error = CollaborateError;
|
||||
|
||||
fn try_from(revision: Revision) -> Result<Self, Self::Error> {
|
||||
@ -48,7 +48,7 @@ impl std::convert::TryFrom<Revision> for TextBlockInfoPB {
|
||||
let delta = RichTextDelta::from_bytes(&revision.delta_data)?;
|
||||
let doc_json = delta.to_delta_str();
|
||||
|
||||
Ok(TextBlockInfoPB {
|
||||
Ok(DocumentPB {
|
||||
block_id: revision.object_id,
|
||||
text: doc_json,
|
||||
rev_id: revision.rev_id,
|
||||
|
@ -1,7 +1,8 @@
|
||||
use crate::entities::revision::{RepeatedRevision, Revision};
|
||||
use crate::{
|
||||
entities::{text_block::TextBlockInfoPB, ws_data::ServerRevisionWSDataBuilder},
|
||||
entities::{text_block::DocumentPB, ws_data::ServerRevisionWSDataBuilder},
|
||||
errors::{internal_error, CollaborateError, CollaborateResult},
|
||||
protobuf::{ClientRevisionWSData, RepeatedRevision as RepeatedRevisionPB, Revision as RevisionPB},
|
||||
protobuf::ClientRevisionWSData,
|
||||
server_document::document_pad::ServerDocument,
|
||||
synchronizer::{RevisionSyncPersistence, RevisionSyncResponse, RevisionSynchronizer, RevisionUser},
|
||||
util::rev_id_from_str,
|
||||
@ -18,27 +19,26 @@ use tokio::{
|
||||
};
|
||||
|
||||
pub trait TextBlockCloudPersistence: Send + Sync + Debug {
|
||||
fn read_text_block(&self, doc_id: &str) -> BoxResultFuture<TextBlockInfoPB, CollaborateError>;
|
||||
fn read_text_block(&self, doc_id: &str) -> BoxResultFuture<DocumentPB, CollaborateError>;
|
||||
|
||||
fn create_text_block(
|
||||
&self,
|
||||
doc_id: &str,
|
||||
repeated_revision: RepeatedRevisionPB,
|
||||
) -> BoxResultFuture<Option<TextBlockInfoPB>, CollaborateError>;
|
||||
repeated_revision: RepeatedRevision,
|
||||
) -> BoxResultFuture<Option<DocumentPB>, CollaborateError>;
|
||||
|
||||
fn read_text_block_revisions(
|
||||
&self,
|
||||
doc_id: &str,
|
||||
rev_ids: Option<Vec<i64>>,
|
||||
) -> BoxResultFuture<Vec<RevisionPB>, CollaborateError>;
|
||||
) -> BoxResultFuture<Vec<Revision>, CollaborateError>;
|
||||
|
||||
fn save_text_block_revisions(&self, repeated_revision: RepeatedRevisionPB)
|
||||
-> BoxResultFuture<(), CollaborateError>;
|
||||
fn save_text_block_revisions(&self, repeated_revision: RepeatedRevision) -> BoxResultFuture<(), CollaborateError>;
|
||||
|
||||
fn reset_text_block(
|
||||
&self,
|
||||
doc_id: &str,
|
||||
repeated_revision: RepeatedRevisionPB,
|
||||
repeated_revision: RepeatedRevision,
|
||||
) -> BoxResultFuture<(), CollaborateError>;
|
||||
}
|
||||
|
||||
@ -47,18 +47,18 @@ impl RevisionSyncPersistence for Arc<dyn TextBlockCloudPersistence> {
|
||||
&self,
|
||||
object_id: &str,
|
||||
rev_ids: Option<Vec<i64>>,
|
||||
) -> BoxResultFuture<Vec<RevisionPB>, CollaborateError> {
|
||||
) -> BoxResultFuture<Vec<Revision>, CollaborateError> {
|
||||
(**self).read_text_block_revisions(object_id, rev_ids)
|
||||
}
|
||||
|
||||
fn save_revisions(&self, repeated_revision: RepeatedRevisionPB) -> BoxResultFuture<(), CollaborateError> {
|
||||
fn save_revisions(&self, repeated_revision: RepeatedRevision) -> BoxResultFuture<(), CollaborateError> {
|
||||
(**self).save_text_block_revisions(repeated_revision)
|
||||
}
|
||||
|
||||
fn reset_object(
|
||||
&self,
|
||||
object_id: &str,
|
||||
repeated_revision: RepeatedRevisionPB,
|
||||
repeated_revision: RepeatedRevision,
|
||||
) -> BoxResultFuture<(), CollaborateError> {
|
||||
(**self).reset_text_block(object_id, repeated_revision)
|
||||
}
|
||||
@ -82,7 +82,7 @@ impl ServerDocumentManager {
|
||||
user: Arc<dyn RevisionUser>,
|
||||
mut client_data: ClientRevisionWSData,
|
||||
) -> Result<(), CollaborateError> {
|
||||
let repeated_revision = client_data.take_revisions();
|
||||
let repeated_revision: RepeatedRevision = client_data.take_revisions().into();
|
||||
let cloned_user = user.clone();
|
||||
let ack_id = rev_id_from_str(&client_data.data_id)?;
|
||||
let object_id = client_data.object_id;
|
||||
@ -131,9 +131,10 @@ impl ServerDocumentManager {
|
||||
pub async fn handle_document_reset(
|
||||
&self,
|
||||
doc_id: &str,
|
||||
mut repeated_revision: RepeatedRevisionPB,
|
||||
mut repeated_revision: RepeatedRevision,
|
||||
) -> Result<(), CollaborateError> {
|
||||
repeated_revision.mut_items().sort_by(|a, b| a.rev_id.cmp(&b.rev_id));
|
||||
repeated_revision.sort_by(|a, b| a.rev_id.cmp(&b.rev_id));
|
||||
|
||||
match self.get_document_handler(doc_id).await {
|
||||
None => {
|
||||
tracing::warn!("Document:{} doesn't exist, ignore document reset", doc_id);
|
||||
@ -166,7 +167,7 @@ impl ServerDocumentManager {
|
||||
async fn create_document(
|
||||
&self,
|
||||
doc_id: &str,
|
||||
repeated_revision: RepeatedRevisionPB,
|
||||
repeated_revision: RepeatedRevision,
|
||||
) -> Result<Arc<OpenDocumentHandler>, CollaborateError> {
|
||||
match self.persistence.create_text_block(doc_id, repeated_revision).await? {
|
||||
None => Err(CollaborateError::internal().context("Create document info from revisions failed")),
|
||||
@ -182,10 +183,7 @@ impl ServerDocumentManager {
|
||||
}
|
||||
|
||||
#[tracing::instrument(level = "debug", skip(self, doc), err)]
|
||||
async fn create_document_handler(
|
||||
&self,
|
||||
doc: TextBlockInfoPB,
|
||||
) -> Result<Arc<OpenDocumentHandler>, CollaborateError> {
|
||||
async fn create_document_handler(&self, doc: DocumentPB) -> Result<Arc<OpenDocumentHandler>, CollaborateError> {
|
||||
let persistence = self.persistence.clone();
|
||||
let handle = spawn_blocking(|| OpenDocumentHandler::new(doc, persistence))
|
||||
.await
|
||||
@ -209,7 +207,7 @@ struct OpenDocumentHandler {
|
||||
}
|
||||
|
||||
impl OpenDocumentHandler {
|
||||
fn new(doc: TextBlockInfoPB, persistence: Arc<dyn TextBlockCloudPersistence>) -> Result<Self, CollaborateError> {
|
||||
fn new(doc: DocumentPB, persistence: Arc<dyn TextBlockCloudPersistence>) -> Result<Self, CollaborateError> {
|
||||
let doc_id = doc.block_id.clone();
|
||||
let (sender, receiver) = mpsc::channel(1000);
|
||||
let users = DashMap::new();
|
||||
@ -232,7 +230,7 @@ impl OpenDocumentHandler {
|
||||
async fn apply_revisions(
|
||||
&self,
|
||||
user: Arc<dyn RevisionUser>,
|
||||
repeated_revision: RepeatedRevisionPB,
|
||||
repeated_revision: RepeatedRevision,
|
||||
) -> Result<(), CollaborateError> {
|
||||
let (ret, rx) = oneshot::channel();
|
||||
self.users.insert(user.user_id(), user.clone());
|
||||
@ -255,7 +253,7 @@ impl OpenDocumentHandler {
|
||||
}
|
||||
|
||||
#[tracing::instrument(level = "debug", skip(self, repeated_revision), err)]
|
||||
async fn apply_document_reset(&self, repeated_revision: RepeatedRevisionPB) -> Result<(), CollaborateError> {
|
||||
async fn apply_document_reset(&self, repeated_revision: RepeatedRevision) -> Result<(), CollaborateError> {
|
||||
let (ret, rx) = oneshot::channel();
|
||||
let msg = DocumentCommand::Reset { repeated_revision, ret };
|
||||
let result = self.send(msg, rx).await?;
|
||||
@ -282,7 +280,7 @@ impl std::ops::Drop for OpenDocumentHandler {
|
||||
enum DocumentCommand {
|
||||
ApplyRevisions {
|
||||
user: Arc<dyn RevisionUser>,
|
||||
repeated_revision: RepeatedRevisionPB,
|
||||
repeated_revision: RepeatedRevision,
|
||||
ret: oneshot::Sender<CollaborateResult<()>>,
|
||||
},
|
||||
Ping {
|
||||
@ -291,7 +289,7 @@ enum DocumentCommand {
|
||||
ret: oneshot::Sender<CollaborateResult<()>>,
|
||||
},
|
||||
Reset {
|
||||
repeated_revision: RepeatedRevisionPB,
|
||||
repeated_revision: RepeatedRevision,
|
||||
ret: oneshot::Sender<CollaborateResult<()>>,
|
||||
},
|
||||
}
|
||||
|
@ -1,10 +1,11 @@
|
||||
use crate::entities::revision::{RepeatedRevision, Revision};
|
||||
use crate::{
|
||||
entities::{
|
||||
folder::{FolderDelta, FolderInfo},
|
||||
ws_data::ServerRevisionWSDataBuilder,
|
||||
},
|
||||
errors::{internal_error, CollaborateError, CollaborateResult},
|
||||
protobuf::{ClientRevisionWSData, RepeatedRevision as RepeatedRevisionPB, Revision as RevisionPB},
|
||||
protobuf::ClientRevisionWSData,
|
||||
server_folder::folder_pad::ServerFolder,
|
||||
synchronizer::{RevisionSyncPersistence, RevisionSyncResponse, RevisionSynchronizer, RevisionUser},
|
||||
util::rev_id_from_str,
|
||||
@ -26,21 +27,21 @@ pub trait FolderCloudPersistence: Send + Sync + Debug {
|
||||
&self,
|
||||
user_id: &str,
|
||||
folder_id: &str,
|
||||
repeated_revision: RepeatedRevisionPB,
|
||||
repeated_revision: RepeatedRevision,
|
||||
) -> BoxResultFuture<Option<FolderInfo>, CollaborateError>;
|
||||
|
||||
fn save_folder_revisions(&self, repeated_revision: RepeatedRevisionPB) -> BoxResultFuture<(), CollaborateError>;
|
||||
fn save_folder_revisions(&self, repeated_revision: RepeatedRevision) -> BoxResultFuture<(), CollaborateError>;
|
||||
|
||||
fn read_folder_revisions(
|
||||
&self,
|
||||
folder_id: &str,
|
||||
rev_ids: Option<Vec<i64>>,
|
||||
) -> BoxResultFuture<Vec<RevisionPB>, CollaborateError>;
|
||||
) -> BoxResultFuture<Vec<Revision>, CollaborateError>;
|
||||
|
||||
fn reset_folder(
|
||||
&self,
|
||||
folder_id: &str,
|
||||
repeated_revision: RepeatedRevisionPB,
|
||||
repeated_revision: RepeatedRevision,
|
||||
) -> BoxResultFuture<(), CollaborateError>;
|
||||
}
|
||||
|
||||
@ -49,18 +50,18 @@ impl RevisionSyncPersistence for Arc<dyn FolderCloudPersistence> {
|
||||
&self,
|
||||
object_id: &str,
|
||||
rev_ids: Option<Vec<i64>>,
|
||||
) -> BoxResultFuture<Vec<RevisionPB>, CollaborateError> {
|
||||
) -> BoxResultFuture<Vec<Revision>, CollaborateError> {
|
||||
(**self).read_folder_revisions(object_id, rev_ids)
|
||||
}
|
||||
|
||||
fn save_revisions(&self, repeated_revision: RepeatedRevisionPB) -> BoxResultFuture<(), CollaborateError> {
|
||||
fn save_revisions(&self, repeated_revision: RepeatedRevision) -> BoxResultFuture<(), CollaborateError> {
|
||||
(**self).save_folder_revisions(repeated_revision)
|
||||
}
|
||||
|
||||
fn reset_object(
|
||||
&self,
|
||||
object_id: &str,
|
||||
repeated_revision: RepeatedRevisionPB,
|
||||
repeated_revision: RepeatedRevision,
|
||||
) -> BoxResultFuture<(), CollaborateError> {
|
||||
(**self).reset_folder(object_id, repeated_revision)
|
||||
}
|
||||
@ -84,7 +85,7 @@ impl ServerFolderManager {
|
||||
user: Arc<dyn RevisionUser>,
|
||||
mut client_data: ClientRevisionWSData,
|
||||
) -> Result<(), CollaborateError> {
|
||||
let repeated_revision = client_data.take_revisions();
|
||||
let repeated_revision: RepeatedRevision = client_data.take_revisions().into();
|
||||
let cloned_user = user.clone();
|
||||
let ack_id = rev_id_from_str(&client_data.data_id)?;
|
||||
let folder_id = client_data.object_id;
|
||||
@ -167,7 +168,7 @@ impl ServerFolderManager {
|
||||
&self,
|
||||
user_id: &str,
|
||||
folder_id: &str,
|
||||
repeated_revision: RepeatedRevisionPB,
|
||||
repeated_revision: RepeatedRevision,
|
||||
) -> Result<Arc<OpenFolderHandler>, CollaborateError> {
|
||||
match self
|
||||
.persistence
|
||||
@ -221,7 +222,7 @@ impl OpenFolderHandler {
|
||||
async fn apply_revisions(
|
||||
&self,
|
||||
user: Arc<dyn RevisionUser>,
|
||||
repeated_revision: RepeatedRevisionPB,
|
||||
repeated_revision: RepeatedRevision,
|
||||
) -> CollaborateResult<()> {
|
||||
let (ret, rx) = oneshot::channel();
|
||||
let msg = FolderCommand::ApplyRevisions {
|
||||
@ -258,7 +259,7 @@ impl std::ops::Drop for OpenFolderHandler {
|
||||
enum FolderCommand {
|
||||
ApplyRevisions {
|
||||
user: Arc<dyn RevisionUser>,
|
||||
repeated_revision: RepeatedRevisionPB,
|
||||
repeated_revision: RepeatedRevision,
|
||||
ret: oneshot::Sender<CollaborateResult<()>>,
|
||||
},
|
||||
Ping {
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user