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

Allow creating public knock rooms #11481

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions src/components/views/dialogs/CreateRoomDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,25 @@ interface IProps {
}

interface IState {
// The selected room join rule.
joinRule: JoinRule;
isPublic: boolean;
// Indicates whether the knock room is public visible. Applies only for rooms with knock join rule.
charlynguyen marked this conversation as resolved.
Show resolved Hide resolved
isPublicKnockRoom: boolean;
// Indicates whether end-to-end encryption is enabled for the room.
isEncrypted: boolean;
// The room name.
name: string;
// The room topic.
topic: string;
// The room alias.
alias: string;
// Indicates whether the details section is open.
detailsOpen: boolean;
// Indicates whether federation is disabled for the room.
noFederate: boolean;
// Indicates whether the room name is valid.
nameIsValid: boolean;
// Indicates whether the user can change encryption settings for the room.
canChangeEncryption: boolean;
charlynguyen marked this conversation as resolved.
Show resolved Hide resolved
}

Expand All @@ -79,7 +89,7 @@ export default class CreateRoomDialog extends React.Component<IProps, IState> {

const cli = MatrixClientPeg.safeGet();
this.state = {
isPublic: this.props.defaultPublic || false,
isPublicKnockRoom: this.props.defaultPublic || false,
isEncrypted: this.props.defaultEncrypted ?? privateShouldBeEncrypted(cli),
joinRule,
name: this.props.defaultName || "",
Expand Down Expand Up @@ -130,7 +140,7 @@ export default class CreateRoomDialog extends React.Component<IProps, IState> {

if (this.state.joinRule === JoinRule.Knock) {
opts.joinRule = JoinRule.Knock;
createOpts.visibility = this.state.isPublic ? Visibility.Public : Visibility.Private;
createOpts.visibility = this.state.isPublicKnockRoom ? Visibility.Public : Visibility.Private;
}

return opts;
Expand Down Expand Up @@ -217,8 +227,8 @@ export default class CreateRoomDialog extends React.Component<IProps, IState> {
return result;
};

private onIsPublicChange = (isPublic: boolean): void => {
this.setState({ isPublic });
private onIsPublicKnockRoomChange = (isPublicKnockRoom: boolean): void => {
this.setState({ isPublicKnockRoom });
};

private static validateRoomName = withValidation({
Expand Down Expand Up @@ -310,8 +320,8 @@ export default class CreateRoomDialog extends React.Component<IProps, IState> {
<LabelledCheckbox
className="mx_CreateRoomDialog_labelledCheckbox"
label={_t("Make this room visible in the public room directory.")}
onChange={this.onIsPublicChange}
value={this.state.isPublic}
onChange={this.onIsPublicKnockRoomChange}
value={this.state.isPublicKnockRoom}
/>
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/views/elements/LabelledCheckbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ interface IProps {
disabled?: boolean;
// The function to call when the value changes
onChange(checked: boolean): void;
// Optional CSS class to apply to the label
// Optional additional CSS class to apply to the label
className?: string;
}

Expand Down
9 changes: 5 additions & 4 deletions test/components/views/dialogs/CreateRoomDialog-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ describe("<CreateRoomDialog />", () => {
});

describe("for a knock room", () => {
describe("when disabling feature", () => {
describe("when feature is disabled", () => {
it("should not have the option to create a knock room", async () => {
jest.spyOn(SettingsStore, "getValue").mockReturnValue(false);
getComponent();
Expand All @@ -219,11 +219,12 @@ describe("<CreateRoomDialog />", () => {
});
});

describe("when enabling feature", () => {
describe("when feature is enabled", () => {
const onFinished = jest.fn();
charlynguyen marked this conversation as resolved.
Show resolved Hide resolved
const roomName = "Test Room Name";

beforeEach(async () => {
onFinished.mockReset();
jest.spyOn(SettingsStore, "getValue").mockImplementation(
(setting) => setting === "feature_ask_to_join",
);
Expand All @@ -245,7 +246,7 @@ describe("<CreateRoomDialog />", () => {
).toBeInTheDocument();
});

it("should create a private knock room", async () => {
it("should create a knock room with private visibility", async () => {
fireEvent.click(screen.getByText("Create room"));
await flushPromises();
expect(onFinished).toHaveBeenCalledWith(true, {
Expand All @@ -260,7 +261,7 @@ describe("<CreateRoomDialog />", () => {
});
});

it("should create a public knock room", async () => {
it("should create a knock room with public visibility", async () => {
fireEvent.click(
screen.getByRole("checkbox", { name: "Make this room visible in the public room directory." }),
);
Expand Down