Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get&returnValueList=reportSummaryList #3894

Merged
merged 5 commits into from
Jul 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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