From 23a0c0f3eb1eff261a8cba5c9b27314b48220a24 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 | 19 +++++++++++++++++++ src/i18n/strings/en_EN.json | 2 ++ src/utils/PreferredRoomVersions.ts | 5 +++++ 3 files changed, 26 insertions(+) diff --git a/src/components/views/settings/JoinRuleSettings.tsx b/src/components/views/settings/JoinRuleSettings.tsx index 49295f0e83b1..0b5963646346 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,15 @@ const JoinRuleSettings = ({ room, promptUpgrade, aliasWarning, onError, beforeCh , }]; + if (!knockingEnabled && !roomSupportsKnocking) { + for (let i = 0; i < definitions.length; i++) { + if (definitions[i].value === JoinRule.Knock) { + definitions.splice(i, 1); + break; + } + } + } + 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 d9030ba7a21b..2ceea07a5d48 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -1327,6 +1327,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 }