From d44abbb48e8c1421c2173ca1b9e19e1ac4017b55 Mon Sep 17 00:00:00 2001 From: Ariel Fuggini Date: Fri, 10 Sep 2021 09:12:46 -0500 Subject: [PATCH] Adds hook to fetchLoginCredentials function (#2640) * Adds hook to fetchLoginCredentials function * Adds documentation --- CHANGES.md | 1 + src/headless/utils/init.js | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 6959072d1..bf85189a9 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -9,6 +9,7 @@ - #2634: Image previews not loading when not serving Converse locally - #2636: Don't fail when setting up a new XEP-0198 managed stream and `_converse.session` is undefined - Bugfix: Don't show minimized chats when logged out +- #2640: Adds `beforeFetchLoginCredentials` hook ## 8.0.0 (2021-09-03) diff --git a/src/headless/utils/init.js b/src/headless/utils/init.js index 5893ca54d..50ed4eb9b 100644 --- a/src/headless/utils/init.js +++ b/src/headless/utils/init.js @@ -230,8 +230,8 @@ async function getLoginCredentials () { function fetchLoginCredentials (wait=0) { return new Promise( - debounce((resolve, reject) => { - const xhr = new XMLHttpRequest(); + debounce(async (resolve, reject) => { + let xhr = new XMLHttpRequest(); xhr.open('GET', _converse.api.settings.get("credentials_url"), true); xhr.setRequestHeader('Accept', 'application/json, text/javascript'); xhr.onload = () => { @@ -248,6 +248,11 @@ function fetchLoginCredentials (wait=0) { } }; xhr.onerror = reject; + /** + * *Hook* which allows modifying the server request + * @event _converse#beforeFetchLoginCredentials + */ + xhr = await _converse.api.hook('beforeFetchLoginCredentials', this, xhr); xhr.send(); }, wait) );