diff --git a/lib/selectors/user-selectors.js b/lib/selectors/user-selectors.js --- a/lib/selectors/user-selectors.js +++ b/lib/selectors/user-selectors.js @@ -16,10 +16,7 @@ import type { BaseAppState } from '../types/redux-types.js'; import { userRelationshipStatus } from '../types/relationship-types.js'; import { threadTypes } from '../types/thread-types-enum.js'; -import type { - LegacyRawThreadInfo, - RawThreadInfos, -} from '../types/thread-types.js'; +import type { RawThreadInfos } from '../types/thread-types.js'; import type { UserInfos, RelativeUserInfo, @@ -37,72 +34,49 @@ const relativeUserInfos: RelativeUserInfo[] = []; for (const userID of userIDs) { const username = userInfos[userID] ? userInfos[userID].username : null; + const relativeUserInfo = { + id: userID, + username, + isViewer: userID === viewerID, + }; if (userID === viewerID) { - relativeUserInfos.unshift({ - id: userID, - username, - isViewer: true, - }); + relativeUserInfos.unshift(relativeUserInfo); } else { - relativeUserInfos.push({ - id: userID, - username, - isViewer: false, - }); + relativeUserInfos.push(relativeUserInfo); } } return relativeUserInfos; } -type ExtractArrayParam = (arr: $ReadOnlyArray) => T; - -function getRelativeMemberInfos( - threadInfo: ?TI, +function getRelativeMemberInfos( + threadInfo: ?RawThreadInfo, currentUserID: ?string, userInfos: UserInfos, -): $ReadOnlyArray< - $ReadOnly<{ - ...$Call>, - +username: ?string, - +isViewer: boolean, - }>, -> { - const relativeMemberInfos: Array< - $ReadOnly<{ - ...$Call>, - +username: ?string, - +isViewer: boolean, - }>, - > = []; +): $ReadOnlyArray { + const relativeMemberInfos: RelativeMemberInfo[] = []; if (!threadInfo) { return relativeMemberInfos; } const memberInfos = threadInfo.members; - for (const memberInfoInput of memberInfos) { - const memberInfo: $Call< - ExtractArrayParam, - $PropertyType, - > = memberInfoInput; + for (const memberInfo of memberInfos) { if (!memberInfo.role) { continue; } - const username: ?string = userInfos[memberInfo.id] + const username = userInfos[memberInfo.id] ? userInfos[memberInfo.id].username : null; - const isViewer: boolean = memberInfo.id === currentUserID; - const relativeMemberInfo: $ReadOnly<{ - ...$Call>, - +username: ?string, - +isViewer: boolean, - }> = { - ...memberInfo, - username, - isViewer, - }; - if (isViewer) { - relativeMemberInfos.unshift(relativeMemberInfo); + if (memberInfo.id === currentUserID) { + relativeMemberInfos.unshift({ + ...memberInfo, + username, + isViewer: true, + }); } else { - relativeMemberInfos.push(relativeMemberInfo); + relativeMemberInfos.push({ + ...memberInfo, + username, + isViewer: false, + }); } } return relativeMemberInfos;