Cancel receipt send when encountering safety number change
This commit is contained in:
parent
a0b6459307
commit
5626cea9c3
4 changed files with 53 additions and 22 deletions
|
@ -455,6 +455,13 @@ export class ConversationJobQueue extends JobQueue<ConversationQueueJobData> {
|
|||
return;
|
||||
}
|
||||
|
||||
if (type === jobSet.Receipts) {
|
||||
log.warn(
|
||||
`Cancelling receipt send, since there were ${untrustedUuids.length} untrusted send targets.`
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
log.error(
|
||||
`Send failed because ${untrustedUuids.length} conversation(s) were untrusted. Adding to verification list.`
|
||||
);
|
||||
|
|
|
@ -23,7 +23,6 @@ import type {
|
|||
ProfileKeyJobData,
|
||||
} from '../conversationJobQueue';
|
||||
import type { CallbackResultType } from '../../textsecure/Types.d';
|
||||
import { isConversationAccepted } from '../../util/isConversationAccepted';
|
||||
import { isConversationUnregistered } from '../../util/isConversationUnregistered';
|
||||
import type { ConversationAttributesType } from '../../model-types.d';
|
||||
import {
|
||||
|
@ -32,8 +31,7 @@ import {
|
|||
SendMessageProtoError,
|
||||
UnregisteredUserError,
|
||||
} from '../../textsecure/Errors';
|
||||
import { getRecipients } from '../../util/getRecipients';
|
||||
import { getUntrustedConversationUuids } from './getUntrustedConversationUuids';
|
||||
import { shouldSendToConversation } from './shouldSendToConversation';
|
||||
|
||||
export function canAllErrorsBeIgnored(
|
||||
conversation: ConversationAttributesType,
|
||||
|
@ -104,24 +102,7 @@ export async function sendProfileKey(
|
|||
|
||||
// Note: flags and the profileKey itself are all that matter in the proto.
|
||||
|
||||
const recipients = getRecipients(conversation.attributes);
|
||||
const untrustedUuids = getUntrustedConversationUuids(recipients);
|
||||
if (untrustedUuids.length) {
|
||||
log.info(
|
||||
`conversation ${conversation.idForLogging()} has untrusted recipients; refusing to send`
|
||||
);
|
||||
}
|
||||
|
||||
if (!isConversationAccepted(conversation.attributes)) {
|
||||
log.info(
|
||||
`conversation ${conversation.idForLogging()} is not accepted; refusing to send`
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (conversation.isBlocked()) {
|
||||
log.info(
|
||||
`conversation ${conversation.idForLogging()} is blocked; refusing to send`
|
||||
);
|
||||
if (!shouldSendToConversation(conversation, log)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -7,12 +7,16 @@ import type {
|
|||
ConversationQueueJobBundle,
|
||||
ReceiptsJobData,
|
||||
} from '../conversationJobQueue';
|
||||
import { shouldSendToConversation } from './shouldSendToConversation';
|
||||
|
||||
export async function sendReceipts(
|
||||
_conversation: ConversationModel,
|
||||
conversation: ConversationModel,
|
||||
{ log }: ConversationQueueJobBundle,
|
||||
data: ReceiptsJobData
|
||||
): Promise<void> {
|
||||
if (!shouldSendToConversation(conversation, log)) {
|
||||
return;
|
||||
}
|
||||
await sendReceiptsTask({
|
||||
log,
|
||||
receipts: data.receipts,
|
||||
|
|
39
ts/jobs/helpers/shouldSendToConversation.ts
Normal file
39
ts/jobs/helpers/shouldSendToConversation.ts
Normal file
|
@ -0,0 +1,39 @@
|
|||
// 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';
|
||||
import { getUntrustedConversationUuids } from './getUntrustedConversationUuids';
|
||||
|
||||
export function shouldSendToConversation(
|
||||
conversation: ConversationModel,
|
||||
log: LoggerType
|
||||
): boolean {
|
||||
const recipients = getRecipients(conversation.attributes);
|
||||
const untrustedUuids = getUntrustedConversationUuids(recipients);
|
||||
|
||||
if (untrustedUuids.length) {
|
||||
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;
|
||||
}
|
Loading…
Reference in a new issue