up
This commit is contained in:
@@ -1901,6 +1901,11 @@
|
||||
// New: periodic delta poller to fetch only messages newer than last seen timestamp
|
||||
async pollNewMessages() {
|
||||
if (!this.currentUserId) return;
|
||||
// Do not run delta polling when a full load is in progress (avoids races/clearing)
|
||||
if (this._fullLoadInProgress) {
|
||||
if (console && console.debug) console.debug('pollNewMessages skipped due to full load in progress');
|
||||
return;
|
||||
}
|
||||
try {
|
||||
// If we don't yet have a latest message timestamp, fall back to full load
|
||||
if (!this._latestMessage) {
|
||||
@@ -2667,6 +2672,8 @@
|
||||
async loadMessages(userId, initial = false, follow = true) {
|
||||
if (this.loadingMessages) return;
|
||||
this.loadingMessages = true;
|
||||
// Mark a full load is in progress to avoid race with delta polling
|
||||
this._fullLoadInProgress = true;
|
||||
const container = document.getElementById('chat-conversations');
|
||||
|
||||
// si cargamos más antiguos, preservar scroll
|
||||
@@ -2893,6 +2900,9 @@
|
||||
|
||||
// Replace media rendering uses window.renderMediaMessage inside element creation/update
|
||||
|
||||
// Full load finished - unset flag so polling can resume
|
||||
this._fullLoadInProgress = false;
|
||||
|
||||
if (initial) {
|
||||
this.scrollToBottom();
|
||||
} else if (container) {
|
||||
@@ -2946,6 +2956,9 @@
|
||||
}
|
||||
} finally {
|
||||
this.loadingMessages = false;
|
||||
// Ensure the full-load-in-progress flag is cleared even on errors/early returns
|
||||
try { this._fullLoadInProgress = false; } catch(e) { /* noop */ }
|
||||
if (console && console.debug) console.debug('loadMessages completed, _fullLoadInProgress cleared');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user