Skip to content
This repository has been archived by the owner on Aug 5, 2021. It is now read-only.

Commit

Permalink
Expose ability to fully delete existing sessions - for resets (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
scottnonnenberg authored Nov 21, 2017
1 parent 6154353 commit f1e22f6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/SessionCipher.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
};

Expand All @@ -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);
};
4 changes: 4 additions & 0 deletions src/SessionRecord.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit f1e22f6

Please sign in to comment.