2023-02-13 18:02:40 +00:00
|
|
|
// Copyright 2023 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import type { ConversationModel } from '../../models/conversations';
|
|
|
|
import type { LoggerType } from '../../types/Logging';
|
|
|
|
import { getRecipients } from '../../util/getRecipients';
|
|
|
|
import { isConversationAccepted } from '../../util/isConversationAccepted';
|
2023-08-10 16:43:33 +00:00
|
|
|
import { getUntrustedConversationServiceIds } from './getUntrustedConversationServiceIds';
|
2023-02-13 18:02:40 +00:00
|
|
|
|
|
|
|
export function shouldSendToConversation(
|
|
|
|
conversation: ConversationModel,
|
|
|
|
log: LoggerType
|
|
|
|
): boolean {
|
|
|
|
const recipients = getRecipients(conversation.attributes);
|
2023-08-10 16:43:33 +00:00
|
|
|
const untrustedServiceIds = getUntrustedConversationServiceIds(recipients);
|
2023-02-13 18:02:40 +00:00
|
|
|
|
2023-08-10 16:43:33 +00:00
|
|
|
if (untrustedServiceIds.length) {
|
2023-02-13 18:02:40 +00:00
|
|
|
log.info(
|
|
|
|
`conversation ${conversation.idForLogging()} has untrusted recipients; refusing to send`
|
|
|
|
);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isConversationAccepted(conversation.attributes)) {
|
|
|
|
log.info(
|
|
|
|
`conversation ${conversation.idForLogging()} is not accepted; refusing to send`
|
|
|
|
);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (conversation.isBlocked()) {
|
|
|
|
log.info(
|
|
|
|
`conversation ${conversation.idForLogging()} is blocked; refusing to send`
|
|
|
|
);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|