Skip to content

Commit

Permalink
Make listeners exclusive to TopBar only
Browse files Browse the repository at this point in the history
Signed-off-by: DorraJaouad <[email protected]>
  • Loading branch information
DorraJaouad committed Jan 6, 2024
1 parent d55ce12 commit 5154841
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 20 deletions.
7 changes: 1 addition & 6 deletions src/components/RightSidebar/Participants/ParticipantsTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,13 @@ export default {
const {
participantsInitialised,
cancelableGetParticipants,
initialiseGetParticipants,
} = useGetParticipants(isActive)
} = useGetParticipants(isActive, false)

return {
sortParticipants,
isInCall,
participantsInitialised,
cancelableGetParticipants,
initialiseGetParticipants,
}
},

Expand Down Expand Up @@ -206,9 +204,6 @@ export default {
beforeMount() {
EventBus.$on('route-change', this.abortSearch)
subscribe('user_status:status.updated', this.updateUserStatus)

// Initialises the get participants composable
this.initialiseGetParticipants()
},

beforeDestroy() {
Expand Down
25 changes: 11 additions & 14 deletions src/composables/useGetParticipants.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*
*/
import debounce from 'debounce'
import { ref, nextTick, computed, watch, onBeforeUnmount } from 'vue'
import { ref, nextTick, computed, watch, onBeforeUnmount, onMounted } from 'vue'

import { subscribe, unsubscribe } from '@nextcloud/event-bus'

Expand All @@ -32,8 +32,9 @@ import { EventBus } from '../services/EventBus.js'

/**
* @param {import('vue').Ref} isActive whether the participants tab is active
* @param {Boolean} isTopBar whether the component is the top bar

Check warning on line 35 in src/composables/useGetParticipants.js

View workflow job for this annotation

GitHub Actions / NPM lint

Invalid JSDoc @param "isTopBar" type "Boolean"; prefer: "boolean"
*/
export function useGetParticipants(isActive = ref(true)) {
export function useGetParticipants(isActive = ref(true), isTopBar = true) {

// Encapsulation
const store = useStore()
Expand All @@ -48,7 +49,7 @@ export function useGetParticipants(isActive = ref(true)) {
const participantsInitialised = ref(false)

/**
* Initialise the get participants functionality
* Initialise the get participants listeners
*
*/
function initialiseGetParticipants() {
Expand All @@ -63,7 +64,7 @@ export function useGetParticipants(isActive = ref(true)) {
}

/**
* Stop the get participants functionality
* Stop the get participants listeners
*
*/
function stopGetParticipants() {
Expand Down Expand Up @@ -123,30 +124,26 @@ export function useGetParticipants(isActive = ref(true)) {
const debounceSlowUpdateParticipants = debounce(
cancelableGetParticipants, 15000)

// Group conversations have composable in RightSidebar, so should work only for one-to-one
watch(isOneToOneConversation, (newValue) => {
if (newValue) {
onMounted(() => {
if (isTopBar) {
initialiseGetParticipants()
} else {
stopGetParticipants()
}
}, { immediate: true })
})

watch(isActive, (newValue) => {
if (newValue && pendingChanges) {
debounceUpdateParticipants()
}
})

onBeforeUnmount(
() => {
onBeforeUnmount(() => {
if (isTopBar) {
stopGetParticipants()
}
)
})

return {
participantsInitialised,
initialiseGetParticipants,
cancelableGetParticipants,
}
}

0 comments on commit 5154841

Please sign in to comment.