2022-07-01 00:52:03 +00:00
|
|
|
// Copyright 2022 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2024-07-22 18:16:33 +00:00
|
|
|
import { DataReader } from '../sql/Client';
|
2022-07-01 00:52:03 +00:00
|
|
|
import type { StoryDistributionWithMembersType } from '../sql/Interface';
|
|
|
|
import type { StoryDistributionListDataType } from '../state/ducks/storyDistributionLists';
|
|
|
|
import { strictAssert } from '../util/assert';
|
|
|
|
|
|
|
|
let distributionLists: Array<StoryDistributionWithMembersType> | undefined;
|
|
|
|
|
|
|
|
export async function loadDistributionLists(): Promise<void> {
|
2024-07-22 18:16:33 +00:00
|
|
|
distributionLists = await DataReader.getAllStoryDistributionsWithMembers();
|
2022-07-01 00:52:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export function getDistributionListsForRedux(): Array<StoryDistributionListDataType> {
|
|
|
|
strictAssert(distributionLists, 'distributionLists has not been loaded');
|
|
|
|
|
2022-07-21 00:07:09 +00:00
|
|
|
const lists = distributionLists
|
|
|
|
.map(list => ({
|
|
|
|
allowsReplies: Boolean(list.allowsReplies),
|
|
|
|
deletedAtTimestamp: list.deletedAtTimestamp,
|
|
|
|
id: list.id,
|
|
|
|
isBlockList: Boolean(list.isBlockList),
|
|
|
|
name: list.name,
|
2023-08-10 16:43:33 +00:00
|
|
|
memberServiceIds: list.members,
|
2022-07-21 00:07:09 +00:00
|
|
|
}))
|
|
|
|
.filter(list => !list.deletedAtTimestamp);
|
2022-07-01 00:52:03 +00:00
|
|
|
|
|
|
|
distributionLists = undefined;
|
|
|
|
|
|
|
|
return lists;
|
|
|
|
}
|