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

Commit f1e22f6

Browse files
Expose ability to fully delete existing sessions - for resets (#35)
1 parent 6154353 commit f1e22f6

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/SessionCipher.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,20 @@ SessionCipher.prototype = {
398398
return this.storage.storeSession(address, record.serialize());
399399
}.bind(this));
400400
}.bind(this));
401+
},
402+
deleteAllSessionsForDevice: function() {
403+
// Used in session reset scenarios, where we really need to delete
404+
var address = this.remoteAddress.toString();
405+
return Internal.SessionLock.queueJobForNumber(address, function() {
406+
return this.getRecord(address).then(function(record) {
407+
if (record === undefined) {
408+
return;
409+
}
410+
411+
record.deleteAllSessions();
412+
return this.storage.storeSession(address, record.serialize());
413+
}.bind(this));
414+
}.bind(this));
401415
}
402416
};
403417

@@ -417,4 +431,5 @@ libsignal.SessionCipher = function(storage, remoteAddress, options) {
417431
this.getRemoteRegistrationId = cipher.getRemoteRegistrationId.bind(cipher);
418432
this.hasOpenSession = cipher.hasOpenSession.bind(cipher);
419433
this.closeOpenSessionForDevice = cipher.closeOpenSessionForDevice.bind(cipher);
434+
this.deleteAllSessionsForDevice = cipher.deleteAllSessionsForDevice.bind(cipher);
420435
};

src/SessionRecord.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,10 @@ Internal.SessionRecord = function() {
263263
delete sessions[util.toString(oldestBaseKey)];
264264
}
265265
},
266+
deleteAllSessions: function() {
267+
// Used primarily in session reset scenarios, where we really delete sessions
268+
this.sessions = {};
269+
}
266270
};
267271

268272
return SessionRecord;

0 commit comments

Comments
 (0)