Skip to content

Commit

Permalink
change logic of when to show the call and share button. (matrix-org#1…
Browse files Browse the repository at this point in the history
…2385)

Allow starting calls in rooms with only one person if one can add invite others with a call link.

Signed-off-by: Timo K <[email protected]>
  • Loading branch information
toger5 authored Apr 4, 2024
1 parent 307d737 commit 015b938
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
10 changes: 7 additions & 3 deletions src/hooks/room/useRoomCall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ export const useRoomCall = (
// We only want to prompt to pin the widget if it's not element call based.
const isECWidget = WidgetType.CALL.matches(widget?.type ?? "");
const promptPinWidget = !isECWidget && canPinWidget && !widgetPinned;
const userId = room.client.getUserId();
const canInviteToRoom = userId ? room.canInvite(userId) : false;
const state = useMemo((): State => {
if (activeCalls.find((call) => call.roomId != room.roomId)) {
return State.Ongoing;
Expand All @@ -199,8 +201,9 @@ export const useRoomCall = (
if (hasLegacyCall) {
return State.Ongoing;
}

if (memberCount <= 1) {
const canCallAlone =
canInviteToRoom && (room.getJoinRule() === "public" || room.getJoinRule() === JoinRule.Knock);
if (!(memberCount > 1 || canCallAlone)) {
return State.NoOneHere;
}

Expand All @@ -210,6 +213,7 @@ export const useRoomCall = (
return State.NoCall;
}, [
activeCalls,
canInviteToRoom,
hasGroupCall,
hasJitsiWidget,
hasLegacyCall,
Expand All @@ -218,7 +222,7 @@ export const useRoomCall = (
mayEditWidgets,
memberCount,
promptPinWidget,
room.roomId,
room,
]);

const voiceCallClick = useCallback(
Expand Down
27 changes: 25 additions & 2 deletions test/components/views/rooms/RoomHeader-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
getByLabelText,
getByRole,
getByText,
queryAllByLabelText,
render,
RenderOptions,
screen,
Expand Down Expand Up @@ -83,7 +84,6 @@ describe("RoomHeader", () => {
);

let room: Room;

const ROOM_ID = "!1:example.org";

let setCardSpy: jest.SpyInstance | undefined;
Expand Down Expand Up @@ -371,14 +371,37 @@ describe("RoomHeader", () => {
}
});

it("can't call if you have no friends", () => {
it("can't call if you have no friends and cannot invite friends", () => {
mockRoomMembers(room, 1);
const { container } = render(<RoomHeader room={room} />, getWrapper());
for (const button of getAllByLabelText(container, "There's no one here to call")) {
expect(button).toHaveAttribute("aria-disabled", "true");
}
});

it("can call if you have no friends but can invite friends", () => {
mockRoomMembers(room, 1);
// go through all the different `canInvite` and `getJoinRule` combinations
jest.spyOn(room, "getJoinRule").mockReturnValue(JoinRule.Invite);
jest.spyOn(room, "canInvite").mockReturnValue(false);
const { container: containerNoInviteNotPublic } = render(<RoomHeader room={room} />, getWrapper());
expect(queryAllByLabelText(containerNoInviteNotPublic, "There's no one here to call")).toHaveLength(2);
jest.spyOn(room, "getJoinRule").mockReturnValue(JoinRule.Knock);
jest.spyOn(room, "canInvite").mockReturnValue(false);
const { container: containerNoInvitePublic } = render(<RoomHeader room={room} />, getWrapper());
expect(queryAllByLabelText(containerNoInvitePublic, "There's no one here to call")).toHaveLength(2);

jest.spyOn(room, "canInvite").mockReturnValue(true);
jest.spyOn(room, "getJoinRule").mockReturnValue(JoinRule.Invite);
const { container: containerInviteNotPublic } = render(<RoomHeader room={room} />, getWrapper());
expect(queryAllByLabelText(containerInviteNotPublic, "There's no one here to call")).toHaveLength(2);

jest.spyOn(room, "getJoinRule").mockReturnValue(JoinRule.Knock);
jest.spyOn(room, "canInvite").mockReturnValue(true);
const { container: containerInvitePublic } = render(<RoomHeader room={room} />, getWrapper());
expect(queryAllByLabelText(containerInvitePublic, "There's no one here to call")).toHaveLength(0);
});

it("calls using legacy or jitsi", async () => {
mockRoomMembers(room, 2);
jest.spyOn(room.currentState, "mayClientSendStateEvent").mockImplementation((key) => {
Expand Down

0 comments on commit 015b938

Please sign in to comment.