Send document versions with cursors

This commit is contained in:
Andras Schmelczer 2025-08-10 14:55:40 +01:00
parent d9ffcfeb5c
commit bb07602c68
No known key found for this signature in database
GPG key ID: FC8F2C3D3D1A718C
7 changed files with 43 additions and 18 deletions

View file

@ -1,8 +1,8 @@
// 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 {
userName: string;
deviceId: string;
cursors: Partial<Record<string, CursorSpan[]>>;
cursors: DocumentWithCursors[];
}

View file

@ -1,6 +1,6 @@
// 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 {
documentToCursors: Partial<Record<string, CursorSpan[]>>;
documentsWithCursors: DocumentWithCursors[];
}

View file

@ -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[];
}

View file

@ -9,3 +9,7 @@ cargo test export_bindings
cd -
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 -

View file

@ -8,12 +8,14 @@ use super::{
websocket::{
broadcasts::Broadcasts,
models::{
ClientCursors, CursorPositionFromServer, CursorSpan, WebSocketServerMessage,
ClientCursors, CursorPositionFromServer, WebSocketServerMessage,
WebSocketServerMessageWithOrigin,
},
},
};
use crate::config::database_config::DatabaseConfig;
use crate::{
app_state::websocket::models::DocumentWithCursors, config::database_config::DatabaseConfig,
};
#[derive(Clone, Debug)]
pub struct Cursors {
@ -36,7 +38,7 @@ impl Cursors {
vault_id: VaultId,
user_name: String,
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;

View file

@ -1,9 +1,9 @@
use std::collections::HashMap;
use serde::{Deserialize, Serialize};
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)]
#[serde(rename_all = "camelCase")]
@ -15,6 +15,22 @@ pub struct WebSocketHandshake {
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)]
#[serde(rename_all = "camelCase")]
pub struct CursorSpan {
@ -22,18 +38,12 @@ pub struct CursorSpan {
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)]
#[serde(rename_all = "camelCase")]
pub struct ClientCursors {
pub user_name: String,
pub device_id: DeviceId,
pub cursors: HashMap<String, Vec<CursorSpan>>,
pub cursors: Vec<DocumentWithCursors>,
}
#[derive(TS, Serialize, Clone, Debug)]

View file

@ -133,7 +133,7 @@ async fn websocket(
vault_id_clone.clone(),
authed_handshake.user.name.clone(),
&device_id,
cursors.document_to_cursors,
cursors.documents_with_cursors,
)
.await;
}