event_map.rs 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. use crate::entities::UserProfilePB;
  2. use crate::{errors::FlowyError, handlers::*, services::UserSession};
  3. use lib_dispatch::prelude::*;
  4. use lib_infra::future::{Fut, FutureResult};
  5. use std::sync::Arc;
  6. use user_model::{
  7. SignInParams, SignInResponse, SignUpParams, SignUpResponse, UpdateUserProfileParams, UserProfile,
  8. };
  9. pub fn init(user_session: Arc<UserSession>) -> AFPlugin {
  10. AFPlugin::new()
  11. .name("Flowy-User")
  12. .state(user_session)
  13. .event(UserEvent::SignIn, sign_in)
  14. .event(UserEvent::SignUp, sign_up)
  15. .event(UserEvent::InitUser, init_user_handler)
  16. .event(UserEvent::GetUserProfile, get_user_profile_handler)
  17. .event(UserEvent::SignOut, sign_out)
  18. .event(UserEvent::UpdateUserProfile, update_user_profile_handler)
  19. .event(UserEvent::CheckUser, check_user_handler)
  20. .event(UserEvent::SetAppearanceSetting, set_appearance_setting)
  21. .event(UserEvent::GetAppearanceSetting, get_appearance_setting)
  22. .event(UserEvent::GetUserSetting, get_user_setting)
  23. }
  24. pub trait UserStatusCallback: Send + Sync + 'static {
  25. fn did_sign_in(&self, token: &str, user_id: &str) -> Fut<FlowyResult<()>>;
  26. fn did_sign_up(&self, user_profile: &UserProfile) -> Fut<FlowyResult<()>>;
  27. fn did_expired(&self, token: &str, user_id: &str) -> Fut<FlowyResult<()>>;
  28. }
  29. pub trait UserCloudService: Send + Sync {
  30. fn sign_up(&self, params: SignUpParams) -> FutureResult<SignUpResponse, FlowyError>;
  31. fn sign_in(&self, params: SignInParams) -> FutureResult<SignInResponse, FlowyError>;
  32. fn sign_out(&self, token: &str) -> FutureResult<(), FlowyError>;
  33. fn update_user(
  34. &self,
  35. token: &str,
  36. params: UpdateUserProfileParams,
  37. ) -> FutureResult<(), FlowyError>;
  38. fn get_user(&self, token: &str) -> FutureResult<UserProfilePB, FlowyError>;
  39. fn ws_addr(&self) -> String;
  40. }
  41. use flowy_derive::{Flowy_Event, ProtoBuf_Enum};
  42. use flowy_error::FlowyResult;
  43. use strum_macros::Display;
  44. #[derive(Clone, Copy, PartialEq, Eq, Debug, Display, Hash, ProtoBuf_Enum, Flowy_Event)]
  45. #[event_err = "FlowyError"]
  46. pub enum UserEvent {
  47. /// Logging into an account using a register email and password
  48. #[event(input = "SignInPayloadPB", output = "UserProfilePB")]
  49. SignIn = 0,
  50. /// Creating a new account
  51. #[event(input = "SignUpPayloadPB", output = "UserProfilePB")]
  52. SignUp = 1,
  53. /// Logging out fo an account
  54. #[event(passthrough)]
  55. SignOut = 2,
  56. /// Update the user information
  57. #[event(input = "UpdateUserProfilePayloadPB")]
  58. UpdateUserProfile = 3,
  59. /// Get the user information
  60. #[event(output = "UserProfilePB")]
  61. GetUserProfile = 4,
  62. /// Check the user current session is valid or not
  63. #[event(output = "UserProfilePB")]
  64. CheckUser = 5,
  65. /// Initialize resources for the current user after launching the application
  66. #[event()]
  67. InitUser = 6,
  68. /// Change the visual elements of the interface, such as theme, font and more
  69. #[event(input = "AppearanceSettingsPB")]
  70. SetAppearanceSetting = 7,
  71. /// Get the appearance setting
  72. #[event(output = "AppearanceSettingsPB")]
  73. GetAppearanceSetting = 8,
  74. /// Get the settings of the user, such as the user storage folder
  75. #[event(output = "UserSettingPB")]
  76. GetUserSetting = 9,
  77. }