Changeset View
Changeset View
Standalone View
Standalone View
lib/shared/search-utils.js
Show All 15 Lines | |||||
} from '../types/thread-types.js'; | } from '../types/thread-types.js'; | ||||
import type { AccountUserInfo, UserListItem } from '../types/user-types.js'; | import type { AccountUserInfo, UserListItem } from '../types/user-types.js'; | ||||
const notFriendNotice = 'not friend'; | const notFriendNotice = 'not friend'; | ||||
function getPotentialMemberItems( | function getPotentialMemberItems( | ||||
text: string, | text: string, | ||||
userInfos: { +[id: string]: AccountUserInfo }, | userInfos: { +[id: string]: AccountUserInfo }, | ||||
searchIndex: SearchIndex, | inputSearchIndex: SearchIndex | $ReadOnlyArray<SearchIndex>, | ||||
excludeUserIDs: $ReadOnlyArray<string>, | excludeUserIDs: $ReadOnlyArray<string>, | ||||
inputParentThreadInfo: ?ThreadInfo, | inputParentThreadInfo: ?ThreadInfo, | ||||
inputCommunityThreadInfo: ?ThreadInfo, | inputCommunityThreadInfo: ?ThreadInfo, | ||||
threadType: ?ThreadType, | threadType: ?ThreadType, | ||||
): UserListItem[] { | ): UserListItem[] { | ||||
const searchIndexes = Array.isArray(inputSearchIndex) | |||||
? inputSearchIndex | |||||
: [inputSearchIndex]; | |||||
const communityThreadInfo = | const communityThreadInfo = | ||||
inputCommunityThreadInfo && inputCommunityThreadInfo.id !== genesis.id | inputCommunityThreadInfo && inputCommunityThreadInfo.id !== genesis.id | ||||
? inputCommunityThreadInfo | ? inputCommunityThreadInfo | ||||
: null; | : null; | ||||
const parentThreadInfo = | const parentThreadInfo = | ||||
inputParentThreadInfo && inputParentThreadInfo.id !== genesis.id | inputParentThreadInfo && inputParentThreadInfo.id !== genesis.id | ||||
? inputParentThreadInfo | ? inputParentThreadInfo | ||||
: null; | : null; | ||||
Show All 31 Lines | results.push({ | ||||
isMemberOfContainingThread: userIsMember(containingThreadInfo, id), | isMemberOfContainingThread: userIsMember(containingThreadInfo, id), | ||||
}); | }); | ||||
}; | }; | ||||
if (text === '') { | if (text === '') { | ||||
for (const id in userInfos) { | for (const id in userInfos) { | ||||
appendUserInfo(userInfos[id]); | appendUserInfo(userInfos[id]); | ||||
} | } | ||||
} else { | } else { | ||||
for (const searchIndex of searchIndexes) { | |||||
const ids = searchIndex.getSearchResults(text); | const ids = searchIndex.getSearchResults(text); | ||||
for (const id of ids) { | for (const id of ids) { | ||||
appendUserInfo(userInfos[id]); | appendUserInfo(userInfos[id]); | ||||
} | } | ||||
} | } | ||||
} | |||||
michal: This won't happen now but I think we should check if we aren't adding duplicates from the… | |||||
const blockedRelationshipsStatuses = new Set([ | const blockedRelationshipsStatuses = new Set([ | ||||
userRelationshipStatus.BLOCKED_BY_VIEWER, | userRelationshipStatus.BLOCKED_BY_VIEWER, | ||||
userRelationshipStatus.BLOCKED_VIEWER, | userRelationshipStatus.BLOCKED_VIEWER, | ||||
userRelationshipStatus.BOTH_BLOCKED, | userRelationshipStatus.BOTH_BLOCKED, | ||||
]); | ]); | ||||
if (text === '') { | if (text === '') { | ||||
▲ Show 20 Lines • Show All 86 Lines • Show Last 20 Lines |
This won't happen now but I think we should check if we aren't adding duplicates from the searchIndexes.