Improve typing around event emitter handlers (#7816)

This commit is contained in:
Michael Telatynski 2022-02-22 12:18:08 +00:00 committed by GitHub
parent 213b32bf14
commit 7fa01ffb06
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
79 changed files with 548 additions and 471 deletions

View file

@ -20,6 +20,10 @@ import { RoomMember } from "matrix-js-sdk/src/models/room-member";
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import { EventType } from "matrix-js-sdk/src/@types/event";
import { DeviceInfo } from "matrix-js-sdk/src/crypto/deviceinfo";
import { UserEvent } from "matrix-js-sdk/src/models/user";
import { CryptoEvent } from "matrix-js-sdk/src/crypto";
import { RoomStateEvent } from "matrix-js-sdk/src/models/room-state";
import { UserTrustLevel } from 'matrix-js-sdk/src/crypto/CrossSigning';
import SettingsStore from "../../../settings/SettingsStore";
import dis from "../../../dispatcher/dispatcher";
@ -67,7 +71,7 @@ export default class MemberTile extends React.Component<IProps, IState> {
if (SettingsStore.getValue("feature_custom_status")) {
const { user } = this.props.member;
if (user) {
user.on("User.unstable_statusMessage", this.onStatusMessageCommitted);
user.on(UserEvent._UnstableStatusMessage, this.onStatusMessageCommitted);
}
}
@ -78,12 +82,12 @@ export default class MemberTile extends React.Component<IProps, IState> {
isRoomEncrypted,
});
if (isRoomEncrypted) {
cli.on("userTrustStatusChanged", this.onUserTrustStatusChanged);
cli.on("deviceVerificationChanged", this.onDeviceVerificationChanged);
cli.on(CryptoEvent.UserTrustStatusChanged, this.onUserTrustStatusChanged);
cli.on(CryptoEvent.DeviceVerificationChanged, this.onDeviceVerificationChanged);
this.updateE2EStatus();
} else {
// Listen for room to become encrypted
cli.on("RoomState.events", this.onRoomStateEvents);
cli.on(RoomStateEvent.Events, this.onRoomStateEvents);
}
}
}
@ -93,16 +97,13 @@ export default class MemberTile extends React.Component<IProps, IState> {
const { user } = this.props.member;
if (user) {
user.removeListener(
"User.unstable_statusMessage",
this.onStatusMessageCommitted,
);
user.removeListener(UserEvent._UnstableStatusMessage, this.onStatusMessageCommitted);
}
if (cli) {
cli.removeListener("RoomState.events", this.onRoomStateEvents);
cli.removeListener("userTrustStatusChanged", this.onUserTrustStatusChanged);
cli.removeListener("deviceVerificationChanged", this.onDeviceVerificationChanged);
cli.removeListener(RoomStateEvent.Events, this.onRoomStateEvents);
cli.removeListener(CryptoEvent.UserTrustStatusChanged, this.onUserTrustStatusChanged);
cli.removeListener(CryptoEvent.DeviceVerificationChanged, this.onDeviceVerificationChanged);
}
}
@ -113,14 +114,14 @@ export default class MemberTile extends React.Component<IProps, IState> {
// The room is encrypted now.
const cli = MatrixClientPeg.get();
cli.removeListener("RoomState.events", this.onRoomStateEvents);
cli.removeListener(RoomStateEvent.Events, this.onRoomStateEvents);
this.setState({
isRoomEncrypted: true,
});
this.updateE2EStatus();
};
private onUserTrustStatusChanged = (userId: string, trustStatus: string): void => {
private onUserTrustStatusChanged = (userId: string, trustStatus: UserTrustLevel): void => {
if (userId !== this.props.member.userId) return;
this.updateE2EStatus();
};