2022-11-11 04:10:30 +00:00
|
|
|
// Copyright 2022 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
// This file is to prevent circular references with other selector files, since
|
|
|
|
// selectors/conversations is used by so many things
|
|
|
|
|
|
|
|
import { createSelector } from 'reselect';
|
|
|
|
|
2023-08-10 16:43:33 +00:00
|
|
|
import { normalizeStoryDistributionId } from '../../types/StoryDistributionId';
|
2022-11-11 04:10:30 +00:00
|
|
|
import type { ContactsByStory } from '../../components/SafetyNumberChangeDialog';
|
|
|
|
import type { ConversationVerificationData } from '../ducks/conversations';
|
|
|
|
import type { StoryDistributionListDataType } from '../ducks/storyDistributionLists';
|
|
|
|
import type { GetConversationByIdType } from './conversations';
|
|
|
|
|
|
|
|
import { isGroup } from '../../util/whatTypeOfConversation';
|
|
|
|
import {
|
|
|
|
getConversationSelector,
|
|
|
|
getConversationVerificationData,
|
|
|
|
} from './conversations';
|
|
|
|
import { ConversationVerificationState } from '../ducks/conversationsEnums';
|
|
|
|
import { getDistributionListSelector } from './storyDistributionLists';
|
|
|
|
|
|
|
|
export const getByDistributionListConversationsStoppingSend = createSelector(
|
|
|
|
getConversationSelector,
|
|
|
|
getDistributionListSelector,
|
|
|
|
getConversationVerificationData,
|
|
|
|
(
|
|
|
|
conversationSelector: GetConversationByIdType,
|
|
|
|
distributionListSelector: (
|
|
|
|
id: string
|
|
|
|
) => StoryDistributionListDataType | undefined,
|
|
|
|
verificationDataByConversation: Record<string, ConversationVerificationData>
|
|
|
|
): ContactsByStory => {
|
|
|
|
const conversations: ContactsByStory = [];
|
|
|
|
|
|
|
|
Object.entries(verificationDataByConversation).forEach(
|
|
|
|
([conversationId, conversationData]) => {
|
|
|
|
if (
|
|
|
|
conversationData.type !==
|
|
|
|
ConversationVerificationState.PendingVerification
|
|
|
|
) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-08-10 16:43:33 +00:00
|
|
|
const conversationServiceIds = new Set(
|
|
|
|
conversationData.serviceIdsNeedingVerification
|
2022-11-11 04:10:30 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
if (conversationData.byDistributionId) {
|
|
|
|
Object.entries(conversationData.byDistributionId).forEach(
|
|
|
|
([distributionId, distributionData]) => {
|
2023-08-10 16:43:33 +00:00
|
|
|
if (distributionData.serviceIdsNeedingVerification.length === 0) {
|
2022-11-11 04:10:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
const currentDistribution =
|
|
|
|
distributionListSelector(distributionId);
|
|
|
|
|
|
|
|
if (!currentDistribution) {
|
2023-08-16 20:54:39 +00:00
|
|
|
distributionData.serviceIdsNeedingVerification.forEach(
|
|
|
|
serviceId => {
|
|
|
|
conversationServiceIds.add(serviceId);
|
|
|
|
}
|
|
|
|
);
|
2022-11-11 04:10:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
conversations.push({
|
|
|
|
story: {
|
|
|
|
conversationId,
|
2023-08-10 16:43:33 +00:00
|
|
|
distributionId: normalizeStoryDistributionId(
|
|
|
|
distributionId,
|
|
|
|
'conversations-extra'
|
|
|
|
),
|
2022-11-11 04:10:30 +00:00
|
|
|
name: currentDistribution.name,
|
|
|
|
},
|
2023-08-10 16:43:33 +00:00
|
|
|
contacts: distributionData.serviceIdsNeedingVerification.map(
|
2023-08-16 20:54:39 +00:00
|
|
|
serviceId => conversationSelector(serviceId)
|
2022-11-11 04:10:30 +00:00
|
|
|
),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-08-10 16:43:33 +00:00
|
|
|
if (conversationServiceIds.size) {
|
2022-11-11 04:10:30 +00:00
|
|
|
const currentConversation = conversationSelector(conversationId);
|
|
|
|
conversations.push({
|
|
|
|
story: isGroup(currentConversation)
|
|
|
|
? {
|
|
|
|
conversationId,
|
|
|
|
name: currentConversation.title,
|
|
|
|
}
|
|
|
|
: undefined,
|
2023-08-16 20:54:39 +00:00
|
|
|
contacts: Array.from(conversationServiceIds).map(serviceId =>
|
|
|
|
conversationSelector(serviceId)
|
2022-11-11 04:10:30 +00:00
|
|
|
),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
return conversations;
|
|
|
|
}
|
|
|
|
);
|