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

Support joining non-peekable rooms via the module API #10154

Merged
6 changes: 5 additions & 1 deletion src/components/structures/RoomView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1903,6 +1903,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
loading={loading}
joining={this.state.joining}
oobData={this.props.oobData}
roomId={this.state.roomId}
richvdh marked this conversation as resolved.
Show resolved Hide resolved
/>
</ErrorBoundary>
</div>
Expand Down Expand Up @@ -1932,7 +1933,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
invitedEmail={invitedEmail}
oobData={this.props.oobData}
signUrl={this.props.threepidInvite?.signUrl}
room={this.state.room}
roomId={this.state.roomId}
/>
</ErrorBoundary>
</div>
Expand Down Expand Up @@ -1969,6 +1970,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
error={this.state.roomLoadError}
joining={this.state.joining}
rejecting={this.state.rejecting}
roomId={this.state.roomId}
/>
</ErrorBoundary>
);
Expand Down Expand Up @@ -1998,6 +2000,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
canPreview={false}
joining={this.state.joining}
room={this.state.room}
roomId={this.state.roomId}
/>
</ErrorBoundary>
</div>
Expand Down Expand Up @@ -2090,6 +2093,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
oobData={this.props.oobData}
canPreview={this.state.canPeek}
room={this.state.room}
roomId={this.state.roomId}
/>
);
if (!this.state.canPeek && !this.state.room?.isSpaceRoom()) {
Expand Down
16 changes: 9 additions & 7 deletions src/components/views/rooms/RoomPreviewBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ enum MessageCase {
}

interface IProps {
// The id of the room to be previewed
maheichyk marked this conversation as resolved.
Show resolved Hide resolved
roomId?: string;

maheichyk marked this conversation as resolved.
Show resolved Hide resolved
// if inviterName is specified, the preview bar will shown an invite to the room.
// You should also specify onRejectClick if specifying inviterName
inviterName?: string;
Expand All @@ -76,6 +79,9 @@ interface IProps {

canPreview?: boolean;
previewLoading?: boolean;

// The room to be previewed
richvdh marked this conversation as resolved.
Show resolved Hide resolved
// If given, the room passed is peekable
maheichyk marked this conversation as resolved.
Show resolved Hide resolved
room?: Room;

loading?: boolean;
Expand Down Expand Up @@ -310,18 +316,14 @@ export default class RoomPreviewBar extends React.Component<IProps, IState> {
}
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);
};
richvdh marked this conversation as resolved.
Show resolved Hide resolved
} else {
title = _t("Join the conversation with an account");
Expand Down
5 changes: 3 additions & 2 deletions test/components/views/rooms/RoomPreviewBar-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@ describe("<RoomPreviewBar />", () => {
const inviterUserId = "@inviter:test.com";
const otherUserId = "@othertester:test.com";

const getComponent = (props: ComponentProps<typeof RoomPreviewBar> = {}) => {
const getComponent = (props: Omit<ComponentProps<typeof RoomPreviewBar>, "roomId"> = {}) => {
maheichyk marked this conversation as resolved.
Show resolved Hide resolved
const defaultProps = {
roomId,
room: createRoom(roomId, userId),
};
return render(<RoomPreviewBar {...defaultProps} {...props} />);
Expand Down Expand Up @@ -324,7 +325,7 @@ describe("<RoomPreviewBar />", () => {
{ medium: "not-email", address: "address 2" },
];

const testJoinButton = (props: ComponentProps<typeof RoomPreviewBar>) => async () => {
const testJoinButton = (props: Omit<ComponentProps<typeof RoomPreviewBar>, "roomId">) => async () => {
const onJoinClick = jest.fn();
const onRejectClick = jest.fn();
const component = getComponent({ ...props, onJoinClick, onRejectClick });
Expand Down