Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ export default {
unwatchJoinedConversation = watchJoinedConversation(targetToken, () => {
stopWatchingJoinedConversation()
this._joinCallHandler({ token: targetToken })
}, { immediate: true })
})
}
},
},
Expand Down
22 changes: 11 additions & 11 deletions src/composables/useJoinedConversation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import type { MaybeRefOrGetter, WatchCallback, WatchOptions, WatchStopHandle } from 'vue'
import type { MaybeRefOrGetter, WatchCallback, WatchStopHandle } from 'vue'

import { createSharedComposable } from '@vueuse/core'
import { onBeforeMount, onBeforeUnmount, readonly, ref, toValue, watch } from 'vue'
import { createSharedComposable, whenever } from '@vueuse/core'
import { onBeforeMount, onBeforeUnmount, readonly, ref, toValue } from 'vue'
import { EventBus } from '../services/EventBus.ts'
import SessionStorage from '../services/SessionStorage.js'

Expand Down Expand Up @@ -39,24 +39,24 @@ export const useJoinedConversation = createSharedComposable(useJoinedConversatio

/**
* Watch for the current joined conversation matching the provided token.
* Fires immediately if already matching, and stops after the first match
*
* @param token token to match against the joined conversation
* @param callback callback triggered when the joined conversation matches the token
* @param options watch options
*/
export function watchJoinedConversation(
token: MaybeRefOrGetter<string | null>,
callback: WatchCallback<string, string | null | undefined>,
options?: WatchOptions,
callback: WatchCallback<string, string | undefined>,
): WatchStopHandle {
const currentJoinedConversation = useJoinedConversation()

return watch(currentJoinedConversation, (newToken, oldToken, onCleanup) => {
// Getter resolves to the matching token / undefined
// `whenever()` only invokes the callback and stops watching on a truthy value.
return whenever<string | undefined>(() => {
const targetToken = toValue(token)
if (!targetToken || newToken !== targetToken) {
if (!targetToken || currentJoinedConversation.value !== targetToken) {
return
}

callback(newToken, oldToken, onCleanup)
}, options)
return targetToken
}, callback, { immediate: true, once: true })
}
2 changes: 1 addition & 1 deletion src/views/MainView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ function handleDirectCall(routeToken: string) {
unwatchJoinedConversation = watchJoinedConversation(routeToken, () => {
stopWatchingJoinedConversation()
void joinCall(routeToken, { directCall: true })
}, { immediate: true })
})
}
</script>

Expand Down
Loading