2020-10-30 20:34:04 +00:00
|
|
|
// Copyright 2018-2020 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2021-02-26 21:06:37 +00:00
|
|
|
/* global i18n, Whisper, $ */
|
2018-07-03 22:33:50 +00:00
|
|
|
|
|
|
|
// eslint-disable-next-line func-names
|
2020-11-18 15:15:42 +00:00
|
|
|
(function () {
|
2018-07-03 22:33:50 +00:00
|
|
|
window.Whisper = window.Whisper || {};
|
|
|
|
const { Logs } = window.Signal;
|
|
|
|
|
|
|
|
const CLEAR_DATA_STEPS = {
|
|
|
|
CHOICE: 1,
|
|
|
|
DELETING: 2,
|
|
|
|
};
|
|
|
|
window.Whisper.ClearDataView = Whisper.View.extend({
|
2021-02-26 21:06:37 +00:00
|
|
|
template: () => $('#clear-data').html(),
|
2018-07-03 22:33:50 +00:00
|
|
|
className: 'full-screen-flow overlay',
|
|
|
|
events: {
|
|
|
|
'click .cancel': 'onCancel',
|
|
|
|
'click .delete-all-data': 'onDeleteAllData',
|
|
|
|
},
|
|
|
|
initialize() {
|
|
|
|
this.step = CLEAR_DATA_STEPS.CHOICE;
|
|
|
|
},
|
|
|
|
onCancel() {
|
|
|
|
this.remove();
|
|
|
|
},
|
|
|
|
async onDeleteAllData() {
|
2018-07-21 19:00:08 +00:00
|
|
|
window.log.info('Deleting everything!');
|
2018-07-03 22:33:50 +00:00
|
|
|
this.step = CLEAR_DATA_STEPS.DELETING;
|
|
|
|
this.render();
|
|
|
|
|
2018-10-18 01:01:21 +00:00
|
|
|
await this.clearAllData();
|
2018-07-03 22:33:50 +00:00
|
|
|
},
|
|
|
|
async clearAllData() {
|
|
|
|
try {
|
2018-08-28 21:53:05 +00:00
|
|
|
await Logs.deleteAll();
|
2018-07-27 01:13:56 +00:00
|
|
|
|
2021-05-13 20:54:54 +00:00
|
|
|
window.log.info('clearAllData: deleted all logs');
|
|
|
|
|
2018-08-28 21:53:05 +00:00
|
|
|
await window.Signal.Data.removeAll();
|
2021-05-13 20:54:54 +00:00
|
|
|
|
|
|
|
window.log.info('clearAllData: emptied database');
|
|
|
|
|
2018-07-27 01:13:56 +00:00
|
|
|
await window.Signal.Data.close();
|
2021-05-13 20:54:54 +00:00
|
|
|
|
|
|
|
window.log.info('clearAllData: closed database');
|
|
|
|
|
2018-07-27 01:13:56 +00:00
|
|
|
await window.Signal.Data.removeDB();
|
2018-08-28 21:53:05 +00:00
|
|
|
|
2021-05-13 20:54:54 +00:00
|
|
|
window.log.info('clearAllData: removed database');
|
|
|
|
|
2018-08-28 21:53:05 +00:00
|
|
|
await window.Signal.Data.removeOtherData();
|
2021-05-13 20:54:54 +00:00
|
|
|
|
|
|
|
window.log.info('clearAllData: removed all other data');
|
2018-07-03 22:33:50 +00:00
|
|
|
} catch (error) {
|
2018-07-21 19:00:08 +00:00
|
|
|
window.log.error(
|
2018-07-03 22:33:50 +00:00
|
|
|
'Something went wrong deleting all data:',
|
|
|
|
error && error.stack ? error.stack : error
|
|
|
|
);
|
|
|
|
}
|
|
|
|
window.restart();
|
|
|
|
},
|
|
|
|
render_attributes() {
|
|
|
|
return {
|
|
|
|
isStep1: this.step === CLEAR_DATA_STEPS.CHOICE,
|
|
|
|
header: i18n('deleteAllDataHeader'),
|
|
|
|
body: i18n('deleteAllDataBody'),
|
|
|
|
cancelButton: i18n('cancel'),
|
|
|
|
deleteButton: i18n('deleteAllDataButton'),
|
|
|
|
|
|
|
|
isStep2: this.step === CLEAR_DATA_STEPS.DELETING,
|
|
|
|
deleting: i18n('deleteAllDataProgress'),
|
|
|
|
};
|
|
|
|
},
|
|
|
|
});
|
|
|
|
})();
|