notification.rs 986 B

12345678910111213141516171819202122232425262728293031323334
  1. use flowy_derive::ProtoBuf_Enum;
  2. use flowy_notification::NotificationBuilder;
  3. const DOCUMENT_OBSERVABLE_SOURCE: &str = "Document";
  4. #[derive(ProtoBuf_Enum, Debug, Default)]
  5. pub enum DocumentNotification {
  6. #[default]
  7. Unknown = 0,
  8. DidReceiveUpdate = 1,
  9. DidUpdateDocumentSnapshotState = 2,
  10. DidUpdateDocumentSyncState = 3,
  11. }
  12. impl std::convert::From<DocumentNotification> for i32 {
  13. fn from(notification: DocumentNotification) -> Self {
  14. notification as i32
  15. }
  16. }
  17. impl std::convert::From<i32> for DocumentNotification {
  18. fn from(notification: i32) -> Self {
  19. match notification {
  20. 1 => DocumentNotification::DidReceiveUpdate,
  21. 2 => DocumentNotification::DidUpdateDocumentSnapshotState,
  22. 3 => DocumentNotification::DidUpdateDocumentSyncState,
  23. _ => DocumentNotification::Unknown,
  24. }
  25. }
  26. }
  27. pub(crate) fn send_notification(id: &str, ty: DocumentNotification) -> NotificationBuilder {
  28. NotificationBuilder::new(id, ty, DOCUMENT_OBSERVABLE_SOURCE)
  29. }