From 23012c707532a132530c0f405bbfacea3fe714ac Mon Sep 17 00:00:00 2001 From: Cristi Paval Date: Mon, 15 Jan 2024 21:30:44 +0200 Subject: [PATCH 1/6] Verify if the user comes from OldDot --- src/libs/SessionUtils.ts | 7 ++++++- src/pages/home/ReportScreen.js | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/libs/SessionUtils.ts b/src/libs/SessionUtils.ts index c73513c747af..24bc51fd3e9e 100644 --- a/src/libs/SessionUtils.ts +++ b/src/libs/SessionUtils.ts @@ -53,4 +53,9 @@ function didUserLogInDuringSession() { return Boolean(loggedInDuringSession); } -export {isLoggingInAsNewUser, didUserLogInDuringSession, resetDidUserLogInDuringSession}; +function didSessionStartAsOldDotConcierge(initialURL: string) { + console.debug("CRISTIII - " + initialURL); + return Boolean(true); +} + +export {isLoggingInAsNewUser, didUserLogInDuringSession, resetDidUserLogInDuringSession, didSessionStartAsOldDotConcierge}; diff --git a/src/pages/home/ReportScreen.js b/src/pages/home/ReportScreen.js index b35d9240f3f7..3616499d0a08 100644 --- a/src/pages/home/ReportScreen.js +++ b/src/pages/home/ReportScreen.js @@ -2,7 +2,7 @@ import {useIsFocused} from '@react-navigation/native'; import lodashGet from 'lodash/get'; import PropTypes from 'prop-types'; import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react'; -import {View} from 'react-native'; +import {Linking, View} from 'react-native'; import {withOnyx} from 'react-native-onyx'; import _ from 'underscore'; import Banner from '@components/Banner'; @@ -44,6 +44,7 @@ import reportActionPropTypes from './report/reportActionPropTypes'; import ReportActionsView from './report/ReportActionsView'; import ReportFooter from './report/ReportFooter'; import {ActionListContext, ReactionListContext} from './ReportScreenContext'; +import * as SessionUtils from '@libs/SessionUtils'; const propTypes = { /** Navigation route context info provided by react navigation */ @@ -194,6 +195,7 @@ function ReportScreen({ const policy = policies[`${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`] || {}; const isTopMostReportId = currentReportID === getReportID(route); const didSubscribeToReportLeavingEvents = useRef(false); + const isOldDotConciergeRef = useRef(false); useEffect(() => { if (!report || !report.reportID || shouldHideReport) { @@ -350,6 +352,9 @@ function ReportScreen({ Timing.end(CONST.TIMING.CHAT_RENDER); Performance.markEnd(CONST.TIMING.CHAT_RENDER); + Linking.getInitialURL().then((url) => { + isOldDotConciergeRef.current = SessionUtils.didSessionStartAsOldDotConcierge(url); + }); fetchReportIfNeeded(); ComposerActions.setShouldShowComposeInput(true); return () => { From 020a22b0d97d5c2a1be8c29f413025cf36083174 Mon Sep 17 00:00:00 2001 From: Cristi Paval Date: Mon, 15 Jan 2024 21:35:23 +0200 Subject: [PATCH 2/6] Create ReportUtils.isOldDotConciergeChat function --- src/libs/ReportUtils.ts | 9 +++++++++ src/libs/SessionUtils.ts | 7 +------ src/pages/home/ReportScreen.js | 3 +-- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 7e8966ed0d3f..de6250c2da84 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -831,6 +831,14 @@ function isConciergeChatReport(report: OnyxEntry): boolean { return report?.participantAccountIDs?.length === 1 && Number(report.participantAccountIDs?.[0]) === CONST.ACCOUNT_ID.CONCIERGE && !isChatThread(report); } +/** + * Only returns true if this is a DM report with Concierge, opened from OldDot + */ +function isOldDotConciergeChat(initialURL: string, report: OnyxEntry): boolean { + + return report?.participantAccountIDs?.length === 1 && Number(report.participantAccountIDs?.[0]) === CONST.ACCOUNT_ID.CONCIERGE; +} + /** * Returns true if report is still being processed */ @@ -4432,6 +4440,7 @@ export { isPublicRoom, isPublicAnnounceRoom, isConciergeChatReport, + isOldDotConciergeChat, isProcessingReport, isCurrentUserTheOnlyParticipant, hasAutomatedExpensifyAccountIDs, diff --git a/src/libs/SessionUtils.ts b/src/libs/SessionUtils.ts index 24bc51fd3e9e..c73513c747af 100644 --- a/src/libs/SessionUtils.ts +++ b/src/libs/SessionUtils.ts @@ -53,9 +53,4 @@ function didUserLogInDuringSession() { return Boolean(loggedInDuringSession); } -function didSessionStartAsOldDotConcierge(initialURL: string) { - console.debug("CRISTIII - " + initialURL); - return Boolean(true); -} - -export {isLoggingInAsNewUser, didUserLogInDuringSession, resetDidUserLogInDuringSession, didSessionStartAsOldDotConcierge}; +export {isLoggingInAsNewUser, didUserLogInDuringSession, resetDidUserLogInDuringSession}; diff --git a/src/pages/home/ReportScreen.js b/src/pages/home/ReportScreen.js index 3616499d0a08..77043c5142ec 100644 --- a/src/pages/home/ReportScreen.js +++ b/src/pages/home/ReportScreen.js @@ -44,7 +44,6 @@ import reportActionPropTypes from './report/reportActionPropTypes'; import ReportActionsView from './report/ReportActionsView'; import ReportFooter from './report/ReportFooter'; import {ActionListContext, ReactionListContext} from './ReportScreenContext'; -import * as SessionUtils from '@libs/SessionUtils'; const propTypes = { /** Navigation route context info provided by react navigation */ @@ -353,7 +352,7 @@ function ReportScreen({ Performance.markEnd(CONST.TIMING.CHAT_RENDER); Linking.getInitialURL().then((url) => { - isOldDotConciergeRef.current = SessionUtils.didSessionStartAsOldDotConcierge(url); + isOldDotConciergeRef.current = ReportUtils.isOldDotConciergeChat(url, report); }); fetchReportIfNeeded(); ComposerActions.setShouldShowComposeInput(true); From 34d6d90cc1ab521e00aa8e9378593e4247bbc6f8 Mon Sep 17 00:00:00 2001 From: Cristi Paval Date: Tue, 16 Jan 2024 18:36:44 +0200 Subject: [PATCH 3/6] Try a new approach --- src/libs/ReportUtils.ts | 7 ++++++- src/libs/actions/Report.ts | 18 +++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index de6250c2da84..a0673a2e0cec 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -835,7 +835,12 @@ function isConciergeChatReport(report: OnyxEntry): boolean { * Only returns true if this is a DM report with Concierge, opened from OldDot */ function isOldDotConciergeChat(initialURL: string, report: OnyxEntry): boolean { - + const params = new URLSearchParams(initialURL); + const exitToRoute = params.get('exitTo') ?? ''; + const {reportID} = parseReportRouteParams(exitToRoute); + if (reportID !== report?.reportID) { + return false; + } return report?.participantAccountIDs?.length === 1 && Number(report.participantAccountIDs?.[0]) === CONST.ACCOUNT_ID.CONCIERGE; } diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 4729feea736e..d940b96e2a42 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -2,7 +2,7 @@ import {format as timezoneFormat, utcToZonedTime} from 'date-fns-tz'; import ExpensiMark from 'expensify-common/lib/ExpensiMark'; import Str from 'expensify-common/lib/str'; import isEmpty from 'lodash/isEmpty'; -import {DeviceEventEmitter, InteractionManager} from 'react-native'; +import {DeviceEventEmitter, InteractionManager, Linking} from 'react-native'; import type {OnyxCollection, OnyxEntry, OnyxUpdate} from 'react-native-onyx'; import Onyx from 'react-native-onyx'; import type {NullishDeep} from 'react-native-onyx/lib/types'; @@ -127,6 +127,16 @@ const allReports: OnyxCollection = {}; let conciergeChatReportID: string | undefined; const typingWatchTimers: Record = {}; +let reportIDDeeplinkedFromOldDot: string | undefined; +Linking.getInitialURL().then((url) => { + console.debug("CRISTIIII - " + url); + const params = new URLSearchParams(url ?? ''); + const exitToRoute = params.get('exitTo') ?? ''; + const {reportID} = ReportUtils.parseReportRouteParams(exitToRoute); + reportIDDeeplinkedFromOldDot = reportID; + console.debug("CRISTIIII - " + reportIDDeeplinkedFromOldDot); +}); + /** Get the private pusher channel name for a Report. */ function getReportChannelName(reportID: string): string { return `${CONST.PUSHER.PRIVATE_REPORT_CHANNEL_PREFIX}${reportID}${CONFIG.PUSHER.SUFFIX}`; @@ -343,6 +353,7 @@ function addActions(reportID: string, text = '', file?: File) { timezone?: string; shouldAllowActionableMentionWhispers?: boolean; clientCreatedTime?: string; + isOldDotConciergeChat?: boolean; }; const parameters: AddCommentOrAttachementParameters = { @@ -354,6 +365,11 @@ function addActions(reportID: string, text = '', file?: File) { shouldAllowActionableMentionWhispers: true, clientCreatedTime: file ? attachmentAction?.created : reportCommentAction?.created, }; + console.debug("CRISTIIII - reportIDDeeplinkedFromOldDot: " + reportIDDeeplinkedFromOldDot); + if (reportIDDeeplinkedFromOldDot === reportID && report?.participantAccountIDs?.length === 1 && Number(report.participantAccountIDs?.[0]) === CONST.ACCOUNT_ID.CONCIERGE) { + console.debug("CRISTIIII - isOldDotConciergeChat: " + true); + parameters.isOldDotConciergeChat = true; + } const optimisticData: OnyxUpdate[] = [ { From 9eaddcd8c1532856fd9c8116cc8ccf86553d0da4 Mon Sep 17 00:00:00 2001 From: Cristi Paval Date: Tue, 16 Jan 2024 18:43:28 +0200 Subject: [PATCH 4/6] Revert initial changes --- src/libs/ReportUtils.ts | 14 -------------- src/pages/home/ReportScreen.js | 6 +----- 2 files changed, 1 insertion(+), 19 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index a0673a2e0cec..7e8966ed0d3f 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -831,19 +831,6 @@ function isConciergeChatReport(report: OnyxEntry): boolean { return report?.participantAccountIDs?.length === 1 && Number(report.participantAccountIDs?.[0]) === CONST.ACCOUNT_ID.CONCIERGE && !isChatThread(report); } -/** - * Only returns true if this is a DM report with Concierge, opened from OldDot - */ -function isOldDotConciergeChat(initialURL: string, report: OnyxEntry): boolean { - const params = new URLSearchParams(initialURL); - const exitToRoute = params.get('exitTo') ?? ''; - const {reportID} = parseReportRouteParams(exitToRoute); - if (reportID !== report?.reportID) { - return false; - } - return report?.participantAccountIDs?.length === 1 && Number(report.participantAccountIDs?.[0]) === CONST.ACCOUNT_ID.CONCIERGE; -} - /** * Returns true if report is still being processed */ @@ -4445,7 +4432,6 @@ export { isPublicRoom, isPublicAnnounceRoom, isConciergeChatReport, - isOldDotConciergeChat, isProcessingReport, isCurrentUserTheOnlyParticipant, hasAutomatedExpensifyAccountIDs, diff --git a/src/pages/home/ReportScreen.js b/src/pages/home/ReportScreen.js index 77043c5142ec..b35d9240f3f7 100644 --- a/src/pages/home/ReportScreen.js +++ b/src/pages/home/ReportScreen.js @@ -2,7 +2,7 @@ import {useIsFocused} from '@react-navigation/native'; import lodashGet from 'lodash/get'; import PropTypes from 'prop-types'; import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react'; -import {Linking, View} from 'react-native'; +import {View} from 'react-native'; import {withOnyx} from 'react-native-onyx'; import _ from 'underscore'; import Banner from '@components/Banner'; @@ -194,7 +194,6 @@ function ReportScreen({ const policy = policies[`${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`] || {}; const isTopMostReportId = currentReportID === getReportID(route); const didSubscribeToReportLeavingEvents = useRef(false); - const isOldDotConciergeRef = useRef(false); useEffect(() => { if (!report || !report.reportID || shouldHideReport) { @@ -351,9 +350,6 @@ function ReportScreen({ Timing.end(CONST.TIMING.CHAT_RENDER); Performance.markEnd(CONST.TIMING.CHAT_RENDER); - Linking.getInitialURL().then((url) => { - isOldDotConciergeRef.current = ReportUtils.isOldDotConciergeChat(url, report); - }); fetchReportIfNeeded(); ComposerActions.setShouldShowComposeInput(true); return () => { From c71299b3031882ec39a9da05995242667c70df34 Mon Sep 17 00:00:00 2001 From: Cristi Paval Date: Tue, 16 Jan 2024 18:46:42 +0200 Subject: [PATCH 5/6] Remove console logs --- src/libs/actions/Report.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index d940b96e2a42..cbea69dd6eb6 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -129,12 +129,10 @@ const typingWatchTimers: Record = {}; let reportIDDeeplinkedFromOldDot: string | undefined; Linking.getInitialURL().then((url) => { - console.debug("CRISTIIII - " + url); const params = new URLSearchParams(url ?? ''); const exitToRoute = params.get('exitTo') ?? ''; const {reportID} = ReportUtils.parseReportRouteParams(exitToRoute); reportIDDeeplinkedFromOldDot = reportID; - console.debug("CRISTIIII - " + reportIDDeeplinkedFromOldDot); }); /** Get the private pusher channel name for a Report. */ @@ -365,9 +363,8 @@ function addActions(reportID: string, text = '', file?: File) { shouldAllowActionableMentionWhispers: true, clientCreatedTime: file ? attachmentAction?.created : reportCommentAction?.created, }; - console.debug("CRISTIIII - reportIDDeeplinkedFromOldDot: " + reportIDDeeplinkedFromOldDot); + if (reportIDDeeplinkedFromOldDot === reportID && report?.participantAccountIDs?.length === 1 && Number(report.participantAccountIDs?.[0]) === CONST.ACCOUNT_ID.CONCIERGE) { - console.debug("CRISTIIII - isOldDotConciergeChat: " + true); parameters.isOldDotConciergeChat = true; } From 4524a3e38cac289a49c845c7c9a5cb4268325b28 Mon Sep 17 00:00:00 2001 From: Cristi Paval Date: Tue, 16 Jan 2024 19:02:47 +0200 Subject: [PATCH 6/6] Run prettier --- src/libs/actions/Report.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index cbea69dd6eb6..f218918bb094 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -363,7 +363,7 @@ function addActions(reportID: string, text = '', file?: File) { shouldAllowActionableMentionWhispers: true, clientCreatedTime: file ? attachmentAction?.created : reportCommentAction?.created, }; - + if (reportIDDeeplinkedFromOldDot === reportID && report?.participantAccountIDs?.length === 1 && Number(report.participantAccountIDs?.[0]) === CONST.ACCOUNT_ID.CONCIERGE) { parameters.isOldDotConciergeChat = true; }