Remove config after unlink, clear db when linked with new number
This commit is contained in:
parent
fd056e1b4c
commit
9acb189650
7 changed files with 108 additions and 11 deletions
|
@ -694,8 +694,25 @@
|
||||||
console.log('background onError:', Errors.toLogFormat(error));
|
console.log('background onError:', Errors.toLogFormat(error));
|
||||||
|
|
||||||
if (error.name === 'HTTPError' && (error.code == 401 || error.code == 403)) {
|
if (error.name === 'HTTPError' && (error.code == 401 || error.code == 403)) {
|
||||||
Whisper.Registration.remove();
|
|
||||||
Whisper.events.trigger('unauthorized');
|
Whisper.events.trigger('unauthorized');
|
||||||
|
|
||||||
|
console.log('Client is no longer authorized; deleting local configuration');
|
||||||
|
Whisper.Registration.remove();
|
||||||
|
var previousNumberId = textsecure.storage.get('number_id');
|
||||||
|
|
||||||
|
textsecure.storage.protocol.removeAllConfiguration().then(function() {
|
||||||
|
// These two bits of data are important to ensure that the app loads up
|
||||||
|
// the conversation list, instead of showing just the QR code screen.
|
||||||
|
Whisper.Registration.markEverDone();
|
||||||
|
textsecure.storage.put('number_id', previousNumberId);
|
||||||
|
console.log('Successfully cleared local configuration');
|
||||||
|
}, function(error) {
|
||||||
|
console.log(
|
||||||
|
'Something went wrong clearing local configuration',
|
||||||
|
error && error.stack ? error.stack : error
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
17
js/backup.js
17
js/backup.js
|
@ -913,9 +913,13 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function clearAllStores(idb_db) {
|
function clearAllStores(idb_db) {
|
||||||
|
return clearStores(idb_db);
|
||||||
|
}
|
||||||
|
|
||||||
|
function clearStores(idb_db, names) {
|
||||||
return new Promise(function(resolve, reject) {
|
return new Promise(function(resolve, reject) {
|
||||||
console.log('Clearing all indexeddb stores');
|
var storeNames = names || idb_db.objectStoreNames;
|
||||||
var storeNames = idb_db.objectStoreNames;
|
console.log('Clearing these indexeddb stores:', storeNames);
|
||||||
var transaction = idb_db.transaction(storeNames, 'readwrite');
|
var transaction = idb_db.transaction(storeNames, 'readwrite');
|
||||||
|
|
||||||
var finished = false;
|
var finished = false;
|
||||||
|
@ -930,7 +934,7 @@
|
||||||
transaction.oncomplete = finish.bind(null, 'transaction complete');
|
transaction.oncomplete = finish.bind(null, 'transaction complete');
|
||||||
transaction.onerror = function(e) {
|
transaction.onerror = function(e) {
|
||||||
handleDOMException(
|
handleDOMException(
|
||||||
'clearAllStores transaction error',
|
'clearStores transaction error',
|
||||||
transaction.error,
|
transaction.error,
|
||||||
reject
|
reject
|
||||||
);
|
);
|
||||||
|
@ -953,7 +957,7 @@
|
||||||
|
|
||||||
request.onerror = function(e) {
|
request.onerror = function(e) {
|
||||||
handleDOMException(
|
handleDOMException(
|
||||||
'clearAllStores request error',
|
'clearStores request error',
|
||||||
request.error,
|
request.error,
|
||||||
reject
|
reject
|
||||||
);
|
);
|
||||||
|
@ -973,6 +977,11 @@
|
||||||
return clearAllStores(idb_db);
|
return clearAllStores(idb_db);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
clearStores: function(storeNames) {
|
||||||
|
return openDatabase().then(function(idb_db) {
|
||||||
|
return clearStores(idb_db, storeNames);
|
||||||
|
});
|
||||||
|
},
|
||||||
getDirectoryForExport: function() {
|
getDirectoryForExport: function() {
|
||||||
var options = {
|
var options = {
|
||||||
title: i18n('exportChooserTitle'),
|
title: i18n('exportChooserTitle'),
|
||||||
|
|
|
@ -161,7 +161,7 @@
|
||||||
return this._initialPromise;
|
return this._initialPromise;
|
||||||
},
|
},
|
||||||
reset: function() {
|
reset: function() {
|
||||||
this._initialPromise = null;
|
this._initialPromise = Promise.resolve();
|
||||||
conversations.reset([]);
|
conversations.reset([]);
|
||||||
},
|
},
|
||||||
load: function() {
|
load: function() {
|
||||||
|
|
|
@ -4,8 +4,11 @@
|
||||||
(function () {
|
(function () {
|
||||||
'use strict';
|
'use strict';
|
||||||
Whisper.Registration = {
|
Whisper.Registration = {
|
||||||
markDone: function () {
|
markEverDone: function() {
|
||||||
storage.put('chromiumRegistrationDoneEver', '');
|
storage.put('chromiumRegistrationDoneEver', '');
|
||||||
|
},
|
||||||
|
markDone: function () {
|
||||||
|
this.markEverDone();
|
||||||
storage.put('chromiumRegistrationDone', '');
|
storage.put('chromiumRegistrationDone', '');
|
||||||
},
|
},
|
||||||
isDone: function () {
|
isDone: function () {
|
||||||
|
|
|
@ -171,18 +171,18 @@
|
||||||
constructor: SignalProtocolStore,
|
constructor: SignalProtocolStore,
|
||||||
getIdentityKeyPair: function() {
|
getIdentityKeyPair: function() {
|
||||||
var item = new Item({id: 'identityKey'});
|
var item = new Item({id: 'identityKey'});
|
||||||
return new Promise(function(resolve) {
|
return new Promise(function(resolve, reject) {
|
||||||
item.fetch().then(function() {
|
item.fetch().then(function() {
|
||||||
resolve(item.get('value'));
|
resolve(item.get('value'));
|
||||||
});
|
}, reject);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
getLocalRegistrationId: function() {
|
getLocalRegistrationId: function() {
|
||||||
var item = new Item({id: 'registrationId'});
|
var item = new Item({id: 'registrationId'});
|
||||||
return new Promise(function(resolve) {
|
return new Promise(function(resolve, reject) {
|
||||||
item.fetch().then(function() {
|
item.fetch().then(function() {
|
||||||
resolve(item.get('value'));
|
resolve(item.get('value'));
|
||||||
});
|
}, reject);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -854,6 +854,37 @@
|
||||||
return unprocessed.destroy().then(resolve, reject);
|
return unprocessed.destroy().then(resolve, reject);
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
},
|
},
|
||||||
|
removeAllData: function() {
|
||||||
|
// First the in-memory caches:
|
||||||
|
window.storage.reset(); // items store
|
||||||
|
ConversationController.reset(); // conversations store
|
||||||
|
|
||||||
|
// Then, the database. All stores:
|
||||||
|
// items
|
||||||
|
// identityKeys
|
||||||
|
// sessions
|
||||||
|
// signedPreKeys
|
||||||
|
// preKeys
|
||||||
|
// unprocessed
|
||||||
|
// groups
|
||||||
|
// conversations
|
||||||
|
// messages
|
||||||
|
return window.Whisper.Backup.clearDatabase();
|
||||||
|
},
|
||||||
|
removeAllConfiguration: function() {
|
||||||
|
// First the in-memory cache for the items store:
|
||||||
|
window.storage.reset();
|
||||||
|
|
||||||
|
// Then anything in the database that isn't a message/conversation/group:
|
||||||
|
return window.Whisper.Backup.clearStores([
|
||||||
|
'items',
|
||||||
|
'identityKeys',
|
||||||
|
'sessions',
|
||||||
|
'signedPreKeys',
|
||||||
|
'preKeys',
|
||||||
|
'unprocessed',
|
||||||
|
]);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
_.extend(SignalProtocolStore.prototype, Backbone.Events);
|
_.extend(SignalProtocolStore.prototype, Backbone.Events);
|
||||||
|
|
||||||
|
|
|
@ -67,6 +67,10 @@
|
||||||
console.log('Failed to fetch from storage');
|
console.log('Failed to fetch from storage');
|
||||||
}).always(resolve);
|
}).always(resolve);
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
reset: function() {
|
||||||
|
items.reset();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
window.textsecure = window.textsecure || {};
|
window.textsecure = window.textsecure || {};
|
||||||
|
|
|
@ -14,6 +14,19 @@
|
||||||
this.pending = Promise.resolve();
|
this.pending = Promise.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getNumber(numberId) {
|
||||||
|
if (!numberId || !numberId.length) {
|
||||||
|
return numberId;
|
||||||
|
}
|
||||||
|
|
||||||
|
var parts = numberId.split('.');
|
||||||
|
if (!parts.length) {
|
||||||
|
return numberId;
|
||||||
|
}
|
||||||
|
|
||||||
|
return parts[1];
|
||||||
|
}
|
||||||
|
|
||||||
AccountManager.prototype = new textsecure.EventTarget();
|
AccountManager.prototype = new textsecure.EventTarget();
|
||||||
AccountManager.prototype.extend({
|
AccountManager.prototype.extend({
|
||||||
constructor: AccountManager,
|
constructor: AccountManager,
|
||||||
|
@ -261,9 +274,29 @@
|
||||||
password = password.substring(0, password.length - 2);
|
password = password.substring(0, password.length - 2);
|
||||||
var registrationId = libsignal.KeyHelper.generateRegistrationId();
|
var registrationId = libsignal.KeyHelper.generateRegistrationId();
|
||||||
|
|
||||||
|
var previousNumber = getNumber(textsecure.storage.get('number_id'));
|
||||||
|
|
||||||
return this.server.confirmCode(
|
return this.server.confirmCode(
|
||||||
number, verificationCode, password, signalingKey, registrationId, deviceName
|
number, verificationCode, password, signalingKey, registrationId, deviceName
|
||||||
).then(function(response) {
|
).then(function(response) {
|
||||||
|
if (previousNumber && previousNumber !== number) {
|
||||||
|
console.log('New number is different from old number; deleting all previous data');
|
||||||
|
|
||||||
|
return textsecure.storage.protocol.removeAllData().then(function() {
|
||||||
|
console.log('Successfully deleted previous data');
|
||||||
|
return response;
|
||||||
|
}, function(error) {
|
||||||
|
console.log(
|
||||||
|
'Something went wrong deleting data from previous number',
|
||||||
|
error && error.stack ? error.stack : error
|
||||||
|
);
|
||||||
|
|
||||||
|
return response;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}).then(function(response) {
|
||||||
textsecure.storage.remove('identityKey');
|
textsecure.storage.remove('identityKey');
|
||||||
textsecure.storage.remove('signaling_key');
|
textsecure.storage.remove('signaling_key');
|
||||||
textsecure.storage.remove('password');
|
textsecure.storage.remove('password');
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue