diff --git a/src/components/views/settings/JoinRuleSettings.tsx b/src/components/views/settings/JoinRuleSettings.tsx index 49295f0e83b1..cacb598888b1 100644 --- a/src/components/views/settings/JoinRuleSettings.tsx +++ b/src/components/views/settings/JoinRuleSettings.tsx @@ -24,6 +24,7 @@ import { _t } from "../../../languageHandler"; import AccessibleButton from "../elements/AccessibleButton"; import RoomAvatar from "../avatars/RoomAvatar"; import SpaceStore from "../../../stores/spaces/SpaceStore"; +import SettingsStore from "../../../settings/SettingsStore"; import { MatrixClientPeg } from "../../../MatrixClientPeg"; import Modal from "../../../Modal"; import ManageRestrictedJoinRuleDialog from "../dialogs/ManageRestrictedJoinRuleDialog"; @@ -49,6 +50,11 @@ interface IProps { const JoinRuleSettings = ({ room, promptUpgrade, aliasWarning, onError, beforeChange, closeSettingsFn }: IProps) => { const cli = room.client; + const roomSupportsKnocking = doesRoomVersionSupport(room.getVersion(), PreferredRoomVersions.KnockingRooms); + const preferredKnockingVersion = !roomSupportsKnocking && promptUpgrade + ? PreferredRoomVersions.KnockingRooms + : undefined; + const roomSupportsRestricted = doesRoomVersionSupport(room.getVersion(), PreferredRoomVersions.RestrictedRooms); const preferredRestrictionVersion = !roomSupportsRestricted && promptUpgrade ? PreferredRoomVersions.RestrictedRooms @@ -56,6 +62,8 @@ const JoinRuleSettings = ({ room, promptUpgrade, aliasWarning, onError, beforeCh const disabled = !room.currentState.mayClientSendStateEvent(EventType.RoomJoinRules, cli); + const knockingEnabled = SettingsStore.getValue("feature_knocking"); + const [content, setContent] = useLocalEcho( () => room.currentState.getStateEvents(EventType.RoomJoinRules, "")?.getContent(), content => cli.sendStateEvent(room.roomId, EventType.RoomJoinRules, content, ""), @@ -89,6 +97,11 @@ const JoinRuleSettings = ({ room, promptUpgrade, aliasWarning, onError, beforeCh label: _t("Private (invite only)"), description: _t("Only invited people can join."), checked: joinRule === JoinRule.Invite || (joinRule === JoinRule.Restricted && !restrictedAllowRoomIds?.length), + }, { + value: JoinRule.Knock, + label: _t("Ask to join"), + description: _t("Requires users to be granted access in order to join"), + checked: joinRule === JoinRule.Knock && knockingEnabled === true, }, { value: JoinRule.Public, label: _t("Public"), diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 805ed4c20864..7853bad8aca6 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -1326,6 +1326,8 @@ "Integration manager": "Integration manager", "Private (invite only)": "Private (invite only)", "Only invited people can join.": "Only invited people can join.", + "Ask to join": "Ask to join", + "Requires users to be granted access in order to join": "Requires users to be granted access in order to join", "Anyone can find and join.": "Anyone can find and join.", "Upgrade required": "Upgrade required", "& %(count)s more|other": "& %(count)s more", diff --git a/src/utils/PreferredRoomVersions.ts b/src/utils/PreferredRoomVersions.ts index 2dc269da6c2f..377c6dda1009 100644 --- a/src/utils/PreferredRoomVersions.ts +++ b/src/utils/PreferredRoomVersions.ts @@ -28,6 +28,11 @@ export class PreferredRoomVersions { */ public static readonly RestrictedRooms = "9"; + /** + * The room version to use when creating "knocking" rooms. + */ + public static readonly KnockingRooms = "9"; + private constructor() { // readonly, static, class }