sendProfileKey: Be resilient to more kinds of errors
This commit is contained in:
parent
2f44e33c9c
commit
4c1b27c150
1 changed files with 35 additions and 16 deletions
|
@ -7,6 +7,7 @@ import { handleMessageSend } from '../../util/handleMessageSend';
|
||||||
import { getSendOptions } from '../../util/getSendOptions';
|
import { getSendOptions } from '../../util/getSendOptions';
|
||||||
import {
|
import {
|
||||||
isDirectConversation,
|
isDirectConversation,
|
||||||
|
isGroup,
|
||||||
isGroupV2,
|
isGroupV2,
|
||||||
} from '../../util/whatTypeOfConversation';
|
} from '../../util/whatTypeOfConversation';
|
||||||
import { SignalService as Proto } from '../../protobuf';
|
import { SignalService as Proto } from '../../protobuf';
|
||||||
|
@ -22,10 +23,39 @@ import type {
|
||||||
ProfileKeyJobData,
|
ProfileKeyJobData,
|
||||||
} from '../conversationJobQueue';
|
} from '../conversationJobQueue';
|
||||||
import type { CallbackResultType } from '../../textsecure/Types.d';
|
import type { CallbackResultType } from '../../textsecure/Types.d';
|
||||||
import { getUntrustedConversationIds } from './getUntrustedConversationIds';
|
|
||||||
import { areAllErrorsUnregistered } from './areAllErrorsUnregistered';
|
|
||||||
import { isConversationAccepted } from '../../util/isConversationAccepted';
|
import { isConversationAccepted } from '../../util/isConversationAccepted';
|
||||||
import { isConversationUnregistered } from '../../util/isConversationUnregistered';
|
import { isConversationUnregistered } from '../../util/isConversationUnregistered';
|
||||||
|
import type { ConversationAttributesType } from '../../model-types.d';
|
||||||
|
import {
|
||||||
|
OutgoingIdentityKeyError,
|
||||||
|
SendMessageChallengeError,
|
||||||
|
SendMessageProtoError,
|
||||||
|
UnregisteredUserError,
|
||||||
|
} from '../../textsecure/Errors';
|
||||||
|
|
||||||
|
export function canAllErrorsBeIgnored(
|
||||||
|
conversation: ConversationAttributesType,
|
||||||
|
error: unknown
|
||||||
|
): boolean {
|
||||||
|
if (
|
||||||
|
error instanceof OutgoingIdentityKeyError ||
|
||||||
|
error instanceof SendMessageChallengeError ||
|
||||||
|
error instanceof UnregisteredUserError
|
||||||
|
) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Boolean(
|
||||||
|
isGroup(conversation) &&
|
||||||
|
error instanceof SendMessageProtoError &&
|
||||||
|
error.errors?.every(
|
||||||
|
item =>
|
||||||
|
item instanceof OutgoingIdentityKeyError ||
|
||||||
|
item instanceof SendMessageChallengeError ||
|
||||||
|
item instanceof UnregisteredUserError
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// Note: because we don't have a recipient map, we will resend this message to folks that
|
// Note: because we don't have a recipient map, we will resend this message to folks that
|
||||||
// got it on the first go-round, if some sends fail. This is okay, because a recipient
|
// got it on the first go-round, if some sends fail. This is okay, because a recipient
|
||||||
|
@ -71,18 +101,7 @@ export async function sendProfileKey(
|
||||||
|
|
||||||
// Note: flags and the profileKey itself are all that matter in the proto.
|
// Note: flags and the profileKey itself are all that matter in the proto.
|
||||||
|
|
||||||
const untrustedConversationIds = getUntrustedConversationIds(
|
// Note: we don't check for untrusted conversations here; we attempt to send anyway
|
||||||
conversation.getRecipients()
|
|
||||||
);
|
|
||||||
if (untrustedConversationIds.length) {
|
|
||||||
window.reduxActions.conversations.conversationStoppedByMissingVerification({
|
|
||||||
conversationId: conversation.id,
|
|
||||||
untrustedConversationIds,
|
|
||||||
});
|
|
||||||
throw new Error(
|
|
||||||
`Profile key send blocked because ${untrustedConversationIds.length} conversation(s) were untrusted. Failing this attempt.`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isDirectConversation(conversation.attributes)) {
|
if (isDirectConversation(conversation.attributes)) {
|
||||||
if (!isConversationAccepted(conversation.attributes)) {
|
if (!isConversationAccepted(conversation.attributes)) {
|
||||||
|
@ -149,9 +168,9 @@ export async function sendProfileKey(
|
||||||
sendType,
|
sendType,
|
||||||
});
|
});
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
if (areAllErrorsUnregistered(conversation.attributes, error)) {
|
if (canAllErrorsBeIgnored(conversation.attributes, error)) {
|
||||||
log.info(
|
log.info(
|
||||||
'Group send failures were all UnregisteredUserError, returning succcessfully.'
|
'Group send failures were all OutgoingIdentityKeyError, SendMessageChallengeError, or UnregisteredUserError. Returning succcessfully.'
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue