Skip to content

Commit

Permalink
[lib] Add containedThreadInfos selector
Browse files Browse the repository at this point in the history
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
  • Loading branch information
pklatka committed Aug 2, 2023
1 parent 00ce9bf commit 28cbe2c
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions lib/selectors/thread-selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,27 @@ const childThreadInfos: (state: BaseAppState<>) => {
},
);

const containedThreadInfos: (state: BaseAppState<>) => {
+[id: string]: $ReadOnlyArray<ThreadInfo>,
} = 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,
Expand Down Expand Up @@ -451,6 +472,7 @@ export {
entryInfoSelector,
currentDaysToEntries,
childThreadInfos,
containedThreadInfos,
unreadCount,
unreadBackgroundCount,
otherUsersButNoOtherAdmins,
Expand Down

0 comments on commit 28cbe2c

Please sign in to comment.