From a086e4a19aa32e0604adb8c808584dab5046e31a Mon Sep 17 00:00:00 2001 From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com> Date: Mon, 26 Jan 2026 23:28:13 -0500 Subject: [PATCH] scroll --- conversations.php | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/conversations.php b/conversations.php index cc6a8c0..7b66089 100644 --- a/conversations.php +++ b/conversations.php @@ -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); }