Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit a61076b

Browse files
authored
Add confirm end voice broadcast dialog (#9442)
1 parent 57eec82 commit a61076b

File tree

3 files changed

+58
-5
lines changed

3 files changed

+58
-5
lines changed

src/i18n/strings/en_EN.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,9 @@
637637
"Send <b>%(msgtype)s</b> messages as you in your active room": "Send <b>%(msgtype)s</b> messages as you in your active room",
638638
"See <b>%(msgtype)s</b> messages posted to this room": "See <b>%(msgtype)s</b> messages posted to this room",
639639
"See <b>%(msgtype)s</b> messages posted to your active room": "See <b>%(msgtype)s</b> messages posted to your active room",
640+
"Stop live broadcasting?": "Stop live broadcasting?",
641+
"Are you sure you want to stop your live broadcast?This will end the broadcast and the full recording will be available in the room.": "Are you sure you want to stop your live broadcast?This will end the broadcast and the full recording will be available in the room.",
642+
"Yes, stop broadcast": "Yes, stop broadcast",
640643
"Live": "Live",
641644
"pause voice broadcast": "pause voice broadcast",
642645
"resume voice broadcast": "resume voice broadcast",

src/voice-broadcast/hooks/useVoiceBroadcastRecording.ts renamed to src/voice-broadcast/hooks/useVoiceBroadcastRecording.tsx

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,48 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
import { useState } from "react";
17+
import React, { useState } from "react";
1818

1919
import {
2020
VoiceBroadcastInfoState,
2121
VoiceBroadcastRecording,
2222
VoiceBroadcastRecordingEvent,
2323
VoiceBroadcastRecordingsStore,
2424
} from "..";
25+
import QuestionDialog from "../../components/views/dialogs/QuestionDialog";
2526
import { useTypedEventEmitter } from "../../hooks/useEventEmitter";
27+
import { _t } from "../../languageHandler";
2628
import { MatrixClientPeg } from "../../MatrixClientPeg";
29+
import Modal from "../../Modal";
30+
31+
const showStopBroadcastingDialog = async (): Promise<boolean> => {
32+
const { finished } = Modal.createDialog(
33+
QuestionDialog,
34+
{
35+
title: _t("Stop live broadcasting?"),
36+
description: (
37+
<p>
38+
{ _t("Are you sure you want to stop your live broadcast?"
39+
+ "This will end the broadcast and the full recording will be available in the room.") }
40+
</p>
41+
),
42+
button: _t("Yes, stop broadcast"),
43+
},
44+
);
45+
const [confirmed] = await finished;
46+
return confirmed;
47+
};
2748

2849
export const useVoiceBroadcastRecording = (recording: VoiceBroadcastRecording) => {
2950
const client = MatrixClientPeg.get();
3051
const room = client.getRoom(recording.infoEvent.getRoomId());
31-
const stopRecording = () => {
32-
recording.stop();
33-
VoiceBroadcastRecordingsStore.instance().clearCurrent();
52+
const stopRecording = async () => {
53+
const confirmed = await showStopBroadcastingDialog();
54+
55+
if (confirmed) {
56+
recording.stop();
57+
VoiceBroadcastRecordingsStore.instance().clearCurrent();
58+
}
3459
};
3560

3661
const [live, setLive] = useState(recording.getState() === VoiceBroadcastInfoState.Started);

test/voice-broadcast/components/molecules/VoiceBroadcastRecordingPip-test.tsx

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,14 @@ limitations under the License.
1616
//
1717

1818
import React from "react";
19-
import { render, RenderResult } from "@testing-library/react";
19+
import { render, RenderResult, screen } from "@testing-library/react";
20+
import userEvent from "@testing-library/user-event";
2021
import { MatrixClient, MatrixEvent } from "matrix-js-sdk/src/matrix";
22+
import { sleep } from "matrix-js-sdk/src/utils";
2123

2224
import {
2325
VoiceBroadcastInfoEventType,
26+
VoiceBroadcastInfoState,
2427
VoiceBroadcastRecording,
2528
VoiceBroadcastRecordingPip,
2629
} from "../../../../src/voice-broadcast";
@@ -63,5 +66,27 @@ describe("VoiceBroadcastRecordingPip", () => {
6366
it("should create the expected result", () => {
6467
expect(renderResult.container).toMatchSnapshot();
6568
});
69+
70+
describe("and clicking the stop button", () => {
71+
beforeEach(async () => {
72+
await userEvent.click(screen.getByLabelText("stop voice broadcast"));
73+
// modal rendering has some weird sleeps
74+
await sleep(100);
75+
});
76+
77+
it("should display the confirm end dialog", () => {
78+
screen.getByText("Stop live broadcasting?");
79+
});
80+
81+
describe("and confirming the dialog", () => {
82+
beforeEach(async () => {
83+
await userEvent.click(screen.getByText("Yes, stop broadcast"));
84+
});
85+
86+
it("should end the recording", () => {
87+
expect(recording.getState()).toBe(VoiceBroadcastInfoState.Stopped);
88+
});
89+
});
90+
});
6691
});
6792
});

0 commit comments

Comments
 (0)