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 @@
}
},
"@octokit/types": {
"version": "5.4.0",
"resolved": "https://registry.npmjs.org/@octokit/types/-/types-5.4.0.tgz",
"integrity": "sha512-D/uotqF69M50OIlwMqgyIg9PuLT2daOiBAYF0P40I2ekFA2ESwwBY5dxZe/UhXdPvIbNKDzuZmQrO7rMpuFbcg==",
"version": "5.4.1",
"resolved": "https://registry.npmjs.org/@octokit/types/-/types-5.4.1.tgz",
"integrity": "sha512-OlMlSySBJoJ6uozkr/i03nO5dlYQyE05vmQNZhAh9MyO4DPBP88QlwsDVLmVjIMFssvIZB6WO0ctIGMRG+xsJQ==",
"dev": true,
"requires": {
"@types/node": ">= 8"
......@@ -8880,9 +8880,9 @@
}
},
"dot-prop": {
"version": "4.2.0",
"resolved": "https://registry.npmjs.org/dot-prop/-/dot-prop-4.2.0.tgz",
"integrity": "sha512-tUMXrxlExSW6U2EXiiKGSBVdYgtV8qlHL+C10TsW4PURY/ic+eaysnSkwB4kA/mBlCyy/IKDJ+Lc3wbWeaXtuQ==",
"version": "4.2.1",
"resolved": "https://registry.npmjs.org/dot-prop/-/dot-prop-4.2.1.tgz",
"integrity": "sha512-l0p4+mIuJIua0mhxGoh4a+iNL9bmeK5DvnSVQa6T0OhrVmaEa1XScX5Etc673FePCJOArq/4Pa2cLGODUWTPOQ==",
"dev": true,
"requires": {
"is-obj": "^1.0.0"
......@@ -9181,9 +9181,9 @@
"dev": true
},
"envinfo": {
"version": "7.7.2",
"resolved": "https://registry.npmjs.org/envinfo/-/envinfo-7.7.2.tgz",
"integrity": "sha512-k3Eh5bKuQnZjm49/L7H4cHzs2FlL5QjbTB3JrPxoTI8aJG7hVMe4uKyJxSYH4ahseby2waUwk5OaKX/nAsaYgg==",
"version": "7.7.3",
"resolved": "https://registry.npmjs.org/envinfo/-/envinfo-7.7.3.tgz",
"integrity": "sha512-46+j5QxbPWza0PB1i15nZx0xQ4I/EfQxg9J8Had3b408SV63nEtor2e+oiY63amTo9KTuh2a3XLObNwduxYwwA==",
"dev": true
},
"err-code": {
......@@ -13126,6 +13126,12 @@
"integrity": "sha512-mrqyZKfX5EhL7hvqcV6WG1yYjnjeuYDzDhhcAAUrq8Po85NBQBJP+ZDUT75qZQ98IkUoBqdkExkukOU7Ts2wrw==",
"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": {
"version": "0.2.3",
"resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.2.3.tgz",
......@@ -14118,9 +14124,9 @@
}
},
"meow": {
"version": "7.1.0",
"resolved": "https://registry.npmjs.org/meow/-/meow-7.1.0.tgz",
"integrity": "sha512-kq5F0KVteskZ3JdfyQFivJEj2RaA8NFsS4+r9DaMKLcUHpk5OcHS3Q0XkCXONB1mZRPsu/Y/qImKri0nwSEZog==",
"version": "7.1.1",
"resolved": "https://registry.npmjs.org/meow/-/meow-7.1.1.tgz",
"integrity": "sha512-GWHvA5QOcS412WCo8vwKDlTelGLsCGBVevQB5Kva961rmNfun0PCbv5+xta2kUMFJyR8/oWnn7ddeKdosbAPbA==",
"dev": true,
"requires": {
"@types/minimist": "^1.2.0",
......@@ -14165,14 +14171,14 @@
}
},
"parse-json": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/parse-json/-/parse-json-5.0.1.tgz",
"integrity": "sha512-ztoZ4/DYeXQq4E21v169sC8qWINGpcosGv9XhTDvg9/hWvx/zrFkc9BiWxR58OJLHGk28j5BL0SDLeV2WmFZlQ==",
"version": "5.1.0",
"resolved": "https://registry.npmjs.org/parse-json/-/parse-json-5.1.0.tgz",
"integrity": "sha512-+mi/lmVVNKFNVyLXV31ERiy2CY5E1/F6QtJFEzoChPRwwngMNXRDQ9GJ5WdE2Z2P4AujsOi0/+2qHID68KwfIQ==",
"dev": true,
"requires": {
"@babel/code-frame": "^7.0.0",
"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"
}
},
......@@ -20643,14 +20649,13 @@
}
},
"read-package-json": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/read-package-json/-/read-package-json-2.1.1.tgz",
"integrity": "sha512-dAiqGtVc/q5doFz6096CcnXhpYk0ZN8dEKVkGLU0CsASt8SrgF6SF7OTKAYubfvFhWaqofl+Y8HK19GR8jwW+A==",
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/read-package-json/-/read-package-json-2.1.2.tgz",
"integrity": "sha512-D1KmuLQr6ZSJS0tW8hf3WGpRlwszJOXZ3E8Yd/DNRaM5d+1wVRZdHlpGBLAuovjr28LbWvjpWkBHMxpRGGjzNA==",
"dev": true,
"requires": {
"glob": "^7.1.1",
"graceful-fs": "^4.1.2",
"json-parse-better-errors": "^1.0.1",
"json-parse-even-better-errors": "^2.3.0",
"normalize-package-data": "^2.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";
*/
class ConverseRoot extends HTMLElement {
connectedCallback () {
async connectedCallback () {
await api.waitUntil('initialized');
converse.insertInto(this);
}
}
......
......@@ -49,7 +49,6 @@ converse.plugins.add('converse-chatboxviews', {
/* The initialize function gets called as soon as the plugin is
* loaded by converse.js's plugin machinery.
*/
api.elements.register();
api.promises.add(['chatBoxViewsInitialized']);
......
......@@ -68,10 +68,7 @@ converse.plugins.add('converse-rosterview', {
toHTML () {
const label_nickname = api.settings.get('xhr_user_search_url') ? __('Contact name') : __('Optional nickname');
return tpl_add_contact_modal(Object.assign(this.model.toJSON(), {
'_converse': _converse,
'label_nickname': label_nickname,
}));
return tpl_add_contact_modal(Object.assign(this.model.toJSON(), { _converse, label_nickname }));
},
afterRender () {
......
......@@ -151,12 +151,6 @@ export class Connection extends Strophe.Connection {
*/
api.trigger('reconnected');
} 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
* has got all its ducks in a row.
......
......@@ -74,19 +74,6 @@ _.templateSettings = {
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
// These are just the @converse/headless plugins, for the full converse,
// the other plugins are whitelisted in src/converse.js
......@@ -174,8 +161,10 @@ CONNECTION_STATUS[Strophe.Status.REDIRECT] = 'REDIRECT';
export const _converse = {
log,
CONNECTION_STATUS,
'templates': {},
'promises': {},
templates: {},
promises: {
'initialized': u.getResolveablePromise()
},
STATUS_WEIGHTS: {
'offline': 6,
......@@ -227,7 +216,6 @@ export const _converse = {
router: new Router(),
TimeoutError: TimeoutError,
IllegalMessage: IllegalMessage,
isTestEnv: () => {
return initialization_settings.bosh_service_url === 'montague.lit/http-bind';
......@@ -1023,7 +1011,6 @@ function initPlugins () {
* @event _converse#pluginsInitialized
* @memberOf _converse
* @example _converse.api.listen.on('pluginsInitialized', () => { ... });
* @example _converse.api.waitUntil('pluginsInitialized').then(() => { ... });
*/
_converse.api.trigger('pluginsInitialized');
}
......@@ -1321,6 +1308,9 @@ async function cleanup () {
_converse.connection?.reset();
_converse.stopListening();
_converse.off();
if (_converse.promises['initialized'].isResolved) {
api.promises.add('initialized')
}
}
......@@ -1529,7 +1519,7 @@ Object.assign(converse, {
*/
async initialize (settings) {
await cleanup();
PROMISES.forEach(name => api.promises.add(name));
setUnloadEvent();
initSettings(settings);
_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