From 68374b81272eec273e59b5cfb1b8e9168b49f581 Mon Sep 17 00:00:00 2001 From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com> Date: Tue, 27 Jan 2026 00:38:46 -0500 Subject: [PATCH] Update conversations.php --- conversations.php | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/conversations.php b/conversations.php index a0402ef..4819592 100644 --- a/conversations.php +++ b/conversations.php @@ -2574,7 +2574,24 @@ } // Cargar mensajes (con paginación) - await this.loadMessages(userId, true); + // Scroll inmediato al fondo para que el usuario vea el final mientras cargamos el bloque completo + try { + const immedContainer = document.getElementById('chat-conversations'); + if (immedContainer) { + immedContainer.scrollTop = immedContainer.scrollHeight; + // clear any pending reloads and temporarily suspend auto-refresh to avoid races + this._pendingReloadAfterScroll = false; + this._pendingReloadAfterMedia = false; + this._suspendAutoRefresh = true; + if (console && console.debug) console.debug('openConversation: scrolled to bottom and suspended auto-refresh prior to full load'); + } + } catch(e) { /* ignore */ } + + await this.loadMessages(userId, true, true); + + // Resume auto-refresh after the load + try { this._suspendAutoRefresh = false; } catch(e) {} + // Añadir listener para scroll arriba (cargar más historial) const chatContainer = document.getElementById('chat-conversations'); if (chatContainer) { @@ -2595,7 +2612,9 @@ } catch(e) { /* ignore */ } if (chatContainer.scrollTop <= 60 && this.hasMoreMessages && !this.loadingMessages && this.currentUserId == userId) { - await this.loadMessages(userId, false); + // User scrolled to top: trigger a full reload (initial=true) but don't jump to bottom (follow=false) + try { if (console && console.debug) console.debug('User scrolled to top - triggering full load (follow=false)'); } catch(e) {} + await this.loadMessages(userId, true, false); } // If the user scrolled near the bottom and there are staged messages, apply them @@ -2918,7 +2937,8 @@ this._fullLoadInProgress = false; if (initial) { - this.scrollToBottom(); + // Scroll to bottom only if the caller requested following behavior + if (follow) { this.scrollToBottom(); } } else if (container) { // Mantener posición: desplazar por la diferencia de heights const newScrollHeight = container.scrollHeight;