From 90834be4db9ffdcf72d07bf94a91676d4bcfa83e Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Mon, 22 Apr 2024 13:33:21 +0700 Subject: [PATCH 1/9] fix allow to search selfDM in new chat page --- src/libs/OptionsListUtils.ts | 8 ++++++-- src/pages/NewChatPage.tsx | 14 +++++++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 2aad4179c337..049e538cb18a 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -1505,7 +1505,8 @@ function createOptionList(personalDetails: OnyxEntry, repor } function createOptionFromReport(report: Report, personalDetails: OnyxEntry) { - const accountIDs = report.participantAccountIDs ?? []; + const isSelfDM = ReportUtils.isSelfDM(report); + const accountIDs = isSelfDM ? [currentUserAccountID ?? 0] : report.participantAccountIDs ?? []; return { item: report, @@ -1741,7 +1742,10 @@ function getOptions( } // Exclude the current user from the personal details list - const optionsToExclude: Option[] = [{login: currentUserLogin}, {login: CONST.EMAIL.NOTIFICATIONS}]; + const optionsToExclude: Option[] = [{login: CONST.EMAIL.NOTIFICATIONS}]; + if (!includeSelfDM) { + optionsToExclude.push({login: currentUserLogin}); + } // If we're including selected options from the search results, we only want to exclude them if the search input is empty // This is because on certain pages, we show the selected options at the top when the search input is empty diff --git a/src/pages/NewChatPage.tsx b/src/pages/NewChatPage.tsx index 470afc28d76e..b3ac000daea7 100755 --- a/src/pages/NewChatPage.tsx +++ b/src/pages/NewChatPage.tsx @@ -25,7 +25,7 @@ import * as DeviceCapabilities from '@libs/DeviceCapabilities'; import Log from '@libs/Log'; import Navigation from '@libs/Navigation/Navigation'; import * as OptionsListUtils from '@libs/OptionsListUtils'; -import type {OptionData} from '@libs/ReportUtils'; +import {getReport, type OptionData} from '@libs/ReportUtils'; import variables from '@styles/variables'; import * as Report from '@userActions/Report'; import CONST from '@src/CONST'; @@ -68,6 +68,10 @@ function useOptions({isGroupChat}: NewChatPageProps) { {}, [], true, + undefined, + undefined, + undefined, + true, ); const maxParticipantsReached = selectedOptions.length === CONST.REPORT.MAXIMUM_PARTICIPANTS; @@ -182,6 +186,11 @@ function NewChatPage({isGroupChat}: NewChatPageProps) { */ const createChat = useCallback( (option?: OptionsListUtils.Option) => { + const report = getReport(option?.reportID); + if (option?.isSelfDM && report) { + Navigation.dismissModalWithReport(report); + return; + } let login = ''; if (option?.login) { @@ -200,6 +209,9 @@ function NewChatPage({isGroupChat}: NewChatPageProps) { const itemRightSideComponent = useCallback( (item: ListItem & OptionsListUtils.Option) => { + if (item.isSelfDM) { + return null; + } /** * Removes a selected option from list if already selected. If not already selected add this option to the list. * @param option From 4fa9decddd651f15dd24cc19aef277acaf837288 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Mon, 22 Apr 2024 13:51:13 +0700 Subject: [PATCH 2/9] fix lint --- src/pages/NewChatPage.tsx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/pages/NewChatPage.tsx b/src/pages/NewChatPage.tsx index b3ac000daea7..f0b983033c94 100755 --- a/src/pages/NewChatPage.tsx +++ b/src/pages/NewChatPage.tsx @@ -25,7 +25,8 @@ import * as DeviceCapabilities from '@libs/DeviceCapabilities'; import Log from '@libs/Log'; import Navigation from '@libs/Navigation/Navigation'; import * as OptionsListUtils from '@libs/OptionsListUtils'; -import {getReport, type OptionData} from '@libs/ReportUtils'; +import type {OptionData} from '@libs/ReportUtils'; +import * as ReportUtils from '@libs/ReportUtils'; import variables from '@styles/variables'; import * as Report from '@userActions/Report'; import CONST from '@src/CONST'; @@ -186,9 +187,9 @@ function NewChatPage({isGroupChat}: NewChatPageProps) { */ const createChat = useCallback( (option?: OptionsListUtils.Option) => { - const report = getReport(option?.reportID); + const report = ReportUtils.getReport(option?.reportID); if (option?.isSelfDM && report) { - Navigation.dismissModalWithReport(report); + Navigation.dismissModal(report.reportID); return; } let login = ''; From 84605aad893eab7948de04f89f980eca8e372583 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Mon, 22 Apr 2024 14:30:01 +0700 Subject: [PATCH 3/9] fix use option.reportID in createChat --- src/pages/NewChatPage.tsx | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/pages/NewChatPage.tsx b/src/pages/NewChatPage.tsx index f0b983033c94..3e5a99c1b222 100755 --- a/src/pages/NewChatPage.tsx +++ b/src/pages/NewChatPage.tsx @@ -187,9 +187,8 @@ function NewChatPage({isGroupChat}: NewChatPageProps) { */ const createChat = useCallback( (option?: OptionsListUtils.Option) => { - const report = ReportUtils.getReport(option?.reportID); - if (option?.isSelfDM && report) { - Navigation.dismissModal(report.reportID); + if (option?.isSelfDM) { + Navigation.dismissModal(option.reportID); return; } let login = ''; From d40e0cf3c16eb0737d18b26b682d99cd192dd6c2 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Mon, 22 Apr 2024 14:36:26 +0700 Subject: [PATCH 4/9] fix lint --- src/pages/NewChatPage.tsx | 1 - tests/unit/OptionsListUtilsTest.ts | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/pages/NewChatPage.tsx b/src/pages/NewChatPage.tsx index 3e5a99c1b222..3f0c9a23da3f 100755 --- a/src/pages/NewChatPage.tsx +++ b/src/pages/NewChatPage.tsx @@ -26,7 +26,6 @@ import Log from '@libs/Log'; import Navigation from '@libs/Navigation/Navigation'; import * as OptionsListUtils from '@libs/OptionsListUtils'; import type {OptionData} from '@libs/ReportUtils'; -import * as ReportUtils from '@libs/ReportUtils'; import variables from '@styles/variables'; import * as Report from '@userActions/Report'; import CONST from '@src/CONST'; diff --git a/tests/unit/OptionsListUtilsTest.ts b/tests/unit/OptionsListUtilsTest.ts index 75ed7fa9d5b1..4c332d0e2e07 100644 --- a/tests/unit/OptionsListUtilsTest.ts +++ b/tests/unit/OptionsListUtilsTest.ts @@ -368,7 +368,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 - expect(results.personalDetails.length).toBe(2); + expect(results.personalDetails.length).toBe(3); // Then all of the reports should be shown including the archived rooms. expect(results.recentReports.length).toBe(Object.values(OPTIONS.reports).length); @@ -2618,7 +2618,7 @@ describe('OptionsListUtils', () => { const options = OptionsListUtils.getSearchOptions(OPTIONS, '', [CONST.BETAS.ALL]); const filteredOptions = OptionsListUtils.filterOptions(options, searchText); - expect(filteredOptions.recentReports.length).toBe(5); + expect(filteredOptions.recentReports.length).toBe(6); expect(filteredOptions.recentReports[0].text).toBe('Invisible Woman'); expect(filteredOptions.recentReports[1].text).toBe('Spider-Man'); expect(filteredOptions.recentReports[2].text).toBe('Black Widow'); From ac68346d8a8bd3b0e91d5547af3dd295b1d090d0 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Mon, 22 Apr 2024 14:50:03 +0700 Subject: [PATCH 5/9] fix revert fix jest --- tests/unit/OptionsListUtilsTest.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit/OptionsListUtilsTest.ts b/tests/unit/OptionsListUtilsTest.ts index 4c332d0e2e07..75ed7fa9d5b1 100644 --- a/tests/unit/OptionsListUtilsTest.ts +++ b/tests/unit/OptionsListUtilsTest.ts @@ -368,7 +368,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 - expect(results.personalDetails.length).toBe(3); + expect(results.personalDetails.length).toBe(2); // Then all of the reports should be shown including the archived rooms. expect(results.recentReports.length).toBe(Object.values(OPTIONS.reports).length); @@ -2618,7 +2618,7 @@ describe('OptionsListUtils', () => { const options = OptionsListUtils.getSearchOptions(OPTIONS, '', [CONST.BETAS.ALL]); const filteredOptions = OptionsListUtils.filterOptions(options, searchText); - expect(filteredOptions.recentReports.length).toBe(6); + expect(filteredOptions.recentReports.length).toBe(5); expect(filteredOptions.recentReports[0].text).toBe('Invisible Woman'); expect(filteredOptions.recentReports[1].text).toBe('Spider-Man'); expect(filteredOptions.recentReports[2].text).toBe('Black Widow'); From 666e9dab5eb4d064dec1d018b76e9f27e5a0fbb4 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Wed, 24 Apr 2024 02:48:13 +0700 Subject: [PATCH 6/9] fix jest test --- src/libs/OptionsListUtils.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 049e538cb18a..4f647e760519 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -1743,9 +1743,6 @@ function getOptions( // Exclude the current user from the personal details list const optionsToExclude: Option[] = [{login: CONST.EMAIL.NOTIFICATIONS}]; - if (!includeSelfDM) { - optionsToExclude.push({login: currentUserLogin}); - } // If we're including selected options from the search results, we only want to exclude them if the search input is empty // This is because on certain pages, we show the selected options at the top when the search input is empty @@ -1824,6 +1821,7 @@ function getOptions( } if (includePersonalDetails) { + optionsToExclude.push({login: currentUserLogin}); // Next loop over all personal details removing any that are selectedUsers or recentChats allPersonalDetailsOptions.forEach((personalDetailOption) => { if (optionsToExclude.some((optionToExclude) => optionToExclude.login === personalDetailOption.login)) { From f60a61093e447477b14b65a5ef96caa3df36bbb6 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Wed, 24 Apr 2024 03:00:39 +0700 Subject: [PATCH 7/9] fix move logic push currentUserLogin to top --- src/libs/OptionsListUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 4f647e760519..de1f1ca797f4 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -1820,8 +1820,8 @@ function getOptions( } } + optionsToExclude.push({login: currentUserLogin}); if (includePersonalDetails) { - optionsToExclude.push({login: currentUserLogin}); // Next loop over all personal details removing any that are selectedUsers or recentChats allPersonalDetailsOptions.forEach((personalDetailOption) => { if (optionsToExclude.some((optionToExclude) => optionToExclude.login === personalDetailOption.login)) { From 6698121471588e6138e368126802df2d5182ab03 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Wed, 24 Apr 2024 10:00:06 +0700 Subject: [PATCH 8/9] fix create new var personalDetailsOptionsToExclude --- 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 de1f1ca797f4..508aead725a4 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -1820,11 +1820,11 @@ function getOptions( } } - optionsToExclude.push({login: currentUserLogin}); if (includePersonalDetails) { + const personalDetailsOptionsToExclude = [...optionsToExclude, {login: currentUserLogin}]; // Next loop over all personal details removing any that are selectedUsers or recentChats allPersonalDetailsOptions.forEach((personalDetailOption) => { - if (optionsToExclude.some((optionToExclude) => optionToExclude.login === personalDetailOption.login)) { + if (personalDetailsOptionsToExclude.some((optionToExclude) => optionToExclude.login === personalDetailOption.login)) { return; } const {searchText, participantsList, isChatRoom} = personalDetailOption; From 003defb7825d83f3b6d8406351b549c0880342a1 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Wed, 24 Apr 2024 10:00:48 +0700 Subject: [PATCH 9/9] fix remove comment --- src/libs/OptionsListUtils.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 508aead725a4..b9e62be19769 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -1741,7 +1741,6 @@ function getOptions( allPersonalDetailsOptions = lodashOrderBy(allPersonalDetailsOptions, [(personalDetail) => personalDetail.text?.toLowerCase()], 'asc'); } - // Exclude the current user from the personal details list const optionsToExclude: Option[] = [{login: CONST.EMAIL.NOTIFICATIONS}]; // If we're including selected options from the search results, we only want to exclude them if the search input is empty