Improve typing around event emitter handlers (#7816)
This commit is contained in:
parent
213b32bf14
commit
7fa01ffb06
79 changed files with 548 additions and 471 deletions
|
@ -15,7 +15,14 @@ limitations under the License.
|
|||
*/
|
||||
|
||||
import React, { ComponentType, createRef } from 'react';
|
||||
import { createClient, EventType, MatrixClient } from 'matrix-js-sdk/src/matrix';
|
||||
import {
|
||||
ClientEvent,
|
||||
createClient,
|
||||
EventType,
|
||||
HttpApiEvent,
|
||||
MatrixClient,
|
||||
MatrixEventEvent,
|
||||
} from 'matrix-js-sdk/src/matrix';
|
||||
import { ISyncStateData, SyncState } from 'matrix-js-sdk/src/sync';
|
||||
import { MatrixError } from 'matrix-js-sdk/src/http-api';
|
||||
import { InvalidStoreError } from "matrix-js-sdk/src/errors";
|
||||
|
@ -23,6 +30,7 @@ import { MatrixEvent } from "matrix-js-sdk/src/models/event";
|
|||
import { defer, IDeferred, QueryDict } from "matrix-js-sdk/src/utils";
|
||||
import { logger } from "matrix-js-sdk/src/logger";
|
||||
import { throttle } from "lodash";
|
||||
import { CryptoEvent } from "matrix-js-sdk/src/crypto";
|
||||
|
||||
// focus-visible is a Polyfill for the :focus-visible CSS pseudo-attribute used by _AccessibleButton.scss
|
||||
import 'focus-visible';
|
||||
|
@ -1246,10 +1254,10 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
|
|||
const saveWelcomeUser = (ev: MatrixEvent) => {
|
||||
if (ev.getType() === EventType.Direct && ev.getContent()[this.props.config.welcomeUserId]) {
|
||||
MatrixClientPeg.get().store.save(true);
|
||||
MatrixClientPeg.get().removeListener("accountData", saveWelcomeUser);
|
||||
MatrixClientPeg.get().removeListener(ClientEvent.AccountData, saveWelcomeUser);
|
||||
}
|
||||
};
|
||||
MatrixClientPeg.get().on("accountData", saveWelcomeUser);
|
||||
MatrixClientPeg.get().on(ClientEvent.AccountData, saveWelcomeUser);
|
||||
|
||||
return roomId;
|
||||
}
|
||||
|
@ -1432,7 +1440,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
|
|||
return this.loggedInView.current.canResetTimelineInRoom(roomId);
|
||||
});
|
||||
|
||||
cli.on('sync', (state: SyncState, prevState?: SyncState, data?: ISyncStateData) => {
|
||||
cli.on(ClientEvent.Sync, (state: SyncState, prevState?: SyncState, data?: ISyncStateData) => {
|
||||
if (state === SyncState.Error || state === SyncState.Reconnecting) {
|
||||
if (data.error instanceof InvalidStoreError) {
|
||||
Lifecycle.handleInvalidStoreError(data.error);
|
||||
|
@ -1497,7 +1505,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
|
|||
});
|
||||
});
|
||||
|
||||
cli.on('Session.logged_out', function(errObj) {
|
||||
cli.on(HttpApiEvent.SessionLoggedOut, function(errObj) {
|
||||
if (Lifecycle.isLoggingOut()) return;
|
||||
|
||||
// A modal might have been open when we were logged out by the server
|
||||
|
@ -1518,7 +1526,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
|
|||
action: 'logout',
|
||||
});
|
||||
});
|
||||
cli.on('no_consent', function(message, consentUri) {
|
||||
cli.on(HttpApiEvent.NoConsent, function(message, consentUri) {
|
||||
Modal.createTrackedDialog('No Consent Dialog', '', QuestionDialog, {
|
||||
title: _t('Terms and Conditions'),
|
||||
description: <div>
|
||||
|
@ -1549,10 +1557,10 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
|
|||
dft.start();
|
||||
|
||||
// When logging out, stop tracking failures and destroy state
|
||||
cli.on("Session.logged_out", () => dft.stop());
|
||||
cli.on("Event.decrypted", (e, err) => dft.eventDecrypted(e, err));
|
||||
cli.on(HttpApiEvent.SessionLoggedOut, () => dft.stop());
|
||||
cli.on(MatrixEventEvent.Decrypted, (e, err) => dft.eventDecrypted(e, err as MatrixError));
|
||||
|
||||
cli.on("Room", (room) => {
|
||||
cli.on(ClientEvent.Room, (room) => {
|
||||
if (MatrixClientPeg.get().isCryptoEnabled()) {
|
||||
const blacklistEnabled = SettingsStore.getValueAt(
|
||||
SettingLevel.ROOM_DEVICE,
|
||||
|
@ -1563,7 +1571,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
|
|||
room.setBlacklistUnverifiedDevices(blacklistEnabled);
|
||||
}
|
||||
});
|
||||
cli.on("crypto.warning", (type) => {
|
||||
cli.on(CryptoEvent.Warning, (type) => {
|
||||
switch (type) {
|
||||
case 'CRYPTO_WARNING_OLD_VERSION_DETECTED':
|
||||
Modal.createTrackedDialog('Crypto migrated', '', ErrorDialog, {
|
||||
|
@ -1582,7 +1590,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
|
|||
break;
|
||||
}
|
||||
});
|
||||
cli.on("crypto.keyBackupFailed", async (errcode) => {
|
||||
cli.on(CryptoEvent.KeyBackupFailed, async (errcode) => {
|
||||
let haveNewVersion;
|
||||
let newVersionInfo;
|
||||
// if key backup is still enabled, there must be a new backup in place
|
||||
|
@ -1615,7 +1623,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
|
|||
}
|
||||
});
|
||||
|
||||
cli.on("crypto.keySignatureUploadFailure", (failures, source, continuation) => {
|
||||
cli.on(CryptoEvent.KeySignatureUploadFailure, (failures, source, continuation) => {
|
||||
Modal.createTrackedDialog(
|
||||
'Failed to upload key signatures',
|
||||
'Failed to upload key signatures',
|
||||
|
@ -1623,7 +1631,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
|
|||
{ failures, source, continuation });
|
||||
});
|
||||
|
||||
cli.on("crypto.verification.request", request => {
|
||||
cli.on(CryptoEvent.VerificationRequest, request => {
|
||||
if (request.verifier) {
|
||||
Modal.createTrackedDialog('Incoming Verification', '', IncomingSasDialog, {
|
||||
verifier: request.verifier,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue