Always show voice broadcasts tile (#9444)
This commit is contained in:
parent
e0ab0ac5c9
commit
84f2974b57
2 changed files with 7 additions and 99 deletions
|
@ -43,8 +43,6 @@ import MjolnirBody from "./MjolnirBody";
|
||||||
import MBeaconBody from "./MBeaconBody";
|
import MBeaconBody from "./MBeaconBody";
|
||||||
import { IEventTileOps } from "../rooms/EventTile";
|
import { IEventTileOps } from "../rooms/EventTile";
|
||||||
import { VoiceBroadcastBody, VoiceBroadcastInfoEventType, VoiceBroadcastInfoState } from '../../../voice-broadcast';
|
import { VoiceBroadcastBody, VoiceBroadcastInfoEventType, VoiceBroadcastInfoState } from '../../../voice-broadcast';
|
||||||
import { Features } from '../../../settings/Settings';
|
|
||||||
import { SettingLevel } from '../../../settings/SettingLevel';
|
|
||||||
|
|
||||||
// onMessageAllowed is handled internally
|
// onMessageAllowed is handled internally
|
||||||
interface IProps extends Omit<IBodyProps, "onMessageAllowed" | "mediaEventHelper"> {
|
interface IProps extends Omit<IBodyProps, "onMessageAllowed" | "mediaEventHelper"> {
|
||||||
|
@ -58,18 +56,10 @@ interface IProps extends Omit<IBodyProps, "onMessageAllowed" | "mediaEventHelper
|
||||||
isSeeingThroughMessageHiddenForModeration?: boolean;
|
isSeeingThroughMessageHiddenForModeration?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface State {
|
|
||||||
voiceBroadcastEnabled: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface IOperableEventTile {
|
export interface IOperableEventTile {
|
||||||
getEventTileOps(): IEventTileOps;
|
getEventTileOps(): IEventTileOps;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface State {
|
|
||||||
voiceBroadcastEnabled: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
const baseBodyTypes = new Map<string, typeof React.Component>([
|
const baseBodyTypes = new Map<string, typeof React.Component>([
|
||||||
[MsgType.Text, TextualBody],
|
[MsgType.Text, TextualBody],
|
||||||
[MsgType.Notice, TextualBody],
|
[MsgType.Notice, TextualBody],
|
||||||
|
@ -87,7 +77,7 @@ const baseEvTypes = new Map<string, React.ComponentType<Partial<IBodyProps>>>([
|
||||||
[M_BEACON_INFO.altName, MBeaconBody],
|
[M_BEACON_INFO.altName, MBeaconBody],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
export default class MessageEvent extends React.Component<IProps, State> implements IMediaBody, IOperableEventTile {
|
export default class MessageEvent extends React.Component<IProps> implements IMediaBody, IOperableEventTile {
|
||||||
private body: React.RefObject<React.Component | IOperableEventTile> = createRef();
|
private body: React.RefObject<React.Component | IOperableEventTile> = createRef();
|
||||||
private mediaHelper: MediaEventHelper;
|
private mediaHelper: MediaEventHelper;
|
||||||
private bodyTypes = new Map<string, typeof React.Component>(baseBodyTypes.entries());
|
private bodyTypes = new Map<string, typeof React.Component>(baseBodyTypes.entries());
|
||||||
|
@ -95,7 +85,6 @@ export default class MessageEvent extends React.Component<IProps, State> impleme
|
||||||
|
|
||||||
public static contextType = MatrixClientContext;
|
public static contextType = MatrixClientContext;
|
||||||
public context!: React.ContextType<typeof MatrixClientContext>;
|
public context!: React.ContextType<typeof MatrixClientContext>;
|
||||||
private voiceBroadcastSettingWatcherRef: string;
|
|
||||||
|
|
||||||
public constructor(props: IProps, context: React.ContextType<typeof MatrixClientContext>) {
|
public constructor(props: IProps, context: React.ContextType<typeof MatrixClientContext>) {
|
||||||
super(props, context);
|
super(props, context);
|
||||||
|
@ -105,29 +94,15 @@ export default class MessageEvent extends React.Component<IProps, State> impleme
|
||||||
}
|
}
|
||||||
|
|
||||||
this.updateComponentMaps();
|
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 {
|
public componentDidMount(): void {
|
||||||
this.props.mxEvent.addListener(MatrixEventEvent.Decrypted, this.onDecrypted);
|
this.props.mxEvent.addListener(MatrixEventEvent.Decrypted, this.onDecrypted);
|
||||||
|
|
||||||
if (this.props.mxEvent.getType() === VoiceBroadcastInfoEventType) {
|
|
||||||
this.watchVoiceBroadcastFeatureSetting();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public componentWillUnmount() {
|
public componentWillUnmount() {
|
||||||
this.props.mxEvent.removeListener(MatrixEventEvent.Decrypted, this.onDecrypted);
|
this.props.mxEvent.removeListener(MatrixEventEvent.Decrypted, this.onDecrypted);
|
||||||
this.mediaHelper?.destroy();
|
this.mediaHelper?.destroy();
|
||||||
|
|
||||||
if (this.voiceBroadcastSettingWatcherRef) {
|
|
||||||
SettingsStore.unwatchSetting(this.voiceBroadcastSettingWatcherRef);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public componentDidUpdate(prevProps: Readonly<IProps>) {
|
public componentDidUpdate(prevProps: Readonly<IProps>) {
|
||||||
|
@ -171,16 +146,6 @@ export default class MessageEvent extends React.Component<IProps, State> impleme
|
||||||
this.forceUpdate();
|
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() {
|
public render() {
|
||||||
const content = this.props.mxEvent.getContent();
|
const content = this.props.mxEvent.getContent();
|
||||||
const type = this.props.mxEvent.getType();
|
const type = this.props.mxEvent.getType();
|
||||||
|
@ -209,8 +174,7 @@ export default class MessageEvent extends React.Component<IProps, State> impleme
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
this.state.voiceBroadcastEnabled
|
type === VoiceBroadcastInfoEventType
|
||||||
&& type === VoiceBroadcastInfoEventType
|
|
||||||
&& content?.state === VoiceBroadcastInfoState.Started
|
&& content?.state === VoiceBroadcastInfoState.Started
|
||||||
) {
|
) {
|
||||||
BodyType = VoiceBroadcastBody;
|
BodyType = VoiceBroadcastBody;
|
||||||
|
|
|
@ -16,11 +16,9 @@ limitations under the License.
|
||||||
|
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { render, RenderResult } from "@testing-library/react";
|
import { render, RenderResult } from "@testing-library/react";
|
||||||
import { mocked } from "jest-mock";
|
|
||||||
import { MatrixClient, MatrixEvent, Room } from "matrix-js-sdk/src/matrix";
|
import { MatrixClient, MatrixEvent, Room } from "matrix-js-sdk/src/matrix";
|
||||||
|
|
||||||
import { Features } from "../../../../src/settings/Settings";
|
import SettingsStore from "../../../../src/settings/SettingsStore";
|
||||||
import SettingsStore, { CallbackFn } from "../../../../src/settings/SettingsStore";
|
|
||||||
import { VoiceBroadcastInfoEventType, VoiceBroadcastInfoState } from "../../../../src/voice-broadcast";
|
import { VoiceBroadcastInfoEventType, VoiceBroadcastInfoState } from "../../../../src/voice-broadcast";
|
||||||
import { mkEvent, mkRoom, stubClient } from "../../../test-utils";
|
import { mkEvent, mkRoom, stubClient } from "../../../test-utils";
|
||||||
import MessageEvent from "../../../../src/components/views/messages/MessageEvent";
|
import MessageEvent from "../../../../src/components/views/messages/MessageEvent";
|
||||||
|
@ -57,8 +55,7 @@ describe("MessageEvent", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("when a voice broadcast start event occurs", () => {
|
describe("when a voice broadcast start event occurs", () => {
|
||||||
const voiceBroadcastSettingWatcherRef = "vb ref";
|
let result: RenderResult;
|
||||||
let onVoiceBroadcastSettingChanged: CallbackFn;
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
event = mkEvent({
|
event = mkEvent({
|
||||||
|
@ -70,64 +67,11 @@ describe("MessageEvent", () => {
|
||||||
state: VoiceBroadcastInfoState.Started,
|
state: VoiceBroadcastInfoState.Started,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
result = renderMessageEvent();
|
||||||
mocked(SettingsStore.watchSetting).mockImplementation(
|
|
||||||
(settingName: string, roomId: string | null, callbackFn: CallbackFn) => {
|
|
||||||
if (settingName === Features.VoiceBroadcast) {
|
|
||||||
onVoiceBroadcastSettingChanged = callbackFn;
|
|
||||||
return voiceBroadcastSettingWatcherRef;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("and the voice broadcast feature is enabled", () => {
|
it("should render a VoiceBroadcast component", () => {
|
||||||
let result: RenderResult;
|
result.getByTestId("voice-broadcast-body");
|
||||||
|
|
||||||
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");
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue