From 7a5fcd01424e2cfaacf66456d4d343e1ea2f5da8 Mon Sep 17 00:00:00 2001 From: Brandon Stites Date: Tue, 19 Jul 2022 08:18:47 -0600 Subject: [PATCH 1/9] Create a method to generate 53 bit reportIDs --- src/libs/ReportUtils.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 058c90d1aa61..cc95da687839 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -510,6 +510,16 @@ function navigateToDetailsPage(report) { Navigation.navigate(ROUTES.getReportParticipantsRoute(report.reportID)); } +/** + * Generate a random reportID between 98000000 (the number of reports before the switch from sequential to random) + * and the maximum safe integer of js (53 bits aka 9,007,199,254,740,991) + * + * @returns {number} + */ +function generateRandomReportID() { + return Math.floor(Math.random() * (Number.MAX_SAFE_INTEGER - 98000000)) + 98000000; +} + export { getReportParticipantsTitle, isReportMessageAttachment, @@ -538,4 +548,5 @@ export { getDisplayNamesWithTooltips, getReportName, navigateToDetailsPage, + generateRandomReportID, }; From 7580df27ae6c772d04eace1c95eea765bbbc8514 Mon Sep 17 00:00:00 2001 From: Brandon Stites Date: Tue, 19 Jul 2022 08:22:06 -0600 Subject: [PATCH 2/9] Add method to generate optimistic reports --- src/libs/actions/Report.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index c14279085fbf..c2ee4ae17602 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -820,6 +820,38 @@ function fetchAllReports( }); } +/** + * Creates an optimistic report with a randomly generated reportID and as much information as we currently have + * + * @param {Array} participantList + * @returns {Object} + */ +function createOptimisticReport(participantList) { + return { + chatType: "", + hasOutstandingIOU: false, + isOwnPolicyExpenseChat: false, + isPinned: false, + lastActorEmail: "", + lastMessageHtml: "", + lastMessageText: null, + lastMessageTimestamp: 0, + lastVisitedTimestamp: 0, + maxSequenceNumber: 0, + notificationPreference: "", + oldPolicyName: "", + ownerEmail: "__FAKE__", + Participants: participantList, + policyID: "_FAKE_", + reportID: ReportUtils.generateRandomReportID(), + reportName: "Chat Report", + stateNum: 0, + statusNum: 0, + unreadActionCount: 0, + visibility: undefined, + } +} + /** * @param {Number} reportID * @param {String} [text] From 0afd1d89e5b6a1f65a3865ed55b28c51d2217f45 Mon Sep 17 00:00:00 2001 From: Brandon Stites Date: Tue, 19 Jul 2022 08:31:49 -0600 Subject: [PATCH 3/9] Export createOptimisticReport --- src/libs/actions/Report.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index c2ee4ae17602..47e2c9ba710f 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -1695,4 +1695,5 @@ export { readNewestAction, openReport, openPaymentDetailsPage, + createOptimisticReport, }; From 21bf7f39e77cf956d83e8f9fb599d26fa424046d Mon Sep 17 00:00:00 2001 From: Brandon Stites Date: Tue, 19 Jul 2022 08:43:46 -0600 Subject: [PATCH 4/9] Add lastReadSequenceNumber so that the optimistic report matches the simplified report correctly --- src/libs/actions/Report.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 47e2c9ba710f..741b27c5db55 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -835,6 +835,7 @@ function createOptimisticReport(participantList) { lastActorEmail: "", lastMessageHtml: "", lastMessageText: null, + lastReadSequenceNumber: undefined, lastMessageTimestamp: 0, lastVisitedTimestamp: 0, maxSequenceNumber: 0, From 58b6b3f5672368ae76bdabafdfe0c959ee37e7c8 Mon Sep 17 00:00:00 2001 From: Brandon Stites Date: Tue, 19 Jul 2022 08:48:35 -0600 Subject: [PATCH 5/9] Add missing semicolon --- src/libs/actions/Report.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 741b27c5db55..1aa5631abc9d 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -850,7 +850,7 @@ function createOptimisticReport(participantList) { statusNum: 0, unreadActionCount: 0, visibility: undefined, - } + }; } /** From 017bef4c512ee29668e9f09af0d7d6f4a6fe5c4d Mon Sep 17 00:00:00 2001 From: Brandon Stites Date: Tue, 19 Jul 2022 08:49:21 -0600 Subject: [PATCH 6/9] Use singlequote instead of doubleQuote --- src/libs/actions/Report.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 1aa5631abc9d..91c7e2d205ad 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -828,24 +828,24 @@ function fetchAllReports( */ function createOptimisticReport(participantList) { return { - chatType: "", + chatType: '', hasOutstandingIOU: false, isOwnPolicyExpenseChat: false, isPinned: false, - lastActorEmail: "", - lastMessageHtml: "", + lastActorEmail: '', + lastMessageHtml: '', lastMessageText: null, lastReadSequenceNumber: undefined, lastMessageTimestamp: 0, lastVisitedTimestamp: 0, maxSequenceNumber: 0, - notificationPreference: "", - oldPolicyName: "", - ownerEmail: "__FAKE__", + notificationPreference: '', + oldPolicyName: '', + ownerEmail: '__FAKE__', Participants: participantList, - policyID: "_FAKE_", + policyID: '_FAKE_', reportID: ReportUtils.generateRandomReportID(), - reportName: "Chat Report", + reportName: 'Chat Report', stateNum: 0, statusNum: 0, unreadActionCount: 0, From 761964bf9aa29fb959f3a68d2e436815e12fa758 Mon Sep 17 00:00:00 2001 From: Brandon Stites Date: Wed, 20 Jul 2022 07:40:11 -0600 Subject: [PATCH 7/9] Increase comment clarity --- 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 cc95da687839..44ad15e65507 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -514,7 +514,10 @@ function navigateToDetailsPage(report) { * Generate a random reportID between 98000000 (the number of reports before the switch from sequential to random) * and the maximum safe integer of js (53 bits aka 9,007,199,254,740,991) * - * @returns {number} + * In a test of 500M reports (28 years of reports at our current max rate) we got 20-40 collisions meaning that + * this is more than random enough for our needs. + * + * @returns {Number} */ function generateRandomReportID() { return Math.floor(Math.random() * (Number.MAX_SAFE_INTEGER - 98000000)) + 98000000; From 1b1cec60e22090e1bad1f8abf861e1b56ad24cff Mon Sep 17 00:00:00 2001 From: Brandon Stites Date: Wed, 20 Jul 2022 08:01:11 -0600 Subject: [PATCH 8/9] Update method name to reduce confusion --- src/libs/ReportUtils.js | 4 ++-- src/libs/actions/Report.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 44ad15e65507..515101b5665f 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -519,7 +519,7 @@ function navigateToDetailsPage(report) { * * @returns {Number} */ -function generateRandomReportID() { +function generateReportID() { return Math.floor(Math.random() * (Number.MAX_SAFE_INTEGER - 98000000)) + 98000000; } @@ -551,5 +551,5 @@ export { getDisplayNamesWithTooltips, getReportName, navigateToDetailsPage, - generateRandomReportID, + generateReportID, }; diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 91c7e2d205ad..d1b49e7022b9 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -844,7 +844,7 @@ function createOptimisticReport(participantList) { ownerEmail: '__FAKE__', Participants: participantList, policyID: '_FAKE_', - reportID: ReportUtils.generateRandomReportID(), + reportID: ReportUtils.generateReportID(), reportName: 'Chat Report', stateNum: 0, statusNum: 0, From ed7b747b72d14c31c9ee0de933546ea89b59b621 Mon Sep 17 00:00:00 2001 From: Brandon Stites Date: Wed, 20 Jul 2022 08:56:25 -0600 Subject: [PATCH 9/9] Un-capitalize --- src/libs/actions/Report.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index d1b49e7022b9..5645e24dd2cf 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -842,7 +842,7 @@ function createOptimisticReport(participantList) { notificationPreference: '', oldPolicyName: '', ownerEmail: '__FAKE__', - Participants: participantList, + participants: participantList, policyID: '_FAKE_', reportID: ReportUtils.generateReportID(), reportName: 'Chat Report',