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 10 Lines | ): UserListItem[] { | ||||
} | } | ||||
let results = []; | let results = []; | ||||
const appendUserInfo = (userInfo: AccountUserInfo) => { | const appendUserInfo = (userInfo: AccountUserInfo) => { | ||||
const { id } = userInfo; | const { id } = userInfo; | ||||
if (excludeUserIDs.includes(id)) { | if (excludeUserIDs.includes(id)) { | ||||
return; | return; | ||||
} | } | ||||
if (results.some(item => item.id === id)) { | |||||
return; | |||||
} | |||||
if ( | if ( | ||||
communityThreadInfo && | communityThreadInfo && | ||||
!threadMemberHasPermission( | !threadMemberHasPermission( | ||||
communityThreadInfo, | communityThreadInfo, | ||||
id, | id, | ||||
threadPermissions.KNOW_OF, | threadPermissions.KNOW_OF, | ||||
) | ) | ||||
) { | ) { | ||||
return; | return; | ||||
} | } | ||||
results.push({ | results.push({ | ||||
...userInfo, | ...userInfo, | ||||
isMemberOfParentThread: userIsMember(parentThreadInfo, id), | isMemberOfParentThread: userIsMember(parentThreadInfo, id), | ||||
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]); | ||||
} | } | ||||
} | } | ||||
} | |||||
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 |