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

Commit

Permalink
Merge pull request #6884 from matrix-org/t3chguy/fix/19010
Browse files Browse the repository at this point in the history
  • Loading branch information
t3chguy authored Oct 14, 2021
2 parents 4118d13 + 020eca6 commit 4d8346f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 9 deletions.
11 changes: 9 additions & 2 deletions src/components/structures/MatrixChat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ import { PosthogAnalytics } from '../../PosthogAnalytics';
import { initSentry } from "../../sentry";

import { logger } from "matrix-js-sdk/src/logger";
import { showSpaceInvite } from "../../utils/space";

/** constants for MatrixChat.state.view */
export enum Views {
Expand Down Expand Up @@ -741,9 +742,15 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
case 'view_create_chat':
showStartChatInviteDialog(payload.initialText || "");
break;
case 'view_invite':
showRoomInviteDialog(payload.roomId);
case 'view_invite': {
const room = MatrixClientPeg.get().getRoom(payload.roomId);
if (room?.isSpaceRoom()) {
showSpaceInvite(room);
} else {
showRoomInviteDialog(payload.roomId);
}
break;
}
case 'view_last_screen':
// This function does what we want, despite the name. The idea is that it shows
// the last room we were looking at or some reasonable default/guess. We don't
Expand Down
9 changes: 6 additions & 3 deletions src/components/structures/SpaceRoomView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import {
showAddExistingRooms,
showCreateNewRoom,
showCreateNewSubspace,
showSpaceInvite,
showSpaceSettings,
} from "../../utils/space";
import SpaceHierarchy, { showRoom } from "./SpaceHierarchy";
Expand Down Expand Up @@ -407,19 +408,21 @@ const SpaceLandingAddButton = ({ space }) => {
</>;
};

const SpaceLanding = ({ space }) => {
const SpaceLanding = ({ space }: { space: Room }) => {
const cli = useContext(MatrixClientContext);
const myMembership = useMyRoomMembership(space);
const userId = cli.getUserId();

let inviteButton;
if (myMembership === "join" && space.canInvite(userId) && shouldShowComponent(UIComponent.InviteUsers)) {
if (((myMembership === "join" && space.canInvite(userId)) || space.getJoinRule() === JoinRule.Public) &&
shouldShowComponent(UIComponent.InviteUsers)
) {
inviteButton = (
<AccessibleButton
kind="primary"
className="mx_SpaceRoomView_landing_inviteButton"
onClick={() => {
showRoomInviteDialog(space.roomId);
showSpaceInvite(space);
}}
>
{ _t("Invite") }
Expand Down
7 changes: 6 additions & 1 deletion src/components/views/rooms/MemberList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import { throttle } from 'lodash';
import SpaceStore from "../../../stores/SpaceStore";
import { shouldShowComponent } from "../../../customisations/helpers/UIComponents";
import { UIComponent } from "../../../settings/UIFeature";
import { JoinRule } from "matrix-js-sdk/src/@types/partials";

const getSearchQueryLSKey = (roomId: string) => `mx_MemberList_searchQuarry_${roomId}`;

Expand Down Expand Up @@ -171,7 +172,11 @@ export default class MemberList extends React.Component<IProps, IState> {
private get canInvite(): boolean {
const cli = MatrixClientPeg.get();
const room = cli.getRoom(this.props.roomId);
return room && room.canInvite(cli.getUserId());

return (
room?.canInvite(cli.getUserId()) ||
(room?.isSpaceRoom() && room.getJoinRule() === JoinRule.Public)
);
}

private getMembersState(members: Array<RoomMember>): IState {
Expand Down
11 changes: 8 additions & 3 deletions src/components/views/rooms/RoomList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import RoomAvatar from "../avatars/RoomAvatar";
import AccessibleTooltipButton from "../elements/AccessibleTooltipButton";
import { shouldShowComponent } from "../../../customisations/helpers/UIComponents";
import { UIComponent } from "../../../settings/UIFeature";
import { JoinRule } from "matrix-js-sdk/src/@types/partials";

interface IProps {
onKeyDown: (ev: React.KeyboardEvent) => void;
Expand Down Expand Up @@ -529,19 +530,23 @@ export default class RoomList extends React.PureComponent<IProps, IState> {
</AccessibleButton>
</div>;
} else if (
this.props.activeSpace?.canInvite(userId) || this.props.activeSpace?.getMyMembership() === "join"
this.props.activeSpace?.canInvite(userId) ||
this.props.activeSpace?.getMyMembership() === "join" ||
this.props.activeSpace?.getJoinRule() === JoinRule.Public
) {
const spaceName = this.props.activeSpace.name;
const canInvite = this.props.activeSpace?.canInvite(userId) ||
this.props.activeSpace?.getJoinRule() === JoinRule.Public;
explorePrompt = <div className="mx_RoomList_explorePrompt">
<div>{ _t("Quick actions") }</div>
{ this.props.activeSpace.canInvite(userId) && <AccessibleTooltipButton
{ canInvite && <AccessibleTooltipButton
className="mx_RoomList_explorePrompt_spaceInvite"
onClick={this.onSpaceInviteClick}
title={_t("Invite to %(spaceName)s", { spaceName })}
>
{ _t("Invite people") }
</AccessibleTooltipButton> }
{ this.props.activeSpace.getMyMembership() === "join" && <AccessibleTooltipButton
{ this.props.activeSpace?.getMyMembership() === "join" && <AccessibleTooltipButton
className="mx_RoomList_explorePrompt_spaceExplore"
onClick={this.onExplore}
title={_t("Explore %(spaceName)s", { spaceName })}
Expand Down

0 comments on commit 4d8346f

Please sign in to comment.