Add confirm end voice broadcast dialog (#9442)

This commit is contained in:
Michael Weimann 2022-10-18 09:12:28 +02:00 committed by GitHub
parent 57eec824d9
commit a61076b4fb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 58 additions and 5 deletions

View file

@ -637,6 +637,9 @@
"Send <b>%(msgtype)s</b> messages as you in your active room": "Send <b>%(msgtype)s</b> messages as you in your active room", "Send <b>%(msgtype)s</b> messages as you in your active room": "Send <b>%(msgtype)s</b> messages as you in your active room",
"See <b>%(msgtype)s</b> messages posted to this room": "See <b>%(msgtype)s</b> messages posted to this room", "See <b>%(msgtype)s</b> messages posted to this room": "See <b>%(msgtype)s</b> messages posted to this room",
"See <b>%(msgtype)s</b> messages posted to your active room": "See <b>%(msgtype)s</b> messages posted to your active room", "See <b>%(msgtype)s</b> messages posted to your active room": "See <b>%(msgtype)s</b> messages posted to your active room",
"Stop live broadcasting?": "Stop live broadcasting?",
"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.",
"Yes, stop broadcast": "Yes, stop broadcast",
"Live": "Live", "Live": "Live",
"pause voice broadcast": "pause voice broadcast", "pause voice broadcast": "pause voice broadcast",
"resume voice broadcast": "resume voice broadcast", "resume voice broadcast": "resume voice broadcast",

View file

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
import { useState } from "react"; import React, { useState } from "react";
import { import {
VoiceBroadcastInfoState, VoiceBroadcastInfoState,
@ -22,15 +22,40 @@ import {
VoiceBroadcastRecordingEvent, VoiceBroadcastRecordingEvent,
VoiceBroadcastRecordingsStore, VoiceBroadcastRecordingsStore,
} from ".."; } from "..";
import QuestionDialog from "../../components/views/dialogs/QuestionDialog";
import { useTypedEventEmitter } from "../../hooks/useEventEmitter"; import { useTypedEventEmitter } from "../../hooks/useEventEmitter";
import { _t } from "../../languageHandler";
import { MatrixClientPeg } from "../../MatrixClientPeg"; import { MatrixClientPeg } from "../../MatrixClientPeg";
import Modal from "../../Modal";
const showStopBroadcastingDialog = async (): Promise<boolean> => {
const { finished } = Modal.createDialog(
QuestionDialog,
{
title: _t("Stop live broadcasting?"),
description: (
<p>
{ _t("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.") }
</p>
),
button: _t("Yes, stop broadcast"),
},
);
const [confirmed] = await finished;
return confirmed;
};
export const useVoiceBroadcastRecording = (recording: VoiceBroadcastRecording) => { export const useVoiceBroadcastRecording = (recording: VoiceBroadcastRecording) => {
const client = MatrixClientPeg.get(); const client = MatrixClientPeg.get();
const room = client.getRoom(recording.infoEvent.getRoomId()); const room = client.getRoom(recording.infoEvent.getRoomId());
const stopRecording = () => { const stopRecording = async () => {
recording.stop(); const confirmed = await showStopBroadcastingDialog();
VoiceBroadcastRecordingsStore.instance().clearCurrent();
if (confirmed) {
recording.stop();
VoiceBroadcastRecordingsStore.instance().clearCurrent();
}
}; };
const [live, setLive] = useState(recording.getState() === VoiceBroadcastInfoState.Started); const [live, setLive] = useState(recording.getState() === VoiceBroadcastInfoState.Started);

View file

@ -16,11 +16,14 @@ limitations under the License.
// //
import React from "react"; import React from "react";
import { render, RenderResult } from "@testing-library/react"; import { render, RenderResult, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { MatrixClient, MatrixEvent } from "matrix-js-sdk/src/matrix"; import { MatrixClient, MatrixEvent } from "matrix-js-sdk/src/matrix";
import { sleep } from "matrix-js-sdk/src/utils";
import { import {
VoiceBroadcastInfoEventType, VoiceBroadcastInfoEventType,
VoiceBroadcastInfoState,
VoiceBroadcastRecording, VoiceBroadcastRecording,
VoiceBroadcastRecordingPip, VoiceBroadcastRecordingPip,
} from "../../../../src/voice-broadcast"; } from "../../../../src/voice-broadcast";
@ -63,5 +66,27 @@ describe("VoiceBroadcastRecordingPip", () => {
it("should create the expected result", () => { it("should create the expected result", () => {
expect(renderResult.container).toMatchSnapshot(); expect(renderResult.container).toMatchSnapshot();
}); });
describe("and clicking the stop button", () => {
beforeEach(async () => {
await userEvent.click(screen.getByLabelText("stop voice broadcast"));
// modal rendering has some weird sleeps
await sleep(100);
});
it("should display the confirm end dialog", () => {
screen.getByText("Stop live broadcasting?");
});
describe("and confirming the dialog", () => {
beforeEach(async () => {
await userEvent.click(screen.getByText("Yes, stop broadcast"));
});
it("should end the recording", () => {
expect(recording.getState()).toBe(VoiceBroadcastInfoState.Stopped);
});
});
});
}); });
}); });