settings.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import log from '@converse/headless/log.js';
  2. import { getAppSetting, extendAppSettings, updateAppSettings } from '@converse/headless/shared/settings';
  3. /**
  4. * This grouping allows access to the
  5. * [configuration settings](/docs/html/configuration.html#configuration-settings)
  6. * of Converse.
  7. *
  8. * @namespace _converse.api.settings
  9. * @memberOf _converse.api
  10. */
  11. export default {
  12. /**
  13. * Allows new configuration settings to be specified, or new default values for
  14. * existing configuration settings to be specified.
  15. *
  16. * Note, calling this method *after* converse.initialize has been
  17. * called will *not* change the initialization settings provided via
  18. * `converse.initialize`.
  19. *
  20. * @method _converse.api.settings.extend
  21. * @param {object} settings The configuration settings
  22. * @example
  23. * _converse.api.settings.extend({
  24. * 'enable_foo': true
  25. * });
  26. *
  27. * // The user can then override the default value of the configuration setting when
  28. * // calling `converse.initialize`.
  29. * converse.initialize({
  30. * 'enable_foo': false
  31. * });
  32. */
  33. extend (settings) {
  34. return extendAppSettings(settings);
  35. },
  36. update (settings) {
  37. log.warn(
  38. 'The api.settings.update method has been deprecated and will be removed. ' +
  39. 'Please use api.settings.extend instead.'
  40. );
  41. return this.extend(settings);
  42. },
  43. /**
  44. * @method _converse.api.settings.get
  45. * @returns {*} Value of the particular configuration setting.
  46. * @example _converse.api.settings.get("play_sounds");
  47. */
  48. get (key) {
  49. return getAppSetting(key);
  50. },
  51. /**
  52. * Set one or many configuration settings.
  53. *
  54. * Note, this is not an alternative to calling {@link converse.initialize}, which still needs
  55. * to be called. Generally, you'd use this method after Converse is already
  56. * running and you want to change the configuration on-the-fly.
  57. *
  58. * @method _converse.api.settings.set
  59. * @param {Object} [settings] An object containing configuration settings.
  60. * @param {string} [key] Alternatively to passing in an object, you can pass in a key and a value.
  61. * @param {string} [value]
  62. * @example _converse.api.settings.set("play_sounds", true);
  63. * @example
  64. * _converse.api.settings.set({
  65. * "play_sounds": true,
  66. * "hide_offline_users": true
  67. * });
  68. */
  69. set (key, val) {
  70. updateAppSettings(key, val);
  71. },
  72. };