2021-05-07 01:15:25 +00:00
|
|
|
// Copyright 2021 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import { compact } from 'lodash';
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { ConversationAttributesType } from '../model-types.d';
|
2023-08-10 16:43:33 +00:00
|
|
|
import type { ServiceIdString } from '../types/ServiceId';
|
2021-05-07 01:15:25 +00:00
|
|
|
import { isDirectConversation } from './whatTypeOfConversation';
|
|
|
|
|
|
|
|
export function getConversationMembers(
|
|
|
|
conversationAttrs: ConversationAttributesType,
|
|
|
|
options: { includePendingMembers?: boolean } = {}
|
|
|
|
): Array<ConversationAttributesType> {
|
|
|
|
if (isDirectConversation(conversationAttrs)) {
|
|
|
|
return [conversationAttrs];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (conversationAttrs.membersV2) {
|
|
|
|
const { includePendingMembers } = options;
|
2023-08-10 16:43:33 +00:00
|
|
|
const members: Array<{ uuid: ServiceIdString }> = includePendingMembers
|
2021-05-07 01:15:25 +00:00
|
|
|
? [
|
|
|
|
...(conversationAttrs.membersV2 || []),
|
|
|
|
...(conversationAttrs.pendingMembersV2 || []),
|
|
|
|
]
|
|
|
|
: conversationAttrs.membersV2 || [];
|
|
|
|
|
|
|
|
return compact(
|
|
|
|
members.map(member => {
|
2021-10-26 22:59:08 +00:00
|
|
|
const conversation = window.ConversationController.get(member.uuid);
|
2021-05-07 01:15:25 +00:00
|
|
|
|
2022-02-25 02:40:56 +00:00
|
|
|
// In groups we won't sent to blocked contacts or those we think are unregistered
|
|
|
|
if (
|
|
|
|
conversation &&
|
|
|
|
(conversation.isUnregistered() || conversation.isBlocked())
|
|
|
|
) {
|
2021-05-07 01:15:25 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return conversation?.attributes;
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (conversationAttrs.members) {
|
|
|
|
return compact(
|
|
|
|
conversationAttrs.members.map(id => {
|
|
|
|
const conversation = window.ConversationController.get(id);
|
|
|
|
|
2022-02-25 02:40:56 +00:00
|
|
|
// In groups we won't sent to blocked contacts or those we think are unregistered
|
|
|
|
if (
|
|
|
|
conversation &&
|
|
|
|
(conversation.isUnregistered() || conversation.isBlocked())
|
|
|
|
) {
|
2021-05-07 01:15:25 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return conversation?.attributes;
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return [];
|
|
|
|
}
|