@@ -29,6 +29,13 @@ function environmentSupportsSnooze(environmentId: EnvironmentThreadShell["enviro
2929 ) ;
3030}
3131
32+ function environmentSupportsPinning ( environmentId : EnvironmentThreadShell [ "environmentId" ] ) {
33+ return (
34+ appAtomRegistry . get ( environmentServerConfigsAtom ) . get ( environmentId ) ?. environment . capabilities
35+ . threadPinning === true
36+ ) ;
37+ }
38+
3239type ThreadListAction = "archive" | "unarchive" | "delete" | "settle" | "unsettle" ;
3340
3441const ACTION_VERBS : Record < ThreadListAction , string > = {
@@ -202,10 +209,14 @@ export function useThreadListActions(): {
202209 readonly snoozeThread : ( thread : EnvironmentThreadShell , snoozedUntil : string ) => Promise < boolean > ;
203210 readonly unsnoozeThread : ( thread : EnvironmentThreadShell ) => Promise < boolean > ;
204211 readonly unsettleThread : ( thread : EnvironmentThreadShell ) => Promise < boolean > ;
212+ readonly pinThread : ( thread : EnvironmentThreadShell ) => Promise < boolean > ;
213+ readonly unpinThread : ( thread : EnvironmentThreadShell ) => Promise < boolean > ;
205214} {
206215 const executeAction = useThreadActionExecutor ( ) ;
207216 const snoozeMutation = useAtomCommand ( threadEnvironment . snooze , { reportFailure : false } ) ;
208217 const unsnoozeMutation = useAtomCommand ( threadEnvironment . unsnooze , { reportFailure : false } ) ;
218+ const pinMutation = useAtomCommand ( threadEnvironment . pin , { reportFailure : false } ) ;
219+ const unpinMutation = useAtomCommand ( threadEnvironment . unpin , { reportFailure : false } ) ;
209220 const snoozeInFlightThreadKeys = useRef ( new Set < string > ( ) ) ;
210221
211222 const archiveThread = useCallback (
@@ -310,6 +321,62 @@ export function useThreadListActions(): {
310321 async ( thread : EnvironmentThreadShell ) => ( await executeAction ( "unsettle" , thread ) ) === true ,
311322 [ executeAction ] ,
312323 ) ;
324+ const pinThread = useCallback (
325+ async ( thread : EnvironmentThreadShell ) => {
326+ if ( ! environmentSupportsPinning ( thread . environmentId ) ) {
327+ Alert . alert (
328+ "Could not pin thread" ,
329+ "This environment's server does not support pinning yet. Update the server to use Pin." ,
330+ ) ;
331+ return false ;
332+ }
333+ selectionHaptic ( ) ;
334+ const result = await pinMutation ( {
335+ environmentId : thread . environmentId ,
336+ input : { threadId : thread . id } ,
337+ } ) ;
338+ if ( result . _tag === "Failure" ) {
339+ const error = Cause . squash ( result . cause ) ;
340+ Alert . alert (
341+ "Could not pin thread" ,
342+ error instanceof Error && error . message . trim ( ) . length > 0
343+ ? error . message
344+ : "The thread could not be pinned." ,
345+ ) ;
346+ return false ;
347+ }
348+ return true ;
349+ } ,
350+ [ pinMutation ] ,
351+ ) ;
352+ const unpinThread = useCallback (
353+ async ( thread : EnvironmentThreadShell ) => {
354+ if ( ! environmentSupportsPinning ( thread . environmentId ) ) {
355+ Alert . alert (
356+ "Could not unpin thread" ,
357+ "This environment's server does not support pinning yet. Update the server to use Pin." ,
358+ ) ;
359+ return false ;
360+ }
361+ selectionHaptic ( ) ;
362+ const result = await unpinMutation ( {
363+ environmentId : thread . environmentId ,
364+ input : { threadId : thread . id } ,
365+ } ) ;
366+ if ( result . _tag === "Failure" ) {
367+ const error = Cause . squash ( result . cause ) ;
368+ Alert . alert (
369+ "Could not unpin thread" ,
370+ error instanceof Error && error . message . trim ( ) . length > 0
371+ ? error . message
372+ : "The thread could not be unpinned." ,
373+ ) ;
374+ return false ;
375+ }
376+ return true ;
377+ } ,
378+ [ unpinMutation ] ,
379+ ) ;
313380
314381 const confirmDeleteThread = useConfirmDeleteThread ( executeAction ) ;
315382
@@ -320,6 +387,8 @@ export function useThreadListActions(): {
320387 snoozeThread,
321388 unsnoozeThread,
322389 unsettleThread,
390+ pinThread,
391+ unpinThread,
323392 } ;
324393}
325394
0 commit comments