2018-04-08 14:32:39 +03:00
|
|
|
export default () => new Promise((resolve, reject) => {
|
|
|
|
// ServiceWorker is required to synchronize the login state.
|
2018-03-24 14:06:27 +02:00
|
|
|
// Microsoft Edge 17 does not support getAll according to:
|
|
|
|
// Catalog of standard and vendor APIs across browsers - Microsoft Edge Development
|
|
|
|
// https://developer.microsoft.com/en-us/microsoft-edge/platform/catalog/?q=specName%3Aindexeddb
|
2018-04-08 14:32:39 +03:00
|
|
|
if (!('caches' in self && 'getAll' in IDBObjectStore.prototype)) {
|
2018-03-24 14:06:27 +02:00
|
|
|
reject();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-04-08 14:32:39 +03:00
|
|
|
const request = indexedDB.open('mastodon');
|
2018-03-24 14:06:27 +02:00
|
|
|
|
|
|
|
request.onerror = reject;
|
|
|
|
request.onsuccess = ({ target }) => resolve(target.result);
|
|
|
|
|
|
|
|
request.onupgradeneeded = ({ target }) => {
|
|
|
|
const accounts = target.result.createObjectStore('accounts', { autoIncrement: true });
|
|
|
|
const statuses = target.result.createObjectStore('statuses', { autoIncrement: true });
|
|
|
|
|
|
|
|
accounts.createIndex('id', 'id', { unique: true });
|
|
|
|
accounts.createIndex('moved', 'moved');
|
|
|
|
|
|
|
|
statuses.createIndex('id', 'id', { unique: true });
|
|
|
|
statuses.createIndex('account', 'account');
|
|
|
|
statuses.createIndex('reblog', 'reblog');
|
|
|
|
};
|
|
|
|
});
|