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