From 27fe7e355edc8394e250844345e28b3ad7a2595e Mon Sep 17 00:00:00 2001 From: lilia Date: Thu, 4 Feb 2016 11:25:25 -0800 Subject: [PATCH] Process end session flags in sync messages Because remote clients will delete all sessions in response to an end session message, regardless of which device it came from, when our linked device sends an end session message, we must also end all sessions with the destination. This change moves the end session flag processing to processDecrypted, which is shared between handlers of sent messages, data messages, and messages which are re-tried after resolving identity conflicts. // FREEBIE --- js/libtextsecure.js | 25 ++++++++++++++++--------- libtextsecure/message_receiver.js | 25 ++++++++++++++++--------- 2 files changed, 32 insertions(+), 18 deletions(-) diff --git a/js/libtextsecure.js b/js/libtextsecure.js index 740b1b039..b66fe27e6 100644 --- a/js/libtextsecure.js +++ b/js/libtextsecure.js @@ -36947,15 +36947,22 @@ MessageReceiver.prototype.extend({ }.bind(this)); }, handleSentMessage: function(destination, timestamp, message) { - return this.processDecrypted(message, this.number).then(function(message) { - var ev = new Event('sent'); - ev.data = { - destination : destination, - timestamp : timestamp.toNumber(), - message : message - }; - this.dispatchEvent(ev); - }.bind(this)); + var p = Promise.resolve(); + if ((message.flags & textsecure.protobuf.DataMessage.Flags.END_SESSION) == + textsecure.protobuf.DataMessage.Flags.END_SESSION ) { + p = this.handleEndSession(destination); + } + return p.then(function() { + return this.processDecrypted(message, this.number).then(function(message) { + var ev = new Event('sent'); + ev.data = { + destination : destination, + timestamp : timestamp.toNumber(), + message : message + }; + this.dispatchEvent(ev); + }.bind(this)); + }); }, handleDataMessage: function(envelope, message, close_session) { var encodedNumber = envelope.source + '.' + envelope.sourceDevice; diff --git a/libtextsecure/message_receiver.js b/libtextsecure/message_receiver.js index cc545eeab..08660c7ac 100644 --- a/libtextsecure/message_receiver.js +++ b/libtextsecure/message_receiver.js @@ -130,15 +130,22 @@ MessageReceiver.prototype.extend({ }.bind(this)); }, handleSentMessage: function(destination, timestamp, message) { - return this.processDecrypted(message, this.number).then(function(message) { - var ev = new Event('sent'); - ev.data = { - destination : destination, - timestamp : timestamp.toNumber(), - message : message - }; - this.dispatchEvent(ev); - }.bind(this)); + var p = Promise.resolve(); + if ((message.flags & textsecure.protobuf.DataMessage.Flags.END_SESSION) == + textsecure.protobuf.DataMessage.Flags.END_SESSION ) { + p = this.handleEndSession(destination); + } + return p.then(function() { + return this.processDecrypted(message, this.number).then(function(message) { + var ev = new Event('sent'); + ev.data = { + destination : destination, + timestamp : timestamp.toNumber(), + message : message + }; + this.dispatchEvent(ev); + }.bind(this)); + }); }, handleDataMessage: function(envelope, message, close_session) { var encodedNumber = envelope.source + '.' + envelope.sourceDevice;