96 lines
3.2 KiB
Rust
Raw Normal View History

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