Skip to content

Commit

Permalink
Merge pull request #11097 from nextcloud/backport/11064/stable28
Browse files Browse the repository at this point in the history
[stable28] fix(participants): cancel scheduled request when requesting new one
  • Loading branch information
Antreesy authored Dec 3, 2023
2 parents 078d707 + 055d3bc commit 8d5c737
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions src/mixins/getParticipants.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ const getParticipants = {
participantsInitialised: false,
fetchingParticipants: false,
pendingChanges: false,
debounceFastUpdateParticipants: null,
debounceSlowUpdateParticipants: null,
}
},

Expand All @@ -45,6 +47,16 @@ const getParticipants = {
},
},

created() {
this.debounceFastUpdateParticipants = debounce(function() {
this.cancelableGetParticipants()
}, 3000)

this.debounceSlowUpdateParticipants = debounce(function() {
this.cancelableGetParticipants()
}, 15000)
},

methods: {
initialiseGetParticipantsMixin() {
EventBus.$on('route-change', this.onRouteChange)
Expand Down Expand Up @@ -96,25 +108,17 @@ const getParticipants = {
this.pendingChanges = false
},

debounceSlowUpdateParticipants: debounce(function() {
if (!this.fetchingParticipants) {
this.cancelableGetParticipants()
}
}, 15000),

debounceFastUpdateParticipants: debounce(function() {
if (!this.fetchingParticipants) {
this.cancelableGetParticipants()
}
}, 3000),

async cancelableGetParticipants() {
if (this.token === '' || this.isInLobby || !this.isModeratorOrUser) {
if (this.fetchingParticipants || this.token === '' || this.isInLobby || !this.isModeratorOrUser) {
return
}

this.fetchingParticipants = true

// Clear previously requested updates
this.debounceFastUpdateParticipants.clear()
this.debounceSlowUpdateParticipants.clear()

const response = await this.$store.dispatch('fetchParticipants', { token: this.token })
if (response) {
this.participantsInitialised = true
Expand Down

0 comments on commit 8d5c737

Please sign in to comment.