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 <mikhail.aheichyk@nordeck.net>
This commit is contained in:
maheichyk 2023-02-23 13:29:21 +03:00 committed by GitHub
parent 880428ab94
commit d0c266d4a1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 8 deletions

View file

@ -1957,6 +1957,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
loading={loading} loading={loading}
joining={this.state.joining} joining={this.state.joining}
oobData={this.props.oobData} oobData={this.props.oobData}
roomId={this.state.roomId}
/> />
</ErrorBoundary> </ErrorBoundary>
</div> </div>
@ -1986,7 +1987,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
invitedEmail={invitedEmail} invitedEmail={invitedEmail}
oobData={this.props.oobData} oobData={this.props.oobData}
signUrl={this.props.threepidInvite?.signUrl} signUrl={this.props.threepidInvite?.signUrl}
room={this.state.room} roomId={this.state.roomId}
/> />
</ErrorBoundary> </ErrorBoundary>
</div> </div>
@ -2023,6 +2024,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
error={this.state.roomLoadError} error={this.state.roomLoadError}
joining={this.state.joining} joining={this.state.joining}
rejecting={this.state.rejecting} rejecting={this.state.rejecting}
roomId={this.state.roomId}
/> />
</ErrorBoundary> </ErrorBoundary>
); );
@ -2052,6 +2054,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
canPreview={false} canPreview={false}
joining={this.state.joining} joining={this.state.joining}
room={this.state.room} room={this.state.room}
roomId={this.state.roomId}
/> />
</ErrorBoundary> </ErrorBoundary>
</div> </div>
@ -2144,6 +2147,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
oobData={this.props.oobData} oobData={this.props.oobData}
canPreview={this.state.canPeek} canPreview={this.state.canPeek}
room={this.state.room} room={this.state.room}
roomId={this.state.roomId}
/> />
); );
if (!this.state.canPeek && !this.state.room?.isSpaceRoom()) { if (!this.state.canPeek && !this.state.room?.isSpaceRoom()) {

View file

@ -76,6 +76,12 @@ interface IProps {
canPreview?: boolean; canPreview?: boolean;
previewLoading?: 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; room?: Room;
loading?: boolean; loading?: boolean;
@ -310,18 +316,14 @@ export default class RoomPreviewBar extends React.Component<IProps, IState> {
} }
case MessageCase.NotLoggedIn: { case MessageCase.NotLoggedIn: {
const opts: RoomPreviewOpts = { canJoin: false }; const opts: RoomPreviewOpts = { canJoin: false };
if (this.props.room?.roomId) { if (this.props.roomId) {
ModuleRunner.instance.invoke( ModuleRunner.instance.invoke(RoomViewLifecycle.PreviewRoomNotLoggedIn, opts, this.props.roomId);
RoomViewLifecycle.PreviewRoomNotLoggedIn,
opts,
this.props.room.roomId,
);
} }
if (opts.canJoin) { if (opts.canJoin) {
title = _t("Join the room to participate"); title = _t("Join the room to participate");
primaryActionLabel = _t("Join"); primaryActionLabel = _t("Join");
primaryActionHandler = () => { primaryActionHandler = () => {
ModuleRunner.instance.invoke(RoomViewLifecycle.JoinFromRoomPreview, this.props.room.roomId); ModuleRunner.instance.invoke(RoomViewLifecycle.JoinFromRoomPreview, this.props.roomId);
}; };
} else { } else {
title = _t("Join the conversation with an account"); title = _t("Join the conversation with an account");

View file

@ -73,6 +73,7 @@ describe("<RoomPreviewBar />", () => {
const getComponent = (props: ComponentProps<typeof RoomPreviewBar> = {}) => { const getComponent = (props: ComponentProps<typeof RoomPreviewBar> = {}) => {
const defaultProps = { const defaultProps = {
roomId,
room: createRoom(roomId, userId), room: createRoom(roomId, userId),
}; };
return render(<RoomPreviewBar {...defaultProps} {...props} />); return render(<RoomPreviewBar {...defaultProps} {...props} />);