Skip to content

Commit

Permalink
Replace the remaining use of the old draft detection
Browse files Browse the repository at this point in the history
  • Loading branch information
marktoman committed Oct 30, 2021
1 parent 302e018 commit 2a591b5
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions src/libs/OptionsListUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORTS_WITH_DRAFT,
callback: (hasDraft, key) => {
if (key) {
reportsWithDraft[key] = hasDraft
reportsWithDraft[key] = hasDraft;
}
},
});
Expand Down Expand Up @@ -188,12 +188,23 @@ function getSearchText(report, personalDetailList, isDefaultChatRoom) {
return _.unique(searchTerms).join(' ');
}

/**
* Determines whether a report has a draft comment.
*
* @param {Object} report
* @return {Boolean}
*/
function hasReportDraftComment(report) {
return report
&& reportsWithDraft
&& lodashGet(reportsWithDraft, `${ONYXKEYS.COLLECTION.REPORTS_WITH_DRAFT}${report.reportID}`, false);
}

/**
* Creates a report list option
*
* @param {Array<Object>} personalDetailList
* @param {Object} [report]
* @param {Object} draftComments
* @param {Boolean} showChatPreviewLine
* @param {Boolean} forcePolicyNamePreview
* @returns {Object}
Expand All @@ -204,10 +215,7 @@ function createOption(personalDetailList, report, {
const isDefaultChatRoom = isDefaultRoom(report);
const hasMultipleParticipants = personalDetailList.length > 1 || isDefaultChatRoom;
const personalDetail = personalDetailList[0];
const hasDraft = report
&& reportsWithDraft
&& lodashGet(reportsWithDraft, `${ONYXKEYS.COLLECTION.REPORTS_WITH_DRAFT}${report.reportID}`, false);

const hasDraftComment = hasReportDraftComment(report);
const hasOutstandingIOU = lodashGet(report, 'hasOutstandingIOU', false);
const iouReport = hasOutstandingIOU
? lodashGet(iouReports, `${ONYXKEYS.COLLECTION.REPORT_IOUS}${report.iouReportID}`, {})
Expand Down Expand Up @@ -253,7 +261,7 @@ function createOption(personalDetailList, report, {
phoneNumber: !hasMultipleParticipants ? personalDetail.phoneNumber : null,
payPalMeAddress: !hasMultipleParticipants ? personalDetail.payPalMeAddress : null,
isUnread: report ? report.unreadActionCount > 0 : null,
hasDraftComment: hasDraft,
hasDraftComment,
keyForList: report ? String(report.reportID) : personalDetail.login,
searchText: getSearchText(report, personalDetailList, isDefaultChatRoom),
isPinned: lodashGet(report, 'isPinned', false),
Expand Down Expand Up @@ -324,13 +332,12 @@ function isCurrentUser(userDetails) {
*
* @param {Object} reports
* @param {Object} personalDetails
* @param {Object} draftComments
* @param {Number} activeReportID
* @param {Object} options
* @returns {Object}
* @private
*/
function getOptions(reports, personalDetails, draftComments, activeReportID, {
function getOptions(reports, personalDetails, activeReportID, {
betas = [],
selectedOptions = [],
maxRecentReportsToShow = 0,
Expand Down Expand Up @@ -377,17 +384,15 @@ function getOptions(reports, personalDetails, draftComments, activeReportID, {
return;
}

const reportDraftComment = report
&& draftComments
&& lodashGet(draftComments, `${ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT}${report.reportID}`, '');
const hasDraftComment = hasReportDraftComment(report);
const iouReportOwner = lodashGet(report, 'hasOutstandingIOU', false)
? lodashGet(iouReports, [`${ONYXKEYS.COLLECTION.REPORT_IOUS}${report.iouReportID}`, 'ownerEmail'], '')
: '';

const reportContainsIOUDebt = iouReportOwner && iouReportOwner !== currentUserLogin;
const shouldFilterReportIfEmpty = !showReportsWithNoComments && report.lastMessageTimestamp === 0;
const shouldFilterReportIfRead = hideReadReports && report.unreadActionCount === 0;
const shouldShowReportIfHasDraft = showReportsWithDrafts && reportDraftComment && reportDraftComment.length > 0;
const shouldShowReportIfHasDraft = showReportsWithDrafts && hasDraftComment;
const shouldFilterReport = shouldFilterReportIfEmpty || shouldFilterReportIfRead;
if (report.reportID !== activeReportID
&& !report.isPinned
Expand Down Expand Up @@ -560,7 +565,7 @@ function getSearchOptions(
searchValue = '',
betas,
) {
return getOptions(reports, personalDetails, {}, 0, {
return getOptions(reports, personalDetails, 0, {
betas,
searchValue,
includeRecentReports: true,
Expand Down Expand Up @@ -628,7 +633,7 @@ function getNewChatOptions(
selectedOptions = [],
excludeLogins = [],
) {
return getOptions(reports, personalDetails, {}, 0, {
return getOptions(reports, personalDetails, 0, {
betas,
searchValue,
selectedOptions,
Expand All @@ -645,7 +650,6 @@ function getNewChatOptions(
*
* @param {Object} reports
* @param {Object} personalDetails
* @param {Object} draftComments
* @param {Number} activeReportID
* @param {String} priorityMode
* @param {Array<String>} betas
Expand All @@ -654,7 +658,6 @@ function getNewChatOptions(
function getSidebarOptions(
reports,
personalDetails,
draftComments,
activeReportID,
priorityMode,
betas,
Expand All @@ -672,7 +675,7 @@ function getSidebarOptions(
};
}

return getOptions(reports, personalDetails, draftComments, activeReportID, {
return getOptions(reports, personalDetails, activeReportID, {
betas,
includeRecentReports: true,
includeMultipleParticipantReports: true,
Expand Down

0 comments on commit 2a591b5

Please sign in to comment.