2025-03-14 17:22:45 +01:00
|
|
|
/*
|
|
|
|
|
* Copyright 2025 New Vector Ltd.
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
|
|
|
|
|
* Please see LICENSE files in the repository root for full details.
|
|
|
|
|
*/
|
|
|
|
|
|
2025-03-18 11:02:33 +01:00
|
|
|
import { type Room, KnownMembership, EventTimeline, EventType, type MatrixClient } from "matrix-js-sdk/src/matrix";
|
2025-03-14 17:22:45 +01:00
|
|
|
|
|
|
|
|
import { isKnockDenied } from "../../../utils/membership";
|
|
|
|
|
import { shouldShowComponent } from "../../../customisations/helpers/UIComponents";
|
|
|
|
|
import { UIComponent } from "../../../settings/UIFeature";
|
2025-03-18 11:02:33 +01:00
|
|
|
import { showCreateNewRoom } from "../../../utils/space";
|
|
|
|
|
import dispatcher from "../../../dispatcher/dispatcher";
|
|
|
|
|
import { Action } from "../../../dispatcher/actions";
|
2025-03-14 17:22:45 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check if the user has access to the options menu.
|
|
|
|
|
* @param room
|
|
|
|
|
*/
|
|
|
|
|
export function hasAccessToOptionsMenu(room: Room): boolean {
|
|
|
|
|
return (
|
|
|
|
|
room.getMyMembership() === KnownMembership.Invite ||
|
|
|
|
|
(room.getMyMembership() !== KnownMembership.Knock &&
|
|
|
|
|
!isKnockDenied(room) &&
|
|
|
|
|
shouldShowComponent(UIComponent.RoomOptionsMenu))
|
|
|
|
|
);
|
|
|
|
|
}
|
2025-03-18 11:02:33 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create a room
|
|
|
|
|
* @param space - The space to create the room in
|
|
|
|
|
*/
|
|
|
|
|
export async function createRoom(space?: Room | null): Promise<void> {
|
|
|
|
|
if (space) {
|
|
|
|
|
await showCreateNewRoom(space);
|
|
|
|
|
} else {
|
|
|
|
|
dispatcher.fire(Action.CreateRoom);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check if the user has the rights to create a room in the given space
|
|
|
|
|
* If the space is not provided, it will check if the user has the rights to create a room in general
|
|
|
|
|
* @param matrixClient
|
|
|
|
|
* @param space
|
|
|
|
|
*/
|
|
|
|
|
export function hasCreateRoomRights(matrixClient: MatrixClient, space?: Room | null): boolean {
|
|
|
|
|
const hasUIRight = shouldShowComponent(UIComponent.CreateRooms);
|
|
|
|
|
if (!space || !hasUIRight) return hasUIRight;
|
|
|
|
|
|
|
|
|
|
return Boolean(
|
|
|
|
|
space
|
|
|
|
|
?.getLiveTimeline()
|
|
|
|
|
.getState(EventTimeline.FORWARDS)
|
|
|
|
|
?.maySendStateEvent(EventType.RoomAvatar, matrixClient.getSafeUserId()),
|
|
|
|
|
);
|
|
|
|
|
}
|