Browse Source

Bugfix. XEP-0198 stream management not working when using IndexedDB

The issue was that batched writing was incorrectly also being applied
for sessionStorage stores, so when the `active` flag in
`_converse.session` was being set to `false` on window unload, the
change wasn't persisted before the window was unloaded.

This caused a new session to be created upon reload, thereby losing the
SMACKS data.

We already solved this for persistent stores by flushing them, and
doing so for the session stores would also work, but session stores
don't have to be batched in the first place, so we turn that off.
JC Brand 4 years ago
parent
commit
fe3650d766
1 changed files with 6 additions and 2 deletions
  1. 6 2
      src/headless/shared/utils.js

+ 6 - 2
src/headless/shared/utils.js

@@ -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));