Allow creating knock rooms (#11182)

Signed-off-by: Charly Nguyen <charly.nguyen@nordeck.net>
This commit is contained in:
Charly Nguyen 2023-07-10 10:01:03 +02:00 committed by GitHub
parent 01bd80fe59
commit fd749172e1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 197 additions and 3 deletions

View file

@ -34,6 +34,7 @@ import JoinRuleDropdown from "../elements/JoinRuleDropdown";
import { getKeyBindingsManager } from "../../../KeyBindingsManager";
import { KeyBindingAction } from "../../../accessibility/KeyboardShortcuts";
import { privateShouldBeEncrypted } from "../../../utils/rooms";
import SettingsStore from "../../../settings/SettingsStore";
interface IProps {
type?: RoomType;
@ -59,6 +60,7 @@ interface IState {
}
export default class CreateRoomDialog extends React.Component<IProps, IState> {
private readonly askToJoinEnabled: boolean;
private readonly supportsRestricted: boolean;
private nameField = createRef<Field>();
private aliasField = createRef<RoomAliasField>();
@ -66,6 +68,7 @@ export default class CreateRoomDialog extends React.Component<IProps, IState> {
public constructor(props: IProps) {
super(props);
this.askToJoinEnabled = SettingsStore.getValue("feature_ask_to_join");
this.supportsRestricted = !!this.props.parentSpace;
let joinRule = JoinRule.Invite;
@ -126,6 +129,10 @@ export default class CreateRoomDialog extends React.Component<IProps, IState> {
opts.joinRule = JoinRule.Restricted;
}
if (this.state.joinRule === JoinRule.Knock) {
opts.joinRule = JoinRule.Knock;
}
return opts;
}
@ -283,6 +290,14 @@ export default class CreateRoomDialog extends React.Component<IProps, IState> {
{_t("You can change this at any time from room settings.")}
</p>
);
} else if (this.state.joinRule === JoinRule.Knock) {
publicPrivateLabel = (
<p>
{_t(
"Anyone can request to join, but admins or moderators need to grant access. You can change this later.",
)}
</p>
);
}
let e2eeSection: JSX.Element | undefined;
@ -332,7 +347,7 @@ export default class CreateRoomDialog extends React.Component<IProps, IState> {
let title: string;
if (isVideoRoom) {
title = _t("Create a video room");
} else if (this.props.parentSpace) {
} else if (this.props.parentSpace || this.state.joinRule === JoinRule.Knock) {
title = _t("Create a room");
} else {
title = this.state.joinRule === JoinRule.Public ? _t("Create a public room") : _t("Create a private room");
@ -365,6 +380,7 @@ export default class CreateRoomDialog extends React.Component<IProps, IState> {
<JoinRuleDropdown
label={_t("Room visibility")}
labelInvite={_t("Private room (invite only)")}
labelKnock={this.askToJoinEnabled ? _t("Ask to join") : undefined}
labelPublic={_t("Public room")}
labelRestricted={this.supportsRestricted ? _t("Visible to space members") : undefined}
value={this.state.joinRule}