From 4a99f227c8a59e21040778902bce6292afb3233c Mon Sep 17 00:00:00 2001 From: Roji Philip Date: Thu, 28 Sep 2023 10:03:47 +0530 Subject: [PATCH 1/4] [Deleted message] in LHN subtitle --- src/libs/OptionsListUtils.js | 2 ++ src/libs/ReportActionsUtils.js | 15 ++++++++++++++- src/libs/ReportUtils.js | 5 +++-- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index 7c36fa095029..b2075657b54f 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -394,6 +394,8 @@ function getLastMessageTextForReport(report) { } else if (ReportActionUtils.isReportPreviewAction(lastReportAction)) { const iouReport = ReportUtils.getReport(ReportActionUtils.getIOUReportIDFromReportActionPreview(lastReportAction)); lastMessageTextFromReport = ReportUtils.getReportPreviewMessage(iouReport, lastReportAction); + } else if (ReportActionUtils.isDeletedParentAction(lastReportAction) && ReportUtils.isChatReport(report)) { + lastMessageTextFromReport = Localize.translate(preferredLocale, 'parentReportAction.deletedMessage'); } else if (ReportActionUtils.isModifiedExpenseAction(lastReportAction)) { lastMessageTextFromReport = ReportUtils.getModifiedExpenseMessage(lastReportAction); } else { diff --git a/src/libs/ReportActionsUtils.js b/src/libs/ReportActionsUtils.js index 67c44784eeb2..4f081ef306e8 100644 --- a/src/libs/ReportActionsUtils.js +++ b/src/libs/ReportActionsUtils.js @@ -8,6 +8,8 @@ import * as CollectionUtils from './CollectionUtils'; import CONST from '../CONST'; import ONYXKEYS from '../ONYXKEYS'; import Log from './Log'; +import * as Localize from './Localize'; +import * as ReportUtils from './ReportUtils'; import isReportMessageAttachment from './isReportMessageAttachment'; const allReports = {}; @@ -383,8 +385,11 @@ function shouldReportActionBeVisibleAsLastAction(reportAction) { } // If a whisper action is the REPORTPREVIEW action, we are displaying it. + // If the action's message text is empty and it is not a deleted parent with visible child actions, hide it. Else, consider the action to be displayable. return ( - shouldReportActionBeVisible(reportAction, reportAction.reportActionID) && !(isWhisperAction(reportAction) && !isReportPreviewAction(reportAction)) && !isDeletedAction(reportAction) + shouldReportActionBeVisible(reportAction, reportAction.reportActionID) && + !(isWhisperAction(reportAction) && !isReportPreviewAction(reportAction)) && + !(isDeletedAction(reportAction) && !isDeletedParentAction(reportAction)) ); } @@ -437,6 +442,14 @@ function getLastVisibleMessage(reportID, actionsToMerge = {}) { }; } + // For Chat Report, let us return [Deleted message] when the last visible action + // is a deleted parent which has visible child actions + if (isDeletedParentAction(lastVisibleAction) && ReportUtils.isChatReport(reportID)) { + return { + lastMessageText: Localize.translateLocal('parentReportAction.deletedMessage'), + }; + } + const messageText = lodashGet(message, 'text', ''); return { lastMessageText: String(messageText).replace(CONST.REGEX.AFTER_FIRST_LINE_BREAK, '').substring(0, CONST.REPORT.LAST_MESSAGE_TEXT_MAX_LENGTH).trim(), diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 7fc151ce6f26..5ccb5509ffb6 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -153,10 +153,11 @@ function getReportParticipantsTitle(accountIDs) { /** * Checks if a report is a chat report. * - * @param {Object} report + * @param {Object|String} reportOrID * @returns {Boolean} */ -function isChatReport(report) { +function isChatReport(reportOrID) { + const report = _.isObject(reportOrID) ? reportOrID : allReports[`${ONYXKEYS.COLLECTION.REPORT}${reportOrID}`]; return report && report.type === CONST.REPORT.TYPE.CHAT; } From 099706949ea86bfb5df7925b23d5aeafd2140712 Mon Sep 17 00:00:00 2001 From: Roji Philip Date: Thu, 28 Sep 2023 15:11:20 +0530 Subject: [PATCH 2/4] lint fix - Avoid dependency cycle --- src/libs/ReportActionsUtils.js | 24 ++++++++++-------------- src/libs/ReportUtils.js | 5 ++--- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/src/libs/ReportActionsUtils.js b/src/libs/ReportActionsUtils.js index 4f081ef306e8..5530aa960684 100644 --- a/src/libs/ReportActionsUtils.js +++ b/src/libs/ReportActionsUtils.js @@ -9,20 +9,13 @@ import CONST from '../CONST'; import ONYXKEYS from '../ONYXKEYS'; import Log from './Log'; import * as Localize from './Localize'; -import * as ReportUtils from './ReportUtils'; import isReportMessageAttachment from './isReportMessageAttachment'; -const allReports = {}; +let allReports; Onyx.connect({ key: ONYXKEYS.COLLECTION.REPORT, - callback: (report, key) => { - if (!key || !report) { - return; - } - - const reportID = CollectionUtils.extractCollectionItemID(key); - allReports[reportID] = report; - }, + waitForCollectionCallback: true, + callback: (val) => (allReports = val), }); const allReportActions = {}; @@ -444,10 +437,13 @@ function getLastVisibleMessage(reportID, actionsToMerge = {}) { // For Chat Report, let us return [Deleted message] when the last visible action // is a deleted parent which has visible child actions - if (isDeletedParentAction(lastVisibleAction) && ReportUtils.isChatReport(reportID)) { - return { - lastMessageText: Localize.translateLocal('parentReportAction.deletedMessage'), - }; + if (isDeletedParentAction(lastVisibleAction)) { + const report = allReports[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]; + if (report && report.type === CONST.REPORT.TYPE.CHAT) { + return { + lastMessageText: Localize.translateLocal('parentReportAction.deletedMessage'), + }; + } } const messageText = lodashGet(message, 'text', ''); diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 5b94ef79f9a7..42e7e40fe62b 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -153,11 +153,10 @@ function getReportParticipantsTitle(accountIDs) { /** * Checks if a report is a chat report. * - * @param {Object|String} reportOrID + * @param {Object} report * @returns {Boolean} */ -function isChatReport(reportOrID) { - const report = _.isObject(reportOrID) ? reportOrID : allReports[`${ONYXKEYS.COLLECTION.REPORT}${reportOrID}`]; +function isChatReport(report) { return report && report.type === CONST.REPORT.TYPE.CHAT; } From ae59e9bb0640b33cf07632d1047dc0f18509b5d3 Mon Sep 17 00:00:00 2001 From: Roji Philip Date: Sat, 30 Sep 2023 02:02:22 +0530 Subject: [PATCH 3/4] lint fix - Avoid Dependency cycle for Localize --- src/libs/ReportActionsUtils.js | 24 +++++++++--------------- src/libs/ReportUtils.js | 22 ++++++++++++++++++++++ src/libs/actions/Report.js | 2 +- 3 files changed, 32 insertions(+), 16 deletions(-) diff --git a/src/libs/ReportActionsUtils.js b/src/libs/ReportActionsUtils.js index 5530aa960684..9f3ceb4a0fd3 100644 --- a/src/libs/ReportActionsUtils.js +++ b/src/libs/ReportActionsUtils.js @@ -8,14 +8,19 @@ import * as CollectionUtils from './CollectionUtils'; import CONST from '../CONST'; import ONYXKEYS from '../ONYXKEYS'; import Log from './Log'; -import * as Localize from './Localize'; import isReportMessageAttachment from './isReportMessageAttachment'; -let allReports; +const allReports = {}; Onyx.connect({ key: ONYXKEYS.COLLECTION.REPORT, - waitForCollectionCallback: true, - callback: (val) => (allReports = val), + callback: (report, key) => { + if (!key || !report) { + return; + } + + const reportID = CollectionUtils.extractCollectionItemID(key); + allReports[reportID] = report; + }, }); const allReportActions = {}; @@ -435,17 +440,6 @@ function getLastVisibleMessage(reportID, actionsToMerge = {}) { }; } - // For Chat Report, let us return [Deleted message] when the last visible action - // is a deleted parent which has visible child actions - if (isDeletedParentAction(lastVisibleAction)) { - const report = allReports[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]; - if (report && report.type === CONST.REPORT.TYPE.CHAT) { - return { - lastMessageText: Localize.translateLocal('parentReportAction.deletedMessage'), - }; - } - } - const messageText = lodashGet(message, 'text', ''); return { lastMessageText: String(messageText).replace(CONST.REGEX.AFTER_FIRST_LINE_BREAK, '').substring(0, CONST.REPORT.LAST_MESSAGE_TEXT_MAX_LENGTH).trim(), diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index f41ad0b75b42..509eea442ba2 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -1205,6 +1205,27 @@ function getReport(reportID) { return lodashGet(allReports, `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, {}) || {}; } +/** + * @param {String} reportID + * @param {Object} [actionsToMerge] + * @return {Object} + */ +function getLastVisibleMessage(reportID, actionsToMerge = {}) { + const report = getReport(reportID); + const lastVisibleAction = ReportActionsUtils.getLastVisibleAction(reportID, actionsToMerge); + + // For Chat Report, let us return [Deleted message] when the last visible action + // is a deleted parent which has visible child actions + if (ReportActionsUtils.isDeletedParentAction(lastVisibleAction) && isChatReport(report)) { + return { + lastMessageText: Localize.translateLocal('parentReportAction.deletedMessage'), + }; + } + + // Fetch the last visible message for report represented by reportID and based on actions to merge. + return ReportActionsUtils.getLastVisibleMessage(reportID, actionsToMerge); +} + /** * Determines if a report has an IOU that is waiting for an action from the current user (either Pay or Add a credit bank account) * @@ -3725,6 +3746,7 @@ export { getReport, getReportIDFromLink, getRouteFromLink, + getLastVisibleMessage, navigateToDetailsPage, generateReportID, hasReportNameError, diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 66008ae5ae2a..169658e7a0f1 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -1040,7 +1040,7 @@ function deleteReportComment(reportID, reportAction) { isLastMessageDeletedParentAction: true, }; } else { - const {lastMessageText = '', lastMessageTranslationKey = ''} = ReportActionsUtils.getLastVisibleMessage(originalReportID, optimisticReportActions); + const {lastMessageText = '', lastMessageTranslationKey = ''} = ReportUtils.getLastVisibleMessage(originalReportID, optimisticReportActions); if (lastMessageText || lastMessageTranslationKey) { const lastVisibleAction = ReportActionsUtils.getLastVisibleAction(originalReportID, optimisticReportActions); const lastVisibleActionCreated = lastVisibleAction.created; From 901499a604e762494fd2bc4511d9f9e67d53a48d Mon Sep 17 00:00:00 2001 From: Roji Philip Date: Tue, 17 Oct 2023 13:37:57 +0530 Subject: [PATCH 4/4] fix for [Deleted task] --- src/libs/OptionsListUtils.js | 2 +- src/libs/ReportUtils.js | 30 +++++++++++++++++++++++++----- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index 2cf2098f8f8e..99c2845af469 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -377,7 +377,7 @@ function getLastMessageTextForReport(report) { ); lastMessageTextFromReport = ReportUtils.getReportPreviewMessage(iouReport, lastIOUMoneyReport, true); } else if (ReportActionUtils.isDeletedParentAction(lastReportAction) && ReportUtils.isChatReport(report)) { - lastMessageTextFromReport = Localize.translate(preferredLocale, 'parentReportAction.deletedMessage'); + lastMessageTextFromReport = ReportUtils.getDeletedParentActionMessageForChatReport(lastReportAction); } else if (ReportActionUtils.isModifiedExpenseAction(lastReportAction)) { const properSchemaForModifiedExpenseMessage = ReportUtils.getModifiedExpenseMessage(lastReportAction); lastMessageTextFromReport = ReportUtils.formatReportLastMessageText(properSchemaForModifiedExpenseMessage, true); diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 3060d6f97f6f..0e4ed12b5d7c 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -1213,19 +1213,38 @@ function getDisplayNamesWithTooltips(personalDetailsList, isMultipleParticipantR } /** - * @param {String} reportID - * @param {Object} [actionsToMerge] + * For a deleted parent report action within a chat report, + * let us return the appropriate display message + * + * @param {Object} reportAction - The deleted report action of a chat report for which we need to return message. + * @return {String} + */ +function getDeletedParentActionMessageForChatReport(reportAction) { + // By default, let us display [Deleted message] + let deletedMessageText = Localize.translateLocal('parentReportAction.deletedMessage'); + if (ReportActionsUtils.isCreatedTaskReportAction(reportAction)) { + // For canceled task report, let us display [Deleted task] + deletedMessageText = Localize.translateLocal('parentReportAction.deletedTask'); + } + return deletedMessageText; +} + +/** + * Returns the last visible message for a given report after considering the given optimistic actions + * + * @param {String} reportID - the report for which last visible message has to be fetched + * @param {Object} [actionsToMerge] - the optimistic merge actions that needs to be considered while fetching last visible message * @return {Object} */ function getLastVisibleMessage(reportID, actionsToMerge = {}) { const report = getReport(reportID); const lastVisibleAction = ReportActionsUtils.getLastVisibleAction(reportID, actionsToMerge); - // For Chat Report, let us return [Deleted message] when the last visible action - // is a deleted parent which has visible child actions + // For Chat Report with deleted parent actions, let us fetch the correct message if (ReportActionsUtils.isDeletedParentAction(lastVisibleAction) && isChatReport(report)) { + const lastMessageText = getDeletedParentActionMessageForChatReport(lastVisibleAction); return { - lastMessageText: Localize.translateLocal('parentReportAction.deletedMessage'), + lastMessageText, }; } @@ -3948,6 +3967,7 @@ export { getReport, getReportIDFromLink, getRouteFromLink, + getDeletedParentActionMessageForChatReport, getLastVisibleMessage, navigateToDetailsPage, generateReportID,