diff --git a/src/SessionCipher.js b/src/SessionCipher.js index 3ba0102..14d3f2d 100644 --- a/src/SessionCipher.js +++ b/src/SessionCipher.js @@ -398,6 +398,20 @@ SessionCipher.prototype = { return this.storage.storeSession(address, record.serialize()); }.bind(this)); }.bind(this)); + }, + deleteAllSessionsForDevice: function() { + // Used in session reset scenarios, where we really need to delete + var address = this.remoteAddress.toString(); + return Internal.SessionLock.queueJobForNumber(address, function() { + return this.getRecord(address).then(function(record) { + if (record === undefined) { + return; + } + + record.deleteAllSessions(); + return this.storage.storeSession(address, record.serialize()); + }.bind(this)); + }.bind(this)); } }; @@ -417,4 +431,5 @@ libsignal.SessionCipher = function(storage, remoteAddress, options) { this.getRemoteRegistrationId = cipher.getRemoteRegistrationId.bind(cipher); this.hasOpenSession = cipher.hasOpenSession.bind(cipher); this.closeOpenSessionForDevice = cipher.closeOpenSessionForDevice.bind(cipher); + this.deleteAllSessionsForDevice = cipher.deleteAllSessionsForDevice.bind(cipher); }; diff --git a/src/SessionRecord.js b/src/SessionRecord.js index f56cef5..6aa325c 100644 --- a/src/SessionRecord.js +++ b/src/SessionRecord.js @@ -263,6 +263,10 @@ Internal.SessionRecord = function() { delete sessions[util.toString(oldestBaseKey)]; } }, + deleteAllSessions: function() { + // Used primarily in session reset scenarios, where we really delete sessions + this.sessions = {}; + } }; return SessionRecord;