diff --git a/src/components/views/messages/MessageEvent.tsx b/src/components/views/messages/MessageEvent.tsx index 91807d568f..858bf0eb6c 100644 --- a/src/components/views/messages/MessageEvent.tsx +++ b/src/components/views/messages/MessageEvent.tsx @@ -43,8 +43,6 @@ import MjolnirBody from "./MjolnirBody"; import MBeaconBody from "./MBeaconBody"; import { IEventTileOps } from "../rooms/EventTile"; import { VoiceBroadcastBody, VoiceBroadcastInfoEventType, VoiceBroadcastInfoState } from '../../../voice-broadcast'; -import { Features } from '../../../settings/Settings'; -import { SettingLevel } from '../../../settings/SettingLevel'; // onMessageAllowed is handled internally interface IProps extends Omit { @@ -58,18 +56,10 @@ interface IProps extends Omit([ [MsgType.Text, TextualBody], [MsgType.Notice, TextualBody], @@ -87,7 +77,7 @@ const baseEvTypes = new Map>>([ [M_BEACON_INFO.altName, MBeaconBody], ]); -export default class MessageEvent extends React.Component implements IMediaBody, IOperableEventTile { +export default class MessageEvent extends React.Component implements IMediaBody, IOperableEventTile { private body: React.RefObject = createRef(); private mediaHelper: MediaEventHelper; private bodyTypes = new Map(baseBodyTypes.entries()); @@ -95,7 +85,6 @@ export default class MessageEvent extends React.Component impleme public static contextType = MatrixClientContext; public context!: React.ContextType; - private voiceBroadcastSettingWatcherRef: string; public constructor(props: IProps, context: React.ContextType) { super(props, context); @@ -105,29 +94,15 @@ export default class MessageEvent extends React.Component impleme } this.updateComponentMaps(); - - this.state = { - // only check voice broadcast settings for a voice broadcast event - voiceBroadcastEnabled: this.props.mxEvent.getType() === VoiceBroadcastInfoEventType - && SettingsStore.getValue(Features.VoiceBroadcast), - }; } public componentDidMount(): void { this.props.mxEvent.addListener(MatrixEventEvent.Decrypted, this.onDecrypted); - - if (this.props.mxEvent.getType() === VoiceBroadcastInfoEventType) { - this.watchVoiceBroadcastFeatureSetting(); - } } public componentWillUnmount() { this.props.mxEvent.removeListener(MatrixEventEvent.Decrypted, this.onDecrypted); this.mediaHelper?.destroy(); - - if (this.voiceBroadcastSettingWatcherRef) { - SettingsStore.unwatchSetting(this.voiceBroadcastSettingWatcherRef); - } } public componentDidUpdate(prevProps: Readonly) { @@ -171,16 +146,6 @@ export default class MessageEvent extends React.Component impleme this.forceUpdate(); }; - private watchVoiceBroadcastFeatureSetting(): void { - this.voiceBroadcastSettingWatcherRef = SettingsStore.watchSetting( - Features.VoiceBroadcast, - null, - (settingName: string, roomId: string, atLevel: SettingLevel, newValAtLevel, newValue: boolean) => { - this.setState({ voiceBroadcastEnabled: newValue }); - }, - ); - } - public render() { const content = this.props.mxEvent.getContent(); const type = this.props.mxEvent.getType(); @@ -209,8 +174,7 @@ export default class MessageEvent extends React.Component impleme } if ( - this.state.voiceBroadcastEnabled - && type === VoiceBroadcastInfoEventType + type === VoiceBroadcastInfoEventType && content?.state === VoiceBroadcastInfoState.Started ) { BodyType = VoiceBroadcastBody; diff --git a/test/components/views/messages/MessageEvent-test.tsx b/test/components/views/messages/MessageEvent-test.tsx index 82442855fc..dadddca093 100644 --- a/test/components/views/messages/MessageEvent-test.tsx +++ b/test/components/views/messages/MessageEvent-test.tsx @@ -16,11 +16,9 @@ limitations under the License. import React from "react"; import { render, RenderResult } from "@testing-library/react"; -import { mocked } from "jest-mock"; import { MatrixClient, MatrixEvent, Room } from "matrix-js-sdk/src/matrix"; -import { Features } from "../../../../src/settings/Settings"; -import SettingsStore, { CallbackFn } from "../../../../src/settings/SettingsStore"; +import SettingsStore from "../../../../src/settings/SettingsStore"; import { VoiceBroadcastInfoEventType, VoiceBroadcastInfoState } from "../../../../src/voice-broadcast"; import { mkEvent, mkRoom, stubClient } from "../../../test-utils"; import MessageEvent from "../../../../src/components/views/messages/MessageEvent"; @@ -57,8 +55,7 @@ describe("MessageEvent", () => { }); describe("when a voice broadcast start event occurs", () => { - const voiceBroadcastSettingWatcherRef = "vb ref"; - let onVoiceBroadcastSettingChanged: CallbackFn; + let result: RenderResult; beforeEach(() => { event = mkEvent({ @@ -70,64 +67,11 @@ describe("MessageEvent", () => { state: VoiceBroadcastInfoState.Started, }, }); - - mocked(SettingsStore.watchSetting).mockImplementation( - (settingName: string, roomId: string | null, callbackFn: CallbackFn) => { - if (settingName === Features.VoiceBroadcast) { - onVoiceBroadcastSettingChanged = callbackFn; - return voiceBroadcastSettingWatcherRef; - } - }, - ); + result = renderMessageEvent(); }); - describe("and the voice broadcast feature is enabled", () => { - let result: RenderResult; - - beforeEach(() => { - mocked(SettingsStore.getValue).mockImplementation((settingName: string) => { - return settingName === Features.VoiceBroadcast; - }); - result = renderMessageEvent(); - }); - - it("should render a VoiceBroadcast component", () => { - result.getByTestId("voice-broadcast-body"); - }); - - describe("and switching the voice broadcast feature off", () => { - beforeEach(() => { - onVoiceBroadcastSettingChanged(Features.VoiceBroadcast, null, null, null, false); - }); - - it("should render an UnknownBody component", () => { - const result = renderMessageEvent(); - result.getByTestId("unknown-body"); - }); - }); - - describe("and unmounted", () => { - beforeEach(() => { - result.unmount(); - }); - - it("should unregister the settings watcher", () => { - expect(SettingsStore.unwatchSetting).toHaveBeenCalled(); - }); - }); - }); - - describe("and the voice broadcast feature is disabled", () => { - beforeEach(() => { - mocked(SettingsStore.getValue).mockImplementation((settingName: string) => { - return false; - }); - }); - - it("should render an UnknownBody component", () => { - const result = renderMessageEvent(); - result.getByTestId("unknown-body"); - }); + it("should render a VoiceBroadcast component", () => { + result.getByTestId("voice-broadcast-body"); }); }); });