-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Update for compatibility with v12 rooms #30452
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
3eca1de
ddbf88a
c42ba2a
dd0b7a9
56b34de
c63e619
f646164
bc2cb7a
76abd06
6ea1786
823034c
853550c
0ccbac2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -131,3 +131,16 @@ export async function waitForMember( | |
| client.removeListener(RoomStateEvent.NewMember, handler); | ||
| }); | ||
| } | ||
|
|
||
| export function isOnlyAdmin(room: Room, client: MatrixClient): boolean { | ||
| const currentUserLevel = room.getMember(client.getUserId()!)?.powerLevel; | ||
|
||
|
|
||
| const userLevelValues = room.getMembers().map((m) => m.powerLevel); | ||
|
||
|
|
||
| const maxUserLevel = Math.max(...userLevelValues.filter((x) => typeof x === "number")); | ||
| // If the user is the only user with highest power level | ||
| return ( | ||
| maxUserLevel === currentUserLevel && | ||
| userLevelValues.lastIndexOf(maxUserLevel) == userLevelValues.indexOf(maxUserLevel) | ||
| ); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| /* | ||
| 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 React from "react"; | ||
| import { render, screen } from "jest-matrix-react"; | ||
| import { MatrixEvent, type RoomMember } from "matrix-js-sdk/src/matrix"; | ||
|
|
||
| import LeaveSpaceDialog from "../../../../../src/components/views/dialogs/LeaveSpaceDialog"; | ||
| import { createTestClient, mkStubRoom } from "../../../../test-utils"; | ||
|
|
||
| describe("LeaveSpaceDialog", () => { | ||
| it("should warn about not being able to rejoin non-public space", () => { | ||
| const mockClient = createTestClient(); | ||
| const mockSpace = mkStubRoom("myfakeroom", "myfakeroom", mockClient) as any; | ||
| jest.spyOn(mockSpace.currentState, "getStateEvents").mockReturnValue( | ||
| new MatrixEvent({ | ||
| type: "m.room.join_rules", | ||
| content: { | ||
| join_rule: "invite", | ||
| }, | ||
| }), | ||
| ); | ||
|
|
||
| render(<LeaveSpaceDialog space={mockSpace} onFinished={jest.fn()} />); | ||
|
|
||
| expect(screen.getByText(/You won't be able to rejoin unless you are re-invited/)).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it("should warn if user is the only admin", () => { | ||
| const mockClient = createTestClient(); | ||
| const mockSpace = mkStubRoom("myfakeroom", "myfakeroom", mockClient) as any; | ||
| jest.spyOn(mockSpace, "getMembers").mockReturnValue([ | ||
| { powerLevel: 100 } as unknown as RoomMember, | ||
| { powerLevel: 0 } as unknown as RoomMember, | ||
| ]); | ||
| jest.spyOn(mockSpace, "getMember").mockReturnValue({ | ||
| powerLevel: 100, | ||
| } as unknown as RoomMember); | ||
|
|
||
| render(<LeaveSpaceDialog space={mockSpace} onFinished={jest.fn()} />); | ||
|
|
||
| expect( | ||
| screen.getByText(/You're the only admin of this space. Leaving it will mean no one has control over it./), | ||
| ).toBeInTheDocument(); | ||
| }); | ||
| }); |
Uh oh!
There was an error while loading. Please reload this page.