Files
element-web/src/components/viewmodels/roomlist/utils.ts
Florian Duros 817d7b78b8 New room list: add notification options menu (#29639)
* feat: add `utils.hasAccessToNotificationMenu`

* feat(room list item view model): use `hasAccessToNotificationMenu` to compute `showHoverMenu`

* feat(room list item menu view model): add notification options menu attributes

* feat(room list item menu view): add notification options

* test: add tests for `utils.hasAccessToNotificationMenu`

* test(room list item view model): add test for `showHoverMenu`

* test(room list item menu view model): add tests for new attributes

* test(room list item menu view): add tests for notification options menu

* chore: update i18n

* test(e2e): update screenshots

* test(e2e): add tests for notification options menu
2025-04-02 12:30:27 +00:00

69 lines
2.2 KiB
TypeScript

/*
* 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.
*/
import { type Room, KnownMembership, EventTimeline, EventType, type MatrixClient } from "matrix-js-sdk/src/matrix";
import { isKnockDenied } from "../../../utils/membership";
import { shouldShowComponent } from "../../../customisations/helpers/UIComponents";
import { UIComponent } from "../../../settings/UIFeature";
import { showCreateNewRoom } from "../../../utils/space";
import dispatcher from "../../../dispatcher/dispatcher";
import { Action } from "../../../dispatcher/actions";
/**
* 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))
);
}
/**
* Check if the user has access to the notification menu.
* @param room
* @param isGuest
* @param isArchived
*/
export function hasAccessToNotificationMenu(room: Room, isGuest: boolean, isArchived: boolean): boolean {
return !isGuest && !isArchived && hasAccessToOptionsMenu(room);
}
/**
* 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()),
);
}