From 28cbe2cf3e82ae340d6b12cba3c3d1868460aca3 Mon Sep 17 00:00:00 2001 From: Patryk Klatka Date: Wed, 2 Aug 2023 22:54:04 +0200 Subject: [PATCH] [lib] Add containedThreadInfos selector Summary: Part of [ENG-4319](https://linear.app/comm/issue/ENG-4319/warn-the-user-when-deleting-a-chat-that-has-contained-chats). A new selector is needed to obtain contained chats. There exists `childThreadInfos` selector, but it operates on `parentThreadID` rather than on `containingThreadID`. Depends on D8686. Test Plan: Tested later in the stack. Reviewers: bartek, tomek, inka, michal, ashoat Reviewed By: bartek, inka, ashoat Subscribers: ashoat, tomek Differential Revision: https://phab.comm.dev/D8526 --- lib/selectors/thread-selectors.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/lib/selectors/thread-selectors.js b/lib/selectors/thread-selectors.js index 6b1f996153..c49270ca5c 100644 --- a/lib/selectors/thread-selectors.js +++ b/lib/selectors/thread-selectors.js @@ -200,6 +200,27 @@ const childThreadInfos: (state: BaseAppState<>) => { }, ); +const containedThreadInfos: (state: BaseAppState<>) => { + +[id: string]: $ReadOnlyArray, +} = createSelector( + threadInfoSelector, + (threadInfos: { +[id: string]: ThreadInfo }) => { + const result = {}; + for (const id in threadInfos) { + const threadInfo = threadInfos[id]; + const { containingThreadID } = threadInfo; + if (containingThreadID === null || containingThreadID === undefined) { + continue; + } + if (result[containingThreadID] === undefined) { + result[containingThreadID] = []; + } + result[containingThreadID].push(threadInfo); + } + return result; + }, +); + function getMostRecentRawMessageInfo( threadInfo: ThreadInfo, messageStore: MessageStore, @@ -451,6 +472,7 @@ export { entryInfoSelector, currentDaysToEntries, childThreadInfos, + containedThreadInfos, unreadCount, unreadBackgroundCount, otherUsersButNoOtherAdmins,