Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/components/viewmodels/avatars/RoomAvatarViewModel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
type User,
UserEvent,
} from "matrix-js-sdk/src/matrix";
import { useState } from "react";
import { useEffect, useState } from "react";

import { useTypedEventEmitter } from "../../../hooks/useEventEmitter";
import DMRoomMap from "../../../utils/DMRoomMap";
Expand Down Expand Up @@ -82,6 +82,11 @@ function useIsPublic(room: Room): boolean {
setIsPublic(isRoomPublic(_room));
});

// Reset the value when the room changes
useEffect(() => {
setIsPublic(isRoomPublic(room));
}, [room]);

return isPublic;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,17 @@ describe("RoomAvatarViewModel", () => {
expect(vm.current.hasDecoration).toBe(true);
});

it("should recompute isPublic when room changed", async () => {
const { result: vm, rerender } = renderHook((props) => useRoomAvatarViewModel(props), { initialProps: room });
expect(vm.current.isPublic).toBe(false);

const publicRoom = mkStubRoom("roomId2", "roomName2", matrixClient);
jest.spyOn(publicRoom, "getJoinRule").mockReturnValue(JoinRule.Public);
rerender(publicRoom);

await waitFor(() => expect(vm.current.isPublic).toBe(true));
});

describe("presence", () => {
let user: User;

Expand Down