From 482b6dc6d27c1d33d50ebbd3c83425abd8d907e6 Mon Sep 17 00:00:00 2001 From: tienifr Date: Fri, 21 Jul 2023 16:01:49 +0700 Subject: [PATCH 1/5] fix: welcome message flickers in LHN after message deletion --- src/libs/OptionsListUtils.js | 6 +----- src/libs/ReportActionsUtils.js | 22 +++++++++++++++++----- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index 2acb1f51cbe7..41df0b6348a3 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -409,11 +409,7 @@ function getLastMessageTextForReport(report) { // Yeah this is a bit ugly. If the latest report action that is not a whisper has been moderated as pending remove, then set the last message text to the text of the latest visible action that is not a whisper. const lastNonWhisper = _.find(allSortedReportActions[report.reportID], (action) => !ReportActionUtils.isWhisperAction(action)) || {}; if (ReportActionUtils.isPendingRemove(lastNonWhisper)) { - const latestVisibleAction = - _.find( - allSortedReportActions[report.reportID], - (action) => ReportActionUtils.shouldReportActionBeVisible(action, action.reportActionID) && !ReportActionUtils.isWhisperAction(action), - ) || {}; + const latestVisibleAction = _.find(allSortedReportActions[report.reportID], (action) => ReportActionUtils.shouldReportActionBeVisibleAsLastAction(action)) || {}; lastMessageTextFromReport = lodashGet(latestVisibleAction, 'message[0].text', ''); } } diff --git a/src/libs/ReportActionsUtils.js b/src/libs/ReportActionsUtils.js index dbfd57a85c43..085822ac3e2e 100644 --- a/src/libs/ReportActionsUtils.js +++ b/src/libs/ReportActionsUtils.js @@ -85,6 +85,10 @@ function isReportPreviewAction(reportAction) { return lodashGet(reportAction, 'actionName', '') === CONST.REPORT.ACTIONS.TYPE.REPORTPREVIEW; } +function isWhisperAction(action) { + return (action.whisperedToAccountIDs || []).length > 0; +} + /** * @param {Object} reportAction * @returns {Boolean} @@ -277,7 +281,7 @@ function isConsecutiveActionMadeByPreviousActor(reportActions, actionIndex) { */ function getLastVisibleAction(reportID, actionsToMerge = {}) { const actions = _.toArray(lodashMerge({}, allReportActions[reportID], actionsToMerge)); - const visibleActions = _.filter(actions, (action) => !isDeletedAction(action)); + const visibleActions = _.filter(actions, (action) => shouldReportActionBeVisibleAsLastAction(action)); if (_.isEmpty(visibleActions)) { return {}; @@ -377,6 +381,17 @@ function shouldReportActionBeVisible(reportAction, key) { return !isDeleted || isPending || isDeletedParentAction; } +/** + * Checks if a reportAction is fit for display as report last action, meaning that it's not deprecated, is of a valid + * and supported type, it's not deleted and also not closed. + * + * @param {Object} reportAction + * @returns {Boolean} + */ +function shouldReportActionBeVisibleAsLastAction(reportAction) { + return shouldReportActionBeVisible(reportAction, reportAction.reportActionID) && !isWhisperAction(reportAction) && !isDeletedAction(reportAction); +} + /** * A helper method to filter out report actions keyed by sequenceNumbers. * @@ -535,10 +550,6 @@ function isMessageDeleted(reportAction) { return lodashGet(reportAction, ['message', 0, 'isDeletedParentAction'], false); } -function isWhisperAction(action) { - return (action.whisperedToAccountIDs || []).length > 0; -} - export { getSortedReportActions, getLastVisibleAction, @@ -547,6 +558,7 @@ export { extractLinksFromMessageHtml, isDeletedAction, shouldReportActionBeVisible, + shouldReportActionBeVisibleAsLastAction, isReportActionDeprecated, isConsecutiveActionMadeByPreviousActor, getSortedReportActionsForDisplay, From f0e0b8c795df9f29830c623f6004536df4b1cee7 Mon Sep 17 00:00:00 2001 From: tienifr Date: Fri, 21 Jul 2023 17:03:56 +0700 Subject: [PATCH 2/5] fix lint --- src/libs/ReportActionsUtils.js | 86 +++++++++++++++++----------------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/src/libs/ReportActionsUtils.js b/src/libs/ReportActionsUtils.js index 085822ac3e2e..1718360aea18 100644 --- a/src/libs/ReportActionsUtils.js +++ b/src/libs/ReportActionsUtils.js @@ -274,49 +274,6 @@ function isConsecutiveActionMadeByPreviousActor(reportActions, actionIndex) { return currentAction.actorAccountID === previousAction.actorAccountID; } -/** - * @param {String} reportID - * @param {Object} [actionsToMerge] - * @return {Object} - */ -function getLastVisibleAction(reportID, actionsToMerge = {}) { - const actions = _.toArray(lodashMerge({}, allReportActions[reportID], actionsToMerge)); - const visibleActions = _.filter(actions, (action) => shouldReportActionBeVisibleAsLastAction(action)); - - if (_.isEmpty(visibleActions)) { - return {}; - } - - return _.max(visibleActions, (action) => moment.utc(action.created).valueOf()); -} - -/** - * @param {String} reportID - * @param {Object} [actionsToMerge] - * @return {Object} - */ -function getLastVisibleMessage(reportID, actionsToMerge = {}) { - const lastVisibleAction = getLastVisibleAction(reportID, actionsToMerge); - const message = lodashGet(lastVisibleAction, ['message', 0], {}); - - if (isReportMessageAttachment(message)) { - return { - lastMessageTranslationKey: CONST.TRANSLATION_KEYS.ATTACHMENT, - }; - } - - if (isCreatedAction(lastVisibleAction)) { - return { - lastMessageText: '', - }; - } - - 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(), - }; -} - /** * Checks if a reportAction is deprecated. * @@ -392,6 +349,49 @@ function shouldReportActionBeVisibleAsLastAction(reportAction) { return shouldReportActionBeVisible(reportAction, reportAction.reportActionID) && !isWhisperAction(reportAction) && !isDeletedAction(reportAction); } +/** + * @param {String} reportID + * @param {Object} [actionsToMerge] + * @return {Object} + */ +function getLastVisibleAction(reportID, actionsToMerge = {}) { + const actions = _.toArray(lodashMerge({}, allReportActions[reportID], actionsToMerge)); + const visibleActions = _.filter(actions, (action) => shouldReportActionBeVisibleAsLastAction(action)); + + if (_.isEmpty(visibleActions)) { + return {}; + } + + return _.max(visibleActions, (action) => moment.utc(action.created).valueOf()); +} + +/** + * @param {String} reportID + * @param {Object} [actionsToMerge] + * @return {Object} + */ +function getLastVisibleMessage(reportID, actionsToMerge = {}) { + const lastVisibleAction = getLastVisibleAction(reportID, actionsToMerge); + const message = lodashGet(lastVisibleAction, ['message', 0], {}); + + if (isReportMessageAttachment(message)) { + return { + lastMessageTranslationKey: CONST.TRANSLATION_KEYS.ATTACHMENT, + }; + } + + if (isCreatedAction(lastVisibleAction)) { + return { + lastMessageText: '', + }; + } + + 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(), + }; +} + /** * A helper method to filter out report actions keyed by sequenceNumbers. * From 62872104cd42e74ccc2c798dbf26be6cea1fd57d Mon Sep 17 00:00:00 2001 From: tienifr Date: Fri, 21 Jul 2023 17:05:43 +0700 Subject: [PATCH 3/5] add comment --- src/libs/ReportActionsUtils.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/ReportActionsUtils.js b/src/libs/ReportActionsUtils.js index 1718360aea18..e4cc6ced62ec 100644 --- a/src/libs/ReportActionsUtils.js +++ b/src/libs/ReportActionsUtils.js @@ -339,8 +339,8 @@ function shouldReportActionBeVisible(reportAction, key) { } /** - * Checks if a reportAction is fit for display as report last action, meaning that it's not deprecated, is of a valid - * and supported type, it's not deleted and also not closed. + * Checks if a reportAction is fit for display as report last action, meaning that + * it satisfies shouldReportActionBeVisible, it's not whisper action and not deleted. * * @param {Object} reportAction * @returns {Boolean} From 9bd655d21724ebbbbe812209534c52c159c506fe Mon Sep 17 00:00:00 2001 From: tienifr Date: Sun, 23 Jul 2023 23:31:15 +0700 Subject: [PATCH 4/5] remove isDeletedAction check --- src/libs/ReportActionsUtils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReportActionsUtils.js b/src/libs/ReportActionsUtils.js index e4cc6ced62ec..d4c52142b1f6 100644 --- a/src/libs/ReportActionsUtils.js +++ b/src/libs/ReportActionsUtils.js @@ -346,7 +346,7 @@ function shouldReportActionBeVisible(reportAction, key) { * @returns {Boolean} */ function shouldReportActionBeVisibleAsLastAction(reportAction) { - return shouldReportActionBeVisible(reportAction, reportAction.reportActionID) && !isWhisperAction(reportAction) && !isDeletedAction(reportAction); + return shouldReportActionBeVisible(reportAction, reportAction.reportActionID) && !isWhisperAction(reportAction); } /** From 77bd9aa14a0449bd845cdbb7089ffd4898304bbe Mon Sep 17 00:00:00 2001 From: tienifr Date: Mon, 24 Jul 2023 12:31:49 +0700 Subject: [PATCH 5/5] Revert "remove isDeletedAction check" This reverts commit 9bd655d21724ebbbbe812209534c52c159c506fe. --- src/libs/ReportActionsUtils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReportActionsUtils.js b/src/libs/ReportActionsUtils.js index d4c52142b1f6..e4cc6ced62ec 100644 --- a/src/libs/ReportActionsUtils.js +++ b/src/libs/ReportActionsUtils.js @@ -346,7 +346,7 @@ function shouldReportActionBeVisible(reportAction, key) { * @returns {Boolean} */ function shouldReportActionBeVisibleAsLastAction(reportAction) { - return shouldReportActionBeVisible(reportAction, reportAction.reportActionID) && !isWhisperAction(reportAction); + return shouldReportActionBeVisible(reportAction, reportAction.reportActionID) && !isWhisperAction(reportAction) && !isDeletedAction(reportAction); } /**