chore: notification parser (#1745)

This commit is contained in:
Nathan.fooo
2023-01-27 22:57:23 +08:00
committed by GitHub
parent 7a750e5255
commit 4fb2afe82e
36 changed files with 143 additions and 78 deletions

View File

@ -162,8 +162,8 @@ pub enum GridEvent {
/// [UpdateSelectOption] event is used to update a FieldTypeOptionData whose field_type is
/// FieldType::SingleSelect or FieldType::MultiSelect.
///
/// This event may trigger the GridDartNotification::DidUpdateCell event.
/// For example, GridDartNotification::DidUpdateCell will be triggered if the [SelectOptionChangesetPB]
/// This event may trigger the GridNotification::DidUpdateCell event.
/// For example, GridNotification::DidUpdateCell will be triggered if the [SelectOptionChangesetPB]
/// carries a change that updates the name of the option.
#[event(input = "SelectOptionChangesetPB")]
UpdateSelectOption = 32,

View File

@ -3,7 +3,7 @@ use flowy_notification::NotificationBuilder;
const OBSERVABLE_CATEGORY: &str = "Grid";
#[derive(ProtoBuf_Enum, Debug)]
pub enum GridDartNotification {
pub enum GridNotification {
Unknown = 0,
DidCreateBlock = 11,
DidUpdateGridViewRows = 20,
@ -22,19 +22,19 @@ pub enum GridDartNotification {
DidUpdateGridSetting = 70,
}
impl std::default::Default for GridDartNotification {
impl std::default::Default for GridNotification {
fn default() -> Self {
GridDartNotification::Unknown
GridNotification::Unknown
}
}
impl std::convert::From<GridDartNotification> for i32 {
fn from(notification: GridDartNotification) -> Self {
impl std::convert::From<GridNotification> for i32 {
fn from(notification: GridNotification) -> Self {
notification as i32
}
}
#[tracing::instrument(level = "trace")]
pub fn send_notification(id: &str, ty: GridDartNotification) -> NotificationBuilder {
pub fn send_notification(id: &str, ty: GridNotification) -> NotificationBuilder {
NotificationBuilder::new(id, ty, OBSERVABLE_CATEGORY)
}

View File

@ -1,6 +1,6 @@
use crate::entities::{CellChangesetPB, InsertedRowPB, UpdatedRowPB};
use crate::manager::GridUser;
use crate::notification::{send_notification, GridDartNotification};
use crate::notification::{send_notification, GridNotification};
use crate::services::block_editor::{GridBlockRevisionEditor, GridBlockRevisionMergeable};
use crate::services::persistence::block_index::BlockIndexCache;
use crate::services::persistence::rev_sqlite::{
@ -262,7 +262,7 @@ impl GridBlockManager {
async fn notify_did_update_cell(&self, changeset: CellChangesetPB) -> FlowyResult<()> {
let id = format!("{}:{}", changeset.row_id, changeset.field_id);
send_notification(&id, GridDartNotification::DidUpdateCell).send();
send_notification(&id, GridNotification::DidUpdateCell).send();
Ok(())
}
}

View File

@ -1,7 +1,7 @@
use crate::entities::CellPathParams;
use crate::entities::*;
use crate::manager::GridUser;
use crate::notification::{send_notification, GridDartNotification};
use crate::notification::{send_notification, GridNotification};
use crate::services::block_manager::GridBlockManager;
use crate::services::cell::{
apply_cell_data_changeset, decode_type_cell_data, stringify_cell_data, AnyTypeCache, AtomicCellDataCache,
@ -112,7 +112,7 @@ impl GridRevisionEditor {
self.view_manager.close(&self.grid_id).await;
}
/// Save the type-option data to disk and send a `GridDartNotification::DidUpdateField` notification
/// Save the type-option data to disk and send a `GridNotification::DidUpdateField` notification
/// to dart side.
///
/// It will do nothing if the passed-in type_option_data is empty
@ -852,7 +852,7 @@ impl GridRevisionEditor {
let notified_changeset = GridFieldChangesetPB::update(&self.grid_id, vec![updated_field.clone()]);
self.notify_did_update_grid(notified_changeset).await?;
send_notification(field_id, GridDartNotification::DidUpdateField)
send_notification(field_id, GridNotification::DidUpdateField)
.payload(updated_field)
.send();
}
@ -861,7 +861,7 @@ impl GridRevisionEditor {
}
async fn notify_did_update_grid(&self, changeset: GridFieldChangesetPB) -> FlowyResult<()> {
send_notification(&self.grid_id, GridDartNotification::DidUpdateGridFields)
send_notification(&self.grid_id, GridNotification::DidUpdateGridFields)
.payload(changeset)
.send();
Ok(())

View File

@ -1,5 +1,5 @@
use crate::entities::{GridRowsVisibilityChangesetPB, ReorderAllRowsPB, ReorderSingleRowPB};
use crate::notification::{send_notification, GridDartNotification};
use crate::notification::{send_notification, GridNotification};
use crate::services::filter::FilterResultNotification;
use crate::services::sort::{ReorderAllRowsResult, ReorderSingleRowResult};
use async_stream::stream;
@ -37,18 +37,15 @@ impl GridViewChangedReceiverRunner {
invisible_rows: notification.invisible_rows,
};
send_notification(
&changeset.view_id,
GridDartNotification::DidUpdateGridViewRowsVisibility,
)
.payload(changeset)
.send()
send_notification(&changeset.view_id, GridNotification::DidUpdateGridViewRowsVisibility)
.payload(changeset)
.send()
}
GridViewChanged::ReorderAllRowsNotification(notification) => {
let row_orders = ReorderAllRowsPB {
row_orders: notification.row_orders,
};
send_notification(&notification.view_id, GridDartNotification::DidReorderRows)
send_notification(&notification.view_id, GridNotification::DidReorderRows)
.payload(row_orders)
.send()
}
@ -58,7 +55,7 @@ impl GridViewChangedReceiverRunner {
old_index: notification.old_index as i32,
new_index: notification.new_index as i32,
};
send_notification(&notification.view_id, GridDartNotification::DidReorderSingleRow)
send_notification(&notification.view_id, GridNotification::DidReorderSingleRow)
.payload(reorder_row)
.send()
}

View File

@ -1,5 +1,5 @@
use crate::entities::*;
use crate::notification::{send_notification, GridDartNotification};
use crate::notification::{send_notification, GridNotification};
use crate::services::block_manager::GridBlockEvent;
use crate::services::cell::{AtomicCellDataCache, TypeCellData};
use crate::services::field::{RowSingleCellData, TypeOptionCellDataHandler};
@ -184,7 +184,7 @@ impl GridViewRevisionEditor {
}
};
send_notification(&self.view_id, GridDartNotification::DidUpdateGridViewRows)
send_notification(&self.view_id, GridNotification::DidUpdateGridViewRows)
.payload(changeset)
.send();
}
@ -616,7 +616,7 @@ impl GridViewRevisionEditor {
debug_assert!(!changeset.is_empty());
if !changeset.is_empty() {
send_notification(&changeset.view_id, GridDartNotification::DidGroupByNewField)
send_notification(&changeset.view_id, GridNotification::DidGroupByNewField)
.payload(changeset)
.send();
}
@ -630,33 +630,33 @@ impl GridViewRevisionEditor {
async fn notify_did_update_setting(&self) {
let setting = self.get_view_setting().await;
send_notification(&self.view_id, GridDartNotification::DidUpdateGridSetting)
send_notification(&self.view_id, GridNotification::DidUpdateGridSetting)
.payload(setting)
.send();
}
pub async fn notify_did_update_group_rows(&self, payload: GroupRowsNotificationPB) {
send_notification(&payload.group_id, GridDartNotification::DidUpdateGroup)
send_notification(&payload.group_id, GridNotification::DidUpdateGroup)
.payload(payload)
.send();
}
pub async fn notify_did_update_filter(&self, notification: FilterChangesetNotificationPB) {
send_notification(&notification.view_id, GridDartNotification::DidUpdateFilter)
send_notification(&notification.view_id, GridNotification::DidUpdateFilter)
.payload(notification)
.send();
}
pub async fn notify_did_update_sort(&self, notification: SortChangesetNotificationPB) {
if !notification.is_empty() {
send_notification(&notification.view_id, GridDartNotification::DidUpdateSort)
send_notification(&notification.view_id, GridNotification::DidUpdateSort)
.payload(notification)
.send();
}
}
async fn notify_did_update_view(&self, changeset: GroupViewChangesetPB) {
send_notification(&self.view_id, GridDartNotification::DidUpdateGroupView)
send_notification(&self.view_id, GridNotification::DidUpdateGroupView)
.payload(changeset)
.send();
}