feat: debounce the scroll check

This commit is contained in:
Shivam Mishra
2025-03-17 17:47:10 +05:30
parent 8a0dc90a29
commit d8d65a0273
@@ -30,6 +30,7 @@ import {
getReadMessages,
getUnreadMessages,
} from 'dashboard/helper/conversationHelper';
import { debounce } from '@chatwoot/utils';
// constants
import { BUS_EVENTS } from 'shared/constants/busEvents';
@@ -278,6 +279,7 @@ export default {
this.addScrollListener();
this.fetchAllAttachmentsFromCurrentChat();
this.fetchSuggestions();
this.debouncedMarkReadIfRequired = debounce(this.markReadIfRequired, 100);
},
unmounted() {
@@ -475,15 +477,18 @@ export default {
// in case the user has scrolled to the bottom manually
// we trigger the makeMessagesRead method if there are unread messages
// TODO: debounce this check to ensure this does not affect performance
if (this.isNearBottom(50) && this.unreadMessageCount !== 0) {
this.makeMessagesRead();
}
this.debouncedMarkReadIfRequired();
emitter.emit(BUS_EVENTS.ON_MESSAGE_LIST_SCROLL);
this.fetchPreviousMessages(e.target.scrollTop);
},
markReadIfRequired() {
if (this.isNearBottom(50) && this.unreadMessageCount !== 0) {
this.makeMessagesRead();
}
},
makeMessagesRead() {
this.$store.dispatch('markMessagesRead', { id: this.currentChat.id });
},