@@ -4,7 +4,6 @@ import type {AppStateStatus} from 'react-native';
44import { AppState } from 'react-native' ;
55import type { OnyxCollection , OnyxEntry , OnyxUpdate } from 'react-native-onyx' ;
66import Onyx from 'react-native-onyx' ;
7- import type { ValueOf } from 'type-fest' ;
87import { importEmojiLocale } from '@assets/emojis' ;
98import * as API from '@libs/API' ;
109import type { GetMissingOnyxMessagesParams , HandleRestrictedEventParams , OpenAppParams , OpenOldDotLinkParams , ReconnectAppParams , UpdatePreferredLocaleParams } from '@libs/API/parameters' ;
@@ -76,19 +75,6 @@ Onyx.connect({
7675 } ,
7776} ) ;
7877
79- let priorityMode : ValueOf < typeof CONST . PRIORITY_MODE > | undefined ;
80- Onyx . connect ( {
81- key : ONYXKEYS . NVP_PRIORITY_MODE ,
82- callback : ( nextPriorityMode ) => {
83- // When someone switches their priority mode we need to fetch all their chats because only #focus mode works with a subset of a user's chats. This is only possible via the OpenApp command.
84- if ( nextPriorityMode === CONST . PRIORITY_MODE . DEFAULT && priorityMode === CONST . PRIORITY_MODE . GSD ) {
85- // eslint-disable-next-line @typescript-eslint/no-use-before-define
86- openApp ( ) ;
87- }
88- priorityMode = nextPriorityMode ;
89- } ,
90- } ) ;
91-
9278let isUsingImportedState : boolean | undefined ;
9379Onyx . connect ( {
9480 key : ONYXKEYS . IS_USING_IMPORTED_STATE ,
@@ -259,7 +245,12 @@ function getPolicyParamsForOpenOrReconnect(): Promise<PolicyParamsForOpenOrRecon
259245/**
260246 * Returns the Onyx data that is used for both the OpenApp and ReconnectApp API commands.
261247 */
262- function getOnyxDataForOpenOrReconnect ( isOpenApp = false , isFullReconnect = false , shouldKeepPublicRooms = false ) : OnyxData {
248+ function getOnyxDataForOpenOrReconnect (
249+ isOpenApp = false ,
250+ isFullReconnect = false ,
251+ shouldKeepPublicRooms = false ,
252+ allReportsWithDraftComments ?: Record < string , string | undefined > ,
253+ ) : OnyxData {
263254 const result : OnyxData = {
264255 optimisticData : [
265256 {
@@ -320,16 +311,33 @@ function getOnyxDataForOpenOrReconnect(isOpenApp = false, isFullReconnect = fals
320311 } ) ;
321312 }
322313
314+ // Find all reports that have a non-null draft comment and map them to their corresponding report objects from allReports
315+ // This ensures that any report with a draft comment is preserved in Onyx even if it doesn’t contain chat history
316+ const reportsWithDraftComments = Object . entries ( allReportsWithDraftComments ?? { } )
317+ . filter ( ( [ , value ] ) => value !== null )
318+ . map ( ( [ key ] ) => key . replace ( ONYXKEYS . COLLECTION . REPORT_DRAFT_COMMENT , '' ) )
319+ . map ( ( reportID ) => allReports ?. [ `${ ONYXKEYS . COLLECTION . REPORT } ${ reportID } ` ] ) ;
320+
321+ reportsWithDraftComments ?. forEach ( ( report ) => {
322+ result . successData ?. push ( {
323+ onyxMethod : Onyx . METHOD . MERGE ,
324+ key : `${ ONYXKEYS . COLLECTION . REPORT } ${ report ?. reportID } ` ,
325+ value : {
326+ ...report ,
327+ } ,
328+ } ) ;
329+ } ) ;
330+
323331 return result ;
324332}
325333
326334/**
327335 * Fetches data needed for app initialization
328336 */
329- function openApp ( shouldKeepPublicRooms = false ) {
337+ function openApp ( shouldKeepPublicRooms = false , allReportsWithDraftComments ?: Record < string , string | undefined > ) {
330338 return getPolicyParamsForOpenOrReconnect ( ) . then ( ( policyParams : PolicyParamsForOpenOrReconnect ) => {
331339 const params : OpenAppParams = { enablePriorityModeFilter : true , ...policyParams } ;
332- return API . writeWithNoDuplicatesConflictAction ( WRITE_COMMANDS . OPEN_APP , params , getOnyxDataForOpenOrReconnect ( true , undefined , shouldKeepPublicRooms ) ) ;
340+ return API . writeWithNoDuplicatesConflictAction ( WRITE_COMMANDS . OPEN_APP , params , getOnyxDataForOpenOrReconnect ( true , undefined , shouldKeepPublicRooms , allReportsWithDraftComments ) ) ;
333341 } ) ;
334342}
335343
0 commit comments