diff --git a/src/components/structures/SpaceRoomView.tsx b/src/components/structures/SpaceRoomView.tsx index aad770888b..a91c47b067 100644 --- a/src/components/structures/SpaceRoomView.tsx +++ b/src/components/structures/SpaceRoomView.tsx @@ -14,58 +14,60 @@ See the License for the specific language governing permissions and limitations under the License. */ -import React, {RefObject, useContext, useRef, useState} from "react"; -import {EventType} from "matrix-js-sdk/src/@types/event"; -import {Room} from "matrix-js-sdk/src/models/room"; -import {EventSubscription} from "fbemitter"; +import React, { RefObject, useContext, useRef, useState } from "react"; +import { EventType } from "matrix-js-sdk/src/@types/event"; +import { Preset } from "matrix-js-sdk/src/@types/partials"; +import { Room } from "matrix-js-sdk/src/models/room"; +import { EventSubscription } from "fbemitter"; import MatrixClientContext from "../../contexts/MatrixClientContext"; import RoomAvatar from "../views/avatars/RoomAvatar"; -import {_t} from "../../languageHandler"; +import { _t } from "../../languageHandler"; import AccessibleButton from "../views/elements/AccessibleButton"; import RoomName from "../views/elements/RoomName"; import RoomTopic from "../views/elements/RoomTopic"; import InlineSpinner from "../views/elements/InlineSpinner"; -import {inviteMultipleToRoom, showRoomInviteDialog} from "../../RoomInvite"; -import {useRoomMembers} from "../../hooks/useRoomMembers"; -import createRoom, {IOpts} from "../../createRoom"; +import { inviteMultipleToRoom, showRoomInviteDialog } from "../../RoomInvite"; +import { useRoomMembers } from "../../hooks/useRoomMembers"; +import createRoom, { IOpts } from "../../createRoom"; import Field from "../views/elements/Field"; -import {useEventEmitter} from "../../hooks/useEventEmitter"; +import { useEventEmitter } from "../../hooks/useEventEmitter"; import withValidation from "../views/elements/Validation"; import * as Email from "../../email"; import defaultDispatcher from "../../dispatcher/dispatcher"; -import {Action} from "../../dispatcher/actions"; +import dis from "../../dispatcher/dispatcher"; +import { Action } from "../../dispatcher/actions"; import ResizeNotifier from "../../utils/ResizeNotifier" import MainSplit from './MainSplit'; import ErrorBoundary from "../views/elements/ErrorBoundary"; -import {ActionPayload} from "../../dispatcher/payloads"; +import { ActionPayload } from "../../dispatcher/payloads"; import RightPanel from "./RightPanel"; import RightPanelStore from "../../stores/RightPanelStore"; -import {RightPanelPhases} from "../../stores/RightPanelStorePhases"; -import {SetRightPanelPhasePayload} from "../../dispatcher/payloads/SetRightPanelPhasePayload"; -import {useStateArray} from "../../hooks/useStateArray"; +import { RightPanelPhases } from "../../stores/RightPanelStorePhases"; +import { SetRightPanelPhasePayload } from "../../dispatcher/payloads/SetRightPanelPhasePayload"; +import { useStateArray } from "../../hooks/useStateArray"; import SpacePublicShare from "../views/spaces/SpacePublicShare"; -import {showAddExistingRooms, showCreateNewRoom, shouldShowSpaceSettings, showSpaceSettings} from "../../utils/space"; -import {showRoom, SpaceHierarchy} from "./SpaceRoomDirectory"; +import { shouldShowSpaceSettings, showAddExistingRooms, showCreateNewRoom, showSpaceSettings } from "../../utils/space"; +import { showRoom, SpaceHierarchy } from "./SpaceRoomDirectory"; import MemberAvatar from "../views/avatars/MemberAvatar"; -import {useStateToggle} from "../../hooks/useStateToggle"; +import { useStateToggle } from "../../hooks/useStateToggle"; import SpaceStore from "../../stores/SpaceStore"; import FacePile from "../views/elements/FacePile"; -import {AddExistingToSpace} from "../views/dialogs/AddExistingToSpaceDialog"; -import {ChevronFace, ContextMenuButton, useContextMenu} from "./ContextMenu"; +import { AddExistingToSpace } from "../views/dialogs/AddExistingToSpaceDialog"; +import { ChevronFace, ContextMenuButton, useContextMenu } from "./ContextMenu"; import IconizedContextMenu, { IconizedContextMenuOption, IconizedContextMenuOptionList, } from "../views/context_menus/IconizedContextMenu"; import AccessibleTooltipButton from "../views/elements/AccessibleTooltipButton"; -import {BetaPill} from "../views/beta/BetaCard"; +import { BetaPill } from "../views/beta/BetaCard"; import { UserTab } from "../views/dialogs/UserSettingsDialog"; import SettingsStore from "../../settings/SettingsStore"; -import dis from "../../dispatcher/dispatcher"; import Modal from "../../Modal"; import BetaFeedbackDialog from "../views/dialogs/BetaFeedbackDialog"; import SdkConfig from "../../SdkConfig"; -import { Preset } from "matrix-js-sdk/src/@types/partials"; +import { EffectiveMembership, getEffectiveMembership } from "../../utils/membership"; +import { JoinRule } from "../views/settings/tabs/room/SecurityRoomSettingsTab"; interface IProps { space: Room; @@ -178,6 +180,9 @@ const SpacePreview = ({ space, onJoinButtonClicked, onRejectButtonClicked }) => const spacesEnabled = SettingsStore.getValue("feature_spaces"); + const cannotJoin = getEffectiveMembership(myMembership) === EffectiveMembership.Leave + && space.getJoinRule() !== JoinRule.Public; + let inviterSection; let joinButtons; if (myMembership === "join") { @@ -244,7 +249,7 @@ const SpacePreview = ({ space, onJoinButtonClicked, onRejectButtonClicked }) => setBusy(true); onJoinButtonClicked(); }} - disabled={!spacesEnabled} + disabled={!spacesEnabled || cannotJoin} > { _t("Join") } @@ -255,6 +260,30 @@ const SpacePreview = ({ space, onJoinButtonClicked, onRejectButtonClicked }) => joinButtons = ; } + let footer; + if (!spacesEnabled) { + footer =
+ { myMembership === "join" + ? _t("To view %(spaceName)s, turn on the Spaces beta", { + spaceName: space.name, + }, { + a: sub => { sub }, + }) + : _t("To join %(spaceName)s, turn on the Spaces beta", { + spaceName: space.name, + }, { + a: sub => { sub }, + }) + } +
; + } else if (cannotJoin) { + footer =
+ { _t("To view %(spaceName)s, you need an invite", { + spaceName: space.name, + }) } +
; + } + return
{ inviterSection } @@ -274,20 +303,7 @@ const SpacePreview = ({ space, onJoinButtonClicked, onRejectButtonClicked }) =>
{ joinButtons }
- { !spacesEnabled &&
- { myMembership === "join" - ? _t("To view %(spaceName)s, turn on the Spaces beta", { - spaceName: space.name, - }, { - a: sub => { sub }, - }) - : _t("To join %(spaceName)s, turn on the Spaces beta", { - spaceName: space.name, - }, { - a: sub => { sub }, - }) - } -
} + { footer }
; }; diff --git a/src/components/views/settings/tabs/room/SecurityRoomSettingsTab.tsx b/src/components/views/settings/tabs/room/SecurityRoomSettingsTab.tsx index bb7e194253..16c620ad84 100644 --- a/src/components/views/settings/tabs/room/SecurityRoomSettingsTab.tsx +++ b/src/components/views/settings/tabs/room/SecurityRoomSettingsTab.tsx @@ -33,6 +33,9 @@ export enum JoinRule { Public = "public", Knock = "knock", Invite = "invite", + /** + * @deprecated Reserved. Should not be used. + */ Private = "private", } diff --git a/src/components/views/spaces/SpaceCreateMenu.tsx b/src/components/views/spaces/SpaceCreateMenu.tsx index 2d096e1b9f..0a92bd2dbf 100644 --- a/src/components/views/spaces/SpaceCreateMenu.tsx +++ b/src/components/views/spaces/SpaceCreateMenu.tsx @@ -129,7 +129,9 @@ const SpaceCreateMenu = ({ onFinished }) => { events_default: 100, ...Visibility.Public ? { invite: 0 } : {}, }, - room_alias_name: alias ? alias.substr(1, alias.indexOf(":") - 1) : undefined, + room_alias_name: visibility === Visibility.Public && alias + ? alias.substr(1, alias.indexOf(":") - 1) + : undefined, topic, }, spinner: false, diff --git a/src/components/views/spaces/SpaceSettingsVisibilityTab.tsx b/src/components/views/spaces/SpaceSettingsVisibilityTab.tsx index 263823603b..f27b73a511 100644 --- a/src/components/views/spaces/SpaceSettingsVisibilityTab.tsx +++ b/src/components/views/spaces/SpaceSettingsVisibilityTab.tsx @@ -62,9 +62,9 @@ const SpaceSettingsVisibilityTab = ({ matrixClient: cli, space }: IProps) => { const userId = cli.getUserId(); const [visibility, setVisibility] = useLocalEcho( - () => space.getJoinRule() === JoinRule.Private ? SpaceVisibility.Private : SpaceVisibility.Unlisted, + () => space.getJoinRule() === JoinRule.Invite ? SpaceVisibility.Private : SpaceVisibility.Unlisted, visibility => cli.sendStateEvent(space.roomId, EventType.RoomJoinRules, { - join_rule: visibility === SpaceVisibility.Unlisted ? JoinRule.Public : JoinRule.Private, + join_rule: visibility === SpaceVisibility.Unlisted ? JoinRule.Public : JoinRule.Invite, }, ""), () => setError(_t("Failed to update the visibility of this space")), ); diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index b3b2eec85b..bfca730776 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -2767,6 +2767,7 @@ " invites you": " invites you", "To view %(spaceName)s, turn on the Spaces beta": "To view %(spaceName)s, turn on the Spaces beta", "To join %(spaceName)s, turn on the Spaces beta": "To join %(spaceName)s, turn on the Spaces beta", + "To view %(spaceName)s, you need an invite": "To view %(spaceName)s, you need an invite", "Welcome to ": "Welcome to ", "Random": "Random", "Support": "Support",