Apply `strictNullChecks` to `src/components/structures/Space*` (#10475)
parent
9a733a6444
commit
9848cdf4e7
|
@ -362,7 +362,7 @@ export const showRoom = (cli: MatrixClient, hierarchy: RoomHierarchy, roomId: st
|
||||||
// Don't let the user view a room they won't be able to either peek or join:
|
// Don't let the user view a room they won't be able to either peek or join:
|
||||||
// fail earlier so they don't have to click back to the directory.
|
// fail earlier so they don't have to click back to the directory.
|
||||||
if (cli.isGuest()) {
|
if (cli.isGuest()) {
|
||||||
if (!room.world_readable && !room.guest_can_join) {
|
if (!room?.world_readable && !room?.guest_can_join) {
|
||||||
defaultDispatcher.dispatch({ action: "require_registration" });
|
defaultDispatcher.dispatch({ action: "require_registration" });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -374,12 +374,12 @@ export const showRoom = (cli: MatrixClient, hierarchy: RoomHierarchy, roomId: st
|
||||||
action: Action.ViewRoom,
|
action: Action.ViewRoom,
|
||||||
should_peek: true,
|
should_peek: true,
|
||||||
room_alias: roomAlias,
|
room_alias: roomAlias,
|
||||||
room_id: room.room_id,
|
room_id: roomId,
|
||||||
via_servers: Array.from(hierarchy.viaMap.get(roomId) || []),
|
via_servers: Array.from(hierarchy.viaMap.get(roomId) || []),
|
||||||
oob_data: {
|
oob_data: {
|
||||||
avatarUrl: room.avatar_url,
|
avatarUrl: room?.avatar_url,
|
||||||
// XXX: This logic is duplicated from the JS SDK which would normally decide what the name is.
|
// XXX: This logic is duplicated from the JS SDK which would normally decide what the name is.
|
||||||
name: room.name || roomAlias || _t("Unnamed room"),
|
name: room?.name || roomAlias || _t("Unnamed room"),
|
||||||
roomType,
|
roomType,
|
||||||
} as IOOBData,
|
} as IOOBData,
|
||||||
metricsTrigger: "RoomDirectory",
|
metricsTrigger: "RoomDirectory",
|
||||||
|
@ -560,7 +560,7 @@ export const useRoomHierarchy = (
|
||||||
const hierarchy = new RoomHierarchy(space, INITIAL_PAGE_SIZE);
|
const hierarchy = new RoomHierarchy(space, INITIAL_PAGE_SIZE);
|
||||||
hierarchy.load().then(() => {
|
hierarchy.load().then(() => {
|
||||||
if (space !== hierarchy.root) return; // discard stale results
|
if (space !== hierarchy.root) return; // discard stale results
|
||||||
setRooms(hierarchy.rooms);
|
setRooms(hierarchy.rooms ?? []);
|
||||||
}, setError);
|
}, setError);
|
||||||
setHierarchy(hierarchy);
|
setHierarchy(hierarchy);
|
||||||
}, [space]);
|
}, [space]);
|
||||||
|
@ -577,7 +577,7 @@ export const useRoomHierarchy = (
|
||||||
async (pageSize?: number): Promise<void> => {
|
async (pageSize?: number): Promise<void> => {
|
||||||
if (!hierarchy || hierarchy.loading || !hierarchy.canLoadMore || hierarchy.noSupport || error) return;
|
if (!hierarchy || hierarchy.loading || !hierarchy.canLoadMore || hierarchy.noSupport || error) return;
|
||||||
await hierarchy.load(pageSize).catch(setError);
|
await hierarchy.load(pageSize).catch(setError);
|
||||||
setRooms(hierarchy.rooms);
|
setRooms(hierarchy.rooms ?? []);
|
||||||
},
|
},
|
||||||
[error, hierarchy],
|
[error, hierarchy],
|
||||||
);
|
);
|
||||||
|
@ -638,7 +638,7 @@ const ManageButtons: React.FC<IManageButtonsProps> = ({ hierarchy, selected, set
|
||||||
const [saving, setSaving] = useState(false);
|
const [saving, setSaving] = useState(false);
|
||||||
|
|
||||||
const selectedRelations = Array.from(selected.keys()).flatMap((parentId) => {
|
const selectedRelations = Array.from(selected.keys()).flatMap((parentId) => {
|
||||||
return [...selected.get(parentId).values()].map((childId) => [parentId, childId]);
|
return [...selected.get(parentId)!.values()].map((childId) => [parentId, childId]);
|
||||||
});
|
});
|
||||||
|
|
||||||
const selectionAllSuggested = selectedRelations.every(([parentId, childId]) => {
|
const selectionAllSuggested = selectedRelations.every(([parentId, childId]) => {
|
||||||
|
@ -814,12 +814,13 @@ const SpaceHierarchy: React.FC<IProps> = ({ space, initialText = "", showRoom, a
|
||||||
space?.getMyMembership() === "join" &&
|
space?.getMyMembership() === "join" &&
|
||||||
space.currentState.maySendStateEvent(EventType.SpaceChild, cli.getSafeUserId());
|
space.currentState.maySendStateEvent(EventType.SpaceChild, cli.getSafeUserId());
|
||||||
|
|
||||||
|
const root = hierarchy.roomMap.get(space.roomId);
|
||||||
let results: JSX.Element | undefined;
|
let results: JSX.Element | undefined;
|
||||||
if (filteredRoomSet.size) {
|
if (filteredRoomSet.size && root) {
|
||||||
results = (
|
results = (
|
||||||
<>
|
<>
|
||||||
<HierarchyLevel
|
<HierarchyLevel
|
||||||
root={hierarchy.roomMap.get(space.roomId)}
|
root={root}
|
||||||
roomSet={filteredRoomSet}
|
roomSet={filteredRoomSet}
|
||||||
hierarchy={hierarchy}
|
hierarchy={hierarchy}
|
||||||
parents={new Set()}
|
parents={new Set()}
|
||||||
|
|
|
@ -18,7 +18,7 @@ import { EventType, RoomType } from "matrix-js-sdk/src/@types/event";
|
||||||
import { JoinRule, Preset } from "matrix-js-sdk/src/@types/partials";
|
import { JoinRule, Preset } from "matrix-js-sdk/src/@types/partials";
|
||||||
import { logger } from "matrix-js-sdk/src/logger";
|
import { logger } from "matrix-js-sdk/src/logger";
|
||||||
import { Room, RoomEvent } from "matrix-js-sdk/src/models/room";
|
import { Room, RoomEvent } from "matrix-js-sdk/src/models/room";
|
||||||
import React, { MutableRefObject, useCallback, useContext, useRef, useState } from "react";
|
import React, { RefObject, useCallback, useContext, useRef, useState } from "react";
|
||||||
|
|
||||||
import MatrixClientContext from "../../contexts/MatrixClientContext";
|
import MatrixClientContext from "../../contexts/MatrixClientContext";
|
||||||
import createRoom, { IOpts } from "../../createRoom";
|
import createRoom, { IOpts } from "../../createRoom";
|
||||||
|
@ -353,7 +353,7 @@ const SpaceSetupFirstRooms: React.FC<{
|
||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
onFinished(roomIds[0]);
|
onFinished(roomIds[0] ?? undefined);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.error("Failed to create initial space rooms", e);
|
logger.error("Failed to create initial space rooms", e);
|
||||||
setError(_t("Failed to create initial space rooms"));
|
setError(_t("Failed to create initial space rooms"));
|
||||||
|
@ -511,7 +511,7 @@ const SpaceSetupPrivateInvite: React.FC<{
|
||||||
const [busy, setBusy] = useState(false);
|
const [busy, setBusy] = useState(false);
|
||||||
const [error, setError] = useState("");
|
const [error, setError] = useState("");
|
||||||
const numFields = 3;
|
const numFields = 3;
|
||||||
const fieldRefs: MutableRefObject<Field | undefined>[] = [useRef(), useRef(), useRef()];
|
const fieldRefs = [useRef(), useRef(), useRef()] as RefObject<Field>[];
|
||||||
const [emailAddresses, setEmailAddress] = useStateArray(numFields, "");
|
const [emailAddresses, setEmailAddress] = useStateArray(numFields, "");
|
||||||
const fields = new Array(numFields).fill(0).map((x, i) => {
|
const fields = new Array(numFields).fill(0).map((x, i) => {
|
||||||
const name = "emailAddress" + i;
|
const name = "emailAddress" + i;
|
||||||
|
@ -537,12 +537,12 @@ const SpaceSetupPrivateInvite: React.FC<{
|
||||||
if (busy) return;
|
if (busy) return;
|
||||||
setError("");
|
setError("");
|
||||||
for (const fieldRef of fieldRefs) {
|
for (const fieldRef of fieldRefs) {
|
||||||
const valid = await fieldRef.current.validate({ allowEmpty: true });
|
const valid = await fieldRef.current?.validate({ allowEmpty: true });
|
||||||
|
|
||||||
if (valid === false) {
|
if (valid === false) {
|
||||||
// true/null are allowed
|
// true/null are allowed
|
||||||
fieldRef.current.focus();
|
fieldRef.current!.focus();
|
||||||
fieldRef.current.validate({ allowEmpty: true, focused: true });
|
fieldRef.current!.validate({ allowEmpty: true, focused: true });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -636,7 +636,6 @@ export default class SpaceRoomView extends React.PureComponent<IProps, IState> {
|
||||||
public static contextType = MatrixClientContext;
|
public static contextType = MatrixClientContext;
|
||||||
public context!: React.ContextType<typeof MatrixClientContext>;
|
public context!: React.ContextType<typeof MatrixClientContext>;
|
||||||
|
|
||||||
private readonly creator: string;
|
|
||||||
private readonly dispatcherRef: string;
|
private readonly dispatcherRef: string;
|
||||||
|
|
||||||
public constructor(props: IProps, context: React.ContextType<typeof MatrixClientContext>) {
|
public constructor(props: IProps, context: React.ContextType<typeof MatrixClientContext>) {
|
||||||
|
@ -644,8 +643,8 @@ export default class SpaceRoomView extends React.PureComponent<IProps, IState> {
|
||||||
|
|
||||||
let phase = Phase.Landing;
|
let phase = Phase.Landing;
|
||||||
|
|
||||||
this.creator = this.props.space.currentState.getStateEvents(EventType.RoomCreate, "")?.getSender();
|
const creator = this.props.space.currentState.getStateEvents(EventType.RoomCreate, "")?.getSender();
|
||||||
const showSetup = this.props.justCreatedOpts && context.getUserId() === this.creator;
|
const showSetup = this.props.justCreatedOpts && context.getSafeUserId() === creator;
|
||||||
|
|
||||||
if (showSetup) {
|
if (showSetup) {
|
||||||
phase =
|
phase =
|
||||||
|
|
|
@ -87,7 +87,7 @@ const partitionSpacesAndRooms = (arr: Room[]): [Room[], Room[]] => {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const validOrder = (order: string): string | undefined => {
|
const validOrder = (order?: string): string | undefined => {
|
||||||
if (
|
if (
|
||||||
typeof order === "string" &&
|
typeof order === "string" &&
|
||||||
order.length <= 50 &&
|
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`
|
// 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
|
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[] {
|
public getParents(roomId: string, canonicalOnly = false): Room[] {
|
||||||
const userId = this.matrixClient?.getUserId();
|
if (!this.matrixClient) return [];
|
||||||
const room = this.matrixClient?.getRoom(roomId);
|
const userId = this.matrixClient.getSafeUserId();
|
||||||
|
const room = this.matrixClient.getRoom(roomId);
|
||||||
const events = room?.currentState.getStateEvents(EventType.SpaceParent) ?? [];
|
const events = room?.currentState.getStateEvents(EventType.SpaceParent) ?? [];
|
||||||
return filterBoolean(
|
return filterBoolean(
|
||||||
events.map((ev) => {
|
events.map((ev) => {
|
||||||
|
@ -871,6 +876,7 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
|
||||||
};
|
};
|
||||||
|
|
||||||
private switchSpaceIfNeeded = (roomId = SdkContextClass.instance.roomViewStore.getRoomId()): void => {
|
private switchSpaceIfNeeded = (roomId = SdkContextClass.instance.roomViewStore.getRoomId()): void => {
|
||||||
|
if (!roomId) return;
|
||||||
if (!this.isRoomInSpace(this.activeSpace, roomId) && !this.matrixClient.getRoom(roomId)?.isSpaceRoom()) {
|
if (!this.isRoomInSpace(this.activeSpace, roomId) && !this.matrixClient.getRoom(roomId)?.isSpaceRoom()) {
|
||||||
this.switchToRelatedSpace(roomId);
|
this.switchToRelatedSpace(roomId);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue