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

Commit

Permalink
Added Ask to join option in Room Settings
Browse files Browse the repository at this point in the history
Signed-off-by: ankur12-1610 <[email protected]>
  • Loading branch information
ankur12-1610 committed Aug 1, 2022
1 parent 927fc46 commit 9054db8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/components/views/settings/JoinRuleSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -49,13 +50,20 @@ 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
: undefined;

const disabled = !room.currentState.mayClientSendStateEvent(EventType.RoomJoinRules, cli);

const knockingEnabled = SettingsStore.getValue("feature_knocking");

const [content, setContent] = useLocalEcho<IJoinRuleEventContent>(
() => room.currentState.getStateEvents(EventType.RoomJoinRules, "")?.getContent(),
content => cli.sendStateEvent(room.roomId, EventType.RoomJoinRules, content, ""),
Expand Down Expand Up @@ -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"),
Expand Down
2 changes: 2 additions & 0 deletions src/i18n/strings/en_EN.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 5 additions & 0 deletions src/utils/PreferredRoomVersions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 9054db8

Please sign in to comment.