xmpp.chapril.org-conversejs/src/converse-singleton.js
JC Brand 830e060568 Rename api.settings.update to api.settings.extend
This is to try and make it clearer that this method won't override
initialization settings, and is instead simply to add to the default
settings.
2020-06-03 09:32:16 +02:00

37 lines
1.5 KiB
JavaScript

/**
* @module converse-singleton
* @copyright JC Brand
* @license Mozilla Public License (MPLv2)
* @description A plugin which restricts Converse to only one chat.
*/
import { converse } from "@converse/headless/converse-core";
converse.plugins.add('converse-singleton', {
enabled (_converse) {
return _converse.api.settings.get("singleton");
},
initialize () {
/* The initialize function gets called as soon as the plugin is
* loaded by converse.js's plugin machinery.
*/
this._converse.api.settings.extend({
'allow_logout': false, // No point in logging out when we have auto_login as true.
'allow_muc_invitations': false, // Doesn't make sense to allow because only
// roster contacts can be invited
'hide_muc_server': true
});
const { _converse } = this;
if (!Array.isArray(_converse.auto_join_rooms) && !Array.isArray(_converse.auto_join_private_chats)) {
throw new Error("converse-singleton: auto_join_rooms must be an Array");
}
if (_converse.auto_join_rooms.length > 1 || _converse.auto_join_private_chats.length > 1) {
throw new Error("It doesn't make sense to have singleton set to true and " +
"auto_join_rooms or auto_join_private_chats set to more then one, " +
"since only one chat room may be open at any time.");
}
}
});