Use MatrixClientPeg::safeGet for strict typing (#10989)
This commit is contained in:
@@ -70,7 +70,7 @@ export class BanList {
|
||||
public async banEntity(kind: string, entity: string, reason: string): Promise<any> {
|
||||
const type = ruleTypeToStable(kind);
|
||||
if (!type) return; // unknown rule type
|
||||
await MatrixClientPeg.get().sendStateEvent(
|
||||
await MatrixClientPeg.safeGet().sendStateEvent(
|
||||
this._roomId,
|
||||
type,
|
||||
{
|
||||
@@ -87,7 +87,7 @@ export class BanList {
|
||||
const type = ruleTypeToStable(kind);
|
||||
if (!type) return; // unknown rule type
|
||||
// Empty state event is effectively deleting it.
|
||||
await MatrixClientPeg.get().sendStateEvent(this._roomId, type, {}, "rule:" + entity);
|
||||
await MatrixClientPeg.safeGet().sendStateEvent(this._roomId, type, {}, "rule:" + entity);
|
||||
this._rules = this._rules.filter((r) => {
|
||||
if (r.kind !== ruleTypeToStable(kind)) return true;
|
||||
if (r.entity !== entity) return true;
|
||||
@@ -98,7 +98,7 @@ export class BanList {
|
||||
public updateList(): void {
|
||||
this._rules = [];
|
||||
|
||||
const room = MatrixClientPeg.get().getRoom(this._roomId);
|
||||
const room = MatrixClientPeg.safeGet().getRoom(this._roomId);
|
||||
if (!room) return;
|
||||
|
||||
for (const eventType of ALL_RULE_TYPES) {
|
||||
|
||||
@@ -67,7 +67,7 @@ export class Mjolnir {
|
||||
public setup(): void {
|
||||
if (!MatrixClientPeg.get()) return;
|
||||
this.updateLists(SettingsStore.getValue("mjolnirRooms"));
|
||||
MatrixClientPeg.get().on(RoomStateEvent.Events, this.onEvent);
|
||||
MatrixClientPeg.get()!.on(RoomStateEvent.Events, this.onEvent);
|
||||
}
|
||||
|
||||
public stop(): void {
|
||||
@@ -81,14 +81,13 @@ export class Mjolnir {
|
||||
this.dispatcherRef = null;
|
||||
}
|
||||
|
||||
if (!MatrixClientPeg.get()) return;
|
||||
MatrixClientPeg.get().removeListener(RoomStateEvent.Events, this.onEvent);
|
||||
MatrixClientPeg.get()?.removeListener(RoomStateEvent.Events, this.onEvent);
|
||||
}
|
||||
|
||||
public async getOrCreatePersonalList(): Promise<BanList> {
|
||||
let personalRoomId = SettingsStore.getValue("mjolnirPersonalRoom");
|
||||
if (!personalRoomId) {
|
||||
const resp = await MatrixClientPeg.get().createRoom({
|
||||
const resp = await MatrixClientPeg.safeGet().createRoom({
|
||||
name: _t("My Ban List"),
|
||||
topic: _t("This is your list of users/servers you have blocked - don't leave the room!"),
|
||||
preset: Preset.PrivateChat,
|
||||
|
||||
Reference in New Issue
Block a user