enhancement(realtime): send metadata update on revision save
Some checks are pending
Docker / build-and-push (backend) (push) Waiting to run
Docker / build-and-push (frontend) (push) Waiting to run
E2E Tests / backend-sqlite (push) Waiting to run
E2E Tests / backend-mariadb (push) Waiting to run
E2E Tests / backend-postgres (push) Waiting to run
E2E Tests / Build test build of frontend (push) Waiting to run
E2E Tests / frontend-cypress (1) (push) Blocked by required conditions
E2E Tests / frontend-cypress (2) (push) Blocked by required conditions
E2E Tests / frontend-cypress (3) (push) Blocked by required conditions
Lint and check format / Lint files and check formatting (push) Waiting to run
REUSE Compliance Check / reuse (push) Waiting to run
Scorecard supply-chain security / Scorecard analysis (push) Waiting to run
Static Analysis / Njsscan code scanning (push) Waiting to run
Static Analysis / CodeQL analysis (javascript) (push) Waiting to run
Run tests & build / Test and build with NodeJS 20 (push) Waiting to run

When the frontend is notified about metadata updates, it refreshes the
data and therefore refreshes information like the timestamp of the last
revision save in the sidebar.
This commit adds such a notification from the backend to all clients on
each revision save, so that the "last saved at" value in the frontend is
correct.

Signed-off-by: Erik Michelson <github@erik.michelson.eu>
This commit is contained in:
Erik Michelson 2024-08-07 22:12:12 +02:00 committed by Philip Molares
parent 9cbd78f622
commit 6684b0f886
3 changed files with 12 additions and 8 deletions

View file

@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file)
* SPDX-FileCopyrightText: 2024 The HedgeDoc developers (see AUTHORS file)
*
* SPDX-License-Identifier: AGPL-3.0-only
*/
@ -49,6 +49,9 @@ export class RealtimeNoteService implements BeforeApplicationShutdown {
realtimeNote.getRealtimeDoc().getCurrentContent(),
realtimeNote.getRealtimeDoc().encodeStateAsUpdate(),
)
.then(() => {
realtimeNote.announceMetadataUpdate();
})
.catch((reason) => this.logger.error(reason));
}
@ -117,7 +120,7 @@ export class RealtimeNoteService implements BeforeApplicationShutdown {
const realtimeNote = this.realtimeNoteStore.find(note.id);
if (!realtimeNote) return;
realtimeNote.announcePermissionChange();
realtimeNote.announceMetadataUpdate();
const allConnections = realtimeNote.getConnections();
await this.updateOrCloseConnection(allConnections, note);
}

View file

@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2023 The HedgeDoc developers (see AUTHORS file)
* SPDX-FileCopyrightText: 2024 The HedgeDoc developers (see AUTHORS file)
*
* SPDX-License-Identifier: AGPL-3.0-only
*/
@ -82,11 +82,11 @@ describe('realtime note', () => {
const sendMessage2Spy = jest.spyOn(client2.getTransporter(), 'sendMessage');
const metadataMessage = { type: MessageType.METADATA_UPDATED };
sut.announcePermissionChange();
sut.announceMetadataUpdate();
expect(sendMessage1Spy).toHaveBeenCalledWith(metadataMessage);
expect(sendMessage2Spy).toHaveBeenCalledWith(metadataMessage);
sut.removeClient(client2);
sut.announcePermissionChange();
sut.announceMetadataUpdate();
expect(sendMessage1Spy).toHaveBeenCalledTimes(2);
expect(sendMessage2Spy).toHaveBeenCalledTimes(1);
});

View file

@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file)
* SPDX-FileCopyrightText: 2024 The HedgeDoc developers (see AUTHORS file)
*
* SPDX-License-Identifier: AGPL-3.0-only
*/
@ -149,9 +149,10 @@ export class RealtimeNote extends EventEmitter2<RealtimeNoteEventMap> {
}
/**
* Announce to all clients that the permissions of the note have been changed.
* Announce to all clients that the metadata of the note have been changed.
* This could for example be a permission change or a revision being saved.
*/
public announcePermissionChange(): void {
public announceMetadataUpdate(): void {
this.sendToAllClients({ type: MessageType.METADATA_UPDATED });
}