up
This commit is contained in:
@@ -63,25 +63,54 @@ try {
|
|||||||
|
|
||||||
// Formatear mensajes
|
// Formatear mensajes
|
||||||
$conversations = array_map(function($msg) {
|
$conversations = array_map(function($msg) {
|
||||||
return [
|
// Build external URL if available (media id -> api/get_media proxy)
|
||||||
'id' => intval($msg['id']),
|
$external = (isset($msg['media_url']) && $msg['media_url']) ? (preg_match('#^https?://#i', $msg['media_url']) ? $msg['media_url'] : ("api/get_media.php?id=" . urlencode($msg['media_url']))) : null;
|
||||||
'message_id' => $msg['message_id'] ?? '',
|
|
||||||
'direction' => $msg['direction'],
|
// Fallback: if no external URL but content is JSON with link, extract it
|
||||||
'message_type' => $msg['message_type'],
|
$contentStr = $msg['content'] ?? '';
|
||||||
'content' => $msg['content'] ?? '',
|
if (!$external && $contentStr) {
|
||||||
'media_url' => null,
|
$j = json_decode($contentStr, true);
|
||||||
'local_file' => $msg['local_file'] ?? null,
|
if (is_array($j)) {
|
||||||
'local_thumb' => $msg['local_thumb'] ?? null,
|
// Look for common shapes: image.link, image.url, document.link, audio.link
|
||||||
'media_url_external' => (isset($msg['media_url']) && $msg['media_url']) ? (preg_match('#^https?://#i', $msg['media_url']) ? $msg['media_url'] : ("api/get_media.php?id=" . urlencode($msg['media_url']))) : null,
|
$candidates = [];
|
||||||
'filename' => $msg['filename'] ?? null,
|
foreach (['image','document','audio','video'] as $k) {
|
||||||
'mime_type' => $msg['mime_type'] ?? null,
|
if (isset($j[$k]) && is_array($j[$k])) {
|
||||||
'status' => $msg['status'] ?? 'sent',
|
if (!empty($j[$k]['link'])) $candidates[] = $j[$k]['link'];
|
||||||
'created_at' => $msg['created_at'],
|
if (!empty($j[$k]['url'])) $candidates[] = $j[$k]['url'];
|
||||||
'time' => date('H:i', strtotime($msg['created_at'])),
|
if (!empty($j[$k]['id'])) $candidates[] = $j[$k]['id'];
|
||||||
'date' => date('d/m/Y', strtotime($msg['created_at']))
|
}
|
||||||
];
|
}
|
||||||
}, $conversations);
|
// also top-level 'link'
|
||||||
|
if (!empty($j['link'])) $candidates[] = $j['link'];
|
||||||
|
// first valid candidate wins
|
||||||
|
foreach ($candidates as $cand) {
|
||||||
|
if ($cand) {
|
||||||
|
// if looks like id or url
|
||||||
|
$external = preg_match('#^https?://#i', $cand) ? $cand : (strpos($cand, 'http') === false ? "api/get_media.php?id=" . urlencode($cand) : $cand);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
'id' => intval($msg['id']),
|
||||||
|
'message_id' => $msg['message_id'] ?? '',
|
||||||
|
'direction' => $msg['direction'],
|
||||||
|
'message_type' => $msg['message_type'],
|
||||||
|
'content' => $msg['content'] ?? '',
|
||||||
|
'media_url' => null,
|
||||||
|
'local_file' => $msg['local_file'] ?? null,
|
||||||
|
'local_thumb' => $msg['local_thumb'] ?? null,
|
||||||
|
'media_url_external' => $external,
|
||||||
|
'filename' => $msg['filename'] ?? null,
|
||||||
|
'mime_type' => $msg['mime_type'] ?? null,
|
||||||
|
'status' => $msg['status'] ?? 'sent',
|
||||||
|
'created_at' => $msg['created_at'],
|
||||||
|
'time' => date('H:i', strtotime($msg['created_at'])),
|
||||||
|
'date' => date('d/m/Y', strtotime($msg['created_at']))
|
||||||
|
];
|
||||||
|
}, $conversations);
|
||||||
// Marcar mensajes como leídos
|
// Marcar mensajes como leídos
|
||||||
$db->query(
|
$db->query(
|
||||||
"UPDATE conversations SET status = 'read' WHERE user_id = ? AND direction = 'incoming' AND status != 'read'",
|
"UPDATE conversations SET status = 'read' WHERE user_id = ? AND direction = 'incoming' AND status != 'read'",
|
||||||
|
|||||||
@@ -81,6 +81,22 @@ try {
|
|||||||
|
|
||||||
// Formatear fechas y limpiar datos
|
// Formatear fechas y limpiar datos
|
||||||
$conversations = array_map(function($msg) {
|
$conversations = array_map(function($msg) {
|
||||||
|
$external = (isset($msg['media_url']) && $msg['media_url']) ? (preg_match('#^https?://#i', $msg['media_url']) ? $msg['media_url'] : ("api/get_media.php?id=" . urlencode($msg['media_url']))) : null;
|
||||||
|
$contentStr = $msg['content'] ?? '';
|
||||||
|
if (!$external && $contentStr) {
|
||||||
|
$j = json_decode($contentStr, true);
|
||||||
|
if (is_array($j)) {
|
||||||
|
foreach (['image','document','audio','video'] as $k) {
|
||||||
|
if (isset($j[$k]) && is_array($j[$k])) {
|
||||||
|
if (!empty($j[$k]['link'])) { $external = $j[$k]['link']; break; }
|
||||||
|
if (!empty($j[$k]['url'])) { $external = $j[$k]['url']; break; }
|
||||||
|
if (!empty($j[$k]['id'])) { $external = "api/get_media.php?id=" . urlencode($j[$k]['id']); break; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!$external && !empty($j['link'])) $external = $j['link'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'id' => intval($msg['id']),
|
'id' => intval($msg['id']),
|
||||||
'user_id' => intval($msg['user_id']),
|
'user_id' => intval($msg['user_id']),
|
||||||
@@ -89,7 +105,7 @@ try {
|
|||||||
'media_url' => null,
|
'media_url' => null,
|
||||||
'local_file' => $msg['local_file'] ?? null,
|
'local_file' => $msg['local_file'] ?? null,
|
||||||
'local_thumb' => $msg['local_thumb'] ?? null,
|
'local_thumb' => $msg['local_thumb'] ?? null,
|
||||||
'media_url_external' => (isset($msg['media_url']) && $msg['media_url']) ? (preg_match('#^https?://#i', $msg['media_url']) ? $msg['media_url'] : ("api/get_media.php?id=" . urlencode($msg['media_url']))) : null,
|
'media_url_external' => $external,
|
||||||
'filename' => $msg['filename'] ?? null,
|
'filename' => $msg['filename'] ?? null,
|
||||||
'mime_type' => $msg['mime_type'] ?? null,
|
'mime_type' => $msg['mime_type'] ?? null,
|
||||||
'user_phone' => $msg['user_phone'] ?? null,
|
'user_phone' => $msg['user_phone'] ?? null,
|
||||||
|
|||||||
+18
-3
@@ -1378,7 +1378,9 @@
|
|||||||
}
|
}
|
||||||
return `
|
return `
|
||||||
<div class="message-media">
|
<div class="message-media">
|
||||||
<img src="${thumb}" alt="Imagen" onclick="window.open('${full}', '_blank')" style="cursor:zoom-in">
|
<a href="${full}" target="_blank" rel="noopener noreferrer">
|
||||||
|
<img src="${thumb}" alt="Imagen" style="cursor:zoom-in">
|
||||||
|
</a>
|
||||||
</div>
|
</div>
|
||||||
${caption ? `<div>${caption}</div>` : ''}
|
${caption ? `<div>${caption}</div>` : ''}
|
||||||
`;
|
`;
|
||||||
@@ -1453,12 +1455,25 @@
|
|||||||
docUrl = `/api/version/media-url.php?url=${encodeURIComponent(msg.media_url_external)}&download=1`;
|
docUrl = `/api/version/media-url.php?url=${encodeURIComponent(msg.media_url_external)}&download=1`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!docUrl) {
|
||||||
|
return `
|
||||||
|
<div class="message-document disabled">
|
||||||
|
<i class="fas fa-file-pdf"></i>
|
||||||
|
<div class="document-info">
|
||||||
|
<div class="document-name">${caption || 'Documento'}</div>
|
||||||
|
<div class="document-size text-muted">No disponible para descargar</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
}
|
||||||
return `
|
return `
|
||||||
<div class="message-document" onclick="window.open('${docUrl}', '_blank')" style="cursor:pointer">
|
<div class="message-document">
|
||||||
<i class="fas fa-file-pdf"></i>
|
<i class="fas fa-file-pdf"></i>
|
||||||
<div class="document-info">
|
<div class="document-info">
|
||||||
<div class="document-name">${caption || 'Documento'}</div>
|
<div class="document-name">${caption || 'Documento'}</div>
|
||||||
<div class="document-size">Haz clic para descargar</div>
|
<div class="document-size">
|
||||||
|
<a href="${docUrl}" target="_blank" rel="noopener noreferrer" ${docUrl && docUrl.indexOf('download=1') !== -1 ? 'download' : ''}>Descargar</a>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<i class="fas fa-download"></i>
|
<i class="fas fa-download"></i>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -645,7 +645,7 @@ try {
|
|||||||
<!-- Scripts -->
|
<!-- Scripts -->
|
||||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
||||||
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
||||||
<script src="./assets/js/app_simple.js?v=3"></script>
|
<script src="./assets/js/app_simple.js?v=4"></script>
|
||||||
<script>
|
<script>
|
||||||
// Función de diagnóstico mejorada
|
// Función de diagnóstico mejorada
|
||||||
function runDiagnostic() {
|
function runDiagnostic() {
|
||||||
|
|||||||
Reference in New Issue
Block a user