This commit is contained in:
Lizandro Guarnizo
2026-01-26 23:28:13 -05:00
parent 437a99dbcf
commit a086e4a19a
+23 -5
View File
@@ -1021,6 +1021,8 @@
// Suspend periodic refresh while media playback or recording is active
this._suspendAutoRefresh = false;
this._pendingReloadAfterMedia = false;
// Flag to request a reload after user stops scrolling
this._pendingReloadAfterScroll = false;
// Removed: automatic "Nuevos mensajes" indicator — we always reload full conversation now
// this._lastRenderMessageCount = 0;
@@ -1841,12 +1843,18 @@
setInterval(() => {
if (this.currentUserId) {
try {
if (this._userScrolling) {
console.debug('Periodic load skipped: user is scrolling; scheduling reload after inactivity');
this._pendingReloadAfterScroll = true;
return;
}
if (typeof this.isMediaActive === 'function' && this.isMediaActive()) {
console.debug('Periodic load skipped: media active or recording in progress; scheduling reload after media ends');
this._pendingReloadAfterMedia = true;
return;
}
} catch (e) { console.warn('isMediaActive check failed', e); }
} catch (e) { console.warn('Periodic checks failed', e); }
// full reload forces scroll-to-bottom
this.loadMessages(this.currentUserId, true).catch(err => console.warn('Periodic loadMessages failed', err));
}
@@ -2440,7 +2448,14 @@
try {
this._userScrolling = true;
if (this._userScrollTimer) clearTimeout(this._userScrollTimer);
this._userScrollTimer = setTimeout(() => { this._userScrolling = false; this._userScrollTimer = null; }, 1500);
this._userScrollTimer = setTimeout(() => {
this._userScrolling = false;
this._userScrollTimer = null;
if (this._pendingReloadAfterScroll && this.currentUserId) {
this._pendingReloadAfterScroll = false;
try { this.loadMessages(this.currentUserId, true).catch(e => console.warn('reload after scroll failed', e)); } catch(e) { console.warn('reload after scroll schedule failed', e); }
}
}, 1500);
} catch(e) { /* ignore */ }
if (chatContainer.scrollTop <= 60 && this.hasMoreMessages && !this.loadingMessages && this.currentUserId == userId) {
@@ -3280,8 +3295,9 @@
// Resume auto-refresh and trigger a reload if one was pending
try {
this._suspendAutoRefresh = false;
if (this._pendingReloadAfterMedia && this.currentUserId) {
if ((this._pendingReloadAfterMedia || this._pendingReloadAfterScroll) && this.currentUserId) {
this._pendingReloadAfterMedia = false;
this._pendingReloadAfterScroll = false;
await this.loadMessages(this.currentUserId, true);
}
} catch (e) { console.warn('Failed to resume reload after recording', e); }
@@ -3328,8 +3344,9 @@
// Ensure we resume periodic reloads and trigger pending reload
try {
this._suspendAutoRefresh = false;
if (this._pendingReloadAfterMedia && this.currentUserId) {
if ((this._pendingReloadAfterMedia || this._pendingReloadAfterScroll) && this.currentUserId) {
this._pendingReloadAfterMedia = false;
this._pendingReloadAfterScroll = false;
this.loadMessages(this.currentUserId, true).catch(e => console.warn('Reload after stopRecording failed', e));
}
} catch (e) { console.warn('stopRecording resume failed', e); }
@@ -3358,8 +3375,9 @@
// Resume auto-refresh if it was suspended and trigger pending reload
try {
this._suspendAutoRefresh = false;
if (this._pendingReloadAfterMedia && this.currentUserId) {
if ((this._pendingReloadAfterMedia || this._pendingReloadAfterScroll) && this.currentUserId) {
this._pendingReloadAfterMedia = false;
this._pendingReloadAfterScroll = false;
this.loadMessages(this.currentUserId, true).catch(e => console.warn('Reload after cancelRecording failed', e));
}
} catch (e) { console.warn('cancelRecording resume failed', e); }