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

Commit 84f2974

Browse files
authored
Always show voice broadcasts tile (#9444)
1 parent e0ab0ac commit 84f2974

File tree

2 files changed

+7
-99
lines changed

2 files changed

+7
-99
lines changed

src/components/views/messages/MessageEvent.tsx

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ import MjolnirBody from "./MjolnirBody";
4343
import MBeaconBody from "./MBeaconBody";
4444
import { IEventTileOps } from "../rooms/EventTile";
4545
import { VoiceBroadcastBody, VoiceBroadcastInfoEventType, VoiceBroadcastInfoState } from '../../../voice-broadcast';
46-
import { Features } from '../../../settings/Settings';
47-
import { SettingLevel } from '../../../settings/SettingLevel';
4846

4947
// onMessageAllowed is handled internally
5048
interface IProps extends Omit<IBodyProps, "onMessageAllowed" | "mediaEventHelper"> {
@@ -58,18 +56,10 @@ interface IProps extends Omit<IBodyProps, "onMessageAllowed" | "mediaEventHelper
5856
isSeeingThroughMessageHiddenForModeration?: boolean;
5957
}
6058

61-
interface State {
62-
voiceBroadcastEnabled: boolean;
63-
}
64-
6559
export interface IOperableEventTile {
6660
getEventTileOps(): IEventTileOps;
6761
}
6862

69-
interface State {
70-
voiceBroadcastEnabled: boolean;
71-
}
72-
7363
const baseBodyTypes = new Map<string, typeof React.Component>([
7464
[MsgType.Text, TextualBody],
7565
[MsgType.Notice, TextualBody],
@@ -87,15 +77,14 @@ const baseEvTypes = new Map<string, React.ComponentType<Partial<IBodyProps>>>([
8777
[M_BEACON_INFO.altName, MBeaconBody],
8878
]);
8979

90-
export default class MessageEvent extends React.Component<IProps, State> implements IMediaBody, IOperableEventTile {
80+
export default class MessageEvent extends React.Component<IProps> implements IMediaBody, IOperableEventTile {
9181
private body: React.RefObject<React.Component | IOperableEventTile> = createRef();
9282
private mediaHelper: MediaEventHelper;
9383
private bodyTypes = new Map<string, typeof React.Component>(baseBodyTypes.entries());
9484
private evTypes = new Map<string, React.ComponentType<Partial<IBodyProps>>>(baseEvTypes.entries());
9585

9686
public static contextType = MatrixClientContext;
9787
public context!: React.ContextType<typeof MatrixClientContext>;
98-
private voiceBroadcastSettingWatcherRef: string;
9988

10089
public constructor(props: IProps, context: React.ContextType<typeof MatrixClientContext>) {
10190
super(props, context);
@@ -105,29 +94,15 @@ export default class MessageEvent extends React.Component<IProps, State> impleme
10594
}
10695

10796
this.updateComponentMaps();
108-
109-
this.state = {
110-
// only check voice broadcast settings for a voice broadcast event
111-
voiceBroadcastEnabled: this.props.mxEvent.getType() === VoiceBroadcastInfoEventType
112-
&& SettingsStore.getValue(Features.VoiceBroadcast),
113-
};
11497
}
11598

11699
public componentDidMount(): void {
117100
this.props.mxEvent.addListener(MatrixEventEvent.Decrypted, this.onDecrypted);
118-
119-
if (this.props.mxEvent.getType() === VoiceBroadcastInfoEventType) {
120-
this.watchVoiceBroadcastFeatureSetting();
121-
}
122101
}
123102

124103
public componentWillUnmount() {
125104
this.props.mxEvent.removeListener(MatrixEventEvent.Decrypted, this.onDecrypted);
126105
this.mediaHelper?.destroy();
127-
128-
if (this.voiceBroadcastSettingWatcherRef) {
129-
SettingsStore.unwatchSetting(this.voiceBroadcastSettingWatcherRef);
130-
}
131106
}
132107

133108
public componentDidUpdate(prevProps: Readonly<IProps>) {
@@ -171,16 +146,6 @@ export default class MessageEvent extends React.Component<IProps, State> impleme
171146
this.forceUpdate();
172147
};
173148

174-
private watchVoiceBroadcastFeatureSetting(): void {
175-
this.voiceBroadcastSettingWatcherRef = SettingsStore.watchSetting(
176-
Features.VoiceBroadcast,
177-
null,
178-
(settingName: string, roomId: string, atLevel: SettingLevel, newValAtLevel, newValue: boolean) => {
179-
this.setState({ voiceBroadcastEnabled: newValue });
180-
},
181-
);
182-
}
183-
184149
public render() {
185150
const content = this.props.mxEvent.getContent();
186151
const type = this.props.mxEvent.getType();
@@ -209,8 +174,7 @@ export default class MessageEvent extends React.Component<IProps, State> impleme
209174
}
210175

211176
if (
212-
this.state.voiceBroadcastEnabled
213-
&& type === VoiceBroadcastInfoEventType
177+
type === VoiceBroadcastInfoEventType
214178
&& content?.state === VoiceBroadcastInfoState.Started
215179
) {
216180
BodyType = VoiceBroadcastBody;

test/components/views/messages/MessageEvent-test.tsx

Lines changed: 5 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,9 @@ limitations under the License.
1616

1717
import React from "react";
1818
import { render, RenderResult } from "@testing-library/react";
19-
import { mocked } from "jest-mock";
2019
import { MatrixClient, MatrixEvent, Room } from "matrix-js-sdk/src/matrix";
2120

22-
import { Features } from "../../../../src/settings/Settings";
23-
import SettingsStore, { CallbackFn } from "../../../../src/settings/SettingsStore";
21+
import SettingsStore from "../../../../src/settings/SettingsStore";
2422
import { VoiceBroadcastInfoEventType, VoiceBroadcastInfoState } from "../../../../src/voice-broadcast";
2523
import { mkEvent, mkRoom, stubClient } from "../../../test-utils";
2624
import MessageEvent from "../../../../src/components/views/messages/MessageEvent";
@@ -57,8 +55,7 @@ describe("MessageEvent", () => {
5755
});
5856

5957
describe("when a voice broadcast start event occurs", () => {
60-
const voiceBroadcastSettingWatcherRef = "vb ref";
61-
let onVoiceBroadcastSettingChanged: CallbackFn;
58+
let result: RenderResult;
6259

6360
beforeEach(() => {
6461
event = mkEvent({
@@ -70,64 +67,11 @@ describe("MessageEvent", () => {
7067
state: VoiceBroadcastInfoState.Started,
7168
},
7269
});
73-
74-
mocked(SettingsStore.watchSetting).mockImplementation(
75-
(settingName: string, roomId: string | null, callbackFn: CallbackFn) => {
76-
if (settingName === Features.VoiceBroadcast) {
77-
onVoiceBroadcastSettingChanged = callbackFn;
78-
return voiceBroadcastSettingWatcherRef;
79-
}
80-
},
81-
);
70+
result = renderMessageEvent();
8271
});
8372

84-
describe("and the voice broadcast feature is enabled", () => {
85-
let result: RenderResult;
86-
87-
beforeEach(() => {
88-
mocked(SettingsStore.getValue).mockImplementation((settingName: string) => {
89-
return settingName === Features.VoiceBroadcast;
90-
});
91-
result = renderMessageEvent();
92-
});
93-
94-
it("should render a VoiceBroadcast component", () => {
95-
result.getByTestId("voice-broadcast-body");
96-
});
97-
98-
describe("and switching the voice broadcast feature off", () => {
99-
beforeEach(() => {
100-
onVoiceBroadcastSettingChanged(Features.VoiceBroadcast, null, null, null, false);
101-
});
102-
103-
it("should render an UnknownBody component", () => {
104-
const result = renderMessageEvent();
105-
result.getByTestId("unknown-body");
106-
});
107-
});
108-
109-
describe("and unmounted", () => {
110-
beforeEach(() => {
111-
result.unmount();
112-
});
113-
114-
it("should unregister the settings watcher", () => {
115-
expect(SettingsStore.unwatchSetting).toHaveBeenCalled();
116-
});
117-
});
118-
});
119-
120-
describe("and the voice broadcast feature is disabled", () => {
121-
beforeEach(() => {
122-
mocked(SettingsStore.getValue).mockImplementation((settingName: string) => {
123-
return false;
124-
});
125-
});
126-
127-
it("should render an UnknownBody component", () => {
128-
const result = renderMessageEvent();
129-
result.getByTestId("unknown-body");
130-
});
73+
it("should render a VoiceBroadcast component", () => {
74+
result.getByTestId("voice-broadcast-body");
13175
});
13276
});
13377
});

0 commit comments

Comments
 (0)