2017-04-20 21:24:20 +02:00
|
|
|
// Converse.js (A browser based XMPP chat client)
|
|
|
|
// http://conversejs.org
|
|
|
|
//
|
|
|
|
// Copyright (c) 2012-2017, JC Brand <jc@opkode.com>
|
|
|
|
// Licensed under the Mozilla Public License (MPLv2)
|
|
|
|
//
|
2018-02-09 16:02:56 +01:00
|
|
|
/*global Backbone, define, window, JSON */
|
2017-04-20 21:24:20 +02:00
|
|
|
|
|
|
|
/* converse-singleton
|
2017-11-01 10:37:24 +01:00
|
|
|
* ******************
|
2017-04-20 21:24:20 +02:00
|
|
|
*
|
2017-11-01 10:37:24 +01:00
|
|
|
* A plugin which ensures that only one chat (private or groupchat) is
|
2017-04-20 21:24:20 +02:00
|
|
|
* visible at any one time. All other ongoing chats are hidden and kept in the
|
|
|
|
* background.
|
|
|
|
*
|
2017-11-01 10:37:24 +01:00
|
|
|
* This plugin makes sense in mobile or fullscreen chat environments (as
|
|
|
|
* configured by the `view_mode` setting).
|
|
|
|
*
|
2017-04-20 21:24:20 +02:00
|
|
|
*/
|
|
|
|
(function (root, factory) {
|
|
|
|
define(
|
|
|
|
["converse-core", "converse-chatview"],
|
|
|
|
factory);
|
|
|
|
}(this, function (converse) {
|
|
|
|
"use strict";
|
2017-07-10 17:46:22 +02:00
|
|
|
const { _, Strophe } = converse.env;
|
2017-04-20 21:24:20 +02:00
|
|
|
|
2017-06-10 20:39:09 +02:00
|
|
|
function hideChat (view) {
|
|
|
|
if (view.model.get('id') === 'controlbox') { return; }
|
|
|
|
view.model.save({'hidden': true});
|
|
|
|
view.hide();
|
|
|
|
}
|
|
|
|
|
2017-04-20 21:24:20 +02:00
|
|
|
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,
|
|
|
|
// an error will be raised if the plugin is not found.
|
|
|
|
//
|
|
|
|
// NB: These plugins need to have already been loaded via require.js.
|
2018-02-21 22:40:51 +01:00
|
|
|
dependencies: ['converse-chatboxes', 'converse-muc', 'converse-controlbox', 'converse-rosterview'],
|
2017-04-20 21:24:20 +02:00
|
|
|
|
2017-11-02 15:30:24 +01:00
|
|
|
enabled (_converse) {
|
2018-02-09 16:33:48 +01:00
|
|
|
return _.includes(['mobile', 'fullscreen', 'embedded'], _converse.view_mode);
|
2017-11-02 15:30:24 +01:00
|
|
|
},
|
|
|
|
|
2017-04-20 21:24:20 +02:00
|
|
|
overrides: {
|
|
|
|
// overrides mentioned here will be picked up by converse.js's
|
|
|
|
// plugin architecture they will replace existing methods on the
|
|
|
|
// relevant objects or classes.
|
|
|
|
//
|
|
|
|
// new functions which don't exist yet can also be added.
|
2017-04-21 12:20:26 +02:00
|
|
|
ChatBoxes: {
|
2018-02-21 22:40:51 +01:00
|
|
|
chatBoxMayBeShown (chatbox) {
|
|
|
|
return !chatbox.get('hidden');
|
|
|
|
},
|
|
|
|
|
2017-07-10 17:46:22 +02:00
|
|
|
createChatBox (jid, attrs) {
|
2018-02-21 22:40:51 +01:00
|
|
|
/* Make sure new chat boxes are hidden by default. */
|
2017-11-02 15:30:24 +01:00
|
|
|
attrs = attrs || {};
|
|
|
|
attrs.hidden = true;
|
2017-04-21 12:20:26 +02:00
|
|
|
return this.__super__.createChatBox.call(this, jid, attrs);
|
|
|
|
}
|
|
|
|
},
|
2017-06-15 16:22:49 +02:00
|
|
|
|
2017-04-20 21:24:20 +02:00
|
|
|
ChatBoxView: {
|
2018-03-13 19:11:49 +01:00
|
|
|
shouldShowOnTextMessage () {
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
2018-02-21 22:40:51 +01:00
|
|
|
_show (focus) {
|
2017-04-20 21:24:20 +02:00
|
|
|
/* We only have one chat visible at any one
|
|
|
|
* time. So before opening a chat, we make sure all other
|
|
|
|
* chats are hidden.
|
|
|
|
*/
|
2018-02-21 22:40:51 +01:00
|
|
|
_.each(this.__super__._converse.chatboxviews.xget(this.model.get('id')), hideChat);
|
|
|
|
this.model.set('hidden', false);
|
|
|
|
return this.__super__._show.apply(this, arguments);
|
2017-04-20 21:24:20 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-02-14 13:44:17 +01:00
|
|
|
ChatRoomView: {
|
|
|
|
show (focus) {
|
2018-02-21 22:40:51 +01:00
|
|
|
_.each(this.__super__._converse.chatboxviews.xget(this.model.get('id')), hideChat);
|
|
|
|
this.model.set('hidden', false);
|
|
|
|
return this.__super__.show.apply(this, arguments);
|
2018-02-14 13:44:17 +01:00
|
|
|
}
|
2017-04-20 21:24:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}));
|