Commit 9ed2ad63 authored by JC Brand's avatar JC Brand

Store whether this is a trusted device in _converse.session

So that it persists across page loads. Otherwise storage falls back to
the default, causing records to be in both local- and sessionStorage.

Additionally, update singleton models to have the 'id' available as a getter.

Otherwise multiple records gets stored in browserStorage, causing random
results being returned.
parent 4141a223
...@@ -68287,9 +68287,12 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_ ...@@ -68287,9 +68287,12 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
this.on('add', _.flow(this.openBookmarkedRoom, this.markRoomAsBookmarked)); this.on('add', _.flow(this.openBookmarkedRoom, this.markRoomAsBookmarked));
this.on('remove', this.markRoomAsUnbookmarked, this); this.on('remove', this.markRoomAsUnbookmarked, this);
this.on('remove', this.sendBookmarkStanza, this); this.on('remove', this.sendBookmarkStanza, this);
const cache_key = `converse.room-bookmarks${_converse.bare_jid}`;
const storage = _converse.session.get('storage'),
cache_key = `converse.room-bookmarks${_converse.bare_jid}`;
this.fetched_flag = b64_sha1(cache_key + 'fetched'); this.fetched_flag = b64_sha1(cache_key + 'fetched');
this.browserStorage = new Backbone.BrowserStorage[_converse.storage](b64_sha1(cache_key)); this.browserStorage = new Backbone.BrowserStorage[storage](b64_sha1(cache_key));
}, },
openBookmarkedRoom(bookmark) { openBookmarkedRoom(bookmark) {
...@@ -68497,10 +68500,13 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_ ...@@ -68497,10 +68500,13 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
_converse.chatboxes.on('remove', this.renderBookmarkListElement, this); _converse.chatboxes.on('remove', this.renderBookmarkListElement, this);
const cachekey = `converse.room-bookmarks${_converse.bare_jid}-list-model`; const storage = _converse.session.get('storage'),
this.list_model = new _converse.BookmarksList(); id = b64_sha1(`converse.room-bookmarks${_converse.bare_jid}-list-model`);
this.list_model.id = cachekey;
this.list_model.browserStorage = new Backbone.BrowserStorage[_converse.storage](b64_sha1(cachekey)); this.list_model = new _converse.BookmarksList({
'id': id
});
this.list_model.browserStorage = new Backbone.BrowserStorage[storage](id);
this.list_model.fetch(); this.list_model.fetch();
this.render(); this.render();
this.sortAndPositionAllItems(); this.sortAndPositionAllItems();
...@@ -69033,7 +69039,10 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_ ...@@ -69033,7 +69039,10 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
}); });
this.messages = new _converse.Messages(); this.messages = new _converse.Messages();
this.messages.browserStorage = new Backbone.BrowserStorage[_converse.storage](b64_sha1(`converse.messages${this.get('jid')}${_converse.bare_jid}`));
const storage = _converse.session.get('storage');
this.messages.browserStorage = new Backbone.BrowserStorage[storage](b64_sha1(`converse.messages${this.get('jid')}${_converse.bare_jid}`));
this.messages.chatbox = this; this.messages.chatbox = this;
this.messages.on('change:upload', message => { this.messages.on('change:upload', message => {
if (message.get('upload') === _converse.SUCCESS) { if (message.get('upload') === _converse.SUCCESS) {
...@@ -69996,11 +70005,7 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_ ...@@ -69996,11 +70005,7 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
'scroll_position': 0 'scroll_position': 0
}, },
initialize() { initialize() {}
const id = `converse.emoji-${_converse.bare_jid}`;
this.id = id;
this.browserStorage = new Backbone.BrowserStorage[_converse.storage](id);
}
}); });
_converse.EmojiPickerView = Backbone.VDOMView.extend({ _converse.EmojiPickerView = Backbone.VDOMView.extend({
...@@ -70957,7 +70962,13 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_ ...@@ -70957,7 +70962,13 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
createEmojiPicker() { createEmojiPicker() {
if (_.isUndefined(_converse.emojipicker)) { if (_.isUndefined(_converse.emojipicker)) {
_converse.emojipicker = new _converse.EmojiPicker(); const storage = _converse.session.get('storage'),
id = `converse.emoji-${_converse.bare_jid}`;
_converse.emojipicker = new _converse.EmojiPicker({
'id': id
});
_converse.emojipicker.browserStorage = new Backbone.BrowserStorage[storage](id);
_converse.emojipicker.fetch(); _converse.emojipicker.fetch();
} }
...@@ -71725,8 +71736,12 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_ ...@@ -71725,8 +71736,12 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
} }
const form_data = new FormData(ev.target); const form_data = new FormData(ev.target);
_converse.trusted = form_data.get('trusted');
_converse.storage = form_data.get('trusted') ? 'local' : 'session'; _converse.session.save({
'trusted': form_data.get('trusted') && true || false,
'storage': form_data.get('trusted') ? 'local' : 'session'
});
let jid = form_data.get('jid'); let jid = form_data.get('jid');
if (_converse.locked_domain) { if (_converse.locked_domain) {
...@@ -71853,7 +71868,7 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_ ...@@ -71853,7 +71868,7 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
}); });
_converse.on('clearSession', () => { _converse.on('clearSession', () => {
if (_converse.trusted) { if (_converse.session.get('trusted')) {
const chatboxes = _.get(_converse, 'chatboxes', null); const chatboxes = _.get(_converse, 'chatboxes', null);
if (!_.isNil(chatboxes)) { if (!_.isNil(chatboxes)) {
...@@ -72087,7 +72102,6 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_ ...@@ -72087,7 +72102,6 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
rid: undefined, rid: undefined,
root: window.document, root: window.document,
sid: undefined, sid: undefined,
storage: 'session',
strict_plugin_dependencies: false, strict_plugin_dependencies: false,
trusted: true, trusted: true,
view_mode: 'overlayed', view_mode: 'overlayed',
...@@ -72567,23 +72581,25 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_ ...@@ -72567,23 +72581,25 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
if (reconnecting) { if (reconnecting) {
_converse.onStatusInitialized(reconnecting); _converse.onStatusInitialized(reconnecting);
} else { } else {
this.xmppstatus = new this.XMPPStatus(); const id = `converse.xmppstatus-${_converse.bare_jid}`;
const id = b64_sha1(`converse.xmppstatus-${_converse.bare_jid}`); this.xmppstatus = new this.XMPPStatus({
this.xmppstatus.id = id; // Appears to be necessary for backbone.browserStorage 'id': id
});
this.xmppstatus.browserStorage = new Backbone.BrowserStorage[_converse.storage](id); this.xmppstatus.browserStorage = new Backbone.BrowserStorage.session(id);
this.xmppstatus.fetch({ this.xmppstatus.fetch({
success: _.partial(_converse.onStatusInitialized, reconnecting), 'success': _.partial(_converse.onStatusInitialized, reconnecting),
error: _.partial(_converse.onStatusInitialized, reconnecting) 'error': _.partial(_converse.onStatusInitialized, reconnecting)
}); });
} }
}; };
this.initSession = function () { this.initSession = function () {
_converse.session = new Backbone.Model();
const id = b64_sha1('converse.bosh-session'); const id = b64_sha1('converse.bosh-session');
_converse.session.id = id; // Appears to be necessary for backbone.browserStorage _converse.session = new Backbone.Model({
'id': id,
'trusted': _converse.trusted && true || false,
'storage': _converse.trusted ? 'local' : 'session'
});
_converse.session.browserStorage = new Backbone.BrowserStorage.session(id); _converse.session.browserStorage = new Backbone.BrowserStorage.session(id);
_converse.session.fetch(); _converse.session.fetch();
...@@ -72592,7 +72608,7 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_ ...@@ -72592,7 +72608,7 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
}; };
this.clearSession = function () { this.clearSession = function () {
if (!_converse.trusted) { if (!_converse.session.get('trusted')) {
window.localStorage.clear(); window.localStorage.clear();
window.sessionStorage.clear(); window.sessionStorage.clear();
} else if (!_.isUndefined(this.session) && this.session.browserStorage) { } else if (!_.isUndefined(this.session) && this.session.browserStorage) {
...@@ -72731,11 +72747,13 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_ ...@@ -72731,11 +72747,13 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
} }
}; };
this.setUserJid = function () { this.setUserJID = function () {
_converse.jid = _converse.connection.jid; _converse.jid = _converse.connection.jid;
_converse.bare_jid = Strophe.getBareJidFromJid(_converse.connection.jid); _converse.bare_jid = Strophe.getBareJidFromJid(_converse.connection.jid);
_converse.resource = Strophe.getResourceFromJid(_converse.connection.jid); _converse.resource = Strophe.getResourceFromJid(_converse.connection.jid);
_converse.domain = Strophe.getDomainFromJid(_converse.connection.jid); _converse.domain = Strophe.getDomainFromJid(_converse.connection.jid);
_converse.emit('setUserJID');
}; };
this.onConnected = function (reconnecting) { this.onConnected = function (reconnecting) {
...@@ -72745,9 +72763,7 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_ ...@@ -72745,9 +72763,7 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
_converse.connection.flush(); // Solves problem of returned PubSub BOSH response not received by browser _converse.connection.flush(); // Solves problem of returned PubSub BOSH response not received by browser
_converse.setUserJid(); _converse.setUserJID();
_converse.initSession();
_converse.enableCarbons(); _converse.enableCarbons();
...@@ -73120,6 +73136,8 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_ ...@@ -73120,6 +73136,8 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
function finishInitialization() { function finishInitialization() {
_converse.initPlugins(); _converse.initPlugins();
_converse.initSession();
_converse.initConnection(); _converse.initConnection();
_converse.setUpXMLLogging(); _converse.setUpXMLLogging();
...@@ -73640,7 +73658,7 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_ ...@@ -73640,7 +73658,7 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
}).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL)); }).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
} }
_converse.api.listen.on('sessionInitialized', initStreamFeatures); _converse.api.listen.on('setUserJID', initStreamFeatures);
_converse.api.listen.on('reconnected', initializeDisco); _converse.api.listen.on('reconnected', initializeDisco);
...@@ -75958,13 +75976,15 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_ ...@@ -75958,13 +75976,15 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
}, },
initToggle() { initToggle() {
const storage = _converse.session.get('storage'),
id = b64_sha1(`converse.minchatstoggle${_converse.bare_jid}`);
this.toggleview = new _converse.MinimizedChatsToggleView({ this.toggleview = new _converse.MinimizedChatsToggleView({
model: new _converse.MinimizedChatsToggle() 'model': new _converse.MinimizedChatsToggle({
'id': id
})
}); });
const id = b64_sha1(`converse.minchatstoggle${_converse.bare_jid}`); this.toggleview.model.browserStorage = new Backbone.BrowserStorage[storage](id);
this.toggleview.model.id = id; // Appears to be necessary for backbone.browserStorage
this.toggleview.model.browserStorage = new Backbone.BrowserStorage[_converse.storage](id);
this.toggleview.model.fetch(); this.toggleview.model.fetch();
}, },
...@@ -76305,7 +76325,7 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_ ...@@ -76305,7 +76325,7 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
'model': new (_converse.RoomsPanelModel.extend({ 'model': new (_converse.RoomsPanelModel.extend({
'id': b64_sha1(`converse.roomspanel${_converse.bare_jid}`), 'id': b64_sha1(`converse.roomspanel${_converse.bare_jid}`),
// Required by sessionStorage // Required by sessionStorage
'browserStorage': new Backbone.BrowserStorage[_converse.storage](b64_sha1(`converse.roomspanel${_converse.bare_jid}`)) 'browserStorage': new Backbone.BrowserStorage[_converse.session.get('storage')](b64_sha1(`converse.roomspanel${_converse.bare_jid}`))
}))() }))()
}); });
this.roomspanel.model.fetch(); this.roomspanel.model.fetch();
...@@ -81693,8 +81713,6 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_ ...@@ -81693,8 +81713,6 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
}, },
initialize() { initialize() {
this.browserStorage = new Backbone.BrowserStorage[_converse.storage](b64_sha1(`converse.open-rooms-{_converse.bare_jid}`));
_converse.chatboxes.on('add', this.onChatBoxAdded, this); _converse.chatboxes.on('add', this.onChatBoxAdded, this);
_converse.chatboxes.on('change:hidden', this.onChatBoxChanged, this); _converse.chatboxes.on('change:hidden', this.onChatBoxChanged, this);
...@@ -81820,10 +81838,14 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_ ...@@ -81820,10 +81838,14 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
Backbone.OrderedListView.prototype.initialize.apply(this, arguments); Backbone.OrderedListView.prototype.initialize.apply(this, arguments);
this.model.on('add', this.showOrHide, this); this.model.on('add', this.showOrHide, this);
this.model.on('remove', this.showOrHide, this); this.model.on('remove', this.showOrHide, this);
const cachekey = `converse.roomslist${_converse.bare_jid}`;
this.list_model = new _converse.RoomsList(); const storage = _converse.session.get('storage'),
this.list_model.id = cachekey; id = b64_sha1(`converse.roomslist${_converse.bare_jid}`);
this.list_model.browserStorage = new Backbone.BrowserStorage[_converse.storage](b64_sha1(cachekey));
this.list_model = new _converse.RoomsList({
'id': id
});
this.list_model.browserStorage = new Backbone.BrowserStorage[storage](id);
this.list_model.fetch(); this.list_model.fetch();
this.render(); this.render();
this.sortAndPositionAllItems(); this.sortAndPositionAllItems();
...@@ -81928,8 +81950,13 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_ ...@@ -81928,8 +81950,13 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
}); });
const initRoomsListView = function initRoomsListView() { const initRoomsListView = function initRoomsListView() {
const storage = _converse.session.get('storage'),
id = b64_sha1(`converse.open-rooms-{_converse.bare_jid}`),
model = new _converse.OpenRooms();
model.browserStorage = new Backbone.BrowserStorage[storage](id);
_converse.rooms_list_view = new _converse.RoomsListView({ _converse.rooms_list_view = new _converse.RoomsListView({
'model': new _converse.OpenRooms() 'model': model
}); });
}; };
...@@ -82026,19 +82053,21 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_ ...@@ -82026,19 +82053,21 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
_converse.initRoster = function () { _converse.initRoster = function () {
/* Initialize the Bakcbone collections that represent the contats /* Initialize the Bakcbone collections that represent the contats
* roster and the roster groups. * roster and the roster groups.
*/ */
const storage = _converse.session.get('storage');
_converse.roster = new _converse.RosterContacts(); _converse.roster = new _converse.RosterContacts();
_converse.roster.browserStorage = new Backbone.BrowserStorage[_converse.storage](b64_sha1(`converse.contacts-${_converse.bare_jid}`)); _converse.roster.browserStorage = new Backbone.BrowserStorage[storage](b64_sha1(`converse.contacts-${_converse.bare_jid}`));
_converse.roster.data = new Backbone.Model(); _converse.roster.data = new Backbone.Model();
const id = b64_sha1(`converse-roster-model-${_converse.bare_jid}`); const id = b64_sha1(`converse-roster-model-${_converse.bare_jid}`);
_converse.roster.data.id = id; _converse.roster.data.id = id;
_converse.roster.data.browserStorage = new Backbone.BrowserStorage[_converse.storage](id); _converse.roster.data.browserStorage = new Backbone.BrowserStorage[storage](id);
_converse.roster.data.fetch(); _converse.roster.data.fetch();
_converse.rostergroups = new _converse.RosterGroups(); _converse.rostergroups = new _converse.RosterGroups();
_converse.rostergroups.browserStorage = new Backbone.BrowserStorage[_converse.storage](b64_sha1(`converse.roster.groups${_converse.bare_jid}`)); _converse.rostergroups.browserStorage = new Backbone.BrowserStorage[storage](b64_sha1(`converse.roster.groups${_converse.bare_jid}`));
_converse.emit('rosterInitialized'); _converse.emit('rosterInitialized');
}; };
...@@ -84376,12 +84405,13 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_ ...@@ -84376,12 +84405,13 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
_converse.initVCardCollection = function () { _converse.initVCardCollection = function () {
_converse.vcards = new _converse.VCards(); _converse.vcards = new _converse.VCards();
_converse.vcards.browserStorage = new Backbone.BrowserStorage[_converse.storage](b64_sha1(`converse.vcards`)); const id = b64_sha1(`converse.vcards`);
_converse.vcards.browserStorage = new Backbone.BrowserStorage[_converse.session.get('storage')](id);
_converse.vcards.fetch(); _converse.vcards.fetch();
}; };
_converse.api.listen.on('sessionInitialized', _converse.initVCardCollection); _converse.api.listen.on('setUserJID', _converse.initVCardCollection);
_converse.on('addClientFeatures', () => { _converse.on('addClientFeatures', () => {
_converse.api.disco.own.features.add(Strophe.NS.VCARD); _converse.api.disco.own.features.add(Strophe.NS.VCARD);
...@@ -86408,7 +86438,7 @@ __e(o.__('password')) + ...@@ -86408,7 +86438,7 @@ __e(o.__('password')) +
'">\n </div>\n '; '">\n </div>\n ';
} ; } ;
__p += '\n <div class="form-group form-check">\n <input id="converse-login-trusted" type="checkbox" class="form-check-input" name="trusted" '; __p += '\n <div class="form-group form-check">\n <input id="converse-login-trusted" type="checkbox" class="form-check-input" name="trusted" ';
if (o._converse.trusted) { ; if (o._converse.session.get('trusted')) { ;
__p += ' checked="checked" '; __p += ' checked="checked" ';
} ; } ;
__p += '>\n <label for="converse-login-trusted" class="form-check-label">' + __p += '>\n <label for="converse-login-trusted" class="form-check-label">' +
...@@ -29,15 +29,15 @@ ...@@ -29,15 +29,15 @@
spyOn(cbview.loginpanel, 'connect'); spyOn(cbview.loginpanel, 'connect');
cbview.delegateEvents(); cbview.delegateEvents();
expect(_converse.storage).toBe('session'); expect(_converse.session.get('storage')).toBe('local');
cbview.el.querySelector('input[type="submit"]').click(); cbview.el.querySelector('input[type="submit"]').click();
expect(_converse.storage).toBe('local'); expect(_converse.session.get('storage')).toBe('local');
expect(cbview.loginpanel.connect).toHaveBeenCalled(); expect(cbview.loginpanel.connect).toHaveBeenCalled();
checkbox.click(); checkbox.click();
cbview.el.querySelector('input[type="submit"]').click(); cbview.el.querySelector('input[type="submit"]').click();
expect(_converse.storage).toBe('session'); expect(_converse.session.get('storage')).toBe('session');
done(); done();
}); });
})); }));
...@@ -51,7 +51,7 @@ ...@@ -51,7 +51,7 @@
function (done, _converse) { function (done, _converse) {
test_utils.waitUntil(() => _converse.chatboxviews.get('controlbox')) test_utils.waitUntil(() => _converse.chatboxviews.get('controlbox'))
.then(function () { .then(() => {
var cbview = _converse.chatboxviews.get('controlbox'); var cbview = _converse.chatboxviews.get('controlbox');
test_utils.openControlBox(); test_utils.openControlBox();
const checkboxes = cbview.el.querySelectorAll('input[type="checkbox"]'); const checkboxes = cbview.el.querySelectorAll('input[type="checkbox"]');
...@@ -67,14 +67,14 @@ ...@@ -67,14 +67,14 @@
spyOn(cbview.loginpanel, 'connect'); spyOn(cbview.loginpanel, 'connect');
expect(_converse.storage).toBe('session'); expect(_converse.session.get('storage')).toBe('session');
cbview.el.querySelector('input[type="submit"]').click(); cbview.el.querySelector('input[type="submit"]').click();
expect(_converse.storage).toBe('session'); expect(_converse.session.get('storage')).toBe('session');
expect(cbview.loginpanel.connect).toHaveBeenCalled(); expect(cbview.loginpanel.connect).toHaveBeenCalled();
checkbox.click(); checkbox.click();
cbview.el.querySelector('input[type="submit"]').click(); cbview.el.querySelector('input[type="submit"]').click();
expect(_converse.storage).toBe('local'); expect(_converse.session.get('storage')).toBe('local');
done(); done();
}); });
})); }));
......
...@@ -250,9 +250,10 @@ ...@@ -250,9 +250,10 @@
this.on('remove', this.markRoomAsUnbookmarked, this); this.on('remove', this.markRoomAsUnbookmarked, this);
this.on('remove', this.sendBookmarkStanza, this); this.on('remove', this.sendBookmarkStanza, this);
const cache_key = `converse.room-bookmarks${_converse.bare_jid}`; const storage = _converse.session.get('storage'),
cache_key = `converse.room-bookmarks${_converse.bare_jid}`;
this.fetched_flag = b64_sha1(cache_key+'fetched'); this.fetched_flag = b64_sha1(cache_key+'fetched');
this.browserStorage = new Backbone.BrowserStorage[_converse.storage](b64_sha1(cache_key)); this.browserStorage = new Backbone.BrowserStorage[storage](b64_sha1(cache_key));
}, },
openBookmarkedRoom (bookmark) { openBookmarkedRoom (bookmark) {
...@@ -443,12 +444,10 @@ ...@@ -443,12 +444,10 @@
_converse.chatboxes.on('add', this.renderBookmarkListElement, this); _converse.chatboxes.on('add', this.renderBookmarkListElement, this);
_converse.chatboxes.on('remove', this.renderBookmarkListElement, this); _converse.chatboxes.on('remove', this.renderBookmarkListElement, this);
const cachekey = `converse.room-bookmarks${_converse.bare_jid}-list-model`; const storage = _converse.session.get('storage'),
this.list_model = new _converse.BookmarksList(); id = b64_sha1(`converse.room-bookmarks${_converse.bare_jid}-list-model`);
this.list_model.id = cachekey; this.list_model = new _converse.BookmarksList({'id': id});
this.list_model.browserStorage = new Backbone.BrowserStorage[_converse.storage]( this.list_model.browserStorage = new Backbone.BrowserStorage[storage](id);
b64_sha1(cachekey)
);
this.list_model.fetch(); this.list_model.fetch();
this.render(); this.render();
this.sortAndPositionAllItems(); this.sortAndPositionAllItems();
......
...@@ -258,7 +258,8 @@ ...@@ -258,7 +258,8 @@
this.addRelatedContact(_converse.roster.findWhere({'jid': this.get('jid')})); this.addRelatedContact(_converse.roster.findWhere({'jid': this.get('jid')}));
}); });
this.messages = new _converse.Messages(); this.messages = new _converse.Messages();
this.messages.browserStorage = new Backbone.BrowserStorage[_converse.storage]( const storage = _converse.session.get('storage');
this.messages.browserStorage = new Backbone.BrowserStorage[storage](
b64_sha1(`converse.messages${this.get('jid')}${_converse.bare_jid}`)); b64_sha1(`converse.messages${this.get('jid')}${_converse.bare_jid}`));
this.messages.chatbox = this; this.messages.chatbox = this;
......
...@@ -123,9 +123,6 @@ ...@@ -123,9 +123,6 @@
'scroll_position': 0 'scroll_position': 0
}, },
initialize () { initialize () {
const id = `converse.emoji-${_converse.bare_jid}`;
this.id = id;
this.browserStorage = new Backbone.BrowserStorage[_converse.storage](id);
} }
}); });
...@@ -1059,7 +1056,10 @@ ...@@ -1059,7 +1056,10 @@
createEmojiPicker () { createEmojiPicker () {
if (_.isUndefined(_converse.emojipicker)) { if (_.isUndefined(_converse.emojipicker)) {
_converse.emojipicker = new _converse.EmojiPicker(); const storage = _converse.session.get('storage'),
id = `converse.emoji-${_converse.bare_jid}`;
_converse.emojipicker = new _converse.EmojiPicker({'id': id});
_converse.emojipicker.browserStorage = new Backbone.BrowserStorage[storage](id);
_converse.emojipicker.fetch(); _converse.emojipicker.fetch();
} }
this.emoji_picker_view = new _converse.EmojiPickerView({ this.emoji_picker_view = new _converse.EmojiPickerView({
......
...@@ -466,8 +466,10 @@ ...@@ -466,8 +466,10 @@
if (!this.validate()) { return; } if (!this.validate()) { return; }
const form_data = new FormData(ev.target); const form_data = new FormData(ev.target);
_converse.trusted = form_data.get('trusted'); _converse.session.save({
_converse.storage = form_data.get('trusted') ? 'local' : 'session'; 'trusted': form_data.get('trusted') && true || false,
'storage': form_data.get('trusted') ? 'local' : 'session'
});
let jid = form_data.get('jid'); let jid = form_data.get('jid');
if (_converse.locked_domain) { if (_converse.locked_domain) {
...@@ -583,7 +585,7 @@ ...@@ -583,7 +585,7 @@
}); });
_converse.on('clearSession', () => { _converse.on('clearSession', () => {
if (_converse.trusted) { if (_converse.session.get('trusted')) {
const chatboxes = _.get(_converse, 'chatboxes', null); const chatboxes = _.get(_converse, 'chatboxes', null);
if (!_.isNil(chatboxes)) { if (!_.isNil(chatboxes)) {
const controlbox = chatboxes.get('controlbox'); const controlbox = chatboxes.get('controlbox');
......
...@@ -221,7 +221,6 @@ ...@@ -221,7 +221,6 @@
rid: undefined, rid: undefined,
root: window.document, root: window.document,
sid: undefined, sid: undefined,
storage: 'session',
strict_plugin_dependencies: false, strict_plugin_dependencies: false,
trusted: true, trusted: true,
view_mode: 'overlayed', // Choices are 'overlayed', 'fullscreen', 'mobile' view_mode: 'overlayed', // Choices are 'overlayed', 'fullscreen', 'mobile'
...@@ -649,28 +648,30 @@ ...@@ -649,28 +648,30 @@
if (reconnecting) { if (reconnecting) {
_converse.onStatusInitialized(reconnecting); _converse.onStatusInitialized(reconnecting);
} else { } else {
this.xmppstatus = new this.XMPPStatus(); const id = `converse.xmppstatus-${_converse.bare_jid}`;
const id = b64_sha1(`converse.xmppstatus-${_converse.bare_jid}`); this.xmppstatus = new this.XMPPStatus({'id': id});
this.xmppstatus.id = id; // Appears to be necessary for backbone.browserStorage this.xmppstatus.browserStorage = new Backbone.BrowserStorage.session(id);
this.xmppstatus.browserStorage = new Backbone.BrowserStorage[_converse.storage](id);
this.xmppstatus.fetch({ this.xmppstatus.fetch({
success: _.partial(_converse.onStatusInitialized, reconnecting), 'success': _.partial(_converse.onStatusInitialized, reconnecting),
error: _.partial(_converse.onStatusInitialized, reconnecting) 'error': _.partial(_converse.onStatusInitialized, reconnecting)
}); });
} }
} }
this.initSession = function () { this.initSession = function () {
_converse.session = new Backbone.Model();
const id = b64_sha1('converse.bosh-session'); const id = b64_sha1('converse.bosh-session');
_converse.session.id = id; // Appears to be necessary for backbone.browserStorage _converse.session = new Backbone.Model({
'id': id,
'trusted': _converse.trusted && true || false,
'storage': _converse.trusted ? 'local' : 'session'
});
_converse.session.browserStorage = new Backbone.BrowserStorage.session(id); _converse.session.browserStorage = new Backbone.BrowserStorage.session(id);
_converse.session.fetch(); _converse.session.fetch();
_converse.emit('sessionInitialized'); _converse.emit('sessionInitialized');
}; };
this.clearSession = function () { this.clearSession = function () {
if (!_converse.trusted) { if (!_converse.session.get('trusted')) {
window.localStorage.clear(); window.localStorage.clear();
window.sessionStorage.clear(); window.sessionStorage.clear();
} else if (!_.isUndefined(this.session) && this.session.browserStorage) { } else if (!_.isUndefined(this.session) && this.session.browserStorage) {
...@@ -790,11 +791,12 @@ ...@@ -790,11 +791,12 @@
} }
}; };
this.setUserJid = function () { this.setUserJID = function () {
_converse.jid = _converse.connection.jid; _converse.jid = _converse.connection.jid;
_converse.bare_jid = Strophe.getBareJidFromJid(_converse.connection.jid); _converse.bare_jid = Strophe.getBareJidFromJid(_converse.connection.jid);
_converse.resource = Strophe.getResourceFromJid(_converse.connection.jid); _converse.resource = Strophe.getResourceFromJid(_converse.connection.jid);
_converse.domain = Strophe.getDomainFromJid(_converse.connection.jid); _converse.domain = Strophe.getDomainFromJid(_converse.connection.jid);
_converse.emit('setUserJID');
}; };
this.onConnected = function (reconnecting) { this.onConnected = function (reconnecting) {
...@@ -802,8 +804,7 @@ ...@@ -802,8 +804,7 @@
* by logging in or by attaching to an existing BOSH session. * by logging in or by attaching to an existing BOSH session.
*/ */
_converse.connection.flush(); // Solves problem of returned PubSub BOSH response not received by browser _converse.connection.flush(); // Solves problem of returned PubSub BOSH response not received by browser
_converse.setUserJid(); _converse.setUserJID();
_converse.initSession();
_converse.enableCarbons(); _converse.enableCarbons();
_converse.initStatus(reconnecting) _converse.initStatus(reconnecting)
}; };
...@@ -1168,6 +1169,7 @@ ...@@ -1168,6 +1169,7 @@
function finishInitialization () { function finishInitialization () {
_converse.initPlugins(); _converse.initPlugins();
_converse.initSession();
_converse.initConnection(); _converse.initConnection();
_converse.setUpXMLLogging(); _converse.setUpXMLLogging();
_converse.logIn(); _converse.logIn();
......
...@@ -268,7 +268,7 @@ ...@@ -268,7 +268,7 @@
}).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL)); }).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
} }
_converse.api.listen.on('sessionInitialized', initStreamFeatures); _converse.api.listen.on('setUserJID', initStreamFeatures);
_converse.api.listen.on('reconnected', initializeDisco); _converse.api.listen.on('reconnected', initializeDisco);
_converse.api.listen.on('connected', initializeDisco); _converse.api.listen.on('connected', initializeDisco);
......
...@@ -423,12 +423,12 @@ ...@@ -423,12 +423,12 @@
}, },
initToggle () { initToggle () {
const storage = _converse.session.get('storage'),
id = b64_sha1(`converse.minchatstoggle${_converse.bare_jid}`);
this.toggleview = new _converse.MinimizedChatsToggleView({ this.toggleview = new _converse.MinimizedChatsToggleView({
model: new _converse.MinimizedChatsToggle() 'model': new _converse.MinimizedChatsToggle({'id': id})
}); });
const id = b64_sha1(`converse.minchatstoggle${_converse.bare_jid}`); this.toggleview.model.browserStorage = new Backbone.BrowserStorage[storage](id);
this.toggleview.model.id = id; // Appears to be necessary for backbone.browserStorage
this.toggleview.model.browserStorage = new Backbone.BrowserStorage[_converse.storage](id);
this.toggleview.model.fetch(); this.toggleview.model.fetch();
}, },
......
...@@ -102,7 +102,7 @@ ...@@ -102,7 +102,7 @@
this.roomspanel = new _converse.RoomsPanel({ this.roomspanel = new _converse.RoomsPanel({
'model': new (_converse.RoomsPanelModel.extend({ 'model': new (_converse.RoomsPanelModel.extend({
'id': b64_sha1(`converse.roomspanel${_converse.bare_jid}`), // Required by sessionStorage 'id': b64_sha1(`converse.roomspanel${_converse.bare_jid}`), // Required by sessionStorage
'browserStorage': new Backbone.BrowserStorage[_converse.storage]( 'browserStorage': new Backbone.BrowserStorage[_converse.session.get('storage')](
b64_sha1(`converse.roomspanel${_converse.bare_jid}`)) b64_sha1(`converse.roomspanel${_converse.bare_jid}`))
}))() }))()
}); });
......
...@@ -55,8 +55,6 @@ ...@@ -55,8 +55,6 @@
}, },
initialize () { initialize () {
this.browserStorage = new Backbone.BrowserStorage[_converse.storage](
b64_sha1(`converse.open-rooms-{_converse.bare_jid}`));
_converse.chatboxes.on('add', this.onChatBoxAdded, this); _converse.chatboxes.on('add', this.onChatBoxAdded, this);
_converse.chatboxes.on('change:hidden', this.onChatBoxChanged, this); _converse.chatboxes.on('change:hidden', this.onChatBoxChanged, this);
_converse.chatboxes.on('change:bookmarked', this.onChatBoxChanged, this); _converse.chatboxes.on('change:bookmarked', this.onChatBoxChanged, this);
...@@ -170,12 +168,11 @@ ...@@ -170,12 +168,11 @@
this.model.on('add', this.showOrHide, this); this.model.on('add', this.showOrHide, this);
this.model.on('remove', this.showOrHide, this); this.model.on('remove', this.showOrHide, this);
const cachekey = `converse.roomslist${_converse.bare_jid}`; const storage = _converse.session.get('storage'),
this.list_model = new _converse.RoomsList(); id = b64_sha1(`converse.roomslist${_converse.bare_jid}`);
this.list_model.id = cachekey;
this.list_model.browserStorage = new Backbone.BrowserStorage[_converse.storage]( this.list_model = new _converse.RoomsList({'id': id});
b64_sha1(cachekey) this.list_model.browserStorage = new Backbone.BrowserStorage[storage](id);
);
this.list_model.fetch(); this.list_model.fetch();
this.render(); this.render();
this.sortAndPositionAllItems(); this.sortAndPositionAllItems();
...@@ -265,9 +262,12 @@ ...@@ -265,9 +262,12 @@
}); });
const initRoomsListView = function () { const initRoomsListView = function () {
_converse.rooms_list_view = new _converse.RoomsListView( const storage = _converse.session.get('storage'),
{'model': new _converse.OpenRooms() } id = b64_sha1(`converse.open-rooms-{_converse.bare_jid}`),
); model = new _converse.OpenRooms();
model.browserStorage = new Backbone.BrowserStorage[storage](id);
_converse.rooms_list_view = new _converse.RoomsListView({'model': model});
}; };
if (_converse.allow_bookmarks) { if (_converse.allow_bookmarks) {
......
...@@ -49,20 +49,21 @@ ...@@ -49,20 +49,21 @@
_converse.initRoster = function () { _converse.initRoster = function () {
/* Initialize the Bakcbone collections that represent the contats /* Initialize the Bakcbone collections that represent the contats
* roster and the roster groups. * roster and the roster groups.
*/ */
const storage = _converse.session.get('storage');
_converse.roster = new _converse.RosterContacts(); _converse.roster = new _converse.RosterContacts();
_converse.roster.browserStorage = new Backbone.BrowserStorage[_converse.storage]( _converse.roster.browserStorage = new Backbone.BrowserStorage[storage](
b64_sha1(`converse.contacts-${_converse.bare_jid}`)); b64_sha1(`converse.contacts-${_converse.bare_jid}`));
_converse.roster.data = new Backbone.Model(); _converse.roster.data = new Backbone.Model();
const id = b64_sha1(`converse-roster-model-${_converse.bare_jid}`); const id = b64_sha1(`converse-roster-model-${_converse.bare_jid}`);
_converse.roster.data.id = id; _converse.roster.data.id = id;
_converse.roster.data.browserStorage = new Backbone.BrowserStorage[_converse.storage](id); _converse.roster.data.browserStorage = new Backbone.BrowserStorage[storage](id);
_converse.roster.data.fetch(); _converse.roster.data.fetch();
_converse.rostergroups = new _converse.RosterGroups(); _converse.rostergroups = new _converse.RosterGroups();
_converse.rostergroups.browserStorage = new Backbone.BrowserStorage[_converse.storage]( _converse.rostergroups.browserStorage = new Backbone.BrowserStorage[storage](
b64_sha1(`converse.roster.groups${_converse.bare_jid}`)); b64_sha1(`converse.roster.groups${_converse.bare_jid}`));
_converse.emit('rosterInitialized'); _converse.emit('rosterInitialized');
}; };
......
...@@ -131,10 +131,11 @@ ...@@ -131,10 +131,11 @@
/* Event handlers */ /* Event handlers */
_converse.initVCardCollection = function () { _converse.initVCardCollection = function () {
_converse.vcards = new _converse.VCards(); _converse.vcards = new _converse.VCards();
_converse.vcards.browserStorage = new Backbone.BrowserStorage[_converse.storage](b64_sha1(`converse.vcards`)); const id = b64_sha1(`converse.vcards`);
_converse.vcards.browserStorage = new Backbone.BrowserStorage[_converse.session.get('storage')](id);
_converse.vcards.fetch(); _converse.vcards.fetch();
} }
_converse.api.listen.on('sessionInitialized', _converse.initVCardCollection); _converse.api.listen.on('setUserJID', _converse.initVCardCollection);
_converse.on('addClientFeatures', () => { _converse.on('addClientFeatures', () => {
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
</div> </div>
{[ } ]} {[ } ]}
<div class="form-group form-check"> <div class="form-group form-check">
<input id="converse-login-trusted" type="checkbox" class="form-check-input" name="trusted" {[ if (o._converse.trusted) { ]} checked="checked" {[ } ]}> <input id="converse-login-trusted" type="checkbox" class="form-check-input" name="trusted" {[ if (o._converse.session.get('trusted')) { ]} checked="checked" {[ } ]}>
<label for="converse-login-trusted" class="form-check-label">{{{o.__('This is a trusted device')}}}</label> <label for="converse-login-trusted" class="form-check-label">{{{o.__('This is a trusted device')}}}</label>
<i class="fa fa-info-circle" data-toggle="popover" <i class="fa fa-info-circle" data-toggle="popover"
data-title="Trusted device?" data-title="Trusted device?"
......
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