diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 0fe2bfbf8d47..62f0ac2805f3 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -3938,12 +3938,78 @@ function resolveActionableReportMentionWhisper( }, ]; + const successData: OnyxUpdate[] = []; + + const reportIDList = []; + + if (resolution === CONST.REPORT.ACTIONABLE_REPORT_MENTION_WHISPER_RESOLUTION.CREATE) { + const originalMessage = ReportActionsUtils.getOriginalMessage(reportAction as ReportAction); + originalMessage?.reportNames?.forEach((roomName: string) => { + const optimisticRoom = ReportUtils.buildOptimisticChatReport( + report?.participantAccountIDs ?? [], + roomName, + CONST.REPORT.CHAT_TYPE.POLICY_ROOM, + report?.policyID ?? '', + CONST.REPORT.OWNER_ACCOUNT_ID_FAKE, + false, + '', + report?.visibility, + report?.writeCapability, + CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS, + '', + '', + '', + ); + + reportIDList.push(optimisticRoom.reportID); + const optimisticCreatedAction = ReportUtils.buildOptimisticCreatedReportAction(CONST.REPORT.OWNER_EMAIL_FAKE); + + optimisticData.push({ + onyxMethod: Onyx.METHOD.SET, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${optimisticRoom.reportID}`, + value: {[optimisticCreatedAction.reportActionID]: optimisticCreatedAction}, + }); + + failureData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${optimisticRoom.reportID}`, + value: {[optimisticCreatedAction.reportActionID]: null}, + }); + + optimisticData.push({ + onyxMethod: Onyx.METHOD.SET, + key: `${ONYXKEYS.COLLECTION.REPORT}${optimisticRoom.reportID}`, + value: { + ...optimisticRoom, + pendingFields: { + createChat: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, + }, + isOptimisticReport: true, + }, + }); + + successData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT}${optimisticRoom.reportID}`, + value: { + pendingFields: null, + }, + }); + + failureData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT}${optimisticRoom.reportID}`, + value: null, + }); + }); + } + const parameters: ResolveActionableReportMentionWhisperParams = { reportActionID: reportAction.reportActionID, resolution, }; - API.write(WRITE_COMMANDS.RESOLVE_ACTIONABLE_REPORT_MENTION_WHISPER, parameters, {optimisticData, failureData}); + API.write(WRITE_COMMANDS.RESOLVE_ACTIONABLE_REPORT_MENTION_WHISPER, parameters, {optimisticData, successData, failureData}); } function dismissTrackExpenseActionableWhisper(reportID: string, reportAction: OnyxEntry): void { diff --git a/src/types/onyx/OriginalMessage.ts b/src/types/onyx/OriginalMessage.ts index 4572ac26a449..6304910254f4 100644 --- a/src/types/onyx/OriginalMessage.ts +++ b/src/types/onyx/OriginalMessage.ts @@ -145,6 +145,9 @@ type OriginalMessageActionableReportMentionWhisper = { /** Collection of accountIDs of users mentioned in message */ whisperedTo?: number[]; + + /** List name of the room */ + reportNames?: string[]; }; /** Model of `submitted` report action */