mirror of https://github.com/vector-im/riot-web
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:
|
||||
// fail earlier so they don't have to click back to the directory.
|
||||
if (cli.isGuest()) {
|
||||
if (!room.world_readable && !room.guest_can_join) {
|
||||
if (!room?.world_readable && !room?.guest_can_join) {
|
||||
defaultDispatcher.dispatch({ action: "require_registration" });
|
||||
return;
|
||||
}
|
||||
|
@ -374,12 +374,12 @@ export const showRoom = (cli: MatrixClient, hierarchy: RoomHierarchy, roomId: st
|
|||
action: Action.ViewRoom,
|
||||
should_peek: true,
|
||||
room_alias: roomAlias,
|
||||
room_id: room.room_id,
|
||||
room_id: roomId,
|
||||
via_servers: Array.from(hierarchy.viaMap.get(roomId) || []),
|
||||
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.
|
||||
name: room.name || roomAlias || _t("Unnamed room"),
|
||||
name: room?.name || roomAlias || _t("Unnamed room"),
|
||||
roomType,
|
||||
} as IOOBData,
|
||||
metricsTrigger: "RoomDirectory",
|
||||
|
@ -560,7 +560,7 @@ export const useRoomHierarchy = (
|
|||
const hierarchy = new RoomHierarchy(space, INITIAL_PAGE_SIZE);
|
||||
hierarchy.load().then(() => {
|
||||
if (space !== hierarchy.root) return; // discard stale results
|
||||
setRooms(hierarchy.rooms);
|
||||
setRooms(hierarchy.rooms ?? []);
|
||||
}, setError);
|
||||
setHierarchy(hierarchy);
|
||||
}, [space]);
|
||||
|
@ -577,7 +577,7 @@ export const useRoomHierarchy = (
|
|||
async (pageSize?: number): Promise<void> => {
|
||||
if (!hierarchy || hierarchy.loading || !hierarchy.canLoadMore || hierarchy.noSupport || error) return;
|
||||
await hierarchy.load(pageSize).catch(setError);
|
||||
setRooms(hierarchy.rooms);
|
||||
setRooms(hierarchy.rooms ?? []);
|
||||
},
|
||||
[error, hierarchy],
|
||||
);
|
||||
|
@ -638,7 +638,7 @@ const ManageButtons: React.FC<IManageButtonsProps> = ({ hierarchy, selected, set
|
|||
const [saving, setSaving] = useState(false);
|
||||
|
||||
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]) => {
|
||||
|
@ -814,12 +814,13 @@ const SpaceHierarchy: React.FC<IProps> = ({ space, initialText = "", showRoom, a
|
|||
space?.getMyMembership() === "join" &&
|
||||
space.currentState.maySendStateEvent(EventType.SpaceChild, cli.getSafeUserId());
|
||||
|
||||
const root = hierarchy.roomMap.get(space.roomId);
|
||||
let results: JSX.Element | undefined;
|
||||
if (filteredRoomSet.size) {
|
||||
if (filteredRoomSet.size && root) {
|
||||
results = (
|
||||
<>
|
||||
<HierarchyLevel
|
||||
root={hierarchy.roomMap.get(space.roomId)}
|
||||
root={root}
|
||||
roomSet={filteredRoomSet}
|
||||
hierarchy={hierarchy}
|
||||
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 { logger } from "matrix-js-sdk/src/logger";
|
||||
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 createRoom, { IOpts } from "../../createRoom";
|
||||
|
@ -353,7 +353,7 @@ const SpaceSetupFirstRooms: React.FC<{
|
|||
});
|
||||
}),
|
||||
);
|
||||
onFinished(roomIds[0]);
|
||||
onFinished(roomIds[0] ?? undefined);
|
||||
} catch (e) {
|
||||
logger.error("Failed to create initial space rooms", e);
|
||||
setError(_t("Failed to create initial space rooms"));
|
||||
|
@ -511,7 +511,7 @@ const SpaceSetupPrivateInvite: React.FC<{
|
|||
const [busy, setBusy] = useState(false);
|
||||
const [error, setError] = useState("");
|
||||
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 fields = new Array(numFields).fill(0).map((x, i) => {
|
||||
const name = "emailAddress" + i;
|
||||
|
@ -537,12 +537,12 @@ const SpaceSetupPrivateInvite: React.FC<{
|
|||
if (busy) return;
|
||||
setError("");
|
||||
for (const fieldRef of fieldRefs) {
|
||||
const valid = await fieldRef.current.validate({ allowEmpty: true });
|
||||
const valid = await fieldRef.current?.validate({ allowEmpty: true });
|
||||
|
||||
if (valid === false) {
|
||||
// true/null are allowed
|
||||
fieldRef.current.focus();
|
||||
fieldRef.current.validate({ allowEmpty: true, focused: true });
|
||||
fieldRef.current!.focus();
|
||||
fieldRef.current!.validate({ allowEmpty: true, focused: true });
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -636,7 +636,6 @@ export default class SpaceRoomView extends React.PureComponent<IProps, IState> {
|
|||
public static contextType = MatrixClientContext;
|
||||
public context!: React.ContextType<typeof MatrixClientContext>;
|
||||
|
||||
private readonly creator: string;
|
||||
private readonly dispatcherRef: string;
|
||||
|
||||
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;
|
||||
|
||||
this.creator = this.props.space.currentState.getStateEvents(EventType.RoomCreate, "")?.getSender();
|
||||
const showSetup = this.props.justCreatedOpts && context.getUserId() === this.creator;
|
||||
const creator = this.props.space.currentState.getStateEvents(EventType.RoomCreate, "")?.getSender();
|
||||
const showSetup = this.props.justCreatedOpts && context.getSafeUserId() === creator;
|
||||
|
||||
if (showSetup) {
|
||||
phase =
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue