Page MenuHomePhabricator

D10235.id34599.diff
No OneTemporary

D10235.id34599.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,12 +11,12 @@
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';
import type {
LegacyRawThreadInfo,
- LegacyRelativeMemberInfo,
RelativeMemberInfo,
RawThreadInfos,
} from '../types/thread-types.js';
@@ -54,46 +54,64 @@
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;
}
-const emptyArray: $ReadOnlyArray<LegacyRelativeMemberInfo> = [];
+const emptyArray: $ReadOnlyArray<RelativeMemberInfo> = [];
// Includes current user at the start
const baseRelativeMemberInfoSelectorForMembersOfThread: (
threadID: ?string,
-) => (state: BaseAppState<>) => $ReadOnlyArray<LegacyRelativeMemberInfo> = (
+) => (state: BaseAppState<>) => $ReadOnlyArray<RelativeMemberInfo> = (
threadID: ?string,
) => {
if (!threadID) {

File Metadata

Mime Type
text/plain
Expires
Wed, Nov 27, 9:25 PM (17 h, 44 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2591712
Default Alt Text
D10235.id34599.diff (3 KB)

Event Timeline