2021-12-05 01:29:42 +00:00
|
|
|
use flowy_derive::ProtoBuf_Enum;
|
2023-01-26 07:40:23 +00:00
|
|
|
use flowy_notification::NotificationBuilder;
|
2023-07-29 01:46:24 +00:00
|
|
|
|
2023-08-20 06:13:54 +00:00
|
|
|
use crate::entities::AuthStateChangedPB;
|
|
|
|
|
2023-07-05 12:57:09 +00:00
|
|
|
const USER_OBSERVABLE_SOURCE: &str = "User";
|
2021-09-07 15:30:43 +00:00
|
|
|
|
2023-06-09 14:23:07 +00:00
|
|
|
#[derive(ProtoBuf_Enum, Debug, Default)]
|
2021-10-14 06:34:22 +00:00
|
|
|
pub(crate) enum UserNotification {
|
2023-06-09 14:23:07 +00:00
|
|
|
#[default]
|
2023-02-13 01:29:49 +00:00
|
|
|
Unknown = 0,
|
2023-08-20 06:13:54 +00:00
|
|
|
UserAuthStateChanged = 1,
|
2023-02-13 01:29:49 +00:00
|
|
|
DidUpdateUserProfile = 2,
|
2023-07-29 01:46:24 +00:00
|
|
|
DidUpdateUserWorkspaces = 3,
|
2023-08-17 15:46:39 +00:00
|
|
|
DidUpdateCloudConfig = 4,
|
2021-09-07 15:30:43 +00:00
|
|
|
}
|
|
|
|
|
2021-11-27 11:19:41 +00:00
|
|
|
impl std::convert::From<UserNotification> for i32 {
|
2023-02-13 01:29:49 +00:00
|
|
|
fn from(notification: UserNotification) -> Self {
|
|
|
|
notification as i32
|
|
|
|
}
|
2021-09-07 15:30:43 +00:00
|
|
|
}
|
|
|
|
|
2023-10-24 12:11:06 +00:00
|
|
|
#[tracing::instrument(level = "trace")]
|
2023-01-27 09:17:51 +00:00
|
|
|
pub(crate) fn send_notification(id: &str, ty: UserNotification) -> NotificationBuilder {
|
2023-07-05 12:57:09 +00:00
|
|
|
NotificationBuilder::new(id, ty, USER_OBSERVABLE_SOURCE)
|
2021-10-05 03:46:56 +00:00
|
|
|
}
|
2023-01-27 09:17:51 +00:00
|
|
|
|
2023-08-20 06:13:54 +00:00
|
|
|
pub(crate) fn send_auth_state_notification(payload: AuthStateChangedPB) -> NotificationBuilder {
|
|
|
|
NotificationBuilder::new(
|
|
|
|
"auth_state_change_notification",
|
|
|
|
UserNotification::UserAuthStateChanged,
|
|
|
|
USER_OBSERVABLE_SOURCE,
|
|
|
|
)
|
|
|
|
.payload(payload)
|
2023-01-27 09:17:51 +00:00
|
|
|
}
|