2023-07-14 05:37:13 +00:00
|
|
|
use collab_database::rows::RowDetail;
|
|
|
|
|
2023-04-28 06:08:53 +00:00
|
|
|
use flowy_derive::ProtoBuf;
|
|
|
|
|
2023-07-14 05:37:13 +00:00
|
|
|
use crate::entities::{InsertedRowPB, RowMetaPB, UpdatedRowPB};
|
2023-04-28 06:08:53 +00:00
|
|
|
|
|
|
|
#[derive(Debug, Default, Clone, ProtoBuf)]
|
2023-05-28 08:14:25 +00:00
|
|
|
pub struct RowsVisibilityChangePB {
|
2023-04-28 06:08:53 +00:00
|
|
|
#[pb(index = 1)]
|
|
|
|
pub view_id: String,
|
|
|
|
|
|
|
|
#[pb(index = 5)]
|
|
|
|
pub visible_rows: Vec<InsertedRowPB>,
|
|
|
|
|
|
|
|
#[pb(index = 6)]
|
2023-04-28 12:47:40 +00:00
|
|
|
pub invisible_rows: Vec<String>,
|
2023-04-28 06:08:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Default, Clone, ProtoBuf)]
|
2023-05-28 08:14:25 +00:00
|
|
|
pub struct RowsChangePB {
|
2023-04-28 06:08:53 +00:00
|
|
|
#[pb(index = 1)]
|
|
|
|
pub inserted_rows: Vec<InsertedRowPB>,
|
|
|
|
|
2023-07-14 05:37:13 +00:00
|
|
|
#[pb(index = 2)]
|
2023-04-28 12:47:40 +00:00
|
|
|
pub deleted_rows: Vec<String>,
|
2023-04-28 06:08:53 +00:00
|
|
|
|
2023-07-14 05:37:13 +00:00
|
|
|
#[pb(index = 3)]
|
2023-04-28 06:08:53 +00:00
|
|
|
pub updated_rows: Vec<UpdatedRowPB>,
|
|
|
|
}
|
|
|
|
|
2023-05-28 08:14:25 +00:00
|
|
|
impl RowsChangePB {
|
2023-07-14 05:37:13 +00:00
|
|
|
pub fn from_insert(inserted_row: InsertedRowPB) -> Self {
|
2023-04-28 06:08:53 +00:00
|
|
|
Self {
|
2023-05-28 08:14:25 +00:00
|
|
|
inserted_rows: vec![inserted_row],
|
2023-04-28 06:08:53 +00:00
|
|
|
..Default::default()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-14 05:37:13 +00:00
|
|
|
pub fn from_delete(deleted_row: String) -> Self {
|
2023-04-28 06:08:53 +00:00
|
|
|
Self {
|
2023-05-28 08:14:25 +00:00
|
|
|
deleted_rows: vec![deleted_row],
|
2023-04-28 06:08:53 +00:00
|
|
|
..Default::default()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-14 05:37:13 +00:00
|
|
|
pub fn from_update(updated_row: UpdatedRowPB) -> Self {
|
2023-04-28 06:08:53 +00:00
|
|
|
Self {
|
2023-05-28 08:14:25 +00:00
|
|
|
updated_rows: vec![updated_row],
|
2023-04-28 06:08:53 +00:00
|
|
|
..Default::default()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-14 05:37:13 +00:00
|
|
|
pub fn from_move(deleted_rows: Vec<String>, inserted_rows: Vec<InsertedRowPB>) -> Self {
|
2023-04-28 06:08:53 +00:00
|
|
|
Self {
|
|
|
|
inserted_rows,
|
|
|
|
deleted_rows,
|
|
|
|
..Default::default()
|
|
|
|
}
|
|
|
|
}
|
2023-11-28 02:43:22 +00:00
|
|
|
|
|
|
|
pub fn is_empty(&self) -> bool {
|
|
|
|
self.deleted_rows.is_empty() && self.inserted_rows.is_empty() && self.updated_rows.is_empty()
|
|
|
|
}
|
2023-04-28 06:08:53 +00:00
|
|
|
}
|
2023-07-14 05:37:13 +00:00
|
|
|
|
|
|
|
#[derive(Debug, Default, ProtoBuf)]
|
|
|
|
pub struct DidFetchRowPB {
|
|
|
|
#[pb(index = 1)]
|
|
|
|
pub row_id: String,
|
|
|
|
|
|
|
|
#[pb(index = 2)]
|
|
|
|
pub height: i32,
|
|
|
|
|
|
|
|
#[pb(index = 3)]
|
|
|
|
pub visibility: bool,
|
|
|
|
|
|
|
|
#[pb(index = 4)]
|
|
|
|
pub created_at: i64,
|
|
|
|
|
|
|
|
#[pb(index = 5)]
|
|
|
|
pub modified_at: i64,
|
|
|
|
|
|
|
|
#[pb(index = 6)]
|
|
|
|
pub meta: RowMetaPB,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<RowDetail> for DidFetchRowPB {
|
|
|
|
fn from(value: RowDetail) -> Self {
|
|
|
|
Self {
|
|
|
|
row_id: value.row.id.to_string(),
|
|
|
|
height: value.row.height,
|
|
|
|
visibility: value.row.visibility,
|
|
|
|
created_at: value.row.created_at,
|
|
|
|
modified_at: value.row.modified_at,
|
2023-08-28 05:28:24 +00:00
|
|
|
meta: RowMetaPB::from(value),
|
2023-07-14 05:37:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|