// ECO-PANNEAU.FR - _react/clients/_clients_modals_riverains.jsx window.pano_ClientRiverainsListModal = ({ panneau, myClientData, interactions, onClose, refreshData, openLocalDialog }) => { const { useState } = React; const urlModal = window.pano_useUrlModal ? window.pano_useUrlModal() : {}; const { MessageCircleIcon, MailIcon, SettingsIcon, EyeIcon } = window.pano_getIcons(); const { Modal, Button, EmptyState, DataCard, NotificationBadge } = window.pano_getComponents(); const isOwner = panneau.client_uid === myClientData.id; // CORRECTION SÉCURITÉ : Identification stricte par UID (Zéro-Rétrocompatibilité) const myCollab = !isOwner ? panneau.collaborators?.find(c => c.uid === myClientData.id) : null; const canChat = isOwner || (myCollab && ['read', 'rw'].includes(myCollab.rights?.chat_access)); if (!canChat) { return (

Vous n'avez pas accès à la messagerie de ce panneau.

); } const riverainMessages = interactions.filter(m => m.panneauId === panneau.id && m.isAlert !== 2); const threadsMap = {}; riverainMessages.forEach(m => { const visitorEmail = (m.authorType === 'Admin' || m.authorType === 'Systeme' || m.authorType === 'System' || (m.authorType === 'Client' && (m.author === 'Client' || m.author === myClientData.email || m.author === myClientData.full_name || m.author === myClientData.name || m.author === `${myClientData.full_name || 'Utilisateur'} (${myClientData.name || 'Société'})`))) ? m.target : m.author; if (!threadsMap[visitorEmail]) { threadsMap[visitorEmail] = { email: visitorEmail, unread: 0, messages: [], lastDate: null }; } threadsMap[visitorEmail].messages.push(m); const isMyOwnMessage = (m.authorType === 'Client' && (m.author === 'Client' || m.author === myClientData.email || m.author === myClientData.full_name || m.author === myClientData.name || m.author === `${myClientData.full_name || 'Utilisateur'} (${myClientData.name || 'Société'})`)); if (!m.resolved && !isMyOwnMessage && m.authorType !== 'Systeme' && m.authorType !== 'System') { threadsMap[visitorEmail].unread++; } threadsMap[visitorEmail].lastDate = new Date(String(m.created_at || '').replace(' ', 'T')).getTime(); }); const threads = Object.values(threadsMap).sort((a, b) => b.lastDate - a.lastDate); return ( ( )} >
{threads.length === 0 ? ( ) : ( threads.map(t => ( { onClose(); urlModal.openChat(`${panneau.id}_${t.email}`, false); }} className="cursor-pointer hover:border-amber-300 transition group p-4 border-slate-200 min-w-0">

{t.email}

{window.pano_formatPlural(t.messages.length, 'message', 'messages')}

{t.unread > 0 && }
0 ? 'text-slate-800 font-bold' : 'text-slate-600'}`}> {t.messages[t.messages.length - 1].detail.replace(/\[ATTACHMENT:[^\]]+\]/g, '[Pièce jointe]').replace(/<[^>]*>?/gm, '')}
)) )}
); }; /* EOF ========== [_react/clients/_clients_modals_riverains.jsx] */