Add a clearSession event to avoid using overrides.

This commit is contained in:
JC Brand 2018-05-18 12:44:27 +02:00
parent 2508ef0e9e
commit c920725832
6 changed files with 42 additions and 42 deletions

View File

@ -149,6 +149,11 @@ When a chatbox has been minimized or maximized. Relevant to converse-chatview.js
``_converse.api.listen.on('chatBoxToggled', function (chatbox) { ... });``
clearSession
~~~~~~~~~~~~
Called when the user is logging out and provides the opportunity to remove session data.
connected
~~~~~~~~~

View File

@ -105,10 +105,6 @@
expect($(view.el).find('.chat-msg-text:last').text()).toBe(' wrote a 3rd person message');
expect($(view.el).find('.chat-msg-author:last').is(':visible')).toBeTruthy();
expect(u.hasClass('chat-msg-followup', message_el)).toBeFalsy();
message = 'This a normal message';
done();
});
});

View File

@ -51,15 +51,6 @@
//
// New functions which don't exist yet can also be added.
clearSession () {
if (!_.isUndefined(this.bookmarks)) {
this.bookmarks.reset();
this.bookmarks.browserStorage._clear();
window.sessionStorage.removeItem(this.bookmarks.fetched_flag);
}
this.__super__.clearSession.apply(this, arguments);
},
ChatRoomView: {
events: {
'click .toggle-bookmark': 'toggleBookmark'
@ -575,6 +566,14 @@
{'object': _converse, 'event': 'roomsPanelRendered'}
], initBookmarks);
_converse.on('clearSession', () => {
if (!_.isUndefined(_converse.bookmarks)) {
_converse.bookmarks.browserStorage._clear();
window.sessionStorage.removeItem(_converse.bookmarks.fetched_flag);
}
});
_converse.on('reconnected', initBookmarks);
_converse.on('connected', () => {

View File

@ -104,19 +104,6 @@
}
},
clearSession () {
this.__super__.clearSession.apply(this, arguments);
const chatboxes = _.get(this, 'chatboxes', null);
if (!_.isNil(chatboxes)) {
const controlbox = chatboxes.get('controlbox');
if (controlbox &&
controlbox.collection &&
controlbox.collection.browserStorage) {
controlbox.save({'connected': false});
}
}
},
ChatBoxes: {
chatBoxMayBeShown (chatbox) {
return this.__super__.chatBoxMayBeShown.apply(this, arguments) &&
@ -590,6 +577,20 @@
}
});
_converse.on('clearSession', () => {
if (_converse.trusted) {
const chatboxes = _.get(_converse, 'chatboxes', null);
if (!_.isNil(chatboxes)) {
const controlbox = chatboxes.get('controlbox');
if (controlbox &&
controlbox.collection &&
controlbox.collection.browserStorage) {
controlbox.save({'connected': false});
}
}
}
});
Promise.all([
_converse.api.waitUntil('connectionInitialized'),
_converse.api.waitUntil('chatBoxesInitialized')

View File

@ -649,13 +649,13 @@
};
this.clearSession = function () {
if (!_.isUndefined(this.session) && this.session.browserStorage) {
this.session.browserStorage._clear();
}
if (!_converse.trusted) {
window.localStorage.clear();
window.sessionStorage.clear();
} else if (!_.isUndefined(this.session) && this.session.browserStorage) {
this.session.browserStorage._clear();
}
_converse.emit('clearSession');
};
this.logOut = function () {

View File

@ -16,13 +16,6 @@
dependencies: ["converse-vcard"],
overrides: {
clearSession () {
this.__super__.clearSession.apply(this, arguments);
if (!_.isUndefined(this.roster)) {
this.roster.browserStorage._clear();
}
},
_tearDown () {
this.__super__._tearDown.apply(this, arguments);
if (this.roster) {
@ -360,12 +353,12 @@
fetchRosterContacts () {
/* Fetches the roster contacts, first by trying the
* sessionStorage cache, and if that's empty, then by querying
* the XMPP server.
*
* Returns a promise which resolves once the contacts have been
* fetched.
*/
* sessionStorage cache, and if that's empty, then by querying
* the XMPP server.
*
* Returns a promise which resolves once the contacts have been
* fetched.
*/
return new Promise((resolve, reject) => {
this.fetch({
'add': true,
@ -735,6 +728,12 @@
/********** Event Handlers *************/
_converse.api.listen.on('clearSession', () => {
if (!_.isUndefined(this.roster)) {
this.roster.browserStorage._clear();
}
});
_converse.api.listen.on('statusInitialized', (reconnecting) => {
if (reconnecting) {
// No need to recreate the roster, otherwise we lose our