Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 3fb4dac

Browse files
authored
Strictify RoomView.tsx (#11163)
1 parent 9fa58e4 commit 3fb4dac

File tree

1 file changed

+39
-15
lines changed

1 file changed

+39
-15
lines changed

src/components/structures/RoomView.tsx

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ import { WidgetType } from "../../widgets/WidgetType";
117117
import WidgetUtils from "../../utils/WidgetUtils";
118118
import { shouldEncryptRoomWithSingle3rdPartyInvite } from "../../utils/room/shouldEncryptRoomWithSingle3rdPartyInvite";
119119
import { WaitingForThirdPartyRoomView } from "./WaitingForThirdPartyRoomView";
120+
import { isNotUndefined } from "../../Typeguards";
120121

121122
const DEBUG = false;
122123
const PREVENT_MULTIPLE_JITSI_WITHIN = 30_000;
@@ -809,7 +810,21 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
809810
return this.state.room?.roomId ?? this.state.roomId;
810811
};
811812

812-
private getPermalinkCreatorForRoom(room: Room): RoomPermalinkCreator {
813+
private getPermalinkCreatorForRoom(): RoomPermalinkCreator {
814+
const { room, roomId } = this.state;
815+
816+
// If room is undefined, attempt to use the roomId to create and store a permalinkCreator.
817+
// Throw an error if we can not find a roomId in state.
818+
if (room === undefined) {
819+
if (isNotUndefined(roomId)) {
820+
const permalinkCreator = new RoomPermalinkCreator(null, roomId);
821+
this.permalinkCreators[roomId] = permalinkCreator;
822+
return permalinkCreator;
823+
} else {
824+
throw new Error("Cannot get a permalink creator without a roomId");
825+
}
826+
}
827+
813828
if (this.permalinkCreators[room.roomId]) return this.permalinkCreators[room.roomId];
814829

815830
this.permalinkCreators[room.roomId] = new RoomPermalinkCreator(room);
@@ -1096,14 +1111,19 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
10961111
payload.data.threadId,
10971112
);
10981113
break;
1099-
case "picture_snapshot":
1100-
ContentMessages.sharedInstance().sendContentListToRoom(
1101-
[payload.file],
1102-
this.getRoomId(),
1103-
undefined,
1104-
this.context.client,
1105-
);
1114+
case "picture_snapshot": {
1115+
const roomId = this.getRoomId();
1116+
if (isNotUndefined(roomId)) {
1117+
ContentMessages.sharedInstance().sendContentListToRoom(
1118+
[payload.file],
1119+
roomId,
1120+
undefined,
1121+
this.context.client,
1122+
);
1123+
}
1124+
11061125
break;
1126+
}
11071127
case "notifier_enabled":
11081128
case Action.UploadStarted:
11091129
case Action.UploadFinished:
@@ -1552,12 +1572,16 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
15521572
} else {
15531573
Promise.resolve().then(() => {
15541574
const signUrl = this.props.threepidInvite?.signUrl;
1555-
dis.dispatch<JoinRoomPayload>({
1556-
action: Action.JoinRoom,
1557-
roomId: this.getRoomId(),
1558-
opts: { inviteSignUrl: signUrl },
1559-
metricsTrigger: this.state.room?.getMyMembership() === "invite" ? "Invite" : "RoomPreview",
1560-
});
1575+
const roomId = this.getRoomId();
1576+
if (isNotUndefined(roomId)) {
1577+
dis.dispatch<JoinRoomPayload>({
1578+
action: Action.JoinRoom,
1579+
roomId,
1580+
opts: { inviteSignUrl: signUrl },
1581+
metricsTrigger: this.state.room?.getMyMembership() === "invite" ? "Invite" : "RoomPreview",
1582+
});
1583+
}
1584+
15611585
return Promise.resolve();
15621586
});
15631587
}
@@ -1920,7 +1944,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
19201944
}
19211945

19221946
private get permalinkCreator(): RoomPermalinkCreator {
1923-
return this.getPermalinkCreatorForRoom(this.state.room);
1947+
return this.getPermalinkCreatorForRoom();
19241948
}
19251949

19261950
private renderLocalRoomCreateLoader(localRoom: LocalRoom): ReactNode {

0 commit comments

Comments
 (0)