From ea90394197ef77898d036692bf1a6db64a9e6e50 Mon Sep 17 00:00:00 2001 From: Rajat Parashar Date: Fri, 14 Mar 2025 19:51:29 +0530 Subject: [PATCH 01/10] Exclude the archived Concierge chats --- .../actions/OnyxDerived/configs/conciergeChatReportID.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libs/actions/OnyxDerived/configs/conciergeChatReportID.ts b/src/libs/actions/OnyxDerived/configs/conciergeChatReportID.ts index ce246616b18dc..4403f7be64d78 100644 --- a/src/libs/actions/OnyxDerived/configs/conciergeChatReportID.ts +++ b/src/libs/actions/OnyxDerived/configs/conciergeChatReportID.ts @@ -1,4 +1,4 @@ -import {isThread} from '@libs/ReportUtils'; +import {isThread, isArchivedReportWithID} from '@libs/ReportUtils'; import createOnyxDerivedValueConfig from '@userActions/OnyxDerived/createOnyxDerivedValueConfig'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; @@ -12,7 +12,8 @@ export default createOnyxDerivedValueConfig({ } const conciergeReport = Object.values(reports).find((report) => { - if (!report?.participants || isThread(report)) { + // Merged accounts can have multiple conceirge chats, exclude archived chats. + if (!report?.participants || isThread(report) || isArchivedReportWithID(report?.reportID)) { return false; } From 00a57b83f6aefbcaa7affa5fd59d246065799c3f Mon Sep 17 00:00:00 2001 From: Rajat Parashar Date: Fri, 14 Mar 2025 19:57:13 +0530 Subject: [PATCH 02/10] Fix lint --- src/libs/actions/OnyxDerived/configs/conciergeChatReportID.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/OnyxDerived/configs/conciergeChatReportID.ts b/src/libs/actions/OnyxDerived/configs/conciergeChatReportID.ts index 4403f7be64d78..b204a8ee75f67 100644 --- a/src/libs/actions/OnyxDerived/configs/conciergeChatReportID.ts +++ b/src/libs/actions/OnyxDerived/configs/conciergeChatReportID.ts @@ -1,4 +1,4 @@ -import {isThread, isArchivedReportWithID} from '@libs/ReportUtils'; +import { isThread, isArchivedReportWithID } from '@libs/ReportUtils'; import createOnyxDerivedValueConfig from '@userActions/OnyxDerived/createOnyxDerivedValueConfig'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; From 08140eb256943cb71d91191595145b4ea0cd1a66 Mon Sep 17 00:00:00 2001 From: Rajat Parashar Date: Sat, 15 Mar 2025 16:08:04 +0530 Subject: [PATCH 03/10] Wait for immediate action --- .../actions/OnyxDerived/configs/conciergeChatReportID.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/libs/actions/OnyxDerived/configs/conciergeChatReportID.ts b/src/libs/actions/OnyxDerived/configs/conciergeChatReportID.ts index b204a8ee75f67..abd5a39230794 100644 --- a/src/libs/actions/OnyxDerived/configs/conciergeChatReportID.ts +++ b/src/libs/actions/OnyxDerived/configs/conciergeChatReportID.ts @@ -5,9 +5,9 @@ import ONYXKEYS from '@src/ONYXKEYS'; export default createOnyxDerivedValueConfig({ key: ONYXKEYS.DERIVED.CONCIERGE_CHAT_REPORT_ID, - dependencies: [ONYXKEYS.COLLECTION.REPORT, ONYXKEYS.CONCIERGE_REPORT_ID], - compute: ([reports, conciergeChatReportID]) => { - if (!reports) { + dependencies: [ONYXKEYS.COLLECTION.REPORT, ONYXKEYS.CONCIERGE_REPORT_ID, ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS], + compute: ([reports, conciergeChatReportID, allReportNameValuePair]) => { + if (!reports || !allReportNameValuePair) { return undefined; } @@ -25,6 +25,8 @@ export default createOnyxDerivedValueConfig({ return participantAccountIDs.has(CONST.ACCOUNT_ID.CONCIERGE.toString()) || report?.reportID === conciergeChatReportID; }); + console.debug('conciergeReport?.reportID', conciergeReport?.reportID); + return conciergeReport?.reportID; }, }); From a5ddb6bcb3e4f888a6e736a4f71e2add949fad83 Mon Sep 17 00:00:00 2001 From: Rajat Parashar Date: Sat, 15 Mar 2025 16:58:31 +0530 Subject: [PATCH 04/10] Remove logs --- src/libs/actions/OnyxDerived/configs/conciergeChatReportID.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/libs/actions/OnyxDerived/configs/conciergeChatReportID.ts b/src/libs/actions/OnyxDerived/configs/conciergeChatReportID.ts index abd5a39230794..dbadcb40621e3 100644 --- a/src/libs/actions/OnyxDerived/configs/conciergeChatReportID.ts +++ b/src/libs/actions/OnyxDerived/configs/conciergeChatReportID.ts @@ -25,8 +25,6 @@ export default createOnyxDerivedValueConfig({ return participantAccountIDs.has(CONST.ACCOUNT_ID.CONCIERGE.toString()) || report?.reportID === conciergeChatReportID; }); - console.debug('conciergeReport?.reportID', conciergeReport?.reportID); - return conciergeReport?.reportID; }, }); From 96ac95e121675269b488adeaf498ba68ac8c7b20 Mon Sep 17 00:00:00 2001 From: Rajat Parashar Date: Tue, 18 Mar 2025 14:10:40 +0530 Subject: [PATCH 05/10] Fix tests --- tests/unit/navigateAfterOnboardingTest.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/unit/navigateAfterOnboardingTest.ts b/tests/unit/navigateAfterOnboardingTest.ts index e1913c7fc578a..84364e34b264c 100644 --- a/tests/unit/navigateAfterOnboardingTest.ts +++ b/tests/unit/navigateAfterOnboardingTest.ts @@ -32,6 +32,7 @@ jest.mock('@libs/ReportUtils', () => ({ findLastAccessedReport: () => mockFindLastAccessedReport() as OnyxEntry, parseReportRouteParams: jest.fn(() => ({})), isConciergeChatReport: jest.requireActual('@libs/ReportUtils').isConciergeChatReport, + isArchivedReportWithID: jest.requireActual('@libs/ReportUtils').isArchivedReportWithID, isThread: jest.requireActual('@libs/ReportUtils').isThread, })); From 9b01b2aa0ea5805d673219f6c4f1cecaf1b98fbf Mon Sep 17 00:00:00 2001 From: Rajat Parashar Date: Tue, 18 Mar 2025 14:16:20 +0530 Subject: [PATCH 06/10] Fix prettier --- src/libs/actions/OnyxDerived/configs/conciergeChatReportID.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/OnyxDerived/configs/conciergeChatReportID.ts b/src/libs/actions/OnyxDerived/configs/conciergeChatReportID.ts index dbadcb40621e3..bf7814acc76fe 100644 --- a/src/libs/actions/OnyxDerived/configs/conciergeChatReportID.ts +++ b/src/libs/actions/OnyxDerived/configs/conciergeChatReportID.ts @@ -1,4 +1,4 @@ -import { isThread, isArchivedReportWithID } from '@libs/ReportUtils'; +import {isArchivedReportWithID, isThread} from '@libs/ReportUtils'; import createOnyxDerivedValueConfig from '@userActions/OnyxDerived/createOnyxDerivedValueConfig'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; From df30dd7c2bf5d94f39bb6d6acbccbfd1bcf45a31 Mon Sep 17 00:00:00 2001 From: Rajat Parashar Date: Tue, 18 Mar 2025 22:32:21 +0530 Subject: [PATCH 07/10] fix type --- src/libs/actions/OnyxDerived/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/OnyxDerived/index.ts b/src/libs/actions/OnyxDerived/index.ts index 99b34b095eafc..696c8e6e99ec3 100644 --- a/src/libs/actions/OnyxDerived/index.ts +++ b/src/libs/actions/OnyxDerived/index.ts @@ -54,7 +54,7 @@ function init() { waitForCollectionCallback: true, callback: (value) => { Log.info(`[OnyxDerived] dependency ${dependencyOnyxKey} for derived key ${key} changed, recomputing`); - setDependencyValue(i, value); + setDependencyValue(i, value as Parameters[0][typeof i]); recomputeDerivedValue(); }, }); From 5a98e27f274dade1b3f204402be1c63f91418597 Mon Sep 17 00:00:00 2001 From: Rajat Parashar Date: Tue, 18 Mar 2025 22:42:02 +0530 Subject: [PATCH 08/10] Fix types --- src/libs/actions/OnyxDerived/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/OnyxDerived/index.ts b/src/libs/actions/OnyxDerived/index.ts index 696c8e6e99ec3..c0321d46b29f8 100644 --- a/src/libs/actions/OnyxDerived/index.ts +++ b/src/libs/actions/OnyxDerived/index.ts @@ -63,7 +63,7 @@ function init() { key: dependencyOnyxKey, callback: (value) => { Log.info(`[OnyxDerived] dependency ${dependencyOnyxKey} for derived key ${key} changed, recomputing`); - setDependencyValue(i, value); + setDependencyValue(i, value as Parameters[0][typeof i]); recomputeDerivedValue(); }, }); From 9ebabdc108e6b7bdfaced9c600357b0044fad28a Mon Sep 17 00:00:00 2001 From: Rajat Parashar Date: Wed, 26 Mar 2025 01:34:25 +0530 Subject: [PATCH 09/10] Add more tests --- tests/actions/ReportTest.ts | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/actions/ReportTest.ts b/tests/actions/ReportTest.ts index d18213bd8f548..ff377e574e19f 100644 --- a/tests/actions/ReportTest.ts +++ b/tests/actions/ReportTest.ts @@ -18,6 +18,8 @@ import * as SequentialQueue from '@src/libs/Network/SequentialQueue'; import * as ReportUtils from '@src/libs/ReportUtils'; import ONYXKEYS from '@src/ONYXKEYS'; import type * as OnyxTypes from '@src/types/onyx'; +import initOnyxDerivedValues from '@userActions/OnyxDerived'; +import OnyxUtils from 'react-native-onyx/dist/OnyxUtils'; import createRandomReportAction from '../utils/collections/reportActions'; import createRandomReport from '../utils/collections/reports'; import getIsUsingFakeTimers from '../utils/getIsUsingFakeTimers'; @@ -25,6 +27,8 @@ import PusherHelper from '../utils/PusherHelper'; import * as TestHelper from '../utils/TestHelper'; import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; import waitForNetworkPromises from '../utils/waitForNetworkPromises'; +import * as LHNTestUtils from '../utils/LHNTestUtils'; + const UTC = 'UTC'; jest.mock('@src/libs/actions/Report', () => { @@ -1485,4 +1489,33 @@ describe('actions/Report', () => { expect(report?.lastMentionedTime).toBeUndefined(); }); + + describe('isConciergeChatReport', () => { + const accountID = 2; + const conciergeChatReport1 = LHNTestUtils.getFakeReport([accountID, CONST.ACCOUNT_ID.CONCIERGE]); + const conciergeChatReport2 = LHNTestUtils.getFakeReport([accountID, CONST.ACCOUNT_ID.CONCIERGE]); + + beforeAll(async () => { + Onyx.init({keys: ONYXKEYS}); + await waitForBatchedUpdates(); + }); + + beforeEach(async () => { + await Onyx.clear(); + await waitForBatchedUpdates(); + }); + + it('should not return archived Concierge chat report', async () => { + initOnyxDerivedValues(); + await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${conciergeChatReport1.reportID}`, conciergeChatReport1); + await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${conciergeChatReport2.reportID}`, conciergeChatReport2); + + // Set First conciergeChatReport1 to archived state + await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${conciergeChatReport1.reportID}`, { + private_isArchived: new Date().toString() + }); + const derivedConciergeChatReportID = await OnyxUtils.get(ONYXKEYS.DERIVED.CONCIERGE_CHAT_REPORT_ID); + expect(derivedConciergeChatReportID).toBe(conciergeChatReport2.reportID); + }); + }); }); From 355216dd607ddea93f889cffbe606cbba137fb89 Mon Sep 17 00:00:00 2001 From: Rajat Parashar Date: Wed, 26 Mar 2025 12:36:40 +0530 Subject: [PATCH 10/10] Lint issues --- tests/actions/ReportTest.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/actions/ReportTest.ts b/tests/actions/ReportTest.ts index ff377e574e19f..6be845b7e8661 100644 --- a/tests/actions/ReportTest.ts +++ b/tests/actions/ReportTest.ts @@ -5,8 +5,10 @@ import {toZonedTime} from 'date-fns-tz'; import type {Mock} from 'jest-mock'; import Onyx from 'react-native-onyx'; import type {OnyxCollection, OnyxEntry, OnyxUpdate} from 'react-native-onyx'; +import OnyxUtils from 'react-native-onyx/dist/OnyxUtils'; import {WRITE_COMMANDS} from '@libs/API/types'; import HttpUtils from '@libs/HttpUtils'; +import initOnyxDerivedValues from '@userActions/OnyxDerived'; import CONST from '@src/CONST'; import OnyxUpdateManager from '@src/libs/actions/OnyxUpdateManager'; import * as PersistedRequests from '@src/libs/actions/PersistedRequests'; @@ -18,17 +20,14 @@ import * as SequentialQueue from '@src/libs/Network/SequentialQueue'; import * as ReportUtils from '@src/libs/ReportUtils'; import ONYXKEYS from '@src/ONYXKEYS'; import type * as OnyxTypes from '@src/types/onyx'; -import initOnyxDerivedValues from '@userActions/OnyxDerived'; -import OnyxUtils from 'react-native-onyx/dist/OnyxUtils'; import createRandomReportAction from '../utils/collections/reportActions'; import createRandomReport from '../utils/collections/reports'; import getIsUsingFakeTimers from '../utils/getIsUsingFakeTimers'; +import * as LHNTestUtils from '../utils/LHNTestUtils'; import PusherHelper from '../utils/PusherHelper'; import * as TestHelper from '../utils/TestHelper'; import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; import waitForNetworkPromises from '../utils/waitForNetworkPromises'; -import * as LHNTestUtils from '../utils/LHNTestUtils'; - const UTC = 'UTC'; jest.mock('@src/libs/actions/Report', () => { @@ -1512,7 +1511,7 @@ describe('actions/Report', () => { // Set First conciergeChatReport1 to archived state await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${conciergeChatReport1.reportID}`, { - private_isArchived: new Date().toString() + private_isArchived: new Date().toString(), }); const derivedConciergeChatReportID = await OnyxUtils.get(ONYXKEYS.DERIVED.CONCIERGE_CHAT_REPORT_ID); expect(derivedConciergeChatReportID).toBe(conciergeChatReport2.reportID);