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 { 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<IBodyProps, "onMessageAllowed" | "mediaEventHelper"> {
|
||||
|
@ -58,18 +56,10 @@ interface IProps extends Omit<IBodyProps, "onMessageAllowed" | "mediaEventHelper
|
|||
isSeeingThroughMessageHiddenForModeration?: boolean;
|
||||
}
|
||||
|
||||
interface State {
|
||||
voiceBroadcastEnabled: boolean;
|
||||
}
|
||||
|
||||
export interface IOperableEventTile {
|
||||
getEventTileOps(): IEventTileOps;
|
||||
}
|
||||
|
||||
interface State {
|
||||
voiceBroadcastEnabled: boolean;
|
||||
}
|
||||
|
||||
const baseBodyTypes = new Map<string, typeof React.Component>([
|
||||
[MsgType.Text, TextualBody],
|
||||
[MsgType.Notice, TextualBody],
|
||||
|
@ -87,7 +77,7 @@ const baseEvTypes = new Map<string, React.ComponentType<Partial<IBodyProps>>>([
|
|||
[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 mediaHelper: MediaEventHelper;
|
||||
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 context!: React.ContextType<typeof MatrixClientContext>;
|
||||
private voiceBroadcastSettingWatcherRef: string;
|
||||
|
||||
public constructor(props: IProps, context: React.ContextType<typeof MatrixClientContext>) {
|
||||
super(props, context);
|
||||
|
@ -105,29 +94,15 @@ export default class MessageEvent extends React.Component<IProps, State> 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<IProps>) {
|
||||
|
@ -171,16 +146,6 @@ export default class MessageEvent extends React.Component<IProps, State> 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<IProps, State> impleme
|
|||
}
|
||||
|
||||
if (
|
||||
this.state.voiceBroadcastEnabled
|
||||
&& type === VoiceBroadcastInfoEventType
|
||||
type === VoiceBroadcastInfoEventType
|
||||
&& content?.state === VoiceBroadcastInfoState.Started
|
||||
) {
|
||||
BodyType = VoiceBroadcastBody;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue