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

Commit d0c266d

Browse files
authored
Support joining non-peekable rooms via the module API (#10154)
When previewing a room, we normally do not have a Room object. Currently, when the RoomPreviewBar is instantiated without a room, it doesn't raise the PreviewRoomNotLoggedIn and JoinFromRoomPreview module lifecycle events, meaning that modules are unable to intercept previews of non-peekable rooms. To fix this, make sure that we pass the room ID into RoomPreviewBar irrespective of whether we have a Room object, and use it to raise the module lifecycle events. Signed-off-by: Mikhail Aheichyk <[email protected]>
1 parent 880428a commit d0c266d

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

src/components/structures/RoomView.tsx

+5-1
Original file line numberDiff line numberDiff line change
@@ -1957,6 +1957,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
19571957
loading={loading}
19581958
joining={this.state.joining}
19591959
oobData={this.props.oobData}
1960+
roomId={this.state.roomId}
19601961
/>
19611962
</ErrorBoundary>
19621963
</div>
@@ -1986,7 +1987,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
19861987
invitedEmail={invitedEmail}
19871988
oobData={this.props.oobData}
19881989
signUrl={this.props.threepidInvite?.signUrl}
1989-
room={this.state.room}
1990+
roomId={this.state.roomId}
19901991
/>
19911992
</ErrorBoundary>
19921993
</div>
@@ -2023,6 +2024,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
20232024
error={this.state.roomLoadError}
20242025
joining={this.state.joining}
20252026
rejecting={this.state.rejecting}
2027+
roomId={this.state.roomId}
20262028
/>
20272029
</ErrorBoundary>
20282030
);
@@ -2052,6 +2054,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
20522054
canPreview={false}
20532055
joining={this.state.joining}
20542056
room={this.state.room}
2057+
roomId={this.state.roomId}
20552058
/>
20562059
</ErrorBoundary>
20572060
</div>
@@ -2144,6 +2147,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
21442147
oobData={this.props.oobData}
21452148
canPreview={this.state.canPeek}
21462149
room={this.state.room}
2150+
roomId={this.state.roomId}
21472151
/>
21482152
);
21492153
if (!this.state.canPeek && !this.state.room?.isSpaceRoom()) {

src/components/views/rooms/RoomPreviewBar.tsx

+9-7
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ interface IProps {
7676

7777
canPreview?: boolean;
7878
previewLoading?: boolean;
79+
80+
// The id of the room to be previewed, if it is known.
81+
// (It may be unknown if we are waiting for an alias to be resolved.)
82+
roomId?: string;
83+
84+
// A `Room` object for the room to be previewed, if we have one.
7985
room?: Room;
8086

8187
loading?: boolean;
@@ -310,18 +316,14 @@ export default class RoomPreviewBar extends React.Component<IProps, IState> {
310316
}
311317
case MessageCase.NotLoggedIn: {
312318
const opts: RoomPreviewOpts = { canJoin: false };
313-
if (this.props.room?.roomId) {
314-
ModuleRunner.instance.invoke(
315-
RoomViewLifecycle.PreviewRoomNotLoggedIn,
316-
opts,
317-
this.props.room.roomId,
318-
);
319+
if (this.props.roomId) {
320+
ModuleRunner.instance.invoke(RoomViewLifecycle.PreviewRoomNotLoggedIn, opts, this.props.roomId);
319321
}
320322
if (opts.canJoin) {
321323
title = _t("Join the room to participate");
322324
primaryActionLabel = _t("Join");
323325
primaryActionHandler = () => {
324-
ModuleRunner.instance.invoke(RoomViewLifecycle.JoinFromRoomPreview, this.props.room.roomId);
326+
ModuleRunner.instance.invoke(RoomViewLifecycle.JoinFromRoomPreview, this.props.roomId);
325327
};
326328
} else {
327329
title = _t("Join the conversation with an account");

test/components/views/rooms/RoomPreviewBar-test.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ describe("<RoomPreviewBar />", () => {
7373

7474
const getComponent = (props: ComponentProps<typeof RoomPreviewBar> = {}) => {
7575
const defaultProps = {
76+
roomId,
7677
room: createRoom(roomId, userId),
7778
};
7879
return render(<RoomPreviewBar {...defaultProps} {...props} />);

0 commit comments

Comments
 (0)