Skip to content

Commit 2c6e88c

Browse files
marcoambrosininickvergessen
authored andcommitted
Cancel getparticipants requests once changing conversation
Signed-off-by: Marco Ambrosini <marcoambrosini@pm.me>
1 parent 46482e4 commit 2c6e88c

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

src/components/RightSidebar/Participants/ParticipantsTab.vue

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ import isInLobby from '../../../mixins/isInLobby'
9191
import { loadState } from '@nextcloud/initial-state'
9292
import SHA1 from 'crypto-js/sha1'
9393
import Hex from 'crypto-js/enc-hex'
94+
import CancelableRequest from '../../../utils/cancelableRequest'
9495
9596
export default {
9697
name: 'ParticipantsTab',
@@ -120,6 +121,10 @@ export default {
120121
contactsLoading: false,
121122
participantsInitialised: false,
122123
isCirclesEnabled: loadState('talk', 'circles_enabled'),
124+
/**
125+
* Stores the cancel function for cancelableGetParticipants
126+
*/
127+
cancelGetParticipants: () => {},
123128
}
124129
},
125130
@@ -230,13 +235,13 @@ export default {
230235
// FIXME this works only temporary until signaling is fixed to be only on the calls
231236
// Then we have to search for another solution. Maybe the room list which we update
232237
// periodically gets a hash of all online sessions?
233-
EventBus.$on('Signaling::participantListChanged', this.getParticipants)
238+
EventBus.$on('Signaling::participantListChanged', this.cancelableGetParticipnts)
234239
},
235240
236241
beforeDestroy() {
237242
EventBus.$off('routeChange', this.onRouteChange)
238243
EventBus.$off('joinedConversation', this.onJoinedConversation)
239-
EventBus.$off('Signaling::participantListChanged', this.getParticipants)
244+
EventBus.$off('Signaling::participantListChanged', this.cancelableGetParticipnts)
240245
},
241246
242247
methods: {
@@ -254,7 +259,7 @@ export default {
254259
*/
255260
onJoinedConversation() {
256261
this.$nextTick(() => {
257-
this.getParticipants()
262+
this.cancelableGetParticipnts()
258263
})
259264
},
260265
@@ -277,7 +282,7 @@ export default {
277282
try {
278283
const response = await searchPossibleConversations(this.searchText, this.token)
279284
this.searchResults = response.data.ocs.data
280-
this.getParticipants()
285+
this.cancelableGetParticipnts()
281286
this.contactsLoading = false
282287
} catch (exception) {
283288
console.error(exception)
@@ -295,13 +300,13 @@ export default {
295300
try {
296301
await addParticipant(this.token, item.id, item.source)
297302
this.searchText = ''
298-
this.getParticipants()
303+
this.cancelableGetParticipnts()
299304
} catch (exception) {
300305
console.debug(exception)
301306
}
302307
},
303308
304-
async getParticipants() {
309+
async cancelableGetParticipnts() {
305310
if (this.token === '' || this.isInLobby) {
306311
return
307312
}
@@ -310,7 +315,12 @@ export default {
310315
// The token must be stored in a local variable to ensure that
311316
// the same token is used after waiting.
312317
const token = this.token
313-
const participants = await fetchParticipants(token)
318+
// Clear previous requests if there's one pending
319+
this.cancelGetParticipants('Cancel get participants')
320+
// Get a new cancelable request function and cancel function pair
321+
const { request, cancel } = CancelableRequest(fetchParticipants)
322+
this.cancelGetParticipants = cancel
323+
const participants = await request(token)
314324
this.$store.dispatch('purgeParticipantsStore', token)
315325
participants.data.ocs.data.forEach(participant => {
316326
this.$store.dispatch('addParticipant', {

src/services/participantsService.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ const demoteFromModerator = async(token, options) => {
137137
return response
138138
}
139139

140-
const fetchParticipants = async(token) => {
141-
const response = await axios.get(generateOcsUrl('apps/spreed/api/v1/room', 2) + token + '/participants')
140+
const fetchParticipants = async(token, options) => {
141+
const response = await axios.get(generateOcsUrl('apps/spreed/api/v1/room', 2) + token + '/participants', options)
142142
return response
143143
}
144144

0 commit comments

Comments
 (0)