From ee41e4f71d987d64ebf9aa5c70054c2ab588900c Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Thu, 27 May 2021 13:47:39 -0700 Subject: [PATCH] A few small bugfixes --- ts/background.ts | 7 +++++++ ts/sql/Server.ts | 12 +++++++----- ts/textsecure/SendMessage.ts | 4 ++-- ts/util/sendToGroup.ts | 24 ++++++++++++------------ 4 files changed, 28 insertions(+), 19 deletions(-) diff --git a/ts/background.ts b/ts/background.ts index 5061c385d3..be2be398b6 100644 --- a/ts/background.ts +++ b/ts/background.ts @@ -3221,6 +3221,13 @@ export async function startApp(): Promise { try { await window.textsecure.storage.protocol.removeAllConfiguration(); + // This was already done in the database with removeAllConfiguration; this does it + // for all the conversation models in memory. + window.getConversations().forEach(conversation => { + // eslint-disable-next-line no-param-reassign + delete conversation.attributes.senderKeyInfo; + }); + // These two bits of data are important to ensure that the app loads up // the conversation list, instead of showing just the QR code screen. window.Signal.Util.Registration.markEverDone(); diff --git a/ts/sql/Server.ts b/ts/sql/Server.ts index e0288155a3..df41bdfbe7 100644 --- a/ts/sql/Server.ts +++ b/ts/sql/Server.ts @@ -4863,7 +4863,7 @@ async function removeAllConfiguration(): Promise { const patch: Partial = { senderKeyInfo: undefined }; db.transaction(() => { - db.prepare( + db.exec( ` DELETE FROM identityKeys; DELETE FROM items; @@ -4873,11 +4873,13 @@ async function removeAllConfiguration(): Promise { DELETE FROM signedPreKeys; DELETE FROM unprocessed; DELETE FROM jobs; - UPDATE conversations SET json = json_patch(json, $patch); ` - ).run({ - $patch: patch, - }); + ); + db.prepare('UPDATE conversations SET json = json_patch(json, $patch);').run( + { + patch: JSON.stringify(patch), + } + ); })(); } diff --git a/ts/textsecure/SendMessage.ts b/ts/textsecure/SendMessage.ts index 2071656aed..41368b9d7d 100644 --- a/ts/textsecure/SendMessage.ts +++ b/ts/textsecure/SendMessage.ts @@ -1637,7 +1637,7 @@ export default class MessageSender { // No functions should really call this; since most group sends are now via Sender Key async sendGroupProto( providedIdentifiers: Array, - proto: ContentClass | DataMessageClass, + proto: ContentClass, timestamp = Date.now(), options?: SendOptionsType ): Promise { @@ -1660,7 +1660,7 @@ export default class MessageSender { return new Promise((resolve, reject) => { const silent = true; const callback = (res: CallbackResultType) => { - res.dataMessage = proto.toArrayBuffer(); + res.dataMessage = proto.dataMessage?.toArrayBuffer(); if (res.errors && res.errors.length > 0) { reject(res); } else { diff --git a/ts/util/sendToGroup.ts b/ts/util/sendToGroup.ts index 8aa335271f..693c83ea8e 100644 --- a/ts/util/sendToGroup.ts +++ b/ts/util/sendToGroup.ts @@ -249,7 +249,15 @@ export async function sendToGroupViaSenderKey(options: { `sendToGroupViaSenderKey/${logId}: ${devicesForSenderKey.length} devices for sender key, ${devicesForNormalSend.length} devices for normal send` ); - // 5. Analyze target devices for sender key, determine which have been added or removed + // 5. Ensure we have enough recipients + const senderKeyRecipients = getUuidsFromDevices(devicesForSenderKey); + if (senderKeyRecipients.length < 2) { + throw new Error( + `sendToGroupViaSenderKey/${logId}: Not enough recipients for Sender Key message. Failing over.` + ); + } + + // 6. Analyze target devices for sender key, determine which have been added or removed const { newToMemberDevices, newToMemberUuids, @@ -261,7 +269,7 @@ export async function sendToGroupViaSenderKey(options: { isPartialSend ); - // 6. If members have been removed from the group, we need to reset our sender key, then + // 7. If members have been removed from the group, we need to reset our sender key, then // start over to get a fresh set of target devices. const keyNeedsReset = Array.from(removedFromMemberUuids).some( uuid => !conversation.hasMember(uuid) @@ -277,7 +285,7 @@ export async function sendToGroupViaSenderKey(options: { }); } - // 7. If there are new members or new devices in the group, we need to ensure that they + // 8. If there are new members or new devices in the group, we need to ensure that they // have our sender key before we send sender key messages to them. if (newToMemberUuids.length > 0) { window.log.info( @@ -291,7 +299,7 @@ export async function sendToGroupViaSenderKey(options: { }); } - // 8. Update memberDevices with both adds and the removals which didn't require a reset. + // 9. Update memberDevices with both adds and the removals which didn't require a reset. if (removedFromMemberDevices.length > 0 || newToMemberDevices.length > 0) { const updatedMemberDevices = [ ...differenceWith( @@ -312,14 +320,6 @@ export async function sendToGroupViaSenderKey(options: { await window.Signal.Data.updateConversation(conversation.attributes); } - // 9. Ensure we have enough recipients - const senderKeyRecipients = getUuidsFromDevices(devicesForSenderKey); - if (senderKeyRecipients.length < 2) { - throw new Error( - `sendToGroupViaSenderKey/${logId}: Not enough recipients for Sender Key message. Failing over.` - ); - } - // 10. Send the Sender Key message! try { const messageBuffer = await encryptForSenderKey({