Changeset View
Changeset View
Standalone View
Standalone View
lib/selectors/user-selectors.js
Show First 20 Lines • Show All 107 Lines • ▼ Show 20 Lines | |||||
}; | }; | ||||
const relativeMemberInfoSelectorForMembersOfThread: ( | const relativeMemberInfoSelectorForMembersOfThread: ( | ||||
threadID: ?string, | threadID: ?string, | ||||
) => (state: BaseAppState<*>) => $ReadOnlyArray<RelativeMemberInfo> = _memoize( | ) => (state: BaseAppState<*>) => $ReadOnlyArray<RelativeMemberInfo> = _memoize( | ||||
baseRelativeMemberInfoSelectorForMembersOfThread, | baseRelativeMemberInfoSelectorForMembersOfThread, | ||||
); | ); | ||||
const userInfoSelectorForPotentialMembers: ( | function filterPotentialMembers( | ||||
state: BaseAppState<*>, | |||||
) => { [id: string]: AccountUserInfo } = createSelector( | |||||
(state: BaseAppState<*>) => state.userStore.userInfos, | |||||
(state: BaseAppState<*>) => state.currentUserInfo && state.currentUserInfo.id, | |||||
( | |||||
userInfos: UserInfos, | userInfos: UserInfos, | ||||
currentUserID: ?string, | currentUserID: ?string, | ||||
): { [id: string]: AccountUserInfo } => { | ): { [id: string]: AccountUserInfo } { | ||||
const availableUsers: { [id: string]: AccountUserInfo } = {}; | const availableUsers: { [id: string]: AccountUserInfo } = {}; | ||||
for (const id in userInfos) { | for (const id in userInfos) { | ||||
const { username, relationshipStatus } = userInfos[id]; | const { username, relationshipStatus } = userInfos[id]; | ||||
if (id === currentUserID || !username) { | if (id === currentUserID || !username) { | ||||
continue; | continue; | ||||
} | } | ||||
if ( | if ( | ||||
relationshipStatus !== userRelationshipStatus.BLOCKED_VIEWER && | relationshipStatus !== userRelationshipStatus.BLOCKED_VIEWER && | ||||
relationshipStatus !== userRelationshipStatus.BOTH_BLOCKED | relationshipStatus !== userRelationshipStatus.BOTH_BLOCKED | ||||
) { | ) { | ||||
availableUsers[id] = { id, username, relationshipStatus }; | availableUsers[id] = { id, username, relationshipStatus }; | ||||
} | } | ||||
} | } | ||||
return availableUsers; | return availableUsers; | ||||
}, | } | ||||
const userInfoSelectorForPotentialMembers: ( | |||||
state: BaseAppState<*>, | |||||
) => { [id: string]: AccountUserInfo } = createSelector( | |||||
(state: BaseAppState<*>) => state.userStore.userInfos, | |||||
(state: BaseAppState<*>) => state.currentUserInfo && state.currentUserInfo.id, | |||||
filterPotentialMembers, | |||||
); | ); | ||||
function searchIndexFromUserInfos(userInfos: { | function searchIndexFromUserInfos(userInfos: { | ||||
[id: string]: AccountUserInfo, | [id: string]: AccountUserInfo, | ||||
}) { | }) { | ||||
const searchIndex = new SearchIndex(); | const searchIndex = new SearchIndex(); | ||||
for (const id in userInfos) { | for (const id in userInfos) { | ||||
searchIndex.addEntry(id, userInfos[id].username); | searchIndex.addEntry(id, userInfos[id].username); | ||||
▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | export { | ||||
userIDsToRelativeUserInfos, | userIDsToRelativeUserInfos, | ||||
getRelativeMemberInfos, | getRelativeMemberInfos, | ||||
relativeMemberInfoSelectorForMembersOfThread, | relativeMemberInfoSelectorForMembersOfThread, | ||||
userInfoSelectorForPotentialMembers, | userInfoSelectorForPotentialMembers, | ||||
userSearchIndexForPotentialMembers, | userSearchIndexForPotentialMembers, | ||||
isLoggedIn, | isLoggedIn, | ||||
userStoreSearchIndex, | userStoreSearchIndex, | ||||
usersWithPersonalThreadSelector, | usersWithPersonalThreadSelector, | ||||
filterPotentialMembers, | |||||
}; | }; |