Show room broadcast when ending a recording (#9841)

This commit is contained in:
Michael Weimann 2023-01-02 12:05:51 +01:00 committed by GitHub
parent 3ce064731b
commit 91e078d96b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 86 additions and 12 deletions

View file

@ -54,6 +54,8 @@ import { ThreadPayload } from "../dispatcher/payloads/ThreadPayload";
import {
doClearCurrentVoiceBroadcastPlaybackIfStopped,
doMaybeSetCurrentVoiceBroadcastPlayback,
VoiceBroadcastRecording,
VoiceBroadcastRecordingsStoreEvent,
} from "../voice-broadcast";
import { IRoomStateEventsActionPayload } from "../actions/MatrixActionCreators";
import { showCantStartACallDialog } from "../voice-broadcast/utils/showCantStartACallDialog";
@ -153,6 +155,10 @@ export class RoomViewStore extends EventEmitter {
public constructor(dis: MatrixDispatcher, private readonly stores: SdkContextClass) {
super();
this.resetDispatcher(dis);
this.stores.voiceBroadcastRecordingsStore.addListener(
VoiceBroadcastRecordingsStoreEvent.CurrentChanged,
this.onCurrentBroadcastRecordingChanged,
);
}
public addRoomListener(roomId: string, fn: Listener): void {
@ -167,13 +173,23 @@ export class RoomViewStore extends EventEmitter {
this.emit(roomId, isActive);
}
private onCurrentBroadcastRecordingChanged = (recording: VoiceBroadcastRecording | null) => {
if (recording === null) {
const room = this.stores.client?.getRoom(this.state.roomId || undefined);
if (room) {
this.doMaybeSetCurrentVoiceBroadcastPlayback(room);
}
}
};
private setState(newState: Partial<State>): void {
// If values haven't changed, there's nothing to do.
// This only tries a shallow comparison, so unchanged objects will slip
// through, but that's probably okay for now.
let stateChanged = false;
for (const key of Object.keys(newState)) {
if (this.state[key] !== newState[key]) {
if (this.state[key as keyof State] !== newState[key as keyof State]) {
stateChanged = true;
break;
}

View file

@ -24,7 +24,7 @@ export enum VoiceBroadcastRecordingsStoreEvent {
}
interface EventMap {
[VoiceBroadcastRecordingsStoreEvent.CurrentChanged]: (recording: VoiceBroadcastRecording) => void;
[VoiceBroadcastRecordingsStoreEvent.CurrentChanged]: (recording: VoiceBroadcastRecording | null) => void;
}
/**
@ -41,17 +41,23 @@ export class VoiceBroadcastRecordingsStore extends TypedEventEmitter<VoiceBroadc
public setCurrent(current: VoiceBroadcastRecording): void {
if (this.current === current) return;
const infoEventId = current.infoEvent.getId();
if (!infoEventId) {
throw new Error("Got broadcast info event without Id");
}
if (this.current) {
this.current.off(VoiceBroadcastRecordingEvent.StateChanged, this.onCurrentStateChanged);
}
this.current = current;
this.current.on(VoiceBroadcastRecordingEvent.StateChanged, this.onCurrentStateChanged);
this.recordings.set(current.infoEvent.getId(), current);
this.recordings.set(infoEventId, current);
this.emit(VoiceBroadcastRecordingsStoreEvent.CurrentChanged, current);
}
public getCurrent(): VoiceBroadcastRecording {
public getCurrent(): VoiceBroadcastRecording | null {
return this.current;
}
@ -70,11 +76,13 @@ export class VoiceBroadcastRecordingsStore extends TypedEventEmitter<VoiceBroadc
public getByInfoEvent(infoEvent: MatrixEvent, client: MatrixClient): VoiceBroadcastRecording {
const infoEventId = infoEvent.getId();
if (!this.recordings.has(infoEventId)) {
this.recordings.set(infoEventId, new VoiceBroadcastRecording(infoEvent, client));
if (!infoEventId) {
throw new Error("Got broadcast info event without Id");
}
return this.recordings.get(infoEventId);
const recording = this.recordings.get(infoEventId) || new VoiceBroadcastRecording(infoEvent, client);
this.recordings.set(infoEventId, recording);
return recording;
}
private onCurrentStateChanged = (state: VoiceBroadcastInfoState) => {