docs: udpate user events (#1846)

This commit is contained in:
Nathan.fooo 2023-02-13 08:21:25 +08:00 committed by GitHub
parent 6c895ad4fe
commit e2496e734c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 26 additions and 45 deletions

View file

@ -59,13 +59,7 @@ class UserListener {
void _userNotificationCallback( void _userNotificationCallback(
user.UserNotification ty, Either<Uint8List, FlowyError> result) { user.UserNotification ty, Either<Uint8List, FlowyError> result) {
switch (ty) { switch (ty) {
case user.UserNotification.UserUnauthorized: case user.UserNotification.DidUpdateUserProfile:
result.fold(
(_) {},
(error) => _authNotifier?.value = right(error),
);
break;
case user.UserNotification.UserProfileUpdated:
result.fold( result.fold(
(payload) => (payload) =>
_profileNotifier?.value = left(UserProfilePB.fromBuffer(payload)), _profileNotifier?.value = left(UserProfilePB.fromBuffer(payload)),

View file

@ -18,14 +18,10 @@ export class UserNotificationListener extends AFNotificationListener<UserNotific
let parser = new UserNotificationParser({ let parser = new UserNotificationParser({
callback: (notification, payload) => { callback: (notification, payload) => {
switch (notification) { switch (notification) {
case UserNotification.UserAuthChanged: case UserNotification.DidUpdateUserProfile:
break;
case UserNotification.UserProfileUpdated:
this.onProfileUpdate?.(UserProfilePB.deserializeBinary(payload)); this.onProfileUpdate?.(UserProfilePB.deserializeBinary(payload));
break; break;
case UserNotification.UserUnauthorized: case UserNotification.DidUserSignIn:
break;
case UserNotification.UserSignIn:
this.onUserSignIn?.(UserProfilePB.deserializeBinary(payload)); this.onUserSignIn?.(UserProfilePB.deserializeBinary(payload));
break; break;
default: default:

View file

@ -44,33 +44,43 @@ use strum_macros::Display;
#[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 UserEvent { pub enum UserEvent {
#[event()] /// Logging into an account using a register email and password
InitUser = 0,
#[event(input = "SignInPayloadPB", output = "UserProfilePB")] #[event(input = "SignInPayloadPB", output = "UserProfilePB")]
SignIn = 1, SignIn = 0,
/// Creating a new account
#[event(input = "SignUpPayloadPB", output = "UserProfilePB")] #[event(input = "SignUpPayloadPB", output = "UserProfilePB")]
SignUp = 2, SignUp = 1,
/// Logging out fo an account
#[event(passthrough)] #[event(passthrough)]
SignOut = 3, SignOut = 2,
/// Update the user information
#[event(input = "UpdateUserProfilePayloadPB")] #[event(input = "UpdateUserProfilePayloadPB")]
UpdateUserProfile = 4, UpdateUserProfile = 3,
/// Get the user information
#[event(output = "UserProfilePB")] #[event(output = "UserProfilePB")]
GetUserProfile = 5, GetUserProfile = 4,
/// Check the user current session is valid or not
#[event(output = "UserProfilePB")] #[event(output = "UserProfilePB")]
CheckUser = 6, CheckUser = 5,
/// Initialize resources for the current user after launching the application
#[event()]
InitUser = 6,
/// Change the visual elements of the interface, such as theme, font and more
#[event(input = "AppearanceSettingsPB")] #[event(input = "AppearanceSettingsPB")]
SetAppearanceSetting = 7, SetAppearanceSetting = 7,
/// Get the appearance setting
#[event(output = "AppearanceSettingsPB")] #[event(output = "AppearanceSettingsPB")]
GetAppearanceSetting = 8, GetAppearanceSetting = 8,
/// Get the settings of the user, such as the user storage folder
#[event(output = "UserSettingPB")] #[event(output = "UserSettingPB")]
GetUserSetting = 9, GetUserSetting = 9,
} }

View file

@ -5,11 +5,8 @@ const OBSERVABLE_CATEGORY: &str = "User";
#[derive(ProtoBuf_Enum, Debug)] #[derive(ProtoBuf_Enum, Debug)]
pub(crate) enum UserNotification { pub(crate) enum UserNotification {
Unknown = 0, Unknown = 0,
UserAuthChanged = 1, DidUserSignIn = 1,
UserProfileUpdated = 2, DidUpdateUserProfile = 2,
UserUnauthorized = 3,
UserWsConnectStateChanged = 4,
UserSignIn = 5,
} }
impl std::default::Default for UserNotification { impl std::default::Default for UserNotification {
@ -29,5 +26,5 @@ pub(crate) fn send_notification(id: &str, ty: UserNotification) -> NotificationB
} }
pub(crate) fn send_sign_in_notification() -> NotificationBuilder { pub(crate) fn send_sign_in_notification() -> NotificationBuilder {
NotificationBuilder::new("", UserNotification::UserSignIn, OBSERVABLE_CATEGORY) NotificationBuilder::new("", UserNotification::DidUserSignIn, OBSERVABLE_CATEGORY)
} }

View file

@ -161,7 +161,7 @@ impl UserSession {
let user_profile = self.get_user_profile().await?; let user_profile = self.get_user_profile().await?;
let profile_pb: UserProfilePB = user_profile.into(); let profile_pb: UserProfilePB = user_profile.into();
send_notification(&session.token, UserNotification::UserProfileUpdated) send_notification(&session.token, UserNotification::DidUpdateUserProfile)
.payload(profile_pb) .payload(profile_pb)
.send(); .send();
self.update_user_on_server(&session.token, params).await?; self.update_user_on_server(&session.token, params).await?;
@ -220,22 +220,6 @@ impl UserSession {
impl UserSession { impl UserSession {
fn read_user_profile_on_server(&self, _token: &str) -> Result<(), FlowyError> { fn read_user_profile_on_server(&self, _token: &str) -> Result<(), FlowyError> {
// let server = self.cloud_service.clone();
// let token = token.to_owned();
// tokio::spawn(async move {
// match server.get_user(&token).await {
// Ok(profile) => {
// dart_notify(&token, UserNotification::UserProfileUpdated)
// .payload(profile)
// .send();
// }
// Err(e) => {
// dart_notify(&token, UserNotification::UserProfileUpdated)
// .error(e)
// .send();
// }
// }
// });
Ok(()) Ok(())
} }