Add low priority avatar decoration to room tile (#30065)

* Add avatar decoration for low priority rooms

* Write tests

* Remove unnecesasry step in test

* Make the vm expose which decoration to render

* Fix jest test

* Fix broken e2e test
This commit is contained in:
R Midhun Suresh
2025-06-10 13:45:38 +05:30
committed by GitHub
parent 2b24232f14
commit 6103f7e3b4
8 changed files with 207 additions and 142 deletions

View File

@@ -10,26 +10,26 @@ import { useEffect, useState } from "react";
import { useTypedEventEmitter } from "../../../hooks/useEventEmitter";
import { useDmMember, usePresence, type Presence } from "../../views/avatars/WithPresenceIndicator";
import { DefaultTagID } from "../../../stores/room-list/models";
export enum AvatarBadgeDecoration {
LowPriority = "LowPriority",
VideoRoom = "VideoRoom",
PublicRoom = "PublicRoom",
Presence = "Presence",
}
export interface RoomAvatarViewState {
/**
* Whether the room avatar has a decoration.
* A decoration can be a public or a video call icon or an indicator of presence.
*/
hasDecoration: boolean;
/**
* Whether the room is public.
*/
isPublic: boolean;
/**
* Whether the room is a video room.
*/
isVideoRoom: boolean;
/**
* The presence of the user in the DM room.
* If null, the user is not in a DM room or presence is not enabled.
*/
presence: Presence | null;
/**
* The decoration that should be rendered.
*/
badgeDecoration?: AvatarBadgeDecoration;
}
/**
@@ -41,10 +41,20 @@ export function useRoomAvatarViewModel(room: Room): RoomAvatarViewState {
const roomMember = useDmMember(room);
const presence = usePresence(room, roomMember);
const isPublic = useIsPublic(room);
const isLowPriority = !!room.tags[DefaultTagID.LowPriority];
const hasDecoration = isPublic || isVideoRoom || presence !== null;
let badgeDecoration: AvatarBadgeDecoration | undefined;
if (isLowPriority) {
badgeDecoration = AvatarBadgeDecoration.LowPriority;
} else if (isVideoRoom) {
badgeDecoration = AvatarBadgeDecoration.VideoRoom;
} else if (isPublic) {
badgeDecoration = AvatarBadgeDecoration.PublicRoom;
} else if (presence) {
badgeDecoration = AvatarBadgeDecoration.Presence;
}
return { hasDecoration, isPublic, isVideoRoom, presence };
return { badgeDecoration, presence };
}
/**