diff options
author | Vincent Petry <vincent@nextcloud.com> | 2021-06-21 09:47:38 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-21 09:47:38 +0200 |
commit | fd38439bf1d9172a33d333cd0fa860c898ac1502 (patch) | |
tree | 7a0be7d075c6c4021db08155d58dfa9a80ecff88 /src/components | |
parent | 9a7c42baf6dce5eac970b366d7fde3c1ca58f472 (diff) | |
parent | 7503ecffaff8faea7effeeb6bd1c0f343ff0d367 (diff) |
Merge pull request #5795 from nextcloud/bugfix/5764/fix-concurrent-polling-cancel
Fix concurrency when cancelling lookForNewMessages
Diffstat (limited to 'src/components')
-rw-r--r-- | src/components/MessagesList/MessagesList.vue | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/src/components/MessagesList/MessagesList.vue b/src/components/MessagesList/MessagesList.vue index 50755d2d2..0173c90b2 100644 --- a/src/components/MessagesList/MessagesList.vue +++ b/src/components/MessagesList/MessagesList.vue @@ -79,6 +79,7 @@ import debounce from 'debounce' import { EventBus } from '../../services/EventBus' import LoadingPlaceholder from '../LoadingPlaceholder' import ChevronDown from 'vue-material-design-icons/ChevronDown' +import { uniqueId } from 'lodash' export default { name: 'MessagesList', @@ -114,6 +115,8 @@ export default { data() { return { + viewId: null, + /** * When scrolling to the top of the div .scroller we start loading previous * messages. This boolean allows us to show/hide the loader. @@ -236,7 +239,7 @@ export default { }, chatIdentifier() { - return this.token + ':' + this.isParticipant + ':' + this.isInLobby + return this.token + ':' + this.isParticipant + ':' + this.isInLobby + ':' + this.viewId }, scrollToBottomAriaLabel() { @@ -259,13 +262,17 @@ export default { }, chatIdentifier: { immediate: true, - handler() { + handler(newValue, oldValue) { + if (oldValue) { + this.$store.dispatch('cancelLookForNewMessages', { requestId: oldValue }) + } this.handleStartGettingMessagesPreconditions() }, }, }, mounted() { + this.viewId = uniqueId('messagesList') this.scrollToBottom() EventBus.$on('scrollChatToBottom', this.handleScrollChatToBottomEvent) EventBus.$on('smoothScrollChatToBottom', this.smoothScrollToBottom) @@ -283,7 +290,7 @@ export default { EventBus.$off('focusMessage', this.focusMessage) EventBus.$off('routeChange', this.onRouteChange) - this.$store.dispatch('cancelLookForNewMessages') + this.$store.dispatch('cancelLookForNewMessages', { requestId: this.chatIdentifier }) this.destroying = true unsubscribe('networkOffline', this.handleNetworkOffline) @@ -465,7 +472,7 @@ export default { this.scrollToFocussedMessage() }) } else { - this.$store.dispatch('cancelLookForNewMessages') + this.$store.dispatch('cancelLookForNewMessages', { requestId: this.chatIdentifier }) } }, @@ -526,10 +533,12 @@ export default { // Make the request try { + // TODO: move polling logic to the store and also cancel timers on cancel this.pollingErrorTimeout = 1 await this.$store.dispatch('lookForNewMessages', { token: this.token, lastKnownMessageId: this.$store.getters.getLastKnownMessageId(this.token), + requestId: this.chatIdentifier, }) // Scroll to the last message if sticky @@ -827,7 +836,7 @@ export default { handleNetworkOffline() { console.debug('Canceling message request as we are offline') if (this.cancelLookForNewMessages) { - this.cancelLookForNewMessages() + this.$store.dispatch('cancelLookForNewMessages', { requestId: this.chatIdentifier }) } }, |