Commit 82bce1e9 authored by JC Brand's avatar JC Brand

Move creation of browserStorage into a separate method

This is in anticipation of the localforage/IndexDB merge
parent 877e0777
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
*/ */
import "backbone.nativeview"; import "backbone.nativeview";
import "@converse/headless/converse-muc"; import "@converse/headless/converse-muc";
import BrowserStorage from "backbone.browserStorage";
import { OrderedListView } from "backbone.overview"; import { OrderedListView } from "backbone.overview";
import converse from "@converse/headless/converse-core"; import converse from "@converse/headless/converse-core";
import tpl_bookmark from "templates/bookmark.html"; import tpl_bookmark from "templates/bookmark.html";
...@@ -255,7 +254,7 @@ converse.plugins.add('converse-bookmark-views', { ...@@ -255,7 +254,7 @@ converse.plugins.add('converse-bookmark-views', {
const storage = _converse.config.get('storage'), const storage = _converse.config.get('storage'),
id = `converse.room-bookmarks${_converse.bare_jid}-list-model`; id = `converse.room-bookmarks${_converse.bare_jid}-list-model`;
this.list_model = new _converse.BookmarksList({'id': id}); this.list_model = new _converse.BookmarksList({'id': id});
this.list_model.browserStorage = new BrowserStorage[storage](id); this.list_model.browserStorage = _converse.createStore(id, storage);
const render = () => { const render = () => {
this.render(); this.render();
......
...@@ -147,8 +147,7 @@ converse.plugins.add('converse-chatboxviews', { ...@@ -147,8 +147,7 @@ converse.plugins.add('converse-chatboxviews', {
/* This method gets overridden in src/converse-controlbox.js if /* This method gets overridden in src/converse-controlbox.js if
* the controlbox plugin is active. * the controlbox plugin is active.
*/ */
this.forEach(v => v.close()); return Promise.all(this.map(v => v.close({'name': 'closeAllChatBoxes'})));
return this;
} }
}); });
......
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
import "@converse/headless/converse-emoji"; import "@converse/headless/converse-emoji";
import { debounce, find } from "lodash"; import { debounce, find } from "lodash";
import BrowserStorage from "backbone.browserStorage";
import bootstrap from "bootstrap.native"; import bootstrap from "bootstrap.native";
import tpl_emoji_button from "templates/emoji_button.html"; import tpl_emoji_button from "templates/emoji_button.html";
import tpl_emojis from "templates/emojis.html"; import tpl_emojis from "templates/emojis.html";
...@@ -103,7 +102,7 @@ converse.plugins.add('converse-emoji-views', { ...@@ -103,7 +102,7 @@ converse.plugins.add('converse-emoji-views', {
const storage = _converse.config.get('storage'), const storage = _converse.config.get('storage'),
id = `converse.emoji-${_converse.bare_jid}`; id = `converse.emoji-${_converse.bare_jid}`;
_converse.emojipicker = new _converse.EmojiPicker({'id': id}); _converse.emojipicker = new _converse.EmojiPicker({'id': id});
_converse.emojipicker.browserStorage = new BrowserStorage[storage](id); _converse.emojipicker.browserStorage = _converse.createStore(id, storage);
_converse.emojipicker.fetch(); _converse.emojipicker.fetch();
} }
this.emoji_picker_view = new _converse.EmojiPickerView({'model': _converse.emojipicker}); this.emoji_picker_view = new _converse.EmojiPickerView({'model': _converse.emojipicker});
......
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
* @module converse-minimize * @module converse-minimize
*/ */
import "converse-chatview"; import "converse-chatview";
import BrowserStorage from "backbone.browserStorage";
import { Overview } from "backbone.overview"; import { Overview } from "backbone.overview";
import converse from "@converse/headless/converse-core"; import converse from "@converse/headless/converse-core";
import tpl_chatbox_minimize from "templates/chatbox_minimize.html"; import tpl_chatbox_minimize from "templates/chatbox_minimize.html";
...@@ -459,11 +458,11 @@ converse.plugins.add('converse-minimize', { ...@@ -459,11 +458,11 @@ converse.plugins.add('converse-minimize', {
initToggle () { initToggle () {
const storage = _converse.config.get('storage'), const storage = _converse.config.get('storage'),
id = `converse.minchatstoggle${_converse.bare_jid}`; id = `converse.minchatstoggle-${_converse.bare_jid}`;
this.toggleview = new _converse.MinimizedChatsToggleView({ this.toggleview = new _converse.MinimizedChatsToggleView({
'model': new _converse.MinimizedChatsToggle({'id': id}) 'model': new _converse.MinimizedChatsToggle({'id': id})
}); });
this.toggleview.model.browserStorage = new BrowserStorage[storage](id); this.toggleview.model.browserStorage = _converse.createStore(id, storage);
this.toggleview.model.fetch(); this.toggleview.model.fetch();
}, },
......
...@@ -13,7 +13,6 @@ import "converse-modal"; ...@@ -13,7 +13,6 @@ import "converse-modal";
import "backbone.vdomview"; import "backbone.vdomview";
import "formdata-polyfill"; import "formdata-polyfill";
import "@converse/headless/utils/muc"; import "@converse/headless/utils/muc";
import BrowserStorage from "backbone.browserStorage";
import { OrderedListView } from "backbone.overview"; import { OrderedListView } from "backbone.overview";
import converse from "@converse/headless/converse-core"; import converse from "@converse/headless/converse-core";
import tpl_add_chatroom_modal from "templates/add_chatroom_modal.html"; import tpl_add_chatroom_modal from "templates/add_chatroom_modal.html";
...@@ -124,11 +123,12 @@ converse.plugins.add('converse-muc-views', { ...@@ -124,11 +123,12 @@ converse.plugins.add('converse-muc-views', {
if (this.roomspanel && u.isInDOM(this.roomspanel.el)) { if (this.roomspanel && u.isInDOM(this.roomspanel.el)) {
return this.roomspanel; return this.roomspanel;
} }
const id = `converse.roomspanel${_converse.bare_jid}`;
this.roomspanel = new _converse.RoomsPanel({ this.roomspanel = new _converse.RoomsPanel({
'model': new (_converse.RoomsPanelModel.extend({ 'model': new (_converse.RoomsPanelModel.extend({
'id': `converse.roomspanel${_converse.bare_jid}`, // Required by web storage id,
'browserStorage': new BrowserStorage[_converse.config.get('storage')]( 'browserStorage': _converse.createStore(id, _converse.config.get('storage'))
`converse.roomspanel${_converse.bare_jid}`)
}))() }))()
}); });
this.roomspanel.model.fetch(); this.roomspanel.model.fetch();
...@@ -933,7 +933,7 @@ converse.plugins.add('converse-muc-views', { ...@@ -933,7 +933,7 @@ converse.plugins.add('converse-muc-views', {
_converse.router.navigate(''); _converse.router.navigate('');
} }
this.model.leave(); this.model.leave();
_converse.ChatBoxView.prototype.close.apply(this, arguments); return _converse.ChatBoxView.prototype.close.apply(this, arguments);
}, },
updateOccupantsToggle () { updateOccupantsToggle () {
...@@ -2200,7 +2200,7 @@ converse.plugins.add('converse-muc-views', { ...@@ -2200,7 +2200,7 @@ converse.plugins.add('converse-muc-views', {
* @method _converse.api.roomviews.close * @method _converse.api.roomviews.close
* @param {(String[]|String)} jids The JID or array of JIDs of the chatroom(s) * @param {(String[]|String)} jids The JID or array of JIDs of the chatroom(s)
*/ */
'close' (jids) { close (jids) {
let views; let views;
if (jids === undefined) { if (jids === undefined) {
views = _converse.chatboxviews; views = _converse.chatboxviews;
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
* @module converse-omemo * @module converse-omemo
*/ */
import "converse-profile"; import "converse-profile";
import BrowserStorage from "backbone.browserStorage";
import converse from "@converse/headless/converse-core"; import converse from "@converse/headless/converse-core";
import tpl_toolbar_omemo from "templates/toolbar_omemo.html"; import tpl_toolbar_omemo from "templates/toolbar_omemo.html";
...@@ -988,7 +987,7 @@ converse.plugins.add('converse-omemo', { ...@@ -988,7 +987,7 @@ converse.plugins.add('converse-omemo', {
this.devices = new _converse.Devices(); this.devices = new _converse.Devices();
const id = `converse.devicelist-${_converse.bare_jid}-${this.get('jid')}`; const id = `converse.devicelist-${_converse.bare_jid}-${this.get('jid')}`;
const storage = _converse.config.get('storage'); const storage = _converse.config.get('storage');
this.devices.browserStorage = new BrowserStorage[storage](id); this.devices.browserStorage = _converse.createStore(id, storage);
this.fetchDevices(); this.fetchDevices();
}, },
...@@ -1017,7 +1016,7 @@ converse.plugins.add('converse-omemo', { ...@@ -1017,7 +1016,7 @@ converse.plugins.add('converse-omemo', {
this._devices_promise = new Promise(resolve => { this._devices_promise = new Promise(resolve => {
this.devices.fetch({ this.devices.fetch({
'success': c => resolve(this.onDevicesFound(c)), 'success': c => resolve(this.onDevicesFound(c)),
'error': e => { _converse.log(e, Strophe.LogLevel.ERROR); resolve(); } 'error': (m, e) => { _converse.log(e, Strophe.LogLevel.ERROR); resolve(); }
}); });
}); });
} }
...@@ -1175,7 +1174,7 @@ converse.plugins.add('converse-omemo', { ...@@ -1175,7 +1174,7 @@ converse.plugins.add('converse-omemo', {
const storage = _converse.config.get('storage'), const storage = _converse.config.get('storage'),
id = `converse.omemosession-${_converse.bare_jid}`; id = `converse.omemosession-${_converse.bare_jid}`;
_converse.omemo_store = new _converse.OMEMOStore({'id': id}); _converse.omemo_store = new _converse.OMEMOStore({'id': id});
_converse.omemo_store.browserStorage = new BrowserStorage[storage](id); _converse.omemo_store.browserStorage = _converse.createStore(id, storage);
} }
return _converse.omemo_store.fetchSession(); return _converse.omemo_store.fetchSession();
} }
...@@ -1187,7 +1186,7 @@ converse.plugins.add('converse-omemo', { ...@@ -1187,7 +1186,7 @@ converse.plugins.add('converse-omemo', {
_converse.devicelists = new _converse.DeviceLists(); _converse.devicelists = new _converse.DeviceLists();
const storage = _converse.config.get('storage'), const storage = _converse.config.get('storage'),
id = `converse.devicelists-${_converse.bare_jid}`; id = `converse.devicelists-${_converse.bare_jid}`;
_converse.devicelists.browserStorage = new BrowserStorage[storage](id); _converse.devicelists.browserStorage = _converse.createStore(id, storage);
try { try {
await fetchOwnDevices(); await fetchOwnDevices();
......
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
* rooms in the "Rooms Panel" of the ControlBox. * rooms in the "Rooms Panel" of the ControlBox.
*/ */
import "@converse/headless/converse-muc"; import "@converse/headless/converse-muc";
import BrowserStorage from "backbone.browserStorage";
import { OrderedListView } from "backbone.overview"; import { OrderedListView } from "backbone.overview";
import converse from "@converse/headless/converse-core"; import converse from "@converse/headless/converse-core";
import tpl_rooms_list from "templates/rooms_list.html"; import tpl_rooms_list from "templates/rooms_list.html";
...@@ -175,7 +174,7 @@ converse.plugins.add('converse-roomslist', { ...@@ -175,7 +174,7 @@ converse.plugins.add('converse-roomslist', {
id = `converse.roomslist${_converse.bare_jid}`; id = `converse.roomslist${_converse.bare_jid}`;
this.list_model = new _converse.RoomsList({'id': id}); this.list_model = new _converse.RoomsList({'id': id});
this.list_model.browserStorage = new BrowserStorage[storage](id); this.list_model.browserStorage = _converse.createStore(id, storage);
this.list_model.fetch(); this.list_model.fetch();
this.render(); this.render();
this.sortAndPositionAllItems(); this.sortAndPositionAllItems();
...@@ -271,7 +270,7 @@ converse.plugins.add('converse-roomslist', { ...@@ -271,7 +270,7 @@ converse.plugins.add('converse-roomslist', {
id = `converse.open-rooms-{_converse.bare_jid}`, id = `converse.open-rooms-{_converse.bare_jid}`,
model = new _converse.OpenRooms(); model = new _converse.OpenRooms();
model.browserStorage = new BrowserStorage[storage](id); model.browserStorage = _converse.createStore(id, storage);
_converse.rooms_list_view = new _converse.RoomsListView({'model': model}); _converse.rooms_list_view = new _converse.RoomsListView({'model': model});
/** /**
* Triggered once the _converse.RoomsListView has been created and initialized. * Triggered once the _converse.RoomsListView has been created and initialized.
......
...@@ -10,7 +10,6 @@ import "@converse/headless/converse-chatboxes"; ...@@ -10,7 +10,6 @@ import "@converse/headless/converse-chatboxes";
import "@converse/headless/converse-roster"; import "@converse/headless/converse-roster";
import "converse-modal"; import "converse-modal";
import "formdata-polyfill"; import "formdata-polyfill";
import BrowserStorage from "backbone.browserStorage";
import { OrderedListView } from "backbone.overview"; import { OrderedListView } from "backbone.overview";
import SHA1 from 'strophe.js/src/sha1'; import SHA1 from 'strophe.js/src/sha1';
import converse from "@converse/headless/converse-core"; import converse from "@converse/headless/converse-core";
...@@ -807,7 +806,7 @@ converse.plugins.add('converse-rosterview', { ...@@ -807,7 +806,7 @@ converse.plugins.add('converse-rosterview', {
const model = new _converse.RosterFilter(); const model = new _converse.RosterFilter();
model.id = `_converse.rosterfilter${_converse.bare_jid}`; model.id = `_converse.rosterfilter${_converse.bare_jid}`;
const storage = _converse.config.get('storage'); const storage = _converse.config.get('storage');
model.browserStorage = new BrowserStorage[storage](this.filter.id); model.browserStorage = _converse.createStore(this.filter.id, storage);
this.filter_view = new _converse.RosterFilterView({'model': model}); this.filter_view = new _converse.RosterFilterView({'model': model});
this.listenTo(this.filter_view.model, 'change', this.updateFilter); this.listenTo(this.filter_view.model, 'change', this.updateFilter);
this.filter_view.model.fetch(); this.filter_view.model.fetch();
......
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
* Converse.js plugin which adds views for bookmarks specified in XEP-0048. * Converse.js plugin which adds views for bookmarks specified in XEP-0048.
*/ */
import "@converse/headless/converse-muc"; import "@converse/headless/converse-muc";
import BrowserStorage from "backbone.browserStorage";
import converse from "@converse/headless/converse-core"; import converse from "@converse/headless/converse-core";
const { Backbone, Strophe, $iq, sizzle, _ } = converse.env; const { Backbone, Strophe, $iq, sizzle, _ } = converse.env;
...@@ -110,7 +109,7 @@ converse.plugins.add('converse-bookmarks', { ...@@ -110,7 +109,7 @@ converse.plugins.add('converse-bookmarks', {
const storage = _converse.config.get('storage'); const storage = _converse.config.get('storage');
const cache_key = `converse.room-bookmarks${_converse.bare_jid}`; const cache_key = `converse.room-bookmarks${_converse.bare_jid}`;
this.fetched_flag = cache_key+'fetched'; this.fetched_flag = cache_key+'fetched';
this.browserStorage = new BrowserStorage[storage](cache_key); this.browserStorage = _converse.createStore(cache_key, storage);
}, },
async openBookmarkedRoom (bookmark) { async openBookmarkedRoom (bookmark) {
...@@ -126,7 +125,7 @@ converse.plugins.add('converse-bookmarks', { ...@@ -126,7 +125,7 @@ converse.plugins.add('converse-bookmarks', {
if (this.browserStorage.records.length > 0) { if (this.browserStorage.records.length > 0) {
this.fetch({ this.fetch({
'success': () => deferred.resolve(), 'success': () => deferred.resolve(),
'error': () => deferred.resolve() 'error': () => deferred.resolve()
}); });
} else if (! window.sessionStorage.getItem(this.fetched_flag)) { } else if (! window.sessionStorage.getItem(this.fetched_flag)) {
// There aren't any cached bookmarks and the // There aren't any cached bookmarks and the
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
* Converse.js plugin which add support for XEP-0206: XMPP Over BOSH * Converse.js plugin which add support for XEP-0206: XMPP Over BOSH
*/ */
import 'strophe.js/src/bosh'; import 'strophe.js/src/bosh';
import BrowserStorage from "backbone.browserStorage";
import converse from "./converse-core"; import converse from "./converse-core";
const { Backbone, Strophe } = converse.env; const { Backbone, Strophe } = converse.env;
...@@ -36,7 +35,7 @@ converse.plugins.add('converse-bosh', { ...@@ -36,7 +35,7 @@ converse.plugins.add('converse-bosh', {
const id = BOSH_SESSION_ID; const id = BOSH_SESSION_ID;
if (!_converse.bosh_session) { if (!_converse.bosh_session) {
_converse.bosh_session = new Backbone.Model({id}); _converse.bosh_session = new Backbone.Model({id});
_converse.bosh_session.browserStorage = new BrowserStorage.session(id); _converse.bosh_session.browserStorage = _converse.createStore(id, "session");
await new Promise(resolve => _converse.bosh_session.fetch({'success': resolve, 'error': resolve})); await new Promise(resolve => _converse.bosh_session.fetch({'success': resolve, 'error': resolve}));
} }
if (_converse.jid) { if (_converse.jid) {
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
import "./converse-emoji"; import "./converse-emoji";
import "./utils/form"; import "./utils/form";
import { get, isObject, isString, propertyOf } from "lodash"; import { get, isObject, isString, propertyOf } from "lodash";
import BrowserStorage from "backbone.browserStorage";
import converse from "./converse-core"; import converse from "./converse-core";
import filesize from "filesize"; import filesize from "filesize";
...@@ -328,7 +327,7 @@ converse.plugins.add('converse-chatboxes', { ...@@ -328,7 +327,7 @@ converse.plugins.add('converse-chatboxes', {
this.messages = new this.messagesCollection(); this.messages = new this.messagesCollection();
this.messages.chatbox = this; this.messages.chatbox = this;
const storage = _converse.config.get('storage'); const storage = _converse.config.get('storage');
this.messages.browserStorage = new BrowserStorage[storage](this.getMessagesCacheKey()); this.messages.browserStorage = _converse.createStore(this.getMessagesCacheKey(), storage);
this.listenTo(this.messages, 'change:upload', message => { this.listenTo(this.messages, 'change:upload', message => {
if (message.get('upload') === _converse.SUCCESS) { if (message.get('upload') === _converse.SUCCESS) {
_converse.api.send(this.createMessageStanza(message)); _converse.api.send(this.createMessageStanza(message));
...@@ -1147,8 +1146,8 @@ converse.plugins.add('converse-chatboxes', { ...@@ -1147,8 +1146,8 @@ converse.plugins.add('converse-chatboxes', {
return; return;
} }
const storage = _converse.config.get('storage'); const storage = _converse.config.get('storage');
this.browserStorage = new BrowserStorage[storage]( const id = `converse.chatboxes-${_converse.bare_jid}`;
`converse.chatboxes-${_converse.bare_jid}`); this.browserStorage = _converse.createStore(id, storage);
this.registerMessageHandler(); this.registerMessageHandler();
this.fetch({ this.fetch({
'add': true, 'add': true,
......
...@@ -354,6 +354,12 @@ _converse.isUniView = function () { ...@@ -354,6 +354,12 @@ _converse.isUniView = function () {
return _.includes(['mobile', 'fullscreen', 'embedded'], _converse.view_mode); return _.includes(['mobile', 'fullscreen', 'embedded'], _converse.view_mode);
}; };
_converse.createStore = function (id, storage) {
const s = storage ? storage : _converse.storage[_converse.config.get('storage')];
return new BrowserStorage[s](id);
}
_converse.router = new Backbone.Router(); _converse.router = new Backbone.Router();
function initPlugins () { function initPlugins () {
...@@ -411,7 +417,7 @@ function initClientConfig () { ...@@ -411,7 +417,7 @@ function initClientConfig () {
'trusted': _converse.trusted && true || false, 'trusted': _converse.trusted && true || false,
'storage': _converse.trusted ? 'local' : 'session' 'storage': _converse.trusted ? 'local' : 'session'
}); });
_converse.config.browserStorage = new BrowserStorage.session(id); _converse.config.browserStorage = _converse.createStore(id, "session");
_converse.config.fetch(); _converse.config.fetch();
/** /**
* Triggered once the XMPP-client configuration has been initialized. * Triggered once the XMPP-client configuration has been initialized.
...@@ -641,7 +647,7 @@ async function initSession (jid) { ...@@ -641,7 +647,7 @@ async function initSession (jid) {
const id = `converse.session-${bare_jid}`; const id = `converse.session-${bare_jid}`;
if (!_converse.session || _converse.session.get('id') !== id) { if (!_converse.session || _converse.session.get('id') !== id) {
_converse.session = new Backbone.Model({id}); _converse.session = new Backbone.Model({id});
_converse.session.browserStorage = new BrowserStorage.session(id); _converse.session.browserStorage = _converse.createStore(id, "session");
await new Promise(r => _converse.session.fetch({'success': r, 'error': r})); await new Promise(r => _converse.session.fetch({'success': r, 'error': r}));
if (_converse.session.get('active')) { if (_converse.session.get('active')) {
_converse.session.clear(); _converse.session.clear();
...@@ -1199,7 +1205,7 @@ _converse.initialize = async function (settings, callback) { ...@@ -1199,7 +1205,7 @@ _converse.initialize = async function (settings, callback) {
} else { } else {
const id = `converse.xmppstatus-${_converse.bare_jid}`; const id = `converse.xmppstatus-${_converse.bare_jid}`;
_converse.xmppstatus = new this.XMPPStatus({'id': id}); _converse.xmppstatus = new this.XMPPStatus({'id': id});
_converse.xmppstatus.browserStorage = new BrowserStorage.session(id); _converse.xmppstatus.browserStorage = _converse.createStore(id, "session");
_converse.xmppstatus.fetch({ _converse.xmppstatus.fetch({
'success': () => _converse.onStatusInitialized(reconnecting), 'success': () => _converse.onStatusInitialized(reconnecting),
'error': () => _converse.onStatusInitialized(reconnecting), 'error': () => _converse.onStatusInitialized(reconnecting),
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
* @description * @description
* Converse plugin which add support for XEP-0030: Service Discovery * Converse plugin which add support for XEP-0030: Service Discovery
*/ */
import BrowserStorage from "backbone.browserStorage";
import converse from "./converse-core"; import converse from "./converse-core";
import sizzle from "sizzle"; import sizzle from "sizzle";
...@@ -44,32 +43,27 @@ converse.plugins.add('converse-disco', { ...@@ -44,32 +43,27 @@ converse.plugins.add('converse-disco', {
this.waitUntilFeaturesDiscovered = utils.getResolveablePromise(); this.waitUntilFeaturesDiscovered = utils.getResolveablePromise();
this.dataforms = new _converse.Collection(); this.dataforms = new _converse.Collection();
this.dataforms.browserStorage = new BrowserStorage.session( let id = `converse.dataforms-${this.get('jid')}`;
`converse.dataforms-${this.get('jid')}` this.dataforms.browserStorage = _converse.createStore(id, 'session');
);
this.features = new _converse.Collection(); this.features = new _converse.Collection();
this.features.browserStorage = new BrowserStorage.session( id = `converse.features-${this.get('jid')}`;
`converse.features-${this.get('jid')}` this.features.browserStorage = _converse.createStore(id, 'session');
);
this.listenTo(this.features, 'add', this.onFeatureAdded) this.listenTo(this.features, 'add', this.onFeatureAdded)
this.fields = new _converse.Collection(); this.fields = new _converse.Collection();
this.fields.browserStorage = new BrowserStorage.session( id = `converse.fields-${this.get('jid')}`;
`converse.fields-${this.get('jid')}` this.fields.browserStorage = _converse.createStore(id, 'session');
);
this.listenTo(this.fields, 'add', this.onFieldAdded) this.listenTo(this.fields, 'add', this.onFieldAdded)
this.identities = new _converse.Collection(); this.identities = new _converse.Collection();
this.identities.browserStorage = new BrowserStorage.session( id = `converse.identities-${this.get('jid')}`;
`converse.identities-${this.get('jid')}` this.identities.browserStorage = _converse.createStore(id, 'session');
);
this.fetchFeatures(options); this.fetchFeatures(options);
this.items = new _converse.DiscoEntities(); this.items = new _converse.DiscoEntities();
this.items.browserStorage = new BrowserStorage.session( id = `converse.disco-items-${this.get('jid')}`;
`converse.disco-items-${this.get('jid')}` this.items.browserStorage = _converse.createStore(id, 'session');
);
this.items.fetch(); this.items.fetch();
}, },
...@@ -267,7 +261,7 @@ converse.plugins.add('converse-disco', { ...@@ -267,7 +261,7 @@ converse.plugins.add('converse-disco', {
const id = `converse.stream-features-${bare_jid}`; const id = `converse.stream-features-${bare_jid}`;
if (!_converse.stream_features || _converse.stream_features.browserStorage.id !== id) { if (!_converse.stream_features || _converse.stream_features.browserStorage.id !== id) {
_converse.stream_features = new _converse.Collection(); _converse.stream_features = new _converse.Collection();
_converse.stream_features.browserStorage = new BrowserStorage.session(id); _converse.stream_features.browserStorage = _converse.createStore(id, "session");
_converse.stream_features.fetch({ _converse.stream_features.fetch({
success (collection) { success (collection) {
if (collection.length === 0 && _converse.connection.features) { if (collection.length === 0 && _converse.connection.features) {
...@@ -331,10 +325,8 @@ converse.plugins.add('converse-disco', { ...@@ -331,10 +325,8 @@ converse.plugins.add('converse-disco', {
_converse.connection.addHandler(onDiscoInfoRequest, Strophe.NS.DISCO_INFO, 'iq', 'get', null, null); _converse.connection.addHandler(onDiscoInfoRequest, Strophe.NS.DISCO_INFO, 'iq', 'get', null, null);
_converse.disco_entities = new _converse.DiscoEntities(); _converse.disco_entities = new _converse.DiscoEntities();
_converse.disco_entities.browserStorage = new BrowserStorage.session( const id = `converse.disco-entities-${_converse.bare_jid}`;
`converse.disco-entities-${_converse.bare_jid}` _converse.disco_entities.browserStorage = _converse.createStore(id, 'session');
);
const collection = await _converse.disco_entities.fetchEntities(); const collection = await _converse.disco_entities.fetchEntities();
if (collection.length === 0 || !collection.get(_converse.domain)) { if (collection.length === 0 || !collection.get(_converse.domain)) {
// If we don't have an entity for our own XMPP server, // If we don't have an entity for our own XMPP server,
......
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
import "./converse-disco"; import "./converse-disco";
import "./converse-emoji"; import "./converse-emoji";
import "./utils/muc"; import "./utils/muc";
import BrowserStorage from "backbone.browserStorage";
import converse from "./converse-core"; import converse from "./converse-core";
import u from "./utils/form"; import u from "./utils/form";
...@@ -488,14 +487,13 @@ converse.plugins.add('converse-muc', { ...@@ -488,14 +487,13 @@ converse.plugins.add('converse-muc', {
this.features = new Backbone.Model( this.features = new Backbone.Model(
_.assign({id}, _.zipObject(converse.ROOM_FEATURES, converse.ROOM_FEATURES.map(_.stubFalse))) _.assign({id}, _.zipObject(converse.ROOM_FEATURES, converse.ROOM_FEATURES.map(_.stubFalse)))
); );
this.features.browserStorage = new BrowserStorage.session(id); this.features.browserStorage = _converse.createStore(id, "session");
}, },
initOccupants () { initOccupants () {
this.occupants = new _converse.ChatRoomOccupants(); this.occupants = new _converse.ChatRoomOccupants();
this.occupants.browserStorage = new BrowserStorage.session( const id = `converse.occupants-${_converse.bare_jid}${this.get('jid')}`;
`converse.occupants-${_converse.bare_jid}${this.get('jid')}` this.occupants.browserStorage = _converse.createStore(id, 'session');
);
this.occupants.chatroom = this; this.occupants.chatroom = this;
this.occupants.fetched = new Promise(resolve => { this.occupants.fetched = new Promise(resolve => {
this.occupants.fetch({ this.occupants.fetch({
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
/** /**
* @module converse-roster * @module converse-roster
*/ */
import BrowserStorage from "backbone.browserStorage";
import converse from "@converse/headless/converse-core"; import converse from "@converse/headless/converse-core";
const { Backbone, Strophe, $iq, $pres, dayjs, sizzle, _ } = converse.env; const { Backbone, Strophe, $iq, $pres, dayjs, sizzle, _ } = converse.env;
...@@ -68,18 +67,18 @@ converse.plugins.add('converse-roster', { ...@@ -68,18 +67,18 @@ converse.plugins.add('converse-roster', {
_converse.initRoster = function () { _converse.initRoster = function () {
const storage = _converse.config.get('storage'); const storage = _converse.config.get('storage');
_converse.roster = new _converse.RosterContacts(); _converse.roster = new _converse.RosterContacts();
_converse.roster.browserStorage = new BrowserStorage[storage]( let id = `converse.contacts-${_converse.bare_jid}`;
`converse.contacts-${_converse.bare_jid}`); _converse.roster.browserStorage = _converse.createStore(id, storage);
_converse.roster.data = new Backbone.Model(); _converse.roster.data = new Backbone.Model();
const id = `converse-roster-model-${_converse.bare_jid}`; id = `converse-roster-model-${_converse.bare_jid}`;
_converse.roster.data.id = id; _converse.roster.data.id = id;
_converse.roster.data.browserStorage = new BrowserStorage[storage](id); _converse.roster.data.browserStorage = _converse.createStore(id, storage);
_converse.roster.data.fetch(); _converse.roster.data.fetch();
id = `converse.roster.groups${_converse.bare_jid}`;
_converse.rostergroups = new _converse.RosterGroups(); _converse.rostergroups = new _converse.RosterGroups();
_converse.rostergroups.browserStorage = new BrowserStorage[storage]( _converse.rostergroups.browserStorage = _converse.createStore(id, storage);
`converse.roster.groups${_converse.bare_jid}`);
/** /**
* Triggered once the `_converse.RosterContacts` and `_converse.RosterGroups` have * Triggered once the `_converse.RosterContacts` and `_converse.RosterGroups` have
* been created, but not yet populated with data. * been created, but not yet populated with data.
...@@ -152,7 +151,7 @@ converse.plugins.add('converse-roster', { ...@@ -152,7 +151,7 @@ converse.plugins.add('converse-roster', {
initialize () { initialize () {
this.resources = new Resources(); this.resources = new Resources();
const id = `converse.identities-${this.get('jid')}`; const id = `converse.identities-${this.get('jid')}`;
this.resources.browserStorage = new BrowserStorage.session(id); this.resources.browserStorage = _converse.createStore(id, "session");
this.listenTo(this.resources, 'update', this.onResourcesChanged); this.listenTo(this.resources, 'update', this.onResourcesChanged);
this.listenTo(this.resources, 'change', this.onResourcesChanged); this.listenTo(this.resources, 'change', this.onResourcesChanged);
}, },
...@@ -446,7 +445,7 @@ converse.plugins.add('converse-roster', { ...@@ -446,7 +445,7 @@ converse.plugins.add('converse-roster', {
'add': true, 'add': true,
'silent': true, 'silent': true,
'success': resolve, 'success': resolve,
'error': reject 'error': (m, e) => reject(e)
}); });
}); });
} catch (e) { } catch (e) {
...@@ -965,7 +964,7 @@ converse.plugins.add('converse-roster', { ...@@ -965,7 +964,7 @@ converse.plugins.add('converse-roster', {
} else { } else {
_converse.presences = new _converse.Presences(); _converse.presences = new _converse.Presences();
const id = `converse.presences-${_converse.bare_jid}`; const id = `converse.presences-${_converse.bare_jid}`;
_converse.presences.browserStorage = new BrowserStorage.session(id); _converse.presences.browserStorage = _converse.createStore(id, "session");
// We might be continuing an existing session, so we fetch // We might be continuing an existing session, so we fetch
// cached presence data. // cached presence data.
_converse.presences.fetch(); _converse.presences.fetch();
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
/** /**
* @module converse-vcard * @module converse-vcard
*/ */
import BrowserStorage from "backbone.browserStorage";
import converse from "./converse-core"; import converse from "./converse-core";
import tpl_vcard from "./templates/vcard.html"; import tpl_vcard from "./templates/vcard.html";
...@@ -160,7 +159,7 @@ converse.plugins.add('converse-vcard', { ...@@ -160,7 +159,7 @@ converse.plugins.add('converse-vcard', {
_converse.initVCardCollection = function () { _converse.initVCardCollection = function () {
_converse.vcards = new _converse.VCards(); _converse.vcards = new _converse.VCards();
const id = `${_converse.bare_jid}-converse.vcards`; const id = `${_converse.bare_jid}-converse.vcards`;
_converse.vcards.browserStorage = new BrowserStorage[_converse.config.get('storage')](id); _converse.vcards.browserStorage = _converse.createStore(id, _converse.config.get('storage'));
_converse.vcards.fetch(); _converse.vcards.fetch();
} }
_converse.api.listen.on('afterResourceBinding', _converse.initVCardCollection); _converse.api.listen.on('afterResourceBinding', _converse.initVCardCollection);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment