import { useDMContext } from '@/contexts/DMContext'; import { useAuthor } from '@/hooks/useAuthor'; import { genUserName } from '@/lib/genUserName'; import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar'; import { Badge } from '@/components/ui/badge'; import { Card } from '@/components/ui/card'; import { ScrollArea } from '@/components/ui/scroll-area'; import { Skeleton } from '@/components/ui/skeleton'; import { cn } from '@/lib/utils'; interface ConversationListProps { selectedPubkey: string | null; onSelectConversation: (pubkey: string) => void; className?: string; } function ConversationItem({ pubkey, isSelected, onClick, lastMessage, lastActivity, hasNIP17Messages }: { pubkey: string; isSelected: boolean; onClick: () => void; lastMessage: { decryptedContent?: string; error?: string } | null; lastActivity: number; hasNIP17Messages: boolean; }) { const author = useAuthor(pubkey); const metadata = author.data?.metadata; const displayName = metadata?.name || genUserName(pubkey); const avatarUrl = metadata?.picture; const initials = displayName.slice(0, 2).toUpperCase(); // Format timestamp const formatTime = (timestamp: number) => { const now = Date.now() / 1000; const diff = now - timestamp; if (diff < 60) return 'Just now'; if (diff < 3600) return `${Math.floor(diff / 60)}m ago`; if (diff < 86400) return `${Math.floor(diff / 3600)}h ago`; if (diff < 604800) return `${Math.floor(diff / 86400)}d ago`; return new Date(timestamp * 1000).toLocaleDateString(); }; const lastMessagePreview = lastMessage?.error ? '🔒 Encrypted message' : lastMessage?.decryptedContent?.slice(0, 50) || 'No messages yet'; return ( ); } function ConversationListSkeleton() { return (
No conversations yet
Start a new conversation to get started
{conversations.length} conversation{conversations.length !== 1 ? 's' : ''}