Page MenuHomePhabricator

D10235.id34596.diff
No OneTemporary

D10235.id34596.diff

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
@@ -11,6 +11,7 @@
import SentencePrefixSearchIndex from '../shared/sentence-prefix-search-index.js';
import { getSingleOtherUser } from '../shared/thread-utils.js';
import type { ClientEmojiAvatar } from '../types/avatar-types';
+import type { MinimallyEncodedRawThreadInfo } from '../types/minimally-encoded-thread-permissions-types.js';
import type { BaseAppState } from '../types/redux-types.js';
import { userRelationshipStatus } from '../types/relationship-types.js';
import { threadTypes } from '../types/thread-types-enum.js';
@@ -54,36 +55,54 @@
return relativeUserInfos;
}
-function getRelativeMemberInfos(
- threadInfo: ?LegacyRawThreadInfo,
+type ExtractArrayParam = <T>(arr: $ReadOnlyArray<T>) => T;
+
+function getRelativeMemberInfos<
+ TI: MinimallyEncodedRawThreadInfo | LegacyRawThreadInfo,
+>(
+ threadInfo: ?TI,
currentUserID: ?string,
userInfos: UserInfos,
-): $ReadOnlyArray<LegacyRelativeMemberInfo> {
- const relativeMemberInfos = [];
+): $ReadOnlyArray<
+ $ReadOnly<{
+ ...$Call<ExtractArrayParam, $PropertyType<TI, 'members'>>,
+ +username: ?string,
+ +isViewer: boolean,
+ }>,
+> {
+ const relativeMemberInfos: Array<
+ $ReadOnly<{
+ ...$Call<ExtractArrayParam, $PropertyType<TI, 'members'>>,
+ +username: ?string,
+ +isViewer: boolean,
+ }>,
+ > = [];
if (!threadInfo) {
return relativeMemberInfos;
}
const memberInfos = threadInfo.members;
- for (const memberInfo of memberInfos) {
+ for (const memberInfoInput of memberInfos) {
+ const memberInfo: $Call<
+ ExtractArrayParam,
+ $PropertyType<TI, 'members'>,
+ > = memberInfoInput;
if (!memberInfo.role) {
continue;
}
- const username = userInfos[memberInfo.id]
+ const username: ?string = userInfos[memberInfo.id]
? userInfos[memberInfo.id].username
: null;
- if (memberInfo.id === currentUserID) {
- relativeMemberInfos.unshift({
- ...memberInfo,
- username,
- isViewer: true,
- });
- } else {
- relativeMemberInfos.push({
- ...memberInfo,
- username,
- isViewer: false,
- });
- }
+ const isViewer: boolean = memberInfo.id === currentUserID;
+ const relativeMemberInfo: $ReadOnly<{
+ ...$Call<ExtractArrayParam, $PropertyType<TI, 'members'>>,
+ +username: ?string,
+ +isViewer: boolean,
+ }> = {
+ ...memberInfo,
+ username,
+ isViewer,
+ };
+ relativeMemberInfos.unshift(relativeMemberInfo);
}
return relativeMemberInfos;
}

File Metadata

Mime Type
text/plain
Expires
Wed, Nov 6, 9:34 PM (19 h, 5 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2432618
Default Alt Text
D10235.id34596.diff (2 KB)

Event Timeline