|
@@ -1,18 +1,20 @@
|
|
-use crate::errors::internal_error;
|
|
|
|
-use crate::server_folder::{FolderOperations, FolderOperationsBuilder};
|
|
|
|
|
|
+use crate::errors::internal_sync_error;
|
|
use crate::util::cal_diff;
|
|
use crate::util::cal_diff;
|
|
use crate::{
|
|
use crate::{
|
|
client_folder::builder::FolderPadBuilder,
|
|
client_folder::builder::FolderPadBuilder,
|
|
- errors::{CollaborateError, CollaborateResult},
|
|
|
|
|
|
+ errors::{SyncError, SyncResult},
|
|
};
|
|
};
|
|
-use flowy_http_model::revision::Revision;
|
|
|
|
-use flowy_http_model::util::md5;
|
|
|
|
-use folder_rev_model::{AppRevision, FolderRevision, TrashRevision, ViewRevision, WorkspaceRevision};
|
|
|
|
|
|
+use folder_model::{AppRevision, FolderRevision, TrashRevision, ViewRevision, WorkspaceRevision};
|
|
|
|
+use lib_infra::util::md5;
|
|
use lib_infra::util::move_vec_element;
|
|
use lib_infra::util::move_vec_element;
|
|
use lib_ot::core::*;
|
|
use lib_ot::core::*;
|
|
|
|
+use revision_model::Revision;
|
|
use serde::Deserialize;
|
|
use serde::Deserialize;
|
|
use std::sync::Arc;
|
|
use std::sync::Arc;
|
|
|
|
|
|
|
|
+pub type FolderOperations = DeltaOperations<EmptyAttributes>;
|
|
|
|
+pub type FolderOperationsBuilder = DeltaOperationBuilder<EmptyAttributes>;
|
|
|
|
+
|
|
#[derive(Debug, Clone, Eq, PartialEq)]
|
|
#[derive(Debug, Clone, Eq, PartialEq)]
|
|
pub struct FolderPad {
|
|
pub struct FolderPad {
|
|
folder_rev: FolderRevision,
|
|
folder_rev: FolderRevision,
|
|
@@ -20,7 +22,7 @@ pub struct FolderPad {
|
|
}
|
|
}
|
|
|
|
|
|
impl FolderPad {
|
|
impl FolderPad {
|
|
- pub fn new(workspaces: Vec<WorkspaceRevision>, trash: Vec<TrashRevision>) -> CollaborateResult<Self> {
|
|
|
|
|
|
+ pub fn new(workspaces: Vec<WorkspaceRevision>, trash: Vec<TrashRevision>) -> SyncResult<Self> {
|
|
let folder_rev = FolderRevision {
|
|
let folder_rev = FolderRevision {
|
|
workspaces: workspaces.into_iter().map(Arc::new).collect(),
|
|
workspaces: workspaces.into_iter().map(Arc::new).collect(),
|
|
trash: trash.into_iter().map(Arc::new).collect(),
|
|
trash: trash.into_iter().map(Arc::new).collect(),
|
|
@@ -28,25 +30,25 @@ impl FolderPad {
|
|
Self::from_folder_rev(folder_rev)
|
|
Self::from_folder_rev(folder_rev)
|
|
}
|
|
}
|
|
|
|
|
|
- pub fn from_folder_rev(folder_rev: FolderRevision) -> CollaborateResult<Self> {
|
|
|
|
|
|
+ pub fn from_folder_rev(folder_rev: FolderRevision) -> SyncResult<Self> {
|
|
let json = serde_json::to_string(&folder_rev)
|
|
let json = serde_json::to_string(&folder_rev)
|
|
- .map_err(|e| CollaborateError::internal().context(format!("Serialize to folder json str failed: {}", e)))?;
|
|
|
|
|
|
+ .map_err(|e| SyncError::internal().context(format!("Serialize to folder json str failed: {}", e)))?;
|
|
let operations = FolderOperationsBuilder::new().insert(&json).build();
|
|
let operations = FolderOperationsBuilder::new().insert(&json).build();
|
|
|
|
|
|
Ok(Self { folder_rev, operations })
|
|
Ok(Self { folder_rev, operations })
|
|
}
|
|
}
|
|
|
|
|
|
- pub fn from_revisions(revisions: Vec<Revision>) -> CollaborateResult<Self> {
|
|
|
|
|
|
+ pub fn from_revisions(revisions: Vec<Revision>) -> SyncResult<Self> {
|
|
FolderPadBuilder::new().build_with_revisions(revisions)
|
|
FolderPadBuilder::new().build_with_revisions(revisions)
|
|
}
|
|
}
|
|
|
|
|
|
- pub fn from_operations(operations: FolderOperations) -> CollaborateResult<Self> {
|
|
|
|
|
|
+ pub fn from_operations(operations: FolderOperations) -> SyncResult<Self> {
|
|
let content = operations.content()?;
|
|
let content = operations.content()?;
|
|
let mut deserializer = serde_json::Deserializer::from_reader(content.as_bytes());
|
|
let mut deserializer = serde_json::Deserializer::from_reader(content.as_bytes());
|
|
|
|
|
|
let folder_rev = FolderRevision::deserialize(&mut deserializer).map_err(|e| {
|
|
let folder_rev = FolderRevision::deserialize(&mut deserializer).map_err(|e| {
|
|
tracing::error!("Deserialize folder from {} failed", content);
|
|
tracing::error!("Deserialize folder from {} failed", content);
|
|
- CollaborateError::internal().context(format!("Deserialize operations to folder failed: {}", e))
|
|
|
|
|
|
+ SyncError::internal().context(format!("Deserialize operations to folder failed: {}", e))
|
|
})?;
|
|
})?;
|
|
|
|
|
|
Ok(Self { folder_rev, operations })
|
|
Ok(Self { folder_rev, operations })
|
|
@@ -56,7 +58,7 @@ impl FolderPad {
|
|
&self.operations
|
|
&self.operations
|
|
}
|
|
}
|
|
|
|
|
|
- pub fn reset_folder(&mut self, operations: FolderOperations) -> CollaborateResult<String> {
|
|
|
|
|
|
+ pub fn reset_folder(&mut self, operations: FolderOperations) -> SyncResult<String> {
|
|
let folder = FolderPad::from_operations(operations)?;
|
|
let folder = FolderPad::from_operations(operations)?;
|
|
self.folder_rev = folder.folder_rev;
|
|
self.folder_rev = folder.folder_rev;
|
|
self.operations = folder.operations;
|
|
self.operations = folder.operations;
|
|
@@ -64,7 +66,7 @@ impl FolderPad {
|
|
Ok(self.folder_md5())
|
|
Ok(self.folder_md5())
|
|
}
|
|
}
|
|
|
|
|
|
- pub fn compose_remote_operations(&mut self, operations: FolderOperations) -> CollaborateResult<String> {
|
|
|
|
|
|
+ pub fn compose_remote_operations(&mut self, operations: FolderOperations) -> SyncResult<String> {
|
|
let composed_operations = self.operations.compose(&operations)?;
|
|
let composed_operations = self.operations.compose(&operations)?;
|
|
self.reset_folder(composed_operations)
|
|
self.reset_folder(composed_operations)
|
|
}
|
|
}
|
|
@@ -74,7 +76,7 @@ impl FolderPad {
|
|
}
|
|
}
|
|
|
|
|
|
#[tracing::instrument(level = "trace", skip(self, workspace_rev), fields(workspace_name=%workspace_rev.name), err)]
|
|
#[tracing::instrument(level = "trace", skip(self, workspace_rev), fields(workspace_name=%workspace_rev.name), err)]
|
|
- pub fn create_workspace(&mut self, workspace_rev: WorkspaceRevision) -> CollaborateResult<Option<FolderChangeset>> {
|
|
|
|
|
|
+ pub fn create_workspace(&mut self, workspace_rev: WorkspaceRevision) -> SyncResult<Option<FolderChangeset>> {
|
|
let workspace = Arc::new(workspace_rev);
|
|
let workspace = Arc::new(workspace_rev);
|
|
if self.folder_rev.workspaces.contains(&workspace) {
|
|
if self.folder_rev.workspaces.contains(&workspace) {
|
|
tracing::warn!("[RootFolder]: Duplicate workspace");
|
|
tracing::warn!("[RootFolder]: Duplicate workspace");
|
|
@@ -92,7 +94,7 @@ impl FolderPad {
|
|
workspace_id: &str,
|
|
workspace_id: &str,
|
|
name: Option<String>,
|
|
name: Option<String>,
|
|
desc: Option<String>,
|
|
desc: Option<String>,
|
|
- ) -> CollaborateResult<Option<FolderChangeset>> {
|
|
|
|
|
|
+ ) -> SyncResult<Option<FolderChangeset>> {
|
|
self.with_workspace(workspace_id, |workspace| {
|
|
self.with_workspace(workspace_id, |workspace| {
|
|
if let Some(name) = name {
|
|
if let Some(name) = name {
|
|
workspace.name = name;
|
|
workspace.name = name;
|
|
@@ -105,7 +107,7 @@ impl FolderPad {
|
|
})
|
|
})
|
|
}
|
|
}
|
|
|
|
|
|
- pub fn read_workspaces(&self, workspace_id: Option<String>) -> CollaborateResult<Vec<WorkspaceRevision>> {
|
|
|
|
|
|
+ pub fn read_workspaces(&self, workspace_id: Option<String>) -> SyncResult<Vec<WorkspaceRevision>> {
|
|
match workspace_id {
|
|
match workspace_id {
|
|
None => {
|
|
None => {
|
|
let workspaces = self
|
|
let workspaces = self
|
|
@@ -125,15 +127,14 @@ impl FolderPad {
|
|
{
|
|
{
|
|
Ok(vec![workspace.as_ref().clone()])
|
|
Ok(vec![workspace.as_ref().clone()])
|
|
} else {
|
|
} else {
|
|
- Err(CollaborateError::record_not_found()
|
|
|
|
- .context(format!("Can't find workspace with id {}", workspace_id)))
|
|
|
|
|
|
+ Err(SyncError::record_not_found().context(format!("Can't find workspace with id {}", workspace_id)))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
#[tracing::instrument(level = "trace", skip(self), err)]
|
|
#[tracing::instrument(level = "trace", skip(self), err)]
|
|
- pub fn delete_workspace(&mut self, workspace_id: &str) -> CollaborateResult<Option<FolderChangeset>> {
|
|
|
|
|
|
+ pub fn delete_workspace(&mut self, workspace_id: &str) -> SyncResult<Option<FolderChangeset>> {
|
|
self.modify_workspaces(|workspaces| {
|
|
self.modify_workspaces(|workspaces| {
|
|
workspaces.retain(|w| w.id != workspace_id);
|
|
workspaces.retain(|w| w.id != workspace_id);
|
|
Ok(Some(()))
|
|
Ok(Some(()))
|
|
@@ -141,7 +142,7 @@ impl FolderPad {
|
|
}
|
|
}
|
|
|
|
|
|
#[tracing::instrument(level = "trace", skip(self), fields(app_name=%app_rev.name), err)]
|
|
#[tracing::instrument(level = "trace", skip(self), fields(app_name=%app_rev.name), err)]
|
|
- pub fn create_app(&mut self, app_rev: AppRevision) -> CollaborateResult<Option<FolderChangeset>> {
|
|
|
|
|
|
+ pub fn create_app(&mut self, app_rev: AppRevision) -> SyncResult<Option<FolderChangeset>> {
|
|
let workspace_id = app_rev.workspace_id.clone();
|
|
let workspace_id = app_rev.workspace_id.clone();
|
|
self.with_workspace(&workspace_id, move |workspace| {
|
|
self.with_workspace(&workspace_id, move |workspace| {
|
|
if workspace.apps.contains(&app_rev) {
|
|
if workspace.apps.contains(&app_rev) {
|
|
@@ -153,13 +154,13 @@ impl FolderPad {
|
|
})
|
|
})
|
|
}
|
|
}
|
|
|
|
|
|
- pub fn read_app(&self, app_id: &str) -> CollaborateResult<AppRevision> {
|
|
|
|
|
|
+ pub fn read_app(&self, app_id: &str) -> SyncResult<AppRevision> {
|
|
for workspace in &self.folder_rev.workspaces {
|
|
for workspace in &self.folder_rev.workspaces {
|
|
if let Some(app) = workspace.apps.iter().find(|app| app.id == app_id) {
|
|
if let Some(app) = workspace.apps.iter().find(|app| app.id == app_id) {
|
|
return Ok(app.clone());
|
|
return Ok(app.clone());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- Err(CollaborateError::record_not_found().context(format!("Can't find app with id {}", app_id)))
|
|
|
|
|
|
+ Err(SyncError::record_not_found().context(format!("Can't find app with id {}", app_id)))
|
|
}
|
|
}
|
|
|
|
|
|
pub fn update_app(
|
|
pub fn update_app(
|
|
@@ -167,7 +168,7 @@ impl FolderPad {
|
|
app_id: &str,
|
|
app_id: &str,
|
|
name: Option<String>,
|
|
name: Option<String>,
|
|
desc: Option<String>,
|
|
desc: Option<String>,
|
|
- ) -> CollaborateResult<Option<FolderChangeset>> {
|
|
|
|
|
|
+ ) -> SyncResult<Option<FolderChangeset>> {
|
|
self.with_app(app_id, move |app| {
|
|
self.with_app(app_id, move |app| {
|
|
if let Some(name) = name {
|
|
if let Some(name) = name {
|
|
app.name = name;
|
|
app.name = name;
|
|
@@ -181,7 +182,7 @@ impl FolderPad {
|
|
}
|
|
}
|
|
|
|
|
|
#[tracing::instrument(level = "trace", skip(self), err)]
|
|
#[tracing::instrument(level = "trace", skip(self), err)]
|
|
- pub fn delete_app(&mut self, app_id: &str) -> CollaborateResult<Option<FolderChangeset>> {
|
|
|
|
|
|
+ pub fn delete_app(&mut self, app_id: &str) -> SyncResult<Option<FolderChangeset>> {
|
|
let app = self.read_app(app_id)?;
|
|
let app = self.read_app(app_id)?;
|
|
self.with_workspace(&app.workspace_id, |workspace| {
|
|
self.with_workspace(&app.workspace_id, |workspace| {
|
|
workspace.apps.retain(|app| app.id != app_id);
|
|
workspace.apps.retain(|app| app.id != app_id);
|
|
@@ -190,10 +191,12 @@ impl FolderPad {
|
|
}
|
|
}
|
|
|
|
|
|
#[tracing::instrument(level = "trace", skip(self), err)]
|
|
#[tracing::instrument(level = "trace", skip(self), err)]
|
|
- pub fn move_app(&mut self, app_id: &str, from: usize, to: usize) -> CollaborateResult<Option<FolderChangeset>> {
|
|
|
|
|
|
+ pub fn move_app(&mut self, app_id: &str, from: usize, to: usize) -> SyncResult<Option<FolderChangeset>> {
|
|
let app = self.read_app(app_id)?;
|
|
let app = self.read_app(app_id)?;
|
|
self.with_workspace(&app.workspace_id, |workspace| {
|
|
self.with_workspace(&app.workspace_id, |workspace| {
|
|
- match move_vec_element(&mut workspace.apps, |app| app.id == app_id, from, to).map_err(internal_error)? {
|
|
|
|
|
|
+ match move_vec_element(&mut workspace.apps, |app| app.id == app_id, from, to)
|
|
|
|
+ .map_err(internal_sync_error)?
|
|
|
|
+ {
|
|
true => Ok(Some(())),
|
|
true => Ok(Some(())),
|
|
false => Ok(None),
|
|
false => Ok(None),
|
|
}
|
|
}
|
|
@@ -201,7 +204,7 @@ impl FolderPad {
|
|
}
|
|
}
|
|
|
|
|
|
#[tracing::instrument(level = "trace", skip(self), fields(view_name=%view_rev.name), err)]
|
|
#[tracing::instrument(level = "trace", skip(self), fields(view_name=%view_rev.name), err)]
|
|
- pub fn create_view(&mut self, view_rev: ViewRevision) -> CollaborateResult<Option<FolderChangeset>> {
|
|
|
|
|
|
+ pub fn create_view(&mut self, view_rev: ViewRevision) -> SyncResult<Option<FolderChangeset>> {
|
|
let app_id = view_rev.app_id.clone();
|
|
let app_id = view_rev.app_id.clone();
|
|
self.with_app(&app_id, move |app| {
|
|
self.with_app(&app_id, move |app| {
|
|
if app.belongings.contains(&view_rev) {
|
|
if app.belongings.contains(&view_rev) {
|
|
@@ -213,7 +216,7 @@ impl FolderPad {
|
|
})
|
|
})
|
|
}
|
|
}
|
|
|
|
|
|
- pub fn read_view(&self, view_id: &str) -> CollaborateResult<ViewRevision> {
|
|
|
|
|
|
+ pub fn read_view(&self, view_id: &str) -> SyncResult<ViewRevision> {
|
|
for workspace in &self.folder_rev.workspaces {
|
|
for workspace in &self.folder_rev.workspaces {
|
|
for app in &(*workspace.apps) {
|
|
for app in &(*workspace.apps) {
|
|
if let Some(view) = app.belongings.iter().find(|b| b.id == view_id) {
|
|
if let Some(view) = app.belongings.iter().find(|b| b.id == view_id) {
|
|
@@ -221,10 +224,10 @@ impl FolderPad {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- Err(CollaborateError::record_not_found().context(format!("Can't find view with id {}", view_id)))
|
|
|
|
|
|
+ Err(SyncError::record_not_found().context(format!("Can't find view with id {}", view_id)))
|
|
}
|
|
}
|
|
|
|
|
|
- pub fn read_views(&self, belong_to_id: &str) -> CollaborateResult<Vec<ViewRevision>> {
|
|
|
|
|
|
+ pub fn read_views(&self, belong_to_id: &str) -> SyncResult<Vec<ViewRevision>> {
|
|
for workspace in &self.folder_rev.workspaces {
|
|
for workspace in &self.folder_rev.workspaces {
|
|
for app in &(*workspace.apps) {
|
|
for app in &(*workspace.apps) {
|
|
if app.id == belong_to_id {
|
|
if app.id == belong_to_id {
|
|
@@ -241,7 +244,7 @@ impl FolderPad {
|
|
name: Option<String>,
|
|
name: Option<String>,
|
|
desc: Option<String>,
|
|
desc: Option<String>,
|
|
modified_time: i64,
|
|
modified_time: i64,
|
|
- ) -> CollaborateResult<Option<FolderChangeset>> {
|
|
|
|
|
|
+ ) -> SyncResult<Option<FolderChangeset>> {
|
|
let view = self.read_view(view_id)?;
|
|
let view = self.read_view(view_id)?;
|
|
self.with_view(&view.app_id, view_id, |view| {
|
|
self.with_view(&view.app_id, view_id, |view| {
|
|
if let Some(name) = name {
|
|
if let Some(name) = name {
|
|
@@ -258,7 +261,7 @@ impl FolderPad {
|
|
}
|
|
}
|
|
|
|
|
|
#[tracing::instrument(level = "trace", skip(self), err)]
|
|
#[tracing::instrument(level = "trace", skip(self), err)]
|
|
- pub fn delete_view(&mut self, app_id: &str, view_id: &str) -> CollaborateResult<Option<FolderChangeset>> {
|
|
|
|
|
|
+ pub fn delete_view(&mut self, app_id: &str, view_id: &str) -> SyncResult<Option<FolderChangeset>> {
|
|
self.with_app(app_id, |app| {
|
|
self.with_app(app_id, |app| {
|
|
app.belongings.retain(|view| view.id != view_id);
|
|
app.belongings.retain(|view| view.id != view_id);
|
|
Ok(Some(()))
|
|
Ok(Some(()))
|
|
@@ -266,17 +269,19 @@ impl FolderPad {
|
|
}
|
|
}
|
|
|
|
|
|
#[tracing::instrument(level = "trace", skip(self), err)]
|
|
#[tracing::instrument(level = "trace", skip(self), err)]
|
|
- pub fn move_view(&mut self, view_id: &str, from: usize, to: usize) -> CollaborateResult<Option<FolderChangeset>> {
|
|
|
|
|
|
+ pub fn move_view(&mut self, view_id: &str, from: usize, to: usize) -> SyncResult<Option<FolderChangeset>> {
|
|
let view = self.read_view(view_id)?;
|
|
let view = self.read_view(view_id)?;
|
|
self.with_app(&view.app_id, |app| {
|
|
self.with_app(&view.app_id, |app| {
|
|
- match move_vec_element(&mut app.belongings, |view| view.id == view_id, from, to).map_err(internal_error)? {
|
|
|
|
|
|
+ match move_vec_element(&mut app.belongings, |view| view.id == view_id, from, to)
|
|
|
|
+ .map_err(internal_sync_error)?
|
|
|
|
+ {
|
|
true => Ok(Some(())),
|
|
true => Ok(Some(())),
|
|
false => Ok(None),
|
|
false => Ok(None),
|
|
}
|
|
}
|
|
})
|
|
})
|
|
}
|
|
}
|
|
|
|
|
|
- pub fn create_trash(&mut self, trash: Vec<TrashRevision>) -> CollaborateResult<Option<FolderChangeset>> {
|
|
|
|
|
|
+ pub fn create_trash(&mut self, trash: Vec<TrashRevision>) -> SyncResult<Option<FolderChangeset>> {
|
|
self.with_trash(|t| {
|
|
self.with_trash(|t| {
|
|
let mut new_trash = trash.into_iter().map(Arc::new).collect::<Vec<Arc<TrashRevision>>>();
|
|
let mut new_trash = trash.into_iter().map(Arc::new).collect::<Vec<Arc<TrashRevision>>>();
|
|
t.append(&mut new_trash);
|
|
t.append(&mut new_trash);
|
|
@@ -285,7 +290,7 @@ impl FolderPad {
|
|
})
|
|
})
|
|
}
|
|
}
|
|
|
|
|
|
- pub fn read_trash(&self, trash_id: Option<String>) -> CollaborateResult<Vec<TrashRevision>> {
|
|
|
|
|
|
+ pub fn read_trash(&self, trash_id: Option<String>) -> SyncResult<Vec<TrashRevision>> {
|
|
match trash_id {
|
|
match trash_id {
|
|
None => Ok(self
|
|
None => Ok(self
|
|
.folder_rev
|
|
.folder_rev
|
|
@@ -300,7 +305,7 @@ impl FolderPad {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- pub fn delete_trash(&mut self, trash_ids: Option<Vec<String>>) -> CollaborateResult<Option<FolderChangeset>> {
|
|
|
|
|
|
+ pub fn delete_trash(&mut self, trash_ids: Option<Vec<String>>) -> SyncResult<Option<FolderChangeset>> {
|
|
match trash_ids {
|
|
match trash_ids {
|
|
None => self.with_trash(|trash| {
|
|
None => self.with_trash(|trash| {
|
|
trash.clear();
|
|
trash.clear();
|
|
@@ -317,21 +322,21 @@ impl FolderPad {
|
|
md5(&self.operations.json_bytes())
|
|
md5(&self.operations.json_bytes())
|
|
}
|
|
}
|
|
|
|
|
|
- pub fn to_json(&self) -> CollaborateResult<String> {
|
|
|
|
|
|
+ pub fn to_json(&self) -> SyncResult<String> {
|
|
make_folder_rev_json_str(&self.folder_rev)
|
|
make_folder_rev_json_str(&self.folder_rev)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-pub fn make_folder_rev_json_str(folder_rev: &FolderRevision) -> CollaborateResult<String> {
|
|
|
|
|
|
+pub fn make_folder_rev_json_str(folder_rev: &FolderRevision) -> SyncResult<String> {
|
|
let json = serde_json::to_string(folder_rev)
|
|
let json = serde_json::to_string(folder_rev)
|
|
- .map_err(|err| internal_error(format!("Serialize folder to json str failed. {:?}", err)))?;
|
|
|
|
|
|
+ .map_err(|err| internal_sync_error(format!("Serialize folder to json str failed. {:?}", err)))?;
|
|
Ok(json)
|
|
Ok(json)
|
|
}
|
|
}
|
|
|
|
|
|
impl FolderPad {
|
|
impl FolderPad {
|
|
- fn modify_workspaces<F>(&mut self, f: F) -> CollaborateResult<Option<FolderChangeset>>
|
|
|
|
|
|
+ fn modify_workspaces<F>(&mut self, f: F) -> SyncResult<Option<FolderChangeset>>
|
|
where
|
|
where
|
|
- F: FnOnce(&mut Vec<Arc<WorkspaceRevision>>) -> CollaborateResult<Option<()>>,
|
|
|
|
|
|
+ F: FnOnce(&mut Vec<Arc<WorkspaceRevision>>) -> SyncResult<Option<()>>,
|
|
{
|
|
{
|
|
let cloned_self = self.clone();
|
|
let cloned_self = self.clone();
|
|
match f(&mut self.folder_rev.workspaces)? {
|
|
match f(&mut self.folder_rev.workspaces)? {
|
|
@@ -353,9 +358,9 @@ impl FolderPad {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- fn with_workspace<F>(&mut self, workspace_id: &str, f: F) -> CollaborateResult<Option<FolderChangeset>>
|
|
|
|
|
|
+ fn with_workspace<F>(&mut self, workspace_id: &str, f: F) -> SyncResult<Option<FolderChangeset>>
|
|
where
|
|
where
|
|
- F: FnOnce(&mut WorkspaceRevision) -> CollaborateResult<Option<()>>,
|
|
|
|
|
|
+ F: FnOnce(&mut WorkspaceRevision) -> SyncResult<Option<()>>,
|
|
{
|
|
{
|
|
self.modify_workspaces(|workspaces| {
|
|
self.modify_workspaces(|workspaces| {
|
|
if let Some(workspace) = workspaces.iter_mut().find(|workspace| workspace_id == workspace.id) {
|
|
if let Some(workspace) = workspaces.iter_mut().find(|workspace| workspace_id == workspace.id) {
|
|
@@ -367,9 +372,9 @@ impl FolderPad {
|
|
})
|
|
})
|
|
}
|
|
}
|
|
|
|
|
|
- fn with_trash<F>(&mut self, f: F) -> CollaborateResult<Option<FolderChangeset>>
|
|
|
|
|
|
+ fn with_trash<F>(&mut self, f: F) -> SyncResult<Option<FolderChangeset>>
|
|
where
|
|
where
|
|
- F: FnOnce(&mut Vec<Arc<TrashRevision>>) -> CollaborateResult<Option<()>>,
|
|
|
|
|
|
+ F: FnOnce(&mut Vec<Arc<TrashRevision>>) -> SyncResult<Option<()>>,
|
|
{
|
|
{
|
|
let cloned_self = self.clone();
|
|
let cloned_self = self.clone();
|
|
match f(&mut self.folder_rev.trash)? {
|
|
match f(&mut self.folder_rev.trash)? {
|
|
@@ -391,9 +396,9 @@ impl FolderPad {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- fn with_app<F>(&mut self, app_id: &str, f: F) -> CollaborateResult<Option<FolderChangeset>>
|
|
|
|
|
|
+ fn with_app<F>(&mut self, app_id: &str, f: F) -> SyncResult<Option<FolderChangeset>>
|
|
where
|
|
where
|
|
- F: FnOnce(&mut AppRevision) -> CollaborateResult<Option<()>>,
|
|
|
|
|
|
+ F: FnOnce(&mut AppRevision) -> SyncResult<Option<()>>,
|
|
{
|
|
{
|
|
let workspace_id = match self
|
|
let workspace_id = match self
|
|
.folder_rev
|
|
.folder_rev
|
|
@@ -414,9 +419,9 @@ impl FolderPad {
|
|
})
|
|
})
|
|
}
|
|
}
|
|
|
|
|
|
- fn with_view<F>(&mut self, belong_to_id: &str, view_id: &str, f: F) -> CollaborateResult<Option<FolderChangeset>>
|
|
|
|
|
|
+ fn with_view<F>(&mut self, belong_to_id: &str, view_id: &str, f: F) -> SyncResult<Option<FolderChangeset>>
|
|
where
|
|
where
|
|
- F: FnOnce(&mut ViewRevision) -> CollaborateResult<Option<()>>,
|
|
|
|
|
|
+ F: FnOnce(&mut ViewRevision) -> SyncResult<Option<()>>,
|
|
{
|
|
{
|
|
self.with_app(belong_to_id, |app| {
|
|
self.with_app(belong_to_id, |app| {
|
|
match app.belongings.iter_mut().find(|view| view_id == view.id) {
|
|
match app.belongings.iter_mut().find(|view| view_id == view.id) {
|
|
@@ -436,7 +441,7 @@ pub fn default_folder_operations() -> FolderOperations {
|
|
.build()
|
|
.build()
|
|
}
|
|
}
|
|
|
|
|
|
-pub fn initial_folder_operations(folder_pad: &FolderPad) -> CollaborateResult<FolderOperations> {
|
|
|
|
|
|
+pub fn initial_folder_operations(folder_pad: &FolderPad) -> SyncResult<FolderOperations> {
|
|
let json = folder_pad.to_json()?;
|
|
let json = folder_pad.to_json()?;
|
|
let operations = FolderOperationsBuilder::new().insert(&json).build();
|
|
let operations = FolderOperationsBuilder::new().insert(&json).build();
|
|
Ok(operations)
|
|
Ok(operations)
|
|
@@ -452,9 +457,9 @@ pub struct FolderChangeset {
|
|
mod tests {
|
|
mod tests {
|
|
#![allow(clippy::all)]
|
|
#![allow(clippy::all)]
|
|
use crate::client_folder::folder_pad::FolderPad;
|
|
use crate::client_folder::folder_pad::FolderPad;
|
|
- use crate::server_folder::{FolderOperations, FolderOperationsBuilder};
|
|
|
|
|
|
+ use crate::client_folder::{FolderOperations, FolderOperationsBuilder};
|
|
use chrono::Utc;
|
|
use chrono::Utc;
|
|
- use folder_rev_model::{AppRevision, FolderRevision, TrashRevision, ViewRevision, WorkspaceRevision};
|
|
|
|
|
|
+ use folder_model::{AppRevision, FolderRevision, TrashRevision, ViewRevision, WorkspaceRevision};
|
|
use lib_ot::core::OperationTransform;
|
|
use lib_ot::core::OperationTransform;
|
|
use serde::Deserialize;
|
|
use serde::Deserialize;
|
|
|
|
|