import { useMemo, useState } from 'react'; import { AlertTriangle } from 'lucide-react'; import { useDMContext } from '@/contexts/DMContext'; import { useAuthor } from '@/hooks/useAuthor'; import { genUserName } from '@/lib/genUserName'; import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar'; import { Card } from '@/components/ui/card'; import { ScrollArea } from '@/components/ui/scroll-area'; import { Skeleton } from '@/components/ui/skeleton'; import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip'; import { cn } from '@/lib/utils'; interface ConversationListProps { selectedPubkey: string | null; onSelectConversation: (pubkey: string) => void; className?: string; } const ConversationItem = ({ pubkey, isSelected, onClick, lastMessage, lastActivity, hasNIP4Messages }: { pubkey: string; isSelected: boolean; onClick: () => void; lastMessage: { decryptedContent?: string; error?: string } | null; lastActivity: number; hasNIP4Messages: 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 'now'; if (diff < 3600) return `${Math.floor(diff / 60)}m`; if (diff < 86400) return `${Math.floor(diff / 3600)}h`; if (diff < 604800) return `${Math.floor(diff / 86400)}d`; const date = new Date(timestamp * 1000); const month = String(date.getMonth() + 1).padStart(2, '0'); const day = String(date.getDate()).padStart(2, '0'); return `${month}/${day}`; }; const lastMessagePreview = lastMessage?.error ? '🔒 Encrypted message' : lastMessage?.decryptedContent || 'No messages yet'; return ( ); }; const ConversationListSkeleton = () => { return (
No conversations yet
Start a new conversation to get started
No conversations