Skip to content
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
11 changes: 10 additions & 1 deletion src/components/MessagesList/MessagesList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ export default {
previousScrollTopValue: null,

pollingErrorTimeout: 1,

oldMessagesPromise: null,
}
},

Expand Down Expand Up @@ -429,7 +431,8 @@ export default {

// Make the request
try {
const messages = await request({ token, lastKnownMessageId, includeLastKnown: includeLastKnown ? '1' : '0' })
this.oldMessagesPromise = request({ token, lastKnownMessageId, includeLastKnown: includeLastKnown ? '1' : '0' })
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the component is reused, so you need to store this based on token?
Otherwise if you quickly change to 2 unloaded conversations the second one wouldn't load?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or more simply reset the value to null when the token changes?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you switch to another conversation the call will get cancelled anyway, so you'll then get a new request

const messages = await this.oldMessagesPromise
// Process each messages and adds it to the store
messages.data.ocs.data.forEach(message => {
if (message.actorType === 'guests') {
Expand All @@ -456,10 +459,12 @@ export default {
id: newestKnownMessageId,
})
}
this.oldMessagesPromise = null
} catch (exception) {
if (Axios.isCancel(exception)) {
console.debug('The request has been canceled', exception)
}
this.oldMessagesPromise = null
}
},

Expand Down Expand Up @@ -563,6 +568,10 @@ export default {
this.displayMessagesLoader = false
this.previousScrollTopValue = scrollTop
} else if (scrollHeight > elementHeight && scrollTop < 800 && scrollTop <= this.previousScrollTopValue) {
if (this.oldMessagesPromise) {
// already loading, don't do it twice
return
}
if (scrollTop === 0) {
this.displayMessagesLoader = true
}
Expand Down