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 8, 2022
1 parent 5c61ef7 commit 23a0c0f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
19 changes: 19 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,17 @@ 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
: 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 +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"),
Expand All @@ -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) {
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 @@ -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",
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 23a0c0f

Please sign in to comment.