2023-04-13 10:53:51 +00:00
|
|
|
use flowy_derive::ProtoBuf_Enum;
|
|
|
|
use flowy_notification::NotificationBuilder;
|
|
|
|
|
2023-07-05 12:57:09 +00:00
|
|
|
const DOCUMENT_OBSERVABLE_SOURCE: &str = "Document";
|
2023-04-13 10:53:51 +00:00
|
|
|
|
2023-06-09 14:23:07 +00:00
|
|
|
#[derive(ProtoBuf_Enum, Debug, Default)]
|
2023-04-13 10:53:51 +00:00
|
|
|
pub(crate) enum DocumentNotification {
|
2023-06-09 14:23:07 +00:00
|
|
|
#[default]
|
2023-04-13 10:53:51 +00:00
|
|
|
Unknown = 0,
|
|
|
|
|
|
|
|
DidReceiveUpdate = 1,
|
2023-07-05 12:57:09 +00:00
|
|
|
DidUpdateDocumentSnapshotState = 2,
|
|
|
|
DidUpdateDocumentSyncState = 3,
|
2023-04-13 10:53:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl std::convert::From<DocumentNotification> for i32 {
|
|
|
|
fn from(notification: DocumentNotification) -> Self {
|
|
|
|
notification as i32
|
|
|
|
}
|
|
|
|
}
|
2023-07-05 12:57:09 +00:00
|
|
|
impl std::convert::From<i32> for DocumentNotification {
|
|
|
|
fn from(notification: i32) -> Self {
|
|
|
|
match notification {
|
|
|
|
1 => DocumentNotification::DidReceiveUpdate,
|
|
|
|
2 => DocumentNotification::DidUpdateDocumentSnapshotState,
|
|
|
|
3 => DocumentNotification::DidUpdateDocumentSyncState,
|
|
|
|
_ => DocumentNotification::Unknown,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-04-13 10:53:51 +00:00
|
|
|
|
|
|
|
pub(crate) fn send_notification(id: &str, ty: DocumentNotification) -> NotificationBuilder {
|
2023-07-05 12:57:09 +00:00
|
|
|
NotificationBuilder::new(id, ty, DOCUMENT_OBSERVABLE_SOURCE)
|
2023-04-13 10:53:51 +00:00
|
|
|
}
|