Skip to content

Commit

Permalink
[lib] fix useThreadSearchIndex to avoid ignoring private thread
Browse files Browse the repository at this point in the history
Summary:
[ENG-9378](https://linear.app/comm/issue/ENG-9378/cant-find-genesis-private-thread-when-searching-ones-username#comment-57c320a9).

This code was ignoring private threads and as a result, causing that private thread not to show up.
On prod, it works only for old users where by default thread name was the user's name, after changing the name in settings it is not working anymore. Right now, when creating an account `name` is not set for the private thread, it's an optional field and not set to own username - that is why this is not working for dev where we have new users.

Test Plan: Searching for my username works (even if I changed name of my private thread).

Reviewers: tomek, ashoat

Reviewed By: ashoat

Differential Revision: https://phab.comm.dev/D13461
  • Loading branch information
xsanm committed Sep 25, 2024
1 parent d788f39 commit 1bab181
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/selectors/nav-selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import type {
} from '../types/minimally-encoded-thread-permissions-types.js';
import type { BaseNavInfo } from '../types/nav-types.js';
import type { BaseAppState } from '../types/redux-types.js';
import { threadTypeIsPrivate } from '../types/thread-types-enum.js';
import type { UserInfo } from '../types/user-types.js';
import { getConfig } from '../utils/config.js';
import { values } from '../utils/objects.js';
Expand Down Expand Up @@ -168,7 +169,10 @@ function useThreadSearchIndex(
searchTextArray.push(threadInfo.description);
}
for (const member of threadInfo.members) {
if (!member.role || member.id === viewerID) {
if (
!member.role ||
(member.id === viewerID && !threadTypeIsPrivate(threadInfo.type))
) {
continue;
}
const userInfo = userInfos[member.id];
Expand Down
9 changes: 9 additions & 0 deletions lib/types/thread-types-enum.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ export const personalThreadTypes: $ReadOnlyArray<number> = Object.freeze([
threadTypes.GENESIS_PERSONAL,
]);

export const privateThreadTypes: $ReadOnlyArray<number> = Object.freeze([
threadTypes.PRIVATE,
threadTypes.GENESIS_PRIVATE,
]);

export function threadTypeIsCommunityRoot(threadType: ThreadType): boolean {
return communityThreadTypes.includes(threadType);
}
Expand All @@ -183,3 +188,7 @@ export function threadTypeIsSidebar(threadType: ThreadType): boolean {
export function threadTypeIsPersonal(threadType: ThreadType): boolean {
return personalThreadTypes.includes(threadType);
}

export function threadTypeIsPrivate(threadType: ThreadType): boolean {
return privateThreadTypes.includes(threadType);
}

0 comments on commit 1bab181

Please sign in to comment.