Update chat-common.js
This commit is contained in:
@@ -59,11 +59,52 @@ function renderMediaMessage(msg) {
|
||||
|
||||
switch (mediaType) {
|
||||
case 'image': {
|
||||
const thumb = effective || '';
|
||||
const full = isValidMediaUrl(localFile) ? `/api/version/media-url.php?local=${encodeURIComponent(localFile)}` : (isValidMediaUrl(mediaExternal) ? `/api/version/media-url.php?url=${encodeURIComponent(mediaExternal)}` : (msg.media_url || ''));
|
||||
if (thumb) {
|
||||
return `<div class="message-media"><a href="#" data-full="${escapeHtml(full)}" onclick="openImageLightbox(this.dataset.full); return false;"><img src="${escapeHtml(thumb)}" alt="Imagen" style="cursor:zoom-in"></a></div>${content?`<div>${escapeHtml(content)}</div>`:''}`;
|
||||
// Compute thumbnail and full image URL following chat_window heuristics
|
||||
let thumbUrl = '';
|
||||
if (isValidMediaUrl(localThumb)) {
|
||||
thumbUrl = `/${localThumb}`;
|
||||
} else if (isValidMediaUrl(localFile)) {
|
||||
thumbUrl = `/${localFile}`;
|
||||
} else if (isValidMediaUrl(effective) || isValidMediaUrl(mediaExternal)) {
|
||||
const external = isValidMediaUrl(effective) ? effective : mediaExternal;
|
||||
if (/lookaside\.fbsbx\.com|graph\.facebook\.com|facebook\.com/i.test(external)) {
|
||||
const m = external.match(/[?&]mid=([^&]+)/i);
|
||||
if (m && m[1]) {
|
||||
thumbUrl = `/api/version/media-url.php?id=${encodeURIComponent(m[1])}`;
|
||||
} else {
|
||||
thumbUrl = `/api/version/media-url.php?url=${encodeURIComponent(external)}`;
|
||||
}
|
||||
} else {
|
||||
thumbUrl = external;
|
||||
}
|
||||
} else if (isValidMediaUrl(msg.media_url)) {
|
||||
thumbUrl = msg.media_url;
|
||||
}
|
||||
|
||||
// Full URL for opening (prefer local file then external with id or url)
|
||||
let fullUrl = '';
|
||||
if (isValidMediaUrl(localFile)) {
|
||||
fullUrl = `/api/version/media-url.php?local=${encodeURIComponent(localFile)}`;
|
||||
} else if (isValidMediaUrl(mediaExternal)) {
|
||||
let mid = '';
|
||||
if (mediaExternal.indexOf('api/get_media.php?id=') !== -1) {
|
||||
const parts = mediaExternal.split('id='); mid = parts[1] ? decodeURIComponent(parts[1]) : '';
|
||||
} else {
|
||||
const m = mediaExternal.match(/[?&]mid=([^&]+)/i); if (m && m[1]) mid = decodeURIComponent(m[1]);
|
||||
}
|
||||
if (mid) fullUrl = `/api/version/media-url.php?id=${encodeURIComponent(mid)}`;
|
||||
else if (/^https?:\/\//i.test(mediaExternal)) fullUrl = `/api/version/media-url.php?url=${encodeURIComponent(mediaExternal)}`;
|
||||
else fullUrl = `/api/version/media-url.php?url=${encodeURIComponent(mediaExternal)}`;
|
||||
} else {
|
||||
fullUrl = '';
|
||||
}
|
||||
|
||||
if (isValidMediaUrl(fullUrl)) {
|
||||
return `<div class="message-media"><a href="#" data-fullurl="${escapeHtml(fullUrl)}" onclick="openImageLightbox(this.dataset.fullurl); return false;" title="Abrir imagen"><img src="${escapeHtml(thumbUrl || fullUrl)}" alt="Imagen" class="message-media-image"></a></div>${content?`<div>${escapeHtml(content)}</div>`:''}`;
|
||||
} else if (isValidMediaUrl(thumbUrl)) {
|
||||
return `<div class="message-media"><img src="${escapeHtml(thumbUrl)}" alt="Imagen" class="message-media-image"></div>${content?`<div>${escapeHtml(content)}</div>`:''}`;
|
||||
}
|
||||
|
||||
return `<div class="text-muted"><em>Imagen no disponible</em></div>`;
|
||||
}
|
||||
case 'video': {
|
||||
|
||||
Reference in New Issue
Block a user