Updates #1705. Add getRoomsPanel method to avoid dangling pointer

This commit is contained in:
JC Brand 2019-09-11 11:28:28 +02:00
parent d0b6e8fd16
commit 26c1dbb0eb
3 changed files with 41 additions and 24 deletions

View File

@ -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)

View File

@ -121,31 +121,43 @@ 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({ }
'model': new (_converse.RoomsPanelModel.extend({ this.roomspanel = new _converse.RoomsPanel({
'id': `converse.roomspanel${_converse.bare_jid}`, // Required by web storage 'model': new (_converse.RoomsPanelModel.extend({
'browserStorage': new BrowserStorage[_converse.config.get('storage')]( 'id': `converse.roomspanel${_converse.bare_jid}`, // Required by web storage
`converse.roomspanel${_converse.bare_jid}`) 'browserStorage': new BrowserStorage[_converse.config.get('storage')](
}))() `converse.roomspanel${_converse.bare_jid}`)
}); }))()
this.roomspanel.model.fetch(); });
this.el.querySelector('.controlbox-pane').insertAdjacentElement( this.roomspanel.model.fetch();
'beforeEnd', this.roomspanel.render().el); this.el.querySelector('.controlbox-pane').insertAdjacentElement(
'beforeEnd', this.roomspanel.render().el);
/** /**
* Triggered once the section of the _converse.ControlBoxView * Triggered once the section of the _converse.ControlBoxView
* which shows gropuchats has been rendered. * which shows gropuchats has been rendered.
* @event _converse#roomsPanelRendered * @event _converse#roomsPanelRendered
* @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', {
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', {
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 {

View File

@ -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;