Commit 26c1dbb0 authored by JC Brand's avatar JC Brand

Updates #1705. Add `getRoomsPanel` method to avoid dangling pointer

parent d0b6e8fd
......@@ -13,6 +13,7 @@
your preferred path and then rebuild all assets (e.g. `make dist`).
- Use `listenTo` to avoid memory leaks when views get removed.
- #1692 Bugfix: `TypeError: oldest_message is undefined`
- #1705 Bugfix: `this.roomspanel` is `undefined` after hibernating
## 5.0.1 (2019-08-14)
......
......@@ -121,9 +121,10 @@ converse.plugins.add('converse-muc-views', {
});
function renderRoomsPanel () {
if (this.roomspanel && u.isVisible(this.roomspanel.el)) {
return;
const viewWithRoomsPanel = {
renderRoomsPanel () {
if (this.roomspanel && u.isInDOM(this.roomspanel.el)) {
return this.roomspanel;
}
this.roomspanel = new _converse.RoomsPanel({
'model': new (_converse.RoomsPanelModel.extend({
......@@ -143,9 +144,20 @@ converse.plugins.add('converse-muc-views', {
* @example _converse.api.listen.on('roomsPanelRendered', () => { ... });
*/
_converse.api.trigger('roomsPanelRendered');
return this.roomspanel;
},
getRoomsPanel () {
if (this.roomspanel && u.isInDOM(this.roomspanel.el)) {
return this.roomspanel;
} else {
return this.renderRoomsPanel();
}
}
}
if (_converse.ControlBoxView) {
Object.assign(_converse.ControlBoxView.prototype, { renderRoomsPanel });
Object.assign(_converse.ControlBoxView.prototype, viewWithRoomsPanel);
}
/* Insert groupchat info (based on returned #disco IQ stanza)
......@@ -2057,7 +2069,7 @@ converse.plugins.add('converse-muc-views', {
function setMUCDomain (domain, controlboxview) {
controlboxview.roomspanel.model.save('muc_domain', Strophe.getDomainFromJid(domain));
controlboxview.getRoomsPanel().model.save('muc_domain', Strophe.getDomainFromJid(domain));
}
function setMUCDomainFromDisco (controlboxview) {
......@@ -2085,7 +2097,7 @@ converse.plugins.add('converse-muc-views', {
function fetchAndSetMUCDomain (controlboxview) {
if (controlboxview.model.get('connected')) {
if (!controlboxview.roomspanel.model.get('muc_domain')) {
if (!controlboxview.getRoomsPanel().model.get('muc_domain')) {
if (_converse.muc_domain === undefined) {
setMUCDomainFromDisco(controlboxview);
} else {
......
......@@ -498,6 +498,10 @@ function afterAnimationEnds (el, callback) {
}
}
u.isInDOM = function (el) {
return document.querySelector('body').contains(el);
}
u.isVisible = function (el) {
if (u.hasClass('hidden', el)) {
return false;
......
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