From b8d10804913a287f271ee4fd32dee227d26ca74e Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Tue, 16 Apr 2024 14:40:02 +0800 Subject: [PATCH 1/4] use participants data --- src/libs/OptionsListUtils.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index aa16d7b2dc5a..310ac4edd5a7 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -1459,8 +1459,8 @@ function createOptionList(personalDetails: OnyxEntry, repor } const isSelfDM = ReportUtils.isSelfDM(report); - // Currently, currentUser is not included in visibleChatMemberAccountIDs, so for selfDM we need to add the currentUser as participants. - const accountIDs = isSelfDM ? [currentUserAccountID ?? 0] : report.visibleChatMemberAccountIDs ?? []; + // Currently, currentUser is not included in participants, so for selfDM we need to add the currentUser as participants. + const accountIDs = isSelfDM ? [currentUserAccountID ?? 0] : ReportUtils.getParticipantAccountIDs(report.reportID); if (!accountIDs || accountIDs.length === 0) { return; @@ -1679,8 +1679,8 @@ function getOptions( const isPolicyExpenseChat = option.isPolicyExpenseChat; const isMoneyRequestReport = option.isMoneyRequestReport; const isSelfDM = option.isSelfDM; - // Currently, currentUser is not included in visibleChatMemberAccountIDs, so for selfDM we need to add the currentUser as participants. - const accountIDs = isSelfDM ? [currentUserAccountID ?? 0] : report.visibleChatMemberAccountIDs ?? []; + // Currently, currentUser is not included in participants, so for selfDM we need to add the currentUser as participants. + const accountIDs = isSelfDM ? [currentUserAccountID ?? 0] : ReportUtils.getParticipantAccountIDs(report.reportID); if (isPolicyExpenseChat && report.isOwnPolicyExpenseChat && !includeOwnedWorkspaceChats) { return; From 809b5a3291269615bc53e984617c45e0a828e2df Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Tue, 16 Apr 2024 14:50:07 +0800 Subject: [PATCH 2/4] optimistically update notification preference to always --- src/libs/actions/IOU.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 85f4b74f3436..068d666eaabe 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -2575,6 +2575,11 @@ function createSplitsAndOnyxData( splitChatReport.lastMessageText = splitIOUReportAction.message?.[0]?.text; splitChatReport.lastMessageHtml = splitIOUReportAction.message?.[0]?.html; + let splitChatReportNotificationPreference = splitChatReport.notificationPreference; + if (splitChatReportNotificationPreference === CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN) { + splitChatReportNotificationPreference = CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS; + } + // If we have an existing splitChatReport (group chat or workspace) use it's pending fields, otherwise indicate that we are adding a chat if (!existingSplitChatReport) { splitChatReport.pendingFields = { @@ -2588,7 +2593,10 @@ function createSplitsAndOnyxData( // and we need the data to be available when we navigate to the chat page onyxMethod: existingSplitChatReport ? Onyx.METHOD.MERGE : Onyx.METHOD.SET, key: `${ONYXKEYS.COLLECTION.REPORT}${splitChatReport.reportID}`, - value: splitChatReport, + value: { + ...splitChatReport, + notificationPreference: splitChatReportNotificationPreference, + }, }, { onyxMethod: Onyx.METHOD.SET, From 0c3e03ad63067f3e780b412e2bad06d89c821cae Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Tue, 16 Apr 2024 15:27:50 +0800 Subject: [PATCH 3/4] fix test --- src/libs/OptionsListUtils.ts | 4 +-- tests/unit/OptionsListUtilsTest.ts | 51 ++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 310ac4edd5a7..6baf0cd30529 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -1460,7 +1460,7 @@ function createOptionList(personalDetails: OnyxEntry, repor const isSelfDM = ReportUtils.isSelfDM(report); // Currently, currentUser is not included in participants, so for selfDM we need to add the currentUser as participants. - const accountIDs = isSelfDM ? [currentUserAccountID ?? 0] : ReportUtils.getParticipantAccountIDs(report.reportID); + const accountIDs = isSelfDM ? [currentUserAccountID ?? 0] : Object.keys(report.participants ?? {}).map(Number); if (!accountIDs || accountIDs.length === 0) { return; @@ -1680,7 +1680,7 @@ function getOptions( const isMoneyRequestReport = option.isMoneyRequestReport; const isSelfDM = option.isSelfDM; // Currently, currentUser is not included in participants, so for selfDM we need to add the currentUser as participants. - const accountIDs = isSelfDM ? [currentUserAccountID ?? 0] : ReportUtils.getParticipantAccountIDs(report.reportID); + const accountIDs = isSelfDM ? [currentUserAccountID ?? 0] : Object.keys(report.participants ?? {}).map(Number); if (isPolicyExpenseChat && report.isOwnPolicyExpenseChat && !includeOwnedWorkspaceChats) { return; diff --git a/tests/unit/OptionsListUtilsTest.ts b/tests/unit/OptionsListUtilsTest.ts index af5782b1ca32..92e5379bfe31 100644 --- a/tests/unit/OptionsListUtilsTest.ts +++ b/tests/unit/OptionsListUtilsTest.ts @@ -21,6 +21,10 @@ describe('OptionsListUtils', () => { reportID: '1', participantAccountIDs: [2, 1], visibleChatMemberAccountIDs: [2, 1], + participants: { + 2: {}, + 1: {}, + }, reportName: 'Iron Man, Mister Fantastic', type: CONST.REPORT.TYPE.CHAT, }, @@ -31,6 +35,9 @@ describe('OptionsListUtils', () => { reportID: '2', participantAccountIDs: [3], visibleChatMemberAccountIDs: [3], + participants: { + 3: {}, + }, reportName: 'Spider-Man', type: CONST.REPORT.TYPE.CHAT, }, @@ -43,6 +50,9 @@ describe('OptionsListUtils', () => { reportID: '3', participantAccountIDs: [1], visibleChatMemberAccountIDs: [1], + participants: { + 1: {}, + }, reportName: 'Mister Fantastic', type: CONST.REPORT.TYPE.CHAT, }, @@ -53,6 +63,9 @@ describe('OptionsListUtils', () => { reportID: '4', participantAccountIDs: [4], visibleChatMemberAccountIDs: [4], + participants: { + 4: {}, + }, reportName: 'Black Panther', type: CONST.REPORT.TYPE.CHAT, }, @@ -63,6 +76,9 @@ describe('OptionsListUtils', () => { reportID: '5', participantAccountIDs: [5], visibleChatMemberAccountIDs: [5], + participants: { + 5: {}, + }, reportName: 'Invisible Woman', type: CONST.REPORT.TYPE.CHAT, }, @@ -73,6 +89,9 @@ describe('OptionsListUtils', () => { reportID: '6', participantAccountIDs: [6], visibleChatMemberAccountIDs: [6], + participants: { + 6: {}, + }, reportName: 'Thor', type: CONST.REPORT.TYPE.CHAT, }, @@ -85,6 +104,9 @@ describe('OptionsListUtils', () => { reportID: '7', participantAccountIDs: [7], visibleChatMemberAccountIDs: [7], + participants: { + 7: {}, + }, reportName: 'Captain America', type: CONST.REPORT.TYPE.CHAT, }, @@ -97,6 +119,9 @@ describe('OptionsListUtils', () => { reportID: '8', participantAccountIDs: [12], visibleChatMemberAccountIDs: [12], + participants: { + 12: {}, + }, reportName: 'Silver Surfer', type: CONST.REPORT.TYPE.CHAT, }, @@ -109,6 +134,9 @@ describe('OptionsListUtils', () => { reportID: '9', participantAccountIDs: [8], visibleChatMemberAccountIDs: [8], + participants: { + 8: {}, + }, reportName: 'Mister Sinister', iouReportID: '100', type: CONST.REPORT.TYPE.CHAT, @@ -122,6 +150,10 @@ describe('OptionsListUtils', () => { isPinned: false, participantAccountIDs: [2, 7], visibleChatMemberAccountIDs: [2, 7], + participants: { + 2: {}, + 7: {}, + }, reportName: '', oldPolicyName: "SHIELD's workspace", chatType: CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT, @@ -212,6 +244,9 @@ describe('OptionsListUtils', () => { reportID: '11', participantAccountIDs: [999], visibleChatMemberAccountIDs: [999], + participants: { + 999: {}, + }, reportName: 'Concierge', type: CONST.REPORT.TYPE.CHAT, }, @@ -226,6 +261,9 @@ describe('OptionsListUtils', () => { reportID: '12', participantAccountIDs: [1000], visibleChatMemberAccountIDs: [1000], + participants: { + 1000: {}, + }, reportName: 'Chronos', type: CONST.REPORT.TYPE.CHAT, }, @@ -240,6 +278,9 @@ describe('OptionsListUtils', () => { reportID: '13', participantAccountIDs: [1001], visibleChatMemberAccountIDs: [1001], + participants: { + 1001: {}, + }, reportName: 'Receipts', type: CONST.REPORT.TYPE.CHAT, }, @@ -254,6 +295,11 @@ describe('OptionsListUtils', () => { reportID: '14', participantAccountIDs: [1, 10, 3], visibleChatMemberAccountIDs: [1, 10, 3], + participants: { + 1: {}, + 10: {}, + 3: {}, + }, reportName: '', oldPolicyName: 'Avengers Room', chatType: CONST.REPORT.CHAT_TYPE.POLICY_ADMINS, @@ -271,6 +317,10 @@ describe('OptionsListUtils', () => { reportID: '15', participantAccountIDs: [3, 4], visibleChatMemberAccountIDs: [3, 4], + participants: { + 3: {}, + 4: {}, + }, reportName: 'Spider-Man, Black Panther', type: CONST.REPORT.TYPE.CHAT, chatType: CONST.REPORT.CHAT_TYPE.DOMAIN_ALL, @@ -368,6 +418,7 @@ describe('OptionsListUtils', () => { // When we filter in the Search view without providing a searchValue let results = OptionsListUtils.getSearchOptions(OPTIONS, '', [CONST.BETAS.ALL]); // Then the 2 personalDetails that don't have reports should be returned + console.log('personal details', OPTIONS.personalDetails.length, results.personalDetails.length) expect(results.personalDetails.length).toBe(2); // Then all of the reports should be shown including the archived rooms. From c67ba1229a673ae9cb82ae80b0c004f5df0a86a3 Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Tue, 16 Apr 2024 15:36:56 +0800 Subject: [PATCH 4/4] remove log --- tests/unit/OptionsListUtilsTest.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/unit/OptionsListUtilsTest.ts b/tests/unit/OptionsListUtilsTest.ts index 92e5379bfe31..6629bd9e531f 100644 --- a/tests/unit/OptionsListUtilsTest.ts +++ b/tests/unit/OptionsListUtilsTest.ts @@ -418,7 +418,6 @@ describe('OptionsListUtils', () => { // When we filter in the Search view without providing a searchValue let results = OptionsListUtils.getSearchOptions(OPTIONS, '', [CONST.BETAS.ALL]); // Then the 2 personalDetails that don't have reports should be returned - console.log('personal details', OPTIONS.personalDetails.length, results.personalDetails.length) expect(results.personalDetails.length).toBe(2); // Then all of the reports should be shown including the archived rooms.