mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-16 09:36:17 +08:00
feat: update yrs doc using ipc from yjs doc
This commit is contained in:
@@ -1,14 +1,17 @@
|
||||
pub mod blob;
|
||||
pub mod workspace;
|
||||
pub mod document;
|
||||
|
||||
use blob::*;
|
||||
use workspace::*;
|
||||
use document::*;
|
||||
|
||||
pub fn invoke_handler() -> impl Fn(tauri::Invoke) + Send + Sync + 'static {
|
||||
tauri::generate_handler![
|
||||
update_y_document,
|
||||
create_workspace,
|
||||
update_workspace,
|
||||
get_doc,
|
||||
put_blob,
|
||||
get_blob
|
||||
]
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
use ipc_types::document::{GetDocumentParameter, GetDocumentResponse, YDocumentUpdate};
|
||||
use jwst::DocStorage;
|
||||
use yrs::StateVector;
|
||||
|
||||
use crate::state::AppState;
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn get_doc<'s>(
|
||||
state: tauri::State<'s, AppState>,
|
||||
parameters: GetDocumentParameter,
|
||||
) -> Result<GetDocumentResponse, String> {
|
||||
// TODO: check user permission
|
||||
|
||||
if let Some(doc) = &state
|
||||
.0
|
||||
.lock()
|
||||
.await
|
||||
.doc_storage
|
||||
.get(parameters.id)
|
||||
.await
|
||||
.ok()
|
||||
{
|
||||
Ok(GetDocumentResponse {
|
||||
update: doc.encode_state_as_update_v1(&StateVector::default()),
|
||||
})
|
||||
} else {
|
||||
Err(format!(
|
||||
"Failed to get yDoc from {}",
|
||||
parameters.id.to_string()
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn update_y_document<'s>(
|
||||
state: tauri::State<'s, AppState>,
|
||||
parameters: YDocumentUpdate,
|
||||
) -> Result<bool, String> {
|
||||
if let Some(doc) = &state
|
||||
.0
|
||||
.lock()
|
||||
.await
|
||||
.doc_storage
|
||||
.write_update(parameters.id, ¶meters.update)
|
||||
.await
|
||||
.ok()
|
||||
{
|
||||
Ok(true)
|
||||
} else {
|
||||
Err(format!(
|
||||
"Failed to update yDoc to {}",
|
||||
parameters.id.to_string()
|
||||
))
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,4 @@
|
||||
use ipc_types::{
|
||||
document::YDocumentUpdate,
|
||||
workspace::{CreateWorkspace, CreateWorkspaceResult, UpdateWorkspace},
|
||||
};
|
||||
use ipc_types::workspace::{CreateWorkspace, CreateWorkspaceResult, UpdateWorkspace};
|
||||
use jwst::{DocStorage, Workspace as OctoBaseWorkspace};
|
||||
use lib0::any::Any;
|
||||
|
||||
@@ -24,8 +21,10 @@ pub async fn create_workspace<'s>(
|
||||
let workspace_doc = OctoBaseWorkspace::new(new_workspace.id.to_string());
|
||||
|
||||
workspace_doc.with_trx(|mut workspace_doc_transaction| {
|
||||
workspace_doc_transaction
|
||||
.set_metadata("name", Any::String(parameters.name.clone().into_boxed_str()));
|
||||
workspace_doc_transaction.set_metadata(
|
||||
"name",
|
||||
Any::String(parameters.name.clone().into_boxed_str()),
|
||||
);
|
||||
});
|
||||
if let Err(error_message) = &state
|
||||
.0
|
||||
@@ -52,11 +51,7 @@ pub async fn update_workspace<'s>(
|
||||
state: tauri::State<'s, AppState>,
|
||||
parameters: UpdateWorkspace,
|
||||
) -> Result<bool, String> {
|
||||
// TODO: check user permission
|
||||
// No thing to update now. The avatar is update in YDoc using websocket or yrs.update
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn update_y_document(parameters: YDocumentUpdate) -> Result<bool, String> {
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user