singleton: Ensure obscured chats gets actively hidden.

So that when a room is closed, a previously obscured chat doesn't become
visible again. Allowing this would force us to know which chat is visible, so
that we can falsify it's `hidden` attribute.
This commit is contained in:
JC Brand 2017-06-10 20:39:09 +02:00
parent d1bafdb38a
commit 1a95472ebe

View File

@ -24,6 +24,12 @@
var _ = converse.env._,
Strophe = converse.env.Strophe;
function hideChat (view) {
if (view.model.get('id') === 'controlbox') { return; }
view.model.save({'hidden': true});
view.hide();
}
converse.plugins.add('converse-singleton', {
// It's possible however to make optional dependencies non-optional.
// If the setting "strict_plugin_dependencies" is set to true,
@ -39,7 +45,6 @@
//
// new functions which don't exist yet can also be added.
ChatBoxes: {
createChatBox: function (jid, attrs) {
/* Make sure new chat boxes are hidden by default.
@ -59,14 +64,7 @@
var _converse = this.__super__._converse;
var chatbox = this.getChatBox(attrs, true);
if ((force || !attrs.hidden) && _converse.connection.authenticated) {
_.each(_converse.chatboxviews.xget(chatbox.get('id')),
function (view) {
if (view.model.get('id') === 'controlbox') {
return;
}
view.model.save({'hidden': true});
}
);
_.each(_converse.chatboxviews.xget(chatbox.get('id')), hideChat);
chatbox.save({'hidden': false});
}
return this.__super__.showChat.apply(this, arguments);
@ -80,13 +78,7 @@
* chats are hidden.
*/
if (!this.model.get('hidden')) {
_.each(this.__super__._converse.chatboxviews.xget(this.model.get('id')), function (view) {
if (view.model.get('id') === 'controlbox') {
return;
}
view.hide();
view.model.set({'hidden': true});
});
_.each(this.__super__._converse.chatboxviews.xget(this.model.get('id')), hideChat);
return this.__super__._show.apply(this, arguments);
}
}
@ -98,8 +90,7 @@
* time. So before opening a chat, we make sure all other
* chats are hidden.
*/
_.each(this.__super__._converse.chatboxviews.xget('controlbox'),
function (view) { view.model.save({'hidden': true}); });
_.each(this.__super__._converse.chatboxviews.xget('controlbox'), hideChat);
this.model.save({'hidden': false});
return this.__super__.openChat.apply(this, arguments);
},