Use MatrixClientPeg::safeGet for strict typing (#10989)
This commit is contained in:
+18
-17
@@ -91,7 +91,7 @@ const msgTypeHandlers: Record<string, (event: MatrixEvent) => string | null> = {
|
||||
return null;
|
||||
}
|
||||
|
||||
return TextForEvent.textForEvent(event, MatrixClientPeg.get());
|
||||
return TextForEvent.textForEvent(event, MatrixClientPeg.safeGet());
|
||||
},
|
||||
};
|
||||
|
||||
@@ -111,13 +111,13 @@ class NotifierClass {
|
||||
if (msgType && msgTypeHandlers.hasOwnProperty(msgType)) {
|
||||
return msgTypeHandlers[msgType](ev);
|
||||
}
|
||||
return TextForEvent.textForEvent(ev, MatrixClientPeg.get());
|
||||
return TextForEvent.textForEvent(ev, MatrixClientPeg.safeGet());
|
||||
}
|
||||
|
||||
// XXX: exported for tests
|
||||
public displayPopupNotification(ev: MatrixEvent, room: Room): void {
|
||||
const plaf = PlatformPeg.get();
|
||||
const cli = MatrixClientPeg.get();
|
||||
const cli = MatrixClientPeg.safeGet();
|
||||
if (!plaf) {
|
||||
return;
|
||||
}
|
||||
@@ -215,7 +215,7 @@ class NotifierClass {
|
||||
|
||||
// XXX: Exported for tests
|
||||
public async playAudioNotification(ev: MatrixEvent, room: Room): Promise<void> {
|
||||
const cli = MatrixClientPeg.get();
|
||||
const cli = MatrixClientPeg.safeGet();
|
||||
if (localNotificationsAreSilenced(cli)) {
|
||||
return;
|
||||
}
|
||||
@@ -246,20 +246,21 @@ class NotifierClass {
|
||||
}
|
||||
|
||||
public start(): void {
|
||||
MatrixClientPeg.get().on(RoomEvent.Timeline, this.onEvent);
|
||||
MatrixClientPeg.get().on(RoomEvent.Receipt, this.onRoomReceipt);
|
||||
MatrixClientPeg.get().on(MatrixEventEvent.Decrypted, this.onEventDecrypted);
|
||||
MatrixClientPeg.get().on(ClientEvent.Sync, this.onSyncStateChange);
|
||||
const cli = MatrixClientPeg.safeGet();
|
||||
cli.on(RoomEvent.Timeline, this.onEvent);
|
||||
cli.on(RoomEvent.Receipt, this.onRoomReceipt);
|
||||
cli.on(MatrixEventEvent.Decrypted, this.onEventDecrypted);
|
||||
cli.on(ClientEvent.Sync, this.onSyncStateChange);
|
||||
this.toolbarHidden = false;
|
||||
this.isSyncing = false;
|
||||
}
|
||||
|
||||
public stop(): void {
|
||||
if (MatrixClientPeg.get()) {
|
||||
MatrixClientPeg.get().removeListener(RoomEvent.Timeline, this.onEvent);
|
||||
MatrixClientPeg.get().removeListener(RoomEvent.Receipt, this.onRoomReceipt);
|
||||
MatrixClientPeg.get().removeListener(MatrixEventEvent.Decrypted, this.onEventDecrypted);
|
||||
MatrixClientPeg.get().removeListener(ClientEvent.Sync, this.onSyncStateChange);
|
||||
MatrixClientPeg.get()!.removeListener(RoomEvent.Timeline, this.onEvent);
|
||||
MatrixClientPeg.get()!.removeListener(RoomEvent.Receipt, this.onRoomReceipt);
|
||||
MatrixClientPeg.get()!.removeListener(MatrixEventEvent.Decrypted, this.onEventDecrypted);
|
||||
MatrixClientPeg.get()!.removeListener(ClientEvent.Sync, this.onSyncStateChange);
|
||||
}
|
||||
this.isSyncing = false;
|
||||
}
|
||||
@@ -400,7 +401,7 @@ class NotifierClass {
|
||||
|
||||
// wait for first non-cached sync to complete
|
||||
if (![SyncState.Stopped, SyncState.Error].includes(state) && !data?.fromCache) {
|
||||
createLocalNotificationSettingsIfNeeded(MatrixClientPeg.get());
|
||||
createLocalNotificationSettingsIfNeeded(MatrixClientPeg.safeGet());
|
||||
}
|
||||
};
|
||||
|
||||
@@ -413,9 +414,9 @@ class NotifierClass {
|
||||
): void => {
|
||||
if (!data.liveEvent) return; // only notify for new things, not old.
|
||||
if (!this.isSyncing) return; // don't alert for any messages initially
|
||||
if (ev.getSender() === MatrixClientPeg.get().getUserId()) return;
|
||||
if (ev.getSender() === MatrixClientPeg.safeGet().getUserId()) return;
|
||||
|
||||
MatrixClientPeg.get().decryptEventIfNeeded(ev);
|
||||
MatrixClientPeg.safeGet().decryptEventIfNeeded(ev);
|
||||
|
||||
// If it's an encrypted event and the type is still 'm.room.encrypted',
|
||||
// it hasn't yet been decrypted, so wait until it is.
|
||||
@@ -473,14 +474,14 @@ class NotifierClass {
|
||||
roomId = nativeRoomId;
|
||||
}
|
||||
}
|
||||
const room = MatrixClientPeg.get().getRoom(roomId);
|
||||
const room = MatrixClientPeg.safeGet().getRoom(roomId);
|
||||
if (!room) {
|
||||
// e.g we are in the process of joining a room.
|
||||
// Seen in the cypress lazy-loading test.
|
||||
return;
|
||||
}
|
||||
|
||||
const actions = MatrixClientPeg.get().getPushActionsForEvent(ev);
|
||||
const actions = MatrixClientPeg.safeGet().getPushActionsForEvent(ev);
|
||||
|
||||
if (actions?.notify) {
|
||||
this.performCustomEventHandling(ev);
|
||||
|
||||
Reference in New Issue
Block a user