2020-10-30 20:34:04 +00:00
|
|
|
// Copyright 2018-2020 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2020-04-28 21:18:41 +00:00
|
|
|
/* global window, Whisper, setTimeout */
|
2018-10-18 01:01:21 +00:00
|
|
|
|
|
|
|
const MESSAGE_MINIMUM_VERSION = 7;
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
doesDatabaseExist,
|
|
|
|
MESSAGE_MINIMUM_VERSION,
|
|
|
|
removeDatabase,
|
|
|
|
};
|
|
|
|
|
|
|
|
async function doesDatabaseExist() {
|
2021-10-07 23:28:47 +00:00
|
|
|
window.SignalContext.log.info(
|
2021-09-17 18:27:53 +00:00
|
|
|
'Checking for the existence of IndexedDB data...'
|
|
|
|
);
|
2018-10-18 01:01:21 +00:00
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
const { id } = Whisper.Database;
|
|
|
|
const req = window.indexedDB.open(id);
|
|
|
|
|
|
|
|
let existed = true;
|
|
|
|
|
2019-06-27 20:21:52 +00:00
|
|
|
setTimeout(() => {
|
2021-10-07 23:28:47 +00:00
|
|
|
window.SignalContext.log.warn(
|
2019-06-27 20:21:52 +00:00
|
|
|
'doesDatabaseExist: Timed out attempting to check IndexedDB status'
|
|
|
|
);
|
|
|
|
return resolve(false);
|
2019-08-06 18:42:57 +00:00
|
|
|
}, 1000);
|
2019-06-27 20:21:52 +00:00
|
|
|
|
2018-10-18 01:01:21 +00:00
|
|
|
req.onerror = reject;
|
|
|
|
req.onsuccess = () => {
|
|
|
|
req.result.close();
|
|
|
|
resolve(existed);
|
|
|
|
};
|
|
|
|
req.onupgradeneeded = () => {
|
|
|
|
if (req.result.version === 1) {
|
|
|
|
existed = false;
|
|
|
|
window.indexedDB.deleteDatabase(id);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function removeDatabase() {
|
2021-10-07 23:28:47 +00:00
|
|
|
window.SignalContext.log.info(
|
2021-09-17 18:27:53 +00:00
|
|
|
`Deleting IndexedDB database '${Whisper.Database.id}'`
|
|
|
|
);
|
2018-10-18 01:01:21 +00:00
|
|
|
window.indexedDB.deleteDatabase(Whisper.Database.id);
|
|
|
|
}
|