forked from mystiq/hydrogen-web
Add initial_state and room type to room creation options
This commit is contained in:
parent
190a405e33
commit
340c3aa068
5 changed files with 34 additions and 22 deletions
|
@ -16,7 +16,7 @@ limitations under the License.
|
|||
|
||||
import {ViewModel} from "../ViewModel";
|
||||
import {imageToInfo} from "./common.js";
|
||||
import {RoomType} from "../../matrix/room/common";
|
||||
import {RoomVisibility} from "../../matrix/room/common";
|
||||
|
||||
export class CreateRoomViewModel extends ViewModel {
|
||||
constructor(options) {
|
||||
|
@ -89,7 +89,7 @@ export class CreateRoomViewModel extends ViewModel {
|
|||
}
|
||||
}
|
||||
const roomBeingCreated = this._session.createRoom({
|
||||
type: this.isPublic ? RoomType.Public : RoomType.Private,
|
||||
type: this.isPublic ? RoomVisibility.Public : RoomVisibility.Private,
|
||||
name: this._name ?? undefined,
|
||||
topic: this._topic ?? undefined,
|
||||
isEncrypted: !this.isPublic && this._isEncrypted,
|
||||
|
|
|
@ -15,7 +15,7 @@ limitations under the License.
|
|||
*/
|
||||
|
||||
import {ViewModel} from "../../ViewModel";
|
||||
import {RoomType} from "../../../matrix/room/common";
|
||||
import {RoomVisibility} from "../../../matrix/room/common";
|
||||
import {avatarInitials, getIdentifierColorNumber, getAvatarHttpUrl} from "../../avatar";
|
||||
|
||||
export class MemberDetailsViewModel extends ViewModel {
|
||||
|
@ -87,7 +87,7 @@ export class MemberDetailsViewModel extends ViewModel {
|
|||
let roomId = room?.id;
|
||||
if (!roomId) {
|
||||
const roomBeingCreated = await this._session.createRoom({
|
||||
type: RoomType.DirectMessage,
|
||||
type: RoomVisibility.DirectMessage,
|
||||
invites: [this.userId]
|
||||
});
|
||||
roomId = roomBeingCreated.id;
|
||||
|
|
|
@ -80,7 +80,7 @@ export {TemplateView} from "./platform/web/ui/general/TemplateView";
|
|||
export {ViewModel} from "./domain/ViewModel";
|
||||
export {LoadingView} from "./platform/web/ui/general/LoadingView.js";
|
||||
export {AvatarView} from "./platform/web/ui/AvatarView.js";
|
||||
export {RoomType} from "./matrix/room/common";
|
||||
export {RoomVisibility} from "./matrix/room/common";
|
||||
export {EventEmitter} from "./utils/EventEmitter";
|
||||
export {Disposables} from "./utils/Disposables";
|
||||
export {LocalMedia} from "./matrix/calls/LocalMedia";
|
||||
|
|
|
@ -20,7 +20,7 @@ import {MediaRepository} from "../net/MediaRepository";
|
|||
import {EventEmitter} from "../../utils/EventEmitter";
|
||||
import {AttachmentUpload} from "./AttachmentUpload";
|
||||
import {loadProfiles, Profile, UserIdProfile} from "../profile";
|
||||
import {RoomType} from "./common";
|
||||
import {RoomType, RoomVisibility} from "./common";
|
||||
|
||||
import type {HomeServerApi} from "../net/HomeServerApi";
|
||||
import type {ILogItem} from "../../logging/types";
|
||||
|
@ -36,7 +36,7 @@ type CreateRoomPayload = {
|
|||
topic?: string;
|
||||
invite?: string[];
|
||||
room_alias_name?: string;
|
||||
creation_content?: {"m.federate": boolean};
|
||||
creation_content?: {"m.federate": boolean, type?: string};
|
||||
initial_state: {type: string; state_key: string; content: Record<string, any>}[]
|
||||
power_level_content_override?: any;
|
||||
}
|
||||
|
@ -55,7 +55,8 @@ type Avatar = {
|
|||
}
|
||||
|
||||
type Options = {
|
||||
type: RoomType;
|
||||
type?: RoomType;
|
||||
visibility: RoomVisibility;
|
||||
isEncrypted?: boolean;
|
||||
isFederationDisabled?: boolean;
|
||||
name?: string;
|
||||
|
@ -64,25 +65,26 @@ type Options = {
|
|||
avatar?: Avatar;
|
||||
alias?: string;
|
||||
powerLevelContentOverride?: any;
|
||||
initialState?: any[];
|
||||
}
|
||||
|
||||
function defaultE2EEStatusForType(type: RoomType): boolean {
|
||||
function defaultE2EEStatusForType(type: RoomVisibility): boolean {
|
||||
switch (type) {
|
||||
case RoomType.DirectMessage:
|
||||
case RoomType.Private:
|
||||
case RoomVisibility.DirectMessage:
|
||||
case RoomVisibility.Private:
|
||||
return true;
|
||||
case RoomType.Public:
|
||||
case RoomVisibility.Public:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function presetForType(type: RoomType): string {
|
||||
function presetForType(type: RoomVisibility): string {
|
||||
switch (type) {
|
||||
case RoomType.DirectMessage:
|
||||
case RoomVisibility.DirectMessage:
|
||||
return "trusted_private_chat";
|
||||
case RoomType.Private:
|
||||
case RoomVisibility.Private:
|
||||
return "private_chat";
|
||||
case RoomType.Public:
|
||||
case RoomVisibility.Public:
|
||||
return "public_chat";
|
||||
}
|
||||
}
|
||||
|
@ -105,7 +107,7 @@ export class RoomBeingCreated extends EventEmitter<{change: never}> {
|
|||
log: ILogItem
|
||||
) {
|
||||
super();
|
||||
this.isEncrypted = options.isEncrypted === undefined ? defaultE2EEStatusForType(options.type) : options.isEncrypted;
|
||||
this.isEncrypted = options.isEncrypted === undefined ? defaultE2EEStatusForType(options.visibility) : options.isEncrypted;
|
||||
if (options.name) {
|
||||
this._calculatedName = options.name;
|
||||
} else {
|
||||
|
@ -132,8 +134,8 @@ export class RoomBeingCreated extends EventEmitter<{change: never}> {
|
|||
attachment.applyToContent("url", avatarEventContent);
|
||||
}
|
||||
const createOptions: CreateRoomPayload = {
|
||||
is_direct: this.options.type === RoomType.DirectMessage,
|
||||
preset: presetForType(this.options.type),
|
||||
is_direct: this.options.visibility === RoomVisibility.DirectMessage,
|
||||
preset: presetForType(this.options.visibility),
|
||||
initial_state: []
|
||||
};
|
||||
if (this.options.name) {
|
||||
|
@ -150,6 +152,7 @@ export class RoomBeingCreated extends EventEmitter<{change: never}> {
|
|||
}
|
||||
if (this.options.isFederationDisabled === true) {
|
||||
createOptions.creation_content = {
|
||||
type: this.options.type === RoomType.World ? "org.matrix.msc3815.world" : undefined,
|
||||
"m.federate": false
|
||||
};
|
||||
}
|
||||
|
@ -166,6 +169,11 @@ export class RoomBeingCreated extends EventEmitter<{change: never}> {
|
|||
if (this.options.powerLevelContentOverride) {
|
||||
createOptions.power_level_content_override = this.options.powerLevelContentOverride;
|
||||
}
|
||||
|
||||
if (this.options.initialState) {
|
||||
createOptions.initial_state.push(...this.options.initialState);
|
||||
}
|
||||
|
||||
const response = await hsApi.createRoom(createOptions, {log}).response();
|
||||
this._roomId = response["room_id"];
|
||||
} catch (err) {
|
||||
|
@ -226,7 +234,7 @@ export class RoomBeingCreated extends EventEmitter<{change: never}> {
|
|||
}
|
||||
|
||||
async adjustDirectMessageMapIfNeeded(user: User, storage: Storage, hsApi: HomeServerApi, log: ILogItem): Promise<void> {
|
||||
if (!this.options.invites || this.options.type !== RoomType.DirectMessage) {
|
||||
if (!this.options.invites || this.options.visibility !== RoomVisibility.DirectMessage) {
|
||||
return;
|
||||
}
|
||||
const userId = this.options.invites[0];
|
||||
|
|
|
@ -41,10 +41,14 @@ export enum RoomStatus {
|
|||
Archived = 1 << 5,
|
||||
}
|
||||
|
||||
export enum RoomType {
|
||||
export enum RoomVisibility {
|
||||
DirectMessage,
|
||||
Private,
|
||||
Public
|
||||
Public,
|
||||
}
|
||||
|
||||
export enum RoomType {
|
||||
World
|
||||
}
|
||||
|
||||
type RoomResponse = {
|
||||
|
|
Loading…
Reference in a new issue