Changeset View
Changeset View
Standalone View
Standalone View
lib/shared/typeahead-utils.js
// @flow | // @flow | ||||
import type { RelativeMemberInfo } from '../types/thread-types'; | import type { RelativeMemberInfo } from '../types/thread-types'; | ||||
import SearchIndex from './search-index'; | import SearchIndex from './search-index'; | ||||
import { threadOtherMembers } from './thread-utils'; | |||||
import { stringForUserExplicit } from './user-utils'; | import { stringForUserExplicit } from './user-utils'; | ||||
function getTypeaheadUserSuggestions( | function getTypeaheadUserSuggestions( | ||||
userSearchIndex: SearchIndex, | userSearchIndex: SearchIndex, | ||||
usersInThread: $ReadOnlyArray<RelativeMemberInfo>, | threadMembers: $ReadOnlyArray<RelativeMemberInfo>, | ||||
typedPrefix: string, | viewerID: ?string, | ||||
typedUsernamePrefix: string, | |||||
): $ReadOnlyArray<RelativeMemberInfo> { | ): $ReadOnlyArray<RelativeMemberInfo> { | ||||
const userIDs = userSearchIndex.getSearchResults(typedPrefix); | const userIDs = userSearchIndex.getSearchResults(typedUsernamePrefix); | ||||
const usersInThread = threadOtherMembers(threadMembers, viewerID); | |||||
return usersInThread | return usersInThread | ||||
.filter(user => typedPrefix.length === 0 || userIDs.includes(user.id)) | .filter( | ||||
user => typedUsernamePrefix.length === 0 || userIDs.includes(user.id), | |||||
) | |||||
.sort((userA, userB) => | .sort((userA, userB) => | ||||
stringForUserExplicit(userA).localeCompare(stringForUserExplicit(userB)), | stringForUserExplicit(userA).localeCompare(stringForUserExplicit(userB)), | ||||
); | ); | ||||
} | } | ||||
export { getTypeaheadUserSuggestions }; | export { getTypeaheadUserSuggestions }; |