Make end session consistent with android

Close all the sessions for a number when receiving an end session
message.

// FREEBIE
This commit is contained in:
lilia 2016-02-03 11:04:39 -08:00
parent bf632bfa54
commit fe82e469f2
2 changed files with 54 additions and 30 deletions

View file

@ -36960,20 +36960,21 @@ MessageReceiver.prototype.extend({
handleDataMessage: function(envelope, message, close_session) { handleDataMessage: function(envelope, message, close_session) {
var encodedNumber = envelope.source + '.' + envelope.sourceDevice; var encodedNumber = envelope.source + '.' + envelope.sourceDevice;
console.log('data message from', encodedNumber, envelope.timestamp.toNumber()); console.log('data message from', encodedNumber, envelope.timestamp.toNumber());
var p = Promise.resolve();
if ((message.flags & textsecure.protobuf.DataMessage.Flags.END_SESSION) == if ((message.flags & textsecure.protobuf.DataMessage.Flags.END_SESSION) ==
textsecure.protobuf.DataMessage.Flags.END_SESSION ) { textsecure.protobuf.DataMessage.Flags.END_SESSION ) {
console.log('got end session'); p = this.handleEndSession(envelope.source);
console.log('closing session for device', encodedNumber);
close_session();
} }
return this.processDecrypted(message, envelope.source).then(function(message) { return p.then(function() {
var ev = new Event('message'); return this.processDecrypted(message, envelope.source).then(function(message) {
ev.data = { var ev = new Event('message');
source : envelope.source, ev.data = {
timestamp : envelope.timestamp.toNumber(), source : envelope.source,
message : message timestamp : envelope.timestamp.toNumber(),
}; message : message
this.dispatchEvent(ev); };
this.dispatchEvent(ev);
}.bind(this));
}.bind(this)); }.bind(this));
}, },
handleLegacyMessage: function (envelope) { handleLegacyMessage: function (envelope) {
@ -37098,17 +37099,28 @@ MessageReceiver.prototype.extend({
return textsecure.protocol_wrapper.handlePreKeyWhisperMessage(from, bytes).then(function(res) { return textsecure.protocol_wrapper.handlePreKeyWhisperMessage(from, bytes).then(function(res) {
var finalMessage = textsecure.protobuf.DataMessage.decode(res[0]); var finalMessage = textsecure.protobuf.DataMessage.decode(res[0]);
var p = Promise.resolve();
if ((finalMessage.flags & textsecure.protobuf.DataMessage.Flags.END_SESSION) if ((finalMessage.flags & textsecure.protobuf.DataMessage.Flags.END_SESSION)
== textsecure.protobuf.DataMessage.Flags.END_SESSION && == textsecure.protobuf.DataMessage.Flags.END_SESSION &&
finalMessage.sync !== null) { finalMessage.sync !== null) {
console.log('got end session'); var number = textsecure.utils.unencodeNumber(encodedNumber)[0];
res[1](); p = this.handleEndSession(number);
console.log('session closed for device', from);
} }
return this.processDecrypted(finalMessage); return p.then(function() {
return this.processDecrypted(finalMessage);
});
}.bind(this)); }.bind(this));
}, },
handleEndSession: function(number) {
console.log('got end session');
return textsecure.storage.devices.getDeviceObjectsForNumber(number).then(function(devices) {
return Promise.all(devices.map(function(device) {
console.log('closing session for', device.encodedNumber);
return textsecure.protocol_wrapper.closeOpenSessionForDevice(device.encodedNumber);
}));
});
},
processDecrypted: function(decrypted, source) { processDecrypted: function(decrypted, source) {
// Now that its decrypted, validate the message and clean it up for consumer processing // Now that its decrypted, validate the message and clean it up for consumer processing
// Note that messages may (generally) only perform one action and we ignore remaining fields // Note that messages may (generally) only perform one action and we ignore remaining fields

View file

@ -143,20 +143,21 @@ MessageReceiver.prototype.extend({
handleDataMessage: function(envelope, message, close_session) { handleDataMessage: function(envelope, message, close_session) {
var encodedNumber = envelope.source + '.' + envelope.sourceDevice; var encodedNumber = envelope.source + '.' + envelope.sourceDevice;
console.log('data message from', encodedNumber, envelope.timestamp.toNumber()); console.log('data message from', encodedNumber, envelope.timestamp.toNumber());
var p = Promise.resolve();
if ((message.flags & textsecure.protobuf.DataMessage.Flags.END_SESSION) == if ((message.flags & textsecure.protobuf.DataMessage.Flags.END_SESSION) ==
textsecure.protobuf.DataMessage.Flags.END_SESSION ) { textsecure.protobuf.DataMessage.Flags.END_SESSION ) {
console.log('got end session'); p = this.handleEndSession(envelope.source);
console.log('closing session for device', encodedNumber);
close_session();
} }
return this.processDecrypted(message, envelope.source).then(function(message) { return p.then(function() {
var ev = new Event('message'); return this.processDecrypted(message, envelope.source).then(function(message) {
ev.data = { var ev = new Event('message');
source : envelope.source, ev.data = {
timestamp : envelope.timestamp.toNumber(), source : envelope.source,
message : message timestamp : envelope.timestamp.toNumber(),
}; message : message
this.dispatchEvent(ev); };
this.dispatchEvent(ev);
}.bind(this));
}.bind(this)); }.bind(this));
}, },
handleLegacyMessage: function (envelope) { handleLegacyMessage: function (envelope) {
@ -281,17 +282,28 @@ MessageReceiver.prototype.extend({
return textsecure.protocol_wrapper.handlePreKeyWhisperMessage(from, bytes).then(function(res) { return textsecure.protocol_wrapper.handlePreKeyWhisperMessage(from, bytes).then(function(res) {
var finalMessage = textsecure.protobuf.DataMessage.decode(res[0]); var finalMessage = textsecure.protobuf.DataMessage.decode(res[0]);
var p = Promise.resolve();
if ((finalMessage.flags & textsecure.protobuf.DataMessage.Flags.END_SESSION) if ((finalMessage.flags & textsecure.protobuf.DataMessage.Flags.END_SESSION)
== textsecure.protobuf.DataMessage.Flags.END_SESSION && == textsecure.protobuf.DataMessage.Flags.END_SESSION &&
finalMessage.sync !== null) { finalMessage.sync !== null) {
console.log('got end session'); var number = textsecure.utils.unencodeNumber(encodedNumber)[0];
res[1](); p = this.handleEndSession(number);
console.log('session closed for device', from);
} }
return this.processDecrypted(finalMessage); return p.then(function() {
return this.processDecrypted(finalMessage);
});
}.bind(this)); }.bind(this));
}, },
handleEndSession: function(number) {
console.log('got end session');
return textsecure.storage.devices.getDeviceObjectsForNumber(number).then(function(devices) {
return Promise.all(devices.map(function(device) {
console.log('closing session for', device.encodedNumber);
return textsecure.protocol_wrapper.closeOpenSessionForDevice(device.encodedNumber);
}));
});
},
processDecrypted: function(decrypted, source) { processDecrypted: function(decrypted, source) {
// Now that its decrypted, validate the message and clean it up for consumer processing // Now that its decrypted, validate the message and clean it up for consumer processing
// Note that messages may (generally) only perform one action and we ignore remaining fields // Note that messages may (generally) only perform one action and we ignore remaining fields