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