Replace broadcast instance with SDKContext (#9824)
This commit is contained in:
parent
6c40e2476a
commit
5912c7a637
11 changed files with 47 additions and 59 deletions
|
@ -50,11 +50,8 @@ import UserIdentifierCustomisations from "../../customisations/UserIdentifier";
|
|||
import PosthogTrackers from "../../PosthogTrackers";
|
||||
import { ViewHomePagePayload } from "../../dispatcher/payloads/ViewHomePagePayload";
|
||||
import { Icon as LiveIcon } from "../../../res/img/element-icons/live.svg";
|
||||
import {
|
||||
VoiceBroadcastRecording,
|
||||
VoiceBroadcastRecordingsStore,
|
||||
VoiceBroadcastRecordingsStoreEvent,
|
||||
} from "../../voice-broadcast";
|
||||
import { VoiceBroadcastRecording, VoiceBroadcastRecordingsStoreEvent } from "../../voice-broadcast";
|
||||
import { SDKContext } from "../../contexts/SDKContext";
|
||||
|
||||
interface IProps {
|
||||
isPanelCollapsed: boolean;
|
||||
|
@ -87,21 +84,24 @@ const below = (rect: PartialDOMRect) => {
|
|||
};
|
||||
|
||||
export default class UserMenu extends React.Component<IProps, IState> {
|
||||
public static contextType = SDKContext;
|
||||
public context!: React.ContextType<typeof SDKContext>;
|
||||
|
||||
private dispatcherRef: string;
|
||||
private themeWatcherRef: string;
|
||||
private readonly dndWatcherRef: string;
|
||||
private buttonRef: React.RefObject<HTMLButtonElement> = createRef();
|
||||
private voiceBroadcastRecordingStore = VoiceBroadcastRecordingsStore.instance();
|
||||
|
||||
public constructor(props: IProps) {
|
||||
super(props);
|
||||
public constructor(props: IProps, context: React.ContextType<typeof SDKContext>) {
|
||||
super(props, context);
|
||||
|
||||
this.context = context;
|
||||
this.state = {
|
||||
contextMenuPosition: null,
|
||||
isDarkTheme: this.isUserOnDarkTheme(),
|
||||
isHighContrast: this.isUserOnHighContrastTheme(),
|
||||
selectedSpace: SpaceStore.instance.activeSpaceRoom,
|
||||
showLiveAvatarAddon: this.voiceBroadcastRecordingStore.hasCurrent(),
|
||||
showLiveAvatarAddon: this.context.voiceBroadcastRecordingsStore.hasCurrent(),
|
||||
};
|
||||
|
||||
OwnProfileStore.instance.on(UPDATE_EVENT, this.onProfileUpdate);
|
||||
|
@ -119,7 +119,7 @@ export default class UserMenu extends React.Component<IProps, IState> {
|
|||
};
|
||||
|
||||
public componentDidMount() {
|
||||
this.voiceBroadcastRecordingStore.on(
|
||||
this.context.voiceBroadcastRecordingsStore.on(
|
||||
VoiceBroadcastRecordingsStoreEvent.CurrentChanged,
|
||||
this.onCurrentVoiceBroadcastRecordingChanged,
|
||||
);
|
||||
|
@ -133,7 +133,7 @@ export default class UserMenu extends React.Component<IProps, IState> {
|
|||
if (this.dispatcherRef) defaultDispatcher.unregister(this.dispatcherRef);
|
||||
OwnProfileStore.instance.off(UPDATE_EVENT, this.onProfileUpdate);
|
||||
SpaceStore.instance.off(UPDATE_SELECTED_SPACE, this.onSelectedSpaceUpdate);
|
||||
this.voiceBroadcastRecordingStore.off(
|
||||
this.context.voiceBroadcastRecordingsStore.off(
|
||||
VoiceBroadcastRecordingsStoreEvent.CurrentChanged,
|
||||
this.onCurrentVoiceBroadcastRecordingChanged,
|
||||
);
|
||||
|
|
|
@ -54,7 +54,6 @@ import { ViewRoomPayload } from "../../../dispatcher/payloads/ViewRoomPayload";
|
|||
import { isLocalRoom } from "../../../utils/localRoom/isLocalRoom";
|
||||
import { Features } from "../../../settings/Settings";
|
||||
import { VoiceMessageRecording } from "../../../audio/VoiceMessageRecording";
|
||||
import { VoiceBroadcastRecordingsStore } from "../../../voice-broadcast";
|
||||
import { SendWysiwygComposer, sendMessage } from "./wysiwyg_composer/";
|
||||
import { MatrixClientProps, withMatrixClientHOC } from "../../../contexts/MatrixClientContext";
|
||||
import { htmlToPlainText } from "../../../utils/room/htmlToPlaintext";
|
||||
|
@ -604,7 +603,7 @@ export class MessageComposer extends React.Component<IProps, IState> {
|
|||
this.props.room,
|
||||
MatrixClientPeg.get(),
|
||||
SdkContextClass.instance.voiceBroadcastPlaybacksStore,
|
||||
VoiceBroadcastRecordingsStore.instance(),
|
||||
SdkContextClass.instance.voiceBroadcastRecordingsStore,
|
||||
SdkContextClass.instance.voiceBroadcastPreRecordingStore,
|
||||
);
|
||||
this.toggleButtonMenu();
|
||||
|
|
|
@ -158,7 +158,7 @@ export class SdkContextClass {
|
|||
|
||||
public get voiceBroadcastRecordingsStore(): VoiceBroadcastRecordingsStore {
|
||||
if (!this._VoiceBroadcastRecordingsStore) {
|
||||
this._VoiceBroadcastRecordingsStore = VoiceBroadcastRecordingsStore.instance();
|
||||
this._VoiceBroadcastRecordingsStore = new VoiceBroadcastRecordingsStore();
|
||||
}
|
||||
return this._VoiceBroadcastRecordingsStore;
|
||||
}
|
||||
|
@ -172,7 +172,7 @@ export class SdkContextClass {
|
|||
|
||||
public get voiceBroadcastPlaybacksStore(): VoiceBroadcastPlaybacksStore {
|
||||
if (!this._VoiceBroadcastPlaybacksStore) {
|
||||
this._VoiceBroadcastPlaybacksStore = VoiceBroadcastPlaybacksStore.instance();
|
||||
this._VoiceBroadcastPlaybacksStore = new VoiceBroadcastPlaybacksStore();
|
||||
}
|
||||
return this._VoiceBroadcastPlaybacksStore;
|
||||
}
|
||||
|
|
|
@ -66,7 +66,6 @@ import { ViewRoomPayload } from "../../dispatcher/payloads/ViewRoomPayload";
|
|||
import Modal from "../../Modal";
|
||||
import ErrorDialog from "../../components/views/dialogs/ErrorDialog";
|
||||
import { SdkContextClass } from "../../contexts/SDKContext";
|
||||
import { VoiceBroadcastRecordingsStore } from "../../voice-broadcast";
|
||||
|
||||
// TODO: Destroy all of this code
|
||||
|
||||
|
@ -292,7 +291,7 @@ export class StopGapWidget extends EventEmitter {
|
|||
this.messaging.on(`action:${WidgetApiFromWidgetAction.OpenModalWidget}`, this.onOpenModal);
|
||||
this.messaging.on(`action:${ElementWidgetActions.JoinCall}`, () => {
|
||||
// pause voice broadcast recording when any widget sends a "join"
|
||||
VoiceBroadcastRecordingsStore.instance().getCurrent()?.pause();
|
||||
SdkContextClass.instance.voiceBroadcastRecordingsStore.getCurrent()?.pause();
|
||||
});
|
||||
|
||||
// Always attach a handler for ViewRoom, but permission check it internally
|
||||
|
|
|
@ -14,23 +14,23 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
import React, { useEffect, useState } from "react";
|
||||
import React, { useContext, useEffect, useState } from "react";
|
||||
import { MatrixEvent, RelationType } from "matrix-js-sdk/src/matrix";
|
||||
|
||||
import {
|
||||
VoiceBroadcastRecordingBody,
|
||||
VoiceBroadcastRecordingsStore,
|
||||
shouldDisplayAsVoiceBroadcastRecordingTile,
|
||||
VoiceBroadcastInfoEventType,
|
||||
VoiceBroadcastPlaybacksStore,
|
||||
VoiceBroadcastPlaybackBody,
|
||||
VoiceBroadcastInfoState,
|
||||
} from "..";
|
||||
import { IBodyProps } from "../../components/views/messages/IBodyProps";
|
||||
import { MatrixClientPeg } from "../../MatrixClientPeg";
|
||||
import { RelationsHelper, RelationsHelperEvent } from "../../events/RelationsHelper";
|
||||
import { SDKContext } from "../../contexts/SDKContext";
|
||||
|
||||
export const VoiceBroadcastBody: React.FC<IBodyProps> = ({ mxEvent }) => {
|
||||
const sdkContext = useContext(SDKContext);
|
||||
const client = MatrixClientPeg.get();
|
||||
const [infoState, setInfoState] = useState(mxEvent.getContent()?.state || VoiceBroadcastInfoState.Stopped);
|
||||
|
||||
|
@ -57,10 +57,10 @@ export const VoiceBroadcastBody: React.FC<IBodyProps> = ({ mxEvent }) => {
|
|||
});
|
||||
|
||||
if (shouldDisplayAsVoiceBroadcastRecordingTile(infoState, client, mxEvent)) {
|
||||
const recording = VoiceBroadcastRecordingsStore.instance().getByInfoEvent(mxEvent, client);
|
||||
const recording = sdkContext.voiceBroadcastRecordingsStore.getByInfoEvent(mxEvent, client);
|
||||
return <VoiceBroadcastRecordingBody recording={recording} />;
|
||||
}
|
||||
|
||||
const playback = VoiceBroadcastPlaybacksStore.instance().getByInfoEvent(mxEvent, client);
|
||||
const playback = sdkContext.voiceBroadcastPlaybacksStore.getByInfoEvent(mxEvent, client);
|
||||
return <VoiceBroadcastPlaybackBody playback={playback} />;
|
||||
};
|
||||
|
|
|
@ -114,13 +114,4 @@ export class VoiceBroadcastPlaybacksStore
|
|||
|
||||
this.playbacks = new Map();
|
||||
}
|
||||
|
||||
public static readonly _instance = new VoiceBroadcastPlaybacksStore();
|
||||
|
||||
/**
|
||||
* TODO Michael W: replace when https://github.com/matrix-org/matrix-react-sdk/pull/9293 has been merged
|
||||
*/
|
||||
public static instance() {
|
||||
return VoiceBroadcastPlaybacksStore._instance;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -82,13 +82,4 @@ export class VoiceBroadcastRecordingsStore extends TypedEventEmitter<VoiceBroadc
|
|||
this.clearCurrent();
|
||||
}
|
||||
};
|
||||
|
||||
private static readonly cachedInstance = new VoiceBroadcastRecordingsStore();
|
||||
|
||||
/**
|
||||
* TODO Michael W: replace when https://github.com/matrix-org/matrix-react-sdk/pull/9293 has been merged
|
||||
*/
|
||||
public static instance(): VoiceBroadcastRecordingsStore {
|
||||
return VoiceBroadcastRecordingsStore.cachedInstance;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue