From 3cd3f6b713adfa4077c2815ec93295b334de9051 Mon Sep 17 00:00:00 2001 From: ankur12-1610 Date: Mon, 1 Aug 2022 12:33:18 +0530 Subject: [PATCH] Added `Ask to join` option in Room Settings Signed-off-by: ankur12-1610 --- .../views/settings/JoinRuleSettings.tsx | 15 +++++++++++++++ src/i18n/strings/en_EN.json | 2 ++ src/utils/PreferredRoomVersions.ts | 5 +++++ 3 files changed, 22 insertions(+) diff --git a/src/components/views/settings/JoinRuleSettings.tsx b/src/components/views/settings/JoinRuleSettings.tsx index 49295f0e83b1..ea70085280aa 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,8 @@ interface IProps { const JoinRuleSettings = ({ room, promptUpgrade, aliasWarning, onError, beforeChange, closeSettingsFn }: IProps) => { const cli = room.client; + const roomSupportsKnocking = doesRoomVersionSupport(room.getVersion(), PreferredRoomVersions.KnockingRooms); + const roomSupportsRestricted = doesRoomVersionSupport(room.getVersion(), PreferredRoomVersions.RestrictedRooms); const preferredRestrictionVersion = !roomSupportsRestricted && promptUpgrade ? PreferredRoomVersions.RestrictedRooms @@ -56,6 +59,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 +94,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 && roomSupportsKnocking, }, { value: JoinRule.Public, label: _t("Public"), @@ -98,6 +108,11 @@ const JoinRuleSettings = ({ room, promptUpgrade, aliasWarning, onError, beforeCh , }]; + if (!knockingEnabled || !roomSupportsKnocking) { + definitions.splice(1, 1); // removes the knock option if the room isn't compatible for the same + definitions[0].checked = true; //makes invite only room as default + } + if (roomSupportsRestricted || preferredRestrictionVersion || joinRule === JoinRule.Restricted) { let upgradeRequiredPill; if (preferredRestrictionVersion) { diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 1395dae60bf1..b8605842c41b 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -1328,6 +1328,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 }