Send document versions with cursors
This commit is contained in:
parent
d9ffcfeb5c
commit
bb07602c68
7 changed files with 43 additions and 18 deletions
|
|
@ -1,8 +1,8 @@
|
||||||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
||||||
import type { CursorSpan } from "./CursorSpan";
|
import type { DocumentWithCursors } from "./DocumentWithCursors";
|
||||||
|
|
||||||
export interface ClientCursors {
|
export interface ClientCursors {
|
||||||
userName: string;
|
userName: string;
|
||||||
deviceId: string;
|
deviceId: string;
|
||||||
cursors: Partial<Record<string, CursorSpan[]>>;
|
cursors: DocumentWithCursors[];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
||||||
import type { CursorSpan } from "./CursorSpan";
|
import type { DocumentWithCursors } from "./DocumentWithCursors";
|
||||||
|
|
||||||
export interface CursorPositionFromClient {
|
export interface CursorPositionFromClient {
|
||||||
documentToCursors: Partial<Record<string, CursorSpan[]>>;
|
documentsWithCursors: DocumentWithCursors[];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
||||||
|
import type { CursorSpan } from "./CursorSpan";
|
||||||
|
|
||||||
|
export interface DocumentWithCursors {
|
||||||
|
vault_update_id: number;
|
||||||
|
document_id: string;
|
||||||
|
relative_path: string;
|
||||||
|
cursors: CursorSpan[];
|
||||||
|
}
|
||||||
|
|
@ -9,3 +9,7 @@ cargo test export_bindings
|
||||||
cd -
|
cd -
|
||||||
|
|
||||||
cp -r sync-server/bindings/* frontend/sync-client/src/services/types/
|
cp -r sync-server/bindings/* frontend/sync-client/src/services/types/
|
||||||
|
|
||||||
|
cd frontend
|
||||||
|
npm run lint || npx prettier --write sync-client/src/services/types/*.ts
|
||||||
|
cd -
|
||||||
|
|
|
||||||
|
|
@ -8,12 +8,14 @@ use super::{
|
||||||
websocket::{
|
websocket::{
|
||||||
broadcasts::Broadcasts,
|
broadcasts::Broadcasts,
|
||||||
models::{
|
models::{
|
||||||
ClientCursors, CursorPositionFromServer, CursorSpan, WebSocketServerMessage,
|
ClientCursors, CursorPositionFromServer, WebSocketServerMessage,
|
||||||
WebSocketServerMessageWithOrigin,
|
WebSocketServerMessageWithOrigin,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use crate::config::database_config::DatabaseConfig;
|
use crate::{
|
||||||
|
app_state::websocket::models::DocumentWithCursors, config::database_config::DatabaseConfig,
|
||||||
|
};
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct Cursors {
|
pub struct Cursors {
|
||||||
|
|
@ -36,7 +38,7 @@ impl Cursors {
|
||||||
vault_id: VaultId,
|
vault_id: VaultId,
|
||||||
user_name: String,
|
user_name: String,
|
||||||
device_id: &DeviceId,
|
device_id: &DeviceId,
|
||||||
document_to_cursors: HashMap<String, Vec<CursorSpan>>,
|
document_to_cursors: Vec<DocumentWithCursors>,
|
||||||
) {
|
) {
|
||||||
let mut vault_to_cursors = self.vault_to_cursors.lock().await;
|
let mut vault_to_cursors = self.vault_to_cursors.lock().await;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
use std::collections::HashMap;
|
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use ts_rs::TS;
|
use ts_rs::TS;
|
||||||
|
|
||||||
use crate::app_state::database::models::{DeviceId, DocumentVersionWithoutContent, VaultUpdateId};
|
use crate::app_state::database::models::{
|
||||||
|
DeviceId, DocumentId, DocumentVersionWithoutContent, VaultUpdateId,
|
||||||
|
};
|
||||||
|
|
||||||
#[derive(TS, Deserialize, Clone, Debug)]
|
#[derive(TS, Deserialize, Clone, Debug)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
|
|
@ -15,6 +15,22 @@ pub struct WebSocketHandshake {
|
||||||
pub last_seen_vault_update_id: Option<VaultUpdateId>,
|
pub last_seen_vault_update_id: Option<VaultUpdateId>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(TS, Deserialize, Clone, Debug)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
pub struct CursorPositionFromClient {
|
||||||
|
pub documents_with_cursors: Vec<DocumentWithCursors>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(TS, Serialize, Deserialize, Clone, Debug)]
|
||||||
|
pub struct DocumentWithCursors {
|
||||||
|
#[ts(as = "u32")]
|
||||||
|
pub vault_update_id: VaultUpdateId,
|
||||||
|
|
||||||
|
pub document_id: DocumentId,
|
||||||
|
pub relative_path: String,
|
||||||
|
pub cursors: Vec<CursorSpan>,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(TS, Serialize, Deserialize, Clone, Debug)]
|
#[derive(TS, Serialize, Deserialize, Clone, Debug)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct CursorSpan {
|
pub struct CursorSpan {
|
||||||
|
|
@ -22,18 +38,12 @@ pub struct CursorSpan {
|
||||||
pub end: usize,
|
pub end: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(TS, Deserialize, Clone, Debug)]
|
|
||||||
#[serde(rename_all = "camelCase")]
|
|
||||||
pub struct CursorPositionFromClient {
|
|
||||||
pub document_to_cursors: HashMap<String, Vec<CursorSpan>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(TS, Serialize, Clone, Debug)]
|
#[derive(TS, Serialize, Clone, Debug)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct ClientCursors {
|
pub struct ClientCursors {
|
||||||
pub user_name: String,
|
pub user_name: String,
|
||||||
pub device_id: DeviceId,
|
pub device_id: DeviceId,
|
||||||
pub cursors: HashMap<String, Vec<CursorSpan>>,
|
pub cursors: Vec<DocumentWithCursors>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(TS, Serialize, Clone, Debug)]
|
#[derive(TS, Serialize, Clone, Debug)]
|
||||||
|
|
|
||||||
|
|
@ -133,7 +133,7 @@ async fn websocket(
|
||||||
vault_id_clone.clone(),
|
vault_id_clone.clone(),
|
||||||
authed_handshake.user.name.clone(),
|
authed_handshake.user.name.clone(),
|
||||||
&device_id,
|
&device_id,
|
||||||
cursors.document_to_cursors,
|
cursors.documents_with_cursors,
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue