From c3631df8d092d067c1692582994cf69bdfeec095 Mon Sep 17 00:00:00 2001 From: Marc Glasser Date: Tue, 6 Jul 2021 12:56:00 -1000 Subject: [PATCH 1/3] use reportSummaryList --- src/libs/API.js | 7 +++++++ src/libs/actions/Report.js | 30 ++++++++++-------------------- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/src/libs/API.js b/src/libs/API.js index 99f0d0c79948..a8a365528bf0 100644 --- a/src/libs/API.js +++ b/src/libs/API.js @@ -992,6 +992,12 @@ function Inbox_CallUser(parameters) { return Network.post(commandName, parameters); } +function GetReportSummaryList(parameters) { + const commandName = 'Get'; + requireParameters(['reportIDList'], parameters, commandName); + return Network.post(commandName, {...parameters, returnValueList: 'reportSummaryList'}); +} + export { Authenticate, BankAccount_Create, @@ -1007,6 +1013,7 @@ export { GetIOUReport, GetPolicyList, GetPolicySummaryList, + GetReportSummaryList, GetRequestCountryCode, Graphite_Timer, Inbox_CallUser, diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 9ebc42db9629..de6d72f0ac81 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -99,17 +99,17 @@ function getUnreadActionCount(report) { // Save the lastReadActionID locally so we can access this later lastReadSequenceNumbers[report.reportID] = lastReadSequenceNumber; - if (report.reportActionList.length === 0) { + if (report.reportActionListLength === 0) { return 0; } if (!lastReadSequenceNumber) { - return report.reportActionList.length; + return report.reportActionListLength; } // There are unread items if the last one the user has read is less // than the highest sequence number we have - const unreadActionCount = report.reportActionList.length - lastReadSequenceNumber; + const unreadActionCount = report.reportActionListLength - lastReadSequenceNumber; return Math.max(0, unreadActionCount); } @@ -154,8 +154,7 @@ function getChatReportName(fullReport, chatType) { * @returns {Object} */ function getSimplifiedReportObject(report) { - const reportActionList = lodashGet(report, ['reportActionList'], []); - const lastReportAction = !_.isEmpty(reportActionList) ? _.last(reportActionList) : null; + const lastReportAction = !_.isEmpty(report.mostRecentReportAction) ? report.mostRecentReportAction : null; const createTimestamp = lastReportAction ? lastReportAction.created : 0; const lastMessageTimestamp = moment.utc(createTimestamp).unix(); const isLastMessageAttachment = /]+)\/>/gi.test(lodashGet(lastReportAction, ['message', 'html'], '')); @@ -179,10 +178,10 @@ function getSimplifiedReportObject(report) { reportID: report.reportID, reportName, chatType, - ownerEmail: lodashGet(report, ['ownerEmail'], ''), + ownerEmail: lodashGet(report, ['accountEmail'], ''), policyID: lodashGet(report, ['reportNameValuePairs', 'expensify_policyID'], ''), unreadActionCount: getUnreadActionCount(report), - maxSequenceNumber: report.reportActionList.length, + maxSequenceNumber: report.reportActionListLength, participants: getParticipantEmailsFromReport(report), isPinned: report.isPinned, lastVisitedTimestamp: lodashGet(report, [ @@ -301,22 +300,13 @@ function fetchIOUReportID(debtorEmail) { function fetchChatReportsByIDs(chatList) { let fetchedReports; const simplifiedReports = {}; - return API.Get({ - returnValueList: 'reportStuff', - reportIDList: chatList.join(','), - shouldLoadOptionalKeys: true, - includePinnedReports: true, - }) - .then(({reports}) => { + return API.GetReportSummaryList({reportIDList: chatList.join(',')}) + .then(({reportSummaryList}) => { Log.info('[Report] successfully fetched report data', true); - fetchedReports = reports; + fetchedReports = reportSummaryList; return Promise.all(_.map(fetchedReports, (chatReport) => { - const reportActionList = chatReport.reportActionList || []; - const containsIOUAction = _.any(reportActionList, - reportAction => reportAction.action === CONST.REPORT.ACTIONS.TYPE.IOU); - // If there aren't any IOU actions, we don't need to fetch any additional data - if (!containsIOUAction) { + if (!chatReport.hasIOUAction) { return; } From a3f43bfc4ada66ae0917efa346251c09a4462a90 Mon Sep 17 00:00:00 2001 From: Marc Glasser Date: Tue, 6 Jul 2021 14:59:54 -1000 Subject: [PATCH 2/3] use ownerEmail instead --- 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 de6d72f0ac81..c5266ab417e8 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -178,7 +178,7 @@ function getSimplifiedReportObject(report) { reportID: report.reportID, reportName, chatType, - ownerEmail: lodashGet(report, ['accountEmail'], ''), + ownerEmail: lodashGet(report, ['ownerEmail'], ''), policyID: lodashGet(report, ['reportNameValuePairs', 'expensify_policyID'], ''), unreadActionCount: getUnreadActionCount(report), maxSequenceNumber: report.reportActionListLength, From a3256919494c93f13df57b068c3539fe2061a298 Mon Sep 17 00:00:00 2001 From: Marc Glasser Date: Wed, 7 Jul 2021 13:05:20 -1000 Subject: [PATCH 3/3] use new param names --- src/libs/actions/Report.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index c5266ab417e8..9199d873d77b 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -154,22 +154,22 @@ function getChatReportName(fullReport, chatType) { * @returns {Object} */ function getSimplifiedReportObject(report) { - const lastReportAction = !_.isEmpty(report.mostRecentReportAction) ? report.mostRecentReportAction : null; - const createTimestamp = lastReportAction ? lastReportAction.created : 0; + const createTimestamp = lodashGet(report, 'lastActionCreated', 0); const lastMessageTimestamp = moment.utc(createTimestamp).unix(); - const isLastMessageAttachment = /]+)\/>/gi.test(lodashGet(lastReportAction, ['message', 'html'], '')); + const lastActionMessage = lodashGet(report, ['lastActionMessage', 'html'], ''); + const isLastMessageAttachment = /]+)\/>/gi.test(lastActionMessage); const chatType = lodashGet(report, ['reportNameValuePairs', 'chatType'], ''); // We are removing any html tags from the message html since we cannot access the text version of any comments as // the report only has the raw reportActionList and not the processed version returned by Report_GetHistory // We convert the line-breaks in html to space ' ' before striping the tags - const lastMessageText = lodashGet(lastReportAction, ['message', 'html'], '') + const lastMessageText = lastActionMessage .replace(/((]*>)+)/gi, ' ') .replace(/(<([^>]+)>)/gi, ''); const reportName = lodashGet(report, ['reportNameValuePairs', 'type']) === 'chat' ? getChatReportName(report, chatType) : report.reportName; - const lastActorEmail = lodashGet(lastReportAction, 'accountEmail', ''); + const lastActorEmail = lodashGet(report, 'lastActionActorEmail', ''); const notificationPreference = isDefaultRoom({chatType}) ? lodashGet(report, ['reportNameValuePairs', 'notificationPreferences', currentUserAccountID], 'daily') : ''; @@ -181,7 +181,7 @@ function getSimplifiedReportObject(report) { ownerEmail: lodashGet(report, ['ownerEmail'], ''), policyID: lodashGet(report, ['reportNameValuePairs', 'expensify_policyID'], ''), unreadActionCount: getUnreadActionCount(report), - maxSequenceNumber: report.reportActionListLength, + maxSequenceNumber: lodashGet(report, 'reportActionCount', 0), participants: getParticipantEmailsFromReport(report), isPinned: report.isPinned, lastVisitedTimestamp: lodashGet(report, [