Add option to set the XHR user search URL. Fixes #51

This commit is contained in:
JC Brand 2013-10-20 18:34:20 +02:00
parent 25dc4a27e2
commit 81f4d19a64
2 changed files with 82 additions and 32 deletions

View File

@ -74,7 +74,9 @@
this.show_toolbar = true;
this.testing = false; // Exposes sensitive data for testing. Never set to true in production systems!
this.xhr_custom_status = false;
this.xhr_custom_status_url = '';
this.xhr_user_search = false;
this.xhr_user_search_url = '';
// Allow only whitelisted configuration attributes to be overwritten
_.extend(this, _.pick(settings, [
@ -100,7 +102,9 @@
'sid',
'testing',
'xhr_custom_status',
'xhr_user_search'
'xhr_custom_status_url',
'xhr_user_search',
'xhr_user_search_url'
]));
// Translation machinery
@ -1330,7 +1334,7 @@
searchContacts: function (ev) {
ev.preventDefault();
$.getJSON(portal_url + "/search-users?q=" + $(ev.target).find('input.username').val(), function (data) {
$.getJSON(xhr_user_search_url+ "?q=" + $(ev.target).find('input.username').val(), function (data) {
var $ul= $('.search-xmpp ul');
$ul.find('li.found-user').remove();
$ul.find('li.chat-info').remove();
@ -3007,7 +3011,7 @@
this.save({'status_message': status_message});
if (this.xhr_custom_status) {
$.ajax({
url: 'set-custom-status',
url: this.xhr_custom_status_url,
type: 'POST',
data: {'msg': status_message}
});

View File

@ -589,18 +589,64 @@ Default = ``false``
If set to ``true``, only online users will be shown in the contacts roster.
Users with any other status (e.g. away, busy etc.) will not be shown.
xhr_custom_status
-----------------
Default = ``false``
Note::
XHR stands for XMLHTTPRequest, and is meant here in the AJAX sense (Asynchronous Javascript and XML).
This option will let converse.js make an AJAX POST with your changed custom chat status to a
remote server.
xhr_custom_status_url
---------------------
Note::
XHR stands for XMLHTTPRequest, and is meant here in the AJAX sense (Asynchronous Javascript and XML).
Default = Empty string
Used only in conjunction with ``xhr_custom_status``.
This is the URL to which the AJAX POST request to set the user's custom status
message will be made.
The message itself is sent in the request under the key ``msg``.
xhr_user_search
---------------
Default = ``false``
Note::
XHR stands for XMLHTTPRequest, and is meant here in the AJAX sense (Asynchronous Javascript and XML).
There are two ways to add users.
* The user inputs a valid JID (Jabber ID), and the user is added as a pending contact.
* The user inputs some text (for example part of a firstname or lastname), an XHR will be made to a backend, and a list of matches are returned. The user can then choose one of the matches to add as a contact.
* The user inputs some text (for example part of a firstname or lastname), an XHR (Ajax Request) will be made to a remote server, and a list of matches are returned. The user can then choose one of the matches to add as a contact.
This setting enables the second mechanism, otherwise by default the first will
be used.
This setting enables the second mechanism, otherwise by default the first will be used.
*What is expected from the remote server?*
A default JSON encoded list of objects must be returned. Each object
corresponds to a matched user and needs the keys ``id`` and ``fullname``.
xhr_user_search_url
-------------------
Note::
XHR stands for XMLHTTPRequest, and is meant here in the AJAX sense (Asynchronous Javascript and XML).
Default = Empty string
Used only in conjunction with ``xhr_user_search``.
This is the URL to which an AJAX GET request will be made to fetch user data from your remote server.
The query string will be included in the request with ``q`` as its key.
============
Minification