Commit 8b006d19 authored by JC Brand's avatar JC Brand

Check the view_mode on the fly

instead of disabling the plugin immediately.

This allows us to change the view_mode dynamically.
parent 195a9781
// Converse.js (A browser based XMPP chat client) // Converse.js
// http://conversejs.org // http://conversejs.org
// //
// Copyright (c) 2012-2017, JC Brand <jc@opkode.com> // Copyright (c) 2012-2018, the Converse.js developers
// Licensed under the Mozilla Public License (MPLv2) // Licensed under the Mozilla Public License (MPLv2)
//
/*global Backbone, define, window, JSON */
/* converse-singleton /* converse-singleton
* ****************** * ******************
...@@ -39,10 +37,6 @@ ...@@ -39,10 +37,6 @@
// NB: These plugins need to have already been loaded via require.js. // NB: These plugins need to have already been loaded via require.js.
dependencies: ['converse-chatboxes', 'converse-muc', 'converse-muc-views', 'converse-controlbox', 'converse-rosterview'], dependencies: ['converse-chatboxes', 'converse-muc', 'converse-muc-views', 'converse-controlbox', 'converse-rosterview'],
enabled (_converse) {
return _.includes(['mobile', 'fullscreen', 'embedded'], _converse.view_mode);
},
overrides: { overrides: {
// overrides mentioned here will be picked up by converse.js's // overrides mentioned here will be picked up by converse.js's
// plugin architecture they will replace existing methods on the // plugin architecture they will replace existing methods on the
...@@ -50,21 +44,32 @@ ...@@ -50,21 +44,32 @@
// //
// new functions which don't exist yet can also be added. // new functions which don't exist yet can also be added.
ChatBoxes: { ChatBoxes: {
chatBoxMayBeShown (chatbox) { chatBoxMayBeShown (chatbox) {
return !chatbox.get('hidden'); if (_.includes(['mobile', 'fullscreen', 'embedded'], this.__super__._converse.view_mode)) {
return !chatbox.get('hidden');
} else {
return this.__super__.chatBoxMayBeShown.apply(this, arguments);
}
}, },
createChatBox (jid, attrs) { createChatBox (jid, attrs) {
/* Make sure new chat boxes are hidden by default. */ /* Make sure new chat boxes are hidden by default. */
attrs = attrs || {}; if (_.includes(['mobile', 'fullscreen', 'embedded'], this.__super__._converse.view_mode)) {
attrs.hidden = true; attrs = attrs || {};
attrs.hidden = true;
}
return this.__super__.createChatBox.call(this, jid, attrs); return this.__super__.createChatBox.call(this, jid, attrs);
} }
}, },
ChatBoxView: { ChatBoxView: {
shouldShowOnTextMessage () { shouldShowOnTextMessage () {
return false; if (_.includes(['mobile', 'fullscreen', 'embedded'], this.__super__._converse.view_mode)) {
return false;
} else {
return this.__super__.shouldShowOnTextMessage.apply(this, arguments);
}
}, },
_show (focus) { _show (focus) {
...@@ -72,16 +77,20 @@ ...@@ -72,16 +77,20 @@
* time. So before opening a chat, we make sure all other * time. So before opening a chat, we make sure all other
* chats are hidden. * chats are hidden.
*/ */
_.each(this.__super__._converse.chatboxviews.xget(this.model.get('id')), hideChat); if (_.includes(['mobile', 'fullscreen', 'embedded'], this.__super__._converse.view_mode)) {
this.model.set('hidden', false); _.each(this.__super__._converse.chatboxviews.xget(this.model.get('id')), hideChat);
this.model.set('hidden', false);
}
return this.__super__._show.apply(this, arguments); return this.__super__._show.apply(this, arguments);
} }
}, },
ChatRoomView: { ChatRoomView: {
show (focus) { show (focus) {
_.each(this.__super__._converse.chatboxviews.xget(this.model.get('id')), hideChat); if (_.includes(['mobile', 'fullscreen', 'embedded'], this.__super__._converse.view_mode)) {
this.model.set('hidden', false); _.each(this.__super__._converse.chatboxviews.xget(this.model.get('id')), hideChat);
this.model.set('hidden', false);
}
return this.__super__.show.apply(this, arguments); return this.__super__.show.apply(this, arguments);
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment