import { formatDistanceToNow } from 'date-fns' function ConversationList({ conversations, selectedConversation, onSelectConversation, loading }) { const formatDate = (date) => { try { return formatDistanceToNow(new Date(date), { addSuffix: true }) } catch { return '' } } const truncateMessage = (message, maxLength = 50) => { if (!message) return '' if (message.length <= maxLength) return message return message.substring(0, maxLength).trim() + '...' } const formatPhoneNumber = (number) => { if (!number) return 'Unknown' // Handle comma-separated numbers (group conversations) if (number.includes(',')) { const numbers = number.split(',').map(n => n.trim()) return numbers.map(n => formatSinglePhoneNumber(n)).join(', ') } return formatSinglePhoneNumber(number) } const formatSinglePhoneNumber = (number) => { if (!number) return 'Unknown' // Remove all non-digit characters const cleaned = number.replace(/\D/g, '') // Handle 11-digit numbers (e.g., +1 country code) if (cleaned.length === 11 && cleaned.startsWith('1')) { return `+1 (${cleaned.slice(1, 4)}) ${cleaned.slice(4, 7)}-${cleaned.slice(7)}` } // Handle 10-digit numbers (US format) if (cleaned.length === 10) { return `(${cleaned.slice(0, 3)}) ${cleaned.slice(3, 6)}-${cleaned.slice(6)}` } // Handle other formats - try to format with spaces if (cleaned.length > 10) { // International format: +XX XXX XXX XXXX return `+${cleaned.slice(0, cleaned.length - 10)} ${cleaned.slice(cleaned.length - 10, cleaned.length - 7)} ${cleaned.slice(cleaned.length - 7, cleaned.length - 4)} ${cleaned.slice(cleaned.length - 4)}` } // Return original if we can't format it nicely return number } const shouldDisplaySubject = (subject) => { if (!subject) return false // Filter out protocol buffer/RCS subjects if (subject.startsWith('proto:')) return false return true } const getDisplayName = (conv) => { // If we have a valid subject, use it when contact_name is empty, "(Unknown)", or looks like an 8-digit number if (conv.subject && shouldDisplaySubject(conv.subject)) { if (!conv.contact_name || conv.contact_name === '(Unknown)' || /^\d{8}$/.test(conv.contact_name)) { return conv.subject } } // If contact_name is empty, null, or "(Unknown)", use formatted phone number if (!conv.contact_name || conv.contact_name === '(Unknown)') { return formatPhoneNumber(conv.address) } return conv.contact_name } const getConversationIcon = (type) => { if (type === 'call') { return ( ) } return ( ) } if (loading) { return (
Loading conversations...
No conversations found
Upload a backup file to get started
{truncateMessage(conv.last_message, 50)}