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

[DO NOT MERGE] DMLS proof-of-concept #10669

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
21 changes: 21 additions & 0 deletions src/components/views/dialogs/CreateRoomDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ interface IState {
joinRule: JoinRule;
isPublic: boolean;
isEncrypted: boolean;
useMls: boolean;
name: string;
topic: string;
alias: string;
Expand Down Expand Up @@ -77,6 +78,7 @@ export default class CreateRoomDialog extends React.Component<IProps, IState> {
this.state = {
isPublic: this.props.defaultPublic || false,
isEncrypted: this.props.defaultEncrypted ?? privateShouldBeEncrypted(),
useMls: false,
joinRule,
name: this.props.defaultName || "",
topic: "",
Expand Down Expand Up @@ -107,6 +109,7 @@ export default class CreateRoomDialog extends React.Component<IProps, IState> {
} else {
// If we cannot change encryption we pass `true` for safety, the server should automatically do this for us.
opts.encryption = this.state.canChangeEncryption ? this.state.isEncrypted : true;
opts.useMls = this.state.useMls;
}

if (this.state.topic) {
Expand Down Expand Up @@ -188,6 +191,10 @@ export default class CreateRoomDialog extends React.Component<IProps, IState> {
this.setState({ isEncrypted });
};

private onUseMlsChange = (useMls: boolean): void => {
this.setState({ useMls });
};

private onAliasChange = (alias: string): void => {
this.setState({ alias });
};
Expand Down Expand Up @@ -311,6 +318,19 @@ export default class CreateRoomDialog extends React.Component<IProps, IState> {
</React.Fragment>
);
}
let mlsSection: JSX.Element;
if (this.state.isEncrypted) {
mlsSection = (
<React.Fragment>
<LabelledToggleSwitch
label="Use MLS"
onChange={this.onUseMlsChange}
value={this.state.useMls}
/>
<p>Experimental! Don't do it!</p>
</React.Fragment>
);
}

let federateLabel = _t(
"You might enable this if the room will only be used for collaborating with internal " +
Expand Down Expand Up @@ -374,6 +394,7 @@ export default class CreateRoomDialog extends React.Component<IProps, IState> {
<summary className="mx_CreateRoomDialog_details_summary">
{this.state.detailsOpen ? _t("Hide advanced") : _t("Show advanced")}
</summary>
{mlsSection}
<LabelledToggleSwitch
label={_t("Block anyone not part of %(serverName)s from ever joining this room.", {
serverName: MatrixClientPeg.getHomeserverName(),
Expand Down
12 changes: 11 additions & 1 deletion src/createRoom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ limitations under the License.
*/

import { MatrixClient, ClientEvent } from "matrix-js-sdk/src/client";
import { MLS_ALGORITHM } from "matrix-js-sdk/src/crypto/algorithms/dmls";
import { Room } from "matrix-js-sdk/src/models/room";
import { EventType, RoomCreateTypeField, RoomType } from "matrix-js-sdk/src/@types/event";
import { ICreateRoomOpts } from "matrix-js-sdk/src/@types/requests";
Expand Down Expand Up @@ -66,6 +67,7 @@ export interface IOpts {
// contextually only makes sense if parentSpace is specified, if true then will be added to parentSpace as suggested
suggested?: boolean;
joinRule?: JoinRule;
useMls?: boolean;
}

const DEFAULT_EVENT_POWER_LEVELS = {
Expand Down Expand Up @@ -208,7 +210,7 @@ export default async function createRoom(opts: IOpts): Promise<string | null> {
type: "m.room.encryption",
state_key: "",
content: {
algorithm: "m.megolm.v1.aes-sha2",
algorithm: opts.useMls ? MLS_ALGORITHM.name : "m.megolm.v1.aes-sha2",
},
});
}
Expand Down Expand Up @@ -315,6 +317,14 @@ export default async function createRoom(opts: IOpts): Promise<string | null> {

if (opts.dmUserId) await Rooms.setDMRoom(roomId, opts.dmUserId);
})
.then(async () => {
if (opts.encryption && opts.useMls) {
return await client.crypto.mlsProvider.createGroup(
await room,
createOpts.invite || [],
);
}
})
.then(() => {
if (opts.parentSpace) {
return SpaceStore.instance.addRoomToSpace(
Expand Down
Loading