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

@ -19,14 +19,22 @@ limitations under the License.
import React from 'react';
import { base32 } from "rfc4648";
import { MatrixCall, CallErrorCode, CallState, CallEvent, CallParty, CallType } from "matrix-js-sdk/src/webrtc/call";
import { CallError } from "matrix-js-sdk/src/webrtc/call";
import {
CallError,
CallErrorCode,
CallEvent,
CallParty,
CallState,
CallType,
MatrixCall,
} from "matrix-js-sdk/src/webrtc/call";
import { logger } from 'matrix-js-sdk/src/logger';
import { randomUppercaseString, randomLowercaseString } from "matrix-js-sdk/src/randomstring";
import { randomLowercaseString, randomUppercaseString } from "matrix-js-sdk/src/randomstring";
import EventEmitter from 'events';
import { RuleId, TweakName, Tweaks } from "matrix-js-sdk/src/@types/PushRules";
import { PushProcessor } from 'matrix-js-sdk/src/pushprocessor';
import { SyncState } from "matrix-js-sdk/src/sync";
import { CallEventHandlerEvent } from "matrix-js-sdk/src/webrtc/callEventHandler";
import { MatrixClientPeg } from './MatrixClientPeg';
import Modal from './Modal';
@ -50,10 +58,9 @@ import VoipUserMapper from './VoipUserMapper';
import { addManagedHybridWidget, isManagedHybridWidgetEnabled } from './widgets/ManagedHybrid';
import SdkConfig from './SdkConfig';
import { ensureDMExists, findDMForUser } from './createRoom';
import { WidgetLayoutStore, Container } from './stores/widgets/WidgetLayoutStore';
import { getIncomingCallToastKey } from './toasts/IncomingCallToast';
import { Container, WidgetLayoutStore } from './stores/widgets/WidgetLayoutStore';
import IncomingCallToast, { getIncomingCallToastKey } from './toasts/IncomingCallToast';
import ToastStore from './stores/ToastStore';
import IncomingCallToast from "./toasts/IncomingCallToast";
import Resend from './Resend';
import { ViewRoomPayload } from "./dispatcher/payloads/ViewRoomPayload";
@ -172,7 +179,7 @@ export default class CallHandler extends EventEmitter {
}
if (SettingsStore.getValue(UIFeature.Voip)) {
MatrixClientPeg.get().on('Call.incoming', this.onCallIncoming);
MatrixClientPeg.get().on(CallEventHandlerEvent.Incoming, this.onCallIncoming);
}
this.checkProtocols(CHECK_PROTOCOLS_ATTEMPTS);
@ -181,7 +188,7 @@ export default class CallHandler extends EventEmitter {
public stop(): void {
const cli = MatrixClientPeg.get();
if (cli) {
cli.removeListener('Call.incoming', this.onCallIncoming);
cli.removeListener(CallEventHandlerEvent.Incoming, this.onCallIncoming);
}
}

View file

@ -16,6 +16,8 @@ limitations under the License.
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import { logger } from "matrix-js-sdk/src/logger";
import { CryptoEvent } from "matrix-js-sdk/src/crypto";
import { ClientEvent, RoomStateEvent } from "matrix-js-sdk/src/matrix";
import { MatrixClientPeg } from './MatrixClientPeg';
import dis from "./dispatcher/dispatcher";
@ -32,7 +34,7 @@ import {
hideToast as hideUnverifiedSessionsToast,
showToast as showUnverifiedSessionsToast,
} from "./toasts/UnverifiedSessionToast";
import { isSecretStorageBeingAccessed, accessSecretStorage } from "./SecurityManager";
import { accessSecretStorage, isSecretStorageBeingAccessed } from "./SecurityManager";
import { isSecureBackupRequired } from './utils/WellKnownUtils';
import { isLoggedIn } from './components/structures/MatrixChat';
import { ActionPayload } from "./dispatcher/payloads";
@ -63,28 +65,31 @@ export default class DeviceListener {
}
start() {
MatrixClientPeg.get().on('crypto.willUpdateDevices', this.onWillUpdateDevices);
MatrixClientPeg.get().on('crypto.devicesUpdated', this.onDevicesUpdated);
MatrixClientPeg.get().on('deviceVerificationChanged', this.onDeviceVerificationChanged);
MatrixClientPeg.get().on('userTrustStatusChanged', this.onUserTrustStatusChanged);
MatrixClientPeg.get().on('crossSigning.keysChanged', this.onCrossSingingKeysChanged);
MatrixClientPeg.get().on('accountData', this.onAccountData);
MatrixClientPeg.get().on('sync', this.onSync);
MatrixClientPeg.get().on('RoomState.events', this.onRoomStateEvents);
MatrixClientPeg.get().on(CryptoEvent.WillUpdateDevices, this.onWillUpdateDevices);
MatrixClientPeg.get().on(CryptoEvent.DevicesUpdated, this.onDevicesUpdated);
MatrixClientPeg.get().on(CryptoEvent.DeviceVerificationChanged, this.onDeviceVerificationChanged);
MatrixClientPeg.get().on(CryptoEvent.UserTrustStatusChanged, this.onUserTrustStatusChanged);
MatrixClientPeg.get().on(CryptoEvent.KeysChanged, this.onCrossSingingKeysChanged);
MatrixClientPeg.get().on(ClientEvent.AccountData, this.onAccountData);
MatrixClientPeg.get().on(ClientEvent.Sync, this.onSync);
MatrixClientPeg.get().on(RoomStateEvent.Events, this.onRoomStateEvents);
this.dispatcherRef = dis.register(this.onAction);
this.recheck();
}
stop() {
if (MatrixClientPeg.get()) {
MatrixClientPeg.get().removeListener('crypto.willUpdateDevices', this.onWillUpdateDevices);
MatrixClientPeg.get().removeListener('crypto.devicesUpdated', this.onDevicesUpdated);
MatrixClientPeg.get().removeListener('deviceVerificationChanged', this.onDeviceVerificationChanged);
MatrixClientPeg.get().removeListener('userTrustStatusChanged', this.onUserTrustStatusChanged);
MatrixClientPeg.get().removeListener('crossSigning.keysChanged', this.onCrossSingingKeysChanged);
MatrixClientPeg.get().removeListener('accountData', this.onAccountData);
MatrixClientPeg.get().removeListener('sync', this.onSync);
MatrixClientPeg.get().removeListener('RoomState.events', this.onRoomStateEvents);
MatrixClientPeg.get().removeListener(CryptoEvent.WillUpdateDevices, this.onWillUpdateDevices);
MatrixClientPeg.get().removeListener(CryptoEvent.DevicesUpdated, this.onDevicesUpdated);
MatrixClientPeg.get().removeListener(
CryptoEvent.DeviceVerificationChanged,
this.onDeviceVerificationChanged,
);
MatrixClientPeg.get().removeListener(CryptoEvent.UserTrustStatusChanged, this.onUserTrustStatusChanged);
MatrixClientPeg.get().removeListener(CryptoEvent.KeysChanged, this.onCrossSingingKeysChanged);
MatrixClientPeg.get().removeListener(ClientEvent.AccountData, this.onAccountData);
MatrixClientPeg.get().removeListener(ClientEvent.Sync, this.onSync);
MatrixClientPeg.get().removeListener(RoomStateEvent.Events, this.onRoomStateEvents);
}
if (this.dispatcherRef) {
dis.unregister(this.dispatcherRef);

View file

@ -17,8 +17,9 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import { Room } from "matrix-js-sdk/src/models/room";
import { MatrixEvent, MatrixEventEvent } from "matrix-js-sdk/src/models/event";
import { Room, RoomEvent } from "matrix-js-sdk/src/models/room";
import { ClientEvent } from "matrix-js-sdk/src/client";
import { logger } from "matrix-js-sdk/src/logger";
import { MsgType } from "matrix-js-sdk/src/@types/event";
import { LOCATION_EVENT_TYPE } from "matrix-js-sdk/src/@types/location";
@ -201,20 +202,20 @@ export const Notifier = {
this.boundOnRoomReceipt = this.boundOnRoomReceipt || this.onRoomReceipt.bind(this);
this.boundOnEventDecrypted = this.boundOnEventDecrypted || this.onEventDecrypted.bind(this);
MatrixClientPeg.get().on('event', this.boundOnEvent);
MatrixClientPeg.get().on('Room.receipt', this.boundOnRoomReceipt);
MatrixClientPeg.get().on('Event.decrypted', this.boundOnEventDecrypted);
MatrixClientPeg.get().on("sync", this.boundOnSyncStateChange);
MatrixClientPeg.get().on(ClientEvent.Event, this.boundOnEvent);
MatrixClientPeg.get().on(RoomEvent.Receipt, this.boundOnRoomReceipt);
MatrixClientPeg.get().on(MatrixEventEvent.Decrypted, this.boundOnEventDecrypted);
MatrixClientPeg.get().on(ClientEvent.Sync, this.boundOnSyncStateChange);
this.toolbarHidden = false;
this.isSyncing = false;
},
stop: function() {
if (MatrixClientPeg.get()) {
MatrixClientPeg.get().removeListener('Event', this.boundOnEvent);
MatrixClientPeg.get().removeListener('Room.receipt', this.boundOnRoomReceipt);
MatrixClientPeg.get().removeListener('Event.decrypted', this.boundOnEventDecrypted);
MatrixClientPeg.get().removeListener('sync', this.boundOnSyncStateChange);
MatrixClientPeg.get().removeListener(ClientEvent.Event, this.boundOnEvent);
MatrixClientPeg.get().removeListener(RoomEvent.Receipt, this.boundOnRoomReceipt);
MatrixClientPeg.get().removeListener(MatrixEventEvent.Decrypted, this.boundOnEventDecrypted);
MatrixClientPeg.get().removeListener(ClientEvent.Sync, this.boundOnSyncStateChange);
}
this.isSyncing = false;
},

View file

@ -14,9 +14,9 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import { MatrixClient } from "matrix-js-sdk/src/client";
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import { Room } from "matrix-js-sdk/src/models/room";
import { ClientEvent, MatrixClient } from "matrix-js-sdk/src/client";
import { MatrixEvent, MatrixEventEvent } from "matrix-js-sdk/src/models/event";
import { Room, RoomEvent } from "matrix-js-sdk/src/models/room";
import { IRoomTimelineData } from "matrix-js-sdk/src/models/event-timeline-set";
import dis from "../dispatcher/dispatcher";
@ -274,7 +274,11 @@ let matrixClientListenersStop: Listener[] = [];
* when given the MatrixClient as an argument as well as
* arguments emitted in the MatrixClient event.
*/
function addMatrixClientListener(matrixClient: MatrixClient, eventName: string, actionCreator: ActionCreator): void {
function addMatrixClientListener(
matrixClient: MatrixClient,
eventName: Parameters<MatrixClient["emit"]>[0],
actionCreator: ActionCreator,
): void {
const listener: Listener = (...args) => {
const payload = actionCreator(matrixClient, ...args);
if (payload) {
@ -298,15 +302,15 @@ export default {
* @param {MatrixClient} matrixClient the MatrixClient to listen to events from
*/
start(matrixClient: MatrixClient) {
addMatrixClientListener(matrixClient, 'sync', createSyncAction);
addMatrixClientListener(matrixClient, 'accountData', createAccountDataAction);
addMatrixClientListener(matrixClient, 'Room.accountData', createRoomAccountDataAction);
addMatrixClientListener(matrixClient, 'Room', createRoomAction);
addMatrixClientListener(matrixClient, 'Room.tags', createRoomTagsAction);
addMatrixClientListener(matrixClient, 'Room.receipt', createRoomReceiptAction);
addMatrixClientListener(matrixClient, 'Room.timeline', createRoomTimelineAction);
addMatrixClientListener(matrixClient, 'Room.myMembership', createSelfMembershipAction);
addMatrixClientListener(matrixClient, 'Event.decrypted', createEventDecryptedAction);
addMatrixClientListener(matrixClient, ClientEvent.Sync, createSyncAction);
addMatrixClientListener(matrixClient, ClientEvent.AccountData, createAccountDataAction);
addMatrixClientListener(matrixClient, RoomEvent.AccountData, createRoomAccountDataAction);
addMatrixClientListener(matrixClient, ClientEvent.Room, createRoomAction);
addMatrixClientListener(matrixClient, RoomEvent.Tags, createRoomTagsAction);
addMatrixClientListener(matrixClient, RoomEvent.Receipt, createRoomReceiptAction);
addMatrixClientListener(matrixClient, RoomEvent.Timeline, createRoomTimelineAction);
addMatrixClientListener(matrixClient, RoomEvent.MyMembership, createSelfMembershipAction);
addMatrixClientListener(matrixClient, MatrixEventEvent.Decrypted, createEventDecryptedAction);
},
/**

View file

@ -22,6 +22,7 @@ import { IKeyBackupInfo } from "matrix-js-sdk/src/crypto/keybackup";
import { TrustInfo } from "matrix-js-sdk/src/crypto/backup";
import { CrossSigningKeys } from "matrix-js-sdk/src";
import { IRecoveryKey } from "matrix-js-sdk/src/crypto/api";
import { CryptoEvent } from "matrix-js-sdk/src/crypto";
import { MatrixClientPeg } from '../../../../MatrixClientPeg';
import { _t, _td } from '../../../../languageHandler';
@ -145,13 +146,13 @@ export default class CreateSecretStorageDialog extends React.PureComponent<IProp
accountPassword,
};
MatrixClientPeg.get().on('crypto.keyBackupStatus', this.onKeyBackupStatusChange);
MatrixClientPeg.get().on(CryptoEvent.KeyBackupStatus, this.onKeyBackupStatusChange);
this.getInitialPhase();
}
public componentWillUnmount(): void {
MatrixClientPeg.get().removeListener('crypto.keyBackupStatus', this.onKeyBackupStatusChange);
MatrixClientPeg.get().removeListener(CryptoEvent.KeyBackupStatus, this.onKeyBackupStatusChange);
}
private getInitialPhase(): void {

View file

@ -20,9 +20,9 @@ limitations under the License.
import React from 'react';
import { sortBy } from 'lodash';
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import { Room } from "matrix-js-sdk/src/models/room";
import { Room, RoomEvent } from "matrix-js-sdk/src/models/room";
import { RoomMember } from "matrix-js-sdk/src/models/room-member";
import { RoomState } from "matrix-js-sdk/src/models/room-state";
import { RoomState, RoomStateEvent } from "matrix-js-sdk/src/models/room-state";
import { IRoomTimelineData } from "matrix-js-sdk/src/models/event-timeline-set";
import { MatrixClientPeg } from '../MatrixClientPeg';
@ -60,14 +60,14 @@ export default class UserProvider extends AutocompleteProvider {
shouldMatchWordsOnly: false,
});
MatrixClientPeg.get().on("Room.timeline", this.onRoomTimeline);
MatrixClientPeg.get().on("RoomState.members", this.onRoomStateMember);
MatrixClientPeg.get().on(RoomEvent.Timeline, this.onRoomTimeline);
MatrixClientPeg.get().on(RoomStateEvent.Members, this.onRoomStateMember);
}
destroy() {
if (MatrixClientPeg.get()) {
MatrixClientPeg.get().removeListener("Room.timeline", this.onRoomTimeline);
MatrixClientPeg.get().removeListener("RoomState.members", this.onRoomStateMember);
MatrixClientPeg.get().removeListener(RoomEvent.Timeline, this.onRoomTimeline);
MatrixClientPeg.get().removeListener(RoomStateEvent.Members, this.onRoomStateMember);
}
}

View file

@ -19,8 +19,8 @@ import React from 'react';
import { Filter } from 'matrix-js-sdk/src/filter';
import { EventTimelineSet, IRoomTimelineData } from "matrix-js-sdk/src/models/event-timeline-set";
import { Direction } from "matrix-js-sdk/src/models/event-timeline";
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import { Room } from 'matrix-js-sdk/src/models/room';
import { MatrixEvent, MatrixEventEvent } from "matrix-js-sdk/src/models/event";
import { Room, RoomEvent } from 'matrix-js-sdk/src/models/room';
import { TimelineWindow } from 'matrix-js-sdk/src/timeline-window';
import { logger } from "matrix-js-sdk/src/logger";
@ -121,8 +121,8 @@ class FilePanel extends React.Component<IProps, IState> {
// this could be made more general in the future or the filter logic
// could be fixed.
if (EventIndexPeg.get() !== null) {
client.on('Room.timeline', this.onRoomTimeline);
client.on('Event.decrypted', this.onEventDecrypted);
client.on(RoomEvent.Timeline, this.onRoomTimeline);
client.on(MatrixEventEvent.Decrypted, this.onEventDecrypted);
}
}
@ -133,8 +133,8 @@ class FilePanel extends React.Component<IProps, IState> {
if (!MatrixClientPeg.get().isRoomEncrypted(this.props.roomId)) return;
if (EventIndexPeg.get() !== null) {
client.removeListener('Room.timeline', this.onRoomTimeline);
client.removeListener('Event.decrypted', this.onEventDecrypted);
client.removeListener(RoomEvent.Timeline, this.onRoomTimeline);
client.removeListener(MatrixEventEvent.Decrypted, this.onEventDecrypted);
}
}

View file

@ -15,12 +15,13 @@ limitations under the License.
*/
import React, { ClipboardEvent } from 'react';
import { MatrixClient } from 'matrix-js-sdk/src/client';
import { ClientEvent, MatrixClient } from 'matrix-js-sdk/src/client';
import { MatrixEvent } from 'matrix-js-sdk/src/models/event';
import { MatrixCall } from 'matrix-js-sdk/src/webrtc/call';
import classNames from 'classnames';
import { ISyncStateData, SyncState } from 'matrix-js-sdk/src/sync';
import { IUsageLimit } from 'matrix-js-sdk/src/@types/partials';
import { RoomStateEvent } from "matrix-js-sdk/src/models/room-state";
import { Key } from '../../Keyboard';
import PageTypes from '../../PageTypes';
@ -174,15 +175,15 @@ class LoggedInView extends React.Component<IProps, IState> {
this.updateServerNoticeEvents();
this._matrixClient.on("accountData", this.onAccountData);
this._matrixClient.on("sync", this.onSync);
this._matrixClient.on(ClientEvent.AccountData, this.onAccountData);
this._matrixClient.on(ClientEvent.Sync, this.onSync);
// Call `onSync` with the current state as well
this.onSync(
this._matrixClient.getSyncState(),
null,
this._matrixClient.getSyncStateData(),
);
this._matrixClient.on("RoomState.events", this.onRoomStateEvents);
this._matrixClient.on(RoomStateEvent.Events, this.onRoomStateEvents);
this.layoutWatcherRef = SettingsStore.watchSetting("layout", null, this.onCompactLayoutChanged);
this.compactLayoutWatcherRef = SettingsStore.watchSetting(
@ -203,9 +204,9 @@ class LoggedInView extends React.Component<IProps, IState> {
componentWillUnmount() {
document.removeEventListener('keydown', this.onNativeKeyDown, false);
CallHandler.instance.removeListener(CallHandlerEvent.CallState, this.onCallState);
this._matrixClient.removeListener("accountData", this.onAccountData);
this._matrixClient.removeListener("sync", this.onSync);
this._matrixClient.removeListener("RoomState.events", this.onRoomStateEvents);
this._matrixClient.removeListener(ClientEvent.AccountData, this.onAccountData);
this._matrixClient.removeListener(ClientEvent.Sync, this.onSync);
this._matrixClient.removeListener(RoomStateEvent.Events, this.onRoomStateEvents);
OwnProfileStore.instance.off(UPDATE_EVENT, this.refreshBackgroundImage);
SettingsStore.unwatchSetting(this.layoutWatcherRef);
SettingsStore.unwatchSetting(this.compactLayoutWatcherRef);

View file

@ -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,

View file

@ -21,6 +21,7 @@ import { EventType } from 'matrix-js-sdk/src/@types/event';
import { MatrixEvent } from 'matrix-js-sdk/src/models/event';
import { Relations } from "matrix-js-sdk/src/models/relations";
import { logger } from 'matrix-js-sdk/src/logger';
import { RoomStateEvent } from "matrix-js-sdk/src/models/room-state";
import shouldHideEvent from '../../shouldHideEvent';
import { wantsDateSeparator } from '../../DateUtils';
@ -274,13 +275,13 @@ export default class MessagePanel extends React.Component<IProps, IState> {
componentDidMount() {
this.calculateRoomMembersCount();
this.props.room?.on("RoomState.members", this.calculateRoomMembersCount);
this.props.room?.currentState.on(RoomStateEvent.Members, this.calculateRoomMembersCount);
this.isMounted = true;
}
componentWillUnmount() {
this.isMounted = false;
this.props.room?.off("RoomState.members", this.calculateRoomMembersCount);
this.props.room?.currentState.off(RoomStateEvent.Members, this.calculateRoomMembersCount);
SettingsStore.unwatchSetting(this.showTypingNotificationsWatcherRef);
}

View file

@ -153,14 +153,12 @@ export default class ThreadView extends React.Component<IProps, IState> {
thread = this.props.room.createThread(mxEv);
}
thread.on(ThreadEvent.Update, this.updateLastThreadReply);
thread.once(ThreadEvent.Ready, this.updateThread);
this.updateThread(thread);
};
private teardownThread = () => {
if (this.state.thread) {
this.state.thread.removeListener(ThreadEvent.Update, this.updateLastThreadReply);
this.state.thread.removeListener(ThreadEvent.Ready, this.updateThread);
}
};

View file

@ -16,16 +16,17 @@ limitations under the License.
import React, { createRef, ReactNode, SyntheticEvent } from 'react';
import ReactDOM from "react-dom";
import { NotificationCountType, Room } from "matrix-js-sdk/src/models/room";
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import { NotificationCountType, Room, RoomEvent } from "matrix-js-sdk/src/models/room";
import { MatrixEvent, MatrixEventEvent } from "matrix-js-sdk/src/models/event";
import { EventTimelineSet, IRoomTimelineData } from "matrix-js-sdk/src/models/event-timeline-set";
import { Direction, EventTimeline } from "matrix-js-sdk/src/models/event-timeline";
import { TimelineWindow } from "matrix-js-sdk/src/timeline-window";
import { EventType, RelationType } from 'matrix-js-sdk/src/@types/event';
import { SyncState } from 'matrix-js-sdk/src/sync';
import { RoomMember } from 'matrix-js-sdk/src/models/room-member';
import { RoomMember, RoomMemberEvent } from 'matrix-js-sdk/src/models/room-member';
import { debounce } from 'lodash';
import { logger } from "matrix-js-sdk/src/logger";
import { ClientEvent } from "matrix-js-sdk/src/client";
import SettingsStore from "../../settings/SettingsStore";
import { Layout } from "../../settings/enums/Layout";
@ -276,22 +277,22 @@ class TimelinePanel extends React.Component<IProps, IState> {
this.dispatcherRef = dis.register(this.onAction);
const cli = MatrixClientPeg.get();
cli.on("Room.timeline", this.onRoomTimeline);
cli.on("Room.timelineReset", this.onRoomTimelineReset);
cli.on("Room.redaction", this.onRoomRedaction);
cli.on(RoomEvent.Timeline, this.onRoomTimeline);
cli.on(RoomEvent.TimelineReset, this.onRoomTimelineReset);
cli.on(RoomEvent.Redaction, this.onRoomRedaction);
if (SettingsStore.getValue("feature_msc3531_hide_messages_pending_moderation")) {
// Make sure that events are re-rendered when their visibility-pending-moderation changes.
cli.on("Event.visibilityChange", this.onEventVisibilityChange);
cli.on("RoomMember.powerLevel", this.onVisibilityPowerLevelChange);
cli.on(MatrixEventEvent.VisibilityChange, this.onEventVisibilityChange);
cli.on(RoomMemberEvent.PowerLevel, this.onVisibilityPowerLevelChange);
}
// same event handler as Room.redaction as for both we just do forceUpdate
cli.on("Room.redactionCancelled", this.onRoomRedaction);
cli.on("Room.receipt", this.onRoomReceipt);
cli.on("Room.localEchoUpdated", this.onLocalEchoUpdated);
cli.on("Room.accountData", this.onAccountData);
cli.on("Event.decrypted", this.onEventDecrypted);
cli.on("Event.replaced", this.onEventReplaced);
cli.on("sync", this.onSync);
cli.on(RoomEvent.RedactionCancelled, this.onRoomRedaction);
cli.on(RoomEvent.Receipt, this.onRoomReceipt);
cli.on(RoomEvent.LocalEchoUpdated, this.onLocalEchoUpdated);
cli.on(RoomEvent.AccountData, this.onAccountData);
cli.on(MatrixEventEvent.Decrypted, this.onEventDecrypted);
cli.on(MatrixEventEvent.Replaced, this.onEventReplaced);
cli.on(ClientEvent.Sync, this.onSync);
}
// TODO: [REACT-WARNING] Move into constructor
@ -353,18 +354,18 @@ class TimelinePanel extends React.Component<IProps, IState> {
const client = MatrixClientPeg.get();
if (client) {
client.removeListener("Room.timeline", this.onRoomTimeline);
client.removeListener("Room.timelineReset", this.onRoomTimelineReset);
client.removeListener("Room.redaction", this.onRoomRedaction);
client.removeListener("Room.redactionCancelled", this.onRoomRedaction);
client.removeListener("Room.receipt", this.onRoomReceipt);
client.removeListener("Room.localEchoUpdated", this.onLocalEchoUpdated);
client.removeListener("Room.accountData", this.onAccountData);
client.removeListener("RoomMember.powerLevel", this.onVisibilityPowerLevelChange);
client.removeListener("Event.decrypted", this.onEventDecrypted);
client.removeListener("Event.replaced", this.onEventReplaced);
client.removeListener("Event.visibilityChange", this.onEventVisibilityChange);
client.removeListener("sync", this.onSync);
client.removeListener(RoomEvent.Timeline, this.onRoomTimeline);
client.removeListener(RoomEvent.TimelineReset, this.onRoomTimelineReset);
client.removeListener(RoomEvent.Redaction, this.onRoomRedaction);
client.removeListener(RoomEvent.RedactionCancelled, this.onRoomRedaction);
client.removeListener(RoomEvent.Receipt, this.onRoomReceipt);
client.removeListener(RoomEvent.LocalEchoUpdated, this.onLocalEchoUpdated);
client.removeListener(RoomEvent.AccountData, this.onAccountData);
client.removeListener(RoomMemberEvent.PowerLevel, this.onVisibilityPowerLevelChange);
client.removeListener(MatrixEventEvent.Decrypted, this.onEventDecrypted);
client.removeListener(MatrixEventEvent.Replaced, this.onEventReplaced);
client.removeListener(MatrixEventEvent.VisibilityChange, this.onEventVisibilityChange);
client.removeListener(ClientEvent.Sync, this.onSync);
}
}
@ -673,11 +674,11 @@ class TimelinePanel extends React.Component<IProps, IState> {
this.forceUpdate();
};
private onEventReplaced = (replacedEvent: MatrixEvent, room: Room): void => {
private onEventReplaced = (replacedEvent: MatrixEvent): void => {
if (this.unmounted) return;
// ignore events for other rooms
if (room !== this.props.timelineSet.room) return;
if (replacedEvent.getRoomId() !== this.props.timelineSet.room.roomId) return;
// we could skip an update if the event isn't in our timeline,
// but that's probably an early optimisation.

View file

@ -16,8 +16,8 @@ limitations under the License.
import React from "react";
import classNames from "classnames";
import { Room } from "matrix-js-sdk/src/models/room";
import { User } from "matrix-js-sdk/src/models/user";
import { Room, RoomEvent } from "matrix-js-sdk/src/models/room";
import { User, UserEvent } from "matrix-js-sdk/src/models/user";
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import { EventType } from "matrix-js-sdk/src/@types/event";
import { JoinRule } from "matrix-js-sdk/src/@types/partials";
@ -89,7 +89,7 @@ export default class DecoratedRoomAvatar extends React.PureComponent<IProps, ISt
public componentWillUnmount() {
this.isUnmounted = true;
if (this.isWatchingTimeline) this.props.room.off('Room.timeline', this.onRoomTimeline);
if (this.isWatchingTimeline) this.props.room.off(RoomEvent.Timeline, this.onRoomTimeline);
this.dmUser = null; // clear listeners, if any
}
@ -107,12 +107,12 @@ export default class DecoratedRoomAvatar extends React.PureComponent<IProps, ISt
const oldUser = this._dmUser;
this._dmUser = val;
if (oldUser && oldUser !== this._dmUser) {
oldUser.off('User.currentlyActive', this.onPresenceUpdate);
oldUser.off('User.presence', this.onPresenceUpdate);
oldUser.off(UserEvent.CurrentlyActive, this.onPresenceUpdate);
oldUser.off(UserEvent.Presence, this.onPresenceUpdate);
}
if (this._dmUser && oldUser !== this._dmUser) {
this._dmUser.on('User.currentlyActive', this.onPresenceUpdate);
this._dmUser.on('User.presence', this.onPresenceUpdate);
this._dmUser.on(UserEvent.CurrentlyActive, this.onPresenceUpdate);
this._dmUser.on(UserEvent.Presence, this.onPresenceUpdate);
}
}
@ -169,7 +169,7 @@ export default class DecoratedRoomAvatar extends React.PureComponent<IProps, ISt
// Track publicity
icon = this.isPublicRoom ? Icon.Globe : Icon.None;
if (!this.isWatchingTimeline) {
this.props.room.on('Room.timeline', this.onRoomTimeline);
this.props.room.on(RoomEvent.Timeline, this.onRoomTimeline);
this.isWatchingTimeline = true;
}
}

View file

@ -18,6 +18,7 @@ import React, { ComponentProps } from 'react';
import { Room } from 'matrix-js-sdk/src/models/room';
import { ResizeMethod } from 'matrix-js-sdk/src/@types/partials';
import { MatrixEvent } from 'matrix-js-sdk/src/models/event';
import { RoomStateEvent } from "matrix-js-sdk/src/models/room-state";
import classNames from "classnames";
import BaseAvatar from './BaseAvatar';
@ -68,13 +69,13 @@ export default class RoomAvatar extends React.Component<IProps, IState> {
}
public componentDidMount() {
MatrixClientPeg.get().on("RoomState.events", this.onRoomStateEvents);
MatrixClientPeg.get().on(RoomStateEvent.Events, this.onRoomStateEvents);
}
public componentWillUnmount() {
const cli = MatrixClientPeg.get();
if (cli) {
cli.removeListener("RoomState.events", this.onRoomStateEvents);
cli.removeListener(RoomStateEvent.Events, this.onRoomStateEvents);
}
}

View file

@ -19,6 +19,7 @@ import React, { ReactElement } from 'react';
import { EventStatus, MatrixEvent } from 'matrix-js-sdk/src/models/event';
import { EventType, RelationType } from "matrix-js-sdk/src/@types/event";
import { Relations } from 'matrix-js-sdk/src/models/relations';
import { RoomMemberEvent } from "matrix-js-sdk/src/models/room-member";
import { LOCATION_EVENT_TYPE } from 'matrix-js-sdk/src/@types/location';
import { M_POLL_START } from "matrix-events-sdk";
@ -40,7 +41,7 @@ import ViewSource from '../../structures/ViewSource';
import { createRedactEventDialog } from '../dialogs/ConfirmRedactDialog';
import ShareDialog from '../dialogs/ShareDialog';
import { RoomPermalinkCreator } from "../../../utils/permalinks/Permalinks";
import { IPosition, ChevronFace } from '../../structures/ContextMenu';
import { ChevronFace, IPosition } from '../../structures/ContextMenu';
import RoomContext, { TimelineRenderingType } from '../../../contexts/RoomContext';
import { ComposerInsertPayload } from "../../../dispatcher/payloads/ComposerInsertPayload";
import { WidgetLayoutStore } from '../../../stores/widgets/WidgetLayoutStore';
@ -98,14 +99,14 @@ export default class MessageContextMenu extends React.Component<IProps, IState>
};
componentDidMount() {
MatrixClientPeg.get().on('RoomMember.powerLevel', this.checkPermissions);
MatrixClientPeg.get().on(RoomMemberEvent.PowerLevel, this.checkPermissions);
this.checkPermissions();
}
componentWillUnmount() {
const cli = MatrixClientPeg.get();
if (cli) {
cli.removeListener('RoomMember.powerLevel', this.checkPermissions);
cli.removeListener(RoomMemberEvent.PowerLevel, this.checkPermissions);
}
}

View file

@ -15,8 +15,8 @@ limitations under the License.
*/
import React from 'react';
import { IGeneratedSas, ISasEvent } from "matrix-js-sdk/src/crypto/verification/SAS";
import { VerificationBase } from "matrix-js-sdk/src/crypto/verification/Base";
import { IGeneratedSas, ISasEvent, SasEvent } from "matrix-js-sdk/src/crypto/verification/SAS";
import { VerificationBase, VerificationEvent } from "matrix-js-sdk/src/crypto/verification/Base";
import { logger } from "matrix-js-sdk/src/logger";
import { MatrixClientPeg } from '../../../MatrixClientPeg';
@ -39,7 +39,7 @@ const PHASE_VERIFIED = 3;
const PHASE_CANCELLED = 4;
interface IProps extends IDialogProps {
verifier: VerificationBase;
verifier: VerificationBase<SasEvent, any>;
}
interface IState {
@ -75,8 +75,8 @@ export default class IncomingSasDialog extends React.Component<IProps, IState> {
opponentProfileError: null,
sas: null,
};
this.props.verifier.on('show_sas', this.onVerifierShowSas);
this.props.verifier.on('cancel', this.onVerifierCancel);
this.props.verifier.on(SasEvent.ShowSas, this.onVerifierShowSas);
this.props.verifier.on(VerificationEvent.Cancel, this.onVerifierCancel);
this.fetchOpponentProfile();
}
@ -84,7 +84,7 @@ export default class IncomingSasDialog extends React.Component<IProps, IState> {
if (this.state.phase !== PHASE_CANCELLED && this.state.phase !== PHASE_VERIFIED) {
this.props.verifier.cancel(new Error('User cancel'));
}
this.props.verifier.removeListener('show_sas', this.onVerifierShowSas);
this.props.verifier.removeListener(SasEvent.ShowSas, this.onVerifierShowSas);
}
private async fetchOpponentProfile(): Promise<void> {

View file

@ -16,6 +16,7 @@ limitations under the License.
*/
import React from 'react';
import { RoomEvent } from "matrix-js-sdk/src/models/room";
import TabbedView, { Tab } from "../../structures/TabbedView";
import { _t, _td } from "../../../languageHandler";
@ -61,7 +62,7 @@ export default class RoomSettingsDialog extends React.Component<IProps, IState>
public componentDidMount() {
this.dispatcherRef = dis.register(this.onAction);
MatrixClientPeg.get().on("Room.name", this.onRoomName);
MatrixClientPeg.get().on(RoomEvent.Name, this.onRoomName);
this.onRoomName();
}
@ -70,7 +71,7 @@ export default class RoomSettingsDialog extends React.Component<IProps, IState>
dis.unregister(this.dispatcherRef);
}
MatrixClientPeg.get().removeListener("Room.name", this.onRoomName);
MatrixClientPeg.get().removeListener(RoomEvent.Name, this.onRoomName);
}
private onAction = (payload): void => {

View file

@ -21,7 +21,7 @@ import url from 'url';
import React, { ContextType, createRef } from 'react';
import classNames from 'classnames';
import { MatrixCapabilities } from "matrix-widget-api";
import { Room } from "matrix-js-sdk/src/models/room";
import { Room, RoomEvent } from "matrix-js-sdk/src/models/room";
import { logger } from "matrix-js-sdk/src/logger";
import AccessibleButton from './AccessibleButton';
@ -42,7 +42,7 @@ import WidgetAvatar from "../avatars/WidgetAvatar";
import { replaceableComponent } from "../../../utils/replaceableComponent";
import CallHandler from '../../../CallHandler';
import { IApp } from "../../../stores/WidgetStore";
import { WidgetLayoutStore, Container } from "../../../stores/widgets/WidgetLayoutStore";
import { Container, WidgetLayoutStore } from "../../../stores/widgets/WidgetLayoutStore";
import { OwnProfileStore } from '../../../stores/OwnProfileStore';
import { UPDATE_EVENT } from '../../../stores/AsyncStore';
import RoomViewStore from '../../../stores/RoomViewStore';
@ -269,7 +269,7 @@ export default class AppTile extends React.Component<IProps, IState> {
this.watchUserReady();
if (this.props.room) {
this.context.on("Room.myMembership", this.onMyMembership);
this.context.on(RoomEvent.MyMembership, this.onMyMembership);
}
this.allowedWidgetsWatchRef = SettingsStore.watchSetting("allowedWidgets", null, this.onAllowedWidgetsChange);
@ -306,7 +306,7 @@ export default class AppTile extends React.Component<IProps, IState> {
if (this.dispatcherRef) dis.unregister(this.dispatcherRef);
if (this.props.room) {
this.context.off("Room.myMembership", this.onMyMembership);
this.context.off(RoomEvent.MyMembership, this.onMyMembership);
}
SettingsStore.unwatchSetting(this.allowedWidgetsWatchRef);

View file

@ -18,7 +18,7 @@ import React, { SyntheticEvent } from 'react';
import maplibregl from 'maplibre-gl';
import { logger } from "matrix-js-sdk/src/logger";
import { RoomMember } from 'matrix-js-sdk/src/models/room-member';
import { IClientWellKnown } from 'matrix-js-sdk/src/client';
import { ClientEvent, IClientWellKnown } from 'matrix-js-sdk/src/client';
import DialogButtons from "../elements/DialogButtons";
import { _t } from '../../../languageHandler';
@ -71,7 +71,7 @@ class LocationPicker extends React.Component<IProps, IState> {
};
componentDidMount() {
this.context.on("WellKnown.client", this.updateStyleUrl);
this.context.on(ClientEvent.ClientWellKnown, this.updateStyleUrl);
try {
this.map = new maplibregl.Map({
@ -134,7 +134,7 @@ class LocationPicker extends React.Component<IProps, IState> {
componentWillUnmount() {
this.geolocate?.off('geolocate', this.onGeolocate);
this.context.off("WellKnown.client", this.updateStyleUrl);
this.context.off(ClientEvent.ClientWellKnown, this.updateStyleUrl);
}
private updateStyleUrl = (clientWellKnown: IClientWellKnown) => {

View file

@ -16,7 +16,7 @@ limitations under the License.
import React from 'react';
import { MatrixEvent } from 'matrix-js-sdk/src/models/event';
import { IClientWellKnown, MatrixClient } from 'matrix-js-sdk/src/client';
import { ClientEvent, IClientWellKnown, MatrixClient } from 'matrix-js-sdk/src/client';
import { replaceableComponent } from "../../../utils/replaceableComponent";
import BaseDialog from "../dialogs/BaseDialog";
@ -53,7 +53,7 @@ export default class LocationViewDialog extends React.Component<IProps, IState>
return;
}
this.props.matrixClient.on("WellKnown.client", this.updateStyleUrl);
this.props.matrixClient.on(ClientEvent.ClientWellKnown, this.updateStyleUrl);
this.map = createMap(
this.coords,
@ -65,7 +65,7 @@ export default class LocationViewDialog extends React.Component<IProps, IState>
}
componentWillUnmount() {
this.props.matrixClient.off("WellKnown.client", this.updateStyleUrl);
this.props.matrixClient.off(ClientEvent.ClientWellKnown, this.updateStyleUrl);
}
private updateStyleUrl = (clientWellKnown: IClientWellKnown) => {

View file

@ -15,7 +15,7 @@ limitations under the License.
*/
import React, { createRef } from 'react';
import { EventStatus, MatrixEvent } from 'matrix-js-sdk/src/models/event';
import { EventStatus, MatrixEvent, MatrixEventEvent } from 'matrix-js-sdk/src/models/event';
import classNames from 'classnames';
import * as HtmlUtils from '../../../HtmlUtils';
@ -62,7 +62,7 @@ export default class EditHistoryMessage extends React.PureComponent<IProps, ISta
const event = this.props.mxEvent;
const room = cli.getRoom(event.getRoomId());
if (event.localRedactionEvent()) {
event.localRedactionEvent().on("status", this.onAssociatedStatusChanged);
event.localRedactionEvent().on(MatrixEventEvent.Status, this.onAssociatedStatusChanged);
}
const canRedact = room.currentState.maySendRedactionForEvent(event, userId);
this.state = { canRedact, sendStatus: event.getAssociatedStatus() };
@ -102,7 +102,7 @@ export default class EditHistoryMessage extends React.PureComponent<IProps, ISta
unmountPills(this.pills);
const event = this.props.mxEvent;
if (event.localRedactionEvent()) {
event.localRedactionEvent().off("status", this.onAssociatedStatusChanged);
event.localRedactionEvent().off(MatrixEventEvent.Status, this.onAssociatedStatusChanged);
}
}

View file

@ -21,6 +21,7 @@ import { SyncState } from 'matrix-js-sdk/src/sync';
import classNames from 'classnames';
import { CSSTransition, SwitchTransition } from 'react-transition-group';
import { logger } from "matrix-js-sdk/src/logger";
import { ClientEvent } from "matrix-js-sdk/src/client";
import MFileBody from './MFileBody';
import Modal from '../../../Modal';
@ -299,7 +300,7 @@ export default class MImageBody extends React.Component<IBodyProps, IState> {
componentDidMount() {
this.unmounted = false;
MatrixClientPeg.get().on('sync', this.onClientSync);
MatrixClientPeg.get().on(ClientEvent.Sync, this.onClientSync);
const showImage = this.state.showImage ||
localStorage.getItem("mx_ShowImage_" + this.props.mxEvent.getId()) === "true";
@ -329,7 +330,7 @@ export default class MImageBody extends React.Component<IBodyProps, IState> {
componentWillUnmount() {
this.unmounted = true;
MatrixClientPeg.get().removeListener('sync', this.onClientSync);
MatrixClientPeg.get().removeListener(ClientEvent.Sync, this.onClientSync);
this.clearBlurhashTimeout();
SettingsStore.unwatchSetting(this.sizeWatcher);
}

View file

@ -17,8 +17,12 @@ limitations under the License.
import React from 'react';
import classNames from 'classnames';
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import { VerificationRequest } from "matrix-js-sdk/src/crypto/verification/request/VerificationRequest";
import {
VerificationRequest,
VerificationRequestEvent,
} from "matrix-js-sdk/src/crypto/verification/request/VerificationRequest";
import { EventType } from "matrix-js-sdk/src/@types/event";
import { CryptoEvent } from "matrix-js-sdk/src/crypto";
import { MatrixClientPeg } from '../../../MatrixClientPeg';
import { _t } from '../../../languageHandler';
@ -41,19 +45,19 @@ export default class MKeyVerificationConclusion extends React.Component<IProps>
public componentDidMount(): void {
const request = this.props.mxEvent.verificationRequest;
if (request) {
request.on("change", this.onRequestChanged);
request.on(VerificationRequestEvent.Change, this.onRequestChanged);
}
MatrixClientPeg.get().on("userTrustStatusChanged", this.onTrustChanged);
MatrixClientPeg.get().on(CryptoEvent.UserTrustStatusChanged, this.onTrustChanged);
}
public componentWillUnmount(): void {
const request = this.props.mxEvent.verificationRequest;
if (request) {
request.off("change", this.onRequestChanged);
request.off(VerificationRequestEvent.Change, this.onRequestChanged);
}
const cli = MatrixClientPeg.get();
if (cli) {
cli.removeListener("userTrustStatusChanged", this.onTrustChanged);
cli.removeListener(CryptoEvent.UserTrustStatusChanged, this.onTrustChanged);
}
}

View file

@ -17,11 +17,11 @@ limitations under the License.
import React from 'react';
import { MatrixEvent } from 'matrix-js-sdk/src';
import { logger } from "matrix-js-sdk/src/logger";
import { VerificationRequestEvent } from "matrix-js-sdk/src/crypto/verification/request/VerificationRequest";
import { MatrixClientPeg } from '../../../MatrixClientPeg';
import { _t } from '../../../languageHandler';
import { getNameForEventRoom, userLabelForEventRoom }
from '../../../utils/KeyVerificationStateObserver';
import { getNameForEventRoom, userLabelForEventRoom } from '../../../utils/KeyVerificationStateObserver';
import { RightPanelPhases } from '../../../stores/right-panel/RightPanelStorePhases';
import EventTileBubble from "./EventTileBubble";
import { replaceableComponent } from "../../../utils/replaceableComponent";
@ -38,14 +38,14 @@ export default class MKeyVerificationRequest extends React.Component<IProps> {
public componentDidMount() {
const request = this.props.mxEvent.verificationRequest;
if (request) {
request.on("change", this.onRequestChanged);
request.on(VerificationRequestEvent.Change, this.onRequestChanged);
}
}
public componentWillUnmount() {
const request = this.props.mxEvent.verificationRequest;
if (request) {
request.off("change", this.onRequestChanged);
request.off(VerificationRequestEvent.Change, this.onRequestChanged);
}
}

View file

@ -24,7 +24,7 @@ import {
ILocationContent,
LOCATION_EVENT_TYPE,
} from 'matrix-js-sdk/src/@types/location';
import { IClientWellKnown } from 'matrix-js-sdk/src/client';
import { ClientEvent, IClientWellKnown } from 'matrix-js-sdk/src/client';
import SdkConfig from '../../../SdkConfig';
import { replaceableComponent } from "../../../utils/replaceableComponent";
@ -71,7 +71,7 @@ export default class MLocationBody extends React.Component<IBodyProps, IState> {
return;
}
this.context.on("WellKnown.client", this.updateStyleUrl);
this.context.on(ClientEvent.ClientWellKnown, this.updateStyleUrl);
this.map = createMap(
this.coords,
@ -83,7 +83,7 @@ export default class MLocationBody extends React.Component<IBodyProps, IState> {
}
componentWillUnmount() {
this.context.off("WellKnown.client", this.updateStyleUrl);
this.context.off(ClientEvent.ClientWellKnown, this.updateStyleUrl);
}
private updateStyleUrl = (clientWellKnown: IClientWellKnown) => {

View file

@ -16,8 +16,8 @@ limitations under the License.
import React from 'react';
import classNames from 'classnames';
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import { Relations } from 'matrix-js-sdk/src/models/relations';
import { MatrixEvent, MatrixEventEvent } from "matrix-js-sdk/src/models/event";
import { Relations, RelationsEvent } from 'matrix-js-sdk/src/models/relations';
import { MatrixClient } from 'matrix-js-sdk/src/matrix';
import {
M_POLL_END,
@ -228,37 +228,37 @@ export default class MPollBody extends React.Component<IBodyProps, IState> {
};
this.addListeners(this.state.voteRelations, this.state.endRelations);
this.props.mxEvent.on("Event.relationsCreated", this.onRelationsCreated);
this.props.mxEvent.on(MatrixEventEvent.RelationsCreated, this.onRelationsCreated);
}
componentWillUnmount() {
this.props.mxEvent.off("Event.relationsCreated", this.onRelationsCreated);
this.props.mxEvent.off(MatrixEventEvent.RelationsCreated, this.onRelationsCreated);
this.removeListeners(this.state.voteRelations, this.state.endRelations);
}
private addListeners(voteRelations?: RelatedRelations, endRelations?: RelatedRelations) {
if (voteRelations) {
voteRelations.on("Relations.add", this.onRelationsChange);
voteRelations.on("Relations.remove", this.onRelationsChange);
voteRelations.on("Relations.redaction", this.onRelationsChange);
voteRelations.on(RelationsEvent.Add, this.onRelationsChange);
voteRelations.on(RelationsEvent.Remove, this.onRelationsChange);
voteRelations.on(RelationsEvent.Redaction, this.onRelationsChange);
}
if (endRelations) {
endRelations.on("Relations.add", this.onRelationsChange);
endRelations.on("Relations.remove", this.onRelationsChange);
endRelations.on("Relations.redaction", this.onRelationsChange);
endRelations.on(RelationsEvent.Add, this.onRelationsChange);
endRelations.on(RelationsEvent.Remove, this.onRelationsChange);
endRelations.on(RelationsEvent.Redaction, this.onRelationsChange);
}
}
private removeListeners(voteRelations?: RelatedRelations, endRelations?: RelatedRelations) {
if (voteRelations) {
voteRelations.off("Relations.add", this.onRelationsChange);
voteRelations.off("Relations.remove", this.onRelationsChange);
voteRelations.off("Relations.redaction", this.onRelationsChange);
voteRelations.off(RelationsEvent.Add, this.onRelationsChange);
voteRelations.off(RelationsEvent.Remove, this.onRelationsChange);
voteRelations.off(RelationsEvent.Redaction, this.onRelationsChange);
}
if (endRelations) {
endRelations.off("Relations.add", this.onRelationsChange);
endRelations.off("Relations.remove", this.onRelationsChange);
endRelations.off("Relations.redaction", this.onRelationsChange);
endRelations.off(RelationsEvent.Add, this.onRelationsChange);
endRelations.off(RelationsEvent.Remove, this.onRelationsChange);
endRelations.off(RelationsEvent.Redaction, this.onRelationsChange);
}
}
@ -282,8 +282,7 @@ export default class MPollBody extends React.Component<IBodyProps, IState> {
}
if (this.voteRelationsReceived && this.endRelationsReceived) {
this.props.mxEvent.removeListener(
"Event.relationsCreated", this.onRelationsCreated);
this.props.mxEvent.removeListener(MatrixEventEvent.RelationsCreated, this.onRelationsCreated);
}
};

View file

@ -17,7 +17,7 @@ limitations under the License.
*/
import React, { ReactElement, useEffect } from 'react';
import { EventStatus, MatrixEvent } from 'matrix-js-sdk/src/models/event';
import { EventStatus, MatrixEvent, MatrixEventEvent } from 'matrix-js-sdk/src/models/event';
import classNames from 'classnames';
import { MsgType } from 'matrix-js-sdk/src/@types/event';
@ -175,22 +175,22 @@ export default class MessageActionBar extends React.PureComponent<IMessageAction
public componentDidMount(): void {
if (this.props.mxEvent.status && this.props.mxEvent.status !== EventStatus.SENT) {
this.props.mxEvent.on("Event.status", this.onSent);
this.props.mxEvent.on(MatrixEventEvent.Status, this.onSent);
}
const client = MatrixClientPeg.get();
client.decryptEventIfNeeded(this.props.mxEvent);
if (this.props.mxEvent.isBeingDecrypted()) {
this.props.mxEvent.once("Event.decrypted", this.onDecrypted);
this.props.mxEvent.once(MatrixEventEvent.Decrypted, this.onDecrypted);
}
this.props.mxEvent.on("Event.beforeRedaction", this.onBeforeRedaction);
this.props.mxEvent.on(MatrixEventEvent.BeforeRedaction, this.onBeforeRedaction);
}
public componentWillUnmount(): void {
this.props.mxEvent.off("Event.status", this.onSent);
this.props.mxEvent.off("Event.decrypted", this.onDecrypted);
this.props.mxEvent.off("Event.beforeRedaction", this.onBeforeRedaction);
this.props.mxEvent.off(MatrixEventEvent.Status, this.onSent);
this.props.mxEvent.off(MatrixEventEvent.Decrypted, this.onDecrypted);
this.props.mxEvent.off(MatrixEventEvent.BeforeRedaction, this.onBeforeRedaction);
}
private onDecrypted = (): void => {

View file

@ -16,8 +16,8 @@ limitations under the License.
import React from "react";
import classNames from "classnames";
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import { Relations } from "matrix-js-sdk/src/models/relations";
import { MatrixEvent, MatrixEventEvent } from "matrix-js-sdk/src/models/event";
import { Relations, RelationsEvent } from "matrix-js-sdk/src/models/relations";
import { _t } from '../../../languageHandler';
import { isContentActionable } from '../../../utils/EventUtils';
@ -93,33 +93,33 @@ export default class ReactionsRow extends React.PureComponent<IProps, IState> {
const { mxEvent, reactions } = this.props;
if (mxEvent.isBeingDecrypted() || mxEvent.shouldAttemptDecryption()) {
mxEvent.once("Event.decrypted", this.onDecrypted);
mxEvent.once(MatrixEventEvent.Decrypted, this.onDecrypted);
}
if (reactions) {
reactions.on("Relations.add", this.onReactionsChange);
reactions.on("Relations.remove", this.onReactionsChange);
reactions.on("Relations.redaction", this.onReactionsChange);
reactions.on(RelationsEvent.Add, this.onReactionsChange);
reactions.on(RelationsEvent.Remove, this.onReactionsChange);
reactions.on(RelationsEvent.Redaction, this.onReactionsChange);
}
}
componentWillUnmount() {
const { mxEvent, reactions } = this.props;
mxEvent.off("Event.decrypted", this.onDecrypted);
mxEvent.off(MatrixEventEvent.Decrypted, this.onDecrypted);
if (reactions) {
reactions.off("Relations.add", this.onReactionsChange);
reactions.off("Relations.remove", this.onReactionsChange);
reactions.off("Relations.redaction", this.onReactionsChange);
reactions.off(RelationsEvent.Add, this.onReactionsChange);
reactions.off(RelationsEvent.Remove, this.onReactionsChange);
reactions.off(RelationsEvent.Redaction, this.onReactionsChange);
}
}
componentDidUpdate(prevProps: IProps) {
if (prevProps.reactions !== this.props.reactions) {
this.props.reactions.on("Relations.add", this.onReactionsChange);
this.props.reactions.on("Relations.remove", this.onReactionsChange);
this.props.reactions.on("Relations.redaction", this.onReactionsChange);
this.props.reactions.on(RelationsEvent.Add, this.onReactionsChange);
this.props.reactions.on(RelationsEvent.Remove, this.onReactionsChange);
this.props.reactions.on(RelationsEvent.Redaction, this.onReactionsChange);
this.onReactionsChange();
}
}

View file

@ -15,7 +15,7 @@ limitations under the License.
*/
import React from 'react';
import { MatrixEvent } from 'matrix-js-sdk/src';
import { MatrixEvent, MatrixEventEvent } from 'matrix-js-sdk/src';
import classNames from 'classnames';
import { replaceableComponent } from "../../../utils/replaceableComponent";
@ -48,7 +48,7 @@ export default class ViewSourceEvent extends React.PureComponent<IProps, IState>
client.decryptEventIfNeeded(mxEvent);
if (mxEvent.isBeingDecrypted()) {
mxEvent.once("Event.decrypted", () => this.forceUpdate());
mxEvent.once(MatrixEventEvent.Decrypted, () => this.forceUpdate());
}
}

View file

@ -28,6 +28,7 @@ import { MatrixEvent } from 'matrix-js-sdk/src/models/event';
import { VerificationRequest } from "matrix-js-sdk/src/crypto/verification/request/VerificationRequest";
import { EventType } from "matrix-js-sdk/src/@types/event";
import { logger } from "matrix-js-sdk/src/logger";
import { CryptoEvent } from "matrix-js-sdk/src/crypto";
import dis from '../../../dispatcher/dispatcher';
import Modal from '../../../Modal';
@ -1275,15 +1276,15 @@ export const useDevices = (userId: string) => {
if (_userId !== userId) return;
updateDevices();
};
cli.on("crypto.devicesUpdated", onDevicesUpdated);
cli.on("deviceVerificationChanged", onDeviceVerificationChanged);
cli.on("userTrustStatusChanged", onUserTrustStatusChanged);
cli.on(CryptoEvent.DevicesUpdated, onDevicesUpdated);
cli.on(CryptoEvent.DeviceVerificationChanged, onDeviceVerificationChanged);
cli.on(CryptoEvent.UserTrustStatusChanged, onUserTrustStatusChanged);
// Handle being unmounted
return () => {
cancel = true;
cli.removeListener("crypto.devicesUpdated", onDevicesUpdated);
cli.removeListener("deviceVerificationChanged", onDeviceVerificationChanged);
cli.removeListener("userTrustStatusChanged", onUserTrustStatusChanged);
cli.removeListener(CryptoEvent.DevicesUpdated, onDevicesUpdated);
cli.removeListener(CryptoEvent.DeviceVerificationChanged, onDeviceVerificationChanged);
cli.removeListener(CryptoEvent.UserTrustStatusChanged, onUserTrustStatusChanged);
};
}, [cli, userId]);

View file

@ -16,11 +16,15 @@ limitations under the License.
import React from "react";
import { verificationMethods } from 'matrix-js-sdk/src/crypto';
import { SCAN_QR_CODE_METHOD, ReciprocateQRCode } from "matrix-js-sdk/src/crypto/verification/QRCode";
import { VerificationRequest, Phase } from "matrix-js-sdk/src/crypto/verification/request/VerificationRequest";
import { QrCodeEvent, ReciprocateQRCode, SCAN_QR_CODE_METHOD } from "matrix-js-sdk/src/crypto/verification/QRCode";
import {
Phase,
VerificationRequest,
VerificationRequestEvent,
} from "matrix-js-sdk/src/crypto/verification/request/VerificationRequest";
import { RoomMember } from "matrix-js-sdk/src/models/room-member";
import { User } from "matrix-js-sdk/src/models/user";
import { SAS } from "matrix-js-sdk/src/crypto/verification/SAS";
import { SAS, SasEvent } from "matrix-js-sdk/src/crypto/verification/SAS";
import { logger } from "matrix-js-sdk/src/logger";
import { MatrixClientPeg } from "../../../MatrixClientPeg";
@ -357,8 +361,8 @@ export default class VerificationPanel extends React.PureComponent<IProps, IStat
const { request } = this.props;
const sasEvent = (request.verifier as SAS).sasEvent;
const reciprocateQREvent = (request.verifier as ReciprocateQRCode).reciprocateQREvent;
request.verifier.off('show_sas', this.updateVerifierState);
request.verifier.off('show_reciprocate_qr', this.updateVerifierState);
request.verifier.off(SasEvent.ShowSas, this.updateVerifierState);
request.verifier.off(QrCodeEvent.ShowReciprocateQr, this.updateVerifierState);
this.setState({ sasEvent, reciprocateQREvent });
};
@ -367,8 +371,8 @@ export default class VerificationPanel extends React.PureComponent<IProps, IStat
const hadVerifier = this.hasVerifier;
this.hasVerifier = !!request.verifier;
if (!hadVerifier && this.hasVerifier) {
request.verifier.on('show_sas', this.updateVerifierState);
request.verifier.on('show_reciprocate_qr', this.updateVerifierState);
request.verifier.on(SasEvent.ShowSas, this.updateVerifierState);
request.verifier.on(QrCodeEvent.ShowReciprocateQr, this.updateVerifierState);
try {
// on the requester side, this is also awaited in startSAS,
// but that's ok as verify should return the same promise.
@ -381,7 +385,7 @@ export default class VerificationPanel extends React.PureComponent<IProps, IStat
public componentDidMount() {
const { request } = this.props;
request.on("change", this.onRequestChange);
request.on(VerificationRequestEvent.Change, this.onRequestChange);
if (request.verifier) {
const sasEvent = (request.verifier as SAS).sasEvent;
const reciprocateQREvent = (request.verifier as ReciprocateQRCode).reciprocateQREvent;
@ -393,9 +397,9 @@ export default class VerificationPanel extends React.PureComponent<IProps, IStat
public componentWillUnmount() {
const { request } = this.props;
if (request.verifier) {
request.verifier.off('show_sas', this.updateVerifierState);
request.verifier.off('show_reciprocate_qr', this.updateVerifierState);
request.verifier.off(SasEvent.ShowSas, this.updateVerifierState);
request.verifier.off(QrCodeEvent.ShowReciprocateQr, this.updateVerifierState);
}
request.off("change", this.onRequestChange);
request.off(VerificationRequestEvent.Change, this.onRequestChange);
}
}

View file

@ -18,6 +18,7 @@ import React from 'react';
import { lexicographicCompare } from 'matrix-js-sdk/src/utils';
import { Room } from 'matrix-js-sdk/src/models/room';
import { throttle } from 'lodash';
import { RoomStateEvent } from "matrix-js-sdk/src/models/room-state";
import { MatrixClientPeg } from "../../../MatrixClientPeg";
import AppsDrawer from './AppsDrawer';
@ -66,14 +67,14 @@ export default class AuxPanel extends React.Component<IProps, IState> {
componentDidMount() {
const cli = MatrixClientPeg.get();
if (SettingsStore.getValue("feature_state_counters")) {
cli.on("RoomState.events", this.rateLimitedUpdate);
cli.on(RoomStateEvent.Events, this.rateLimitedUpdate);
}
}
componentWillUnmount() {
const cli = MatrixClientPeg.get();
if (cli && SettingsStore.getValue("feature_state_counters")) {
cli.removeListener("RoomState.events", this.rateLimitedUpdate);
cli.removeListener(RoomStateEvent.Events, this.rateLimitedUpdate);
}
}

View file

@ -18,14 +18,16 @@ limitations under the License.
import React, { createRef } from 'react';
import classNames from "classnames";
import { EventType, MsgType, RelationType } from "matrix-js-sdk/src/@types/event";
import { EventStatus, MatrixEvent } from "matrix-js-sdk/src/models/event";
import { EventStatus, MatrixEvent, MatrixEventEvent } from "matrix-js-sdk/src/models/event";
import { Relations } from "matrix-js-sdk/src/models/relations";
import { RoomMember } from "matrix-js-sdk/src/models/room-member";
import { Thread, ThreadEvent } from 'matrix-js-sdk/src/models/thread';
import { logger } from "matrix-js-sdk/src/logger";
import { NotificationCountType, Room } from 'matrix-js-sdk/src/models/room';
import { NotificationCountType, Room, RoomEvent } from 'matrix-js-sdk/src/models/room';
import { CallErrorCode } from "matrix-js-sdk/src/webrtc/call";
import { M_POLL_START } from "matrix-events-sdk";
import { CryptoEvent } from "matrix-js-sdk/src/crypto";
import { UserTrustLevel } from 'matrix-js-sdk/src/crypto/CrossSigning';
import ReplyChain from "../elements/ReplyChain";
import { _t } from '../../../languageHandler';
@ -488,22 +490,21 @@ export default class EventTile extends React.Component<IProps, IState> {
this.suppressReadReceiptAnimation = false;
const client = MatrixClientPeg.get();
if (!this.props.forExport) {
client.on("deviceVerificationChanged", this.onDeviceVerificationChanged);
client.on("userTrustStatusChanged", this.onUserVerificationChanged);
this.props.mxEvent.on("Event.decrypted", this.onDecrypted);
client.on(CryptoEvent.DeviceVerificationChanged, this.onDeviceVerificationChanged);
client.on(CryptoEvent.UserTrustStatusChanged, this.onUserVerificationChanged);
this.props.mxEvent.on(MatrixEventEvent.Decrypted, this.onDecrypted);
DecryptionFailureTracker.instance.addVisibleEvent(this.props.mxEvent);
if (this.props.showReactions) {
this.props.mxEvent.on("Event.relationsCreated", this.onReactionsCreated);
this.props.mxEvent.on(MatrixEventEvent.RelationsCreated, this.onReactionsCreated);
}
if (this.shouldShowSentReceipt || this.shouldShowSendingReceipt) {
client.on("Room.receipt", this.onRoomReceipt);
client.on(RoomEvent.Receipt, this.onRoomReceipt);
this.isListeningForReceipts = true;
}
}
if (SettingsStore.getValue("feature_thread")) {
this.props.mxEvent.once(ThreadEvent.Ready, this.updateThread);
this.props.mxEvent.on(ThreadEvent.Update, this.updateThread);
if (this.thread) {
@ -578,16 +579,15 @@ export default class EventTile extends React.Component<IProps, IState> {
componentWillUnmount() {
const client = MatrixClientPeg.get();
client.removeListener("deviceVerificationChanged", this.onDeviceVerificationChanged);
client.removeListener("userTrustStatusChanged", this.onUserVerificationChanged);
client.removeListener("Room.receipt", this.onRoomReceipt);
client.removeListener(CryptoEvent.DeviceVerificationChanged, this.onDeviceVerificationChanged);
client.removeListener(CryptoEvent.UserTrustStatusChanged, this.onUserVerificationChanged);
client.removeListener(RoomEvent.Receipt, this.onRoomReceipt);
this.isListeningForReceipts = false;
this.props.mxEvent.removeListener("Event.decrypted", this.onDecrypted);
this.props.mxEvent.removeListener(MatrixEventEvent.Decrypted, this.onDecrypted);
if (this.props.showReactions) {
this.props.mxEvent.removeListener("Event.relationsCreated", this.onReactionsCreated);
this.props.mxEvent.removeListener(MatrixEventEvent.RelationsCreated, this.onReactionsCreated);
}
if (SettingsStore.getValue("feature_thread")) {
this.props.mxEvent.off(ThreadEvent.Ready, this.updateThread);
this.props.mxEvent.off(ThreadEvent.Update, this.updateThread);
}
@ -601,7 +601,7 @@ export default class EventTile extends React.Component<IProps, IState> {
componentDidUpdate(prevProps: IProps, prevState: IState, snapshot) {
// If we're not listening for receipts and expect to be, register a listener.
if (!this.isListeningForReceipts && (this.shouldShowSentReceipt || this.shouldShowSendingReceipt)) {
MatrixClientPeg.get().on("Room.receipt", this.onRoomReceipt);
MatrixClientPeg.get().on(RoomEvent.Receipt, this.onRoomReceipt);
this.isListeningForReceipts = true;
}
}
@ -731,7 +731,7 @@ export default class EventTile extends React.Component<IProps, IState> {
this.forceUpdate(() => {
// Per elsewhere in this file, we can remove the listener once we will have no further purpose for it.
if (!this.shouldShowSentReceipt && !this.shouldShowSendingReceipt) {
MatrixClientPeg.get().removeListener("Room.receipt", this.onRoomReceipt);
MatrixClientPeg.get().removeListener(RoomEvent.Receipt, this.onRoomReceipt);
this.isListeningForReceipts = false;
}
});
@ -753,7 +753,7 @@ export default class EventTile extends React.Component<IProps, IState> {
}
};
private onUserVerificationChanged = (userId: string, _trustStatus: string): void => {
private onUserVerificationChanged = (userId: string, _trustStatus: UserTrustLevel): void => {
if (userId === this.props.mxEvent.getSender()) {
this.verifyEvent(this.props.mxEvent);
}

View file

@ -19,12 +19,13 @@ limitations under the License.
import React from 'react';
import { MatrixEvent } from 'matrix-js-sdk/src/models/event';
import { Room } from 'matrix-js-sdk/src/models/room';
import { RoomMember } from 'matrix-js-sdk/src/models/room-member';
import { RoomState } from 'matrix-js-sdk/src/models/room-state';
import { User } from "matrix-js-sdk/src/models/user";
import { Room, RoomEvent } from 'matrix-js-sdk/src/models/room';
import { RoomMember, RoomMemberEvent } from 'matrix-js-sdk/src/models/room-member';
import { RoomState, RoomStateEvent } from 'matrix-js-sdk/src/models/room-state';
import { User, UserEvent } from "matrix-js-sdk/src/models/user";
import { throttle } from 'lodash';
import { JoinRule } from "matrix-js-sdk/src/@types/partials";
import { ClientEvent } from "matrix-js-sdk/src/client";
import { _t } from '../../../languageHandler';
import SdkConfig from '../../../SdkConfig';
@ -92,7 +93,7 @@ export default class MemberList extends React.Component<IProps, IState> {
this.state = this.getMembersState(this.roomMembers());
}
cli.on("Room", this.onRoom); // invites & joining after peek
cli.on(ClientEvent.Room, this.onRoom); // invites & joining after peek
const enablePresenceByHsUrl = SdkConfig.get()["enable_presence_by_hs_url"];
const hsUrl = MatrixClientPeg.get().baseUrl;
this.showPresence = enablePresenceByHsUrl?.[hsUrl] ?? true;
@ -104,7 +105,7 @@ export default class MemberList extends React.Component<IProps, IState> {
this.mounted = true;
if (cli.hasLazyLoadMembersEnabled()) {
this.showMembersAccordingToMembershipWithLL();
cli.on("Room.myMembership", this.onMyMembership);
cli.on(RoomEvent.MyMembership, this.onMyMembership);
} else {
this.listenForMembersChanges();
}
@ -112,15 +113,15 @@ export default class MemberList extends React.Component<IProps, IState> {
private listenForMembersChanges(): void {
const cli = MatrixClientPeg.get();
cli.on("RoomState.members", this.onRoomStateMember);
cli.on("RoomMember.name", this.onRoomMemberName);
cli.on("RoomState.events", this.onRoomStateEvent);
cli.on(RoomStateEvent.Members, this.onRoomStateMember);
cli.on(RoomMemberEvent.Name, this.onRoomMemberName);
cli.on(RoomStateEvent.Events, this.onRoomStateEvent);
// We listen for changes to the lastPresenceTs which is essentially
// listening for all presence events (we display most of not all of
// the information contained in presence events).
cli.on("User.lastPresenceTs", this.onUserPresenceChange);
cli.on("User.presence", this.onUserPresenceChange);
cli.on("User.currentlyActive", this.onUserPresenceChange);
cli.on(UserEvent.LastPresenceTs, this.onUserPresenceChange);
cli.on(UserEvent.Presence, this.onUserPresenceChange);
cli.on(UserEvent.CurrentlyActive, this.onUserPresenceChange);
// cli.on("Room.timeline", this.onRoomTimeline);
}
@ -128,14 +129,14 @@ export default class MemberList extends React.Component<IProps, IState> {
this.mounted = false;
const cli = MatrixClientPeg.get();
if (cli) {
cli.removeListener("RoomState.members", this.onRoomStateMember);
cli.removeListener("RoomMember.name", this.onRoomMemberName);
cli.removeListener("Room.myMembership", this.onMyMembership);
cli.removeListener("RoomState.events", this.onRoomStateEvent);
cli.removeListener("Room", this.onRoom);
cli.removeListener("User.lastPresenceTs", this.onUserPresenceChange);
cli.removeListener("User.presence", this.onUserPresenceChange);
cli.removeListener("User.currentlyActive", this.onUserPresenceChange);
cli.removeListener(RoomStateEvent.Members, this.onRoomStateMember);
cli.removeListener(RoomMemberEvent.Name, this.onRoomMemberName);
cli.removeListener(RoomEvent.MyMembership, this.onMyMembership);
cli.removeListener(RoomStateEvent.Events, this.onRoomStateEvent);
cli.removeListener(ClientEvent.Room, this.onRoom);
cli.removeListener(UserEvent.LastPresenceTs, this.onUserPresenceChange);
cli.removeListener(UserEvent.Presence, this.onUserPresenceChange);
cli.removeListener(UserEvent.CurrentlyActive, this.onUserPresenceChange);
}
// cancel any pending calls to the rate_limited_funcs

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();
};

View file

@ -16,10 +16,11 @@ limitations under the License.
import React, { createRef } from 'react';
import classNames from 'classnames';
import { MatrixEvent, IEventRelation } from "matrix-js-sdk/src/models/event";
import { IEventRelation, MatrixEvent } from "matrix-js-sdk/src/models/event";
import { Room } from "matrix-js-sdk/src/models/room";
import { RoomMember } from "matrix-js-sdk/src/models/room-member";
import { EventType, RelationType } from 'matrix-js-sdk/src/@types/event';
import { RoomStateEvent } from "matrix-js-sdk/src/models/room-state";
import { Optional } from "matrix-events-sdk";
import { _t } from '../../../languageHandler';
@ -155,7 +156,7 @@ export default class MessageComposer extends React.Component<IProps, IState> {
public componentDidMount() {
this.dispatcherRef = dis.register(this.onAction);
MatrixClientPeg.get().on("RoomState.events", this.onRoomStateEvents);
MatrixClientPeg.get().on(RoomStateEvent.Events, this.onRoomStateEvents);
this.waitForOwnMember();
UIStore.instance.trackElementDimensions(`MessageComposer${this.instanceId}`, this.ref.current);
UIStore.instance.on(`MessageComposer${this.instanceId}`, this.onResize);
@ -220,7 +221,7 @@ export default class MessageComposer extends React.Component<IProps, IState> {
public componentWillUnmount() {
if (MatrixClientPeg.get()) {
MatrixClientPeg.get().removeListener("RoomState.events", this.onRoomStateEvents);
MatrixClientPeg.get().removeListener(RoomStateEvent.Events, this.onRoomStateEvents);
}
VoiceRecordingStore.instance.off(UPDATE_EVENT, this.onVoiceStoreUpdate);
dis.unregister(this.dispatcherRef);

View file

@ -16,7 +16,7 @@ limitations under the License.
import React, { createRef } from 'react';
import classNames from 'classnames';
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import { MatrixEvent, MatrixEventEvent } from "matrix-js-sdk/src/models/event";
import { EventType, MsgType } from 'matrix-js-sdk/src/@types/event';
import { logger } from "matrix-js-sdk/src/logger";
import { Relations } from 'matrix-js-sdk/src/models/relations';
@ -55,15 +55,15 @@ export default class ReplyTile extends React.PureComponent<IProps> {
};
componentDidMount() {
this.props.mxEvent.on("Event.decrypted", this.onDecrypted);
this.props.mxEvent.on("Event.beforeRedaction", this.onEventRequiresUpdate);
this.props.mxEvent.on("Event.replaced", this.onEventRequiresUpdate);
this.props.mxEvent.on(MatrixEventEvent.Decrypted, this.onDecrypted);
this.props.mxEvent.on(MatrixEventEvent.BeforeRedaction, this.onEventRequiresUpdate);
this.props.mxEvent.on(MatrixEventEvent.Replaced, this.onEventRequiresUpdate);
}
componentWillUnmount() {
this.props.mxEvent.removeListener("Event.decrypted", this.onDecrypted);
this.props.mxEvent.removeListener("Event.beforeRedaction", this.onEventRequiresUpdate);
this.props.mxEvent.removeListener("Event.replaced", this.onEventRequiresUpdate);
this.props.mxEvent.removeListener(MatrixEventEvent.Decrypted, this.onDecrypted);
this.props.mxEvent.removeListener(MatrixEventEvent.BeforeRedaction, this.onEventRequiresUpdate);
this.props.mxEvent.removeListener(MatrixEventEvent.Replaced, this.onEventRequiresUpdate);
}
private onDecrypted = (): void => {

View file

@ -18,7 +18,7 @@ limitations under the License.
import React from 'react';
import classNames from 'classnames';
import { throttle } from 'lodash';
import { MatrixEvent, Room, RoomState } from 'matrix-js-sdk/src';
import { MatrixEvent, Room, RoomState, RoomStateEvent } from 'matrix-js-sdk/src';
import { CallType } from "matrix-js-sdk/src/webrtc/call";
import { _t } from '../../../languageHandler';
@ -82,13 +82,13 @@ export default class RoomHeader extends React.Component<IProps, IState> {
public componentDidMount() {
const cli = MatrixClientPeg.get();
cli.on("RoomState.events", this.onRoomStateEvents);
cli.on(RoomStateEvent.Events, this.onRoomStateEvents);
}
public componentWillUnmount() {
const cli = MatrixClientPeg.get();
if (cli) {
cli.removeListener("RoomState.events", this.onRoomStateEvents);
cli.removeListener(RoomStateEvent.Events, this.onRoomStateEvents);
}
const notiStore = RoomNotificationStateStore.instance.getRoomState(this.props.room);
notiStore.removeListener(NotificationStateEvents.Update, this.onNotificationUpdate);

View file

@ -16,7 +16,7 @@ limitations under the License.
*/
import React, { createRef } from "react";
import { Room } from "matrix-js-sdk/src/models/room";
import { Room, RoomEvent } from "matrix-js-sdk/src/models/room";
import classNames from "classnames";
import { logger } from "matrix-js-sdk/src/logger";
@ -149,8 +149,8 @@ export default class RoomTile extends React.PureComponent<IProps, IState> {
CommunityPrototypeStore.getUpdateEventName(this.props.room?.roomId),
this.onCommunityUpdate,
);
prevProps.room?.off("Room.name", this.onRoomNameUpdate);
this.props.room?.on("Room.name", this.onRoomNameUpdate);
prevProps.room?.off(RoomEvent.Name, this.onRoomNameUpdate);
this.props.room?.on(RoomEvent.Name, this.onRoomNameUpdate);
}
}
@ -168,7 +168,7 @@ export default class RoomTile extends React.PureComponent<IProps, IState> {
);
this.notificationState.on(NotificationStateEvents.Update, this.onNotificationUpdate);
this.roomProps.on(PROPERTY_UPDATED, this.onRoomPropertyUpdate);
this.props.room?.on("Room.name", this.onRoomNameUpdate);
this.props.room?.on(RoomEvent.Name, this.onRoomNameUpdate);
CommunityPrototypeStore.instance.on(
CommunityPrototypeStore.getUpdateEventName(this.props.room.roomId),
this.onCommunityUpdate,
@ -186,7 +186,7 @@ export default class RoomTile extends React.PureComponent<IProps, IState> {
CommunityPrototypeStore.getUpdateEventName(this.props.room.roomId),
this.onCommunityUpdate,
);
this.props.room.off("Room.name", this.onRoomNameUpdate);
this.props.room.off(RoomEvent.Name, this.onRoomNameUpdate);
}
ActiveRoomObserver.removeListener(this.props.room.roomId, this.onActiveRoomUpdate);
defaultDispatcher.unregister(this.dispatcherRef);

View file

@ -17,7 +17,7 @@ limitations under the License.
import React from 'react';
import { MatrixEvent } from 'matrix-js-sdk/src/models/event';
import { Room } from 'matrix-js-sdk/src/models/room';
import { RoomState } from 'matrix-js-sdk/src/models/room-state';
import { RoomState, RoomStateEvent } from 'matrix-js-sdk/src/models/room-state';
import Modal from '../../../Modal';
import { _t } from '../../../languageHandler';
@ -49,11 +49,11 @@ export default class RoomUpgradeWarningBar extends React.PureComponent<IProps, I
}
public componentDidMount(): void {
this.context.on("RoomState.events", this.onStateEvents);
this.context.on(RoomStateEvent.Events, this.onStateEvents);
}
public componentWillUnmount(): void {
this.context.removeListener("RoomState.events", this.onStateEvents);
this.context.removeListener(RoomStateEvent.Events, this.onStateEvents);
}
private onStateEvents = (event: MatrixEvent, state: RoomState): void => {

View file

@ -15,7 +15,7 @@ limitations under the License.
*/
import React from 'react';
import { Room } from 'matrix-js-sdk/src/models/room';
import { Room, RoomEvent } from 'matrix-js-sdk/src/models/room';
import { logger } from "matrix-js-sdk/src/logger";
import { _t, _td } from '../../../languageHandler';
@ -133,7 +133,7 @@ export default class Stickerpicker extends React.PureComponent<IProps, IState> {
this.dispatcherRef = dis.register(this.onAction);
// Track updates to widget state in account data
MatrixClientPeg.get().on('accountData', this.updateWidget);
MatrixClientPeg.get().on(RoomEvent.AccountData, this.updateWidget);
RightPanelStore.instance.on(UPDATE_EVENT, this.onRightPanelStoreUpdate);
// Initialise widget state from current account data
@ -142,7 +142,7 @@ export default class Stickerpicker extends React.PureComponent<IProps, IState> {
public componentWillUnmount(): void {
const client = MatrixClientPeg.get();
if (client) client.removeListener('accountData', this.updateWidget);
if (client) client.removeListener(RoomEvent.AccountData, this.updateWidget);
RightPanelStore.instance.off(UPDATE_EVENT, this.onRightPanelStoreUpdate);
window.removeEventListener('resize', this.onResize);
if (this.dispatcherRef) {

View file

@ -18,6 +18,7 @@ import React from 'react';
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import { Room } from "matrix-js-sdk/src/models/room";
import { logger } from "matrix-js-sdk/src/logger";
import { RoomStateEvent } from "matrix-js-sdk/src/models/room-state";
import { MatrixClientPeg } from "../../../MatrixClientPeg";
import { _t } from "../../../languageHandler";
@ -71,13 +72,13 @@ export default class ThirdPartyMemberInfo extends React.Component<IProps, IState
}
componentDidMount(): void {
MatrixClientPeg.get().on("RoomState.events", this.onRoomStateEvents);
MatrixClientPeg.get().on(RoomStateEvent.Events, this.onRoomStateEvents);
}
componentWillUnmount(): void {
const client = MatrixClientPeg.get();
if (client) {
client.removeListener("RoomState.events", this.onRoomStateEvents);
client.removeListener(RoomStateEvent.Events, this.onRoomStateEvents);
}
}

View file

@ -16,8 +16,8 @@ limitations under the License.
*/
import React from 'react';
import { Room } from "matrix-js-sdk/src/models/room";
import { RoomMember } from "matrix-js-sdk/src/models/room-member";
import { Room, RoomEvent } from "matrix-js-sdk/src/models/room";
import { RoomMember, RoomMemberEvent } from "matrix-js-sdk/src/models/room-member";
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import * as WhoIsTyping from '../../../WhoIsTyping';
@ -59,8 +59,8 @@ export default class WhoIsTypingTile extends React.Component<IProps, IState> {
};
componentDidMount() {
MatrixClientPeg.get().on("RoomMember.typing", this.onRoomMemberTyping);
MatrixClientPeg.get().on("Room.timeline", this.onRoomTimeline);
MatrixClientPeg.get().on(RoomMemberEvent.Typing, this.onRoomMemberTyping);
MatrixClientPeg.get().on(RoomEvent.Timeline, this.onRoomTimeline);
}
componentDidUpdate(_, prevState) {
@ -77,8 +77,8 @@ export default class WhoIsTypingTile extends React.Component<IProps, IState> {
// we may have entirely lost our client as we're logging out before clicking login on the guest bar...
const client = MatrixClientPeg.get();
if (client) {
client.removeListener("RoomMember.typing", this.onRoomMemberTyping);
client.removeListener("Room.timeline", this.onRoomTimeline);
client.removeListener(RoomMemberEvent.Typing, this.onRoomMemberTyping);
client.removeListener(RoomEvent.Timeline, this.onRoomTimeline);
}
Object.values(this.state.delayedStopTypingTimers).forEach((t) => (t as Timer).abort());
}

View file

@ -17,6 +17,7 @@ limitations under the License.
import React from 'react';
import { MatrixEvent } from 'matrix-js-sdk/src/models/event';
import { Room } from 'matrix-js-sdk/src/models/room';
import { RoomStateEvent } from "matrix-js-sdk/src/models/room-state";
import { MatrixClientPeg } from "../../../MatrixClientPeg";
import { _t } from '../../../languageHandler';
@ -69,7 +70,7 @@ export default class ChangeAvatar extends React.Component<IProps, IState> {
}
public componentDidMount(): void {
MatrixClientPeg.get().on("RoomState.events", this.onRoomStateEvents);
MatrixClientPeg.get().on(RoomStateEvent.Events, this.onRoomStateEvents);
}
// TODO: [REACT-WARNING] Replace with appropriate lifecycle event
@ -86,7 +87,7 @@ export default class ChangeAvatar extends React.Component<IProps, IState> {
public componentWillUnmount(): void {
if (MatrixClientPeg.get()) {
MatrixClientPeg.get().removeListener("RoomState.events", this.onRoomStateEvents);
MatrixClientPeg.get().removeListener(RoomStateEvent.Events, this.onRoomStateEvents);
}
}

View file

@ -15,8 +15,9 @@ limitations under the License.
*/
import React from 'react';
import { MatrixEvent } from 'matrix-js-sdk/src';
import { ClientEvent, MatrixEvent } from 'matrix-js-sdk/src';
import { logger } from "matrix-js-sdk/src/logger";
import { CryptoEvent } from "matrix-js-sdk/src/crypto";
import { MatrixClientPeg } from '../../../MatrixClientPeg';
import { _t } from '../../../languageHandler';
@ -52,9 +53,9 @@ export default class CrossSigningPanel extends React.PureComponent<{}, IState> {
public componentDidMount() {
const cli = MatrixClientPeg.get();
cli.on("accountData", this.onAccountData);
cli.on("userTrustStatusChanged", this.onStatusChanged);
cli.on("crossSigning.keysChanged", this.onStatusChanged);
cli.on(ClientEvent.AccountData, this.onAccountData);
cli.on(CryptoEvent.UserTrustStatusChanged, this.onStatusChanged);
cli.on(CryptoEvent.KeysChanged, this.onStatusChanged);
this.getUpdatedStatus();
}
@ -62,9 +63,9 @@ export default class CrossSigningPanel extends React.PureComponent<{}, IState> {
this.unmounted = true;
const cli = MatrixClientPeg.get();
if (!cli) return;
cli.removeListener("accountData", this.onAccountData);
cli.removeListener("userTrustStatusChanged", this.onStatusChanged);
cli.removeListener("crossSigning.keysChanged", this.onStatusChanged);
cli.removeListener(ClientEvent.AccountData, this.onAccountData);
cli.removeListener(CryptoEvent.UserTrustStatusChanged, this.onStatusChanged);
cli.removeListener(CryptoEvent.KeysChanged, this.onStatusChanged);
}
private onAccountData = (event: MatrixEvent): void => {

View file

@ -18,6 +18,7 @@ limitations under the License.
import React, { ComponentType } from 'react';
import { IKeyBackupInfo } from "matrix-js-sdk/src/crypto/keybackup";
import { TrustInfo } from "matrix-js-sdk/src/crypto/backup";
import { CryptoEvent } from "matrix-js-sdk/src/crypto";
import { logger } from "matrix-js-sdk/src/logger";
import { MatrixClientPeg } from '../../../MatrixClientPeg';
@ -68,9 +69,9 @@ export default class SecureBackupPanel extends React.PureComponent<{}, IState> {
public componentDidMount(): void {
this.checkKeyBackupStatus();
MatrixClientPeg.get().on('crypto.keyBackupStatus', this.onKeyBackupStatus);
MatrixClientPeg.get().on(CryptoEvent.KeyBackupStatus, this.onKeyBackupStatus);
MatrixClientPeg.get().on(
'crypto.keyBackupSessionsRemaining',
CryptoEvent.KeyBackupSessionsRemaining,
this.onKeyBackupSessionsRemaining,
);
}
@ -79,9 +80,9 @@ export default class SecureBackupPanel extends React.PureComponent<{}, IState> {
this.unmounted = true;
if (MatrixClientPeg.get()) {
MatrixClientPeg.get().removeListener('crypto.keyBackupStatus', this.onKeyBackupStatus);
MatrixClientPeg.get().removeListener(CryptoEvent.KeyBackupStatus, this.onKeyBackupStatus);
MatrixClientPeg.get().removeListener(
'crypto.keyBackupSessionsRemaining',
CryptoEvent.KeyBackupSessionsRemaining,
this.onKeyBackupSessionsRemaining,
);
}

View file

@ -18,7 +18,7 @@ import React from 'react';
import { EventType } from "matrix-js-sdk/src/@types/event";
import { RoomMember } from "matrix-js-sdk/src/models/room-member";
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import { RoomState } from "matrix-js-sdk/src/models/room-state";
import { RoomState, RoomStateEvent } from "matrix-js-sdk/src/models/room-state";
import { logger } from "matrix-js-sdk/src/logger";
import { _t, _td } from "../../../../../languageHandler";
@ -122,13 +122,13 @@ interface IProps {
@replaceableComponent("views.settings.tabs.room.RolesRoomSettingsTab")
export default class RolesRoomSettingsTab extends React.Component<IProps> {
componentDidMount() {
MatrixClientPeg.get().on("RoomState.members", this.onRoomMembership);
MatrixClientPeg.get().on(RoomStateEvent.Members, this.onRoomMembership);
}
componentWillUnmount() {
const client = MatrixClientPeg.get();
if (client) {
client.removeListener("RoomState.members", this.onRoomMembership);
client.removeListener(RoomStateEvent.Members, this.onRoomMembership);
}
}

View file

@ -17,6 +17,7 @@ limitations under the License.
import React from 'react';
import { GuestAccess, HistoryVisibility, JoinRule, RestrictedAllowType } from "matrix-js-sdk/src/@types/partials";
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import { RoomStateEvent } from "matrix-js-sdk/src/models/room-state";
import { EventType } from 'matrix-js-sdk/src/@types/event';
import { logger } from "matrix-js-sdk/src/logger";
@ -71,7 +72,7 @@ export default class SecurityRoomSettingsTab extends React.Component<IProps, ISt
// TODO: [REACT-WARNING] Move this to constructor
UNSAFE_componentWillMount() { // eslint-disable-line
const cli = MatrixClientPeg.get();
cli.on("RoomState.events", this.onStateEvent);
cli.on(RoomStateEvent.Events, this.onStateEvent);
const room = cli.getRoom(this.props.roomId);
const state = room.currentState;
@ -110,7 +111,7 @@ export default class SecurityRoomSettingsTab extends React.Component<IProps, ISt
}
componentWillUnmount() {
MatrixClientPeg.get().removeListener("RoomState.events", this.onStateEvent);
MatrixClientPeg.get().removeListener(RoomStateEvent.Events, this.onStateEvent);
}
private onStateEvent = (e: MatrixEvent) => {

View file

@ -17,7 +17,7 @@ limitations under the License.
import React from 'react';
import { sleep } from "matrix-js-sdk/src/utils";
import { Room } from "matrix-js-sdk/src/models/room";
import { Room, RoomEvent } from "matrix-js-sdk/src/models/room";
import { logger } from "matrix-js-sdk/src/logger";
import { _t } from "../../../../../languageHandler";
@ -105,12 +105,12 @@ export default class SecurityUserSettingsTab extends React.Component<IProps, ISt
public componentDidMount(): void {
this.dispatcherRef = dis.register(this.onAction);
MatrixClientPeg.get().on("Room.myMembership", this.onMyMembership);
MatrixClientPeg.get().on(RoomEvent.MyMembership, this.onMyMembership);
}
public componentWillUnmount(): void {
dis.unregister(this.dispatcherRef);
MatrixClientPeg.get().removeListener("Room.myMembership", this.onMyMembership);
MatrixClientPeg.get().removeListener(RoomEvent.MyMembership, this.onMyMembership);
}
private updateAnalytics = (checked: boolean): void => {

View file

@ -14,15 +14,9 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import React, {
createRef,
InputHTMLAttributes,
LegacyRef,
ComponentProps,
ComponentType,
} from "react";
import React, { ComponentProps, ComponentType, createRef, InputHTMLAttributes, LegacyRef } from "react";
import classNames from "classnames";
import { Room } from "matrix-js-sdk/src/models/room";
import { Room, RoomEvent } from "matrix-js-sdk/src/models/room";
import { DraggableProvidedDragHandleProps } from "react-beautiful-dnd";
import RoomAvatar from "../avatars/RoomAvatar";
@ -184,12 +178,12 @@ export class SpaceItem extends React.PureComponent<IItemProps, IItemState> {
};
SpaceStore.instance.on(this.props.space.roomId, this.onSpaceUpdate);
this.props.space.on("Room.name", this.onRoomNameChange);
this.props.space.on(RoomEvent.Name, this.onRoomNameChange);
}
componentWillUnmount() {
SpaceStore.instance.off(this.props.space.roomId, this.onSpaceUpdate);
this.props.space.off("Room.name", this.onRoomNameChange);
this.props.space.off(RoomEvent.Name, this.onRoomNameChange);
}
private onSpaceUpdate = () => {

View file

@ -15,7 +15,10 @@ limitations under the License.
*/
import React from "react";
import { VerificationRequest } from "matrix-js-sdk/src/crypto/verification/request/VerificationRequest";
import {
VerificationRequest,
VerificationRequestEvent,
} from "matrix-js-sdk/src/crypto/verification/request/VerificationRequest";
import { DeviceInfo } from "matrix-js-sdk/src/crypto/deviceinfo";
import { logger } from "matrix-js-sdk/src/logger";
@ -62,7 +65,7 @@ export default class VerificationRequestToast extends React.PureComponent<IProps
this.setState({ counter });
}, 1000);
}
request.on("change", this.checkRequestIsPending);
request.on(VerificationRequestEvent.Change, this.checkRequestIsPending);
// We should probably have a separate class managing the active verification toasts,
// rather than monitoring this in the toast component itself, since we'll get problems
// like the toasdt not going away when the verification is cancelled unless it's the
@ -85,7 +88,7 @@ export default class VerificationRequestToast extends React.PureComponent<IProps
componentWillUnmount() {
clearInterval(this.intervalHandle);
const { request } = this.props;
request.off("change", this.checkRequestIsPending);
request.off(VerificationRequestEvent.Change, this.checkRequestIsPending);
}
private checkRequestIsPending = () => {

View file

@ -28,6 +28,7 @@ import {
Visibility,
} from "matrix-js-sdk/src/@types/partials";
import { logger } from "matrix-js-sdk/src/logger";
import { RoomStateEvent } from "matrix-js-sdk/src/models/room-state";
import { MatrixClientPeg } from './MatrixClientPeg';
import Modal from './Modal';
@ -332,13 +333,13 @@ export async function waitForMember(client: MatrixClient, roomId: string, userId
if (member.roomId !== roomId) return;
resolve(true);
};
client.on("RoomState.newMember", handler);
client.on(RoomStateEvent.NewMember, handler);
/* We don't want to hang if this goes wrong, so we proceed and hope the other
user is already in the megolm session */
setTimeout(resolve, timeout, false);
}).finally(() => {
client.removeListener("RoomState.newMember", handler);
client.removeListener(RoomStateEvent.NewMember, handler);
});
}

View file

@ -17,16 +17,16 @@ limitations under the License.
import { EventEmitter } from "events";
import { RoomMember } from 'matrix-js-sdk/src/models/room-member';
import { Direction, EventTimeline } from 'matrix-js-sdk/src/models/event-timeline';
import { Room } from 'matrix-js-sdk/src/models/room';
import { Room, RoomEvent } from 'matrix-js-sdk/src/models/room';
import { MatrixEvent } from 'matrix-js-sdk/src/models/event';
import { EventTimelineSet, IRoomTimelineData } from 'matrix-js-sdk/src/models/event-timeline-set';
import { RoomState } from 'matrix-js-sdk/src/models/room-state';
import { RoomState, RoomStateEvent } from 'matrix-js-sdk/src/models/room-state';
import { TimelineIndex, TimelineWindow } from 'matrix-js-sdk/src/timeline-window';
import { sleep } from "matrix-js-sdk/src/utils";
import { IResultRoomEvents } from "matrix-js-sdk/src/@types/search";
import { logger } from "matrix-js-sdk/src/logger";
import { EventType } from "matrix-js-sdk/src/@types/event";
import { MatrixClient } from "matrix-js-sdk/src/client";
import { ClientEvent, MatrixClient } from "matrix-js-sdk/src/client";
import PlatformPeg from "../PlatformPeg";
import { MatrixClientPeg } from "../MatrixClientPeg";
@ -68,10 +68,10 @@ export default class EventIndex extends EventEmitter {
public registerListeners() {
const client = MatrixClientPeg.get();
client.on('sync', this.onSync);
client.on('Room.timeline', this.onRoomTimeline);
client.on('Room.timelineReset', this.onTimelineReset);
client.on('RoomState.events', this.onRoomStateEvent);
client.on(ClientEvent.Sync, this.onSync);
client.on(RoomEvent.Timeline, this.onRoomTimeline);
client.on(RoomEvent.TimelineReset, this.onTimelineReset);
client.on(RoomStateEvent.Events, this.onRoomStateEvent);
}
/**
@ -81,10 +81,10 @@ export default class EventIndex extends EventEmitter {
const client = MatrixClientPeg.get();
if (client === null) return;
client.removeListener('sync', this.onSync);
client.removeListener('Room.timeline', this.onRoomTimeline);
client.removeListener('Room.timelineReset', this.onTimelineReset);
client.removeListener('RoomState.events', this.onRoomStateEvent);
client.removeListener(ClientEvent.Sync, this.onSync);
client.removeListener(RoomEvent.Timeline, this.onRoomTimeline);
client.removeListener(RoomEvent.TimelineReset, this.onTimelineReset);
client.removeListener(RoomStateEvent.Events, this.onRoomStateEvent);
}
/**

View file

@ -16,8 +16,8 @@ limitations under the License.
import url from 'url';
import { logger } from "matrix-js-sdk/src/logger";
import { MatrixClient, ClientEvent } from "matrix-js-sdk/src/client";
import type { MatrixClient } from "matrix-js-sdk/src/client";
import type { MatrixEvent } from "matrix-js-sdk/src/models/event";
import type { Room } from "matrix-js-sdk/src/models/room";
import SdkConfig from '../SdkConfig';
@ -59,15 +59,15 @@ export class IntegrationManagers {
startWatching(): void {
this.stopWatching();
this.client = MatrixClientPeg.get();
this.client.on("accountData", this.onAccountData);
this.client.on("WellKnown.client", this.setupHomeserverManagers);
this.client.on(ClientEvent.AccountData, this.onAccountData);
this.client.on(ClientEvent.ClientWellKnown, this.setupHomeserverManagers);
this.compileManagers();
}
stopWatching(): void {
if (!this.client) return;
this.client.removeListener("accountData", this.onAccountData);
this.client.removeListener("WellKnown.client", this.setupHomeserverManagers);
this.client.removeListener(ClientEvent.AccountData, this.onAccountData);
this.client.removeListener(ClientEvent.ClientWellKnown, this.setupHomeserverManagers);
}
private compileManagers() {

View file

@ -17,6 +17,7 @@ limitations under the License.
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import { Preset } from "matrix-js-sdk/src/@types/partials";
import { logger } from "matrix-js-sdk/src/logger";
import { RoomStateEvent } from "matrix-js-sdk/src/models/room-state";
import { MatrixClientPeg } from "../MatrixClientPeg";
import { ALL_RULE_TYPES, BanList } from "./BanList";
@ -66,7 +67,7 @@ export class Mjolnir {
setup() {
if (!MatrixClientPeg.get()) return;
this.updateLists(SettingsStore.getValue("mjolnirRooms"));
MatrixClientPeg.get().on("RoomState.events", this.onEvent);
MatrixClientPeg.get().on(RoomStateEvent.Events, this.onEvent);
}
stop() {
@ -81,7 +82,7 @@ export class Mjolnir {
}
if (!MatrixClientPeg.get()) return;
MatrixClientPeg.get().removeListener("RoomState.events", this.onEvent);
MatrixClientPeg.get().removeListener(RoomStateEvent.Events, this.onEvent);
}
async getOrCreatePersonalList(): Promise<BanList> {

View file

@ -15,7 +15,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import { MatrixClient } from "matrix-js-sdk/src/client";
import { ClientEvent, MatrixClient } from "matrix-js-sdk/src/client";
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import { MatrixClientPeg } from '../../MatrixClientPeg';
@ -46,10 +46,10 @@ export default class AccountSettingsHandler extends MatrixClientBackedSettingsHa
public initMatrixClient(oldClient: MatrixClient, newClient: MatrixClient) {
if (oldClient) {
oldClient.removeListener("accountData", this.onAccountData);
oldClient.removeListener(ClientEvent.AccountData, this.onAccountData);
}
newClient.on("accountData", this.onAccountData);
newClient.on(ClientEvent.AccountData, this.onAccountData);
}
private onAccountData = (event: MatrixEvent, prevEvent: MatrixEvent) => {

View file

@ -17,7 +17,7 @@ limitations under the License.
import { MatrixClient } from "matrix-js-sdk/src/client";
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import { Room } from "matrix-js-sdk/src/models/room";
import { Room, RoomEvent } from "matrix-js-sdk/src/models/room";
import { MatrixClientPeg } from '../../MatrixClientPeg';
import MatrixClientBackedSettingsHandler from "./MatrixClientBackedSettingsHandler";
@ -37,10 +37,10 @@ export default class RoomAccountSettingsHandler extends MatrixClientBackedSettin
protected initMatrixClient(oldClient: MatrixClient, newClient: MatrixClient) {
if (oldClient) {
oldClient.removeListener("Room.accountData", this.onAccountData);
oldClient.removeListener(RoomEvent.AccountData, this.onAccountData);
}
newClient.on("Room.accountData", this.onAccountData);
newClient.on(RoomEvent.AccountData, this.onAccountData);
}
private onAccountData = (event: MatrixEvent, room: Room, prevEvent: MatrixEvent) => {

View file

@ -17,7 +17,7 @@ limitations under the License.
import { MatrixClient } from "matrix-js-sdk/src/client";
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import { RoomState } from "matrix-js-sdk/src/models/room-state";
import { RoomState, RoomStateEvent } from "matrix-js-sdk/src/models/room-state";
import { MatrixClientPeg } from '../../MatrixClientPeg';
import MatrixClientBackedSettingsHandler from "./MatrixClientBackedSettingsHandler";
@ -35,10 +35,10 @@ export default class RoomSettingsHandler extends MatrixClientBackedSettingsHandl
protected initMatrixClient(oldClient: MatrixClient, newClient: MatrixClient) {
if (oldClient) {
oldClient.removeListener("RoomState.events", this.onEvent);
oldClient.removeListener(RoomStateEvent.Events, this.onEvent);
}
newClient.on("RoomState.events", this.onEvent);
newClient.on(RoomStateEvent.Events, this.onEvent);
}
private onEvent = (event: MatrixEvent, state: RoomState, prevEvent: MatrixEvent) => {

View file

@ -15,7 +15,7 @@ limitations under the License.
*/
import EventEmitter from 'events';
import { MatrixEvent } from "matrix-js-sdk/src";
import { MatrixEvent, RoomStateEvent } from "matrix-js-sdk/src";
import { MatrixClientPeg } from '../MatrixClientPeg';
import { WidgetMessagingStore } from "./widgets/WidgetMessagingStore";
@ -44,12 +44,12 @@ export default class ActiveWidgetStore extends EventEmitter {
}
public start(): void {
MatrixClientPeg.get().on('RoomState.events', this.onRoomStateEvents);
MatrixClientPeg.get().on(RoomStateEvent.Events, this.onRoomStateEvents);
}
public stop(): void {
if (MatrixClientPeg.get()) {
MatrixClientPeg.get().removeListener('RoomState.events', this.onRoomStateEvents);
MatrixClientPeg.get().removeListener(RoomStateEvent.Events, this.onRoomStateEvents);
}
this.roomIdByWidgetId.clear();
}

View file

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import { MatrixEvent } from "matrix-js-sdk/src";
import { ClientEvent, MatrixEvent, MatrixEventEvent } from "matrix-js-sdk/src";
import { sleep } from "matrix-js-sdk/src/utils";
import { ISyncStateData, SyncState } from "matrix-js-sdk/src/sync";
@ -73,16 +73,17 @@ export default class AutoRageshakeStore extends AsyncStoreWithClient<IState> {
if (!SettingsStore.getValue("automaticDecryptionErrorReporting")) return;
if (this.matrixClient) {
this.matrixClient.on('Event.decrypted', this.onDecryptionAttempt);
this.matrixClient.on('toDeviceEvent', this.onDeviceMessage);
this.matrixClient.on('sync', this.onSyncStateChange);
this.matrixClient.on(MatrixEventEvent.Decrypted, this.onDecryptionAttempt);
this.matrixClient.on(ClientEvent.ToDeviceEvent, this.onDeviceMessage);
this.matrixClient.on(ClientEvent.Sync, this.onSyncStateChange);
}
}
protected async onNotReady() {
if (this.matrixClient) {
this.matrixClient.removeListener('toDeviceEvent', this.onDeviceMessage);
this.matrixClient.removeListener('Event.decrypted', this.onDecryptionAttempt);
this.matrixClient.removeListener(ClientEvent.ToDeviceEvent, this.onDeviceMessage);
this.matrixClient.removeListener(MatrixEventEvent.Decrypted, this.onDecryptionAttempt);
this.matrixClient.removeListener(ClientEvent.Sync, this.onSyncStateChange);
}
}

View file

@ -14,8 +14,9 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import { Room } from "matrix-js-sdk/src/models/room";
import { Room, RoomEvent } from "matrix-js-sdk/src/models/room";
import { isNullOrUndefined } from "matrix-js-sdk/src/utils";
import { ClientEvent } from "matrix-js-sdk/src/client";
import SettingsStore from "../settings/SettingsStore";
import { AsyncStoreWithClient } from "./AsyncStoreWithClient";
@ -92,13 +93,13 @@ export class BreadcrumbsStore extends AsyncStoreWithClient<IState> {
await this.updateRooms();
await this.updateState({ enabled: SettingsStore.getValue("breadcrumbs", null) });
this.matrixClient.on("Room.myMembership", this.onMyMembership);
this.matrixClient.on("Room", this.onRoom);
this.matrixClient.on(RoomEvent.MyMembership, this.onMyMembership);
this.matrixClient.on(ClientEvent.Room, this.onRoom);
}
protected async onNotReady() {
this.matrixClient.removeListener("Room.myMembership", this.onMyMembership);
this.matrixClient.removeListener("Room", this.onRoom);
this.matrixClient.removeListener(RoomEvent.MyMembership, this.onMyMembership);
this.matrixClient.removeListener(ClientEvent.Room, this.onRoom);
}
private onMyMembership = async (room: Room) => {

View file

@ -15,7 +15,8 @@ limitations under the License.
*/
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import { User } from "matrix-js-sdk/src/models/user";
import { User, UserEvent } from "matrix-js-sdk/src/models/user";
import { RoomStateEvent } from "matrix-js-sdk/src/models/room-state";
import { throttle } from "lodash";
import { ActionPayload } from "../dispatcher/payloads";
@ -98,11 +99,11 @@ export class OwnProfileStore extends AsyncStoreWithClient<IState> {
protected async onNotReady() {
if (this.monitoredUser) {
this.monitoredUser.removeListener("User.displayName", this.onProfileUpdate);
this.monitoredUser.removeListener("User.avatarUrl", this.onProfileUpdate);
this.monitoredUser.removeListener(UserEvent.DisplayName, this.onProfileUpdate);
this.monitoredUser.removeListener(UserEvent.AvatarUrl, this.onProfileUpdate);
}
if (this.matrixClient) {
this.matrixClient.removeListener("RoomState.events", this.onStateEvents);
this.matrixClient.removeListener(RoomStateEvent.Events, this.onStateEvents);
}
await this.reset({});
}
@ -111,13 +112,13 @@ export class OwnProfileStore extends AsyncStoreWithClient<IState> {
const myUserId = this.matrixClient.getUserId();
this.monitoredUser = this.matrixClient.getUser(myUserId);
if (this.monitoredUser) {
this.monitoredUser.on("User.displayName", this.onProfileUpdate);
this.monitoredUser.on("User.avatarUrl", this.onProfileUpdate);
this.monitoredUser.on(UserEvent.DisplayName, this.onProfileUpdate);
this.monitoredUser.on(UserEvent.AvatarUrl, this.onProfileUpdate);
}
// We also have to listen for membership events for ourselves as the above User events
// are fired only with presence, which matrix.org (and many others) has disabled.
this.matrixClient.on("RoomState.events", this.onStateEvents);
this.matrixClient.on(RoomStateEvent.Events, this.onStateEvents);
await this.onProfileUpdate(); // trigger an initial update
}

View file

@ -24,6 +24,7 @@ import { ViewRoom as ViewRoomEvent } from "matrix-analytics-events/types/typescr
import { JoinedRoom as JoinedRoomEvent } from "matrix-analytics-events/types/typescript/JoinedRoom";
import { JoinRule } from "matrix-js-sdk/src/@types/partials";
import { Room } from "matrix-js-sdk/src/models/room";
import { ClientEvent } from "matrix-js-sdk/src/client";
import dis from '../dispatcher/dispatcher';
import { MatrixClientPeg } from '../MatrixClientPeg';
@ -180,13 +181,13 @@ class RoomViewStore extends Store<ActionPayload> {
isSpace: room.isSpaceRoom(),
});
cli.off("Room", updateMetrics);
cli.off(ClientEvent.Room, updateMetrics);
};
if (cli.getRoom(payload.roomId)) {
updateMetrics();
} else {
cli.on("Room", updateMetrics);
cli.on(ClientEvent.Room, updateMetrics);
}
break;

View file

@ -16,15 +16,17 @@ limitations under the License.
import EventEmitter from 'events';
import {
VerificationRequest,
PHASE_DONE as VERIF_PHASE_DONE,
VerificationRequest,
VerificationRequestEvent,
} from "matrix-js-sdk/src/crypto/verification/request/VerificationRequest";
import { IKeyBackupInfo } from "matrix-js-sdk/src/crypto/keybackup";
import { ISecretStorageKeyInfo } from "matrix-js-sdk/src/crypto/api";
import { logger } from "matrix-js-sdk/src/logger";
import { CryptoEvent } from "matrix-js-sdk/src/crypto";
import { MatrixClientPeg } from '../MatrixClientPeg';
import { accessSecretStorage, AccessCancelledError } from '../SecurityManager';
import { AccessCancelledError, accessSecretStorage } from '../SecurityManager';
import Modal from '../Modal';
import InteractiveAuthDialog from '../components/views/dialogs/InteractiveAuthDialog';
import { _t } from '../languageHandler';
@ -68,8 +70,8 @@ export class SetupEncryptionStore extends EventEmitter {
this.keyInfo = null;
const cli = MatrixClientPeg.get();
cli.on("crypto.verification.request", this.onVerificationRequest);
cli.on('userTrustStatusChanged', this.onUserTrustStatusChanged);
cli.on(CryptoEvent.VerificationRequest, this.onVerificationRequest);
cli.on(CryptoEvent.UserTrustStatusChanged, this.onUserTrustStatusChanged);
const requestsInProgress = cli.getVerificationRequestsToDeviceInProgress(cli.getUserId());
if (requestsInProgress.length) {
@ -88,11 +90,11 @@ export class SetupEncryptionStore extends EventEmitter {
}
this.started = false;
if (this.verificationRequest) {
this.verificationRequest.off("change", this.onVerificationRequestChange);
this.verificationRequest.off(VerificationRequestEvent.Change, this.onVerificationRequestChange);
}
if (MatrixClientPeg.get()) {
MatrixClientPeg.get().removeListener("crypto.verification.request", this.onVerificationRequest);
MatrixClientPeg.get().removeListener('userTrustStatusChanged', this.onUserTrustStatusChanged);
MatrixClientPeg.get().removeListener(CryptoEvent.VerificationRequest, this.onVerificationRequest);
MatrixClientPeg.get().removeListener(CryptoEvent.UserTrustStatusChanged, this.onUserTrustStatusChanged);
}
}
@ -186,11 +188,11 @@ export class SetupEncryptionStore extends EventEmitter {
public onVerificationRequestChange = (): void => {
if (this.verificationRequest.cancelled) {
this.verificationRequest.off("change", this.onVerificationRequestChange);
this.verificationRequest.off(VerificationRequestEvent.Change, this.onVerificationRequestChange);
this.verificationRequest = null;
this.emit("update");
} else if (this.verificationRequest.phase === VERIF_PHASE_DONE) {
this.verificationRequest.off("change", this.onVerificationRequestChange);
this.verificationRequest.off(VerificationRequestEvent.Change, this.onVerificationRequestChange);
this.verificationRequest = null;
// At this point, the verification has finished, we just need to wait for
// cross signing to be ready to use, so wait for the user trust status to
@ -271,11 +273,11 @@ export class SetupEncryptionStore extends EventEmitter {
if (request.otherUserId !== MatrixClientPeg.get().getUserId()) return;
if (this.verificationRequest) {
this.verificationRequest.off("change", this.onVerificationRequestChange);
this.verificationRequest.off(VerificationRequestEvent.Change, this.onVerificationRequestChange);
}
this.verificationRequest = request;
await request.accept();
request.on("change", this.onVerificationRequestChange);
request.on(VerificationRequestEvent.Change, this.onVerificationRequestChange);
this.emit("update");
}

View file

@ -18,6 +18,8 @@ import { Room } from "matrix-js-sdk/src/models/room";
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import { IWidget } from "matrix-widget-api";
import { logger } from "matrix-js-sdk/src/logger";
import { ClientEvent } from "matrix-js-sdk/src/client";
import { RoomStateEvent } from "matrix-js-sdk/src/models/room-state";
import { ActionPayload } from "../dispatcher/payloads";
import { AsyncStoreWithClient } from "./AsyncStoreWithClient";
@ -73,8 +75,8 @@ export default class WidgetStore extends AsyncStoreWithClient<IState> {
}
protected async onReady(): Promise<any> {
this.matrixClient.on("Room", this.onRoom);
this.matrixClient.on("RoomState.events", this.onRoomStateEvents);
this.matrixClient.on(ClientEvent.Room, this.onRoom);
this.matrixClient.on(RoomStateEvent.Events, this.onRoomStateEvents);
this.matrixClient.getRooms().forEach((room: Room) => {
this.loadRoomWidgets(room);
});
@ -82,8 +84,8 @@ export default class WidgetStore extends AsyncStoreWithClient<IState> {
}
protected async onNotReady(): Promise<any> {
this.matrixClient.off("Room", this.onRoom);
this.matrixClient.off("RoomState.events", this.onRoomStateEvents);
this.matrixClient.off(ClientEvent.Room, this.onRoom);
this.matrixClient.off(RoomStateEvent.Events, this.onRoomStateEvents);
this.widgetMap = new Map();
this.roomMap = new Map();
await this.reset({});

View file

@ -29,8 +29,14 @@ export enum NotificationStateEvents {
Update = "update",
}
export abstract class NotificationState extends TypedEventEmitter<NotificationStateEvents>
type EventHandlerMap = {
[NotificationStateEvents.Update]: () => void;
};
export abstract class NotificationState
extends TypedEventEmitter<NotificationStateEvents, EventHandlerMap>
implements INotificationStateSnapshotParams, IDestroyable {
//
protected _symbol: string | null;
protected _count: number;
protected _color: NotificationColor;

View file

@ -14,8 +14,9 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import { NotificationCountType, Room } from "matrix-js-sdk/src/models/room";
import { MatrixEvent, MatrixEventEvent } from "matrix-js-sdk/src/models/event";
import { NotificationCountType, Room, RoomEvent } from "matrix-js-sdk/src/models/room";
import { ClientEvent } from "matrix-js-sdk/src/client";
import { NotificationColor } from "./NotificationColor";
import { IDestroyable } from "../../utils/IDestroyable";
@ -30,13 +31,13 @@ import { getUnsentMessages } from "../../components/structures/RoomStatusBar";
export class RoomNotificationState extends NotificationState implements IDestroyable {
constructor(public readonly room: Room) {
super();
this.room.on("Room.receipt", this.handleReadReceipt);
this.room.on("Room.timeline", this.handleRoomEventUpdate);
this.room.on("Room.redaction", this.handleRoomEventUpdate);
this.room.on("Room.myMembership", this.handleMembershipUpdate);
this.room.on("Room.localEchoUpdated", this.handleLocalEchoUpdated);
MatrixClientPeg.get().on("Event.decrypted", this.onEventDecrypted);
MatrixClientPeg.get().on("accountData", this.handleAccountDataUpdate);
this.room.on(RoomEvent.Receipt, this.handleReadReceipt);
this.room.on(RoomEvent.Timeline, this.handleRoomEventUpdate);
this.room.on(RoomEvent.Redaction, this.handleRoomEventUpdate);
this.room.on(RoomEvent.MyMembership, this.handleMembershipUpdate);
this.room.on(RoomEvent.LocalEchoUpdated, this.handleLocalEchoUpdated);
MatrixClientPeg.get().on(MatrixEventEvent.Decrypted, this.onEventDecrypted);
MatrixClientPeg.get().on(ClientEvent.AccountData, this.handleAccountDataUpdate);
this.updateNotificationState();
}
@ -46,14 +47,14 @@ export class RoomNotificationState extends NotificationState implements IDestroy
public destroy(): void {
super.destroy();
this.room.removeListener("Room.receipt", this.handleReadReceipt);
this.room.removeListener("Room.timeline", this.handleRoomEventUpdate);
this.room.removeListener("Room.redaction", this.handleRoomEventUpdate);
this.room.removeListener("Room.myMembership", this.handleMembershipUpdate);
this.room.removeListener("Room.localEchoUpdated", this.handleLocalEchoUpdated);
this.room.removeListener(RoomEvent.Receipt, this.handleReadReceipt);
this.room.removeListener(RoomEvent.Timeline, this.handleRoomEventUpdate);
this.room.removeListener(RoomEvent.Redaction, this.handleRoomEventUpdate);
this.room.removeListener(RoomEvent.MyMembership, this.handleMembershipUpdate);
this.room.removeListener(RoomEvent.LocalEchoUpdated, this.handleLocalEchoUpdated);
if (MatrixClientPeg.get()) {
MatrixClientPeg.get().removeListener("Event.decrypted", this.onEventDecrypted);
MatrixClientPeg.get().removeListener("accountData", this.handleAccountDataUpdate);
MatrixClientPeg.get().removeListener(MatrixEventEvent.Decrypted, this.onEventDecrypted);
MatrixClientPeg.get().removeListener(ClientEvent.AccountData, this.handleAccountDataUpdate);
}
}

View file

@ -16,6 +16,7 @@ limitations under the License.
import { Room } from "matrix-js-sdk/src/models/room";
import { ISyncStateData, SyncState } from "matrix-js-sdk/src/sync";
import { ClientEvent } from "matrix-js-sdk/src/client";
import { ActionPayload } from "../../dispatcher/payloads";
import { AsyncStoreWithClient } from "../AsyncStoreWithClient";
@ -130,10 +131,11 @@ export class RoomNotificationStateStore extends AsyncStoreWithClient<IState> {
};
protected async onReady() {
this.matrixClient.on("sync", this.onSync);
this.matrixClient.on(ClientEvent.Sync, this.onSync);
}
protected async onNotReady(): Promise<any> {
this.matrixClient?.off(ClientEvent.Sync, this.onSync);
for (const roomState of this.roomMap.values()) {
roomState.destroy();
}

View file

@ -16,6 +16,7 @@ limitations under the License.
import { EventSubscription } from 'fbemitter';
import { logger } from "matrix-js-sdk/src/logger";
import { CryptoEvent } from "matrix-js-sdk/src/crypto";
import defaultDispatcher from '../../dispatcher/dispatcher';
import { pendingVerificationRequestForUser } from '../../verification';
@ -26,9 +27,9 @@ import { SettingLevel } from "../../settings/SettingLevel";
import { UPDATE_EVENT } from '../AsyncStore';
import { ReadyWatchingStore } from '../ReadyWatchingStore';
import {
IRightPanelCard,
convertToStatePanel,
convertToStorePanel,
IRightPanelCard,
IRightPanelForRoom,
} from './RightPanelStoreIPanelState';
import RoomViewStore from '../RoomViewStore';
@ -70,7 +71,7 @@ export default class RightPanelStore extends ReadyWatchingStore {
protected async onReady(): Promise<any> {
this.isReady = true;
this.roomStoreToken = RoomViewStore.addListener(this.onRoomViewStoreUpdate);
this.matrixClient.on("crypto.verification.request", this.onVerificationRequestUpdate);
this.matrixClient.on(CryptoEvent.VerificationRequest, this.onVerificationRequestUpdate);
this.viewedRoomId = RoomViewStore.getRoomId();
this.loadCacheFromSettings();
this.emitAndUpdateSettings();
@ -84,7 +85,7 @@ export default class RightPanelStore extends ReadyWatchingStore {
protected async onNotReady(): Promise<any> {
this.isReady = false;
this.matrixClient.off("crypto.verification.request", this.onVerificationRequestUpdate);
this.matrixClient.off(CryptoEvent.VerificationRequest, this.onVerificationRequestUpdate);
this.roomStoreToken.remove();
}

View file

@ -16,11 +16,12 @@ limitations under the License.
import { ListIteratee, Many, sortBy, throttle } from "lodash";
import { EventType, RoomType } from "matrix-js-sdk/src/@types/event";
import { Room } from "matrix-js-sdk/src/models/room";
import { Room, RoomEvent } from "matrix-js-sdk/src/models/room";
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import { IRoomCapability } from "matrix-js-sdk/src/client";
import { ClientEvent, IRoomCapability } from "matrix-js-sdk/src/client";
import { logger } from "matrix-js-sdk/src/logger";
import { RoomMember } from "matrix-js-sdk/src/models/room-member";
import { RoomStateEvent } from "matrix-js-sdk/src/models/room-state";
import { AsyncStoreWithClient } from "../AsyncStoreWithClient";
import defaultDispatcher from "../../dispatcher/dispatcher";
@ -1048,24 +1049,24 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
protected async onNotReady() {
if (!SpaceStore.spacesEnabled) return;
if (this.matrixClient) {
this.matrixClient.removeListener("Room", this.onRoom);
this.matrixClient.removeListener("Room.myMembership", this.onRoom);
this.matrixClient.removeListener("Room.accountData", this.onRoomAccountData);
this.matrixClient.removeListener("RoomState.events", this.onRoomState);
this.matrixClient.removeListener("RoomState.members", this.onRoomStateMembers);
this.matrixClient.removeListener("accountData", this.onAccountData);
this.matrixClient.removeListener(ClientEvent.Room, this.onRoom);
this.matrixClient.removeListener(RoomEvent.MyMembership, this.onRoom);
this.matrixClient.removeListener(RoomEvent.AccountData, this.onRoomAccountData);
this.matrixClient.removeListener(RoomStateEvent.Events, this.onRoomState);
this.matrixClient.removeListener(RoomStateEvent.Members, this.onRoomStateMembers);
this.matrixClient.removeListener(ClientEvent.AccountData, this.onAccountData);
}
await this.reset();
}
protected async onReady() {
if (!spacesEnabled) return;
this.matrixClient.on("Room", this.onRoom);
this.matrixClient.on("Room.myMembership", this.onRoom);
this.matrixClient.on("Room.accountData", this.onRoomAccountData);
this.matrixClient.on("RoomState.events", this.onRoomState);
this.matrixClient.on("RoomState.members", this.onRoomStateMembers);
this.matrixClient.on("accountData", this.onAccountData);
this.matrixClient.on(ClientEvent.Room, this.onRoom);
this.matrixClient.on(RoomEvent.MyMembership, this.onRoom);
this.matrixClient.on(RoomEvent.AccountData, this.onRoomAccountData);
this.matrixClient.on(RoomStateEvent.Events, this.onRoomState);
this.matrixClient.on(RoomStateEvent.Members, this.onRoomStateMembers);
this.matrixClient.on(ClientEvent.AccountData, this.onAccountData);
this.matrixClient.getCapabilities().then(capabilities => {
this._restrictedJoinRuleSupport = capabilities

View file

@ -17,10 +17,12 @@
import { Room } from "matrix-js-sdk/src/models/room";
import {
ClientWidgetApi,
IModalWidgetOpenRequest,
IStickerActionRequest,
IStickyActionRequest,
ITemplateParams,
IWidget,
IWidgetApiErrorResponseData,
IWidgetApiRequest,
IWidgetApiRequestEmptyData,
IWidgetData,
@ -28,13 +30,12 @@ import {
runTemplate,
Widget,
WidgetApiFromWidgetAction,
IModalWidgetOpenRequest,
IWidgetApiErrorResponseData,
WidgetKind,
} from "matrix-widget-api";
import { EventEmitter } from "events";
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import { MatrixEvent, MatrixEventEvent } from "matrix-js-sdk/src/models/event";
import { logger } from "matrix-js-sdk/src/logger";
import { ClientEvent } from "matrix-js-sdk/src/client";
import { StopGapWidgetDriver } from "./StopGapWidgetDriver";
import { WidgetMessagingStore } from "./WidgetMessagingStore";
@ -315,8 +316,8 @@ export class StopGapWidget extends EventEmitter {
}
// Attach listeners for feeding events - the underlying widget classes handle permissions for us
MatrixClientPeg.get().on('event', this.onEvent);
MatrixClientPeg.get().on('Event.decrypted', this.onEventDecrypted);
MatrixClientPeg.get().on(ClientEvent.Event, this.onEvent);
MatrixClientPeg.get().on(MatrixEventEvent.Decrypted, this.onEventDecrypted);
this.messaging.on(`action:${WidgetApiFromWidgetAction.UpdateAlwaysOnScreen}`,
(ev: CustomEvent<IStickyActionRequest>) => {
@ -423,8 +424,8 @@ export class StopGapWidget extends EventEmitter {
this.messaging = null;
if (MatrixClientPeg.get()) {
MatrixClientPeg.get().off('event', this.onEvent);
MatrixClientPeg.get().off('Event.decrypted', this.onEventDecrypted);
MatrixClientPeg.get().off(ClientEvent.Event, this.onEvent);
MatrixClientPeg.get().off(MatrixEventEvent.Decrypted, this.onEventDecrypted);
}
}

View file

@ -16,6 +16,7 @@
import { Room } from "matrix-js-sdk/src/models/room";
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import { RoomStateEvent } from "matrix-js-sdk/src/models/room-state";
import { Optional } from "matrix-events-sdk";
import SettingsStore from "../../settings/SettingsStore";
@ -130,7 +131,7 @@ export class WidgetLayoutStore extends ReadyWatchingStore {
protected async onReady(): Promise<any> {
this.updateAllRooms();
this.matrixClient.on("RoomState.events", this.updateRoomFromState);
this.matrixClient.on(RoomStateEvent.Events, this.updateRoomFromState);
this.pinnedRef = SettingsStore.watchSetting("Widgets.pinned", null, this.updateFromSettings);
this.layoutRef = SettingsStore.watchSetting("Widgets.layout", null, this.updateFromSettings);
WidgetStore.instance.on(UPDATE_EVENT, this.updateFromWidgetStore);
@ -139,6 +140,7 @@ export class WidgetLayoutStore extends ReadyWatchingStore {
protected async onNotReady(): Promise<any> {
this.byRoom = {};
this.matrixClient?.off(RoomStateEvent.Events, this.updateRoomFromState);
SettingsStore.unwatchSetting(this.pinnedRef);
SettingsStore.unwatchSetting(this.layoutRef);
WidgetStore.instance.off(UPDATE_EVENT, this.updateFromWidgetStore);

View file

@ -16,7 +16,7 @@ limitations under the License.
import { uniq } from "lodash";
import { Room } from "matrix-js-sdk/src/models/room";
import { MatrixClient } from "matrix-js-sdk/src/client";
import { ClientEvent, MatrixClient } from "matrix-js-sdk/src/client";
import { logger } from "matrix-js-sdk/src/logger";
import { EventType } from "matrix-js-sdk/src/@types/event";
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
@ -76,11 +76,11 @@ export default class DMRoomMap {
public start() {
this.populateRoomToUser();
this.matrixClient.on("accountData", this.onAccountData);
this.matrixClient.on(ClientEvent.AccountData, this.onAccountData);
}
public stop() {
this.matrixClient.removeListener("accountData", this.onAccountData);
this.matrixClient.removeListener(ClientEvent.AccountData, this.onAccountData);
}
private onAccountData = (ev: MatrixEvent) => {

View file

@ -17,7 +17,7 @@ limitations under the License.
import { Room } from "matrix-js-sdk/src/models/room";
import { EventType } from "matrix-js-sdk/src/@types/event";
import { logger } from "matrix-js-sdk/src/logger";
import { MatrixClient } from "matrix-js-sdk/src/client";
import { ClientEvent, MatrixClient } from "matrix-js-sdk/src/client";
import { inviteUsersToRoom } from "../RoomInvite";
import Modal, { IHandle } from "../Modal";
@ -46,9 +46,9 @@ export async function awaitRoomDownSync(cli: MatrixClient, roomId: string): Prom
const checkForRoomFn = (room: Room) => {
if (room.roomId !== roomId) return;
resolve(room);
cli.off("Room", checkForRoomFn);
cli.off(ClientEvent.Room, checkForRoomFn);
};
cli.on("Room", checkForRoomFn);
cli.on(ClientEvent.Room, checkForRoomFn);
});
}

View file

@ -20,6 +20,7 @@ import { Capability, IWidget, IWidgetData, MatrixCapabilities } from "matrix-wid
import { Room } from "matrix-js-sdk/src/models/room";
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import { logger } from "matrix-js-sdk/src/logger";
import { ClientEvent, RoomStateEvent } from "matrix-js-sdk/src/matrix";
import { MatrixClientPeg } from '../MatrixClientPeg';
import SdkConfig from "../SdkConfig";
@ -156,16 +157,16 @@ export default class WidgetUtils {
function onAccountData(ev) {
const currentAccountDataEvent = MatrixClientPeg.get().getAccountData('m.widgets');
if (eventInIntendedState(currentAccountDataEvent)) {
MatrixClientPeg.get().removeListener('accountData', onAccountData);
MatrixClientPeg.get().removeListener(ClientEvent.AccountData, onAccountData);
clearTimeout(timerId);
resolve();
}
}
const timerId = setTimeout(() => {
MatrixClientPeg.get().removeListener('accountData', onAccountData);
MatrixClientPeg.get().removeListener(ClientEvent.AccountData, onAccountData);
reject(new Error("Timed out waiting for widget ID " + widgetId + " to appear"));
}, WIDGET_WAIT_TIME);
MatrixClientPeg.get().on('accountData', onAccountData);
MatrixClientPeg.get().on(ClientEvent.AccountData, onAccountData);
});
}
@ -211,16 +212,16 @@ export default class WidgetUtils {
const currentWidgetEvents = room.currentState.getStateEvents('im.vector.modular.widgets');
if (eventsInIntendedState(currentWidgetEvents)) {
MatrixClientPeg.get().removeListener('RoomState.events', onRoomStateEvents);
MatrixClientPeg.get().removeListener(RoomStateEvent.Events, onRoomStateEvents);
clearTimeout(timerId);
resolve();
}
}
const timerId = setTimeout(() => {
MatrixClientPeg.get().removeListener('RoomState.events', onRoomStateEvents);
MatrixClientPeg.get().removeListener(RoomStateEvent.Events, onRoomStateEvents);
reject(new Error("Timed out waiting for widget ID " + widgetId + " to appear"));
}, WIDGET_WAIT_TIME);
MatrixClientPeg.get().on('RoomState.events', onRoomStateEvents);
MatrixClientPeg.get().on(RoomStateEvent.Events, onRoomStateEvents);
});
}

View file

@ -16,7 +16,7 @@ limitations under the License.
import { Room } from "matrix-js-sdk/src/models/room";
import { sleep } from "matrix-js-sdk/src/utils";
import { EventStatus } from "matrix-js-sdk/src/models/event";
import { EventStatus, MatrixEventEvent } from "matrix-js-sdk/src/models/event";
import React from "react";
import { MatrixClientPeg } from "../MatrixClientPeg";
@ -122,12 +122,12 @@ export async function leaveRoomBehaviour(roomId: string, retry = true, spinner =
}
if (!ev.status || ev.status === EventStatus.SENT) {
ev.off("Event.status", handler);
ev.off(MatrixEventEvent.Status, handler);
resolve();
}
};
ev.on("Event.status", handler);
ev.on(MatrixEventEvent.Status, handler);
})));
let results: { [roomId: string]: Error & { errcode?: string, message: string, data?: Record<string, any> } } = {};

View file

@ -19,8 +19,9 @@ import * as utils from "matrix-js-sdk/src/utils";
import { Room } from "matrix-js-sdk/src/models/room";
import { EventType } from "matrix-js-sdk/src/@types/event";
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import { RoomMember } from "matrix-js-sdk/src/models/room-member";
import { RoomMember, RoomMemberEvent } from "matrix-js-sdk/src/models/room-member";
import { logger } from "matrix-js-sdk/src/logger";
import { RoomStateEvent } from "matrix-js-sdk/src/models/room-state";
import { MatrixClientPeg } from "../../MatrixClientPeg";
import MatrixToPermalinkConstructor, { baseUrl as matrixtoBaseUrl } from "./MatrixToPermalinkConstructor";
@ -122,14 +123,14 @@ export class RoomPermalinkCreator {
start() {
this.load();
this.room.on("RoomMember.membership", this.onMembership);
this.room.on("RoomState.events", this.onRoomState);
this.room.client.on(RoomMemberEvent.Membership, this.onMembership);
this.room.currentState.on(RoomStateEvent.Events, this.onRoomState);
this.started = true;
}
stop() {
this.room.removeListener("RoomMember.membership", this.onMembership);
this.room.removeListener("RoomState.events", this.onRoomState);
this.room.client.removeListener(RoomMemberEvent.Membership, this.onMembership);
this.room.currentState.removeListener(RoomStateEvent.Events, this.onRoomState);
this.started = false;
}
@ -176,6 +177,8 @@ export class RoomPermalinkCreator {
};
private onMembership = (evt: MatrixEvent, member: RoomMember, oldMembership: string) => {
if (member.roomId !== this.room.roomId) return;
const userId = member.userId;
const membership = member.membership;
const serverName = getServerName(userId);

View file

@ -15,7 +15,7 @@ limitations under the License.
*/
import { logger } from "matrix-js-sdk/src/logger";
import { IClientWellKnown } from "matrix-js-sdk/src/client";
import { ClientEvent, IClientWellKnown } from "matrix-js-sdk/src/client";
import SdkConfig from "../SdkConfig";
import { MatrixClientPeg } from "../MatrixClientPeg";
@ -63,7 +63,7 @@ export class Jitsi {
public start() {
const cli = MatrixClientPeg.get();
cli.on("WellKnown.client", this.update);
cli.on(ClientEvent.ClientWellKnown, this.update);
// call update initially in case we missed the first WellKnown.client event and for if no well-known present
this.update(cli.getClientWellKnown());
}

View file

@ -103,18 +103,22 @@ describe('Permalinks', function() {
});
it('should change candidate server when highest power level user leaves the room', function() {
const roomId = "!fake:example.org";
const member95 = {
userId: "@alice:pl_95",
powerLevel: 95,
roomId,
};
const room = mockRoom("!fake:example.org", [
const room = mockRoom(roomId, [
{
userId: "@alice:pl_50",
powerLevel: 50,
roomId,
},
{
userId: "@alice:pl_75",
powerLevel: 75,
roomId,
},
member95,
]);