diff --git a/backend/src/service/user/user_default.rs b/backend/src/service/user/user_default.rs index 527e2faf12..ad98a78822 100644 --- a/backend/src/service/user/user_default.rs +++ b/backend/src/service/user/user_default.rs @@ -7,11 +7,9 @@ use crate::{ sqlx_ext::{map_sqlx_error, DBTransaction}, }; +use flowy_document::services::doc::doc_initial_string; use flowy_net::errors::ServerError; -use flowy_workspace::{ - entities::view::DOC_DEFAULT_DATA, - protobuf::{App, CreateViewParams, View, ViewType, Workspace}, -}; +use flowy_workspace::protobuf::{App, CreateViewParams, View, ViewType, Workspace}; pub async fn create_default_workspace( transaction: &mut DBTransaction<'_>, @@ -63,7 +61,7 @@ async fn create_default_view(transaction: &mut DBTransaction<'_>, app: &App) -> desc: "View created by AppFlowy".to_string(), thumbnail: "123.png".to_string(), view_type: ViewType::Doc, - data: DOC_DEFAULT_DATA.to_string(), + data: doc_initial_string(), unknown_fields: Default::default(), cached_size: Default::default(), }; diff --git a/rust-lib/flowy-document/src/services/doc/document/document.rs b/rust-lib/flowy-document/src/services/doc/document/document.rs index 5033d702e4..f55a4817a7 100644 --- a/rust-lib/flowy-document/src/services/doc/document/document.rs +++ b/rust-lib/flowy-document/src/services/doc/document/document.rs @@ -15,9 +15,19 @@ impl CustomDocument for PlainDoc { fn init_delta() -> Delta { Delta::new() } } +#[allow(dead_code)] +#[inline] +pub fn doc_initial_delta() -> Delta { DeltaBuilder::new().insert("\n").build() } +#[allow(dead_code)] +#[inline] +pub fn doc_initial_string() -> String { doc_initial_delta().to_json() } +#[allow(dead_code)] +#[inline] +pub fn doc_initial_bytes() -> Vec { doc_initial_string().into_bytes() } + pub struct FlowyDoc(); impl CustomDocument for FlowyDoc { - fn init_delta() -> Delta { DeltaBuilder::new().insert("\n").build() } + fn init_delta() -> Delta { doc_initial_delta() } } pub struct Document { diff --git a/rust-lib/flowy-document/src/services/server/server_api_mock.rs b/rust-lib/flowy-document/src/services/server/server_api_mock.rs index e76a51d888..58c57b1732 100644 --- a/rust-lib/flowy-document/src/services/server/server_api_mock.rs +++ b/rust-lib/flowy-document/src/services/server/server_api_mock.rs @@ -1,9 +1,10 @@ use crate::{ entities::doc::{CreateDocParams, Doc, DocIdentifier, UpdateDocParams}, errors::DocError, - services::server::DocumentServerAPI, + services::{doc::doc_initial_string, server::DocumentServerAPI}, }; use flowy_infra::future::ResultFuture; + pub struct DocServerMock {} impl DocumentServerAPI for DocServerMock { @@ -11,8 +12,14 @@ impl DocumentServerAPI for DocServerMock { ResultFuture::new(async { Ok(()) }) } - fn read_doc(&self, _token: &str, _params: DocIdentifier) -> ResultFuture, DocError> { - ResultFuture::new(async { Ok(None) }) + fn read_doc(&self, _token: &str, params: DocIdentifier) -> ResultFuture, DocError> { + let doc = Doc { + id: params.doc_id, + data: doc_initial_string(), + rev_id: 0, + base_rev_id: 0, + }; + ResultFuture::new(async { Ok(Some(doc)) }) } fn update_doc(&self, _token: &str, _params: UpdateDocParams) -> ResultFuture<(), DocError> { diff --git a/rust-lib/flowy-workspace/src/entities/view/view_create.rs b/rust-lib/flowy-workspace/src/entities/view/view_create.rs index 406065924e..dfa6d6fec8 100644 --- a/rust-lib/flowy-workspace/src/entities/view/view_create.rs +++ b/rust-lib/flowy-workspace/src/entities/view/view_create.rs @@ -8,6 +8,7 @@ use crate::{ impl_def_and_def_mut, }; use flowy_derive::{ProtoBuf, ProtoBuf_Enum}; +use flowy_document::services::doc::doc_initial_string; use std::convert::TryInto; #[derive(PartialEq, Debug, ProtoBuf_Enum, Clone)] @@ -72,10 +73,6 @@ pub struct CreateViewParams { pub data: String, } -pub const DOC_DEFAULT_DATA: &str = "[{\"insert\":\"\\n\"}]"; -#[allow(dead_code)] -pub fn default_delta() -> Vec { DOC_DEFAULT_DATA.as_bytes().to_vec() } - impl CreateViewParams { pub fn new(belong_to_id: String, name: String, desc: String, view_type: ViewType, thumbnail: String) -> Self { Self { @@ -84,7 +81,7 @@ impl CreateViewParams { desc, thumbnail, view_type, - data: DOC_DEFAULT_DATA.to_string(), + data: doc_initial_string(), } } }