diff --git a/conversations.php b/conversations.php index b97116e..15412bf 100644 --- a/conversations.php +++ b/conversations.php @@ -940,8 +940,8 @@ // Track whether the user is actively scrolling/reading to avoid forcing scroll-to-bottom this._userScrolling = false; this._userScrollTimer = null; - // Track last known messages count to show "Nuevos mensajes" indicator when new messages arrive while user is reading - this._lastRenderMessageCount = 0; + // Removed: automatic "Nuevos mensajes" indicator — we always reload full conversation now + // this._lastRenderMessageCount = 0; this.init(); } @@ -1535,11 +1535,11 @@ }, 30000); // 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(() => { if (this.currentUserId) { - // loadMessages with initial=false fetches older/newer messages without forcing a scroll - this.loadMessages(this.currentUserId, false).catch(err => console.warn('Periodic loadMessages failed', err)); + // full reload forces scroll-to-bottom + this.loadMessages(this.currentUserId, true).catch(err => console.warn('Periodic loadMessages failed', err)); } }, 10000); } @@ -2537,21 +2537,10 @@ const nearBottom = (container.scrollHeight - container.scrollTop - container.clientHeight) < 150; 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) { 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; } - // --- New messages indicator helpers --- + // --- New messages indicator helpers (removed) --- showNewMessagesIndicator(count) { - try { - 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); } + // No-op: indicator removed — full reload & scroll-to-bottom now used } hideNewMessagesIndicator() { - try { - const el = document.getElementById('new-messages-indicator'); - if (el) el.style.display = 'none'; - } catch (e) { console.warn('hideNewMessagesIndicator failed', e); } + // No-op } getStatusIcon(status) {