update and fix messanger
This commit is contained in:
@@ -5,6 +5,7 @@ import { useEffect, useMemo, useState } from 'react';
|
||||
import { UserAvatar } from '@/components/id/user-avatar';
|
||||
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar';
|
||||
import { ChatRoom, apiFetch } from '@/lib/api';
|
||||
import { CHAT_ROOM_AVATAR_UPDATED_EVENT } from '@/lib/avatar-events';
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
interface ChatRoomAvatarDisplayProps {
|
||||
@@ -34,10 +35,30 @@ export function ChatRoomAvatarDisplay({ room, viewerUserId, token, className, si
|
||||
setRoomAvatarUrl(null);
|
||||
return;
|
||||
}
|
||||
let cancelled = false;
|
||||
apiFetch<{ accessUrl: string }>(`/media/chat/${room.id}/avatar/url`, {}, token)
|
||||
.then((response) => setRoomAvatarUrl(response.accessUrl))
|
||||
.catch(() => setRoomAvatarUrl(null));
|
||||
}, [room.hasAvatar, room.id, room.type, token]);
|
||||
.then((response) => {
|
||||
if (!cancelled) setRoomAvatarUrl(response.accessUrl);
|
||||
})
|
||||
.catch(() => {
|
||||
if (!cancelled) setRoomAvatarUrl(null);
|
||||
});
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, [room.hasAvatar, room.id, room.type, room.updatedAt, token]);
|
||||
|
||||
useEffect(() => {
|
||||
function handleRoomAvatarUpdated(event: Event) {
|
||||
const detail = (event as CustomEvent<{ roomId?: string }>).detail;
|
||||
if (detail?.roomId !== room.id || !room.hasAvatar || !token) return;
|
||||
apiFetch<{ accessUrl: string }>(`/media/chat/${room.id}/avatar/url`, {}, token)
|
||||
.then((response) => setRoomAvatarUrl(response.accessUrl))
|
||||
.catch(() => setRoomAvatarUrl(null));
|
||||
}
|
||||
window.addEventListener(CHAT_ROOM_AVATAR_UPDATED_EVENT, handleRoomAvatarUpdated);
|
||||
return () => window.removeEventListener(CHAT_ROOM_AVATAR_UPDATED_EVENT, handleRoomAvatarUpdated);
|
||||
}, [room.hasAvatar, room.id, token]);
|
||||
|
||||
if (peerMember && (room.type === 'DIRECT' || room.type === 'E2E')) {
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user