muc: only create view once model has finished initialization

This commit is contained in:
JC Brand 2019-11-08 09:49:58 +01:00
parent 9965a93291
commit 4b3d427cff
3 changed files with 12 additions and 8 deletions

View File

@ -616,15 +616,13 @@ converse.plugins.add('converse-muc-views', {
/** /**
* The View of an open/ongoing groupchat conversation * Backbone.NativeView which renders a groupchat, based upon
* { @link _converse.ChatBoxView } for normal one-on-one chat boxes.
* @class * @class
* @namespace _converse.ChatRoomView * @namespace _converse.ChatRoomView
* @memberOf _converse * @memberOf _converse
*/ */
_converse.ChatRoomView = _converse.ChatBoxView.extend({ _converse.ChatRoomView = _converse.ChatBoxView.extend({
/* Backbone.NativeView which renders a groupchat, based upon the view
* for normal one-on-one chat boxes.
*/
length: 300, length: 300,
tagName: 'div', tagName: 'div',
className: 'chatbox chatroom hidden', className: 'chatbox chatroom hidden',
@ -700,6 +698,9 @@ converse.plugins.add('converse-muc-views', {
if (this.model.get('connection_status') !== converse.ROOMSTATUS.ENTERED) { if (this.model.get('connection_status') !== converse.ROOMSTATUS.ENTERED) {
this.showSpinner(); this.showSpinner();
} }
if (!this.model.get('hidden')) {
this.show();
}
return this; return this;
}, },
@ -2151,13 +2152,14 @@ converse.plugins.add('converse-muc-views', {
} }
_converse.chatboxviews.delegate('click', 'a.open-chatroom', openChatRoomFromURIClicked); _converse.chatboxviews.delegate('click', 'a.open-chatroom', openChatRoomFromURIClicked);
function addView (model) { async function addView (model) {
const views = _converse.chatboxviews; const views = _converse.chatboxviews;
if (!views.get(model.get('id')) && if (!views.get(model.get('id')) &&
model.get('type') === _converse.CHATROOMS_TYPE && model.get('type') === _converse.CHATROOMS_TYPE &&
model.isValid() model.isValid()
) { ) {
return views.add(model.get('id'), new _converse.ChatRoomView({'model': model})); await model.initialized;
return views.add(model.get('id'), new _converse.ChatRoomView({model}));
} }
} }
_converse.chatboxes.on('add', addView); _converse.chatboxes.on('add', addView);

View File

@ -378,6 +378,7 @@ converse.plugins.add('converse-muc', {
}, },
async initialize() { async initialize() {
this.initialized = u.getResolveablePromise();
this.setVCard(); this.setVCard();
this.set('box_id', `box-${btoa(this.get('jid'))}`); this.set('box_id', `box-${btoa(this.get('jid'))}`);
@ -391,6 +392,7 @@ converse.plugins.add('converse-muc', {
await this.initOccupants(); await this.initOccupants();
await this.fetchMessages(); await this.fetchMessages();
this.enterRoom(); this.enterRoom();
this.initialized.resolve();
}, },
async setVCard () { async setVCard () {