@@ -11,7 +11,7 @@ import type {Timezone} from '@src/types/onyx/PersonalDetails';
1111import { addComment , buildOptimisticResolvedFollowups } from '.' ;
1212
1313/** Delay before showing pre-generated Concierge response (in milliseconds) */
14- const CONCIERGE_RESPONSE_DELAY_MS = 1500 ;
14+ const CONCIERGE_RESPONSE_DELAY_MS = 4000 ;
1515
1616/**
1717 * Resolves a suggested followup by posting the selected question as a comment
@@ -89,22 +89,73 @@ function resolveSuggestedFollowup(
8989 addOptimisticConciergeActionWithDelay ( reportID , optimisticConciergeAction ) ;
9090}
9191
92+ /**
93+ * Queues an optimistic concierge response for delayed display.
94+ * Writes action to Onyx — the usePendingConciergeResponse hook
95+ * handles the actual delay and moves the action to REPORT_ACTIONS
96+ * when the time arrives, with proper lifecycle cleanup.
97+ */
9298function addOptimisticConciergeActionWithDelay ( reportID : string , optimisticConciergeAction : OptimisticReportAction ) {
93- // Show "Concierge is typing..." indicator
94- Onyx . merge ( `${ ONYXKEYS . COLLECTION . REPORT_USER_IS_TYPING } ${ reportID } ` , {
95- [ CONST . ACCOUNT_ID . CONCIERGE ] : true ,
96- } ) ;
99+ Onyx . update ( [
100+ // Store the pending response for the scheduler to process
101+ {
102+ onyxMethod : Onyx . METHOD . SET ,
103+ key : `${ ONYXKEYS . COLLECTION . PENDING_CONCIERGE_RESPONSE } ${ reportID } ` ,
104+ value : {
105+ reportAction : optimisticConciergeAction . reportAction ,
106+ displayAfter : Date . now ( ) + CONCIERGE_RESPONSE_DELAY_MS ,
107+ } ,
108+ } ,
109+ // Show "Concierge is typing..." indicator
110+ {
111+ onyxMethod : Onyx . METHOD . MERGE ,
112+ key : `${ ONYXKEYS . COLLECTION . REPORT_USER_IS_TYPING } ${ reportID } ` ,
113+ value : { [ CONST . ACCOUNT_ID . CONCIERGE ] : true } ,
114+ } ,
115+ ] ) ;
116+ }
97117
98- setTimeout ( ( ) => {
99- // Clear the typing indicator
100- Onyx . merge ( `${ ONYXKEYS . COLLECTION . REPORT_USER_IS_TYPING } ${ reportID } ` , {
101- [ CONST . ACCOUNT_ID . CONCIERGE ] : false ,
102- } ) ;
118+ /**
119+ * Discards a stale pending concierge response and clears the typing indicator.
120+ * Called when the response has been pending too long (e.g. app was killed and restarted).
121+ */
122+ function discardPendingConciergeAction ( reportID : string ) {
123+ Onyx . update ( [
124+ {
125+ onyxMethod : Onyx . METHOD . SET ,
126+ key : `${ ONYXKEYS . COLLECTION . PENDING_CONCIERGE_RESPONSE } ${ reportID } ` ,
127+ value : null ,
128+ } ,
129+ {
130+ onyxMethod : Onyx . METHOD . MERGE ,
131+ key : `${ ONYXKEYS . COLLECTION . REPORT_USER_IS_TYPING } ${ reportID } ` ,
132+ value : { [ CONST . ACCOUNT_ID . CONCIERGE ] : false } ,
133+ } ,
134+ ] ) ;
135+ }
103136
104- Onyx . merge ( `${ ONYXKEYS . COLLECTION . REPORT_ACTIONS } ${ reportID } ` , {
105- [ optimisticConciergeAction . reportAction . reportActionID ] : optimisticConciergeAction . reportAction ,
106- } ) ;
107- } , CONCIERGE_RESPONSE_DELAY_MS ) ;
137+ /**
138+ * Applies a pending concierge response by moving it to REPORT_ACTIONS
139+ * and clearing the pending state and typing indicator.
140+ */
141+ function applyPendingConciergeAction ( reportID : string , reportAction : ReportAction ) {
142+ Onyx . update ( [
143+ {
144+ onyxMethod : Onyx . METHOD . SET ,
145+ key : `${ ONYXKEYS . COLLECTION . PENDING_CONCIERGE_RESPONSE } ${ reportID } ` ,
146+ value : null ,
147+ } ,
148+ {
149+ onyxMethod : Onyx . METHOD . MERGE ,
150+ key : `${ ONYXKEYS . COLLECTION . REPORT_USER_IS_TYPING } ${ reportID } ` ,
151+ value : { [ CONST . ACCOUNT_ID . CONCIERGE ] : false } ,
152+ } ,
153+ {
154+ onyxMethod : Onyx . METHOD . MERGE ,
155+ key : `${ ONYXKEYS . COLLECTION . REPORT_ACTIONS } ${ reportID } ` ,
156+ value : { [ reportAction . reportActionID ] : reportAction } ,
157+ } ,
158+ ] ) ;
108159}
109160
110- export { resolveSuggestedFollowup , CONCIERGE_RESPONSE_DELAY_MS } ;
161+ export { resolveSuggestedFollowup , discardPendingConciergeAction , applyPendingConciergeAction , CONCIERGE_RESPONSE_DELAY_MS } ;
0 commit comments