Fix RoomUpgradeWarningBar exploding (#7214)
This commit is contained in:
parent
dbd148489d
commit
3ffe752730
1 changed files with 15 additions and 9 deletions
|
@ -22,10 +22,10 @@ import { RoomState } from 'matrix-js-sdk/src/models/room-state';
|
||||||
import Modal from '../../../Modal';
|
import Modal from '../../../Modal';
|
||||||
|
|
||||||
import { _t } from '../../../languageHandler';
|
import { _t } from '../../../languageHandler';
|
||||||
import { MatrixClientPeg } from "../../../MatrixClientPeg";
|
|
||||||
import { replaceableComponent } from "../../../utils/replaceableComponent";
|
import { replaceableComponent } from "../../../utils/replaceableComponent";
|
||||||
import RoomUpgradeDialog from '../dialogs/RoomUpgradeDialog';
|
import RoomUpgradeDialog from '../dialogs/RoomUpgradeDialog';
|
||||||
import AccessibleButton from '../elements/AccessibleButton';
|
import AccessibleButton from '../elements/AccessibleButton';
|
||||||
|
import MatrixClientContext from "../../../contexts/MatrixClientContext";
|
||||||
|
|
||||||
interface IProps {
|
interface IProps {
|
||||||
room: Room;
|
room: Room;
|
||||||
|
@ -37,18 +37,24 @@ interface IState {
|
||||||
|
|
||||||
@replaceableComponent("views.rooms.RoomUpgradeWarningBar")
|
@replaceableComponent("views.rooms.RoomUpgradeWarningBar")
|
||||||
export default class RoomUpgradeWarningBar extends React.PureComponent<IProps, IState> {
|
export default class RoomUpgradeWarningBar extends React.PureComponent<IProps, IState> {
|
||||||
public componentDidMount(): void {
|
static contextType = MatrixClientContext;
|
||||||
const tombstone = this.props.room.currentState.getStateEvents("m.room.tombstone", "");
|
public context!: React.ContextType<typeof MatrixClientContext>;
|
||||||
this.setState({ upgraded: tombstone && tombstone.getContent().replacement_room });
|
|
||||||
|
|
||||||
MatrixClientPeg.get().on("RoomState.events", this.onStateEvents);
|
constructor(props, context) {
|
||||||
|
super(props, context);
|
||||||
|
|
||||||
|
const tombstone = this.props.room.currentState.getStateEvents("m.room.tombstone", "");
|
||||||
|
this.state = {
|
||||||
|
upgraded: tombstone?.getContent().replacement_room,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public componentDidMount(): void {
|
||||||
|
this.context.on("RoomState.events", this.onStateEvents);
|
||||||
}
|
}
|
||||||
|
|
||||||
public componentWillUnmount(): void {
|
public componentWillUnmount(): void {
|
||||||
const cli = MatrixClientPeg.get();
|
this.context.removeListener("RoomState.events", this.onStateEvents);
|
||||||
if (cli) {
|
|
||||||
cli.removeListener("RoomState.events", this.onStateEvents);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private onStateEvents = (event: MatrixEvent, state: RoomState): void => {
|
private onStateEvents = (event: MatrixEvent, state: RoomState): void => {
|
||||||
|
|
Loading…
Reference in a new issue