|
|
|
@ -9,13 +9,13 @@ import {
|
|
|
|
|
import { getOurPubKeyStrFromCache } from '../session/utils/User';
|
|
|
|
|
import { trigger } from '../shims/events';
|
|
|
|
|
import {
|
|
|
|
|
createOrUpdateItem,
|
|
|
|
|
removeAllContactPreKeys,
|
|
|
|
|
removeAllContactSignedPreKeys,
|
|
|
|
|
removeAllPreKeys,
|
|
|
|
|
removeAllSessions,
|
|
|
|
|
removeAllSignedPreKeys,
|
|
|
|
|
} from '../data/data';
|
|
|
|
|
import { forceSyncConfigurationNowIfNeeded } from '../session/utils/syncUtils';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Might throw
|
|
|
|
@ -167,6 +167,39 @@ export class AccountManager {
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static async deleteAccount(reason?: string) {
|
|
|
|
|
const deleteEverything = async () => {
|
|
|
|
|
window.log.info(
|
|
|
|
|
'configuration message sent successfully. Deleting everything'
|
|
|
|
|
);
|
|
|
|
|
await window.Signal.Logs.deleteAll();
|
|
|
|
|
await window.Signal.Data.removeAll();
|
|
|
|
|
await window.Signal.Data.close();
|
|
|
|
|
await window.Signal.Data.removeDB();
|
|
|
|
|
await window.Signal.Data.removeOtherData();
|
|
|
|
|
// 'unlink' => toast will be shown on app restart
|
|
|
|
|
window.localStorage.setItem('restart-reason', reason || '');
|
|
|
|
|
};
|
|
|
|
|
try {
|
|
|
|
|
window.log.info('DeleteAccount => Sending a last SyncConfiguration');
|
|
|
|
|
// be sure to wait for the message being effectively sent. Otherwise we won't be able to encrypt it for our devices !
|
|
|
|
|
await forceSyncConfigurationNowIfNeeded(true);
|
|
|
|
|
window.log.info('Last configuration message sent!');
|
|
|
|
|
await deleteEverything();
|
|
|
|
|
} catch (error) {
|
|
|
|
|
window.log.error(
|
|
|
|
|
'Something went wrong deleting all data:',
|
|
|
|
|
error && error.stack ? error.stack : error
|
|
|
|
|
);
|
|
|
|
|
try {
|
|
|
|
|
await deleteEverything();
|
|
|
|
|
} catch (e) {
|
|
|
|
|
window.log.error(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
window.restart();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static async createAccount(identityKeyPair: any) {
|
|
|
|
|
const sodium = await getSodium();
|
|
|
|
|
let password = fromArrayBufferToBase64(sodium.randombytes_buf(16));
|
|
|
|
|