mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
remove some passthrough funcs
This commit is contained in:
parent
f17f0dd6cf
commit
282ed9067a
@ -113,7 +113,7 @@ pub fn create(core: Arc<CoreContext>) -> Module {
|
||||
.event(WorkspaceEvent::DuplicateView, duplicate_view_handler)
|
||||
.event(WorkspaceEvent::OpenView, open_view_handler)
|
||||
.event(WorkspaceEvent::CloseView, close_view_handler)
|
||||
.event(WorkspaceEvent::ApplyDocDelta, apply_doc_delta_handler);
|
||||
.event(WorkspaceEvent::ApplyDocDelta, document_delta_handler);
|
||||
|
||||
module = module
|
||||
.event(WorkspaceEvent::ReadTrash, read_trash_handler)
|
||||
|
@ -59,7 +59,9 @@ impl ViewController {
|
||||
#[tracing::instrument(level = "debug", skip(self, params), fields(name = %params.name), err)]
|
||||
pub(crate) async fn create_view_from_params(&self, params: CreateViewParams) -> Result<View, FlowyError> {
|
||||
let view = self.create_view_on_server(params).await?;
|
||||
self.create_view_on_local(view).await
|
||||
let view = self.create_view_on_local(view).await?;
|
||||
|
||||
Ok(view)
|
||||
}
|
||||
|
||||
pub(crate) async fn create_view_on_local(&self, view: View) -> Result<View, FlowyError> {
|
||||
@ -113,15 +115,16 @@ impl ViewController {
|
||||
#[tracing::instrument(level = "debug", skip(self, params), fields(doc_id = %params.doc_id), err)]
|
||||
pub(crate) async fn open_view(&self, params: DocIdentifier) -> Result<DocumentDelta, FlowyError> {
|
||||
let doc_id = params.doc_id.clone();
|
||||
let edit_context = self.document_ctx.open(params).await?;
|
||||
let db_pool = self.database.db_pool()?;
|
||||
let editor = self.document_ctx.controller.open(params, db_pool).await?;
|
||||
|
||||
KV::set_str(LATEST_VIEW_ID, doc_id);
|
||||
Ok(edit_context.delta().await.map_err(internal_error)?)
|
||||
Ok(editor.delta().await.map_err(internal_error)?)
|
||||
}
|
||||
|
||||
#[tracing::instrument(level = "debug", skip(self,params), fields(doc_id = %params.doc_id), err)]
|
||||
pub(crate) async fn close_view(&self, params: DocIdentifier) -> Result<(), FlowyError> {
|
||||
let _ = self.document_ctx.doc_ctrl.close(¶ms.doc_id)?;
|
||||
let _ = self.document_ctx.controller.close(¶ms.doc_id)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -132,17 +135,19 @@ impl ViewController {
|
||||
let _ = KV::remove(LATEST_VIEW_ID);
|
||||
}
|
||||
}
|
||||
let _ = self.document_ctx.doc_ctrl.close(¶ms.doc_id)?;
|
||||
let _ = self.document_ctx.controller.close(¶ms.doc_id)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(level = "debug", skip(self, params), fields(doc_id = %params.doc_id), err)]
|
||||
pub(crate) async fn duplicate_view(&self, params: DocIdentifier) -> Result<(), FlowyError> {
|
||||
let view: View = ViewTableSql::read_view(¶ms.doc_id, &*self.database.db_connection()?)?.into();
|
||||
let delta_data = self
|
||||
let editor = self
|
||||
.document_ctx
|
||||
.read_document_data(params, self.database.db_pool()?)
|
||||
.controller
|
||||
.open(params, self.database.db_pool()?)
|
||||
.await?;
|
||||
let delta_data = editor.delta().await?.text;
|
||||
|
||||
let duplicate_params = CreateViewParams {
|
||||
belong_to_id: view.belong_to_id.clone(),
|
||||
@ -150,7 +155,7 @@ impl ViewController {
|
||||
desc: view.desc.clone(),
|
||||
thumbnail: "".to_owned(),
|
||||
view_type: view.view_type.clone(),
|
||||
view_data: delta_data.text,
|
||||
view_data: delta_data,
|
||||
view_id: uuid_string(),
|
||||
};
|
||||
|
||||
@ -161,13 +166,15 @@ impl ViewController {
|
||||
#[tracing::instrument(level = "debug", skip(self, params), err)]
|
||||
pub(crate) async fn export_doc(&self, params: ExportParams) -> Result<ExportData, FlowyError> {
|
||||
let doc_identifier: DocIdentifier = params.doc_id.into();
|
||||
let doc = self
|
||||
let editor = self
|
||||
.document_ctx
|
||||
.read_document_data(doc_identifier, self.database.db_pool()?)
|
||||
.controller
|
||||
.open(doc_identifier, self.database.db_pool()?)
|
||||
.await?;
|
||||
let data = editor.delta().await?.text;
|
||||
|
||||
Ok(ExportData {
|
||||
data: doc.text,
|
||||
data,
|
||||
export_type: params.export_type,
|
||||
})
|
||||
}
|
||||
@ -202,9 +209,9 @@ impl ViewController {
|
||||
Ok(updated_view)
|
||||
}
|
||||
|
||||
pub(crate) async fn apply_doc_delta(&self, params: DocumentDelta) -> Result<DocumentDelta, FlowyError> {
|
||||
pub(crate) async fn receive_document_delta(&self, params: DocumentDelta) -> Result<DocumentDelta, FlowyError> {
|
||||
let db_pool = self.document_ctx.user.db_pool()?;
|
||||
let doc = self.document_ctx.doc_ctrl.apply_local_delta(params, db_pool).await?;
|
||||
let doc = self.document_ctx.controller.apply_local_delta(params, db_pool).await?;
|
||||
Ok(doc)
|
||||
}
|
||||
|
||||
@ -340,7 +347,7 @@ async fn handle_trash_event(
|
||||
for identifier in identifiers.items {
|
||||
let view_table = ViewTableSql::read_view(&identifier.id, conn)?;
|
||||
let _ = ViewTableSql::delete_view(&identifier.id, conn)?;
|
||||
let _ = context.doc_ctrl.delete(identifier.id.clone().into())?;
|
||||
let _ = context.controller.delete(identifier.id.clone().into())?;
|
||||
notify_ids.insert(view_table.belong_to_id);
|
||||
}
|
||||
|
||||
@ -374,7 +381,7 @@ fn notify_dart(view_table: ViewTable, notification: WorkspaceNotification) {
|
||||
send_dart_notification(&view.id, notification).payload(view).send();
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(belong_to_id, trash_can, conn), fields(view_count), err)]
|
||||
#[tracing::instrument(skip(belong_to_id, trash_controller, conn), fields(view_count), err)]
|
||||
fn notify_views_changed(
|
||||
belong_to_id: &str,
|
||||
trash_controller: Arc<TrashController>,
|
||||
|
@ -51,12 +51,11 @@ pub(crate) async fn update_view_handler(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) async fn apply_doc_delta_handler(
|
||||
pub(crate) async fn document_delta_handler(
|
||||
data: Data<DocumentDelta>,
|
||||
controller: Unit<Arc<ViewController>>,
|
||||
) -> DataResult<DocumentDelta, FlowyError> {
|
||||
// let params: DocumentDelta = data.into_inner().try_into()?;
|
||||
let doc = controller.apply_doc_delta(data.into_inner()).await?;
|
||||
let doc = controller.receive_document_delta(data.into_inner()).await?;
|
||||
data_result(doc)
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,7 @@ pub trait DocumentUser: Send + Sync {
|
||||
}
|
||||
|
||||
pub struct DocumentContext {
|
||||
pub doc_ctrl: Arc<DocController>,
|
||||
pub controller: Arc<DocController>,
|
||||
pub user: Arc<dyn DocumentUser>,
|
||||
}
|
||||
|
||||
@ -32,26 +32,14 @@ impl DocumentContext {
|
||||
) -> DocumentContext {
|
||||
let server = construct_doc_server(server_config);
|
||||
let doc_ctrl = Arc::new(DocController::new(server, user.clone(), ws_receivers, ws_sender));
|
||||
Self { doc_ctrl, user }
|
||||
Self {
|
||||
controller: doc_ctrl,
|
||||
user,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn init(&self) -> Result<(), FlowyError> {
|
||||
let _ = self.doc_ctrl.init()?;
|
||||
let _ = self.controller.init()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn open(&self, params: DocIdentifier) -> Result<Arc<ClientDocEditor>, FlowyError> {
|
||||
let edit_context = self.doc_ctrl.open(params, self.user.db_pool()?).await?;
|
||||
Ok(edit_context)
|
||||
}
|
||||
|
||||
pub async fn read_document_data(
|
||||
&self,
|
||||
params: DocIdentifier,
|
||||
pool: Arc<ConnectionPool>,
|
||||
) -> Result<DocumentDelta, FlowyError> {
|
||||
let edit_context = self.doc_ctrl.open(params, pool).await?;
|
||||
let delta = edit_context.delta().await?;
|
||||
Ok(delta)
|
||||
}
|
||||
}
|
||||
|
@ -58,18 +58,16 @@ impl DocController {
|
||||
pool: Arc<ConnectionPool>,
|
||||
) -> Result<Arc<ClientDocEditor>, FlowyError> {
|
||||
if !self.open_cache.contains(¶ms.doc_id) {
|
||||
let edit_ctx = self.make_editor(¶ms.doc_id, pool.clone()).await?;
|
||||
return Ok(edit_ctx);
|
||||
let editor = self.make_editor(¶ms.doc_id, pool.clone()).await?;
|
||||
return Ok(editor);
|
||||
}
|
||||
|
||||
let edit_doc_ctx = self.open_cache.get(¶ms.doc_id)?;
|
||||
Ok(edit_doc_ctx)
|
||||
self.open_cache.get(¶ms.doc_id)
|
||||
}
|
||||
|
||||
pub fn close(&self, doc_id: &str) -> Result<(), FlowyError> {
|
||||
tracing::debug!("Close document {}", doc_id);
|
||||
self.open_cache.remove(doc_id);
|
||||
self.ws_receivers.remove_receiver(doc_id);
|
||||
self.ws_receivers.remove(doc_id);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -77,7 +75,7 @@ impl DocController {
|
||||
pub fn delete(&self, params: DocIdentifier) -> Result<(), FlowyError> {
|
||||
let doc_id = ¶ms.doc_id;
|
||||
self.open_cache.remove(doc_id);
|
||||
self.ws_receivers.remove_receiver(doc_id);
|
||||
self.ws_receivers.remove(doc_id);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -112,7 +110,7 @@ impl DocController {
|
||||
server: self.server.clone(),
|
||||
});
|
||||
let doc_editor = ClientDocEditor::new(doc_id, user, pool, rev_manager, self.ws_sender.clone(), server).await?;
|
||||
self.ws_receivers.register_receiver(doc_id, doc_editor.ws_handler());
|
||||
self.ws_receivers.add(doc_id, doc_editor.ws_handler());
|
||||
self.open_cache.insert(&doc_id, &doc_editor);
|
||||
Ok(doc_editor)
|
||||
}
|
||||
|
@ -31,14 +31,14 @@ impl std::default::Default for DocumentWSReceivers {
|
||||
impl DocumentWSReceivers {
|
||||
pub fn new() -> Self { DocumentWSReceivers::default() }
|
||||
|
||||
pub(crate) fn register_receiver(&self, doc_id: &str, receiver: Arc<dyn DocumentWSReceiver>) {
|
||||
pub(crate) fn add(&self, doc_id: &str, receiver: Arc<dyn DocumentWSReceiver>) {
|
||||
if self.receivers.contains_key(doc_id) {
|
||||
log::error!("Duplicate handler registered for {:?}", doc_id);
|
||||
}
|
||||
self.receivers.insert(doc_id.to_string(), receiver);
|
||||
}
|
||||
|
||||
pub(crate) fn remove_receiver(&self, id: &str) { self.receivers.remove(id); }
|
||||
pub(crate) fn remove(&self, id: &str) { self.receivers.remove(id); }
|
||||
|
||||
pub fn did_receive_data(&self, data: Bytes) {
|
||||
let data: DocumentServerWSData = data.try_into().unwrap();
|
||||
|
@ -31,7 +31,9 @@ impl EditorTest {
|
||||
let _ = sdk.init_user().await;
|
||||
let test = ViewTest::new(&sdk).await;
|
||||
let doc_identifier: DocIdentifier = test.view.id.clone().into();
|
||||
let editor = sdk.document_ctx.open(doc_identifier).await.unwrap();
|
||||
|
||||
let db_pool = sdk.user_session.db_pool().unwrap();
|
||||
let editor = sdk.document_ctx.controller.open(doc_identifier, db_pool).await.unwrap();
|
||||
Self { sdk, editor }
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user