Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3158443
D10235.id34598.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D10235.id34598.diff
View Options
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
Details
Attached
Mime Type
text/plain
Expires
Wed, Nov 6, 9:49 PM (19 h, 26 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2432618
Default Alt Text
D10235.id34598.diff (2 KB)
Attached To
Mode
D10235: [lib] Update `getRelativeMemberInfos` to handle both `MinimallyEncoded` and `Legacy` variants
Attached
Detach File
Event Timeline
Log In to Comment