Skip to content

Commit

Permalink
chore(MessagesList): set a a flag to stop fetching when reaching the …
Browse files Browse the repository at this point in the history
…top of the messages list

Signed-off-by: DorraJaouad <dorra.jaoued7@gmail.com>
  • Loading branch information
DorraJaouad committed Feb 27, 2024
1 parent ef9389f commit 1abce7b
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/components/MessagesList/MessagesList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ export default {
debounceUpdateReadMarkerPosition: () => {},
debounceHandleScroll: () => {},
stopFetchingOldMessages: false,
noUpdateCounter: 0,
}
},
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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', {
Expand All @@ -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
}
},
/**
Expand Down

0 comments on commit 1abce7b

Please sign in to comment.