Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(MessagesList): Stop fetching when reaching the chat beginning #11663

Merged
merged 1 commit into from
Feb 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Antreesy marked this conversation as resolved.
Show resolved Hide resolved
},

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
Loading