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 @@ -55,7 +55,6 @@ RelativeMemberInfo, MixedRawThreadInfos, RawThreadInfos, - LegacyThreadInfo, } from '../types/thread-types.js'; import { dateString, dateFromString } from '../utils/date-utils.js'; import { values } from '../utils/objects.js'; @@ -63,7 +62,7 @@ const _mapValuesWithKeys = _mapValues.convert({ cap: false }); type ThreadInfoSelectorType = (state: BaseAppState<>) => { - +[id: string]: LegacyThreadInfo | ThreadInfo, + +[id: string]: ThreadInfo, }; const threadInfoSelector: ThreadInfoSelectorType = createObjectSelector( (state: BaseAppState<>) => state.threadStore.threadInfos, @@ -74,9 +73,9 @@ const communityThreadSelector: ( state: BaseAppState<>, -) => $ReadOnlyArray = createSelector( +) => $ReadOnlyArray = createSelector( threadInfoSelector, - (threadInfos: { +[id: string]: LegacyThreadInfo | ThreadInfo }) => { + (threadInfos: { +[id: string]: ThreadInfo }) => { const result = []; for (const threadID in threadInfos) { const threadInfo = threadInfos[threadID]; @@ -91,9 +90,9 @@ const canBeOnScreenThreadInfos: ( state: BaseAppState<>, -) => $ReadOnlyArray = createSelector( +) => $ReadOnlyArray = createSelector( threadInfoSelector, - (threadInfos: { +[id: string]: LegacyThreadInfo | ThreadInfo }) => { + (threadInfos: { +[id: string]: ThreadInfo }) => { const result = []; for (const threadID in threadInfos) { const threadInfo = threadInfos[threadID]; @@ -108,13 +107,13 @@ const onScreenThreadInfos: ( state: BaseAppState<>, -) => $ReadOnlyArray = createSelector( +) => $ReadOnlyArray = createSelector( filteredThreadIDsSelector, canBeOnScreenThreadInfos, ( inputThreadIDs: ?$ReadOnlySet, - threadInfos: $ReadOnlyArray, - ): $ReadOnlyArray => { + threadInfos: $ReadOnlyArray, + ): $ReadOnlyArray => { const threadIDs = inputThreadIDs; if (!threadIDs) { return threadInfos; @@ -125,11 +124,9 @@ const onScreenEntryEditableThreadInfos: ( state: BaseAppState<>, -) => $ReadOnlyArray = createSelector( +) => $ReadOnlyArray = createSelector( onScreenThreadInfos, - ( - threadInfos: $ReadOnlyArray, - ): $ReadOnlyArray => + (threadInfos: $ReadOnlyArray): $ReadOnlyArray => threadInfos.filter(threadInfo => threadHasPermission(threadInfo, threadPermissions.EDIT_ENTRIES), ), @@ -160,7 +157,7 @@ daysToEntries: { +[day: string]: string[] }, startDateString: string, endDateString: string, - onScreen: $ReadOnlyArray, + onScreen: $ReadOnlyArray, includeDeleted: boolean, ) => { const allDaysWithinRange: { [string]: string[] } = {}, @@ -189,12 +186,12 @@ ); const childThreadInfos: (state: BaseAppState<>) => { - +[id: string]: $ReadOnlyArray, + +[id: string]: $ReadOnlyArray, } = createSelector( threadInfoSelector, - (threadInfos: { +[id: string]: LegacyThreadInfo | ThreadInfo }) => { + (threadInfos: { +[id: string]: ThreadInfo }) => { const result: { - [string]: (LegacyThreadInfo | ThreadInfo)[], + [string]: ThreadInfo[], } = {}; for (const id in threadInfos) { const threadInfo = threadInfos[id]; @@ -203,7 +200,7 @@ continue; } if (result[parentThreadID] === undefined) { - result[parentThreadID] = ([]: (LegacyThreadInfo | ThreadInfo)[]); + result[parentThreadID] = ([]: ThreadInfo[]); } result[parentThreadID].push(threadInfo); } @@ -212,12 +209,12 @@ ); const containedThreadInfos: (state: BaseAppState<>) => { - +[id: string]: $ReadOnlyArray, + +[id: string]: $ReadOnlyArray, } = createSelector( threadInfoSelector, - (threadInfos: { +[id: string]: LegacyThreadInfo | ThreadInfo }) => { + (threadInfos: { +[id: string]: ThreadInfo }) => { const result: { - [string]: (LegacyThreadInfo | ThreadInfo)[], + [string]: ThreadInfo[], } = {}; for (const id in threadInfos) { const threadInfo = threadInfos[id]; @@ -226,7 +223,7 @@ continue; } if (result[containingThreadID] === undefined) { - result[containingThreadID] = ([]: (LegacyThreadInfo | ThreadInfo)[]); + result[containingThreadID] = ([]: ThreadInfo[]); } result[containingThreadID].push(threadInfo); } @@ -235,7 +232,7 @@ ); function getMostRecentRawMessageInfo( - threadInfo: LegacyThreadInfo | ThreadInfo, + threadInfo: ThreadInfo, messageStore: MessageStore, ): ?RawMessageInfo { const thread = messageStore.threads[threadInfo.id]; @@ -253,10 +250,7 @@ } = createObjectSelector( childThreadInfos, (state: BaseAppState<>) => state.messageStore, - ( - childThreads: $ReadOnlyArray, - messageStore: MessageStore, - ) => { + (childThreads: $ReadOnlyArray, messageStore: MessageStore) => { const sidebarInfos = []; for (const childThreadInfo of childThreads) { if ( @@ -326,16 +320,14 @@ const baseAncestorThreadInfos: ( threadID: string, -) => (BaseAppState<>) => $ReadOnlyArray = ( - threadID: string, -) => +) => (BaseAppState<>) => $ReadOnlyArray = (threadID: string) => createSelector( (state: BaseAppState<>) => threadInfoSelector(state), (threadInfos: { - +[id: string]: LegacyThreadInfo | ThreadInfo, - }): $ReadOnlyArray => { - const pathComponents: (LegacyThreadInfo | ThreadInfo)[] = []; - let node: ?(LegacyThreadInfo | ThreadInfo) = threadInfos[threadID]; + +[id: string]: ThreadInfo, + }): $ReadOnlyArray => { + const pathComponents: ThreadInfo[] = []; + let node: ?ThreadInfo = threadInfos[threadID]; while (node) { pathComponents.push(node); node = node.parentThreadID ? threadInfos[node.parentThreadID] : null; @@ -347,8 +339,9 @@ const ancestorThreadInfos: ( threadID: string, -) => (state: BaseAppState<>) => $ReadOnlyArray = - _memoize(baseAncestorThreadInfos); +) => (state: BaseAppState<>) => $ReadOnlyArray = _memoize( + baseAncestorThreadInfos, +); const baseOtherUsersButNoOtherAdmins: ( threadID: string, @@ -428,19 +421,19 @@ ); const threadInfoFromSourceMessageIDSelector: (state: BaseAppState<>) => { - +[id: string]: LegacyThreadInfo | ThreadInfo, + +[id: string]: ThreadInfo, } = createSelector( (state: BaseAppState<>) => state.threadStore.threadInfos, threadInfoSelector, ( rawThreadInfos: RawThreadInfos, threadInfos: { - +[id: string]: LegacyThreadInfo | ThreadInfo, + +[id: string]: ThreadInfo, }, ) => { const pendingToRealizedThreadIDs = pendingToRealizedThreadIDsSelector(rawThreadInfos); - const result: { [string]: LegacyThreadInfo | ThreadInfo } = {}; + const result: { [string]: ThreadInfo } = {}; for (const realizedID of pendingToRealizedThreadIDs.values()) { const threadInfo = threadInfos[realizedID]; if (threadInfo && threadInfo.sourceMessageID) { @@ -496,10 +489,7 @@ (state: BaseAppState<>) => threadInfoSelector(state)[threadID], (state: BaseAppState<>) => containingThreadID ? threadInfoSelector(state)[containingThreadID] : null, - ( - threadInfo: LegacyThreadInfo | ThreadInfo, - containingThreadInfo: ?(LegacyThreadInfo | ThreadInfo), - ) => { + (threadInfo: ThreadInfo, containingThreadInfo: ?ThreadInfo) => { return () => { let threadAvatar = getAvatarForThread(threadInfo, containingThreadInfo); if (threadAvatar.type !== 'emoji') { @@ -519,14 +509,14 @@ const baseThreadInfosSelectorForThreadType: ( threadType: ThreadType, -) => (BaseAppState<>) => $ReadOnlyArray = ( +) => (BaseAppState<>) => $ReadOnlyArray = ( threadType: ThreadType, ) => createSelector( (state: BaseAppState<>) => threadInfoSelector(state), (threadInfos: { - +[id: string]: LegacyThreadInfo | ThreadInfo, - }): $ReadOnlyArray => { + +[id: string]: ThreadInfo, + }): $ReadOnlyArray => { const result = []; for (const threadID in threadInfos) { @@ -542,8 +532,9 @@ const threadInfosSelectorForThreadType: ( threadType: ThreadType, -) => (state: BaseAppState<>) => $ReadOnlyArray = - _memoize(baseThreadInfosSelectorForThreadType); +) => (state: BaseAppState<>) => $ReadOnlyArray = _memoize( + baseThreadInfosSelectorForThreadType, +); export { ancestorThreadInfos,