From 029851400dbba5dfca78deed8528471d5c015cbb Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Mon, 22 Jun 2020 10:50:19 +1000 Subject: [PATCH] include endSession message with new pipeline --- js/models/conversations.js | 21 +++++++++++++-------- libtextsecure/sendmessage.js | 26 -------------------------- ts/receiver/receiver.ts | 5 ++++- 3 files changed, 17 insertions(+), 35 deletions(-) diff --git a/js/models/conversations.js b/js/models/conversations.js index d5f0a4768..bb08c98d9 100644 --- a/js/models/conversations.js +++ b/js/models/conversations.js @@ -1803,15 +1803,20 @@ type: 'outgoing', endSessionType: 'ongoing', }); - await message.send( - this.wrapSend( - textsecure.messaging.resetSession( - this.id, - message.get('sent_at'), - {} - ) - ) + window.log.info('resetting secure session'); + const device = new libsession.Types.PubKey(this.id); + const preKeyBundle = await window.libloki.storage.getPreKeyBundleForContact( + device.key ); + const endSessionMessage = new libsession.Messages.Outgoing.EndSessionMessage( + { + timestamp: message.get('sent_at'), + preKeyBundle, + } + ); + + await libsession.getMessageQueue().send(device, endSessionMessage); + // TODO handle errors to reset session reset status with the new pipeline if (message.hasErrors()) { await this.setSessionResetStatus(SessionResetEnum.none); } diff --git a/libtextsecure/sendmessage.js b/libtextsecure/sendmessage.js index 99bbf8fd7..df476cfee 100644 --- a/libtextsecure/sendmessage.js +++ b/libtextsecure/sendmessage.js @@ -969,31 +969,6 @@ MessageSender.prototype = { options ); }, - - resetSession(number, timestamp, options) { - window.log.info('resetting secure session'); - const silent = false; - const proto = new textsecure.protobuf.DataMessage(); - proto.body = 'TERMINATE'; - proto.flags = textsecure.protobuf.DataMessage.Flags.END_SESSION; - - const logError = prefix => error => { - window.log.error(prefix, error && error.stack ? error.stack : error); - throw error; - }; - - // The actual deletion of the session now happens later - // as we need to ensure the other contact has successfully - // switch to a new session first. - return this.sendIndividualProto( - number, - proto, - timestamp, - silent, - options - ).catch(logError('resetSession/sendToContact error:')); - }, - async sendMessageToGroup( groupId, groupNumbers, @@ -1166,7 +1141,6 @@ textsecure.MessageSender = function MessageSenderWrapper(username, password) { ); this.sendMessageToNumber = sender.sendMessageToNumber.bind(sender); this.sendMessage = sender.sendMessage.bind(sender); - this.resetSession = sender.resetSession.bind(sender); this.sendMessageToGroup = sender.sendMessageToGroup.bind(sender); this.sendGroupUpdate = sender.sendGroupUpdate.bind(sender); this.updateMediumGroup = sender.updateMediumGroup.bind(sender); diff --git a/ts/receiver/receiver.ts b/ts/receiver/receiver.ts index 916cff64a..83c0a496b 100644 --- a/ts/receiver/receiver.ts +++ b/ts/receiver/receiver.ts @@ -603,7 +603,10 @@ export async function handleMessageEvent(event: any): Promise { const isOurDevice = await MultiDeviceProtocol.isOurDevice(source); const shouldSendReceipt = - isIncoming && data.unidentifiedDeliveryReceived && !isGroupMessage && !isOurDevice; + isIncoming && + data.unidentifiedDeliveryReceived && + !isGroupMessage && + !isOurDevice; if (shouldSendReceipt) { await sendDeliveryReceipt(source, data.timestamp);