/** * ConversationList Component * Displays list of conversations in sidebar */ import React from 'react'; import './ConversationList.css'; export default function ConversationList({ conversations, activeConversation, onSelectConversation }) { const formatTime = (timestamp) => { const date = new Date(timestamp); const now = new Date(); const diffMs = now - date; const diffMins = Math.floor(diffMs / 60000); const diffHours = Math.floor(diffMs / 3600000); const diffDays = Math.floor(diffMs / 86400000); if (diffMins < 1) return 'Just now'; if (diffMins < 60) return `${diffMins}m ago`; if (diffHours < 24) return `${diffHours}h ago`; if (diffDays < 7) return `${diffDays}d ago`; return date.toLocaleDateString(); }; const getConversationTitle = (conv) => { if (conv.title) return conv.title; // For direct conversations, show other participant's domain if (conv.otherParticipants && conv.otherParticipants.length > 0) { return conv.otherParticipants[0].verified_domain || conv.otherParticipants[0].username; } return 'Unknown'; }; const getConversationAvatar = (conv) => { if (conv.avatarUrl) return conv.avatarUrl; // For direct conversations, show other participant's avatar if (conv.otherParticipants && conv.otherParticipants.length > 0) { return conv.otherParticipants[0].avatar_url; } return null; }; return (

Messages

{conversations.length === 0 ? (

No conversations yet

Start a new conversation to get started

) : ( conversations.map(conv => (
onSelectConversation(conv)} >
{getConversationAvatar(conv) ? ( Avatar ) : (
{getConversationTitle(conv)[0]?.toUpperCase()}
)} {conv.otherParticipants?.[0]?.status === 'online' && ( )}

{getConversationTitle(conv)}

{formatTime(conv.updatedAt)}

{conv.lastMessage?.content || 'No messages yet'}

{conv.unreadCount > 0 && ( {conv.unreadCount} )}
)) )}
); }