Rename variable to be less confusing

pull/843/head
Mikunj 6 years ago
parent 6620092959
commit 1be4123133

@ -329,10 +329,13 @@
* This handles specific session reset logic that we need. * This handles specific session reset logic that we need.
*/ */
class LokiSessionCipher { class LokiSessionCipher {
constructor(storage, address) { constructor(storage, protocolAddress) {
this.storage = storage; this.storage = storage;
this.address = address; this.protocolAddress = protocolAddress;
this.sessionCipher = new libsignal.SessionCipher(storage, address); this.sessionCipher = new libsignal.SessionCipher(
storage,
protocolAddress
);
this.TYPE = Object.freeze({ this.TYPE = Object.freeze({
MESSAGE: 1, MESSAGE: 1,
PREKEY: 2, PREKEY: 2,
@ -354,7 +357,7 @@
if (type === this.TYPE.PREKEY && !activeSessionBaseKey) { if (type === this.TYPE.PREKEY && !activeSessionBaseKey) {
const wrapped = dcodeIO.ByteBuffer.wrap(buffer); const wrapped = dcodeIO.ByteBuffer.wrap(buffer);
await window.libloki.storage.verifyFriendRequestAcceptPreKey( await window.libloki.storage.verifyFriendRequestAcceptPreKey(
this.address.getName(), this.protocolAddress.getName(),
wrapped wrapped
); );
} }
@ -385,11 +388,14 @@
let conversation; let conversation;
try { try {
conversation = await window.ConversationController.getOrCreateAndWait( conversation = await window.ConversationController.getOrCreateAndWait(
this.address.getName(), this.protocolAddress.getName(),
'private' 'private'
); );
} catch (e) { } catch (e) {
window.log.info('Error getting conversation: ', this.address.getName()); window.log.info(
'Error getting conversation: ',
this.protocolAddress.getName()
);
return; return;
} }
@ -414,7 +420,7 @@
async _getCurrentSessionBaseKey() { async _getCurrentSessionBaseKey() {
const record = await this.sessionCipher.getRecord( const record = await this.sessionCipher.getRecord(
this.address.toString() this.protocolAddress.toString()
); );
if (!record) { if (!record) {
return null; return null;
@ -429,7 +435,7 @@
async _restoreSession(sessionBaseKey) { async _restoreSession(sessionBaseKey) {
const record = await this.sessionCipher.getRecord( const record = await this.sessionCipher.getRecord(
this.address.toString() this.protocolAddress.toString()
); );
if (!record) { if (!record) {
return; return;
@ -437,17 +443,21 @@
record.archiveCurrentState(); record.archiveCurrentState();
const sessionToRestore = record.sessions[sessionBaseKey]; const sessionToRestore = record.sessions[sessionBaseKey];
if (!sessionToRestore) {
throw new Error(`Cannot find session with base key ${sessionBaseKey}`);
}
record.promoteState(sessionToRestore); record.promoteState(sessionToRestore);
record.updateSessionState(sessionToRestore); record.updateSessionState(sessionToRestore);
await this.storage.storeSession( await this.storage.storeSession(
this.address.toString(), this.protocolAddress.toString(),
record.serialize() record.serialize()
); );
} }
async _deleteAllSessionExcept(sessionBaseKey) { async _deleteAllSessionExcept(sessionBaseKey) {
const record = await this.sessionCipher.getRecord( const record = await this.sessionCipher.getRecord(
this.address.toString() this.protocolAddress.toString()
); );
if (!record) { if (!record) {
return; return;
@ -456,7 +466,7 @@
record.sessions = {}; record.sessions = {};
record.updateSessionState(sessionToKeep); record.updateSessionState(sessionToKeep);
await this.storage.storeSession( await this.storage.storeSession(
this.address.toString(), this.protocolAddress.toString(),
record.serialize() record.serialize()
); );
} }

Loading…
Cancel
Save