2022-07-01 00:52:03 +00:00
|
|
|
// Copyright 2022 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import { createSelector } from 'reselect';
|
|
|
|
|
|
|
|
import type { StateType } from '../reducer';
|
|
|
|
import type { StoryDistributionListDataType } from '../ducks/storyDistributionLists';
|
2022-07-21 00:07:09 +00:00
|
|
|
import type { StoryDistributionListWithMembersDataType } from '../../types/Stories';
|
|
|
|
import { getConversationSelector } from './conversations';
|
2022-11-10 15:51:39 +00:00
|
|
|
import { MY_STORY_ID } from '../../types/Stories';
|
2022-07-01 00:52:03 +00:00
|
|
|
|
2022-07-21 00:07:09 +00:00
|
|
|
export const getDistributionLists = (
|
2022-07-01 00:52:03 +00:00
|
|
|
state: StateType
|
|
|
|
): Array<StoryDistributionListDataType> =>
|
2022-08-10 18:37:19 +00:00
|
|
|
state.storyDistributionLists.distributionLists
|
|
|
|
.filter(list => !list.deletedAtTimestamp)
|
2022-11-10 15:51:39 +00:00
|
|
|
.sort(list => (list.id === MY_STORY_ID ? -1 : 1));
|
2022-07-01 00:52:03 +00:00
|
|
|
|
|
|
|
export const getDistributionListSelector = createSelector(
|
|
|
|
getDistributionLists,
|
|
|
|
distributionLists => (id: string) =>
|
|
|
|
distributionLists.find(list => list.id === id)
|
|
|
|
);
|
2022-07-21 00:07:09 +00:00
|
|
|
|
|
|
|
export const getDistributionListsWithMembers = createSelector(
|
|
|
|
getConversationSelector,
|
|
|
|
getDistributionLists,
|
|
|
|
(
|
|
|
|
conversationSelector,
|
|
|
|
distributionLists
|
|
|
|
): Array<StoryDistributionListWithMembersDataType> =>
|
|
|
|
distributionLists.map(list => ({
|
|
|
|
...list,
|
2023-08-10 16:43:33 +00:00
|
|
|
members: list.memberServiceIds.map(serviceId =>
|
|
|
|
conversationSelector(serviceId)
|
|
|
|
),
|
2022-07-21 00:07:09 +00:00
|
|
|
}))
|
|
|
|
);
|