Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix allow to search selfDM in new chat page #40672

Merged
merged 9 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/libs/OptionsListUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1505,7 +1505,8 @@ function createOptionList(personalDetails: OnyxEntry<PersonalDetailsList>, repor
}

function createOptionFromReport(report: Report, personalDetails: OnyxEntry<PersonalDetailsList>) {
const accountIDs = report.participantAccountIDs ?? [];
const isSelfDM = ReportUtils.isSelfDM(report);
const accountIDs = isSelfDM ? [currentUserAccountID ?? 0] : report.participantAccountIDs ?? [];

return {
item: report,
Expand Down Expand Up @@ -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});
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@s77rt Using like this leads to the jest test 2 is failed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I revert that change and update this to:

 if (!reportOption.isSelfDM &&
                (!includeThreads &&
                    (!!reportOption.login || reportOption.reportID) &&
                    optionsToExclude.some((option) => option.login === reportOption.login || option.reportID === reportOption.reportID))
            ) {

the test is passed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not seeing any failing test

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


// 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
Expand Down
11 changes: 11 additions & 0 deletions src/pages/NewChatPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ function useOptions({isGroupChat}: NewChatPageProps) {
{},
[],
true,
undefined,
undefined,
undefined,
true,
);
const maxParticipantsReached = selectedOptions.length === CONST.REPORT.MAXIMUM_PARTICIPANTS;

Expand Down Expand Up @@ -182,6 +186,10 @@ function NewChatPage({isGroupChat}: NewChatPageProps) {
*/
const createChat = useCallback(
(option?: OptionsListUtils.Option) => {
if (option?.isSelfDM) {
Navigation.dismissModal(option.reportID);
return;
}
let login = '';

if (option?.login) {
Expand All @@ -200,6 +208,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
Expand Down
Loading