diff --git a/src/libs/ReportActionsUtils.js b/src/libs/ReportActionsUtils.js index 7946b1cbb710..9c3bfcec0318 100644 --- a/src/libs/ReportActionsUtils.js +++ b/src/libs/ReportActionsUtils.js @@ -52,6 +52,11 @@ function getSortedReportActions(reportActions, shouldSortInDescendingOrder = fal } const invertedMultiplier = shouldSortInDescendingOrder ? -1 : 1; reportActions.sort((first, second) => { + // If only one action is a report created action, return the created action first. + if ((first.actionName === CONST.REPORT.ACTIONS.TYPE.CREATED || second.actionName === CONST.REPORT.ACTIONS.TYPE.CREATED) && first.actionName !== second.actionName) { + return ((first.actionName === CONST.REPORT.ACTIONS.TYPE.CREATED) ? -1 : 1) * invertedMultiplier; + } + if (first.created !== second.created) { return (first.created < second.created ? -1 : 1) * invertedMultiplier; } diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 1836543f7761..1a261262e46c 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -919,6 +919,7 @@ function buildOptimisticCreatedReportAction(ownerEmail) { return { 0: { actionName: CONST.REPORT.ACTIONS.TYPE.CREATED, + reportActionID: NumberUtils.rand64(), pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, actorAccountID: currentUserAccountID, message: [ diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index d0122c0e0531..5d1846cc55cc 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -267,9 +267,13 @@ function createSplitsAndOnyxData(participants, currentUserLogin, amount, comment groupChatReport.lastReadTimestamp = Date.now(); groupChatReport.lastMessageText = groupIOUReportAction.message[0].text; groupChatReport.lastMessageHtml = groupIOUReportAction.message[0].html; - groupChatReport.pendingFields = { - createChat: existingGroupChatReport ? null : CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, - }; + + // If we have an existing groupChatReport use it's pending fields, otherwise indicate that we are adding a chat + if (!existingGroupChatReport) { + groupChatReport.pendingFields = { + createChat: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, + }; + } const optimisticData = [ { @@ -379,9 +383,11 @@ function createSplitsAndOnyxData(participants, currentUserLogin, amount, comment oneOnOneChatReport.lastReadSequenceNumber = oneOnOneChatReportMaxSequenceNumber + 1; oneOnOneChatReport.lastMessageText = oneOnOneIOUReportAction.message[0].text; oneOnOneChatReport.lastMessageHtml = oneOnOneIOUReportAction.message[0].html; - oneOnOneChatReport.pendingFields = { - createChat: existingOneOnOneChatReport ? null : CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, - }; + if (!existingOneOnOneChatReport) { + oneOnOneChatReport.pendingFields = { + createChat: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, + }; + } optimisticData.push( {