@@ -40,6 +40,23 @@ export function useSetter<
4040 } , [ setter , box , value ] ) ;
4141}
4242
43+ /**
44+ * Calls method `setter` on `box` with the arguments `args`, iff `args` is set &
45+ * deeply different from before (and the box is alive)
46+ */
47+ export function useSpreadSetter <
48+ V extends any [ ] ,
49+ S extends string ,
50+ T extends TalkObject & Record < S , ( ...args : V ) => any > ,
51+ > ( box : T | undefined , args : V | undefined , setter : S ) {
52+ args = usePreviousIfDeeplyEqual ( args ) ;
53+ useEffect ( ( ) => {
54+ if ( args !== undefined && box ?. isAlive ) {
55+ box [ setter ] ( ...args ) ;
56+ }
57+ } , [ setter , box , args ] ) ;
58+ }
59+
4360/**
4461 * Calls `box.select` with either `syncConversation` or `conversationId`
4562 * depending on which is set. If neither is set, which is valid for the Inbox,
@@ -50,14 +67,20 @@ export function useConversation<T extends Talk.UIBox>(
5067 box : T | undefined ,
5168 syncConversation : ConversationProps [ "syncConversation" ] ,
5269 conversationId : ConversationProps [ "conversationId" ] ,
70+ asGuest : boolean | undefined ,
5371) {
5472 const conversation = useMemo ( ( ) => {
5573 if ( typeof syncConversation === "function" ) {
5674 return session ?. isAlive ? syncConversation ( session ) : undefined ;
5775 }
5876 return syncConversation ?? conversationId ;
5977 } , [ session , syncConversation , conversationId ] ) ;
60- useSetter ( box , conversation , "select" ) ;
78+
79+ const args = (
80+ conversation !== undefined ? [ conversation , { asGuest } ] : [ ]
81+ ) as any ;
82+
83+ useSpreadSetter ( box , args , "select" ) ;
6184}
6285
6386// subset of Session to help TypeScript pick the right overloads
0 commit comments