diff --git a/native/selectors/message-selectors.js b/native/selectors/message-selectors.js index 0ad08a7f2..f3feac4b9 100644 --- a/native/selectors/message-selectors.js +++ b/native/selectors/message-selectors.js @@ -1,66 +1,70 @@ // @flow import { createSelector } from 'reselect'; import { threadIsPending } from 'lib/shared/thread-utils.js'; import type { ThreadMessageInfo } from 'lib/types/message-types.js'; import { defaultNumberPerThread } from 'lib/types/message-types.js'; import type { ThreadActivityStore } from 'lib/types/thread-activity-types.js'; +import { type RawThreadInfo } from 'lib/types/thread-types.js'; import { activeThreadSelector } from '../navigation/nav-selectors.js'; import type { AppState } from '../redux/state-types.js'; import type { NavPlusRedux } from '../types/selector-types.js'; const msInHour = 60 * 60 * 1000; const nextMessagePruneTimeSelector: (state: AppState) => ?number = createSelector( - (state: AppState) => state.messageStore.threads, - (threadMessageInfos: { +[id: string]: ThreadMessageInfo }): ?number => { + (state: AppState) => state.threadStore.threadInfos, + (state: AppState) => state.threadActivityStore, + ( + threadInfos: { +[id: string]: RawThreadInfo }, + threadActivityStore: ThreadActivityStore, + ): ?number => { let nextTime; - for (const threadID in threadMessageInfos) { - const threadMessageInfo = threadMessageInfos[threadID]; + for (const threadID in threadInfos) { const threadPruneTime = Math.max( - threadMessageInfo.lastNavigatedTo + msInHour, - threadMessageInfo.lastPruned + msInHour * 6, + (threadActivityStore?.[threadID]?.lastNavigatedTo ?? 0) + msInHour, + (threadActivityStore?.[threadID]?.lastPruned ?? 0) + msInHour * 6, ); if (nextTime === undefined || threadPruneTime < nextTime) { nextTime = threadPruneTime; } } return nextTime; }, ); const pruneThreadIDsSelector: ( input: NavPlusRedux, ) => () => $ReadOnlyArray = createSelector( (input: NavPlusRedux): ThreadActivityStore => input.redux.threadActivityStore, (input: NavPlusRedux) => input.redux.messageStore.threads, (input: NavPlusRedux) => activeThreadSelector(input.navContext), ( threadActivityStore: ThreadActivityStore, threadMessageInfos: { +[id: string]: ThreadMessageInfo }, activeThread: ?string, ) => (): $ReadOnlyArray => { const now = Date.now(); const threadIDsToPrune = []; for (const threadID in threadMessageInfos) { if (threadID === activeThread || threadIsPending(threadID)) { continue; } const threadMessageInfo = threadMessageInfos[threadID]; if ( (threadActivityStore?.[threadID]?.lastNavigatedTo ?? 0) + msInHour < now && threadMessageInfo.messageIDs.length > defaultNumberPerThread ) { threadIDsToPrune.push(threadID); } } return threadIDsToPrune; }, ); export { nextMessagePruneTimeSelector, pruneThreadIDsSelector };