mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
chore: reanme flowy-user crate
This commit is contained in:
parent
193527e043
commit
8e18d3a937
@ -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),
|
||||||
@ -73,7 +73,7 @@ void _resolveHomeDeps(GetIt getIt) {
|
|||||||
|
|
||||||
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));
|
||||||
|
|
||||||
// ViewPB
|
// ViewPB
|
||||||
@ -90,14 +90,14 @@ 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),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -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;
|
||||||
@ -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({
|
||||||
|
@ -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;
|
||||||
|
@ -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, CurrentWorkspaceSettingPB 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, CurrentWorkspaceSettingPB 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,7 +116,7 @@ class _SkipLogInScreenState extends State<SkipLogInScreen> {
|
|||||||
|
|
||||||
void _openCurrentWorkspace(
|
void _openCurrentWorkspace(
|
||||||
BuildContext context,
|
BuildContext context,
|
||||||
UserProfile user,
|
UserProfilePB user,
|
||||||
dartz.Either<CurrentWorkspaceSettingPB, FlowyError> workspacesOrError,
|
dartz.Either<CurrentWorkspaceSettingPB, FlowyError> workspacesOrError,
|
||||||
) {
|
) {
|
||||||
workspacesOrError.fold(
|
workspacesOrError.fold(
|
||||||
|
@ -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,
|
||||||
|
@ -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;
|
||||||
|
@ -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, CurrentWorkspaceSettingPB 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 {
|
||||||
|
@ -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,7 +58,7 @@ 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),
|
||||||
@ -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<WorkspacePB>> 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),
|
||||||
|
@ -3,7 +3,7 @@ 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';
|
||||||
@ -17,7 +17,7 @@ class WorkspaceListener {
|
|||||||
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({
|
||||||
|
@ -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,7 +18,7 @@ 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 CurrentWorkspaceSettingPB 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);
|
||||||
|
|
||||||
|
@ -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,7 +32,7 @@ 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 CurrentWorkspaceSettingPB workspaceSetting;
|
final CurrentWorkspaceSettingPB workspaceSetting;
|
||||||
|
|
||||||
const HomeMenu({
|
const HomeMenu({
|
||||||
|
@ -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
|
||||||
|
@ -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();
|
||||||
|
@ -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)
|
||||||
|
@ -263,7 +263,7 @@ use flowy_folder_data_model::revision::{
|
|||||||
};
|
};
|
||||||
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};
|
||||||
@ -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 {
|
||||||
|
@ -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>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ use flowy_folder::{
|
|||||||
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},
|
||||||
};
|
};
|
||||||
@ -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
|
||||||
|
@ -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)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user