From a7e10777913a1f105fa85b0bc4685168ac7362a0 Mon Sep 17 00:00:00 2001
From: Jack Nam <jack@expensify.com>
Date: Thu, 1 Dec 2022 12:37:07 -0800
Subject: [PATCH 01/10] kill sequence number

---
 src/libs/ReportUtils.js | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js
index ba52c58a2772..6766f9658e4a 100644
--- a/src/libs/ReportUtils.js
+++ b/src/libs/ReportUtils.js
@@ -865,8 +865,9 @@ function buildOptimisticChatReport(
  * @returns {Object}
  */
 function buildOptimisticCreatedReportAction(ownerEmail) {
+    const reportActionID = NumberUtils.rand64();
     return {
-        0: {
+        [reportActionID]: {
             actionName: CONST.REPORT.ACTIONS.TYPE.CREATED,
             pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
             actorAccountID: currentUserAccountID,
@@ -890,7 +891,6 @@ function buildOptimisticCreatedReportAction(ownerEmail) {
                 },
             ],
             automatic: false,
-            sequenceNumber: 0,
             avatar: lodashGet(allPersonalDetails, [currentUserEmail, 'avatar'], getDefaultAvatar(currentUserEmail)),
             created: DateUtils.getDBTime(),
             shouldShow: true,

From 2b51063c9593314dcc478a88238eb642a336c5b3 Mon Sep 17 00:00:00 2001
From: Jack Nam <jack@expensify.com>
Date: Thu, 1 Dec 2022 17:01:05 -0800
Subject: [PATCH 02/10] add details to pass in createdReportActionID

---
 src/libs/ReportUtils.js    | 7 +++++++
 src/libs/actions/Policy.js | 6 ++++++
 2 files changed, 13 insertions(+)

diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js
index 6766f9658e4a..4b83622cac8f 100644
--- a/src/libs/ReportUtils.js
+++ b/src/libs/ReportUtils.js
@@ -893,6 +893,7 @@ function buildOptimisticCreatedReportAction(ownerEmail) {
             automatic: false,
             avatar: lodashGet(allPersonalDetails, [currentUserEmail, 'avatar'], getDefaultAvatar(currentUserEmail)),
             created: DateUtils.getDBTime(),
+            reportActionID: reportActionID,
             shouldShow: true,
         },
     };
@@ -919,6 +920,7 @@ function buildOptimisticWorkspaceChats(policyID, policyName) {
     );
     const announceChatReportID = announceChatData.reportID;
     const announceReportActionData = buildOptimisticCreatedReportAction(announceChatData.ownerEmail);
+    const announceCreatedReportActionID = announceReportActionData.reportActionID;
 
     const adminsChatData = buildOptimisticChatReport(
         [currentUserEmail],
@@ -931,6 +933,7 @@ function buildOptimisticWorkspaceChats(policyID, policyName) {
     );
     const adminsChatReportID = adminsChatData.reportID;
     const adminsReportActionData = buildOptimisticCreatedReportAction(adminsChatData.ownerEmail);
+    const adminsCreatedReportActionID = adminsReportActionData.reportActionID;
 
     const expenseChatData = buildOptimisticChatReport(
         [currentUserEmail],
@@ -943,17 +946,21 @@ function buildOptimisticWorkspaceChats(policyID, policyName) {
     );
     const expenseChatReportID = expenseChatData.reportID;
     const expenseReportActionData = buildOptimisticCreatedReportAction(expenseChatData.ownerEmail);
+    const expenseCreatedReportActionID = expenseReportActionData.reportActionID;
 
     return {
         announceChatReportID,
         announceChatData,
         announceReportActionData,
+        announceCreatedReportActionID,
         adminsChatReportID,
         adminsChatData,
         adminsReportActionData,
+        adminsCreatedReportActionID,
         expenseChatReportID,
         expenseChatData,
         expenseReportActionData,
+        expenseCreatedReportActionID,
     };
 }
 
diff --git a/src/libs/actions/Policy.js b/src/libs/actions/Policy.js
index 9f3edbde34a8..19da64369487 100644
--- a/src/libs/actions/Policy.js
+++ b/src/libs/actions/Policy.js
@@ -707,12 +707,15 @@ function createWorkspace(ownerEmail = '', makeMeAdmin = false, policyName = '',
         announceChatReportID,
         announceChatData,
         announceReportActionData,
+        announceCreatedReportActionID,
         adminsChatReportID,
         adminsChatData,
         adminsReportActionData,
+        adminsCreatedReportActionID,
         expenseChatReportID,
         expenseChatData,
         expenseReportActionData,
+        expenseCreatedReportActionID,
     } = ReportUtils.buildOptimisticWorkspaceChats(policyID, workspaceName);
 
     API.write('CreateWorkspace', {
@@ -724,6 +727,9 @@ function createWorkspace(ownerEmail = '', makeMeAdmin = false, policyName = '',
         makeMeAdmin,
         policyName: workspaceName,
         type: CONST.POLICY.TYPE.FREE,
+        announceCreatedReportActionID,
+        adminsCreatedReportActionID,
+        expenseCreatedReportActionID
     },
     {
         optimisticData: [{

From 497d12e568683af0a54aa4d41ad5f80c07d30c53 Mon Sep 17 00:00:00 2001
From: Jack Nam <jack@expensify.com>
Date: Mon, 5 Dec 2022 14:00:46 -0800
Subject: [PATCH 03/10] revert reportActionID

---
 src/libs/ReportUtils.js | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js
index 4b83622cac8f..64f5d40e9894 100644
--- a/src/libs/ReportUtils.js
+++ b/src/libs/ReportUtils.js
@@ -867,7 +867,7 @@ function buildOptimisticChatReport(
 function buildOptimisticCreatedReportAction(ownerEmail) {
     const reportActionID = NumberUtils.rand64();
     return {
-        [reportActionID]: {
+        0: {
             actionName: CONST.REPORT.ACTIONS.TYPE.CREATED,
             pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
             actorAccountID: currentUserAccountID,
@@ -891,6 +891,7 @@ function buildOptimisticCreatedReportAction(ownerEmail) {
                 },
             ],
             automatic: false,
+            sequenceNumber: 0,
             avatar: lodashGet(allPersonalDetails, [currentUserEmail, 'avatar'], getDefaultAvatar(currentUserEmail)),
             created: DateUtils.getDBTime(),
             reportActionID: reportActionID,

From 6fd98ece7d3debfe58b1b5c2878cdb54a6254178 Mon Sep 17 00:00:00 2001
From: Jack Nam <jack@expensify.com>
Date: Thu, 8 Dec 2022 16:25:53 -0800
Subject: [PATCH 04/10] fix missing trailing comma

---
 src/libs/actions/Policy.js | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/libs/actions/Policy.js b/src/libs/actions/Policy.js
index 19da64369487..d59a73dad54a 100644
--- a/src/libs/actions/Policy.js
+++ b/src/libs/actions/Policy.js
@@ -729,7 +729,7 @@ function createWorkspace(ownerEmail = '', makeMeAdmin = false, policyName = '',
         type: CONST.POLICY.TYPE.FREE,
         announceCreatedReportActionID,
         adminsCreatedReportActionID,
-        expenseCreatedReportActionID
+        expenseCreatedReportActionID,
     },
     {
         optimisticData: [{

From adc194b9fb5ce4037ba323f910f54cf690170e7c Mon Sep 17 00:00:00 2001
From: Jack Nam <jack@expensify.com>
Date: Thu, 8 Dec 2022 16:57:08 -0800
Subject: [PATCH 05/10] shorthand

---
 src/libs/ReportUtils.js | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js
index 64f5d40e9894..072c021ad51f 100644
--- a/src/libs/ReportUtils.js
+++ b/src/libs/ReportUtils.js
@@ -894,7 +894,7 @@ function buildOptimisticCreatedReportAction(ownerEmail) {
             sequenceNumber: 0,
             avatar: lodashGet(allPersonalDetails, [currentUserEmail, 'avatar'], getDefaultAvatar(currentUserEmail)),
             created: DateUtils.getDBTime(),
-            reportActionID: reportActionID,
+            reportActionID,
             shouldShow: true,
         },
     };

From 948709f1ac0e656228757a50ff1f71cfd2ec58a5 Mon Sep 17 00:00:00 2001
From: Jack Nam <jack@expensify.com>
Date: Wed, 4 Jan 2023 17:11:16 -0800
Subject: [PATCH 06/10] remove added changes in main

---
 src/libs/ReportUtils.js | 2 --
 1 file changed, 2 deletions(-)

diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js
index 82ccd84078a8..175cbab95cda 100644
--- a/src/libs/ReportUtils.js
+++ b/src/libs/ReportUtils.js
@@ -914,7 +914,6 @@ function buildOptimisticChatReport(
  * @returns {Object}
  */
 function buildOptimisticCreatedReportAction(ownerEmail) {
-    const reportActionID = NumberUtils.rand64();
     return {
         0: {
             actionName: CONST.REPORT.ACTIONS.TYPE.CREATED,
@@ -944,7 +943,6 @@ function buildOptimisticCreatedReportAction(ownerEmail) {
             sequenceNumber: 0,
             avatar: lodashGet(allPersonalDetails, [currentUserEmail, 'avatar'], getDefaultAvatar(currentUserEmail)),
             created: DateUtils.getDBTime(),
-            reportActionID,
             shouldShow: true,
         },
     };

From f62d3803d019fbb3042f07c581ede623f6bd0a95 Mon Sep 17 00:00:00 2001
From: Jack Nam <jack@expensify.com>
Date: Mon, 9 Jan 2023 16:28:29 -0800
Subject: [PATCH 07/10] remove the check for lastActionCreated

---
 src/libs/ReportUtils.js | 1 -
 1 file changed, 1 deletion(-)

diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js
index 175cbab95cda..1945ec498b01 100644
--- a/src/libs/ReportUtils.js
+++ b/src/libs/ReportUtils.js
@@ -892,7 +892,6 @@ function buildOptimisticChatReport(
         lastMessageHtml: '',
         lastMessageText: null,
         lastReadSequenceNumber: 0,
-        lastActionCreated: DateUtils.getDBTime(),
         lastReadTime: '',
         maxSequenceNumber: 0,
         notificationPreference,

From f369cc985b046f957c442dbc711a96d5734651f1 Mon Sep 17 00:00:00 2001
From: Jack Nam <jack@expensify.com>
Date: Tue, 10 Jan 2023 14:31:17 -0800
Subject: [PATCH 08/10] Update ReportUtils.js

---
 src/libs/ReportUtils.js | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js
index 1945ec498b01..bb5341bc706f 100644
--- a/src/libs/ReportUtils.js
+++ b/src/libs/ReportUtils.js
@@ -883,6 +883,8 @@ function buildOptimisticChatReport(
     visibility = undefined,
     notificationPreference = CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS,
 ) {
+    // Used so we can set the lastRead and the lastActionCreated to the exact time and not deal with millisecond differences
+    const currentTime = DateUtils.getDBTime();
     return {
         chatType,
         hasOutstandingIOU: false,
@@ -892,7 +894,8 @@ function buildOptimisticChatReport(
         lastMessageHtml: '',
         lastMessageText: null,
         lastReadSequenceNumber: 0,
-        lastReadTime: '',
+        lastReadTime: currentTime,
+        lastActionCreated: currentTime,
         maxSequenceNumber: 0,
         notificationPreference,
         oldPolicyName,

From e1abf7e934716390a09a217b93a1dc8c2e1eb885 Mon Sep 17 00:00:00 2001
From: Jack Nam <jack@expensify.com>
Date: Tue, 10 Jan 2023 15:57:40 -0800
Subject: [PATCH 09/10] remove comment so changes are the same

---
 src/libs/ReportUtils.js | 1 -
 1 file changed, 1 deletion(-)

diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js
index bb5341bc706f..2e7e8c6c51e6 100644
--- a/src/libs/ReportUtils.js
+++ b/src/libs/ReportUtils.js
@@ -883,7 +883,6 @@ function buildOptimisticChatReport(
     visibility = undefined,
     notificationPreference = CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS,
 ) {
-    // Used so we can set the lastRead and the lastActionCreated to the exact time and not deal with millisecond differences
     const currentTime = DateUtils.getDBTime();
     return {
         chatType,

From 98be065c58c69c99c2ea9987acbb4b60532e8420 Mon Sep 17 00:00:00 2001
From: Jack Nam <jack@expensify.com>
Date: Tue, 10 Jan 2023 18:51:38 -0800
Subject: [PATCH 10/10] grab the index

---
 src/libs/ReportUtils.js | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js
index 2e7e8c6c51e6..7f56ef62f1ec 100644
--- a/src/libs/ReportUtils.js
+++ b/src/libs/ReportUtils.js
@@ -970,7 +970,7 @@ function buildOptimisticWorkspaceChats(policyID, policyName) {
     );
     const announceChatReportID = announceChatData.reportID;
     const announceReportActionData = buildOptimisticCreatedReportAction(announceChatData.ownerEmail);
-    const announceCreatedReportActionID = announceReportActionData.reportActionID;
+    const announceCreatedReportActionID = announceReportActionData[0].reportActionID;
 
     const adminsChatData = buildOptimisticChatReport(
         [currentUserEmail],
@@ -983,7 +983,7 @@ function buildOptimisticWorkspaceChats(policyID, policyName) {
     );
     const adminsChatReportID = adminsChatData.reportID;
     const adminsReportActionData = buildOptimisticCreatedReportAction(adminsChatData.ownerEmail);
-    const adminsCreatedReportActionID = adminsReportActionData.reportActionID;
+    const adminsCreatedReportActionID = adminsReportActionData[0].reportActionID;
 
     const expenseChatData = buildOptimisticChatReport(
         [currentUserEmail],
@@ -996,7 +996,7 @@ function buildOptimisticWorkspaceChats(policyID, policyName) {
     );
     const expenseChatReportID = expenseChatData.reportID;
     const expenseReportActionData = buildOptimisticCreatedReportAction(expenseChatData.ownerEmail);
-    const expenseCreatedReportActionID = expenseReportActionData.reportActionID;
+    const expenseCreatedReportActionID = expenseReportActionData[0].reportActionID;
 
     return {
         announceChatReportID,
