2023-11-16 03:25:34 +00:00
|
|
|
/*
|
2024-09-09 14:57:16 +01:00
|
|
|
Copyright 2024 New Vector Ltd.
|
2023-11-16 03:25:34 +00:00
|
|
|
Copyright 2023 The Matrix.org Foundation C.I.C.
|
|
|
|
|
|
2025-01-06 11:18:54 +00:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
|
2024-09-09 14:57:16 +01:00
|
|
|
Please see LICENSE files in the repository root for full details.
|
2023-11-16 03:25:34 +00:00
|
|
|
*/
|
|
|
|
|
|
2025-02-05 13:25:06 +00:00
|
|
|
import { JoinRule, type Room } from "matrix-js-sdk/src/matrix";
|
2024-03-18 14:40:52 +00:00
|
|
|
import { KnownMembership } from "matrix-js-sdk/src/types";
|
2023-11-16 03:25:34 +00:00
|
|
|
|
|
|
|
|
import { shouldShowComponent } from "../../customisations/helpers/UIComponents";
|
|
|
|
|
import { UIComponent } from "../../settings/UIFeature";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Can a user invite new members to the room
|
|
|
|
|
* @param room
|
|
|
|
|
* @returns whether the user can invite new members to the room
|
|
|
|
|
*/
|
|
|
|
|
export function canInviteTo(room: Room): boolean {
|
|
|
|
|
const client = room.client;
|
|
|
|
|
const canInvite =
|
|
|
|
|
!!room.canInvite(client.getSafeUserId()) || !!(room.isSpaceRoom() && room.getJoinRule() === JoinRule.Public);
|
|
|
|
|
|
2024-03-12 14:52:54 +00:00
|
|
|
return canInvite && room.getMyMembership() === KnownMembership.Join && shouldShowComponent(UIComponent.InviteUsers);
|
2023-11-16 03:25:34 +00:00
|
|
|
}
|