From 16b3280bff67407008db18a5199593c52c5dca09 Mon Sep 17 00:00:00 2001 From: Agata Kosior Date: Wed, 3 Jan 2024 09:41:25 +0100 Subject: [PATCH 1/4] fix: remove doubled name for IOUs previews in SearchPage --- src/libs/OptionsListUtils.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index 0d5162399fcb..53ccb4c8ad4c 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -72,6 +72,7 @@ Onyx.connect({ const lastReportActions = {}; const allSortedReportActions = {}; const allReportActions = {}; +const visibleReportActionItems = {}; Onyx.connect({ key: ONYXKEYS.COLLECTION.REPORT_ACTIONS, callback: (actions, key) => { @@ -83,6 +84,18 @@ Onyx.connect({ const sortedReportActions = ReportActionUtils.getSortedReportActions(_.toArray(actions), true); allSortedReportActions[reportID] = sortedReportActions; lastReportActions[reportID] = _.first(sortedReportActions); + + // The report is only visible if it is the last action not deleted that + // does not match a closed or created state. + const reportActionsForDisplay = _.filter( + sortedReportActions, + (reportAction, actionKey) => + ReportActionUtils.shouldReportActionBeVisible(reportAction, actionKey) && + !ReportActionUtils.isWhisperAction(reportAction) && + reportAction.actionName !== CONST.REPORT.ACTIONS.TYPE.CREATED && + reportAction.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE, + ); + visibleReportActionItems[reportID] = reportActionsForDisplay[reportActionsForDisplay.length - 1]; }, }); @@ -513,7 +526,7 @@ function createOption(accountIDs, personalDetails, report, reportActions = {}, { const lastActorDetails = personalDetailMap[report.lastActorAccountID] || null; const lastActorDisplayName = hasMultipleParticipants && lastActorDetails && lastActorDetails.accountID !== currentUserAccountID ? lastActorDetails.firstName || lastActorDetails.displayName : ''; - let lastMessageText = lastActorDisplayName ? `${lastActorDisplayName}: ${lastMessageTextFromReport}` : lastMessageTextFromReport; + let lastMessageText = lastMessageTextFromReport; if (result.isArchivedRoom) { const archiveReason = @@ -525,12 +538,16 @@ function createOption(accountIDs, personalDetails, report, reportActions = {}, { }); } + const lastAction = visibleReportActionItems[report.reportID]; + if (result.isThread || result.isMoneyRequestReport) { result.alternateText = lastMessageTextFromReport.length > 0 ? lastMessageText : Localize.translate(preferredLocale, 'report.noActivityYet'); } else if (result.isChatRoom || result.isPolicyExpenseChat) { result.alternateText = showChatPreviewLine && !forcePolicyNamePreview && lastMessageText ? lastMessageText : subtitle; } else if (result.isTaskReport) { result.alternateText = showChatPreviewLine && lastMessageText ? lastMessageTextFromReport : Localize.translate(preferredLocale, 'report.noActivityYet'); + } else if (lastAction && lastAction.actionName !== CONST.REPORT.ACTIONS.TYPE.REPORTPREVIEW && lastActorDisplayName && lastMessageTextFromReport) { + result.alternateText = `${lastActorDisplayName}: ${lastMessageText}`; } else { result.alternateText = showChatPreviewLine && lastMessageText ? lastMessageText : LocalePhoneNumber.formatPhoneNumber(personalDetail.login); } From 11e24a34a8191d0d93ce9bd04c7877605bf8a78f Mon Sep 17 00:00:00 2001 From: Agata Kosior Date: Thu, 4 Jan 2024 19:43:59 +0100 Subject: [PATCH 2/4] fix: restore getDisplayNameOrDefault --- src/libs/OptionsListUtils.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index 767b468a8c26..667ae6910ba7 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -529,7 +529,9 @@ function createOption(accountIDs, personalDetails, report, reportActions = {}, { const lastMessageTextFromReport = getLastMessageTextForReport(report); const lastActorDetails = personalDetailMap[report.lastActorAccountID] || null; const lastActorDisplayName = - hasMultipleParticipants && lastActorDetails && lastActorDetails.accountID !== currentUserAccountID ? lastActorDetails.firstName || lastActorDetails.displayName : ''; + hasMultipleParticipants && lastActorDetails && lastActorDetails.accountID !== currentUserAccountID + ? lastActorDetails.firstName || PersonalDetailsUtils.getDisplayNameOrDefault(lastActorDetails) + : ''; let lastMessageText = lastMessageTextFromReport; if (result.isArchivedRoom) { From 37e83cdcf5e34bdeceec82a4d4bc5673e03d4eff Mon Sep 17 00:00:00 2001 From: Agata Kosior Date: Mon, 8 Jan 2024 09:49:07 +0100 Subject: [PATCH 3/4] fix: display actor name for threads --- src/libs/OptionsListUtils.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index a8ece15c7623..19c019b5e41c 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -545,6 +545,11 @@ function createOption(accountIDs, personalDetails, report, reportActions = {}, { } const lastAction = visibleReportActionItems[report.reportID]; + const shouldDisplayLastActorName = lastAction && lastAction.actionName !== CONST.REPORT.ACTIONS.TYPE.REPORTPREVIEW && lastAction.actionName !== CONST.REPORT.ACTIONS.TYPE.IOU + + if (shouldDisplayLastActorName && lastActorDisplayName && lastMessageTextFromReport) { + lastMessageText = `${lastActorDisplayName}: ${lastMessageTextFromReport}`; + } if (result.isThread || result.isMoneyRequestReport) { result.alternateText = lastMessageTextFromReport.length > 0 ? lastMessageText : Localize.translate(preferredLocale, 'report.noActivityYet'); @@ -552,8 +557,6 @@ function createOption(accountIDs, personalDetails, report, reportActions = {}, { result.alternateText = showChatPreviewLine && !forcePolicyNamePreview && lastMessageText ? lastMessageText : subtitle; } else if (result.isTaskReport) { result.alternateText = showChatPreviewLine && lastMessageText ? lastMessageTextFromReport : Localize.translate(preferredLocale, 'report.noActivityYet'); - } else if (lastAction && lastAction.actionName !== CONST.REPORT.ACTIONS.TYPE.REPORTPREVIEW && lastActorDisplayName && lastMessageTextFromReport) { - result.alternateText = `${lastActorDisplayName}: ${lastMessageText}`; } else { result.alternateText = showChatPreviewLine && lastMessageText ? lastMessageText : LocalePhoneNumber.formatPhoneNumber(personalDetail.login); } From 4b985db0d015d877e793f344e4dfb789ae391b22 Mon Sep 17 00:00:00 2001 From: Agata Kosior Date: Mon, 8 Jan 2024 10:02:29 +0100 Subject: [PATCH 4/4] fix: run prettier --- src/libs/OptionsListUtils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index 19c019b5e41c..9516b34dddaf 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -545,7 +545,7 @@ function createOption(accountIDs, personalDetails, report, reportActions = {}, { } const lastAction = visibleReportActionItems[report.reportID]; - const shouldDisplayLastActorName = lastAction && lastAction.actionName !== CONST.REPORT.ACTIONS.TYPE.REPORTPREVIEW && lastAction.actionName !== CONST.REPORT.ACTIONS.TYPE.IOU + const shouldDisplayLastActorName = lastAction && lastAction.actionName !== CONST.REPORT.ACTIONS.TYPE.REPORTPREVIEW && lastAction.actionName !== CONST.REPORT.ACTIONS.TYPE.IOU; if (shouldDisplayLastActorName && lastActorDisplayName && lastMessageTextFromReport) { lastMessageText = `${lastActorDisplayName}: ${lastMessageTextFromReport}`;