Move settings API from core.js to own file
Move CORE_PLUGINS to `constants.js`
This commit is contained in:
parent
d2a35d4ce1
commit
2bdea0dd18
76
src/headless/api/settings.js
Normal file
76
src/headless/api/settings.js
Normal file
|
@ -0,0 +1,76 @@
|
||||||
|
import log from '@converse/headless/log.js';
|
||||||
|
import { getAppSetting, extendAppSettings, updateAppSettings } from '@converse/headless/shared/settings';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This grouping allows access to the
|
||||||
|
* [configuration settings](/docs/html/configuration.html#configuration-settings)
|
||||||
|
* of Converse.
|
||||||
|
*
|
||||||
|
* @namespace _converse.api.settings
|
||||||
|
* @memberOf _converse.api
|
||||||
|
*/
|
||||||
|
export default {
|
||||||
|
/**
|
||||||
|
* Allows new configuration settings to be specified, or new default values for
|
||||||
|
* existing configuration settings to be specified.
|
||||||
|
*
|
||||||
|
* Note, calling this method *after* converse.initialize has been
|
||||||
|
* called will *not* change the initialization settings provided via
|
||||||
|
* `converse.initialize`.
|
||||||
|
*
|
||||||
|
* @method _converse.api.settings.extend
|
||||||
|
* @param {object} settings The configuration settings
|
||||||
|
* @example
|
||||||
|
* _converse.api.settings.extend({
|
||||||
|
* 'enable_foo': true
|
||||||
|
* });
|
||||||
|
*
|
||||||
|
* // The user can then override the default value of the configuration setting when
|
||||||
|
* // calling `converse.initialize`.
|
||||||
|
* converse.initialize({
|
||||||
|
* 'enable_foo': false
|
||||||
|
* });
|
||||||
|
*/
|
||||||
|
extend (settings) {
|
||||||
|
return extendAppSettings(settings);
|
||||||
|
},
|
||||||
|
|
||||||
|
update (settings) {
|
||||||
|
log.warn(
|
||||||
|
'The api.settings.update method has been deprecated and will be removed. ' +
|
||||||
|
'Please use api.settings.extend instead.'
|
||||||
|
);
|
||||||
|
return this.extend(settings);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @method _converse.api.settings.get
|
||||||
|
* @returns {*} Value of the particular configuration setting.
|
||||||
|
* @example _converse.api.settings.get("play_sounds");
|
||||||
|
*/
|
||||||
|
get (key) {
|
||||||
|
return getAppSetting(key);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set one or many configuration settings.
|
||||||
|
*
|
||||||
|
* Note, this is not an alternative to calling {@link converse.initialize}, which still needs
|
||||||
|
* to be called. Generally, you'd use this method after Converse is already
|
||||||
|
* running and you want to change the configuration on-the-fly.
|
||||||
|
*
|
||||||
|
* @method _converse.api.settings.set
|
||||||
|
* @param {Object} [settings] An object containing configuration settings.
|
||||||
|
* @param {string} [key] Alternatively to passing in an object, you can pass in a key and a value.
|
||||||
|
* @param {string} [value]
|
||||||
|
* @example _converse.api.settings.set("play_sounds", true);
|
||||||
|
* @example
|
||||||
|
* _converse.api.settings.set({
|
||||||
|
* "play_sounds": true,
|
||||||
|
* "hide_offline_users": true
|
||||||
|
* });
|
||||||
|
*/
|
||||||
|
set (key, val) {
|
||||||
|
updateAppSettings(key, val);
|
||||||
|
},
|
||||||
|
};
|
|
@ -13,21 +13,20 @@ import invoke from 'lodash-es/invoke';
|
||||||
import isFunction from 'lodash-es/isFunction';
|
import isFunction from 'lodash-es/isFunction';
|
||||||
import isObject from 'lodash-es/isObject';
|
import isObject from 'lodash-es/isObject';
|
||||||
import localDriver from 'localforage-webextensionstorage-driver/local';
|
import localDriver from 'localforage-webextensionstorage-driver/local';
|
||||||
import log from '@converse/headless/log';
|
import log from '@converse/headless/log.js';
|
||||||
import pluggable from 'pluggable.js/src/pluggable.js';
|
import pluggable from 'pluggable.js/src/pluggable.js';
|
||||||
|
import settings_api from '@converse/headless/api/settings.js';
|
||||||
import sizzle from 'sizzle';
|
import sizzle from 'sizzle';
|
||||||
import syncDriver from 'localforage-webextensionstorage-driver/sync';
|
import syncDriver from 'localforage-webextensionstorage-driver/sync';
|
||||||
import u from '@converse/headless/utils/core';
|
import u from '@converse/headless/utils/core';
|
||||||
|
import { CORE_PLUGINS } from '@converse/headless/shared/constants.js';
|
||||||
import { Collection } from "@converse/skeletor/src/collection";
|
import { Collection } from "@converse/skeletor/src/collection";
|
||||||
import { Connection, MockConnection } from '@converse/headless/shared/connection.js';
|
import { Connection, MockConnection } from '@converse/headless/shared/connection.js';
|
||||||
import { initStorage } from '@converse/headless/shared/utils.js';
|
import { initStorage } from '@converse/headless/shared/utils.js';
|
||||||
import {
|
import {
|
||||||
clearUserSettings,
|
clearUserSettings,
|
||||||
extendAppSettings,
|
|
||||||
getAppSetting,
|
|
||||||
getUserSettings,
|
getUserSettings,
|
||||||
initAppSettings,
|
initAppSettings,
|
||||||
updateAppSettings,
|
|
||||||
updateUserSettings
|
updateUserSettings
|
||||||
} from '@converse/headless/shared/settings';
|
} from '@converse/headless/shared/settings';
|
||||||
import { Events } from '@converse/skeletor/src/events.js';
|
import { Events } from '@converse/skeletor/src/events.js';
|
||||||
|
@ -80,32 +79,6 @@ Strophe.addNamespace('VCARDUPDATE', 'vcard-temp:x:update');
|
||||||
Strophe.addNamespace('XFORM', 'jabber:x:data');
|
Strophe.addNamespace('XFORM', 'jabber:x:data');
|
||||||
Strophe.addNamespace('XHTML', 'http://www.w3.org/1999/xhtml');
|
Strophe.addNamespace('XHTML', 'http://www.w3.org/1999/xhtml');
|
||||||
|
|
||||||
|
|
||||||
// Core plugins are whitelisted automatically
|
|
||||||
// These are just the @converse/headless plugins, for the full converse,
|
|
||||||
// the other plugins are whitelisted in src/converse.js
|
|
||||||
const CORE_PLUGINS = [
|
|
||||||
'converse-adhoc',
|
|
||||||
'converse-bookmarks',
|
|
||||||
'converse-bosh',
|
|
||||||
'converse-caps',
|
|
||||||
'converse-carbons',
|
|
||||||
'converse-chat',
|
|
||||||
'converse-chatboxes',
|
|
||||||
'converse-disco',
|
|
||||||
'converse-emoji',
|
|
||||||
'converse-headlines',
|
|
||||||
'converse-mam',
|
|
||||||
'converse-muc',
|
|
||||||
'converse-ping',
|
|
||||||
'converse-pubsub',
|
|
||||||
'converse-roster',
|
|
||||||
'converse-smacks',
|
|
||||||
'converse-status',
|
|
||||||
'converse-vcard'
|
|
||||||
];
|
|
||||||
|
|
||||||
|
|
||||||
_converse.VERSION_NAME = "v7.0.3dev";
|
_converse.VERSION_NAME = "v7.0.3dev";
|
||||||
|
|
||||||
Object.assign(_converse, Events);
|
Object.assign(_converse, Events);
|
||||||
|
@ -447,77 +420,8 @@ export const api = _converse.api = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
settings: settings_api,
|
||||||
* This grouping allows access to the
|
|
||||||
* [configuration settings](/docs/html/configuration.html#configuration-settings)
|
|
||||||
* of Converse.
|
|
||||||
*
|
|
||||||
* @namespace _converse.api.settings
|
|
||||||
* @memberOf _converse.api
|
|
||||||
*/
|
|
||||||
settings: {
|
|
||||||
/**
|
|
||||||
* Allows new configuration settings to be specified, or new default values for
|
|
||||||
* existing configuration settings to be specified.
|
|
||||||
*
|
|
||||||
* Note, calling this method *after* converse.initialize has been
|
|
||||||
* called will *not* change the initialization settings provided via
|
|
||||||
* `converse.initialize`.
|
|
||||||
*
|
|
||||||
* @method _converse.api.settings.extend
|
|
||||||
* @param {object} settings The configuration settings
|
|
||||||
* @example
|
|
||||||
* _converse.api.settings.extend({
|
|
||||||
* 'enable_foo': true
|
|
||||||
* });
|
|
||||||
*
|
|
||||||
* // The user can then override the default value of the configuration setting when
|
|
||||||
* // calling `converse.initialize`.
|
|
||||||
* converse.initialize({
|
|
||||||
* 'enable_foo': false
|
|
||||||
* });
|
|
||||||
*/
|
|
||||||
extend (settings) {
|
|
||||||
return extendAppSettings(settings);
|
|
||||||
},
|
|
||||||
|
|
||||||
update (settings) {
|
|
||||||
log.warn("The api.settings.update method has been deprecated and will be removed. "+
|
|
||||||
"Please use api.settings.extend instead.");
|
|
||||||
return this.extend(settings);
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @method _converse.api.settings.get
|
|
||||||
* @returns {*} Value of the particular configuration setting.
|
|
||||||
* @example _converse.api.settings.get("play_sounds");
|
|
||||||
*/
|
|
||||||
get (key) {
|
|
||||||
return getAppSetting(key);
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set one or many configuration settings.
|
|
||||||
*
|
|
||||||
* Note, this is not an alternative to calling {@link converse.initialize}, which still needs
|
|
||||||
* to be called. Generally, you'd use this method after Converse is already
|
|
||||||
* running and you want to change the configuration on-the-fly.
|
|
||||||
*
|
|
||||||
* @method _converse.api.settings.set
|
|
||||||
* @param {Object} [settings] An object containing configuration settings.
|
|
||||||
* @param {string} [key] Alternatively to passing in an object, you can pass in a key and a value.
|
|
||||||
* @param {string} [value]
|
|
||||||
* @example _converse.api.settings.set("play_sounds", true);
|
|
||||||
* @example
|
|
||||||
* _converse.api.settings.set({
|
|
||||||
* "play_sounds": true,
|
|
||||||
* "hide_offline_users": true
|
|
||||||
* });
|
|
||||||
*/
|
|
||||||
set (key, val) {
|
|
||||||
updateAppSettings(key, val);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converse and its plugins trigger various events which you can listen to via the
|
* Converse and its plugins trigger various events which you can listen to via the
|
||||||
|
|
|
@ -12,3 +12,27 @@ CONNECTION_STATUS[Strophe.Status.DISCONNECTING] = 'DISCONNECTING';
|
||||||
CONNECTION_STATUS[Strophe.Status.ERROR] = 'ERROR';
|
CONNECTION_STATUS[Strophe.Status.ERROR] = 'ERROR';
|
||||||
CONNECTION_STATUS[Strophe.Status.RECONNECTING] = 'RECONNECTING';
|
CONNECTION_STATUS[Strophe.Status.RECONNECTING] = 'RECONNECTING';
|
||||||
CONNECTION_STATUS[Strophe.Status.REDIRECT] = 'REDIRECT';
|
CONNECTION_STATUS[Strophe.Status.REDIRECT] = 'REDIRECT';
|
||||||
|
|
||||||
|
// Core plugins are whitelisted automatically
|
||||||
|
// These are just the @converse/headless plugins, for the full converse,
|
||||||
|
// the other plugins are whitelisted in src/consts.js
|
||||||
|
export const CORE_PLUGINS = [
|
||||||
|
'converse-adhoc',
|
||||||
|
'converse-bookmarks',
|
||||||
|
'converse-bosh',
|
||||||
|
'converse-caps',
|
||||||
|
'converse-carbons',
|
||||||
|
'converse-chat',
|
||||||
|
'converse-chatboxes',
|
||||||
|
'converse-disco',
|
||||||
|
'converse-emoji',
|
||||||
|
'converse-headlines',
|
||||||
|
'converse-mam',
|
||||||
|
'converse-muc',
|
||||||
|
'converse-ping',
|
||||||
|
'converse-pubsub',
|
||||||
|
'converse-roster',
|
||||||
|
'converse-smacks',
|
||||||
|
'converse-status',
|
||||||
|
'converse-vcard'
|
||||||
|
];
|
||||||
|
|
Loading…
Reference in New Issue
Block a user