mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-04-08 06:02:14 +00:00
fix: retrieve read-only state for realtime user status adapter from connection
Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
parent
f012282a41
commit
2f59869e12
4 changed files with 29 additions and 24 deletions
backend/src/realtime/realtime-note
|
@ -68,21 +68,29 @@ describe('websocket connection', () => {
|
|||
expect(sut.getRealtimeNote()).toBe(mockedRealtimeNote);
|
||||
});
|
||||
|
||||
it('returns the correct realtime user status', () => {
|
||||
const realtimeUserStatus = Mock.of<RealtimeUserStatusAdapter>();
|
||||
jest
|
||||
.spyOn(RealtimeUserStatusModule, 'RealtimeUserStatusAdapter')
|
||||
.mockImplementation(() => realtimeUserStatus);
|
||||
it.each([true, false])(
|
||||
'returns the correct realtime user status with acceptEdits %s',
|
||||
(acceptEdits) => {
|
||||
const realtimeUserStatus = Mock.of<RealtimeUserStatusAdapter>();
|
||||
jest
|
||||
.spyOn(RealtimeUserStatusModule, 'RealtimeUserStatusAdapter')
|
||||
.mockImplementation(
|
||||
(username, displayName, connection, acceptCursorUpdateProvider) => {
|
||||
expect(acceptCursorUpdateProvider()).toBe(acceptEdits);
|
||||
return realtimeUserStatus;
|
||||
},
|
||||
);
|
||||
|
||||
const sut = new RealtimeConnection(
|
||||
mockedMessageTransporter,
|
||||
mockedUser,
|
||||
mockedRealtimeNote,
|
||||
true,
|
||||
);
|
||||
const sut = new RealtimeConnection(
|
||||
mockedMessageTransporter,
|
||||
mockedUser,
|
||||
mockedRealtimeNote,
|
||||
acceptEdits,
|
||||
);
|
||||
|
||||
expect(sut.getRealtimeUserStateAdapter()).toBe(realtimeUserStatus);
|
||||
});
|
||||
expect(sut.getRealtimeUserStateAdapter()).toBe(realtimeUserStatus);
|
||||
},
|
||||
);
|
||||
|
||||
it.each([true, false])(
|
||||
'creates a sync adapter with acceptEdits %s',
|
||||
|
@ -91,7 +99,7 @@ describe('websocket connection', () => {
|
|||
jest
|
||||
.spyOn(HedgeDocCommonsModule, 'YDocSyncServerAdapter')
|
||||
.mockImplementation((messageTransporter, doc, acceptEditsProvider) => {
|
||||
expect((acceptEditsProvider as () => boolean)()).toBe(acceptEdits);
|
||||
expect(acceptEditsProvider()).toBe(acceptEdits);
|
||||
return yDocSyncServerAdapter;
|
||||
});
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ export class RealtimeConnection {
|
|||
this.user?.username ?? null,
|
||||
this.getDisplayName(),
|
||||
this,
|
||||
acceptEdits,
|
||||
() => acceptEdits,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ export class RealtimeUserStatusAdapter {
|
|||
username: string | null,
|
||||
displayName: string,
|
||||
private connection: RealtimeConnection,
|
||||
private acceptCursorUpdate: boolean,
|
||||
private acceptCursorUpdateProvider: () => boolean,
|
||||
) {
|
||||
this.realtimeUser = this.createInitialRealtimeUserState(
|
||||
username,
|
||||
|
@ -53,7 +53,7 @@ export class RealtimeUserStatusAdapter {
|
|||
const transporterMessagesListener = connection.getTransporter().on(
|
||||
MessageType.REALTIME_USER_SINGLE_UPDATE,
|
||||
(message: Message<MessageType.REALTIME_USER_SINGLE_UPDATE>) => {
|
||||
if (this.isAcceptingCursorUpdates()) {
|
||||
if (this.acceptCursorUpdateProvider()) {
|
||||
this.realtimeUser.cursor = message.payload;
|
||||
this.sendRealtimeUserStatusUpdateEvent(connection);
|
||||
}
|
||||
|
@ -84,7 +84,7 @@ export class RealtimeUserStatusAdapter {
|
|||
MessageType.REALTIME_USER_SET_ACTIVITY,
|
||||
(message: Message<MessageType.REALTIME_USER_SET_ACTIVITY>) => {
|
||||
if (
|
||||
!this.isAcceptingCursorUpdates() ||
|
||||
!this.acceptCursorUpdateProvider() ||
|
||||
this.realtimeUser.active === message.payload.active
|
||||
) {
|
||||
return;
|
||||
|
@ -116,7 +116,7 @@ export class RealtimeUserStatusAdapter {
|
|||
receivingClient.getRealtimeUserStateAdapter().realtimeUser;
|
||||
const realtimeUsers = this.collectAllConnectionsExcept(receivingClient)
|
||||
.filter((client) =>
|
||||
client.getRealtimeUserStateAdapter().isAcceptingCursorUpdates(),
|
||||
client.getRealtimeUserStateAdapter().acceptCursorUpdateProvider(),
|
||||
)
|
||||
.map((client) => client.getRealtimeUserStateAdapter().realtimeUser)
|
||||
.filter((realtimeUser) => realtimeUser !== null);
|
||||
|
@ -133,10 +133,6 @@ export class RealtimeUserStatusAdapter {
|
|||
});
|
||||
}
|
||||
|
||||
private isAcceptingCursorUpdates(): boolean {
|
||||
return this.acceptCursorUpdate;
|
||||
}
|
||||
|
||||
private collectAllConnectionsExcept(
|
||||
exceptClient: RealtimeConnection,
|
||||
): RealtimeConnection[] {
|
||||
|
|
|
@ -112,7 +112,8 @@ export class MockConnectionBuilder {
|
|||
this.username ?? null,
|
||||
displayName,
|
||||
connection,
|
||||
this.includeRealtimeUserStatus === RealtimeUserState.WITH_READWRITE,
|
||||
() =>
|
||||
this.includeRealtimeUserStatus === RealtimeUserState.WITH_READWRITE,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue