Use MatrixClientContext

Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>
pull/21833/head
Šimon Brandner 2021-09-13 18:28:52 +02:00
parent 807792dc69
commit 8a86407a4c
No known key found for this signature in database
GPG Key ID: 55C211A1226CB17D
1 changed files with 11 additions and 8 deletions

View File

@ -16,7 +16,6 @@ limitations under the License.
import React from 'react'; import React from 'react';
import { _t, _td } from '../../languageHandler'; import { _t, _td } from '../../languageHandler';
import { MatrixClientPeg } from '../../MatrixClientPeg';
import Resend from '../../Resend'; import Resend from '../../Resend';
import dis from '../../dispatcher/dispatcher'; import dis from '../../dispatcher/dispatcher';
import { messageForResourceLimitError } from '../../utils/ErrorUtils'; import { messageForResourceLimitError } from '../../utils/ErrorUtils';
@ -30,6 +29,7 @@ import InlineSpinner from "../views/elements/InlineSpinner";
import { SyncState } from "matrix-js-sdk/src/sync.api"; import { SyncState } from "matrix-js-sdk/src/sync.api";
import { ISyncStateData } from "matrix-js-sdk/src/sync"; import { ISyncStateData } from "matrix-js-sdk/src/sync";
import { Room } from "matrix-js-sdk/src/models/room"; import { Room } from "matrix-js-sdk/src/models/room";
import MatrixClientContext from "../../contexts/MatrixClientContext";
const STATUS_BAR_HIDDEN = 0; const STATUS_BAR_HIDDEN = 0;
const STATUS_BAR_EXPANDED = 1; const STATUS_BAR_EXPANDED = 1;
@ -84,20 +84,23 @@ interface IState {
@replaceableComponent("structures.RoomStatusBar") @replaceableComponent("structures.RoomStatusBar")
export default class RoomStatusBar extends React.PureComponent<IProps, IState> { export default class RoomStatusBar extends React.PureComponent<IProps, IState> {
constructor(props: IProps) { public static contextType = MatrixClientContext;
super(props);
constructor(props: IProps, context: typeof MatrixClientContext) {
super(props, context);
this.state = { this.state = {
syncState: MatrixClientPeg.get().getSyncState(), syncState: this.context.getSyncState(),
syncStateData: MatrixClientPeg.get().getSyncStateData(), syncStateData: this.context.getSyncStateData(),
unsentMessages: getUnsentMessages(this.props.room), unsentMessages: getUnsentMessages(this.props.room),
isResending: false, isResending: false,
}; };
} }
public componentDidMount(): void { public componentDidMount(): void {
MatrixClientPeg.get().on("sync", this.onSyncStateChange); const client = this.context;
MatrixClientPeg.get().on("Room.localEchoUpdated", this.onRoomLocalEchoUpdated); client.on("sync", this.onSyncStateChange);
client.on("Room.localEchoUpdated", this.onRoomLocalEchoUpdated);
this.checkSize(); this.checkSize();
} }
@ -108,7 +111,7 @@ export default class RoomStatusBar extends React.PureComponent<IProps, IState> {
public componentWillUnmount(): void { public componentWillUnmount(): void {
// we may have entirely lost our client as we're logging out before clicking login on the guest bar... // we may have entirely lost our client as we're logging out before clicking login on the guest bar...
const client = MatrixClientPeg.get(); const client = this.context;
if (client) { if (client) {
client.removeListener("sync", this.onSyncStateChange); client.removeListener("sync", this.onSyncStateChange);
client.removeListener("Room.localEchoUpdated", this.onRoomLocalEchoUpdated); client.removeListener("Room.localEchoUpdated", this.onRoomLocalEchoUpdated);