Bugfix. Avoid creating an undefined store

This commit is contained in:
JC Brand 2021-04-22 11:31:04 +02:00
parent b678df8d23
commit 7b49296a24
3 changed files with 18 additions and 3 deletions

View File

@ -4,6 +4,7 @@ import u from '@converse/headless/utils/core';
import { CONNECTION_STATUS } from '@converse/headless/shared/constants';
import { Router } from '@converse/skeletor/src/router.js';
import { TimeoutError } from '@converse/headless/shared/errors';
import { createStore, getDefaultStore } from '@converse/headless/shared/utils.js';
import { getInitSettings } from '@converse/headless/shared/settings';
@ -80,6 +81,9 @@ const _converse = {
return getInitSettings()['bosh_service_url'] === 'montague.lit/http-bind';
},
getDefaultStore,
createStore,
/**
* Translate the given string based on the current locale.
* @method __

View File

@ -1,11 +1,22 @@
import Storage from '@converse/skeletor/src/storage.js';
import _converse from '@converse/headless/shared/_converse';
import { _converse, api } from '@converse/headless/core';
import log from '@converse/headless/log';
import u from '@converse/headless/utils/core';
export function getDefaultStore () {
if (_converse.config.get('trusted')) {
const is_non_persistent = api.settings.get('persistent_store') === 'sessionStorage';
return is_non_persistent ? 'session': 'persistent';
} else {
return 'session';
}
}
export function createStore (id, storage) {
const s = _converse.storage[storage || _converse.getDefaultStore()];
const s = _converse.storage[storage || getDefaultStore()];
if (typeof s === 'undefined') {
throw new TypeError(`createStore: Could not find store for %{id}`);
}
return new Storage(id, s);
}

View File

@ -34,7 +34,7 @@ class MinimizedChats extends ElementView {
async initToggle () {
const id = `converse.minchatstoggle-${_converse.bare_jid}`;
this.minchats = new MinimizedChatsToggle({id});
this.minchats.browserStorage = _converse.createStore(id);
this.minchats.browserStorage = _converse.createStore(id, 'session');
await new Promise(resolve => this.minchats.fetch({'success': resolve, 'error': resolve}));
}