2022-07-01 20:32:11 +08:00
|
|
|
use crate::{entities::folder::FolderDelta, errors::CollaborateError, synchronizer::RevisionSyncObject};
|
2022-02-28 22:38:53 +08:00
|
|
|
use lib_ot::core::{OperationTransformable, PlainTextAttributes, PlainTextDelta};
|
2022-01-21 21:41:24 +08:00
|
|
|
|
|
|
|
pub struct ServerFolder {
|
|
|
|
folder_id: String,
|
|
|
|
delta: FolderDelta,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ServerFolder {
|
|
|
|
pub fn from_delta(folder_id: &str, delta: FolderDelta) -> Self {
|
|
|
|
Self {
|
|
|
|
folder_id: folder_id.to_owned(),
|
|
|
|
delta,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-28 22:38:53 +08:00
|
|
|
impl RevisionSyncObject<PlainTextAttributes> for ServerFolder {
|
2022-01-24 17:35:58 +08:00
|
|
|
fn id(&self) -> &str {
|
|
|
|
&self.folder_id
|
|
|
|
}
|
2022-01-21 21:41:24 +08:00
|
|
|
|
2022-02-28 22:38:53 +08:00
|
|
|
fn compose(&mut self, other: &PlainTextDelta) -> Result<(), CollaborateError> {
|
2022-01-21 21:41:24 +08:00
|
|
|
let new_delta = self.delta.compose(other)?;
|
|
|
|
self.delta = new_delta;
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2022-02-28 22:38:53 +08:00
|
|
|
fn transform(&self, other: &PlainTextDelta) -> Result<(PlainTextDelta, PlainTextDelta), CollaborateError> {
|
2022-01-21 21:41:24 +08:00
|
|
|
let value = self.delta.transform(other)?;
|
|
|
|
Ok(value)
|
|
|
|
}
|
|
|
|
|
2022-01-24 17:35:58 +08:00
|
|
|
fn to_json(&self) -> String {
|
2022-03-05 22:30:42 +08:00
|
|
|
self.delta.to_delta_str()
|
2022-01-24 17:35:58 +08:00
|
|
|
}
|
2022-01-21 21:41:24 +08:00
|
|
|
|
2022-02-28 22:38:53 +08:00
|
|
|
fn set_delta(&mut self, new_delta: PlainTextDelta) {
|
2022-01-24 17:35:58 +08:00
|
|
|
self.delta = new_delta;
|
|
|
|
}
|
2022-01-21 21:41:24 +08:00
|
|
|
}
|