|
@@ -13,19 +13,23 @@ export function getDefaultStore () {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+function storeUsesIndexedDB (store) {
|
|
|
+ return store === 'persistent' && api.settings.get('persistent_store') === 'IndexedDB';
|
|
|
+}
|
|
|
+
|
|
|
export function createStore (id, store) {
|
|
|
const name = store || getDefaultStore();
|
|
|
const s = _converse.storage[name];
|
|
|
if (typeof s === 'undefined') {
|
|
|
throw new TypeError(`createStore: Could not find store for ${id}`);
|
|
|
}
|
|
|
- return new Storage(id, s, api.settings.get('persistent_store') === 'IndexedDB');
|
|
|
+ return new Storage(id, s, storeUsesIndexedDB(store));
|
|
|
}
|
|
|
|
|
|
export function initStorage (model, id, type) {
|
|
|
const store = type || getDefaultStore();
|
|
|
model.browserStorage = _converse.createStore(id, store);
|
|
|
- if (store === 'persistent' && api.settings.get('persistent_store') === 'IndexedDB') {
|
|
|
+ if (storeUsesIndexedDB(store)) {
|
|
|
const flush = () => model.browserStorage.flush();
|
|
|
window.addEventListener(_converse.unloadevent, flush);
|
|
|
model.on('destroy', () => window.removeEventListener(_converse.unloadevent, flush));
|