Update conversations.php
This commit is contained in:
+8
-43
@@ -940,8 +940,8 @@
|
|||||||
// Track whether the user is actively scrolling/reading to avoid forcing scroll-to-bottom
|
// Track whether the user is actively scrolling/reading to avoid forcing scroll-to-bottom
|
||||||
this._userScrolling = false;
|
this._userScrolling = false;
|
||||||
this._userScrollTimer = null;
|
this._userScrollTimer = null;
|
||||||
// Track last known messages count to show "Nuevos mensajes" indicator when new messages arrive while user is reading
|
// Removed: automatic "Nuevos mensajes" indicator — we always reload full conversation now
|
||||||
this._lastRenderMessageCount = 0;
|
// this._lastRenderMessageCount = 0;
|
||||||
|
|
||||||
this.init();
|
this.init();
|
||||||
}
|
}
|
||||||
@@ -1535,11 +1535,11 @@
|
|||||||
}, 30000);
|
}, 30000);
|
||||||
|
|
||||||
// Actualizar mensajes del chat activo cada 10 segundos
|
// Actualizar mensajes del chat activo cada 10 segundos
|
||||||
// Use incremental load (initial=false) to avoid forcing scroll to bottom while the user reads
|
// Use full reload (initial=true) — always fetch the full conversation and scroll to bottom
|
||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
if (this.currentUserId) {
|
if (this.currentUserId) {
|
||||||
// loadMessages with initial=false fetches older/newer messages without forcing a scroll
|
// full reload forces scroll-to-bottom
|
||||||
this.loadMessages(this.currentUserId, false).catch(err => console.warn('Periodic loadMessages failed', err));
|
this.loadMessages(this.currentUserId, true).catch(err => console.warn('Periodic loadMessages failed', err));
|
||||||
}
|
}
|
||||||
}, 10000);
|
}, 10000);
|
||||||
}
|
}
|
||||||
@@ -2537,21 +2537,10 @@
|
|||||||
const nearBottom = (container.scrollHeight - container.scrollTop - container.clientHeight) < 150;
|
const nearBottom = (container.scrollHeight - container.scrollTop - container.clientHeight) < 150;
|
||||||
const shouldScroll = initial ? true : (nearBottom && !this._userScrolling);
|
const shouldScroll = initial ? true : (nearBottom && !this._userScrolling);
|
||||||
|
|
||||||
// Determine if we received new messages since last render
|
|
||||||
const prevCount = this._lastRenderMessageCount || 0;
|
|
||||||
const newCount = this.conversations.length || 0;
|
|
||||||
const added = Math.max(0, newCount - prevCount);
|
|
||||||
|
|
||||||
if (shouldScroll) {
|
if (shouldScroll) {
|
||||||
this.scrollToBottom();
|
this.scrollToBottom();
|
||||||
// hide indicator if visible
|
|
||||||
if (added) this.hideNewMessagesIndicator();
|
|
||||||
} else {
|
|
||||||
if (added > 0) this.showNewMessagesIndicator(added);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save for next render
|
|
||||||
this._lastRenderMessageCount = newCount;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2704,37 +2693,13 @@
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- New messages indicator helpers ---
|
// --- New messages indicator helpers (removed) ---
|
||||||
showNewMessagesIndicator(count) {
|
showNewMessagesIndicator(count) {
|
||||||
try {
|
// No-op: indicator removed — full reload & scroll-to-bottom now used
|
||||||
let el = document.getElementById('new-messages-indicator');
|
|
||||||
if (!el) {
|
|
||||||
el = document.createElement('div');
|
|
||||||
el.id = 'new-messages-indicator';
|
|
||||||
el.style.position = 'fixed';
|
|
||||||
el.style.bottom = '90px';
|
|
||||||
el.style.left = '50%';
|
|
||||||
el.style.transform = 'translateX(-50%)';
|
|
||||||
el.style.background = '#0d6efd';
|
|
||||||
el.style.color = 'white';
|
|
||||||
el.style.padding = '8px 12px';
|
|
||||||
el.style.borderRadius = '20px';
|
|
||||||
el.style.boxShadow = '0 2px 8px rgba(0,0,0,0.2)';
|
|
||||||
el.style.zIndex = '2000';
|
|
||||||
el.style.cursor = 'pointer';
|
|
||||||
el.onclick = () => { this.scrollToBottom(); this.hideNewMessagesIndicator(); };
|
|
||||||
document.body.appendChild(el);
|
|
||||||
}
|
|
||||||
el.textContent = (count > 1) ? (`${count} mensajes nuevos`) : '1 mensaje nuevo';
|
|
||||||
el.style.display = 'block';
|
|
||||||
} catch (e) { console.warn('showNewMessagesIndicator failed', e); }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
hideNewMessagesIndicator() {
|
hideNewMessagesIndicator() {
|
||||||
try {
|
// No-op
|
||||||
const el = document.getElementById('new-messages-indicator');
|
|
||||||
if (el) el.style.display = 'none';
|
|
||||||
} catch (e) { console.warn('hideNewMessagesIndicator failed', e); }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getStatusIcon(status) {
|
getStatusIcon(status) {
|
||||||
|
|||||||
Reference in New Issue
Block a user