2
0
Эх сурвалжийг харах

Move settings related files into one directory

JC Brand 3 жил өмнө
parent
commit
864e8910c4

+ 0 - 76
src/headless/api/settings.js

@@ -1,76 +0,0 @@
-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);
-    },
-};

+ 4 - 74
src/headless/core.js

@@ -9,26 +9,20 @@ import dayjs from 'dayjs';
 import i18n from '@converse/headless/shared/i18n';
 import i18n from '@converse/headless/shared/i18n';
 import invoke from 'lodash-es/invoke';
 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 log from '@converse/headless/log.js';
 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 { settings_api, user_settings_api } from '@converse/headless/shared/settings/api.js';
 import sizzle from 'sizzle';
 import sizzle from 'sizzle';
 import u, { setUnloadEvent, replacePromise } from '@converse/headless/utils/core.js';
 import u, { setUnloadEvent, replacePromise } from '@converse/headless/utils/core.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 {
-    clearUserSettings,
-    getUserSettings,
-    initAppSettings,
-    updateUserSettings
-} from '@converse/headless/shared/settings.js';
 import { Events } from '@converse/skeletor/src/events.js';
 import { Events } from '@converse/skeletor/src/events.js';
 import { Model } from '@converse/skeletor/src/model.js';
 import { Model } from '@converse/skeletor/src/model.js';
 import { Strophe, $build, $iq, $msg, $pres } from 'strophe.js/src/strophe';
 import { Strophe, $build, $iq, $msg, $pres } from 'strophe.js/src/strophe';
 import { TimeoutError } from '@converse/headless/shared/errors';
 import { TimeoutError } from '@converse/headless/shared/errors';
 import { getOpenPromise } from '@converse/openpromise';
 import { getOpenPromise } from '@converse/openpromise';
 import { html } from 'lit';
 import { html } from 'lit';
+import { initAppSettings, } from '@converse/headless/shared/settings/utils.js';
 import { sprintf } from 'sprintf-js';
 import { sprintf } from 'sprintf-js';
 
 
 export { _converse };
 export { _converse };
@@ -270,6 +264,8 @@ export const api = _converse.api = {
      * @memberOf _converse.api
      * @memberOf _converse.api
      */
      */
     user: {
     user: {
+        settings: user_settings_api,
+
         /**
         /**
          * @method _converse.api.user.jid
          * @method _converse.api.user.jid
          * @returns {string} The current user's full JID (Jabber ID)
          * @returns {string} The current user's full JID (Jabber ID)
@@ -355,72 +351,6 @@ export const api = _converse.api = {
                 complete();
                 complete();
             }
             }
             return promise;
             return promise;
-        },
-
-        /**
-         * API for accessing and setting user settings. User settings are
-         * different from the application settings from {@link _converse.api.settings}
-         * because they are per-user and set via user action.
-         * @namespace _converse.api.user.settings
-         * @memberOf _converse.api.user
-         */
-        settings: {
-            /**
-             * Returns the user settings model. Useful when you want to listen for change events.
-             * @async
-             * @method _converse.api.user.settings.getModel
-             * @returns {Promise<Model>}
-             * @example const settings = await _converse.api.user.settings.getModel();
-             */
-            getModel () {
-                return getUserSettings();
-            },
-
-            /**
-             * Get the value of a particular user setting.
-             * @method _converse.api.user.settings.get
-             * @param {String} key - The setting name
-             * @param {*} [fallback] - An optional fallback value if the user setting is undefined
-             * @returns {Promise} Promise which resolves with the value of the particular configuration setting.
-             * @example _converse.api.user.settings.get("foo");
-             */
-            async get (key, fallback) {
-                const user_settings = await getUserSettings();
-                return user_settings.get(key) === undefined ? fallback : user_settings.get(key);
-            },
-
-            /**
-             * Set one or many user settings.
-             * @async
-             * @method _converse.api.user.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.user.settings.set("foo", "bar");
-             * @example
-             * _converse.api.user.settings.set({
-             *     "foo": "bar",
-             *     "baz": "buz"
-             * });
-             */
-            set (key, val) {
-                if (isObject(key)) {
-                    return updateUserSettings(key, {'promise': true});
-                } else {
-                    const o = {};
-                    o[key] = val;
-                    return updateUserSettings(o, {'promise': true});
-                }
-            },
-
-            /**
-             * Clears all the user settings
-             * @async
-             * @method _converse.api.user.settings.clear
-             */
-            clear () {
-                return clearUserSettings();
-            }
         }
         }
     },
     },
 
 

+ 1 - 1
src/headless/shared/_converse.js

@@ -4,7 +4,7 @@ import { CONNECTION_STATUS } from '@converse/headless/shared/constants';
 import { Router } from '@converse/skeletor/src/router.js';
 import { Router } from '@converse/skeletor/src/router.js';
 import { TimeoutError } from '@converse/headless/shared/errors';
 import { TimeoutError } from '@converse/headless/shared/errors';
 import { createStore, getDefaultStore } from '@converse/headless/utils/storage.js';
 import { createStore, getDefaultStore } from '@converse/headless/utils/storage.js';
-import { getInitSettings } from '@converse/headless/shared/settings';
+import { getInitSettings } from '@converse/headless/shared/settings/utils.js';
 import { getOpenPromise } from '@converse/openpromise';
 import { getOpenPromise } from '@converse/openpromise';
 
 
 
 

+ 151 - 0
src/headless/shared/settings/api.js

@@ -0,0 +1,151 @@
+import isObject from 'lodash-es/isObject';
+import log from '@converse/headless/log.js';
+import {
+    clearUserSettings,
+    extendAppSettings,
+    getAppSetting,
+    getUserSettings,
+    updateAppSettings,
+    updateUserSettings,
+} from '@converse/headless/shared/settings/utils.js';
+
+/**
+ * This grouping allows access to the
+ * [configuration settings](/docs/html/configuration.html#configuration-settings)
+ * of Converse.
+ *
+ * @namespace _converse.api.settings
+ * @memberOf _converse.api
+ */
+export const settings_api = {
+    /**
+     * 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);
+    },
+};
+
+
+/**
+ * API for accessing and setting user settings. User settings are
+ * different from the application settings from {@link _converse.api.settings}
+ * because they are per-user and set via user action.
+ * @namespace _converse.api.user.settings
+ * @memberOf _converse.api.user
+ */
+export const user_settings_api = {
+    /**
+     * Returns the user settings model. Useful when you want to listen for change events.
+     * @async
+     * @method _converse.api.user.settings.getModel
+     * @returns {Promise<Model>}
+     * @example const settings = await _converse.api.user.settings.getModel();
+     */
+    getModel () {
+        return getUserSettings();
+    },
+
+    /**
+     * Get the value of a particular user setting.
+     * @method _converse.api.user.settings.get
+     * @param {String} key - The setting name
+     * @param {*} [fallback] - An optional fallback value if the user setting is undefined
+     * @returns {Promise} Promise which resolves with the value of the particular configuration setting.
+     * @example _converse.api.user.settings.get("foo");
+     */
+    async get (key, fallback) {
+        const user_settings = await getUserSettings();
+        return user_settings.get(key) === undefined ? fallback : user_settings.get(key);
+    },
+
+    /**
+     * Set one or many user settings.
+     * @async
+     * @method _converse.api.user.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.user.settings.set("foo", "bar");
+     * @example
+     * _converse.api.user.settings.set({
+     *     "foo": "bar",
+     *     "baz": "buz"
+     * });
+     */
+    set (key, val) {
+        if (isObject(key)) {
+            return updateUserSettings(key, {'promise': true});
+        } else {
+            const o = {};
+            o[key] = val;
+            return updateUserSettings(o, {'promise': true});
+        }
+    },
+
+    /**
+     * Clears all the user settings
+     * @async
+     * @method _converse.api.user.settings.clear
+     */
+    clear () {
+        return clearUserSettings();
+    }
+}

+ 39 - 0
src/headless/shared/settings/constants.js

@@ -0,0 +1,39 @@
+
+// Default configuration values
+// ----------------------------
+export const DEFAULT_SETTINGS = {
+    allow_non_roster_messaging: false,
+    allow_url_history_change: true,
+    assets_path: '/dist',
+    authentication: 'login', // Available values are "login", "prebind", "anonymous" and "external".
+    auto_login: false, // Currently only used in connection with anonymous login
+    auto_reconnect: true,
+    blacklisted_plugins: [],
+    clear_cache_on_logout: false,
+    connection_options: {},
+    credentials_url: null, // URL from where login credentials can be fetched
+    discover_connection_methods: true,
+    geouri_regex: /https\:\/\/www.openstreetmap.org\/.*#map=[0-9]+\/([\-0-9.]+)\/([\-0-9.]+)\S*/g,
+    geouri_replacement: 'https://www.openstreetmap.org/?mlat=$1&mlon=$2#map=18/$1/$2',
+    i18n: undefined,
+    idle_presence_timeout: 300, // Seconds after which an idle presence is sent
+    jid: undefined,
+    keepalive: true,
+    loglevel: 'info',
+    locales: [
+        'af', 'ar', 'bg', 'ca', 'cs', 'da', 'de', 'el', 'eo', 'es', 'eu', 'en', 'fa', 'fi', 'fr',
+        'gl', 'he', 'hi', 'hu', 'id', 'it', 'ja', 'lt', 'nb', 'nl', 'mr', 'oc',
+        'pl', 'pt', 'pt_BR', 'ro', 'ru', 'sv', 'th', 'tr', 'uk', 'vi', 'zh_CN', 'zh_TW'
+    ],
+    nickname: undefined,
+    password: undefined,
+    persistent_store: 'IndexedDB',
+    rid: undefined,
+    root: window.document,
+    sid: undefined,
+    singleton: false,
+    strict_plugin_dependencies: false,
+    view_mode: 'overlayed', // Choices are 'overlayed', 'fullscreen', 'mobile'
+    websocket_url: undefined,
+    whitelisted_plugins: []
+};

+ 1 - 40
src/headless/shared/settings.js → src/headless/shared/settings/utils.js

@@ -4,6 +4,7 @@ import isObject from 'lodash-es/isObject';
 import log from '@converse/headless/log';
 import log from '@converse/headless/log';
 import pick from 'lodash-es/pick';
 import pick from 'lodash-es/pick';
 import u from '@converse/headless/utils/core';
 import u from '@converse/headless/utils/core';
+import { DEFAULT_SETTINGS } from './constants.js';
 import { Model } from '@converse/skeletor/src/model.js';
 import { Model } from '@converse/skeletor/src/model.js';
 import { initStorage } from '@converse/headless/utils/storage.js';
 import { initStorage } from '@converse/headless/utils/storage.js';
 
 
@@ -11,46 +12,6 @@ let init_settings = {}; // Container for settings passed in via converse.initial
 let app_settings = {};
 let app_settings = {};
 let user_settings; // User settings, populated via api.users.settings
 let user_settings; // User settings, populated via api.users.settings
 
 
-// Default configuration values
-// ----------------------------
-export const DEFAULT_SETTINGS = {
-    allow_non_roster_messaging: false,
-    allow_url_history_change: true,
-    assets_path: '/dist',
-    authentication: 'login', // Available values are "login", "prebind", "anonymous" and "external".
-    auto_login: false, // Currently only used in connection with anonymous login
-    auto_reconnect: true,
-    blacklisted_plugins: [],
-    clear_cache_on_logout: false,
-    connection_options: {},
-    credentials_url: null, // URL from where login credentials can be fetched
-    discover_connection_methods: true,
-    geouri_regex: /https\:\/\/www.openstreetmap.org\/.*#map=[0-9]+\/([\-0-9.]+)\/([\-0-9.]+)\S*/g,
-    geouri_replacement: 'https://www.openstreetmap.org/?mlat=$1&mlon=$2#map=18/$1/$2',
-    i18n: undefined,
-    idle_presence_timeout: 300, // Seconds after which an idle presence is sent
-    jid: undefined,
-    keepalive: true,
-    loglevel: 'info',
-    locales: [
-        'af', 'ar', 'bg', 'ca', 'cs', 'da', 'de', 'el', 'eo', 'es', 'eu', 'en', 'fa', 'fi', 'fr',
-        'gl', 'he', 'hi', 'hu', 'id', 'it', 'ja', 'lt', 'nb', 'nl', 'mr', 'oc',
-        'pl', 'pt', 'pt_BR', 'ro', 'ru', 'sv', 'th', 'tr', 'uk', 'vi', 'zh_CN', 'zh_TW'
-    ],
-    nickname: undefined,
-    password: undefined,
-    persistent_store: 'IndexedDB',
-    rid: undefined,
-    root: window.document,
-    sid: undefined,
-    singleton: false,
-    strict_plugin_dependencies: false,
-    view_mode: 'overlayed', // Choices are 'overlayed', 'fullscreen', 'mobile'
-    websocket_url: undefined,
-    whitelisted_plugins: []
-};
-
-
 export function getAppSettings () {
 export function getAppSettings () {
     return app_settings;
     return app_settings;
 }
 }