Strictify RoomView.tsx (#11163)

This commit is contained in:
alunturner 2023-06-30 13:06:03 +01:00 committed by GitHub
parent 9fa58e4e90
commit 3fb4dac6fc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -117,6 +117,7 @@ import { WidgetType } from "../../widgets/WidgetType";
import WidgetUtils from "../../utils/WidgetUtils"; import WidgetUtils from "../../utils/WidgetUtils";
import { shouldEncryptRoomWithSingle3rdPartyInvite } from "../../utils/room/shouldEncryptRoomWithSingle3rdPartyInvite"; import { shouldEncryptRoomWithSingle3rdPartyInvite } from "../../utils/room/shouldEncryptRoomWithSingle3rdPartyInvite";
import { WaitingForThirdPartyRoomView } from "./WaitingForThirdPartyRoomView"; import { WaitingForThirdPartyRoomView } from "./WaitingForThirdPartyRoomView";
import { isNotUndefined } from "../../Typeguards";
const DEBUG = false; const DEBUG = false;
const PREVENT_MULTIPLE_JITSI_WITHIN = 30_000; const PREVENT_MULTIPLE_JITSI_WITHIN = 30_000;
@ -809,7 +810,21 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
return this.state.room?.roomId ?? this.state.roomId; return this.state.room?.roomId ?? this.state.roomId;
}; };
private getPermalinkCreatorForRoom(room: Room): RoomPermalinkCreator { private getPermalinkCreatorForRoom(): RoomPermalinkCreator {
const { room, roomId } = this.state;
// If room is undefined, attempt to use the roomId to create and store a permalinkCreator.
// Throw an error if we can not find a roomId in state.
if (room === undefined) {
if (isNotUndefined(roomId)) {
const permalinkCreator = new RoomPermalinkCreator(null, roomId);
this.permalinkCreators[roomId] = permalinkCreator;
return permalinkCreator;
} else {
throw new Error("Cannot get a permalink creator without a roomId");
}
}
if (this.permalinkCreators[room.roomId]) return this.permalinkCreators[room.roomId]; if (this.permalinkCreators[room.roomId]) return this.permalinkCreators[room.roomId];
this.permalinkCreators[room.roomId] = new RoomPermalinkCreator(room); this.permalinkCreators[room.roomId] = new RoomPermalinkCreator(room);
@ -1096,14 +1111,19 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
payload.data.threadId, payload.data.threadId,
); );
break; break;
case "picture_snapshot": case "picture_snapshot": {
const roomId = this.getRoomId();
if (isNotUndefined(roomId)) {
ContentMessages.sharedInstance().sendContentListToRoom( ContentMessages.sharedInstance().sendContentListToRoom(
[payload.file], [payload.file],
this.getRoomId(), roomId,
undefined, undefined,
this.context.client, this.context.client,
); );
}
break; break;
}
case "notifier_enabled": case "notifier_enabled":
case Action.UploadStarted: case Action.UploadStarted:
case Action.UploadFinished: case Action.UploadFinished:
@ -1552,12 +1572,16 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
} else { } else {
Promise.resolve().then(() => { Promise.resolve().then(() => {
const signUrl = this.props.threepidInvite?.signUrl; const signUrl = this.props.threepidInvite?.signUrl;
const roomId = this.getRoomId();
if (isNotUndefined(roomId)) {
dis.dispatch<JoinRoomPayload>({ dis.dispatch<JoinRoomPayload>({
action: Action.JoinRoom, action: Action.JoinRoom,
roomId: this.getRoomId(), roomId,
opts: { inviteSignUrl: signUrl }, opts: { inviteSignUrl: signUrl },
metricsTrigger: this.state.room?.getMyMembership() === "invite" ? "Invite" : "RoomPreview", metricsTrigger: this.state.room?.getMyMembership() === "invite" ? "Invite" : "RoomPreview",
}); });
}
return Promise.resolve(); return Promise.resolve();
}); });
} }
@ -1920,7 +1944,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
} }
private get permalinkCreator(): RoomPermalinkCreator { private get permalinkCreator(): RoomPermalinkCreator {
return this.getPermalinkCreatorForRoom(this.state.room); return this.getPermalinkCreatorForRoom();
} }
private renderLocalRoomCreateLoader(localRoom: LocalRoom): ReactNode { private renderLocalRoomCreateLoader(localRoom: LocalRoom): ReactNode {