From 8066b9ffbe4b13c92bb2cb67ca559843a0052696 Mon Sep 17 00:00:00 2001 From: Michael Weimann Date: Wed, 19 Oct 2022 16:22:07 +0200 Subject: [PATCH] Prevent starting another voice broadcast (#9457) --- .../utils/startNewVoiceBroadcastRecording.tsx | 5 ++++ ...artNewVoiceBroadcastRecording-test.ts.snap | 25 ++++++++++++++++++- .../startNewVoiceBroadcastRecording-test.ts | 21 +++++++++++++++- 3 files changed, 49 insertions(+), 2 deletions(-) diff --git a/src/voice-broadcast/utils/startNewVoiceBroadcastRecording.tsx b/src/voice-broadcast/utils/startNewVoiceBroadcastRecording.tsx index cff195c668..1084d6d2f3 100644 --- a/src/voice-broadcast/utils/startNewVoiceBroadcastRecording.tsx +++ b/src/voice-broadcast/utils/startNewVoiceBroadcastRecording.tsx @@ -113,6 +113,11 @@ export const startNewVoiceBroadcastRecording = async ( client: MatrixClient, recordingsStore: VoiceBroadcastRecordingsStore, ): Promise => { + if (recordingsStore.getCurrent()) { + showAlreadyRecordingDialog(); + return null; + } + const currentUserId = client.getUserId(); if (!room.currentState.maySendStateEvent(VoiceBroadcastInfoEventType, currentUserId)) { diff --git a/test/voice-broadcast/utils/__snapshots__/startNewVoiceBroadcastRecording-test.ts.snap b/test/voice-broadcast/utils/__snapshots__/startNewVoiceBroadcastRecording-test.ts.snap index c38673e3b6..7ea5b24355 100644 --- a/test/voice-broadcast/utils/__snapshots__/startNewVoiceBroadcastRecording-test.ts.snap +++ b/test/voice-broadcast/utils/__snapshots__/startNewVoiceBroadcastRecording-test.ts.snap @@ -23,7 +23,30 @@ exports[`startNewVoiceBroadcastRecording when the current user is allowed to sen } `; -exports[`startNewVoiceBroadcastRecording when the current user is allowed to send voice broadcast info state events when there already is a live broadcast of the current user should show an info dialog 1`] = ` +exports[`startNewVoiceBroadcastRecording when the current user is allowed to send voice broadcast info state events when there already is a live broadcast of the current user in the room should show an info dialog 1`] = ` +[MockFunction] { + "calls": Array [ + Array [ + [Function], + Object { + "description":

+ You are already recording a voice broadcast. Please end your current voice broadcast to start a new one. +

, + "hasCloseButton": true, + "title": "Can't start a new voice broadcast", + }, + ], + ], + "results": Array [ + Object { + "type": "return", + "value": undefined, + }, + ], +} +`; + +exports[`startNewVoiceBroadcastRecording when the current user is allowed to send voice broadcast info state events when there is already a current voice broadcast should show an info dialog 1`] = ` [MockFunction] { "calls": Array [ Array [ diff --git a/test/voice-broadcast/utils/startNewVoiceBroadcastRecording-test.ts b/test/voice-broadcast/utils/startNewVoiceBroadcastRecording-test.ts index a320bca2eb..0fc0d14cb2 100644 --- a/test/voice-broadcast/utils/startNewVoiceBroadcastRecording-test.ts +++ b/test/voice-broadcast/utils/startNewVoiceBroadcastRecording-test.ts @@ -67,6 +67,7 @@ describe("startNewVoiceBroadcastRecording", () => { recordingsStore = { setCurrent: jest.fn(), + getCurrent: jest.fn(), } as unknown as VoiceBroadcastRecordingsStore; infoEvent = mkVoiceBroadcastInfoStateEvent(roomId, VoiceBroadcastInfoState.Started, client.getUserId()); @@ -132,7 +133,25 @@ describe("startNewVoiceBroadcastRecording", () => { }); }); - describe("when there already is a live broadcast of the current user", () => { + describe("when there is already a current voice broadcast", () => { + beforeEach(async () => { + mocked(recordingsStore.getCurrent).mockReturnValue( + new VoiceBroadcastRecording(infoEvent, client), + ); + + result = await startNewVoiceBroadcastRecording(room, client, recordingsStore); + }); + + it("should not start a voice broadcast", () => { + expect(result).toBeNull(); + }); + + it("should show an info dialog", () => { + expect(Modal.createDialog).toMatchSnapshot(); + }); + }); + + describe("when there already is a live broadcast of the current user in the room", () => { beforeEach(async () => { room.currentState.setStateEvents([ mkVoiceBroadcastInfoStateEvent(roomId, VoiceBroadcastInfoState.Running, client.getUserId()),