Skip to content

Commit

Permalink
Merge pull request #3894 from Expensify/marcaaron-getReportSummaryList
Browse files Browse the repository at this point in the history
Get&returnValueList=reportSummaryList
  • Loading branch information
marcaaron authored Jul 14, 2021
2 parents 484e529 + 517c794 commit 480ddc6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 23 deletions.
12 changes: 12 additions & 0 deletions src/libs/API.js
Original file line number Diff line number Diff line change
Expand Up @@ -1018,6 +1018,17 @@ function Inbox_CallUser(parameters) {
return Network.post(commandName, parameters);
}

/**
* @param {Object} parameters
* @param {String} parameters.reportIDList
* @returns {Promise}
*/
function GetReportSummaryList(parameters) {
const commandName = 'Get';
requireParameters(['reportIDList'], parameters, commandName);
return Network.post(commandName, {...parameters, returnValueList: 'reportSummaryList'});
}

/**
* @param {Object} parameters
* @param {String} parameters.policyID
Expand Down Expand Up @@ -1046,6 +1057,7 @@ export {
GetIOUReport,
GetPolicyList,
GetPolicySummaryList,
GetReportSummaryList,
GetRequestCountryCode,
Graphite_Timer,
Inbox_CallUser,
Expand Down
36 changes: 13 additions & 23 deletions src/libs/actions/Report.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,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);
}

Expand Down Expand Up @@ -161,23 +161,22 @@ function getChatReportName(fullReport, chatType) {
* @returns {Object}
*/
function getSimplifiedReportObject(report) {
const reportActionList = lodashGet(report, ['reportActionList'], []);
const lastReportAction = !_.isEmpty(reportActionList) ? _.last(reportActionList) : null;
const createTimestamp = lastReportAction ? lastReportAction.created : 0;
const createTimestamp = lodashGet(report, 'lastActionCreated', 0);
const lastMessageTimestamp = moment.utc(createTimestamp).unix();
const isLastMessageAttachment = /<img([^>]+)\/>/gi.test(lodashGet(lastReportAction, ['message', 'html'], ''));
const lastActionMessage = lodashGet(report, ['lastActionMessage', 'html'], '');
const isLastMessageAttachment = /<img([^>]+)\/>/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(/((<br[^>]*>)+)/gi, ' ')
.replace(/(<([^>]+)>)/gi, '') || `[${translateLocal('common.deletedCommentMessage')}]`;
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')
: '';
Expand All @@ -189,7 +188,7 @@ function getSimplifiedReportObject(report) {
ownerEmail: lodashGet(report, ['ownerEmail'], ''),
policyID: lodashGet(report, ['reportNameValuePairs', 'expensify_policyID'], ''),
unreadActionCount: getUnreadActionCount(report),
maxSequenceNumber: report.reportActionList.length,
maxSequenceNumber: lodashGet(report, 'reportActionCount', 0),
participants: getParticipantEmailsFromReport(report),
isPinned: report.isPinned,
lastVisitedTimestamp: lodashGet(report, [
Expand Down Expand Up @@ -308,22 +307,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;
}

Expand Down

0 comments on commit 480ddc6

Please sign in to comment.