Commit ce2ae87d authored by JC Brand's avatar JC Brand

Bugfix. Open groupchats not shown when logging in after disconnection

* Replace `tearDown` overrides with event handlers.
* Move presence listeners to `connected` event handler, otherwise they
  don't get called when logging in again after disconnection.
* Add `clearSession` listeners to clean up upon disconnection.
* Use `Promise.all` instead of listening for multiple events.
parent 064ba57a
......@@ -3,6 +3,7 @@
## 4.1.2 (Unreleased)
- Bugfix. Prevent duplicate messages by comparing MAM archive id to XEP-0359 stanza ids.
- Bugfix. Open groupchats not shown when logging in after disconnection.
## 4.1.1 (2019-02-18)
......
......@@ -48802,14 +48802,6 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_0__["default"].plugins
_converse.emit('bookmarksInitialized');
};
u.onMultipleEvents([{
'object': _converse,
'event': 'chatBoxesFetched'
}, {
'object': _converse,
'event': 'roomsPanelRendered'
}], initBookmarks);
_converse.on('clearSession', () => {
if (!_.isUndefined(_converse.bookmarks)) {
_converse.bookmarks.browserStorage._clear();
......@@ -48820,7 +48812,7 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_0__["default"].plugins
_converse.on('reconnected', initBookmarks);
_converse.on('connected', () => {
_converse.on('connected', async () => {
// Add a handler for bookmarks pushed from other connected clients
// (from the same user obviously)
_converse.connection.addHandler(message => {
......@@ -48828,6 +48820,9 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_0__["default"].plugins
_converse.api.waitUntil('bookmarksInitialized').then(() => _converse.bookmarks.createBookmarksFromStanza(message)).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
}
}, null, 'message', 'headline', null, _converse.bare_jid);
await Promise.all([_converse.api.waitUntil('chatBoxesFetched'), _converse.api.waitUntil('roomsPanelRendered')]);
initBookmarks();
});
}
......@@ -50683,20 +50678,6 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_5__["default"].plugins
// relevant objects or classes.
//
// New functions which don't exist yet can also be added.
tearDown() {
this.__super__.tearDown.apply(this, arguments);
if (this.rosterview) {
// Removes roster groups
this.rosterview.model.off().reset();
this.rosterview.each(function (groupview) {
groupview.removeAll();
groupview.remove();
});
this.rosterview.removeAll().remove();
}
},
ChatBoxes: {
model(attrs, options) {
const _converse = this.__super__._converse;
......@@ -50872,7 +50853,7 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_5__["default"].plugins
if (!_converse.connection.connected || !_converse.connection.authenticated || _converse.connection.disconnecting) {
this.renderLoginPanel();
} else if (this.model.get('connected') && (!this.controlbox_pane || !u.isVisible(this.controlbox_pane.el))) {
} else if (this.model.get('connected')) {
this.renderControlBoxPane();
}
......@@ -50943,6 +50924,10 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_5__["default"].plugins
delete this.loginpanel;
}
if (this.controlbox_pane && u.isVisible(this.controlbox_pane.el)) {
return;
}
this.el.classList.remove("logged-out");
this.controlbox_pane = new _converse.ControlBoxPane();
this.el.querySelector('.controlbox-panes').insertAdjacentElement('afterBegin', this.controlbox_pane.el);
......@@ -51304,9 +51289,18 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_5__["default"].plugins
return view;
};
_converse.on('disconnected', () => disconnect().renderLoginPanel());
_converse.api.listen.on('disconnected', () => disconnect().renderLoginPanel());
_converse.api.listen.on('will-reconnect', disconnect);
_converse.api.listen.on('clearSession', () => {
const view = _converse.chatboxviews.get('controlbox');
_converse.on('will-reconnect', disconnect);
if (view && view.controlbox_pane) {
view.controlbox_pane.remove();
delete view.controlbox_pane;
}
});
/************************ BEGIN API ************************/
......@@ -53244,6 +53238,11 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_3__["default"].plugins
ControlBoxView: {
renderRoomsPanel() {
const _converse = this.__super__._converse;
if (this.roomspanel && u.isVisible(this.roomspanel.el)) {
return;
}
this.roomspanel = new _converse.RoomsPanel({
'model': new (_converse.RoomsPanelModel.extend({
'id': `converse.roomspanel${_converse.bare_jid}`,
......@@ -55347,7 +55346,16 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_3__["default"].plugins
});
});
_converse.on('controlboxInitialized', view => {
_converse.api.listen.on('clearSession', () => {
const view = _converse.chatboxviews.get('controlbox');
if (view && view.roomspanel) {
view.roomspanel.remove();
delete view.roomspanel;
}
});
_converse.api.listen.on('controlboxInitialized', view => {
if (!_converse.allow_muc) {
return;
}
......@@ -58756,18 +58764,16 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_0__["default"].plugins
_converse.api.emit('roomsListInitialized');
};
_converse.on('connected', async () => {
if (_converse.allow_bookmarks) {
_converse.api.waitUntil('bookmarksInitialized').then(initRoomsListView);
await _converse.api.waitUntil('bookmarksInitialized');
} else {
u.onMultipleEvents([{
'object': _converse,
'event': 'chatBoxesInitialized'
}, {
'object': _converse,
'event': 'roomsPanelRendered'
}], initRoomsListView);
await Promise.all([_converse.api.waitUntil('chatBoxesFetched'), _converse.api.waitUntil('roomsPanelRendered')]);
}
initRoomsListView();
});
_converse.api.listen.on('reconnected', initRoomsListView);
}
......@@ -58847,17 +58853,6 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_5__["default"].plugins
this.__super__.afterReconnected.apply(this, arguments);
},
tearDown() {
/* Remove the rosterview when tearing down. It gets created
* anew when reconnecting or logging in.
*/
this.__super__.tearDown.apply(this, arguments);
if (!_.isUndefined(this.rosterview)) {
this.rosterview.remove();
}
},
RosterGroups: {
comparator() {
// RosterGroupsComparator only gets set later (once i18n is
......@@ -59919,6 +59914,15 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_5__["default"].plugins
_converse.api.listen.on('rosterInitialized', initRoster);
_converse.api.listen.on('rosterReadyAfterReconnection', initRoster);
_converse.api.listen.on('afterTearDown', () => {
if (_converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_5__["default"].rosterview) {
_converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_5__["default"].rosterview.model.off().reset();
_converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_5__["default"].rosterview.each(groupview => groupview.removeAll().remove());
_converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_5__["default"].rosterview.removeAll().remove();
delete _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_5__["default"].rosterview;
}
});
}
});
......@@ -670,7 +670,7 @@
await test_utils.waitUntil(() => _converse.onMAMPreferences.calls.count());
expect(_converse.onMAMPreferences).toHaveBeenCalled();
expect(_converse.connection.sendIQ.calls.count()).toBe(2);
expect(_converse.connection.sendIQ.calls.count()).toBe(3);
expect(sent_stanza.toString()).toBe(
`<iq id="${IQ_id}" type="set" xmlns="jabber:client">`+
......
......@@ -542,12 +542,6 @@ converse.plugins.add('converse-bookmarks', {
_converse.emit('bookmarksInitialized');
}
u.onMultipleEvents([
{'object': _converse, 'event': 'chatBoxesFetched'},
{'object': _converse, 'event': 'roomsPanelRendered'}
], initBookmarks);
_converse.on('clearSession', () => {
if (!_.isUndefined(_converse.bookmarks)) {
_converse.bookmarks.browserStorage._clear();
......@@ -557,16 +551,22 @@ converse.plugins.add('converse-bookmarks', {
_converse.on('reconnected', initBookmarks);
_converse.on('connected', () => {
_converse.on('connected', async () => {
// Add a handler for bookmarks pushed from other connected clients
// (from the same user obviously)
_converse.connection.addHandler((message) => {
_converse.connection.addHandler(message => {
if (sizzle('event[xmlns="'+Strophe.NS.PUBSUB+'#event"] items[node="storage:bookmarks"]', message).length) {
_converse.api.waitUntil('bookmarksInitialized')
.then(() => _converse.bookmarks.createBookmarksFromStanza(message))
.catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
}
}, null, 'message', 'headline', null, _converse.bare_jid);
await Promise.all([
_converse.api.waitUntil('chatBoxesFetched'),
_converse.api.waitUntil('roomsPanelRendered')
]);
initBookmarks();
});
}
......
......@@ -84,19 +84,6 @@ converse.plugins.add('converse-controlbox', {
//
// New functions which don't exist yet can also be added.
tearDown () {
this.__super__.tearDown.apply(this, arguments);
if (this.rosterview) {
// Removes roster groups
this.rosterview.model.off().reset();
this.rosterview.each(function (groupview) {
groupview.removeAll();
groupview.remove();
});
this.rosterview.removeAll().remove();
}
},
ChatBoxes: {
model (attrs, options) {
const { _converse } = this.__super__;
......@@ -257,8 +244,7 @@ converse.plugins.add('converse-controlbox', {
!_converse.connection.authenticated ||
_converse.connection.disconnecting) {
this.renderLoginPanel();
} else if (this.model.get('connected') &&
(!this.controlbox_pane || !u.isVisible(this.controlbox_pane.el))) {
} else if (this.model.get('connected')) {
this.renderControlBoxPane();
}
return this;
......@@ -324,6 +310,9 @@ converse.plugins.add('converse-controlbox', {
this.loginpanel.remove();
delete this.loginpanel;
}
if (this.controlbox_pane && u.isVisible(this.controlbox_pane.el)) {
return;
}
this.el.classList.remove("logged-out");
this.controlbox_pane = new _converse.ControlBoxPane();
this.el.querySelector('.controlbox-panes').insertAdjacentElement(
......@@ -650,8 +639,16 @@ converse.plugins.add('converse-controlbox', {
view.model.set({'connected': false});
return view;
};
_converse.on('disconnected', () => disconnect().renderLoginPanel());
_converse.on('will-reconnect', disconnect);
_converse.api.listen.on('disconnected', () => disconnect().renderLoginPanel());
_converse.api.listen.on('will-reconnect', disconnect);
_converse.api.listen.on('clearSession', () => {
const view = _converse.chatboxviews.get('controlbox');
if (view && view.controlbox_pane) {
view.controlbox_pane.remove();
delete view.controlbox_pane;
}
});
/************************ BEGIN API ************************/
......
......@@ -58,6 +58,9 @@ converse.plugins.add('converse-muc-views', {
renderRoomsPanel () {
const { _converse } = this.__super__;
if (this.roomspanel && u.isVisible(this.roomspanel.el)) {
return;
}
this.roomspanel = new _converse.RoomsPanel({
'model': new (_converse.RoomsPanelModel.extend({
'id': `converse.roomspanel${_converse.bare_jid}`, // Required by web storage
......@@ -2038,7 +2041,15 @@ converse.plugins.add('converse-muc-views', {
});
});
_converse.on('controlboxInitialized', (view) => {
_converse.api.listen.on('clearSession', () => {
const view = _converse.chatboxviews.get('controlbox');
if (view && view.roomspanel) {
view.roomspanel.remove();
delete view.roomspanel;
}
});
_converse.api.listen.on('controlboxInitialized', (view) => {
if (!_converse.allow_muc) {
return;
}
......
......@@ -273,14 +273,17 @@ converse.plugins.add('converse-roomslist', {
_converse.api.emit('roomsListInitialized');
};
_converse.on('connected', async () => {
if (_converse.allow_bookmarks) {
_converse.api.waitUntil('bookmarksInitialized').then(initRoomsListView);
await _converse.api.waitUntil('bookmarksInitialized');
} else {
u.onMultipleEvents([
{'object': _converse, 'event': 'chatBoxesInitialized'},
{'object': _converse, 'event': 'roomsPanelRendered'}
], initRoomsListView);
await Promise.all([
_converse.api.waitUntil('chatBoxesFetched'),
_converse.api.waitUntil('roomsPanelRendered')
]);
}
initRoomsListView();
});
_converse.api.listen.on('reconnected', initRoomsListView);
}
......
......@@ -37,16 +37,6 @@ converse.plugins.add('converse-rosterview', {
this.__super__.afterReconnected.apply(this, arguments);
},
tearDown () {
/* Remove the rosterview when tearing down. It gets created
* anew when reconnecting or logging in.
*/
this.__super__.tearDown.apply(this, arguments);
if (!_.isUndefined(this.rosterview)) {
this.rosterview.remove();
}
},
RosterGroups: {
comparator () {
// RosterGroupsComparator only gets set later (once i18n is
......@@ -1000,6 +990,15 @@ converse.plugins.add('converse-rosterview', {
}
_converse.api.listen.on('rosterInitialized', initRoster);
_converse.api.listen.on('rosterReadyAfterReconnection', initRoster);
_converse.api.listen.on('afterTearDown', () => {
if (converse.rosterview) {
converse.rosterview.model.off().reset();
converse.rosterview.each(groupview => groupview.removeAll().remove());
converse.rosterview.removeAll().remove();
delete converse.rosterview;
}
});
}
});
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