From a5c93ee41a875b03208819896e23252612469261 Mon Sep 17 00:00:00 2001 From: c3024 Date: Tue, 17 Sep 2024 11:36:24 +0530 Subject: [PATCH 1/4] fix last accessed report for new user --- src/libs/ReportUtils.ts | 31 +++++-------------------------- 1 file changed, 5 insertions(+), 26 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index a92c89479c74..e8247499b249 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -625,14 +625,6 @@ Onyx.connect({ }, }); -let isFirstTimeNewExpensifyUser = false; -Onyx.connect({ - key: ONYXKEYS.NVP_IS_FIRST_TIME_NEW_EXPENSIFY_USER, - callback: (value) => { - isFirstTimeNewExpensifyUser = value ?? false; - }, -}); - let onboarding: OnyxEntry; Onyx.connect({ key: ONYXKEYS.NVP_ONBOARDING, @@ -1336,26 +1328,13 @@ function findLastAccessedReport(ignoreDomainRooms: boolean, openOnAdminRoom = fa }); } - if (isFirstTimeNewExpensifyUser) { - // Filter out the systemChat report from the reports list, as we don't want to drop the user into that report over Concierge when they first log in - reportsValues = reportsValues.filter((report) => !isSystemChat(report)) ?? []; - if (reportsValues.length === 1) { - return reportsValues[0]; - } + // Filter out the system chat (Expensify chat) because the composer is disabled in it, + // and it prompts the user to use the Concierge chat instead. + reportsValues = reportsValues.filter((report) => !isSystemChat(report)) ?? []; - return adminReport ?? reportsValues.find((report) => !isConciergeChatReport(report)); - } - - // If we only have two reports and one of them is the system chat, filter it out so we don't - // overwrite showing the concierge chat - const hasSystemChat = reportsValues.find((report) => isSystemChat(report)) ?? false; - if (reportsValues.length === 2 && hasSystemChat) { - reportsValues = reportsValues.filter((report) => !isSystemChat(report)) ?? []; - } - - // We are getting the last read report from the metadata of the report. + // At least two reports remain: self DM and Concierge chat. + // Return the most recently visited report. Get the last read report from the report metadata. const lastRead = getMostRecentlyVisitedReport(reportsValues, allReportMetadata); - return adminReport ?? lastRead; } From ee02e42a2faefb7a17b3296ca146cc0cf691d035 Mon Sep 17 00:00:00 2001 From: c3024 Date: Wed, 18 Sep 2024 20:02:41 +0530 Subject: [PATCH 2/4] remove deprecated getParentReportAction --- src/libs/ReportUtils.ts | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index e8247499b249..1820a0c00b13 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -492,6 +492,8 @@ type ParsingDetails = { policyID?: string; }; +type Thread = Report & {parentReportID: string; parentReportActionID: string}; + let currentUserEmail: string | undefined; let currentUserPrivateDomain: string | undefined; let currentUserAccountID: number | undefined; @@ -1104,14 +1106,14 @@ function isWorkspaceTaskReport(report: OnyxEntry): boolean { /** * Returns true if report has a parent */ -function isThread(report: OnyxInputOrEntry): boolean { +function isThread(report: OnyxInputOrEntry): report is Thread { return !!(report?.parentReportID && report?.parentReportActionID); } /** * Returns true if report is of type chat and has a parent and is therefore a Thread. */ -function isChatThread(report: OnyxInputOrEntry): boolean { +function isChatThread(report: OnyxInputOrEntry): report is Thread { return isThread(report) && report?.type === CONST.REPORT.TYPE.CHAT; } @@ -1514,9 +1516,9 @@ function isChildReport(report: OnyxEntry): boolean { * An Expense Request is a thread where the parent report is an Expense Report and * the parentReportAction is a transaction. */ -function isExpenseRequest(report: OnyxInputOrEntry): boolean { +function isExpenseRequest(report: OnyxInputOrEntry): report is Thread { if (isThread(report)) { - const parentReportAction = ReportActionsUtils.getParentReportAction(report); + const parentReportAction = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report?.parentReportID}`]?.[report?.parentReportActionID]; const parentReport = ReportConnection.getAllReports()?.[`${ONYXKEYS.COLLECTION.REPORT}${report?.parentReportID}`]; return isExpenseReport(parentReport) && !isEmptyObject(parentReportAction) && ReportActionsUtils.isTransactionThread(parentReportAction); } @@ -1529,7 +1531,7 @@ function isExpenseRequest(report: OnyxInputOrEntry): boolean { */ function isIOURequest(report: OnyxInputOrEntry): boolean { if (isThread(report)) { - const parentReportAction = ReportActionsUtils.getParentReportAction(report); + const parentReportAction = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report?.parentReportID}`]?.[report?.parentReportActionID]; const parentReport = ReportConnection.getAllReports()?.[`${ONYXKEYS.COLLECTION.REPORT}${report?.parentReportID}`]; return isIOUReport(parentReport) && !isEmptyObject(parentReportAction) && ReportActionsUtils.isTransactionThread(parentReportAction); } @@ -1542,7 +1544,7 @@ function isIOURequest(report: OnyxInputOrEntry): boolean { */ function isTrackExpenseReport(report: OnyxInputOrEntry): boolean { if (isThread(report)) { - const parentReportAction = ReportActionsUtils.getParentReportAction(report); + const parentReportAction = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report?.parentReportID}`]?.[report?.parentReportActionID]; return !isEmptyObject(parentReportAction) && ReportActionsUtils.isTrackExpenseAction(parentReportAction); } return false; @@ -2191,7 +2193,7 @@ function getIcons( return [fallbackIcon]; } if (isExpenseRequest(report)) { - const parentReportAction = ReportActionsUtils.getParentReportAction(report); + const parentReportAction = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report?.parentReportID}`]?.[report?.parentReportActionID]; const workspaceIcon = getWorkspaceIcon(report, policy); const memberIcon = { source: personalDetails?.[parentReportAction?.actorAccountID ?? -1]?.avatar ?? FallbackAvatar, @@ -2204,7 +2206,7 @@ function getIcons( return [memberIcon, workspaceIcon]; } if (isChatThread(report)) { - const parentReportAction = ReportActionsUtils.getParentReportAction(report); + const parentReportAction = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report?.parentReportID}`]?.[report?.parentReportActionID]; const actorAccountID = getReportActionActorAccountID(parentReportAction, report); const actorDisplayName = PersonalDetailsUtils.getDisplayNameOrDefault(allPersonalDetails?.[actorAccountID ?? -1], '', false); @@ -3085,8 +3087,9 @@ function canHoldUnholdReportAction(reportAction: OnyxInputOrEntry) const transactionID = moneyRequestReport ? ReportActionsUtils.getOriginalMessage(reportAction)?.IOUTransactionID : 0; const transaction = allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`] ?? ({} as Transaction); - const parentReportAction = ReportActionsUtils.getParentReportAction(moneyRequestReport); - + const parentReportAction = isThread(moneyRequestReport) + ? allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${moneyRequestReport.parentReportID}`]?.[moneyRequestReport.parentReportActionID] + : undefined; const isRequestIOU = isIOUReport(moneyRequestReport); const isHoldActionCreator = isHoldCreator(transaction, reportAction.childReportID ?? '-1'); @@ -3692,7 +3695,13 @@ function getReportName( } let formattedName: string | undefined; - const parentReportAction = parentReportActionParam ?? ReportActionsUtils.getParentReportAction(report); + let parentReportAction: OnyxEntry; + // let parentReportAction = parentReportActionParam as OnyxEntry; + if (parentReportActionParam) { + parentReportAction = parentReportActionParam; + } else { + parentReportAction = isThread(report) ? allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report?.parentReportID}`]?.[report?.parentReportActionID] : undefined; + } const parentReportActionMessage = ReportActionsUtils.getReportActionMessage(parentReportAction); if (parentReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.SUBMITTED) { @@ -5974,7 +5983,7 @@ function shouldReportBeInOptionList({ // This can also happen for anyone accessing a public room or archived room for which they don't have access to the underlying policy. // Optionally exclude reports that do not belong to currently active workspace - const parentReportAction = ReportActionsUtils.getParentReportAction(report); + const parentReportAction = isThread(report) ? allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report?.parentReportID}`]?.[report?.parentReportActionID] : undefined; if ( !report?.reportID || From f365b4edcc2becb35cecc65b4348da72354c73a1 Mon Sep 17 00:00:00 2001 From: c3024 Date: Wed, 18 Sep 2024 20:30:09 +0530 Subject: [PATCH 3/4] refactor to avoid lint --- src/libs/ReportUtils.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 1820a0c00b13..df593f11c0d4 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -4237,10 +4237,13 @@ function buildOptimisticTaskCommentReportAction( // These parameters are not saved on the reportAction, but are used to display the task in the UI // Added when we fetch the reportActions on a report - reportAction.reportAction.originalMessage = { - html: ReportActionsUtils.getReportActionHtml(reportAction.reportAction), - taskReportID: ReportActionsUtils.getReportActionMessage(reportAction.reportAction)?.taskReportID, - whisperedTo: [], + reportAction.reportAction = { + ...reportAction.reportAction, + originalMessage: { + html: ReportActionsUtils.getReportActionHtml(reportAction.reportAction), + taskReportID: ReportActionsUtils.getReportActionMessage(reportAction.reportAction)?.taskReportID, + whisperedTo: [], + }, }; reportAction.reportAction.childReportID = taskReportID; reportAction.reportAction.parentReportID = parentReportID; From 8684bd84cd1dd4a3e5738b0e119ae27495cbbee8 Mon Sep 17 00:00:00 2001 From: c3024 Date: Wed, 18 Sep 2024 20:48:02 +0530 Subject: [PATCH 4/4] remove unnecessary comment --- src/libs/ReportUtils.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index df593f11c0d4..7e950c4636a2 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -3696,7 +3696,6 @@ function getReportName( let formattedName: string | undefined; let parentReportAction: OnyxEntry; - // let parentReportAction = parentReportActionParam as OnyxEntry; if (parentReportActionParam) { parentReportAction = parentReportActionParam; } else {