Apply strictNullChecks to src/components/structures/Space* (#10475)

This commit is contained in:
Michael Telatynski
2023-03-30 08:28:08 +01:00
committed by GitHub
parent 9a733a6444
commit 9848cdf4e7
3 changed files with 28 additions and 22 deletions

View File

@@ -87,7 +87,7 @@ const partitionSpacesAndRooms = (arr: Room[]): [Room[], Room[]] => {
);
};
const validOrder = (order: string): string | undefined => {
const validOrder = (order?: string): string | undefined => {
if (
typeof order === "string" &&
order.length <= 50 &&
@@ -101,7 +101,11 @@ const validOrder = (order: string): string | undefined => {
};
// For sorting space children using a validated `order`, `origin_server_ts`, `room_id`
export const getChildOrder = (order: string, ts: number, roomId: string): Array<Many<ListIteratee<unknown>>> => {
export const getChildOrder = (
order: string | undefined,
ts: number,
roomId: string,
): Array<Many<ListIteratee<unknown>>> => {
return [validOrder(order) ?? NaN, ts, roomId]; // NaN has lodash sort it at the end in asc
};
@@ -378,8 +382,9 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
}
public getParents(roomId: string, canonicalOnly = false): Room[] {
const userId = this.matrixClient?.getUserId();
const room = this.matrixClient?.getRoom(roomId);
if (!this.matrixClient) return [];
const userId = this.matrixClient.getSafeUserId();
const room = this.matrixClient.getRoom(roomId);
const events = room?.currentState.getStateEvents(EventType.SpaceParent) ?? [];
return filterBoolean(
events.map((ev) => {
@@ -871,6 +876,7 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
};
private switchSpaceIfNeeded = (roomId = SdkContextClass.instance.roomViewStore.getRoomId()): void => {
if (!roomId) return;
if (!this.isRoomInSpace(this.activeSpace, roomId) && !this.matrixClient.getRoom(roomId)?.isSpaceRoom()) {
this.switchToRelatedSpace(roomId);
}