Step 3.2: Stop using getComponent
in code
This commit is contained in:
parent
d977865b8e
commit
b667ef9f18
18 changed files with 54 additions and 93 deletions
|
@ -20,7 +20,6 @@ import { Relations } from 'matrix-js-sdk/src/models/relations';
|
|||
import { M_LOCATION } from 'matrix-js-sdk/src/@types/location';
|
||||
import { M_POLL_START } from "matrix-events-sdk";
|
||||
|
||||
import * as sdk from '../../../index';
|
||||
import SettingsStore from "../../../settings/SettingsStore";
|
||||
import { Mjolnir } from "../../../mjolnir/Mjolnir";
|
||||
import RedactedBody from "./RedactedBody";
|
||||
|
@ -31,6 +30,15 @@ import { MediaEventHelper } from "../../../utils/MediaEventHelper";
|
|||
import { ReactAnyComponent } from "../../../@types/common";
|
||||
import { IBodyProps } from "./IBodyProps";
|
||||
import MatrixClientContext from '../../../contexts/MatrixClientContext';
|
||||
import TextualBody from "./TextualBody";
|
||||
import MImageBody from "./MImageBody";
|
||||
import MFileBody from "./MFileBody";
|
||||
import MVoiceOrAudioBody from "./MVoiceOrAudioBody";
|
||||
import MVideoBody from "./MVideoBody";
|
||||
import MStickerBody from "./MStickerBody";
|
||||
import MPollBody from "./MPollBody";
|
||||
import MLocationBody from "./MLocationBody";
|
||||
import MjolnirBody from "./MjolnirBody";
|
||||
|
||||
// onMessageAllowed is handled internally
|
||||
interface IProps extends Omit<IBodyProps, "onMessageAllowed"> {
|
||||
|
@ -70,23 +78,25 @@ export default class MessageEvent extends React.Component<IProps> implements IMe
|
|||
}
|
||||
}
|
||||
|
||||
private get bodyTypes(): Record<string, React.Component> {
|
||||
private get bodyTypes(): Record<string, typeof React.Component> {
|
||||
return {
|
||||
[MsgType.Text]: sdk.getComponent('messages.TextualBody'),
|
||||
[MsgType.Notice]: sdk.getComponent('messages.TextualBody'),
|
||||
[MsgType.Emote]: sdk.getComponent('messages.TextualBody'),
|
||||
[MsgType.Image]: sdk.getComponent('messages.MImageBody'),
|
||||
[MsgType.File]: sdk.getComponent('messages.MFileBody'),
|
||||
[MsgType.Audio]: sdk.getComponent('messages.MVoiceOrAudioBody'),
|
||||
[MsgType.Video]: sdk.getComponent('messages.MVideoBody'),
|
||||
[MsgType.Text]: TextualBody,
|
||||
[MsgType.Notice]: TextualBody,
|
||||
[MsgType.Emote]: TextualBody,
|
||||
[MsgType.Image]: MImageBody,
|
||||
[MsgType.File]: MFileBody,
|
||||
[MsgType.Audio]: MVoiceOrAudioBody,
|
||||
[MsgType.Video]: MVideoBody,
|
||||
|
||||
...(this.props.overrideBodyTypes || {}),
|
||||
};
|
||||
}
|
||||
|
||||
private get evTypes(): Record<string, React.Component> {
|
||||
private get evTypes(): Record<string, typeof React.Component> {
|
||||
return {
|
||||
[EventType.Sticker]: sdk.getComponent('messages.MStickerBody'),
|
||||
[EventType.Sticker]: MStickerBody,
|
||||
[M_POLL_START.name]: MPollBody,
|
||||
[M_POLL_START.altName]: MPollBody,
|
||||
|
||||
...(this.props.overrideEventTypes || {}),
|
||||
};
|
||||
|
@ -108,7 +118,7 @@ export default class MessageEvent extends React.Component<IProps> implements IMe
|
|||
const content = this.props.mxEvent.getContent();
|
||||
const type = this.props.mxEvent.getType();
|
||||
const msgtype = content.msgtype;
|
||||
let BodyType: ReactAnyComponent = RedactedBody;
|
||||
let BodyType: typeof React.Component | ReactAnyComponent = RedactedBody;
|
||||
if (!this.props.mxEvent.isRedacted()) {
|
||||
// only resolve BodyType if event is not redacted
|
||||
if (type && this.evTypes[type]) {
|
||||
|
@ -123,17 +133,12 @@ export default class MessageEvent extends React.Component<IProps> implements IMe
|
|||
BodyType = UnknownBody;
|
||||
}
|
||||
|
||||
// TODO: move to eventTypes when Polls spec stabilises
|
||||
if (M_POLL_START.matches(type)) {
|
||||
BodyType = sdk.getComponent('messages.MPollBody');
|
||||
}
|
||||
|
||||
// TODO: move to eventTypes when location sharing spec stabilises
|
||||
if (
|
||||
M_LOCATION.matches(type) ||
|
||||
(type === EventType.RoomMessage && msgtype === MsgType.Location)
|
||||
) {
|
||||
BodyType = sdk.getComponent('messages.MLocationBody');
|
||||
BodyType = MLocationBody;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -147,7 +152,7 @@ export default class MessageEvent extends React.Component<IProps> implements IMe
|
|||
const serverBanned = Mjolnir.sharedInstance().isServerBanned(userDomain);
|
||||
|
||||
if (userBanned || serverBanned) {
|
||||
BodyType = sdk.getComponent('messages.MjolnirBody');
|
||||
BodyType = MjolnirBody;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue