Skip to content

Commit 9237bdb

Browse files
Antreesybackportbot[bot]
authored andcommitted
fix(call): stop conversation-joined watcher on immediate match
- switch to @vueuse library implementation of whenever - immediate + once matches how we use it - whenever stops the watcher on immediate match, resolving the stray watcher issue Assisted-by: ClaudeCode:claude-sonnet-5 Signed-off-by: Maksim Sukharev <antreesy.web@gmail.com>
1 parent 4327828 commit 9237bdb

3 files changed

Lines changed: 13 additions & 13 deletions

File tree

src/App.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ export default {
615615
unwatchJoinedConversation = watchJoinedConversation(targetToken, () => {
616616
stopWatchingJoinedConversation()
617617
this._joinCallHandler({ token: targetToken })
618-
}, { immediate: true })
618+
})
619619
}
620620
},
621621
},

src/composables/useJoinedConversation.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
* SPDX-License-Identifier: AGPL-3.0-or-later
44
*/
55

6-
import type { MaybeRefOrGetter, WatchCallback, WatchOptions, WatchStopHandle } from 'vue'
6+
import type { MaybeRefOrGetter, WatchCallback, WatchStopHandle } from 'vue'
77

8-
import { createSharedComposable } from '@vueuse/core'
9-
import { onBeforeMount, onBeforeUnmount, readonly, ref, toValue, watch } from 'vue'
8+
import { createSharedComposable, whenever } from '@vueuse/core'
9+
import { onBeforeMount, onBeforeUnmount, readonly, ref, toValue } from 'vue'
1010
import { EventBus } from '../services/EventBus.ts'
1111
import SessionStorage from '../services/SessionStorage.js'
1212

@@ -39,24 +39,24 @@ export const useJoinedConversation = createSharedComposable(useJoinedConversatio
3939

4040
/**
4141
* Watch for the current joined conversation matching the provided token.
42+
* Fires immediately if already matching, and stops after the first match
4243
*
4344
* @param token token to match against the joined conversation
4445
* @param callback callback triggered when the joined conversation matches the token
45-
* @param options watch options
4646
*/
4747
export function watchJoinedConversation(
4848
token: MaybeRefOrGetter<string | null>,
49-
callback: WatchCallback<string, string | null | undefined>,
50-
options?: WatchOptions,
49+
callback: WatchCallback<string, string | undefined>,
5150
): WatchStopHandle {
5251
const currentJoinedConversation = useJoinedConversation()
5352

54-
return watch(currentJoinedConversation, (newToken, oldToken, onCleanup) => {
53+
// Getter resolves to the matching token / undefined
54+
// `whenever()` only invokes the callback and stops watching on a truthy value.
55+
return whenever<string | undefined>(() => {
5556
const targetToken = toValue(token)
56-
if (!targetToken || newToken !== targetToken) {
57+
if (!targetToken || currentJoinedConversation.value !== targetToken) {
5758
return
5859
}
59-
60-
callback(newToken, oldToken, onCleanup)
61-
}, options)
60+
return targetToken
61+
}, callback, { immediate: true, once: true })
6262
}

src/views/MainView.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ function handleDirectCall(routeToken: string) {
125125
unwatchJoinedConversation = watchJoinedConversation(routeToken, () => {
126126
stopWatchingJoinedConversation()
127127
void joinCall(routeToken, { directCall: true })
128-
}, { immediate: true })
128+
})
129129
}
130130
</script>
131131

0 commit comments

Comments
 (0)