diff options
author | Marco Ambrosini <marcoambrosini@pm.me> | 2020-01-31 16:20:59 +0100 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2020-02-24 14:54:54 +0100 |
commit | 2c6e88cfd52a79d3fb8ba657dd5940cdfbd21be9 (patch) | |
tree | ddc2920dfe75fba09442a1c6d4c3c00734aa9336 /src/components/RightSidebar/Participants/ParticipantsTab.vue | |
parent | 46482e40fa0de0ed7177d5f29bacef3d748e6a16 (diff) |
Cancel getparticipants requests once changing conversation
Signed-off-by: Marco Ambrosini <marcoambrosini@pm.me>
Diffstat (limited to 'src/components/RightSidebar/Participants/ParticipantsTab.vue')
-rw-r--r-- | src/components/RightSidebar/Participants/ParticipantsTab.vue | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/src/components/RightSidebar/Participants/ParticipantsTab.vue b/src/components/RightSidebar/Participants/ParticipantsTab.vue index f461b4b2b..0eb50c8ee 100644 --- a/src/components/RightSidebar/Participants/ParticipantsTab.vue +++ b/src/components/RightSidebar/Participants/ParticipantsTab.vue @@ -91,6 +91,7 @@ import isInLobby from '../../../mixins/isInLobby' import { loadState } from '@nextcloud/initial-state' import SHA1 from 'crypto-js/sha1' import Hex from 'crypto-js/enc-hex' +import CancelableRequest from '../../../utils/cancelableRequest' export default { name: 'ParticipantsTab', @@ -120,6 +121,10 @@ export default { contactsLoading: false, participantsInitialised: false, isCirclesEnabled: loadState('talk', 'circles_enabled'), + /** + * Stores the cancel function for cancelableGetParticipants + */ + cancelGetParticipants: () => {}, } }, @@ -230,13 +235,13 @@ export default { // FIXME this works only temporary until signaling is fixed to be only on the calls // Then we have to search for another solution. Maybe the room list which we update // periodically gets a hash of all online sessions? - EventBus.$on('Signaling::participantListChanged', this.getParticipants) + EventBus.$on('Signaling::participantListChanged', this.cancelableGetParticipnts) }, beforeDestroy() { EventBus.$off('routeChange', this.onRouteChange) EventBus.$off('joinedConversation', this.onJoinedConversation) - EventBus.$off('Signaling::participantListChanged', this.getParticipants) + EventBus.$off('Signaling::participantListChanged', this.cancelableGetParticipnts) }, methods: { @@ -254,7 +259,7 @@ export default { */ onJoinedConversation() { this.$nextTick(() => { - this.getParticipants() + this.cancelableGetParticipnts() }) }, @@ -277,7 +282,7 @@ export default { try { const response = await searchPossibleConversations(this.searchText, this.token) this.searchResults = response.data.ocs.data - this.getParticipants() + this.cancelableGetParticipnts() this.contactsLoading = false } catch (exception) { console.error(exception) @@ -295,13 +300,13 @@ export default { try { await addParticipant(this.token, item.id, item.source) this.searchText = '' - this.getParticipants() + this.cancelableGetParticipnts() } catch (exception) { console.debug(exception) } }, - async getParticipants() { + async cancelableGetParticipnts() { if (this.token === '' || this.isInLobby) { return } @@ -310,7 +315,12 @@ export default { // The token must be stored in a local variable to ensure that // the same token is used after waiting. const token = this.token - const participants = await fetchParticipants(token) + // Clear previous requests if there's one pending + this.cancelGetParticipants('Cancel get participants') + // Get a new cancelable request function and cancel function pair + const { request, cancel } = CancelableRequest(fetchParticipants) + this.cancelGetParticipants = cancel + const participants = await request(token) this.$store.dispatch('purgeParticipantsStore', token) participants.data.ocs.data.forEach(participant => { this.$store.dispatch('addParticipant', { |