Page MenuHomePhorge

D10640.1768994385.diff
No OneTemporary

Size
11 KB
Referenced Files
None
Subscribers
None

D10640.1768994385.diff

diff --git a/lib/selectors/thread-selectors.js b/lib/selectors/thread-selectors.js
--- a/lib/selectors/thread-selectors.js
+++ b/lib/selectors/thread-selectors.js
@@ -39,7 +39,10 @@
import type { ClientAvatar, ClientEmojiAvatar } from '../types/avatar-types';
import type { EntryInfo } from '../types/entry-types.js';
import type { MessageStore, RawMessageInfo } from '../types/message-types.js';
-import type { RawThreadInfo } from '../types/minimally-encoded-thread-permissions-types.js';
+import type {
+ MinimallyEncodedThreadInfo,
+ RawThreadInfo,
+} from '../types/minimally-encoded-thread-permissions-types.js';
import type { BaseAppState } from '../types/redux-types.js';
import { threadPermissions } from '../types/thread-permission-types.js';
import {
@@ -50,9 +53,9 @@
import type {
SidebarInfo,
RelativeMemberInfo,
- ThreadInfo,
MixedRawThreadInfos,
RawThreadInfos,
+ LegacyThreadInfo,
} from '../types/thread-types.js';
import { dateString, dateFromString } from '../utils/date-utils.js';
import { values } from '../utils/objects.js';
@@ -60,7 +63,7 @@
const _mapValuesWithKeys = _mapValues.convert({ cap: false });
type ThreadInfoSelectorType = (state: BaseAppState<>) => {
- +[id: string]: ThreadInfo,
+ +[id: string]: LegacyThreadInfo | MinimallyEncodedThreadInfo,
};
const threadInfoSelector: ThreadInfoSelectorType = createObjectSelector(
(state: BaseAppState<>) => state.threadStore.threadInfos,
@@ -71,64 +74,78 @@
const communityThreadSelector: (
state: BaseAppState<>,
-) => $ReadOnlyArray<ThreadInfo> = createSelector(
- threadInfoSelector,
- (threadInfos: { +[id: string]: ThreadInfo }) => {
- const result = [];
- for (const threadID in threadInfos) {
- const threadInfo = threadInfos[threadID];
- if (!threadTypeIsCommunityRoot(threadInfo.type)) {
- continue;
+) => $ReadOnlyArray<LegacyThreadInfo | MinimallyEncodedThreadInfo> =
+ createSelector(
+ threadInfoSelector,
+ (threadInfos: {
+ +[id: string]: LegacyThreadInfo | MinimallyEncodedThreadInfo,
+ }) => {
+ const result = [];
+ for (const threadID in threadInfos) {
+ const threadInfo = threadInfos[threadID];
+ if (!threadTypeIsCommunityRoot(threadInfo.type)) {
+ continue;
+ }
+ result.push(threadInfo);
}
- result.push(threadInfo);
- }
- return result;
- },
-);
+ return result;
+ },
+ );
const canBeOnScreenThreadInfos: (
state: BaseAppState<>,
-) => $ReadOnlyArray<ThreadInfo> = createSelector(
- threadInfoSelector,
- (threadInfos: { +[id: string]: ThreadInfo }) => {
- const result = [];
- for (const threadID in threadInfos) {
- const threadInfo = threadInfos[threadID];
- if (!threadInFilterList(threadInfo)) {
- continue;
+) => $ReadOnlyArray<LegacyThreadInfo | MinimallyEncodedThreadInfo> =
+ createSelector(
+ threadInfoSelector,
+ (threadInfos: {
+ +[id: string]: LegacyThreadInfo | MinimallyEncodedThreadInfo,
+ }) => {
+ const result = [];
+ for (const threadID in threadInfos) {
+ const threadInfo = threadInfos[threadID];
+ if (!threadInFilterList(threadInfo)) {
+ continue;
+ }
+ result.push(threadInfo);
}
- result.push(threadInfo);
- }
- return result;
- },
-);
+ return result;
+ },
+ );
const onScreenThreadInfos: (
state: BaseAppState<>,
-) => $ReadOnlyArray<ThreadInfo> = createSelector(
- filteredThreadIDsSelector,
- canBeOnScreenThreadInfos,
- (
- inputThreadIDs: ?$ReadOnlySet<string>,
- threadInfos: $ReadOnlyArray<ThreadInfo>,
- ): $ReadOnlyArray<ThreadInfo> => {
- const threadIDs = inputThreadIDs;
- if (!threadIDs) {
- return threadInfos;
- }
- return threadInfos.filter(threadInfo => threadIDs.has(threadInfo.id));
- },
-);
+) => $ReadOnlyArray<LegacyThreadInfo | MinimallyEncodedThreadInfo> =
+ createSelector(
+ filteredThreadIDsSelector,
+ canBeOnScreenThreadInfos,
+ (
+ inputThreadIDs: ?$ReadOnlySet<string>,
+ threadInfos: $ReadOnlyArray<
+ LegacyThreadInfo | MinimallyEncodedThreadInfo,
+ >,
+ ): $ReadOnlyArray<LegacyThreadInfo | MinimallyEncodedThreadInfo> => {
+ const threadIDs = inputThreadIDs;
+ if (!threadIDs) {
+ return threadInfos;
+ }
+ return threadInfos.filter(threadInfo => threadIDs.has(threadInfo.id));
+ },
+ );
const onScreenEntryEditableThreadInfos: (
state: BaseAppState<>,
-) => $ReadOnlyArray<ThreadInfo> = createSelector(
- onScreenThreadInfos,
- (threadInfos: $ReadOnlyArray<ThreadInfo>): $ReadOnlyArray<ThreadInfo> =>
- threadInfos.filter(threadInfo =>
- threadHasPermission(threadInfo, threadPermissions.EDIT_ENTRIES),
- ),
-);
+) => $ReadOnlyArray<LegacyThreadInfo | MinimallyEncodedThreadInfo> =
+ createSelector(
+ onScreenThreadInfos,
+ (
+ threadInfos: $ReadOnlyArray<
+ LegacyThreadInfo | MinimallyEncodedThreadInfo,
+ >,
+ ): $ReadOnlyArray<LegacyThreadInfo | MinimallyEncodedThreadInfo> =>
+ threadInfos.filter(threadInfo =>
+ threadHasPermission(threadInfo, threadPermissions.EDIT_ENTRIES),
+ ),
+ );
const entryInfoSelector: (state: BaseAppState<>) => {
+[id: string]: EntryInfo,
@@ -155,7 +172,7 @@
daysToEntries: { +[day: string]: string[] },
startDateString: string,
endDateString: string,
- onScreen: $ReadOnlyArray<ThreadInfo>,
+ onScreen: $ReadOnlyArray<LegacyThreadInfo | MinimallyEncodedThreadInfo>,
includeDeleted: boolean,
) => {
const allDaysWithinRange: { [string]: string[] } = {},
@@ -184,11 +201,15 @@
);
const childThreadInfos: (state: BaseAppState<>) => {
- +[id: string]: $ReadOnlyArray<ThreadInfo>,
+ +[id: string]: $ReadOnlyArray<LegacyThreadInfo | MinimallyEncodedThreadInfo>,
} = createSelector(
threadInfoSelector,
- (threadInfos: { +[id: string]: ThreadInfo }) => {
- const result: { [string]: ThreadInfo[] } = {};
+ (threadInfos: {
+ +[id: string]: LegacyThreadInfo | MinimallyEncodedThreadInfo,
+ }) => {
+ const result: {
+ [string]: (LegacyThreadInfo | MinimallyEncodedThreadInfo)[],
+ } = {};
for (const id in threadInfos) {
const threadInfo = threadInfos[id];
const parentThreadID = threadInfo.parentThreadID;
@@ -196,7 +217,10 @@
continue;
}
if (result[parentThreadID] === undefined) {
- result[parentThreadID] = ([]: ThreadInfo[]);
+ result[parentThreadID] = ([]: (
+ | LegacyThreadInfo
+ | MinimallyEncodedThreadInfo
+ )[]);
}
result[parentThreadID].push(threadInfo);
}
@@ -205,11 +229,15 @@
);
const containedThreadInfos: (state: BaseAppState<>) => {
- +[id: string]: $ReadOnlyArray<ThreadInfo>,
+ +[id: string]: $ReadOnlyArray<LegacyThreadInfo | MinimallyEncodedThreadInfo>,
} = createSelector(
threadInfoSelector,
- (threadInfos: { +[id: string]: ThreadInfo }) => {
- const result: { [string]: ThreadInfo[] } = {};
+ (threadInfos: {
+ +[id: string]: LegacyThreadInfo | MinimallyEncodedThreadInfo,
+ }) => {
+ const result: {
+ [string]: (LegacyThreadInfo | MinimallyEncodedThreadInfo)[],
+ } = {};
for (const id in threadInfos) {
const threadInfo = threadInfos[id];
const { containingThreadID } = threadInfo;
@@ -217,7 +245,10 @@
continue;
}
if (result[containingThreadID] === undefined) {
- result[containingThreadID] = ([]: ThreadInfo[]);
+ result[containingThreadID] = ([]: (
+ | LegacyThreadInfo
+ | MinimallyEncodedThreadInfo
+ )[]);
}
result[containingThreadID].push(threadInfo);
}
@@ -226,7 +257,7 @@
);
function getMostRecentRawMessageInfo(
- threadInfo: ThreadInfo,
+ threadInfo: LegacyThreadInfo | MinimallyEncodedThreadInfo,
messageStore: MessageStore,
): ?RawMessageInfo {
const thread = messageStore.threads[threadInfo.id];
@@ -244,7 +275,10 @@
} = createObjectSelector(
childThreadInfos,
(state: BaseAppState<>) => state.messageStore,
- (childThreads: $ReadOnlyArray<ThreadInfo>, messageStore: MessageStore) => {
+ (
+ childThreads: $ReadOnlyArray<LegacyThreadInfo | MinimallyEncodedThreadInfo>,
+ messageStore: MessageStore,
+ ) => {
const sidebarInfos = [];
for (const childThreadInfo of childThreads) {
if (
@@ -314,14 +348,20 @@
const baseAncestorThreadInfos: (
threadID: string,
-) => (BaseAppState<>) => $ReadOnlyArray<ThreadInfo> = (threadID: string) =>
+) => (
+ BaseAppState<>,
+) => $ReadOnlyArray<LegacyThreadInfo | MinimallyEncodedThreadInfo> = (
+ threadID: string,
+) =>
createSelector(
(state: BaseAppState<>) => threadInfoSelector(state),
(threadInfos: {
- +[id: string]: ThreadInfo,
- }): $ReadOnlyArray<ThreadInfo> => {
- const pathComponents: ThreadInfo[] = [];
- let node: ?ThreadInfo = threadInfos[threadID];
+ +[id: string]: LegacyThreadInfo | MinimallyEncodedThreadInfo,
+ }): $ReadOnlyArray<LegacyThreadInfo | MinimallyEncodedThreadInfo> => {
+ const pathComponents: (LegacyThreadInfo | MinimallyEncodedThreadInfo)[] =
+ [];
+ let node: ?(LegacyThreadInfo | MinimallyEncodedThreadInfo) =
+ threadInfos[threadID];
while (node) {
pathComponents.push(node);
node = node.parentThreadID ? threadInfos[node.parentThreadID] : null;
@@ -333,7 +373,9 @@
const ancestorThreadInfos: (
threadID: string,
-) => (state: BaseAppState<>) => $ReadOnlyArray<ThreadInfo> = _memoize(
+) => (
+ state: BaseAppState<>,
+) => $ReadOnlyArray<LegacyThreadInfo | MinimallyEncodedThreadInfo> = _memoize(
baseAncestorThreadInfos,
);
@@ -415,17 +457,20 @@
);
const threadInfoFromSourceMessageIDSelector: (state: BaseAppState<>) => {
- +[id: string]: ThreadInfo,
+ +[id: string]: LegacyThreadInfo | MinimallyEncodedThreadInfo,
} = createSelector(
(state: BaseAppState<>) => state.threadStore.threadInfos,
threadInfoSelector,
(
rawThreadInfos: RawThreadInfos,
- threadInfos: { +[id: string]: ThreadInfo },
+ threadInfos: {
+ +[id: string]: LegacyThreadInfo | MinimallyEncodedThreadInfo,
+ },
) => {
const pendingToRealizedThreadIDs =
pendingToRealizedThreadIDsSelector(rawThreadInfos);
- const result: { [string]: ThreadInfo } = {};
+ const result: { [string]: LegacyThreadInfo | MinimallyEncodedThreadInfo } =
+ {};
for (const realizedID of pendingToRealizedThreadIDs.values()) {
const threadInfo = threadInfos[realizedID];
if (threadInfo && threadInfo.sourceMessageID) {
@@ -481,7 +526,10 @@
(state: BaseAppState<>) => threadInfoSelector(state)[threadID],
(state: BaseAppState<>) =>
containingThreadID ? threadInfoSelector(state)[containingThreadID] : null,
- (threadInfo: ThreadInfo, containingThreadInfo: ?ThreadInfo) => {
+ (
+ threadInfo: LegacyThreadInfo | MinimallyEncodedThreadInfo,
+ containingThreadInfo: ?(LegacyThreadInfo | MinimallyEncodedThreadInfo),
+ ) => {
return () => {
let threadAvatar = getAvatarForThread(threadInfo, containingThreadInfo);
if (threadAvatar.type !== 'emoji') {
@@ -501,14 +549,16 @@
const baseThreadInfosSelectorForThreadType: (
threadType: ThreadType,
-) => (BaseAppState<>) => $ReadOnlyArray<ThreadInfo> = (
+) => (
+ BaseAppState<>,
+) => $ReadOnlyArray<LegacyThreadInfo | MinimallyEncodedThreadInfo> = (
threadType: ThreadType,
) =>
createSelector(
(state: BaseAppState<>) => threadInfoSelector(state),
(threadInfos: {
- +[id: string]: ThreadInfo,
- }): $ReadOnlyArray<ThreadInfo> => {
+ +[id: string]: LegacyThreadInfo | MinimallyEncodedThreadInfo,
+ }): $ReadOnlyArray<LegacyThreadInfo | MinimallyEncodedThreadInfo> => {
const result = [];
for (const threadID in threadInfos) {
@@ -524,7 +574,9 @@
const threadInfosSelectorForThreadType: (
threadType: ThreadType,
-) => (state: BaseAppState<>) => $ReadOnlyArray<ThreadInfo> = _memoize(
+) => (
+ state: BaseAppState<>,
+) => $ReadOnlyArray<LegacyThreadInfo | MinimallyEncodedThreadInfo> = _memoize(
baseThreadInfosSelectorForThreadType,
);

File Metadata

Mime Type
text/plain
Expires
Wed, Jan 21, 11:19 AM (9 h, 22 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5968382
Default Alt Text
D10640.1768994385.diff (11 KB)

Event Timeline