2019-07-11 10:48:52 +02:00
|
|
|
/**
|
|
|
|
* @module converse-singleton
|
2019-09-11 15:23:58 +02:00
|
|
|
* @copyright JC Brand
|
|
|
|
* @license Mozilla Public License (MPLv2)
|
|
|
|
* @description A plugin which restricts Converse to only one chat.
|
2017-04-20 21:24:20 +02:00
|
|
|
*/
|
2020-06-03 09:57:14 +02:00
|
|
|
import { api, converse } from "@converse/headless/converse-core";
|
2017-04-20 21:24:20 +02:00
|
|
|
|
2018-09-06 09:44:44 +02:00
|
|
|
|
2018-10-23 03:41:38 +02:00
|
|
|
converse.plugins.add('converse-singleton', {
|
2017-06-15 16:22:49 +02:00
|
|
|
|
2018-12-04 12:52:25 +01:00
|
|
|
enabled (_converse) {
|
2020-03-30 16:29:09 +02:00
|
|
|
return _converse.api.settings.get("singleton");
|
2018-12-04 12:52:25 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
initialize () {
|
|
|
|
/* The initialize function gets called as soon as the plugin is
|
|
|
|
* loaded by converse.js's plugin machinery.
|
|
|
|
*/
|
2020-06-03 09:57:14 +02:00
|
|
|
api.settings.extend({
|
2018-12-04 12:52:25 +01:00
|
|
|
'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
|
|
|
|
});
|
2020-06-03 09:57:14 +02:00
|
|
|
if (!Array.isArray(api.settings.get('auto_join_rooms')) &&
|
|
|
|
!Array.isArray(api.settings.get('auto_join_private_chats'))) {
|
2018-12-04 12:52:25 +01:00
|
|
|
throw new Error("converse-singleton: auto_join_rooms must be an Array");
|
|
|
|
}
|
2020-06-03 09:57:14 +02:00
|
|
|
if (api.settings.get('auto_join_rooms').length > 1 || api.settings.get('auto_join_private_chats').length > 1) {
|
2018-12-04 12:52:25 +01:00
|
|
|
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.");
|
2017-04-20 21:24:20 +02:00
|
|
|
}
|
2018-10-23 03:41:38 +02:00
|
|
|
}
|
|
|
|
});
|