2022-02-28 23:37:41 -05:00
|
|
|
import 'dart:async';
|
2022-07-03 16:52:06 +08:00
|
|
|
|
2022-02-28 23:37:41 -05:00
|
|
|
import 'package:dartz/dartz.dart';
|
|
|
|
import 'package:flowy_sdk/dispatch/dispatch.dart';
|
|
|
|
import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart';
|
2022-07-04 15:00:54 +08:00
|
|
|
import 'package:flowy_sdk/protobuf/flowy-folder/workspace.pb.dart';
|
2022-07-04 15:07:11 +08:00
|
|
|
import 'package:flowy_sdk/protobuf/flowy-user/user_profile.pb.dart';
|
2022-02-28 23:37:41 -05:00
|
|
|
|
|
|
|
class UserService {
|
2022-07-03 16:52:06 +08:00
|
|
|
final String userId;
|
|
|
|
UserService({
|
|
|
|
required this.userId,
|
|
|
|
});
|
2022-07-19 14:40:56 +08:00
|
|
|
Future<Either<UserProfilePB, FlowyError>> getUserProfile({required String userId}) {
|
2022-02-28 23:37:41 -05:00
|
|
|
return UserEventGetUserProfile().send();
|
|
|
|
}
|
|
|
|
|
2022-07-03 16:52:06 +08:00
|
|
|
Future<Either<Unit, FlowyError>> updateUserProfile({
|
|
|
|
String? name,
|
|
|
|
String? password,
|
|
|
|
String? email,
|
|
|
|
}) {
|
2022-07-19 14:40:56 +08:00
|
|
|
var payload = UpdateUserProfilePayloadPB.create()..id = userId;
|
2022-07-03 16:52:06 +08:00
|
|
|
|
|
|
|
if (name != null) {
|
|
|
|
payload.name = name;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (password != null) {
|
|
|
|
payload.password = password;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (email != null) {
|
|
|
|
payload.email = email;
|
|
|
|
}
|
|
|
|
|
|
|
|
return UserEventUpdateUserProfile(payload).send();
|
|
|
|
}
|
|
|
|
|
2022-02-28 23:37:41 -05:00
|
|
|
Future<Either<Unit, FlowyError>> deleteWorkspace({required String workspaceId}) {
|
|
|
|
throw UnimplementedError();
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<Either<Unit, FlowyError>> signOut() {
|
|
|
|
return UserEventSignOut().send();
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<Either<Unit, FlowyError>> initUser() async {
|
|
|
|
return UserEventInitUser().send();
|
|
|
|
}
|
|
|
|
|
2022-07-19 14:11:29 +08:00
|
|
|
Future<Either<List<WorkspacePB>, FlowyError>> getWorkspaces() {
|
|
|
|
final request = WorkspaceIdPB.create();
|
2022-02-28 23:37:41 -05:00
|
|
|
|
|
|
|
return FolderEventReadWorkspaces(request).send().then((result) {
|
|
|
|
return result.fold(
|
|
|
|
(workspaces) => left(workspaces.items),
|
|
|
|
(error) => right(error),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-07-19 14:11:29 +08:00
|
|
|
Future<Either<WorkspacePB, FlowyError>> openWorkspace(String workspaceId) {
|
|
|
|
final request = WorkspaceIdPB.create()..value = workspaceId;
|
2022-02-28 23:37:41 -05:00
|
|
|
return FolderEventOpenWorkspace(request).send().then((result) {
|
|
|
|
return result.fold(
|
|
|
|
(workspace) => left(workspace),
|
|
|
|
(error) => right(error),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-07-19 14:11:29 +08:00
|
|
|
Future<Either<WorkspacePB, FlowyError>> createWorkspace(String name, String desc) {
|
|
|
|
final request = CreateWorkspacePayloadPB.create()
|
2022-02-28 23:37:41 -05:00
|
|
|
..name = name
|
|
|
|
..desc = desc;
|
|
|
|
return FolderEventCreateWorkspace(request).send().then((result) {
|
|
|
|
return result.fold(
|
|
|
|
(workspace) => left(workspace),
|
|
|
|
(error) => right(error),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|