Improve typing around event emitter handlers (#7816)
This commit is contained in:
parent
213b32bf14
commit
7fa01ffb06
79 changed files with 548 additions and 471 deletions
|
@ -15,7 +15,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();
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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) => {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
||||
|
|
|
@ -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({});
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue