Update conversations.php

This commit is contained in:
Lizandro Guarnizo
2026-01-27 00:38:46 -05:00
parent 7bcb595b18
commit 68374b8127
+23 -3
View File
@@ -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;