notification.rs 936 B

1234567891011121314151617181920212223242526272829303132333435
  1. use flowy_derive::ProtoBuf_Enum;
  2. use flowy_notification::NotificationBuilder;
  3. use crate::entities::AuthStateChangedPB;
  4. const USER_OBSERVABLE_SOURCE: &str = "User";
  5. #[derive(ProtoBuf_Enum, Debug, Default)]
  6. pub(crate) enum UserNotification {
  7. #[default]
  8. Unknown = 0,
  9. UserAuthStateChanged = 1,
  10. DidUpdateUserProfile = 2,
  11. DidUpdateUserWorkspaces = 3,
  12. DidUpdateCloudConfig = 4,
  13. }
  14. impl std::convert::From<UserNotification> for i32 {
  15. fn from(notification: UserNotification) -> Self {
  16. notification as i32
  17. }
  18. }
  19. pub(crate) fn send_notification(id: &str, ty: UserNotification) -> NotificationBuilder {
  20. NotificationBuilder::new(id, ty, USER_OBSERVABLE_SOURCE)
  21. }
  22. pub(crate) fn send_auth_state_notification(payload: AuthStateChangedPB) -> NotificationBuilder {
  23. NotificationBuilder::new(
  24. "auth_state_change_notification",
  25. UserNotification::UserAuthStateChanged,
  26. USER_OBSERVABLE_SOURCE,
  27. )
  28. .payload(payload)
  29. }