87 lines
3.2 KiB
Rust
Raw Normal View History

2023-01-30 11:11:19 +08:00
use crate::entities::UserProfilePB;
2022-07-04 14:53:35 +08:00
use crate::{errors::FlowyError, handlers::*, services::UserSession};
2022-01-11 13:34:45 +08:00
use lib_dispatch::prelude::*;
2023-01-31 19:30:48 +08:00
use lib_infra::future::{Fut, FutureResult};
2021-07-09 23:31:44 +08:00
use std::sync::Arc;
2023-01-31 19:30:48 +08:00
use user_model::{SignInParams, SignInResponse, SignUpParams, SignUpResponse, UpdateUserProfileParams, UserProfile};
pub fn init(user_session: Arc<UserSession>) -> AFPlugin {
AFPlugin::new()
2021-07-03 14:14:10 +08:00
.name("Flowy-User")
.state(user_session)
2021-07-25 08:13:59 +08:00
.event(UserEvent::SignIn, sign_in)
.event(UserEvent::SignUp, sign_up)
2021-09-17 19:03:46 +08:00
.event(UserEvent::InitUser, init_user_handler)
.event(UserEvent::GetUserProfile, get_user_profile_handler)
2021-07-25 08:13:59 +08:00
.event(UserEvent::SignOut, sign_out)
.event(UserEvent::UpdateUserProfile, update_user_profile_handler)
.event(UserEvent::CheckUser, check_user_handler)
2022-01-28 18:34:21 +08:00
.event(UserEvent::SetAppearanceSetting, set_appearance_setting)
2022-01-28 10:56:55 +08:00
.event(UserEvent::GetAppearanceSetting, get_appearance_setting)
2022-11-11 17:24:10 +08:00
.event(UserEvent::GetUserSetting, get_user_setting)
}
2022-01-10 23:45:59 +08:00
2023-01-31 19:30:48 +08:00
pub trait UserStatusCallback: Send + Sync + 'static {
fn did_sign_in(&self, token: &str, user_id: &str) -> Fut<FlowyResult<()>>;
fn did_sign_up(&self, user_profile: &UserProfile) -> Fut<FlowyResult<()>>;
fn did_expired(&self, token: &str, user_id: &str) -> Fut<FlowyResult<()>>;
}
2022-01-10 23:45:59 +08:00
pub trait UserCloudService: Send + Sync {
fn sign_up(&self, params: SignUpParams) -> FutureResult<SignUpResponse, FlowyError>;
fn sign_in(&self, params: SignInParams) -> FutureResult<SignInResponse, FlowyError>;
fn sign_out(&self, token: &str) -> FutureResult<(), FlowyError>;
fn update_user(&self, token: &str, params: UpdateUserProfileParams) -> FutureResult<(), FlowyError>;
2022-07-19 14:40:56 +08:00
fn get_user(&self, token: &str) -> FutureResult<UserProfilePB, FlowyError>;
2022-01-10 23:45:59 +08:00
fn ws_addr(&self) -> String;
}
2022-01-28 10:56:55 +08:00
use flowy_derive::{Flowy_Event, ProtoBuf_Enum};
2023-01-31 19:30:48 +08:00
use flowy_error::FlowyResult;
2022-01-28 10:56:55 +08:00
use strum_macros::Display;
#[derive(Clone, Copy, PartialEq, Eq, Debug, Display, Hash, ProtoBuf_Enum, Flowy_Event)]
#[event_err = "FlowyError"]
pub enum UserEvent {
2023-02-13 08:21:25 +08:00
/// Logging into an account using a register email and password
2022-07-19 14:40:56 +08:00
#[event(input = "SignInPayloadPB", output = "UserProfilePB")]
2023-02-13 08:21:25 +08:00
SignIn = 0,
2022-01-28 10:56:55 +08:00
2023-02-13 08:21:25 +08:00
/// Creating a new account
2022-07-19 14:40:56 +08:00
#[event(input = "SignUpPayloadPB", output = "UserProfilePB")]
2023-02-13 08:21:25 +08:00
SignUp = 1,
2022-01-28 10:56:55 +08:00
2023-02-13 08:21:25 +08:00
/// Logging out fo an account
2022-01-28 10:56:55 +08:00
#[event(passthrough)]
2023-02-13 08:21:25 +08:00
SignOut = 2,
2022-01-28 10:56:55 +08:00
2023-02-13 08:21:25 +08:00
/// Update the user information
2022-07-19 14:40:56 +08:00
#[event(input = "UpdateUserProfilePayloadPB")]
2023-02-13 08:21:25 +08:00
UpdateUserProfile = 3,
2022-01-28 10:56:55 +08:00
2023-02-13 08:21:25 +08:00
/// Get the user information
2022-07-19 14:40:56 +08:00
#[event(output = "UserProfilePB")]
2023-02-13 08:21:25 +08:00
GetUserProfile = 4,
2022-01-28 10:56:55 +08:00
2023-02-13 08:21:25 +08:00
/// Check the user current session is valid or not
2022-07-19 14:40:56 +08:00
#[event(output = "UserProfilePB")]
2023-02-13 08:21:25 +08:00
CheckUser = 5,
/// Initialize resources for the current user after launching the application
#[event()]
InitUser = 6,
2022-01-28 10:56:55 +08:00
2023-02-13 08:21:25 +08:00
/// Change the visual elements of the interface, such as theme, font and more
2022-07-19 14:40:56 +08:00
#[event(input = "AppearanceSettingsPB")]
2022-01-28 18:34:21 +08:00
SetAppearanceSetting = 7,
2022-01-28 10:56:55 +08:00
2023-02-13 08:21:25 +08:00
/// Get the appearance setting
2022-07-19 14:40:56 +08:00
#[event(output = "AppearanceSettingsPB")]
2022-01-28 10:56:55 +08:00
GetAppearanceSetting = 8,
2022-11-11 17:24:10 +08:00
2023-02-13 08:21:25 +08:00
/// Get the settings of the user, such as the user storage folder
2022-11-11 17:24:10 +08:00
#[event(output = "UserSettingPB")]
GetUserSetting = 9,
2022-01-28 10:56:55 +08:00
}