diff --git a/lib/selectors/chat-selectors.js b/lib/selectors/chat-selectors.js --- a/lib/selectors/chat-selectors.js +++ b/lib/selectors/chat-selectors.js @@ -51,18 +51,15 @@ import memoize2 from '../utils/memoize.js'; import { useSelector } from '../utils/redux-utils.js'; -type ChatThreadItemBase = { +export type ChatThreadItem = { +type: 'chatThreadItem', +threadInfo: ThreadInfo, +mostRecentNonLocalMessage: ?string, +sidebars: $ReadOnlyArray, +pendingPersonalThreadUserInfo?: UserInfo, -}; -export type ChatThreadItem = $ReadOnly<{ - ...ChatThreadItemBase, +lastUpdatedTime: number, +lastUpdatedTimeIncludingSidebars: number, -}>; +}; const messageInfoSelector: (state: BaseAppState<>) => { +[id: string]: ?MessageInfo, @@ -82,13 +79,13 @@ ); } -type CreatedChatThreadItem = $ReadOnly<{ - ...ChatThreadItemBase, - +lastUpdatedAtLeastTime: number, +type CreatedChatThreadItem = { + +threadInfo: ThreadInfo, +lastUpdatedAtLeastTimeIncludingSidebars: number, +lastUpdatedAtMostTimeIncludingSidebars: number, + +initialChatThreadItem: ChatThreadItem, +getFinalChatThreadItem: () => Promise, -}>; +}; function useCreateChatThreadItem(): ThreadInfo => CreatedChatThreadItem { const messageInfos = useSelector(messageInfoSelector); const sidebarInfos = useSidebarInfos(); @@ -153,13 +150,19 @@ : lastUpdatedAtMostTime; const allInitialSidebarItems = getAllInitialSidebarItems(sidebars); - - return { + const initialChatThreadItem = { ...chatThreadItemBase, sidebars: getSidebarItems(allInitialSidebarItems), - lastUpdatedAtLeastTime, + lastUpdatedTime: lastUpdatedAtLeastTime, + lastUpdatedTimeIncludingSidebars: + lastUpdatedAtLeastTimeIncludingSidebars, + }; + + return { + threadInfo, lastUpdatedAtLeastTimeIncludingSidebars, lastUpdatedAtMostTimeIncludingSidebars, + initialChatThreadItem, getFinalChatThreadItem, }; }, @@ -194,21 +197,9 @@ const initialChatThreadItems = React.useMemo( () => - createdChatThreadItems.map(createdChatThreadItem => { - const { - lastUpdatedAtLeastTime, - lastUpdatedAtLeastTimeIncludingSidebars, - lastUpdatedAtMostTimeIncludingSidebars, - getFinalChatThreadItem, - ...rest - } = createdChatThreadItem; - return { - ...rest, - lastUpdatedTime: lastUpdatedAtLeastTime, - lastUpdatedTimeIncludingSidebars: - lastUpdatedAtLeastTimeIncludingSidebars, - }; - }), + createdChatThreadItems.map( + createdChatThreadItem => createdChatThreadItem.initialChatThreadItem, + ), [createdChatThreadItems], );