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 <[email protected]>
  • Loading branch information
DorraJaouad committed Feb 28, 2024
1 parent ef9389f commit cfc6bd9
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/components/MessagesList/MessagesList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ export default {
debounceUpdateReadMarkerPosition: () => {},

debounceHandleScroll: () => {},

stopFetchingOldMessages: false,
}
},

Expand Down Expand Up @@ -268,6 +270,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,6 +692,9 @@ 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
this.loadingOldMessages = true
try {
Expand All @@ -698,13 +704,26 @@ export default {
includeLastKnown,
minimumVisible: CHAT.MINIMUM_VISIBLE,
})

} catch (exception) {
if (Axios.isCancel(exception)) {
console.debug('The request has been canceled', exception)
}
if (exception?.response?.status === 304) {
// 304 - Not modified
this.stopFetchingOldMessages = true
}
}
this.loadingOldMessages = false

if (!this.stopFetchingOldMessages) {
// Stop fetching old messages, if this is the beginning of the chat
const firstMessage = this.messagesList?.at(0)
const ChatBeginFlag = firstMessage?.messageType === 'system'
&& ['conversation_created', 'history_cleared'].includes(firstMessage.systemMessage)
if (ChatBeginFlag) {
this.stopFetchingOldMessages = true
}
}
},

/**
Expand Down

0 comments on commit cfc6bd9

Please sign in to comment.