From a68d1ebed553e0b664542af50ac953082134722e Mon Sep 17 00:00:00 2001 From: Agata Kosior Date: Fri, 19 Jan 2024 19:39:30 +0000 Subject: [PATCH 01/14] refactor: move creating lastMessageText for archived rooms, create getLastActorDisplayName method --- src/libs/OptionsListUtils.js | 44 +++++++++++++++++++++++------------- src/libs/SidebarUtils.ts | 25 +++----------------- 2 files changed, 31 insertions(+), 38 deletions(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index e86c9daacb42..18a2475ca052 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -394,12 +394,27 @@ function getAllReportErrors(report, reportActions) { return allReportErrors; } +/** + * Get the last actor display name from last actor details. + * @param lastActorDetails + * @param hasMultipleParticipants + * @returns {String} + */ + +function getLastActorDisplayName(lastActorDetails, hasMultipleParticipants) { + return hasMultipleParticipants && lastActorDetails && lastActorDetails.accountID !== currentUserAccountID + ? lastActorDetails.firstName || PersonalDetailsUtils.getDisplayNameOrDefault(lastActorDetails) + : ''; +} + /** * Get the last message text from the report directly or from other sources for special cases. * @param {Object} report + * @param {Object | null} lastActorDetails + * @param {Object} [policy] * @returns {String} */ -function getLastMessageTextForReport(report) { +function getLastMessageTextForReport(report, lastActorDetails, policy) { const lastReportAction = _.find(allSortedReportActions[report.reportID], (reportAction) => ReportActionUtils.shouldReportActionBeVisibleAsLastAction(reportAction)); let lastMessageTextFromReport = ''; const lastActionName = lodashGet(lastReportAction, 'actionName', ''); @@ -436,6 +451,15 @@ function getLastMessageTextForReport(report) { lastMessageTextFromReport = lodashGet(lastReportAction, 'message[0].text', ''); } else if (ReportActionUtils.isCreatedTaskReportAction(lastReportAction)) { lastMessageTextFromReport = TaskUtils.getTaskCreatedMessage(lastReportAction); + } else if (ReportUtils.isArchivedRoom(report)) { + const archiveReason = + (lastReportActions[report.reportID] && lastReportActions[report.reportID].originalMessage && lastReportActions[report.reportID].originalMessage.reason) || + CONST.REPORT.ARCHIVE_REASON.DEFAULT; + + lastMessageTextFromReport = Localize.translate(preferredLocale, `reportArchiveReasons.${archiveReason}`, { + displayName: PersonalDetailsUtils.getDisplayNameOrDefault(lastActorDetails), + policyName: ReportUtils.getPolicyName(report, false, policy), + }); } return lastMessageTextFromReport || lodashGet(report, 'lastMessageText', ''); @@ -526,24 +550,11 @@ function createOption(accountIDs, personalDetails, report, reportActions = {}, { hasMultipleParticipants = personalDetailList.length > 1 || result.isChatRoom || result.isPolicyExpenseChat; subtitle = ReportUtils.getChatRoomSubtitle(report); - const lastMessageTextFromReport = getLastMessageTextForReport(report); const lastActorDetails = personalDetailMap[report.lastActorAccountID] || null; - const lastActorDisplayName = - hasMultipleParticipants && lastActorDetails && lastActorDetails.accountID !== currentUserAccountID - ? lastActorDetails.firstName || PersonalDetailsUtils.getDisplayNameOrDefault(lastActorDetails) - : ''; + const lastActorDisplayName = getLastActorDisplayName(lastActorDetails, hasMultipleParticipants); + const lastMessageTextFromReport = getLastMessageTextForReport(report, lastActorDetails); let lastMessageText = lastMessageTextFromReport; - if (result.isArchivedRoom) { - const archiveReason = - (lastReportActions[report.reportID] && lastReportActions[report.reportID].originalMessage && lastReportActions[report.reportID].originalMessage.reason) || - CONST.REPORT.ARCHIVE_REASON.DEFAULT; - lastMessageText = Localize.translate(preferredLocale, `reportArchiveReasons.${archiveReason}`, { - displayName: archiveReason.displayName || PersonalDetailsUtils.getDisplayNameOrDefault(lastActorDetails), - policyName: ReportUtils.getPolicyName(report), - }); - } - const lastAction = visibleReportActionItems[report.reportID]; const shouldDisplayLastActorName = lastAction && lastAction.actionName !== CONST.REPORT.ACTIONS.TYPE.REPORTPREVIEW && lastAction.actionName !== CONST.REPORT.ACTIONS.TYPE.IOU; @@ -2010,6 +2021,7 @@ export { getParticipantsOption, isSearchStringMatch, shouldOptionShowTooltip, + getLastActorDisplayName, getLastMessageTextForReport, getEnabledCategoriesCount, hasEnabledOptions, diff --git a/src/libs/SidebarUtils.ts b/src/libs/SidebarUtils.ts index 445d9dc30dd8..b5f821c087cc 100644 --- a/src/libs/SidebarUtils.ts +++ b/src/libs/SidebarUtils.ts @@ -349,12 +349,12 @@ function getOptionData({ // We only create tooltips for the first 10 users or so since some reports have hundreds of users, causing performance to degrade. const displayNamesWithTooltips = ReportUtils.getDisplayNamesWithTooltips((participantPersonalDetailList || []).slice(0, 10), hasMultipleParticipants); - const lastMessageTextFromReport = OptionsListUtils.getLastMessageTextForReport(report); // If the last actor's details are not currently saved in Onyx Collection, // then try to get that from the last report action if that action is valid // to get data from. let lastActorDetails: ActorDetails | null = report.lastActorAccountID && personalDetails?.[report.lastActorAccountID] ? personalDetails[report.lastActorAccountID] : null; + if (!lastActorDetails && visibleReportActionItems[report.reportID]) { const lastActorDisplayName = visibleReportActionItems[report.reportID]?.person?.[0]?.text; lastActorDetails = lastActorDisplayName @@ -365,31 +365,12 @@ function getOptionData({ : null; } - const shouldShowDisplayName = hasMultipleParticipants && lastActorDetails?.accountID && Number(lastActorDetails.accountID) !== currentUserAccountID; - const lastActorName = lastActorDetails?.firstName ?? lastActorDetails?.displayName; - const lastActorDisplayName = shouldShowDisplayName ? lastActorName : ''; + const lastMessageTextFromReport = OptionsListUtils.getLastMessageTextForReport(report, lastActorDetails, policy); + const lastActorDisplayName = OptionsListUtils.getLastActorDisplayName(lastActorDetails, hasMultipleParticipants); let lastMessageText = lastMessageTextFromReport; const reportAction = lastReportActions?.[report.reportID]; - if (result.isArchivedRoom) { - const archiveReason = (reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.CLOSED && reportAction?.originalMessage?.reason) || CONST.REPORT.ARCHIVE_REASON.DEFAULT; - - switch (archiveReason) { - case CONST.REPORT.ARCHIVE_REASON.ACCOUNT_CLOSED: - case CONST.REPORT.ARCHIVE_REASON.REMOVED_FROM_POLICY: - case CONST.REPORT.ARCHIVE_REASON.POLICY_DELETED: { - lastMessageText = Localize.translate(preferredLocale, `reportArchiveReasons.${archiveReason}`, { - policyName: ReportUtils.getPolicyName(report, false, policy), - displayName: PersonalDetailsUtils.getDisplayNameOrDefault(lastActorDetails), - }); - break; - } - default: { - lastMessageText = Localize.translate(preferredLocale, `reportArchiveReasons.default`); - } - } - } const isThreadMessage = ReportUtils.isThread(report) && reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT && reportAction?.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE; From 173215755e79403b87f6a7009efd658c26a08e28 Mon Sep 17 00:00:00 2001 From: Agata Kosior Date: Mon, 22 Jan 2024 12:11:40 +0000 Subject: [PATCH 02/14] fix: lint errors --- src/libs/SidebarUtils.ts | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/src/libs/SidebarUtils.ts b/src/libs/SidebarUtils.ts index b5f821c087cc..b10e04a896d2 100644 --- a/src/libs/SidebarUtils.ts +++ b/src/libs/SidebarUtils.ts @@ -16,7 +16,6 @@ import * as CollectionUtils from './CollectionUtils'; import * as LocalePhoneNumber from './LocalePhoneNumber'; import * as Localize from './Localize'; import * as OptionsListUtils from './OptionsListUtils'; -import * as PersonalDetailsUtils from './PersonalDetailsUtils'; import * as ReportActionsUtils from './ReportActionsUtils'; import * as ReportUtils from './ReportUtils'; import * as TaskUtils from './TaskUtils'; @@ -49,21 +48,6 @@ Onyx.connect({ }, }); -// Session can remain stale because the only way for the current user to change is to -// sign out and sign in, which would clear out all the Onyx -// data anyway and cause SidebarLinks to rerender. -let currentUserAccountID: number | undefined; -Onyx.connect({ - key: ONYXKEYS.SESSION, - callback: (session) => { - if (!session) { - return; - } - - currentUserAccountID = session.accountID; - }, -}); - let resolveSidebarIsReadyPromise: (args?: unknown[]) => void; let sidebarIsReadyPromise = new Promise((resolve) => { From 70de8b819915e7471eace638d4cadf2b7ed8fbd5 Mon Sep 17 00:00:00 2001 From: Agata Kosior Date: Tue, 23 Jan 2024 09:51:39 +0000 Subject: [PATCH 03/14] fix: apply requested changes --- src/libs/OptionsListUtils.js | 5 ++--- src/libs/SidebarUtils.ts | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index 75623403acb7..1f6c1c97a2ee 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -397,11 +397,10 @@ function getAllReportErrors(report, reportActions) { /** * Get the last actor display name from last actor details. - * @param lastActorDetails - * @param hasMultipleParticipants + * @param {Object | null} lastActorDetails + * @param {Boolean} hasMultipleParticipants * @returns {String} */ - function getLastActorDisplayName(lastActorDetails, hasMultipleParticipants) { return hasMultipleParticipants && lastActorDetails && lastActorDetails.accountID !== currentUserAccountID ? lastActorDetails.firstName || PersonalDetailsUtils.getDisplayNameOrDefault(lastActorDetails) diff --git a/src/libs/SidebarUtils.ts b/src/libs/SidebarUtils.ts index b10e04a896d2..73831d1d008b 100644 --- a/src/libs/SidebarUtils.ts +++ b/src/libs/SidebarUtils.ts @@ -349,8 +349,8 @@ function getOptionData({ : null; } - const lastMessageTextFromReport = OptionsListUtils.getLastMessageTextForReport(report, lastActorDetails, policy); const lastActorDisplayName = OptionsListUtils.getLastActorDisplayName(lastActorDetails, hasMultipleParticipants); + const lastMessageTextFromReport = OptionsListUtils.getLastMessageTextForReport(report, lastActorDetails, policy); let lastMessageText = lastMessageTextFromReport; From 1f150d960749666663aedfd10116057150fa18ac Mon Sep 17 00:00:00 2001 From: Agata Kosior Date: Wed, 24 Jan 2024 12:06:27 +0000 Subject: [PATCH 04/14] fix: do not show latest activity for workspaces on search page --- src/libs/OptionsListUtils.js | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index 1f6c1c97a2ee..a6a6c6e41027 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -1441,16 +1441,11 @@ function getOptions( if (accountIDs.length <= 1 && !isPolicyExpenseChat && !isChatRoom) { reportMapForAccountIDs[accountIDs[0]] = report; } - const isSearchingSomeonesPolicyExpenseChat = !report.isOwnPolicyExpenseChat && searchValue !== ''; - - // Checks to see if the current user is the admin of the policy, if so the policy - // name preview will be shown. - const isPolicyChatAdmin = ReportUtils.isPolicyExpenseChatAdmin(report, policies); allReportOptions.push( createOption(accountIDs, personalDetails, report, reportActions, { showChatPreviewLine, - forcePolicyNamePreview: isPolicyExpenseChat ? isSearchingSomeonesPolicyExpenseChat || isPolicyChatAdmin : forcePolicyNamePreview, + forcePolicyNamePreview, }), ); }); @@ -1962,9 +1957,9 @@ function formatSectionsFromSearchTerm(searchTerm, selectedOptions, filteredRecen title: undefined, data: shouldGetOptionDetails ? _.map(selectedOptions, (participant) => { - const isPolicyExpenseChat = lodashGet(participant, 'isPolicyExpenseChat', false); - return isPolicyExpenseChat ? getPolicyExpenseReportOption(participant) : getParticipantsOption(participant, personalDetails); - }) + const isPolicyExpenseChat = lodashGet(participant, 'isPolicyExpenseChat', false); + return isPolicyExpenseChat ? getPolicyExpenseReportOption(participant) : getParticipantsOption(participant, personalDetails); + }) : selectedOptions, shouldShow: !_.isEmpty(selectedOptions), indexOffset, @@ -1988,9 +1983,9 @@ function formatSectionsFromSearchTerm(searchTerm, selectedOptions, filteredRecen title: undefined, data: shouldGetOptionDetails ? _.map(selectedParticipantsWithoutDetails, (participant) => { - const isPolicyExpenseChat = lodashGet(participant, 'isPolicyExpenseChat', false); - return isPolicyExpenseChat ? getPolicyExpenseReportOption(participant) : getParticipantsOption(participant, personalDetails); - }) + const isPolicyExpenseChat = lodashGet(participant, 'isPolicyExpenseChat', false); + return isPolicyExpenseChat ? getPolicyExpenseReportOption(participant) : getParticipantsOption(participant, personalDetails); + }) : selectedParticipantsWithoutDetails, shouldShow: !_.isEmpty(selectedParticipantsWithoutDetails), indexOffset, From c749e0b511b330b75fd98f9407e0d8bf6b61c618 Mon Sep 17 00:00:00 2001 From: Agata Kosior Date: Wed, 24 Jan 2024 12:16:57 +0000 Subject: [PATCH 05/14] fix: run prettier --- src/libs/OptionsListUtils.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index a6a6c6e41027..ea5577d8ac80 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -1957,9 +1957,9 @@ function formatSectionsFromSearchTerm(searchTerm, selectedOptions, filteredRecen title: undefined, data: shouldGetOptionDetails ? _.map(selectedOptions, (participant) => { - const isPolicyExpenseChat = lodashGet(participant, 'isPolicyExpenseChat', false); - return isPolicyExpenseChat ? getPolicyExpenseReportOption(participant) : getParticipantsOption(participant, personalDetails); - }) + const isPolicyExpenseChat = lodashGet(participant, 'isPolicyExpenseChat', false); + return isPolicyExpenseChat ? getPolicyExpenseReportOption(participant) : getParticipantsOption(participant, personalDetails); + }) : selectedOptions, shouldShow: !_.isEmpty(selectedOptions), indexOffset, @@ -1983,9 +1983,9 @@ function formatSectionsFromSearchTerm(searchTerm, selectedOptions, filteredRecen title: undefined, data: shouldGetOptionDetails ? _.map(selectedParticipantsWithoutDetails, (participant) => { - const isPolicyExpenseChat = lodashGet(participant, 'isPolicyExpenseChat', false); - return isPolicyExpenseChat ? getPolicyExpenseReportOption(participant) : getParticipantsOption(participant, personalDetails); - }) + const isPolicyExpenseChat = lodashGet(participant, 'isPolicyExpenseChat', false); + return isPolicyExpenseChat ? getPolicyExpenseReportOption(participant) : getParticipantsOption(participant, personalDetails); + }) : selectedParticipantsWithoutDetails, shouldShow: !_.isEmpty(selectedParticipantsWithoutDetails), indexOffset, From 37c445e3ee7f3590eb44a126759349dc159c825a Mon Sep 17 00:00:00 2001 From: Agata Kosior Date: Wed, 24 Jan 2024 12:23:08 +0000 Subject: [PATCH 06/14] fix: typing --- 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 ea5577d8ac80..e340afe65a2f 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -411,7 +411,7 @@ function getLastActorDisplayName(lastActorDetails, hasMultipleParticipants) { * Get the last message text from the report directly or from other sources for special cases. * @param {Object} report * @param {Object | null} lastActorDetails - * @param {Object} [policy] + * @param {Object | null} [policy] * @returns {String} */ function getLastMessageTextForReport(report, lastActorDetails, policy) { From 62078a0fdc42e54d84d655c5d50dc33f67847bdf Mon Sep 17 00:00:00 2001 From: Agata Kosior Date: Thu, 25 Jan 2024 09:49:29 +0000 Subject: [PATCH 07/14] fix: keep the old logic for displaying archivedRoom message --- src/libs/OptionsListUtils.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index 44ebe56ee97d..9a8171ad986c 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -458,10 +458,20 @@ function getLastMessageTextForReport(report, lastActorDetails, policy) { (lastReportActions[report.reportID] && lastReportActions[report.reportID].originalMessage && lastReportActions[report.reportID].originalMessage.reason) || CONST.REPORT.ARCHIVE_REASON.DEFAULT; - lastMessageTextFromReport = Localize.translate(preferredLocale, `reportArchiveReasons.${archiveReason}`, { - displayName: PersonalDetailsUtils.getDisplayNameOrDefault(lastActorDetails), - policyName: ReportUtils.getPolicyName(report, false, policy), - }); + switch (archiveReason) { + case CONST.REPORT.ARCHIVE_REASON.ACCOUNT_CLOSED: + case CONST.REPORT.ARCHIVE_REASON.REMOVED_FROM_POLICY: + case CONST.REPORT.ARCHIVE_REASON.POLICY_DELETED: { + lastMessageTextFromReport = Localize.translate(preferredLocale, `reportArchiveReasons.${archiveReason}`, { + displayName: PersonalDetailsUtils.getDisplayNameOrDefault(lastActorDetails), + policyName: ReportUtils.getPolicyName(report, false, policy), + }); + break; + } + default: { + lastMessageTextFromReport = Localize.translate(preferredLocale, `reportArchiveReasons.default`); + } + } } return lastMessageTextFromReport || lodashGet(report, 'lastMessageText', ''); From 19e149a8ad4c54bbd783df432d4e6fdef287eb98 Mon Sep 17 00:00:00 2001 From: Agata Kosior Date: Fri, 26 Jan 2024 09:18:58 +0000 Subject: [PATCH 08/14] fix: change condition order --- src/libs/OptionsListUtils.js | 40 ++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index 9a8171ad986c..c7604783cd4a 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -421,7 +421,26 @@ function getLastMessageTextForReport(report, lastActorDetails, policy) { let lastMessageTextFromReport = ''; const lastActionName = lodashGet(lastReportAction, 'actionName', ''); - if (ReportActionUtils.isMoneyRequestAction(lastReportAction)) { + if (ReportUtils.isArchivedRoom(report)) { + const archiveReason = + (lastReportActions[report.reportID] && lastReportActions[report.reportID].originalMessage && lastReportActions[report.reportID].originalMessage.reason) || + CONST.REPORT.ARCHIVE_REASON.DEFAULT; + + switch (archiveReason) { + case CONST.REPORT.ARCHIVE_REASON.ACCOUNT_CLOSED: + case CONST.REPORT.ARCHIVE_REASON.REMOVED_FROM_POLICY: + case CONST.REPORT.ARCHIVE_REASON.POLICY_DELETED: { + lastMessageTextFromReport = Localize.translate(preferredLocale, `reportArchiveReasons.${archiveReason}`, { + displayName: PersonalDetailsUtils.getDisplayNameOrDefault(lastActorDetails), + policyName: ReportUtils.getPolicyName(report, false, policy), + }); + break; + } + default: { + lastMessageTextFromReport = Localize.translate(preferredLocale, `reportArchiveReasons.default`); + } + } + } else if (ReportActionUtils.isMoneyRequestAction(lastReportAction)) { const properSchemaForMoneyRequestMessage = ReportUtils.getReportPreviewMessage(report, lastReportAction, true, false, null, true); lastMessageTextFromReport = ReportUtils.formatReportLastMessageText(properSchemaForMoneyRequestMessage); } else if (ReportActionUtils.isReportPreviewAction(lastReportAction)) { @@ -453,25 +472,6 @@ function getLastMessageTextForReport(report, lastActorDetails, policy) { lastMessageTextFromReport = lodashGet(lastReportAction, 'message[0].text', ''); } else if (ReportActionUtils.isCreatedTaskReportAction(lastReportAction)) { lastMessageTextFromReport = TaskUtils.getTaskCreatedMessage(lastReportAction); - } else if (ReportUtils.isArchivedRoom(report)) { - const archiveReason = - (lastReportActions[report.reportID] && lastReportActions[report.reportID].originalMessage && lastReportActions[report.reportID].originalMessage.reason) || - CONST.REPORT.ARCHIVE_REASON.DEFAULT; - - switch (archiveReason) { - case CONST.REPORT.ARCHIVE_REASON.ACCOUNT_CLOSED: - case CONST.REPORT.ARCHIVE_REASON.REMOVED_FROM_POLICY: - case CONST.REPORT.ARCHIVE_REASON.POLICY_DELETED: { - lastMessageTextFromReport = Localize.translate(preferredLocale, `reportArchiveReasons.${archiveReason}`, { - displayName: PersonalDetailsUtils.getDisplayNameOrDefault(lastActorDetails), - policyName: ReportUtils.getPolicyName(report, false, policy), - }); - break; - } - default: { - lastMessageTextFromReport = Localize.translate(preferredLocale, `reportArchiveReasons.default`); - } - } } return lastMessageTextFromReport || lodashGet(report, 'lastMessageText', ''); From 9a42d3a357b62645f8a33e081c09e04f7ed2d2fe Mon Sep 17 00:00:00 2001 From: Agata Kosior Date: Fri, 26 Jan 2024 10:52:12 +0000 Subject: [PATCH 09/14] fix: fix types --- src/libs/OptionsListUtils.ts | 14 ++++---------- src/libs/SidebarUtils.ts | 9 +-------- 2 files changed, 5 insertions(+), 18 deletions(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index bde903fb02af..eef63431a898 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -489,17 +489,11 @@ function getAllReportErrors(report: OnyxEntry, reportActions: OnyxEntry< return allReportErrors; } -type ActorDetails = { - displayName?: string; - firstName?: string; - lastName?: string; - accountID?: number; -}; /** * Get the last actor display name from last actor details. */ -function getLastActorDisplayName(lastActorDetails: ActorDetails | null, hasMultipleParticipants: boolean) { +function getLastActorDisplayName(lastActorDetails: Partial | null, hasMultipleParticipants: boolean) { return hasMultipleParticipants && lastActorDetails && lastActorDetails.accountID !== currentUserAccountID ? lastActorDetails.firstName ?? PersonalDetailsUtils.getDisplayNameOrDefault(lastActorDetails) : ''; @@ -508,13 +502,13 @@ function getLastActorDisplayName(lastActorDetails: ActorDetails | null, hasMulti /** * Get the last message text from the report directly or from other sources for special cases. */ -function getLastMessageTextForReport(report: OnyxEntry, lastActorDetails: ActorDetails | null, policy?: OnyxEntry): string { +function getLastMessageTextForReport(report: OnyxEntry, lastActorDetails: Partial | null, policy?: OnyxEntry): string { const lastReportAction = allSortedReportActions[report?.reportID ?? '']?.find((reportAction) => ReportActionUtils.shouldReportActionBeVisibleAsLastAction(reportAction)) ?? null; let lastMessageTextFromReport = ''; const lastActionName = lastReportAction?.actionName ?? ''; - if (ReportUtils.isArchivedRoom(report)) { - const archiveReason = (lastReportAction?.originalMessage?.reason) || CONST.REPORT.ARCHIVE_REASON.DEFAULT; + if (ReportUtils.isArchivedRoom(report) && lastReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.CLOSED) { + const archiveReason = lastReportAction?.originalMessage?.reason || CONST.REPORT.ARCHIVE_REASON.DEFAULT; switch (archiveReason) { case CONST.REPORT.ARCHIVE_REASON.ACCOUNT_CLOSED: case CONST.REPORT.ARCHIVE_REASON.REMOVED_FROM_POLICY: diff --git a/src/libs/SidebarUtils.ts b/src/libs/SidebarUtils.ts index dd353874f7f1..6e0fd8f81152 100644 --- a/src/libs/SidebarUtils.ts +++ b/src/libs/SidebarUtils.ts @@ -223,13 +223,6 @@ function getOrderedReportIDs( return LHNReports; } -type ActorDetails = { - displayName?: string; - firstName?: string; - lastName?: string; - accountID?: number; -}; - /** * Gets all the data necessary for rendering an OptionRowLHN component */ @@ -338,7 +331,7 @@ function getOptionData({ // If the last actor's details are not currently saved in Onyx Collection, // then try to get that from the last report action if that action is valid // to get data from. - let lastActorDetails: ActorDetails | null = report.lastActorAccountID && personalDetails?.[report.lastActorAccountID] ? personalDetails[report.lastActorAccountID] : null; + let lastActorDetails: Partial | null = report.lastActorAccountID && personalDetails?.[report.lastActorAccountID] ? personalDetails[report.lastActorAccountID] : null; if (!lastActorDetails && visibleReportActionItems[report.reportID]) { const lastActorDisplayName = visibleReportActionItems[report.reportID]?.person?.[0]?.text; From 285821c60cd01a6e7fe3f306c6f638535fdc5f8c Mon Sep 17 00:00:00 2001 From: Agata Kosior Date: Fri, 26 Jan 2024 11:21:09 +0000 Subject: [PATCH 10/14] fix: check the last unfiltered action --- src/libs/OptionsListUtils.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index eef63431a898..cb74a3d37d6d 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -504,11 +504,13 @@ function getLastActorDisplayName(lastActorDetails: Partial | nu */ function getLastMessageTextForReport(report: OnyxEntry, lastActorDetails: Partial | null, policy?: OnyxEntry): string { const lastReportAction = allSortedReportActions[report?.reportID ?? '']?.find((reportAction) => ReportActionUtils.shouldReportActionBeVisibleAsLastAction(reportAction)) ?? null; + // some types of actions are filtered out for lastReportAction, in some cases we need to check the actual last action + const lastOriginalReportAction = lastReportActions[report?.reportID ?? ''] ?? null; let lastMessageTextFromReport = ''; const lastActionName = lastReportAction?.actionName ?? ''; - if (ReportUtils.isArchivedRoom(report) && lastReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.CLOSED) { - const archiveReason = lastReportAction?.originalMessage?.reason || CONST.REPORT.ARCHIVE_REASON.DEFAULT; + if (ReportUtils.isArchivedRoom(report) && lastOriginalReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.CLOSED) { + const archiveReason = lastOriginalReportAction?.originalMessage?.reason || CONST.REPORT.ARCHIVE_REASON.DEFAULT; switch (archiveReason) { case CONST.REPORT.ARCHIVE_REASON.ACCOUNT_CLOSED: case CONST.REPORT.ARCHIVE_REASON.REMOVED_FROM_POLICY: From 27a1234df6b42c639bd9bce5c6eb6421eeef5115 Mon Sep 17 00:00:00 2001 From: Agata Kosior Date: Fri, 26 Jan 2024 11:34:17 +0000 Subject: [PATCH 11/14] fix: run prettier --- src/libs/OptionsListUtils.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index cb74a3d37d6d..30c9eec6cf6d 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -489,7 +489,6 @@ function getAllReportErrors(report: OnyxEntry, reportActions: OnyxEntry< return allReportErrors; } - /** * Get the last actor display name from last actor details. */ @@ -509,7 +508,7 @@ function getLastMessageTextForReport(report: OnyxEntry, lastActorDetails let lastMessageTextFromReport = ''; const lastActionName = lastReportAction?.actionName ?? ''; - if (ReportUtils.isArchivedRoom(report) && lastOriginalReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.CLOSED) { + if (ReportUtils.isArchivedRoom(report) && lastOriginalReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.CLOSED) { const archiveReason = lastOriginalReportAction?.originalMessage?.reason || CONST.REPORT.ARCHIVE_REASON.DEFAULT; switch (archiveReason) { case CONST.REPORT.ARCHIVE_REASON.ACCOUNT_CLOSED: From 00910417d069111136a29c024702b9a692952ee6 Mon Sep 17 00:00:00 2001 From: Agata Kosior Date: Fri, 26 Jan 2024 11:54:21 +0000 Subject: [PATCH 12/14] fix: fix test --- tests/unit/SidebarTest.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/unit/SidebarTest.js b/tests/unit/SidebarTest.js index 8f9d7492a1f5..dba1365626ba 100644 --- a/tests/unit/SidebarTest.js +++ b/tests/unit/SidebarTest.js @@ -56,6 +56,14 @@ describe('Sidebar', () => { stateNum: CONST.REPORT.STATE_NUM.APPROVED, }; + const action = { + ...LHNTestUtils.getFakeReportAction('email1@test.com', 3, true), + actionName: 'CLOSED', + originalMessage: { + reason: CONST.REPORT.ARCHIVE_REASON.DEFAULT, + }, + }; + // Given the user is in all betas const betas = [CONST.BETAS.DEFAULT_ROOMS]; LHNTestUtils.getDefaultRenderedSidebarLinks('0'); @@ -69,6 +77,7 @@ describe('Sidebar', () => { [ONYXKEYS.PERSONAL_DETAILS_LIST]: LHNTestUtils.fakePersonalDetails, [ONYXKEYS.IS_LOADING_APP]: false, [`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`]: report, + [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`]: {[action.reportActionId]: action}, }), ) .then(() => { From d311da4e71855b80f839b6a5910d43c093760529 Mon Sep 17 00:00:00 2001 From: Agata Kosior Date: Tue, 30 Jan 2024 09:58:24 +0000 Subject: [PATCH 13/14] fix: fix condition displaying the archiver room preview --- src/libs/OptionsListUtils.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 931d857a93fe..9b51de41095d 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -508,8 +508,8 @@ function getLastMessageTextForReport(report: OnyxEntry, lastActorDetails let lastMessageTextFromReport = ''; const lastActionName = lastReportAction?.actionName ?? ''; - if (ReportUtils.isArchivedRoom(report) && lastOriginalReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.CLOSED) { - const archiveReason = lastOriginalReportAction?.originalMessage?.reason || CONST.REPORT.ARCHIVE_REASON.DEFAULT; + if (ReportUtils.isArchivedRoom(report)) { + const archiveReason = lastOriginalReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.CLOSED && lastOriginalReportAction?.originalMessage?.reason || CONST.REPORT.ARCHIVE_REASON.DEFAULT; switch (archiveReason) { case CONST.REPORT.ARCHIVE_REASON.ACCOUNT_CLOSED: case CONST.REPORT.ARCHIVE_REASON.REMOVED_FROM_POLICY: From cba06080f5501038a8b9ef3fa156c532054af3e5 Mon Sep 17 00:00:00 2001 From: Agata Kosior Date: Tue, 30 Jan 2024 09:59:05 +0000 Subject: [PATCH 14/14] fix: run prettier --- src/libs/OptionsListUtils.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 9b51de41095d..00e9aea7ad81 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -509,7 +509,8 @@ function getLastMessageTextForReport(report: OnyxEntry, lastActorDetails const lastActionName = lastReportAction?.actionName ?? ''; if (ReportUtils.isArchivedRoom(report)) { - const archiveReason = lastOriginalReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.CLOSED && lastOriginalReportAction?.originalMessage?.reason || CONST.REPORT.ARCHIVE_REASON.DEFAULT; + const archiveReason = + (lastOriginalReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.CLOSED && lastOriginalReportAction?.originalMessage?.reason) || CONST.REPORT.ARCHIVE_REASON.DEFAULT; switch (archiveReason) { case CONST.REPORT.ARCHIVE_REASON.ACCOUNT_CLOSED: case CONST.REPORT.ARCHIVE_REASON.REMOVED_FROM_POLICY: