From 5e8843e8bdccbdbd77d1fefbfe46a28e8ad01aff Mon Sep 17 00:00:00 2001 From: JC Brand Date: Mon, 26 Mar 2018 16:35:32 +0200 Subject: [PATCH] `xhr_user_search_url` fixes after some real world testing --- src/converse-rosterview.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/converse-rosterview.js b/src/converse-rosterview.js index dc1b6e038..554e8d5e5 100644 --- a/src/converse-rosterview.js +++ b/src/converse-rosterview.js @@ -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); - awesomplete.evaluate(); + 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, {