diff --git a/src/components/MessagesList/MessagesList.vue b/src/components/MessagesList/MessagesList.vue index 1433b32b0d5b..c41eefe1911d 100644 --- a/src/components/MessagesList/MessagesList.vue +++ b/src/components/MessagesList/MessagesList.vue @@ -169,6 +169,10 @@ export default { debounceUpdateReadMarkerPosition: () => {}, debounceHandleScroll: () => {}, + + stopFetchingOldMessages: false, + + noUpdateCounter: 0, } }, @@ -268,6 +272,7 @@ export default { token(newToken, oldToken) { // Expire older messages when navigating to another conversation this.$store.dispatch('easeMessageList', { token: oldToken }) + this.stopFetchingOldMessages = false }, messagesList: { @@ -689,7 +694,11 @@ export default { * @param {boolean} includeLastKnown Include or exclude the last known message in the response */ async getOldMessages(includeLastKnown) { + if (this.stopFetchingOldMessages) { + return + } // Make the request + const prevMessagesList = this.messagesList this.loadingOldMessages = true try { await this.$store.dispatch('fetchMessages', { @@ -705,6 +714,21 @@ export default { } } this.loadingOldMessages = false + + // check if the messages list has changed (the first one is enough) + if (prevMessagesList?.at(0) === this.messagesList?.at(0)) { + this.noUpdateCounter++ + } else { + this.noUpdateCounter = 0 + } + + const firstMessage = this.messagesList?.at(0) + const ChatBeginFlag = firstMessage?.messageType === 'system' + && ['conversation_created', 'history_cleared'].includes(firstMessage.systemMessage) + if (ChatBeginFlag || this.noUpdateCounter > 1) { + // stop fetching old messages if there are no more messages to load + this.stopFetchingOldMessages = true + } }, /**