2022-12-28 21:36:40 +01:00
|
|
|
import i18n from './i18n.js';
|
|
|
|
import log from '../log.js';
|
2023-02-26 16:46:31 +01:00
|
|
|
import pluggable from 'pluggable.js/src/pluggable.js';
|
2023-02-26 10:39:57 +01:00
|
|
|
import { Events } from '@converse/skeletor/src/events.js';
|
2021-03-09 12:55:44 +01:00
|
|
|
import { Router } from '@converse/skeletor/src/router.js';
|
2022-12-28 21:36:40 +01:00
|
|
|
import { createStore, getDefaultStore } from '../utils/storage.js';
|
|
|
|
import { getInitSettings } from './settings/utils.js';
|
2021-04-28 18:35:08 +02:00
|
|
|
import { getOpenPromise } from '@converse/openpromise';
|
2023-02-26 18:04:20 +01:00
|
|
|
import { shouldClearCache } from '../utils/core.js';
|
2021-03-09 12:55:44 +01:00
|
|
|
|
2023-03-02 12:18:26 +01:00
|
|
|
import {
|
|
|
|
ACTIVE,
|
|
|
|
ANONYMOUS,
|
|
|
|
CHATROOMS_TYPE,
|
|
|
|
CLOSED,
|
|
|
|
COMPOSING,
|
|
|
|
CONTROLBOX_TYPE,
|
|
|
|
DEFAULT_IMAGE,
|
|
|
|
DEFAULT_IMAGE_TYPE,
|
|
|
|
EXTERNAL,
|
|
|
|
FAILURE,
|
|
|
|
GONE,
|
|
|
|
HEADLINES_TYPE,
|
|
|
|
INACTIVE,
|
|
|
|
LOGIN,
|
|
|
|
LOGOUT,
|
|
|
|
OPENED,
|
|
|
|
PAUSED,
|
|
|
|
PREBIND,
|
|
|
|
PRIVATE_CHAT_TYPE,
|
|
|
|
SUCCESS,
|
|
|
|
VERSION_NAME
|
|
|
|
} from './constants';
|
|
|
|
|
2021-03-09 12:55:44 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A private, closured object containing the private api (via {@link _converse.api})
|
|
|
|
* as well as private methods and internal data-structures.
|
|
|
|
* @global
|
|
|
|
* @namespace _converse
|
|
|
|
*/
|
|
|
|
const _converse = {
|
|
|
|
log,
|
2023-02-26 18:04:20 +01:00
|
|
|
|
2023-03-02 09:08:22 +01:00
|
|
|
shouldClearCache, // TODO: Should be moved to utils with next major release
|
2023-02-26 16:46:31 +01:00
|
|
|
VERSION_NAME,
|
2023-02-26 18:04:20 +01:00
|
|
|
|
2021-03-09 12:55:44 +01:00
|
|
|
templates: {},
|
|
|
|
promises: {
|
2021-04-28 18:35:08 +02:00
|
|
|
'initialized': getOpenPromise()
|
2021-03-09 12:55:44 +01:00
|
|
|
},
|
|
|
|
|
2023-03-02 12:18:26 +01:00
|
|
|
// TODO: remove constants in next major release
|
|
|
|
ANONYMOUS,
|
|
|
|
CLOSED,
|
|
|
|
EXTERNAL,
|
|
|
|
LOGIN,
|
|
|
|
LOGOUT,
|
|
|
|
OPENED,
|
|
|
|
PREBIND,
|
|
|
|
|
|
|
|
SUCCESS,
|
|
|
|
FAILURE,
|
|
|
|
|
|
|
|
DEFAULT_IMAGE_TYPE,
|
|
|
|
DEFAULT_IMAGE,
|
2021-03-09 12:55:44 +01:00
|
|
|
|
2023-03-02 12:18:26 +01:00
|
|
|
INACTIVE,
|
|
|
|
ACTIVE,
|
|
|
|
COMPOSING,
|
|
|
|
PAUSED,
|
|
|
|
GONE,
|
2021-03-09 12:55:44 +01:00
|
|
|
|
2023-03-02 12:18:26 +01:00
|
|
|
PRIVATE_CHAT_TYPE,
|
|
|
|
CHATROOMS_TYPE,
|
|
|
|
HEADLINES_TYPE,
|
|
|
|
CONTROLBOX_TYPE,
|
2021-03-09 12:55:44 +01:00
|
|
|
|
2023-03-02 12:18:26 +01:00
|
|
|
// Set as module attr so that we can override in tests.
|
|
|
|
// TODO: replace with config settings
|
2021-03-09 12:55:44 +01:00
|
|
|
TIMEOUTS: {
|
|
|
|
PAUSED: 10000,
|
|
|
|
INACTIVE: 90000
|
|
|
|
},
|
|
|
|
|
|
|
|
default_connection_options: {'explicitResourceBinding': true},
|
|
|
|
router: new Router(),
|
|
|
|
|
|
|
|
isTestEnv: () => {
|
2021-03-10 12:39:17 +01:00
|
|
|
return getInitSettings()['bosh_service_url'] === 'montague.lit/http-bind';
|
2021-03-09 12:55:44 +01:00
|
|
|
},
|
|
|
|
|
2021-04-22 11:31:04 +02:00
|
|
|
getDefaultStore,
|
|
|
|
createStore,
|
|
|
|
|
2021-03-09 12:55:44 +01:00
|
|
|
/**
|
|
|
|
* Translate the given string based on the current locale.
|
|
|
|
* @method __
|
|
|
|
* @private
|
|
|
|
* @memberOf _converse
|
|
|
|
* @param { String } str
|
|
|
|
*/
|
|
|
|
'__': (...args) => i18n.__(...args),
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A no-op method which is used to signal to gettext that the passed in string
|
|
|
|
* should be included in the pot translation file.
|
|
|
|
*
|
|
|
|
* In contrast to the double-underscore method, the triple underscore method
|
|
|
|
* doesn't actually translate the strings.
|
|
|
|
*
|
|
|
|
* One reason for this method might be because we're using strings we cannot
|
|
|
|
* send to the translation function because they require variable interpolation
|
|
|
|
* and we don't yet have the variables at scan time.
|
|
|
|
*
|
|
|
|
* @method ___
|
|
|
|
* @private
|
|
|
|
* @memberOf _converse
|
|
|
|
* @param { String } str
|
|
|
|
*/
|
|
|
|
'___': str => str
|
|
|
|
}
|
|
|
|
|
2023-02-26 16:46:31 +01:00
|
|
|
// Make _converse an event emitter
|
2023-02-26 10:39:57 +01:00
|
|
|
Object.assign(_converse, Events);
|
|
|
|
|
2023-02-26 16:46:31 +01:00
|
|
|
// Make _converse pluggable
|
|
|
|
pluggable.enable(_converse, '_converse', 'pluggable');
|
|
|
|
|
2021-03-09 12:55:44 +01:00
|
|
|
export default _converse;
|