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

Fix RoomUpgradeWarningBar exploding #7214

Merged
merged 1 commit into from
Nov 29, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions src/components/views/rooms/RoomUpgradeWarningBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import { RoomState } from 'matrix-js-sdk/src/models/room-state';
import Modal from '../../../Modal';

import { _t } from '../../../languageHandler';
import { MatrixClientPeg } from "../../../MatrixClientPeg";
import { replaceableComponent } from "../../../utils/replaceableComponent";
import RoomUpgradeDialog from '../dialogs/RoomUpgradeDialog';
import AccessibleButton from '../elements/AccessibleButton';
import MatrixClientContext from "../../../contexts/MatrixClientContext";

interface IProps {
room: Room;
Expand All @@ -37,18 +37,24 @@ interface IState {

@replaceableComponent("views.rooms.RoomUpgradeWarningBar")
export default class RoomUpgradeWarningBar extends React.PureComponent<IProps, IState> {
public componentDidMount(): void {
static contextType = MatrixClientContext;
public context!: React.ContextType<typeof MatrixClientContext>;

constructor(props, context) {
super(props, context);

const tombstone = this.props.room.currentState.getStateEvents("m.room.tombstone", "");
this.setState({ upgraded: tombstone && tombstone.getContent().replacement_room });
this.state = {
upgraded: tombstone?.getContent().replacement_room,
};
}

MatrixClientPeg.get().on("RoomState.events", this.onStateEvents);
public componentDidMount(): void {
this.context.on("RoomState.events", this.onStateEvents);
}

public componentWillUnmount(): void {
const cli = MatrixClientPeg.get();
if (cli) {
cli.removeListener("RoomState.events", this.onStateEvents);
}
this.context.removeListener("RoomState.events", this.onStateEvents);
}

private onStateEvents = (event: MatrixEvent, state: RoomState): void => {
Expand Down