Update conversations.php
This commit is contained in:
+12
-7
@@ -2484,11 +2484,14 @@
|
|||||||
// No existing media element, render new media block without touching other parts
|
// No existing media element, render new media block without touching other parts
|
||||||
try {
|
try {
|
||||||
body.innerHTML = window.renderMediaMessage ? window.renderMediaMessage(msg) : window.escapeHtml(msg.content || '[Mensaje]');
|
body.innerHTML = window.renderMediaMessage ? window.renderMediaMessage(msg) : window.escapeHtml(msg.content || '[Mensaje]');
|
||||||
// If after inserting media/text the body appears empty, replace with placeholder
|
// If after inserting media/text the body appears empty and there's no media element, replace with placeholder
|
||||||
if ((body.textContent || '').trim() === '') {
|
try {
|
||||||
body.innerHTML = '<em>(Mensaje sin texto)</em>';
|
const hasMediaNode = !!body.querySelector && !!body.querySelector('img,video,audio,source,.message-media');
|
||||||
console.warn('Post-update: media/text produced empty body, set placeholder for', msg && (msg.id || msg.message_id));
|
if ((body.textContent || '').trim() === '' && !hasMediaNode) {
|
||||||
}
|
body.innerHTML = '<em>(Mensaje sin texto)</em>';
|
||||||
|
console.warn('Post-update: media/text produced empty body, set placeholder for', msg && (msg.id || msg.message_id));
|
||||||
|
}
|
||||||
|
} catch (e) { /* ignore DOM query errors */ }
|
||||||
} catch(e) { /* ignore */ }
|
} catch(e) { /* ignore */ }
|
||||||
} else if (existingMedia && !newMediaUrl) {
|
} else if (existingMedia && !newMediaUrl) {
|
||||||
// Media removed in new message: replace body with text/content
|
// Media removed in new message: replace body with text/content
|
||||||
@@ -2528,10 +2531,12 @@
|
|||||||
? (window.renderMediaMessage ? window.renderMediaMessage(msg) : (window.formatMessageContent ? window.formatMessageContent(msg.content || '[Mensaje]') : window.escapeHtml(msg.content || '[Mensaje]')))
|
? (window.renderMediaMessage ? window.renderMediaMessage(msg) : (window.formatMessageContent ? window.formatMessageContent(msg.content || '[Mensaje]') : window.escapeHtml(msg.content || '[Mensaje]')))
|
||||||
: (window.formatMessageContent ? window.formatMessageContent(msg.content || '') : window.escapeHtml(msg.content || ''));
|
: (window.formatMessageContent ? window.formatMessageContent(msg.content || '') : window.escapeHtml(msg.content || ''));
|
||||||
|
|
||||||
// If after formatting the content is empty (spaces or nothing), show a clearer placeholder
|
// If after formatting the content is empty (spaces or nothing), show a clearer placeholder.
|
||||||
|
// But allow pure media-only content (images/audio/video) to render instead of being treated as empty.
|
||||||
try {
|
try {
|
||||||
const tmp = (content || '').replace(/<[^>]*>/g, '').trim(); // strip tags and check
|
const tmp = (content || '').replace(/<[^>]*>/g, '').trim(); // strip tags and check
|
||||||
if (!tmp) {
|
const hasMediaTag = /<(img|audio|video|source|a[^>]*download|div\s+class=["']?message-media)/i.test(content || '');
|
||||||
|
if (!tmp && !hasMediaTag) {
|
||||||
console.warn('Rendered message content empty, replacing with placeholder', mid, msg.id, msg.created_at);
|
console.warn('Rendered message content empty, replacing with placeholder', mid, msg.id, msg.created_at);
|
||||||
content = '<em>(Mensaje sin texto)</em>';
|
content = '<em>(Mensaje sin texto)</em>';
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user