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

Create a new store, `_converse.config` to store `trusted`

The `_converse.session` store gets cleared after logout, but we want the
`trusted` flag to persist after logout.

Also update the documentation no that the `storage` config option has
been removed in favor of `trusted`.
parent 9ed2ad63
......@@ -53,6 +53,7 @@
## Configuration changes
- Removed the `storage` configuration setting, use [trusted](https://conversejs.org/docs/html/configurations.html#trusted) instead.
- Removed the `use_vcards` configuration setting, instead VCards are always used.
- Removed the `xhr_custom_status` and `xhr_custom_status_url` configuration
settings. If you relied on these settings, you can instead listen for the
......
This diff is collapsed.
This diff is collapsed.
......@@ -29,15 +29,15 @@
spyOn(cbview.loginpanel, 'connect');
cbview.delegateEvents();
expect(_converse.session.get('storage')).toBe('local');
expect(_converse.config.get('storage')).toBe('local');
cbview.el.querySelector('input[type="submit"]').click();
expect(_converse.session.get('storage')).toBe('local');
expect(_converse.config.get('storage')).toBe('local');
expect(cbview.loginpanel.connect).toHaveBeenCalled();
checkbox.click();
cbview.el.querySelector('input[type="submit"]').click();
expect(_converse.session.get('storage')).toBe('session');
expect(_converse.config.get('storage')).toBe('session');
done();
});
}));
......@@ -67,14 +67,14 @@
spyOn(cbview.loginpanel, 'connect');
expect(_converse.session.get('storage')).toBe('session');
expect(_converse.config.get('storage')).toBe('session');
cbview.el.querySelector('input[type="submit"]').click();
expect(_converse.session.get('storage')).toBe('session');
expect(_converse.config.get('storage')).toBe('session');
expect(cbview.loginpanel.connect).toHaveBeenCalled();
checkbox.click();
cbview.el.querySelector('input[type="submit"]').click();
expect(_converse.session.get('storage')).toBe('local');
expect(_converse.config.get('storage')).toBe('local');
done();
});
}));
......
......@@ -250,7 +250,7 @@
this.on('remove', this.markRoomAsUnbookmarked, this);
this.on('remove', this.sendBookmarkStanza, this);
const storage = _converse.session.get('storage'),
const storage = _converse.config.get('storage'),
cache_key = `converse.room-bookmarks${_converse.bare_jid}`;
this.fetched_flag = b64_sha1(cache_key+'fetched');
this.browserStorage = new Backbone.BrowserStorage[storage](b64_sha1(cache_key));
......@@ -444,7 +444,7 @@
_converse.chatboxes.on('add', this.renderBookmarkListElement, this);
_converse.chatboxes.on('remove', this.renderBookmarkListElement, this);
const storage = _converse.session.get('storage'),
const storage = _converse.config.get('storage'),
id = b64_sha1(`converse.room-bookmarks${_converse.bare_jid}-list-model`);
this.list_model = new _converse.BookmarksList({'id': id});
this.list_model.browserStorage = new Backbone.BrowserStorage[storage](id);
......
......@@ -258,7 +258,7 @@
this.addRelatedContact(_converse.roster.findWhere({'jid': this.get('jid')}));
});
this.messages = new _converse.Messages();
const storage = _converse.session.get('storage');
const storage = _converse.config.get('storage');
this.messages.browserStorage = new Backbone.BrowserStorage[storage](
b64_sha1(`converse.messages${this.get('jid')}${_converse.bare_jid}`));
this.messages.chatbox = this;
......
......@@ -121,8 +121,6 @@
'current_category': 'people',
'current_skintone': '',
'scroll_position': 0
},
initialize () {
}
});
......@@ -1056,7 +1054,7 @@
createEmojiPicker () {
if (_.isUndefined(_converse.emojipicker)) {
const storage = _converse.session.get('storage'),
const storage = _converse.config.get('storage'),
id = `converse.emoji-${_converse.bare_jid}`;
_converse.emojipicker = new _converse.EmojiPicker({'id': id});
_converse.emojipicker.browserStorage = new Backbone.BrowserStorage[storage](id);
......
......@@ -466,7 +466,7 @@
if (!this.validate()) { return; }
const form_data = new FormData(ev.target);
_converse.session.save({
_converse.config.save({
'trusted': form_data.get('trusted') && true || false,
'storage': form_data.get('trusted') ? 'local' : 'session'
});
......@@ -585,7 +585,7 @@
});
_converse.on('clearSession', () => {
if (_converse.session.get('trusted')) {
if (_converse.config.get('trusted')) {
const chatboxes = _.get(_converse, 'chatboxes', null);
if (!_.isNil(chatboxes)) {
const controlbox = chatboxes.get('controlbox');
......
......@@ -341,9 +341,11 @@
delete _converse.controlboxtoggle;
delete _converse.chatboxviews;
_converse.connection.reset();
_converse.off();
_converse.stopListening();
_converse.tearDown();
delete _converse.config;
_converse.initClientConfig();
_converse.off();
}
if ('onpagehide' in window) {
......@@ -658,20 +660,33 @@
}
}
this.initSession = function () {
const id = b64_sha1('converse.bosh-session');
_converse.session = new Backbone.Model({
this.initClientConfig = function () {
/* The client config refers to configuration of the client which is
* independent of any particular user.
* What this means is that config values need to persist across
* user sessions.
*/
const id = b64_sha1('converse.client-config');
_converse.config = new Backbone.Model({
'id': id,
'trusted': _converse.trusted && true || false,
'storage': _converse.trusted ? 'local' : 'session'
});
_converse.config.browserStorage = new Backbone.BrowserStorage.session(id);
_converse.config.fetch();
_converse.emit('clientConfigInitialized');
};
this.initSession = function () {
const id = b64_sha1('converse.bosh-session');
_converse.session = new Backbone.Model({'id': id});
_converse.session.browserStorage = new Backbone.BrowserStorage.session(id);
_converse.session.fetch();
_converse.emit('sessionInitialized');
};
this.clearSession = function () {
if (!_converse.session.get('trusted')) {
if (!_converse.config.get('trusted')) {
window.localStorage.clear();
window.sessionStorage.clear();
} else if (!_.isUndefined(this.session) && this.session.browserStorage) {
......@@ -805,6 +820,7 @@
*/
_converse.connection.flush(); // Solves problem of returned PubSub BOSH response not received by browser
_converse.setUserJID();
_converse.initSession();
_converse.enableCarbons();
_converse.initStatus(reconnecting)
};
......@@ -1169,7 +1185,7 @@
function finishInitialization () {
_converse.initPlugins();
_converse.initSession();
_converse.initClientConfig();
_converse.initConnection();
_converse.setUpXMLLogging();
_converse.logIn();
......
......@@ -268,7 +268,7 @@
}).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
}
_converse.api.listen.on('setUserJID', initStreamFeatures);
_converse.api.listen.on('sessionInitialized', initStreamFeatures);
_converse.api.listen.on('reconnected', initializeDisco);
_converse.api.listen.on('connected', initializeDisco);
......
......@@ -423,12 +423,16 @@
},
initToggle () {
const storage = _converse.session.get('storage'),
const storage = _converse.config.get('storage'),
id = b64_sha1(`converse.minchatstoggle${_converse.bare_jid}`);
this.toggleview = new _converse.MinimizedChatsToggleView({
'model': new _converse.MinimizedChatsToggle({'id': id})
});
this.toggleview.model.browserStorage = new Backbone.BrowserStorage[storage](id);
try {
this.toggleview.model.browserStorage = new Backbone.BrowserStorage[storage](id);
} catch (e) {
debugger;
}
this.toggleview.model.fetch();
},
......
......@@ -102,7 +102,7 @@
this.roomspanel = new _converse.RoomsPanel({
'model': new (_converse.RoomsPanelModel.extend({
'id': b64_sha1(`converse.roomspanel${_converse.bare_jid}`), // Required by sessionStorage
'browserStorage': new Backbone.BrowserStorage[_converse.session.get('storage')](
'browserStorage': new Backbone.BrowserStorage[_converse.config.get('storage')](
b64_sha1(`converse.roomspanel${_converse.bare_jid}`))
}))()
});
......
......@@ -168,7 +168,7 @@
this.model.on('add', this.showOrHide, this);
this.model.on('remove', this.showOrHide, this);
const storage = _converse.session.get('storage'),
const storage = _converse.config.get('storage'),
id = b64_sha1(`converse.roomslist${_converse.bare_jid}`);
this.list_model = new _converse.RoomsList({'id': id});
......@@ -262,7 +262,7 @@
});
const initRoomsListView = function () {
const storage = _converse.session.get('storage'),
const storage = _converse.config.get('storage'),
id = b64_sha1(`converse.open-rooms-{_converse.bare_jid}`),
model = new _converse.OpenRooms();
......
......@@ -51,7 +51,7 @@
/* Initialize the Bakcbone collections that represent the contats
* roster and the roster groups.
*/
const storage = _converse.session.get('storage');
const storage = _converse.config.get('storage');
_converse.roster = new _converse.RosterContacts();
_converse.roster.browserStorage = new Backbone.BrowserStorage[storage](
b64_sha1(`converse.contacts-${_converse.bare_jid}`));
......
......@@ -132,10 +132,10 @@
_converse.initVCardCollection = function () {
_converse.vcards = new _converse.VCards();
const id = b64_sha1(`converse.vcards`);
_converse.vcards.browserStorage = new Backbone.BrowserStorage[_converse.session.get('storage')](id);
_converse.vcards.browserStorage = new Backbone.BrowserStorage[_converse.config.get('storage')](id);
_converse.vcards.fetch();
}
_converse.api.listen.on('setUserJID', _converse.initVCardCollection);
_converse.api.listen.on('sessionInitialized', _converse.initVCardCollection);
_converse.on('addClientFeatures', () => {
......
......@@ -19,7 +19,7 @@
</div>
{[ } ]}
<div class="form-group form-check">
<input id="converse-login-trusted" type="checkbox" class="form-check-input" name="trusted" {[ if (o._converse.session.get('trusted')) { ]} checked="checked" {[ } ]}>
<input id="converse-login-trusted" type="checkbox" class="form-check-input" name="trusted" {[ if (o._converse.config.get('trusted')) { ]} checked="checked" {[ } ]}>
<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"
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