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 = createSelector( - threadInfoSelector, - (threadInfos: { +[id: string]: ThreadInfo }) => { - const result = []; - for (const threadID in threadInfos) { - const threadInfo = threadInfos[threadID]; - if (!threadTypeIsCommunityRoot(threadInfo.type)) { - continue; +) => $ReadOnlyArray = + 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 = createSelector( - threadInfoSelector, - (threadInfos: { +[id: string]: ThreadInfo }) => { - const result = []; - for (const threadID in threadInfos) { - const threadInfo = threadInfos[threadID]; - if (!threadInFilterList(threadInfo)) { - continue; +) => $ReadOnlyArray = + 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 = createSelector( - filteredThreadIDsSelector, - canBeOnScreenThreadInfos, - ( - inputThreadIDs: ?$ReadOnlySet, - threadInfos: $ReadOnlyArray, - ): $ReadOnlyArray => { - const threadIDs = inputThreadIDs; - if (!threadIDs) { - return threadInfos; - } - return threadInfos.filter(threadInfo => threadIDs.has(threadInfo.id)); - }, -); +) => $ReadOnlyArray = + createSelector( + filteredThreadIDsSelector, + canBeOnScreenThreadInfos, + ( + inputThreadIDs: ?$ReadOnlySet, + threadInfos: $ReadOnlyArray< + LegacyThreadInfo | MinimallyEncodedThreadInfo, + >, + ): $ReadOnlyArray => { + const threadIDs = inputThreadIDs; + if (!threadIDs) { + return threadInfos; + } + return threadInfos.filter(threadInfo => threadIDs.has(threadInfo.id)); + }, + ); const onScreenEntryEditableThreadInfos: ( state: BaseAppState<>, -) => $ReadOnlyArray = createSelector( - onScreenThreadInfos, - (threadInfos: $ReadOnlyArray): $ReadOnlyArray => - threadInfos.filter(threadInfo => - threadHasPermission(threadInfo, threadPermissions.EDIT_ENTRIES), - ), -); +) => $ReadOnlyArray = + createSelector( + onScreenThreadInfos, + ( + threadInfos: $ReadOnlyArray< + LegacyThreadInfo | MinimallyEncodedThreadInfo, + >, + ): $ReadOnlyArray => + 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, + onScreen: $ReadOnlyArray, includeDeleted: boolean, ) => { const allDaysWithinRange: { [string]: string[] } = {}, @@ -184,11 +201,15 @@ ); const childThreadInfos: (state: BaseAppState<>) => { - +[id: string]: $ReadOnlyArray, + +[id: string]: $ReadOnlyArray, } = 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, + +[id: string]: $ReadOnlyArray, } = 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, messageStore: MessageStore) => { + ( + childThreads: $ReadOnlyArray, + messageStore: MessageStore, + ) => { const sidebarInfos = []; for (const childThreadInfo of childThreads) { if ( @@ -314,14 +348,20 @@ const baseAncestorThreadInfos: ( threadID: string, -) => (BaseAppState<>) => $ReadOnlyArray = (threadID: string) => +) => ( + BaseAppState<>, +) => $ReadOnlyArray = ( + threadID: string, +) => createSelector( (state: BaseAppState<>) => threadInfoSelector(state), (threadInfos: { - +[id: string]: ThreadInfo, - }): $ReadOnlyArray => { - const pathComponents: ThreadInfo[] = []; - let node: ?ThreadInfo = threadInfos[threadID]; + +[id: string]: LegacyThreadInfo | MinimallyEncodedThreadInfo, + }): $ReadOnlyArray => { + 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 = _memoize( +) => ( + state: BaseAppState<>, +) => $ReadOnlyArray = _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 = ( +) => ( + BaseAppState<>, +) => $ReadOnlyArray = ( threadType: ThreadType, ) => createSelector( (state: BaseAppState<>) => threadInfoSelector(state), (threadInfos: { - +[id: string]: ThreadInfo, - }): $ReadOnlyArray => { + +[id: string]: LegacyThreadInfo | MinimallyEncodedThreadInfo, + }): $ReadOnlyArray => { const result = []; for (const threadID in threadInfos) { @@ -524,7 +574,9 @@ const threadInfosSelectorForThreadType: ( threadType: ThreadType, -) => (state: BaseAppState<>) => $ReadOnlyArray = _memoize( +) => ( + state: BaseAppState<>, +) => $ReadOnlyArray = _memoize( baseThreadInfosSelectorForThreadType, );