From eebbb79d081c62ce2fe87f6a961314faeabaaec5 Mon Sep 17 00:00:00 2001 From: Tilman Vatteroth Date: Mon, 8 May 2023 18:06:54 +0200 Subject: [PATCH] fix: retrieve read-only state for y-doc-sync-server-adapter from connection Signed-off-by: Tilman Vatteroth --- backend/src/realtime/realtime-note/realtime-connection.ts | 2 +- commons/src/y-doc-sync/y-doc-sync-adapter.spec.ts | 4 ++-- commons/src/y-doc-sync/y-doc-sync-server-adapter.ts | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/backend/src/realtime/realtime-note/realtime-connection.ts b/backend/src/realtime/realtime-note/realtime-connection.ts index f0cf9b100..9c2e5fac8 100644 --- a/backend/src/realtime/realtime-note/realtime-connection.ts +++ b/backend/src/realtime/realtime-note/realtime-connection.ts @@ -46,7 +46,7 @@ export class RealtimeConnection { this.yDocSyncAdapter = new YDocSyncServerAdapter( this.transporter, realtimeNote.getRealtimeDoc(), - acceptEdits, + () => acceptEdits, ); this.realtimeUserStateAdapter = new RealtimeUserStatusAdapter( this.user?.username ?? null, diff --git a/commons/src/y-doc-sync/y-doc-sync-adapter.spec.ts b/commons/src/y-doc-sync/y-doc-sync-adapter.spec.ts index 683fb3929..676bbf51d 100644 --- a/commons/src/y-doc-sync/y-doc-sync-adapter.spec.ts +++ b/commons/src/y-doc-sync/y-doc-sync-adapter.spec.ts @@ -105,13 +105,13 @@ describe('message transporter', () => { const yDocSyncAdapterServerTo1 = new YDocSyncServerAdapter( transporterServerTo1, docServer, - true + () => true ) const yDocSyncAdapterServerTo2 = new YDocSyncServerAdapter( transporterServerTo2, docServer, - true + () => true ) const waitForClient1Sync = new Promise((resolve) => { diff --git a/commons/src/y-doc-sync/y-doc-sync-server-adapter.ts b/commons/src/y-doc-sync/y-doc-sync-server-adapter.ts index 24f72dfb9..eac4ff08b 100644 --- a/commons/src/y-doc-sync/y-doc-sync-server-adapter.ts +++ b/commons/src/y-doc-sync/y-doc-sync-server-adapter.ts @@ -11,14 +11,14 @@ export class YDocSyncServerAdapter extends YDocSyncAdapter { constructor( readonly messageTransporter: MessageTransporter, readonly doc: RealtimeDoc, - readonly acceptEdits: boolean + private readonly acceptEditsProvider: () => boolean ) { super(messageTransporter, doc) this.markAsSynced() } protected applyIncomingUpdatePayload(update: number[]): void { - if (!this.acceptEdits) { + if (!this.acceptEditsProvider()) { return } super.applyIncomingUpdatePayload(update)