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

Implement MSC3817: Add an action to create matrix rooms via the Widget API #9136

Closed
Closed
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
33 changes: 33 additions & 0 deletions src/stores/widgets/StopGapWidgetDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import {
Capability,
EventDirection,
ICreateRoom,
IOpenIDCredentials,
IOpenIDUpdate,
ISendEventDetails,
Expand All @@ -34,6 +35,7 @@ import { IContent, IEvent, MatrixEvent } from "matrix-js-sdk/src/models/event";
import { Room } from "matrix-js-sdk/src/models/room";
import { logger } from "matrix-js-sdk/src/logger";
import { THREAD_RELATION_TYPE } from "matrix-js-sdk/src/models/thread";
import { Preset, Visibility } from "matrix-js-sdk/src/matrix";

import { iterableDiff, iterableIntersection } from "../../utils/iterables";
import { MatrixClientPeg } from "../../MatrixClientPeg";
Expand Down Expand Up @@ -192,6 +194,37 @@ export class StopGapWidgetDriver extends WidgetDriver {
return targetRooms.filter(r => !!r);
}

public async createRoom(opts: ICreateRoom): Promise<{ roomId: string }> {
const client = MatrixClientPeg.get();

if (!client) throw new Error("Not attached to a client");

const visibility: Visibility | undefined = Object.values(Visibility).includes(opts.visibility as any)
? (opts.visibility as Visibility)
: undefined;

const preset: Preset | undefined = Object.values(Preset).includes(opts.preset as any)
? (opts.visibility as Preset)
: undefined;

const createdRoom = await client.createRoom({
room_alias_name: opts.room_alias_name,
visibility,
name: opts.name,
topic: opts.topic,
preset,
power_level_content_override: opts.power_level_content_override,
creation_content: opts.creation_content,
initial_state: opts.initial_state,
invite: opts.invite,
invite_3pid: opts.invite_3pid,
is_direct: opts.is_direct,
room_version: opts.room_version,
});

return { roomId: createdRoom.room_id };
}

public async readRoomEvents(
eventType: string,
msgtype: string | undefined,
Expand Down