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:
parent
b0b0906e48
commit
94693f2d02
|
@ -73,8 +73,8 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
ChatBoxes: {
|
ChatBoxes: {
|
||||||
chatBoxShouldBeShown: function (chatbox) {
|
chatBoxMayBeShown: function (chatbox) {
|
||||||
return this._super.chatBoxShouldBeShown.apply(this, arguments) &&
|
return this._super.chatBoxMayBeShown.apply(this, arguments) &&
|
||||||
chatbox.get('id') !== 'controlbox';
|
chatbox.get('id') !== 'controlbox';
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -1215,7 +1215,7 @@
|
||||||
}.bind(this), null, 'message', 'chat');
|
}.bind(this), null, 'message', 'chat');
|
||||||
},
|
},
|
||||||
|
|
||||||
chatBoxShouldBeShown: function (chatbox) {
|
chatBoxMayBeShown: function (chatbox) {
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -1226,10 +1226,11 @@
|
||||||
* if the controlbox plugin is active.
|
* if the controlbox plugin is active.
|
||||||
*/
|
*/
|
||||||
collection.each(function (chatbox) {
|
collection.each(function (chatbox) {
|
||||||
if (this.chatBoxShouldBeShown(chatbox)) {
|
if (this.chatBoxMayBeShown(chatbox)) {
|
||||||
chatbox.trigger('show');
|
chatbox.trigger('show');
|
||||||
}
|
}
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
converse.emit('chatBoxesFetched');
|
||||||
},
|
},
|
||||||
|
|
||||||
onConnected: function () {
|
onConnected: function () {
|
||||||
|
@ -1385,8 +1386,13 @@
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
chatBoxMayBeShown: function (chatbox) {
|
||||||
|
return this.model.chatBoxMayBeShown(chatbox);
|
||||||
|
},
|
||||||
|
|
||||||
showChat: function (attrs) {
|
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);
|
var chatbox = this.model.get(attrs.jid);
|
||||||
if (!chatbox) {
|
if (!chatbox) {
|
||||||
|
@ -1396,7 +1402,9 @@
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if (this.chatBoxMayBeShown(chatbox)) {
|
||||||
chatbox.trigger('show', true);
|
chatbox.trigger('show', true);
|
||||||
|
}
|
||||||
return chatbox;
|
return chatbox;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -191,8 +191,8 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
ChatBoxes: {
|
ChatBoxes: {
|
||||||
chatBoxShouldBeShown: function (chatbox) {
|
chatBoxMayBeShown: function (chatbox) {
|
||||||
return this._super.chatBoxShouldBeShown.apply(this, arguments) &&
|
return this._super.chatBoxMayBeShown.apply(this, arguments) &&
|
||||||
!chatbox.get('minimized');
|
!chatbox.get('minimized');
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -180,6 +180,9 @@
|
||||||
|
|
||||||
initialize: function () {
|
initialize: function () {
|
||||||
this.model.messages.on('add', this.onMessageAdded, this);
|
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({
|
this.occupantsview = new converse.ChatRoomOccupantsView({
|
||||||
model: new converse.ChatRoomOccupants({nick: this.model.get('nick')})
|
model: new converse.ChatRoomOccupants({nick: this.model.get('nick')})
|
||||||
});
|
});
|
||||||
|
@ -191,7 +194,6 @@
|
||||||
this.join(null, {'maxstanzas': converse.muc_history_max_stanzas});
|
this.join(null, {'maxstanzas': converse.muc_history_max_stanzas});
|
||||||
this.fetchMessages();
|
this.fetchMessages();
|
||||||
this.$el.insertAfter(converse.chatboxviews.get("controlbox").$el);
|
this.$el.insertAfter(converse.chatboxviews.get("controlbox").$el);
|
||||||
this.show();
|
|
||||||
converse.emit('chatRoomOpened', this);
|
converse.emit('chatRoomOpened', this);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -1312,12 +1314,8 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
var onConnected = function () {
|
|
||||||
converse.connection.addHandler(
|
var autoJoinRooms = function () {
|
||||||
function (message) {
|
|
||||||
converse.onDirectMUCInvitation(message);
|
|
||||||
return true;
|
|
||||||
}, 'jabber:x:conference', 'message');
|
|
||||||
_.each(converse.auto_join_rooms, function (room) {
|
_.each(converse.auto_join_rooms, function (room) {
|
||||||
if (typeof room === 'string') {
|
if (typeof room === 'string') {
|
||||||
converse_api.rooms.open(room);
|
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('connected', onConnected);
|
||||||
converse.on('reconnected', onConnected);
|
converse.on('reconnected', onConnected);
|
||||||
/* ------------------------------------------------------------ */
|
/* ------------------------------------------------------------ */
|
||||||
|
|
Loading…
Reference in New Issue
Block a user