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
|
@ -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) => {
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -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> } } = {};
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue