Some refactoring to fix issues with how/when chat rooms are shown

- Don't call show in a room's initialize method (instead let the code be more
  similar to normal chats, in that it should listen to the "show" trigger).
- Rename chatBoxShouldBeShown to chatBoxMayBeShown
- Implement auto_join for rooms only once boxes have been fetched already.
This commit is contained in:
JC Brand 2016-04-05 11:23:16 +00:00
parent b0b0906e48
commit 94693f2d02
4 changed files with 30 additions and 15 deletions

View File

@ -73,8 +73,8 @@
},
ChatBoxes: {
chatBoxShouldBeShown: function (chatbox) {
return this._super.chatBoxShouldBeShown.apply(this, arguments) &&
chatBoxMayBeShown: function (chatbox) {
return this._super.chatBoxMayBeShown.apply(this, arguments) &&
chatbox.get('id') !== 'controlbox';
},

View File

@ -1215,7 +1215,7 @@
}.bind(this), null, 'message', 'chat');
},
chatBoxShouldBeShown: function (chatbox) {
chatBoxMayBeShown: function (chatbox) {
return true;
},
@ -1226,10 +1226,11 @@
* if the controlbox plugin is active.
*/
collection.each(function (chatbox) {
if (this.chatBoxShouldBeShown(chatbox)) {
if (this.chatBoxMayBeShown(chatbox)) {
chatbox.trigger('show');
}
}.bind(this));
converse.emit('chatBoxesFetched');
},
onConnected: function () {
@ -1385,8 +1386,13 @@
return this;
},
chatBoxMayBeShown: function (chatbox) {
return this.model.chatBoxMayBeShown(chatbox);
},
showChat: function (attrs) {
/* Find the chat box and show it. If it doesn't exist, create it.
/* Find the chat box and show it (if it may be shown).
* If it doesn't exist, create it.
*/
var chatbox = this.model.get(attrs.jid);
if (!chatbox) {
@ -1396,7 +1402,9 @@
}
});
}
chatbox.trigger('show', true);
if (this.chatBoxMayBeShown(chatbox)) {
chatbox.trigger('show', true);
}
return chatbox;
}
});

View File

@ -191,8 +191,8 @@
},
ChatBoxes: {
chatBoxShouldBeShown: function (chatbox) {
return this._super.chatBoxShouldBeShown.apply(this, arguments) &&
chatBoxMayBeShown: function (chatbox) {
return this._super.chatBoxMayBeShown.apply(this, arguments) &&
!chatbox.get('minimized');
},
},

View File

@ -180,6 +180,9 @@
initialize: function () {
this.model.messages.on('add', this.onMessageAdded, this);
this.model.on('show', this.show, this);
this.model.on('destroy', this.hide, this);
this.occupantsview = new converse.ChatRoomOccupantsView({
model: new converse.ChatRoomOccupants({nick: this.model.get('nick')})
});
@ -191,7 +194,6 @@
this.join(null, {'maxstanzas': converse.muc_history_max_stanzas});
this.fetchMessages();
this.$el.insertAfter(converse.chatboxviews.get("controlbox").$el);
this.show();
converse.emit('chatRoomOpened', this);
},
@ -1312,12 +1314,8 @@
}
}
};
var onConnected = function () {
converse.connection.addHandler(
function (message) {
converse.onDirectMUCInvitation(message);
return true;
}, 'jabber:x:conference', 'message');
var autoJoinRooms = function () {
_.each(converse.auto_join_rooms, function (room) {
if (typeof room === 'string') {
converse_api.rooms.open(room);
@ -1328,6 +1326,15 @@
}
});
};
converse.on('chatBoxesFetched', autoJoinRooms);
var onConnected = function () {
converse.connection.addHandler(
function (message) {
converse.onDirectMUCInvitation(message);
return true;
}, 'jabber:x:conference', 'message');
};
converse.on('connected', onConnected);
converse.on('reconnected', onConnected);
/* ------------------------------------------------------------ */