Commit 5e8843e8 authored by JC Brand's avatar JC Brand

`xhr_user_search_url` fixes after some real world testing

parent e21f14f4
......@@ -153,16 +153,21 @@
afterRender () {
const input_el = this.el.querySelector('input[name="jid"]');
if (_converse.xhr_user_search_url && _.isString(_converse.xhr_user_search_url)) {
const awesomplete = new Awesomplete(input_el, {'list': [], 'minChars': 2});
const awesomplete = new Awesomplete(input_el, {'list': []});
const xhr = new window.XMLHttpRequest();
// `open` must be called after `onload` for
// mock/testing purposes.
// `open` must be called after `onload` for mock/testing purposes.
xhr.onload = function () {
awesomplete.list = JSON.parse(xhr.responseText).map((i) => i.jid);
if (xhr.responseText) {
awesomplete.list = JSON.parse(xhr.responseText).map((i) => {
return {'label': i.fullname, 'value': i.jid};
});
awesomplete.evaluate();
}
};
xhr.open("GET", _converse.xhr_user_search_url, true);
input_el.addEventListener('input', _.debounce(() => xhr.send()), 100, {'leading': true});
input_el.addEventListener('input', _.debounce(() => {
xhr.open("GET", `${_converse.xhr_user_search_url}?q=${input_el.value}`, true);
xhr.send()
} , 500));
} else {
const list = _.uniq(_converse.roster.map((item) => Strophe.getDomainFromJid(item.get('jid'))));
new Awesomplete(input_el, {
......
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