Retry send: Always remove all errors and recalculate recipients

pull/272/head
Scott Nonnenberg 6 years ago
parent 377ab6c1cb
commit 4d8fbe95ff

@ -778,46 +778,26 @@
return null; return null;
} }
const [retries, errors] = _.partition( this.set({ errors: null });
this.get('errors'),
this.isReplayableError.bind(this)
);
// Put the errors back which aren't replayable
this.set({ errors });
const conversation = this.getConversation(); const conversation = this.getConversation();
const intendedRecipients = this.get('recipients') || []; const intendedRecipients = this.get('recipients') || [];
const successfulRecipients = this.get('sent_to') || [];
const currentRecipients = conversation.getRecipients(); const currentRecipients = conversation.getRecipients();
const profileKey = conversation.get('profileSharing') const profileKey = conversation.get('profileSharing')
? storage.get('profileKey') ? storage.get('profileKey')
: null; : null;
const errorNumbers = retries let recipients = _.intersection(intendedRecipients, currentRecipients);
.map(retry => retry.number) recipients = _.without(recipients, successfulRecipients);
.filter(item => Boolean(item));
let numbers = _.intersection(
errorNumbers,
intendedRecipients,
currentRecipients
);
if (!numbers.length) { if (!recipients.length) {
window.log.warn( window.log.warn('retrySend: Nobody to send to!');
'retrySend: No numbers in error set, using all recipients'
);
if (conversation) { return window.Signal.Data.saveMessage(this.attributes, {
numbers = _.intersection(currentRecipients, intendedRecipients); Message: Whisper.Message,
// We clear all errors here to start with a fresh slate, since we are starting });
// from scratch on this message with a fresh set of recipients
this.set({ errors: null });
} else {
throw new Error(
'No numbers in error set, did not find conversation for message'
);
}
} }
const attachmentsWithData = await Promise.all( const attachmentsWithData = await Promise.all(
@ -833,8 +813,8 @@
const previewWithData = await loadPreviewData(this.get('preview')); const previewWithData = await loadPreviewData(this.get('preview'));
// Special-case the self-send case - we send only a sync message // Special-case the self-send case - we send only a sync message
if (numbers.length === 1 && numbers[0] === this.OUR_NUMBER) { if (recipients.length === 1 && recipients[0] === this.OUR_NUMBER) {
const [number] = numbers; const [number] = recipients;
const dataMessage = await textsecure.messaging.getMessageProto( const dataMessage = await textsecure.messaging.getMessageProto(
number, number,
body, body,
@ -852,7 +832,7 @@
const options = conversation.getSendOptions(); const options = conversation.getSendOptions();
if (conversation.isPrivate()) { if (conversation.isPrivate()) {
const [number] = numbers; const [number] = recipients;
promise = textsecure.messaging.sendMessageToNumber( promise = textsecure.messaging.sendMessageToNumber(
number, number,
body, body,
@ -870,7 +850,7 @@
promise = textsecure.messaging.sendMessage( promise = textsecure.messaging.sendMessage(
{ {
recipients: numbers, recipients,
body, body,
timestamp: this.get('sent_at'), timestamp: this.get('sent_at'),
attachments, attachments,

Loading…
Cancel
Save