From f4af41e07f7c11d19f905c938d05692199f582db Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Thu, 16 Jul 2020 15:53:32 +1000 Subject: [PATCH 1/6] remove wrapSend() and prepareForSend() from conversation --- js/conversation_controller.js | 10 ---- js/models/conversations.js | 92 +---------------------------------- 2 files changed, 1 insertion(+), 101 deletions(-) diff --git a/js/conversation_controller.js b/js/conversation_controller.js index 86c228e57..559464040 100644 --- a/js/conversation_controller.js +++ b/js/conversation_controller.js @@ -213,16 +213,6 @@ ); }); }, - prepareForSend(id) { - // id is either a group id or an individual user's id - const conversation = this.get(id); - const sendOptions = {}; - const wrap = conversation - ? conversation.wrapSend.bind(conversation) - : promise => promise; - - return { wrap, sendOptions }; - }, async getAllGroupsInvolvingId(id) { const groups = await window.Signal.Data.getAllGroupsInvolvingId(id, { ConversationCollection: Whisper.ConversationCollection, diff --git a/js/models/conversations.js b/js/models/conversations.js index 1a79b1bcf..b9472f74c 100644 --- a/js/models/conversations.js +++ b/js/models/conversations.js @@ -741,17 +741,8 @@ } }, async sendVerifySyncMessage(number, state) { - // Because syncVerification sends a (null) message to the target of the verify and - // a sync message to our own devices, we need to send the accessKeys down for both - // contacts. So we merge their sendOptions. - const { sendOptions } = ConversationController.prepareForSend( - this.ourNumber, - { syncMessage: true } - ); - const options = Object.assign({}, sendOptions, {}); - const key = await textsecure.storage.protocol.loadIdentityKey(number); - return textsecure.messaging.syncVerification(number, state, key, options); + return textsecure.messaging.syncVerification(number, state, key); }, isVerified() { if (this.isPrivate()) { @@ -1460,30 +1451,6 @@ } }); }, - wrapSend(promise) { - return promise.then( - async result => { - // success - if (result) { - await this.handleMessageSendResult({ - ...result, - success: true, - }); - } - return result; - }, - async result => { - // failure - if (result) { - await this.handleMessageSendResult({ - ...result, - success: false, - }); - } - throw result; - } - ); - }, async updateAvatarOnPublicChat({ url, profileKey }) { if (!this.isPublic()) { @@ -1505,63 +1472,6 @@ ); await serverAPI.setAvatar(url, profileKey); }, - - async handleMessageSendResult({ failoverNumbers, unidentifiedDeliveries }) { - await Promise.all( - (failoverNumbers || []).map(async number => { - const conversation = ConversationController.get(number); - - if ( - conversation && - conversation.get('sealedSender') !== SEALED_SENDER.DISABLED - ) { - window.log.info( - `Setting sealedSender to DISABLED for conversation ${conversation.idForLogging()}` - ); - conversation.set({ - sealedSender: SEALED_SENDER.DISABLED, - }); - await window.Signal.Data.updateConversation( - conversation.id, - conversation.attributes, - { Conversation: Whisper.Conversation } - ); - } - }) - ); - - await Promise.all( - (unidentifiedDeliveries || []).map(async number => { - const conversation = ConversationController.get(number); - - if ( - conversation && - conversation.get('sealedSender') === SEALED_SENDER.UNKNOWN - ) { - if (conversation.get('accessKey')) { - window.log.info( - `Setting sealedSender to ENABLED for conversation ${conversation.idForLogging()}` - ); - conversation.set({ - sealedSender: SEALED_SENDER.ENABLED, - }); - } else { - window.log.info( - `Setting sealedSender to UNRESTRICTED for conversation ${conversation.idForLogging()}` - ); - conversation.set({ - sealedSender: SEALED_SENDER.UNRESTRICTED, - }); - } - await window.Signal.Data.updateConversation( - conversation.id, - conversation.attributes, - { Conversation: Whisper.Conversation } - ); - } - }) - ); - }, async updateLastMessage() { if (!this.id) { return; From a17edd0ce9288acf7ddd7e1da4e665b99561afcc Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Thu, 16 Jul 2020 15:54:17 +1000 Subject: [PATCH 2/6] enable back delivery Receipt and read receipt message --- js/models/conversations.js | 45 +++++++++++++++++--------------------- ts/receiver/dataMessage.ts | 15 +++++++------ 2 files changed, 28 insertions(+), 32 deletions(-) diff --git a/js/models/conversations.js b/js/models/conversations.js index b9472f74c..ba9a8bbf7 100644 --- a/js/models/conversations.js +++ b/js/models/conversations.js @@ -2099,31 +2099,26 @@ window.log.info(`Sending ${read.length} read receipts`); // Because syncReadMessages sends to our other devices, and sendReadReceipts goes // to a contact, we need accessKeys for both. - const { sendOptions } = ConversationController.prepareForSend( - this.ourNumber, - { syncMessage: true } - ); - await textsecure.messaging.syncReadMessages(read, sendOptions); - - // FIXME AUDRIC - // if (storage.get('read-receipt-setting')) { - // await Promise.all( - // _.map(_.groupBy(read, 'sender'), async (receipts, sender) => { - // const timestamps = _.map(receipts, 'timestamp'); - // const receiptMessage = new libsession.Messages.Outgoing.ReadReceiptMessage( - // { - // timestamp: Date.now(), - // timestamps, - // } - // ); - - // const device = new libsession.Types.PubKey(sender); - // await libsession - // .getMessageQueue() - // .sendUsingMultiDevice(device, receiptMessage); - // }) - // ); - // } + await textsecure.messaging.syncReadMessages(read); + + if (storage.get('read-receipt-setting')) { + await Promise.all( + _.map(_.groupBy(read, 'sender'), async (receipts, sender) => { + const timestamps = _.map(receipts, 'timestamp'); + const receiptMessage = new libsession.Messages.Outgoing.ReadReceiptMessage( + { + timestamp: Date.now(), + timestamps, + } + ); + + const device = new libsession.Types.PubKey(sender); + await libsession + .getMessageQueue() + .sendUsingMultiDevice(device, receiptMessage); + }) + ); + } } }, diff --git a/ts/receiver/dataMessage.ts b/ts/receiver/dataMessage.ts index 24de0c604..df74fcbd4 100644 --- a/ts/receiver/dataMessage.ts +++ b/ts/receiver/dataMessage.ts @@ -14,6 +14,8 @@ import { handleUnpairRequest } from './multidevice'; import { downloadAttachment } from './attachments'; import _ from 'lodash'; import { StringUtils } from '../session/utils'; +import { DeliveryReceiptMessage } from '../session/messages/outgoing'; +import { getMessageQueue } from '../session'; export async function updateProfile( conversation: any, @@ -528,13 +530,12 @@ function createMessage( } function sendDeliveryReceipt(source: string, timestamp: any) { - // FIXME audric - // const receiptMessage = new DeliveryReceiptMessage({ - // timestamp: Date.now(), - // timestamps: [timestamp], - // }); - // const device = new PubKey(source); - // await getMessageQueue().sendUsingMultiDevice(device, receiptMessage); + const receiptMessage = new DeliveryReceiptMessage({ + timestamp: Date.now(), + timestamps: [timestamp], + }); + const device = new PubKey(source); + void getMessageQueue().sendUsingMultiDevice(device, receiptMessage); } interface MessageEvent { From 5276c3eee33d8c031b3fddae675037d549abd992 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Fri, 17 Jul 2020 09:43:23 +1000 Subject: [PATCH 3/6] remove non existing file from html file --- background.html | 1 - background_test.html | 1 - test/index.html | 1 - 3 files changed, 3 deletions(-) diff --git a/background.html b/background.html index ad3063e11..db453bb99 100644 --- a/background.html +++ b/background.html @@ -456,7 +456,6 @@ - diff --git a/background_test.html b/background_test.html index cbb09488c..c6a198b6e 100644 --- a/background_test.html +++ b/background_test.html @@ -456,7 +456,6 @@ - diff --git a/test/index.html b/test/index.html index c98043693..7e9022a49 100644 --- a/test/index.html +++ b/test/index.html @@ -503,7 +503,6 @@ - From dd3080d9feb348c3c13fa83b5cdf71b12d8a9f83 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Mon, 20 Jul 2020 09:46:05 +1000 Subject: [PATCH 4/6] mark conversation as secondary on message synced when needed --- password_preload.js | 2 +- ts/receiver/dataMessage.ts | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/password_preload.js b/password_preload.js index d499b1609..bd18b92db 100644 --- a/password_preload.js +++ b/password_preload.js @@ -32,7 +32,7 @@ window.Signal = { Components: { SessionPasswordPrompt, }, -} +}; window.CONSTANTS = { MAX_LOGIN_TRIES: 3, diff --git a/ts/receiver/dataMessage.ts b/ts/receiver/dataMessage.ts index 24de0c604..b55439fbd 100644 --- a/ts/receiver/dataMessage.ts +++ b/ts/receiver/dataMessage.ts @@ -631,7 +631,20 @@ export async function handleMessageEvent(event: MessageEvent): Promise { ); } - await window.ConversationController.getOrCreateAndWait(conversationId, type); + const conv = await window.ConversationController.getOrCreateAndWait( + conversationId, + type + ); + if (!isGroupMessage && !isIncoming) { + const primaryDestination = await MultiDeviceProtocol.getPrimaryDevice( + destination + ); + + if (destination !== primaryDestination.key) { + // mark created conversation as secondary if this is one + conv.setSecondaryStatus(true, primaryDestination.key); + } + } // =========== Process flags ============= From 258b406b9ecb1b1d40199e8942f7d67111e57051 Mon Sep 17 00:00:00 2001 From: Mikunj Date: Mon, 20 Jul 2020 11:29:42 +1000 Subject: [PATCH 5/6] Improve unhandled promise error logging --- js/logging.js | 6 +++--- password_preload.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/js/logging.js b/js/logging.js index e2fec0d44..e675e44ef 100644 --- a/js/logging.js +++ b/js/logging.js @@ -136,7 +136,7 @@ window.onerror = (message, script, line, col, error) => { }; window.addEventListener('unhandledrejection', rejectionEvent => { - window.log.error( - `Top-level unhandled promise rejection: ${rejectionEvent.reason}` - ); + const error = rejectionEvent.reason; + const errorInfo = error && error.stack ? error.stack : JSON.stringify(error); + window.log.error(`Top-level unhandled promise rejection: ${errorInfo}`); }); diff --git a/password_preload.js b/password_preload.js index d499b1609..bd18b92db 100644 --- a/password_preload.js +++ b/password_preload.js @@ -32,7 +32,7 @@ window.Signal = { Components: { SessionPasswordPrompt, }, -} +}; window.CONSTANTS = { MAX_LOGIN_TRIES: 3, From 7580b46b5be62f1bedaf33369c1b1d7bf554b1e7 Mon Sep 17 00:00:00 2001 From: Mikunj Date: Tue, 21 Jul 2020 13:18:04 +1000 Subject: [PATCH 6/6] Fix build-release command --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d37bdca13..40e0fd910 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "grunt": "grunt", "icon-gen": "electron-icon-maker --input=images/icon_1024.png --output=./build", "generate": "yarn icon-gen && yarn grunt", - "build-release": "cross-env SIGNAL_ENV=production npm run build -- --config.directories.output=release", + "build-release": "cross-env SIGNAL_ENV=production electron-builder --config.extraMetadata.environment=production --publish=never --config.directories.output=release", "build-module-protobuf": "pbjs --target static-module --wrap commonjs --out ts/protobuf/compiled.js protos/*.proto && pbts --out ts/protobuf/compiled.d.ts ts/protobuf/compiled.js --force-long", "clean-module-protobuf": "rm -f ts/protobuf/compiled.d.ts ts/protobuf/compiled.js", "build-protobuf": "yarn build-module-protobuf",