diff --git a/chat_window.php b/chat_window.php index 7d0e025..2c29071 100644 --- a/chat_window.php +++ b/chat_window.php @@ -570,19 +570,20 @@ if (empty($user_id)) { const isOutgoing = msg.direction === 'outgoing'; const messageClass = isOutgoing ? 'message-outgoing' : 'message-incoming'; - // Debug: ver todos los datos del mensaje (incluye media_url_external/local_file/local_thumb) - const has_media = !!(msg.media_url || msg.media_url_external || msg.local_file || msg.local_thumb); + // Debug: ver todos los datos del mensaje (prioriza media_url_external) + const has_media_external = !!(msg.media_url_external && msg.media_url_external.trim() !== ''); + const effective_media = msg.media_url_external || msg.local_file || msg.local_thumb || msg.media_url || ''; console.log('Procesando mensaje:', { id: msg.id, type: msg.message_type, - has_media_url: has_media, - media_url: msg.media_url || msg.media_url_external || msg.local_file || msg.local_thumb, + has_media_external: has_media_external, + effective_media: effective_media, content: msg.content }); - // Verificar si es multimedia (considerando varios orígenes de media) + // Verificar si es multimedia (validando principalmente media_url_external o archivos locales) let contentHtml = ''; - const hasMediaUrl = (msg.media_url && msg.media_url.trim() !== '') || (msg.media_url_external && msg.media_url_external.trim() !== '') || (msg.local_file && msg.local_file.trim() !== '') || (msg.local_thumb && msg.local_thumb.trim() !== ''); + const hasMediaUrl = (msg.media_url_external && msg.media_url_external.trim() !== '') || (msg.local_file && msg.local_file.trim() !== '') || (msg.local_thumb && msg.local_thumb.trim() !== ''); const isMultimedia = hasMediaUrl && msg.message_type && msg.message_type !== 'text'; if (isMultimedia) { @@ -590,16 +591,16 @@ if (empty($user_id)) { // Mensaje multimedia switch (msg.message_type) { case 'image': - // Determinar miniatura y URL completa (soporte para local, api/get_media?id= y URLs directas) + // Determinar miniatura y URL completa (prioriza media_url_external o archivos locales) let thumbUrl = ''; if (msg.local_thumb) { thumbUrl = `/${msg.local_thumb}`; } else if (msg.local_file) { thumbUrl = `/${msg.local_file}`; + } else if (msg.media_url_external) { + thumbUrl = msg.media_url_external; } else if (msg.media_url) { thumbUrl = msg.media_url; - } else if (msg.media_url_external) { - thumbUrl = msg.media_url_external; // se intentará redirigir/proxear al abrir } let fullUrl = ''; @@ -616,13 +617,22 @@ if (empty($user_id)) { fullUrl = `/api/version/media-url.php?url=${encodeURIComponent(msg.media_url_external)}`; } } else { - fullUrl = msg.media_url || thumbUrl || ''; + // No usar msg.media_url como fuente principal para apertura; dejar vacío para forzar 'no disponible' + fullUrl = ''; } - contentHtml = ` - - - `; + if (fullUrl && fullUrl.trim() !== '') { + contentHtml = ` + + + `; + } else if (thumbUrl && thumbUrl.trim() !== '') { + // Mostrar solo la miniatura si no hay URL externa/local para abrir + contentHtml = ``; + } else { + // No hay media disponible + contentHtml = `