From 141db79f3a617ac178bcbcc4b867cde76ef6b043 Mon Sep 17 00:00:00 2001 From: Andras Schmelczer Date: Sat, 19 Sep 2026 20:20:50 +0100 Subject: [PATCH] Adjust cursor tracking to new api --- .../src/sync-operations/cursor-tracker.ts | 30 +++++++++++++------ 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/frontend/sync-client/src/sync-operations/cursor-tracker.ts b/frontend/sync-client/src/sync-operations/cursor-tracker.ts index bdd7d9b7..a3d37885 100644 --- a/frontend/sync-client/src/sync-operations/cursor-tracker.ts +++ b/frontend/sync-client/src/sync-operations/cursor-tracker.ts @@ -138,7 +138,7 @@ export class CursorTracker { const record = this.database.getLatestDocumentByRelativePath( doc.relative_path ); - if (record?.metadata?.hash !== hash(readContent)) { + if (record?.metadata?.hash !== (await hash(readContent))) { doc.vault_update_id = null; } } @@ -178,6 +178,15 @@ export class CursorTracker { result.push({ ...clientCursors, + documentsWithCursors: clientCursors.documentsWithCursors.map( + (document) => ({ + ...document, + relative_path: + this.database.getDocumentByDocumentId( + document.document_id + )?.relativePath ?? document.relative_path + }) + ), isOutdated: clientCursors.upToDateness === DocumentUpToDateness.Prior }); @@ -223,8 +232,8 @@ export class CursorTracker { private async getDocumentUpToDateness( document: DocumentWithCursors ): Promise { - const record = this.database.getLatestDocumentByRelativePath( - document.relative_path + const record = this.database.getDocumentByDocumentId( + document.document_id ); if (!record) { @@ -245,13 +254,16 @@ export class CursorTracker { return DocumentUpToDateness.Prior; } - const currentContent = await this.fileOperations.read( - document.relative_path - ); + let currentContent: Uint8Array; + try { + currentContent = await this.fileOperations.read( + record.relativePath + ); + } catch { + return DocumentUpToDateness.Prior; + } - return this.database.getLatestDocumentByRelativePath( - document.relative_path - )?.metadata?.hash === hash(currentContent) + return record.metadata?.hash === (await hash(currentContent)) ? DocumentUpToDateness.UpToDate : DocumentUpToDateness.Prior; }