From d0c266d4a1a418177674fafb3755317f0a80a6ec Mon Sep 17 00:00:00 2001 From: maheichyk Date: Thu, 23 Feb 2023 13:29:21 +0300 Subject: [PATCH] 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 --- src/components/structures/RoomView.tsx | 6 +++++- src/components/views/rooms/RoomPreviewBar.tsx | 16 +++++++++------- .../views/rooms/RoomPreviewBar-test.tsx | 1 + 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/components/structures/RoomView.tsx b/src/components/structures/RoomView.tsx index ae792e0fff..c2fb700f36 100644 --- a/src/components/structures/RoomView.tsx +++ b/src/components/structures/RoomView.tsx @@ -1957,6 +1957,7 @@ export class RoomView extends React.Component { loading={loading} joining={this.state.joining} oobData={this.props.oobData} + roomId={this.state.roomId} /> @@ -1986,7 +1987,7 @@ export class RoomView extends React.Component { invitedEmail={invitedEmail} oobData={this.props.oobData} signUrl={this.props.threepidInvite?.signUrl} - room={this.state.room} + roomId={this.state.roomId} /> @@ -2023,6 +2024,7 @@ export class RoomView extends React.Component { error={this.state.roomLoadError} joining={this.state.joining} rejecting={this.state.rejecting} + roomId={this.state.roomId} /> ); @@ -2052,6 +2054,7 @@ export class RoomView extends React.Component { canPreview={false} joining={this.state.joining} room={this.state.room} + roomId={this.state.roomId} /> @@ -2144,6 +2147,7 @@ export class RoomView extends React.Component { oobData={this.props.oobData} canPreview={this.state.canPeek} room={this.state.room} + roomId={this.state.roomId} /> ); if (!this.state.canPeek && !this.state.room?.isSpaceRoom()) { diff --git a/src/components/views/rooms/RoomPreviewBar.tsx b/src/components/views/rooms/RoomPreviewBar.tsx index 87631318e4..b209e26024 100644 --- a/src/components/views/rooms/RoomPreviewBar.tsx +++ b/src/components/views/rooms/RoomPreviewBar.tsx @@ -76,6 +76,12 @@ interface IProps { canPreview?: boolean; previewLoading?: boolean; + + // The id of the room to be previewed, if it is known. + // (It may be unknown if we are waiting for an alias to be resolved.) + roomId?: string; + + // A `Room` object for the room to be previewed, if we have one. room?: Room; loading?: boolean; @@ -310,18 +316,14 @@ export default class RoomPreviewBar extends React.Component { } case MessageCase.NotLoggedIn: { const opts: RoomPreviewOpts = { canJoin: false }; - if (this.props.room?.roomId) { - ModuleRunner.instance.invoke( - RoomViewLifecycle.PreviewRoomNotLoggedIn, - opts, - this.props.room.roomId, - ); + if (this.props.roomId) { + ModuleRunner.instance.invoke(RoomViewLifecycle.PreviewRoomNotLoggedIn, opts, this.props.roomId); } if (opts.canJoin) { title = _t("Join the room to participate"); primaryActionLabel = _t("Join"); primaryActionHandler = () => { - ModuleRunner.instance.invoke(RoomViewLifecycle.JoinFromRoomPreview, this.props.room.roomId); + ModuleRunner.instance.invoke(RoomViewLifecycle.JoinFromRoomPreview, this.props.roomId); }; } else { title = _t("Join the conversation with an account"); diff --git a/test/components/views/rooms/RoomPreviewBar-test.tsx b/test/components/views/rooms/RoomPreviewBar-test.tsx index 18484f8feb..b6566132ac 100644 --- a/test/components/views/rooms/RoomPreviewBar-test.tsx +++ b/test/components/views/rooms/RoomPreviewBar-test.tsx @@ -73,6 +73,7 @@ describe("", () => { const getComponent = (props: ComponentProps = {}) => { const defaultProps = { + roomId, room: createRoom(roomId, userId), }; return render();