Commit 4e7b29e4 authored by JC Brand's avatar JC Brand

Make sure `initialize` can be awaited...

before `converse.initialize` has been called

In the process, remove other "core" promises. There is no core or
community plugins code awaiting on them and since it's possible to
call `converse.initialize` twice, I'm not sure it makes sense to even have them.

Also removed unused error class IllegalMessage.
parent cb53c867
...@@ -5069,9 +5069,9 @@ ...@@ -5069,9 +5069,9 @@
} }
}, },
"@octokit/types": { "@octokit/types": {
"version": "5.4.0", "version": "5.4.1",
"resolved": "https://registry.npmjs.org/@octokit/types/-/types-5.4.0.tgz", "resolved": "https://registry.npmjs.org/@octokit/types/-/types-5.4.1.tgz",
"integrity": "sha512-D/uotqF69M50OIlwMqgyIg9PuLT2daOiBAYF0P40I2ekFA2ESwwBY5dxZe/UhXdPvIbNKDzuZmQrO7rMpuFbcg==", "integrity": "sha512-OlMlSySBJoJ6uozkr/i03nO5dlYQyE05vmQNZhAh9MyO4DPBP88QlwsDVLmVjIMFssvIZB6WO0ctIGMRG+xsJQ==",
"dev": true, "dev": true,
"requires": { "requires": {
"@types/node": ">= 8" "@types/node": ">= 8"
...@@ -8880,9 +8880,9 @@ ...@@ -8880,9 +8880,9 @@
} }
}, },
"dot-prop": { "dot-prop": {
"version": "4.2.0", "version": "4.2.1",
"resolved": "https://registry.npmjs.org/dot-prop/-/dot-prop-4.2.0.tgz", "resolved": "https://registry.npmjs.org/dot-prop/-/dot-prop-4.2.1.tgz",
"integrity": "sha512-tUMXrxlExSW6U2EXiiKGSBVdYgtV8qlHL+C10TsW4PURY/ic+eaysnSkwB4kA/mBlCyy/IKDJ+Lc3wbWeaXtuQ==", "integrity": "sha512-l0p4+mIuJIua0mhxGoh4a+iNL9bmeK5DvnSVQa6T0OhrVmaEa1XScX5Etc673FePCJOArq/4Pa2cLGODUWTPOQ==",
"dev": true, "dev": true,
"requires": { "requires": {
"is-obj": "^1.0.0" "is-obj": "^1.0.0"
...@@ -9181,9 +9181,9 @@ ...@@ -9181,9 +9181,9 @@
"dev": true "dev": true
}, },
"envinfo": { "envinfo": {
"version": "7.7.2", "version": "7.7.3",
"resolved": "https://registry.npmjs.org/envinfo/-/envinfo-7.7.2.tgz", "resolved": "https://registry.npmjs.org/envinfo/-/envinfo-7.7.3.tgz",
"integrity": "sha512-k3Eh5bKuQnZjm49/L7H4cHzs2FlL5QjbTB3JrPxoTI8aJG7hVMe4uKyJxSYH4ahseby2waUwk5OaKX/nAsaYgg==", "integrity": "sha512-46+j5QxbPWza0PB1i15nZx0xQ4I/EfQxg9J8Had3b408SV63nEtor2e+oiY63amTo9KTuh2a3XLObNwduxYwwA==",
"dev": true "dev": true
}, },
"err-code": { "err-code": {
...@@ -13126,6 +13126,12 @@ ...@@ -13126,6 +13126,12 @@
"integrity": "sha512-mrqyZKfX5EhL7hvqcV6WG1yYjnjeuYDzDhhcAAUrq8Po85NBQBJP+ZDUT75qZQ98IkUoBqdkExkukOU7Ts2wrw==", "integrity": "sha512-mrqyZKfX5EhL7hvqcV6WG1yYjnjeuYDzDhhcAAUrq8Po85NBQBJP+ZDUT75qZQ98IkUoBqdkExkukOU7Ts2wrw==",
"dev": true "dev": true
}, },
"json-parse-even-better-errors": {
"version": "2.3.1",
"resolved": "https://registry.npmjs.org/json-parse-even-better-errors/-/json-parse-even-better-errors-2.3.1.tgz",
"integrity": "sha512-xyFwyhro/JEof6Ghe2iz2NcXoj2sloNsWr/XsERDK/oiPCfaNhl5ONfp+jQdAZRQQ0IJWNzH9zIZF7li91kh2w==",
"dev": true
},
"json-schema": { "json-schema": {
"version": "0.2.3", "version": "0.2.3",
"resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.2.3.tgz", "resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.2.3.tgz",
...@@ -14118,9 +14124,9 @@ ...@@ -14118,9 +14124,9 @@
} }
}, },
"meow": { "meow": {
"version": "7.1.0", "version": "7.1.1",
"resolved": "https://registry.npmjs.org/meow/-/meow-7.1.0.tgz", "resolved": "https://registry.npmjs.org/meow/-/meow-7.1.1.tgz",
"integrity": "sha512-kq5F0KVteskZ3JdfyQFivJEj2RaA8NFsS4+r9DaMKLcUHpk5OcHS3Q0XkCXONB1mZRPsu/Y/qImKri0nwSEZog==", "integrity": "sha512-GWHvA5QOcS412WCo8vwKDlTelGLsCGBVevQB5Kva961rmNfun0PCbv5+xta2kUMFJyR8/oWnn7ddeKdosbAPbA==",
"dev": true, "dev": true,
"requires": { "requires": {
"@types/minimist": "^1.2.0", "@types/minimist": "^1.2.0",
...@@ -14165,14 +14171,14 @@ ...@@ -14165,14 +14171,14 @@
} }
}, },
"parse-json": { "parse-json": {
"version": "5.0.1", "version": "5.1.0",
"resolved": "https://registry.npmjs.org/parse-json/-/parse-json-5.0.1.tgz", "resolved": "https://registry.npmjs.org/parse-json/-/parse-json-5.1.0.tgz",
"integrity": "sha512-ztoZ4/DYeXQq4E21v169sC8qWINGpcosGv9XhTDvg9/hWvx/zrFkc9BiWxR58OJLHGk28j5BL0SDLeV2WmFZlQ==", "integrity": "sha512-+mi/lmVVNKFNVyLXV31ERiy2CY5E1/F6QtJFEzoChPRwwngMNXRDQ9GJ5WdE2Z2P4AujsOi0/+2qHID68KwfIQ==",
"dev": true, "dev": true,
"requires": { "requires": {
"@babel/code-frame": "^7.0.0", "@babel/code-frame": "^7.0.0",
"error-ex": "^1.3.1", "error-ex": "^1.3.1",
"json-parse-better-errors": "^1.0.1", "json-parse-even-better-errors": "^2.3.0",
"lines-and-columns": "^1.1.6" "lines-and-columns": "^1.1.6"
} }
}, },
...@@ -20643,14 +20649,13 @@ ...@@ -20643,14 +20649,13 @@
} }
}, },
"read-package-json": { "read-package-json": {
"version": "2.1.1", "version": "2.1.2",
"resolved": "https://registry.npmjs.org/read-package-json/-/read-package-json-2.1.1.tgz", "resolved": "https://registry.npmjs.org/read-package-json/-/read-package-json-2.1.2.tgz",
"integrity": "sha512-dAiqGtVc/q5doFz6096CcnXhpYk0ZN8dEKVkGLU0CsASt8SrgF6SF7OTKAYubfvFhWaqofl+Y8HK19GR8jwW+A==", "integrity": "sha512-D1KmuLQr6ZSJS0tW8hf3WGpRlwszJOXZ3E8Yd/DNRaM5d+1wVRZdHlpGBLAuovjr28LbWvjpWkBHMxpRGGjzNA==",
"dev": true, "dev": true,
"requires": { "requires": {
"glob": "^7.1.1", "glob": "^7.1.1",
"graceful-fs": "^4.1.2", "json-parse-even-better-errors": "^2.3.0",
"json-parse-better-errors": "^1.0.1",
"normalize-package-data": "^2.0.0", "normalize-package-data": "^2.0.0",
"npm-normalize-package-bin": "^1.0.0" "npm-normalize-package-bin": "^1.0.0"
} }
......
import { converse } from "@converse/headless/converse-core"; import { api, converse } from "@converse/headless/converse-core";
/** /**
...@@ -10,7 +10,8 @@ import { converse } from "@converse/headless/converse-core"; ...@@ -10,7 +10,8 @@ import { converse } from "@converse/headless/converse-core";
*/ */
class ConverseRoot extends HTMLElement { class ConverseRoot extends HTMLElement {
connectedCallback () { async connectedCallback () {
await api.waitUntil('initialized');
converse.insertInto(this); converse.insertInto(this);
} }
} }
......
...@@ -49,7 +49,6 @@ converse.plugins.add('converse-chatboxviews', { ...@@ -49,7 +49,6 @@ converse.plugins.add('converse-chatboxviews', {
/* The initialize function gets called as soon as the plugin is /* The initialize function gets called as soon as the plugin is
* loaded by converse.js's plugin machinery. * loaded by converse.js's plugin machinery.
*/ */
api.elements.register(); api.elements.register();
api.promises.add(['chatBoxViewsInitialized']); api.promises.add(['chatBoxViewsInitialized']);
......
...@@ -68,10 +68,7 @@ converse.plugins.add('converse-rosterview', { ...@@ -68,10 +68,7 @@ converse.plugins.add('converse-rosterview', {
toHTML () { toHTML () {
const label_nickname = api.settings.get('xhr_user_search_url') ? __('Contact name') : __('Optional nickname'); const label_nickname = api.settings.get('xhr_user_search_url') ? __('Contact name') : __('Optional nickname');
return tpl_add_contact_modal(Object.assign(this.model.toJSON(), { return tpl_add_contact_modal(Object.assign(this.model.toJSON(), { _converse, label_nickname }));
'_converse': _converse,
'label_nickname': label_nickname,
}));
}, },
afterRender () { afterRender () {
......
...@@ -151,12 +151,6 @@ export class Connection extends Strophe.Connection { ...@@ -151,12 +151,6 @@ export class Connection extends Strophe.Connection {
*/ */
api.trigger('reconnected'); api.trigger('reconnected');
} else { } else {
/**
* Triggered once converse.js has been initialized.
* See also {@link _converse#event:pluginsInitialized}.
* @event _converse#initialized
*/
api.trigger('initialized');
/** /**
* Triggered after the connection has been established and Converse * Triggered after the connection has been established and Converse
* has got all its ducks in a row. * has got all its ducks in a row.
......
...@@ -74,19 +74,6 @@ _.templateSettings = { ...@@ -74,19 +74,6 @@ _.templateSettings = {
class TimeoutError extends Error {} class TimeoutError extends Error {}
class IllegalMessage extends Error {}
// Setting wait to 59 instead of 60 to avoid timing conflicts with the
// webserver, which is often also set to 60 and might therefore sometimes
// return a 504 error page instead of passing through to the BOSH proxy.
const PROMISES = [
'afterResourceBinding',
'connectionInitialized',
'initialized',
'pluginsInitialized',
];
// Core plugins are whitelisted automatically // Core plugins are whitelisted automatically
// These are just the @converse/headless plugins, for the full converse, // These are just the @converse/headless plugins, for the full converse,
// the other plugins are whitelisted in src/converse.js // the other plugins are whitelisted in src/converse.js
...@@ -174,8 +161,10 @@ CONNECTION_STATUS[Strophe.Status.REDIRECT] = 'REDIRECT'; ...@@ -174,8 +161,10 @@ CONNECTION_STATUS[Strophe.Status.REDIRECT] = 'REDIRECT';
export const _converse = { export const _converse = {
log, log,
CONNECTION_STATUS, CONNECTION_STATUS,
'templates': {}, templates: {},
'promises': {}, promises: {
'initialized': u.getResolveablePromise()
},
STATUS_WEIGHTS: { STATUS_WEIGHTS: {
'offline': 6, 'offline': 6,
...@@ -227,7 +216,6 @@ export const _converse = { ...@@ -227,7 +216,6 @@ export const _converse = {
router: new Router(), router: new Router(),
TimeoutError: TimeoutError, TimeoutError: TimeoutError,
IllegalMessage: IllegalMessage,
isTestEnv: () => { isTestEnv: () => {
return initialization_settings.bosh_service_url === 'montague.lit/http-bind'; return initialization_settings.bosh_service_url === 'montague.lit/http-bind';
...@@ -1023,7 +1011,6 @@ function initPlugins () { ...@@ -1023,7 +1011,6 @@ function initPlugins () {
* @event _converse#pluginsInitialized * @event _converse#pluginsInitialized
* @memberOf _converse * @memberOf _converse
* @example _converse.api.listen.on('pluginsInitialized', () => { ... }); * @example _converse.api.listen.on('pluginsInitialized', () => { ... });
* @example _converse.api.waitUntil('pluginsInitialized').then(() => { ... });
*/ */
_converse.api.trigger('pluginsInitialized'); _converse.api.trigger('pluginsInitialized');
} }
...@@ -1321,6 +1308,9 @@ async function cleanup () { ...@@ -1321,6 +1308,9 @@ async function cleanup () {
_converse.connection?.reset(); _converse.connection?.reset();
_converse.stopListening(); _converse.stopListening();
_converse.off(); _converse.off();
if (_converse.promises['initialized'].isResolved) {
api.promises.add('initialized')
}
} }
...@@ -1529,7 +1519,7 @@ Object.assign(converse, { ...@@ -1529,7 +1519,7 @@ Object.assign(converse, {
*/ */
async initialize (settings) { async initialize (settings) {
await cleanup(); await cleanup();
PROMISES.forEach(name => api.promises.add(name));
setUnloadEvent(); setUnloadEvent();
initSettings(settings); initSettings(settings);
_converse.strict_plugin_dependencies = settings.strict_plugin_dependencies; // Needed by pluggable.js _converse.strict_plugin_dependencies = settings.strict_plugin_dependencies; // Needed by pluggable.js
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment