sendToGroup: Combine into final send result even in error scenarios
This commit is contained in:
parent
1d89ffcc2d
commit
de942e1af2
1 changed files with 45 additions and 23 deletions
|
@ -617,43 +617,65 @@ export async function sendToGroupViaSenderKey(options: {
|
||||||
deviceIds,
|
deviceIds,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
const normalSendResult = await window.textsecure.messaging.sendGroupProto({
|
|
||||||
contentHint,
|
|
||||||
groupId,
|
|
||||||
options: { ...sendOptions, online },
|
|
||||||
proto: contentMessage,
|
|
||||||
recipients: normalSendRecipients,
|
|
||||||
sendLogCallback,
|
|
||||||
timestamp,
|
|
||||||
});
|
|
||||||
|
|
||||||
|
try {
|
||||||
|
const normalSendResult = await window.textsecure.messaging.sendGroupProto({
|
||||||
|
contentHint,
|
||||||
|
groupId,
|
||||||
|
options: { ...sendOptions, online },
|
||||||
|
proto: contentMessage,
|
||||||
|
recipients: normalSendRecipients,
|
||||||
|
sendLogCallback,
|
||||||
|
timestamp,
|
||||||
|
});
|
||||||
|
|
||||||
|
return mergeSendResult({
|
||||||
|
result: normalSendResult,
|
||||||
|
senderKeyRecipients,
|
||||||
|
senderKeyRecipientsWithDevices,
|
||||||
|
});
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof SendMessageProtoError) {
|
||||||
|
const callbackResult = mergeSendResult({
|
||||||
|
result: error,
|
||||||
|
senderKeyRecipients,
|
||||||
|
senderKeyRecipientsWithDevices,
|
||||||
|
});
|
||||||
|
throw new SendMessageProtoError(callbackResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Utility Methods
|
||||||
|
|
||||||
|
function mergeSendResult({
|
||||||
|
result,
|
||||||
|
senderKeyRecipients,
|
||||||
|
senderKeyRecipientsWithDevices,
|
||||||
|
}: {
|
||||||
|
result: CallbackResultType | SendMessageProtoError;
|
||||||
|
senderKeyRecipients: Array<string>;
|
||||||
|
senderKeyRecipientsWithDevices: Record<string, Array<number>>;
|
||||||
|
}): CallbackResultType {
|
||||||
return {
|
return {
|
||||||
dataMessage: contentMessage.dataMessage
|
...result,
|
||||||
? Proto.DataMessage.encode(contentMessage.dataMessage).finish()
|
|
||||||
: undefined,
|
|
||||||
errors: normalSendResult.errors,
|
|
||||||
failoverIdentifiers: normalSendResult.failoverIdentifiers,
|
|
||||||
successfulIdentifiers: [
|
successfulIdentifiers: [
|
||||||
...(normalSendResult.successfulIdentifiers || []),
|
...(result.successfulIdentifiers || []),
|
||||||
...senderKeyRecipients,
|
...senderKeyRecipients,
|
||||||
],
|
],
|
||||||
unidentifiedDeliveries: [
|
unidentifiedDeliveries: [
|
||||||
...(normalSendResult.unidentifiedDeliveries || []),
|
...(result.unidentifiedDeliveries || []),
|
||||||
...senderKeyRecipients,
|
...senderKeyRecipients,
|
||||||
],
|
],
|
||||||
|
|
||||||
contentHint,
|
|
||||||
timestamp,
|
|
||||||
contentProto: Buffer.from(Proto.Content.encode(contentMessage).finish()),
|
|
||||||
recipients: {
|
recipients: {
|
||||||
...normalSendResult.recipients,
|
...result.recipients,
|
||||||
...senderKeyRecipientsWithDevices,
|
...senderKeyRecipientsWithDevices,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Utility Methods
|
|
||||||
|
|
||||||
const MAX_SENDER_KEY_EXPIRE_DURATION = 90 * DAY;
|
const MAX_SENDER_KEY_EXPIRE_DURATION = 90 * DAY;
|
||||||
|
|
||||||
function getSenderKeyExpireDuration(): number {
|
function getSenderKeyExpireDuration(): number {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue