Commit 3e964ccd authored by JC Brand's avatar JC Brand

Don't make a @@xmpp-userDetails ajax call. We can do it all client side.

parent 92a18780
...@@ -13,36 +13,31 @@ xmppchat.UI = (function (xmppUI, $, console) { ...@@ -13,36 +13,31 @@ xmppchat.UI = (function (xmppUI, $, console) {
// gone offline, we need to look in the ChatPartners storage to see // gone offline, we need to look in the ChatPartners storage to see
// if there are more storages before we mark the user as offline in the UI. // if there are more storages before we mark the user as offline in the UI.
var user_id = Strophe.getNodeFromJid(jid), var user_id = Strophe.getNodeFromJid(jid),
barejid = Strophe.getBareJidFromJid(jid), bare_jid = Strophe.getBareJidFromJid(jid),
existing_user_element = $('#online-users-' + user_id), existing_user_element = $('#online-users-' + user_id),
online_count; online_count;
if (barejid === Strophe.getBareJidFromJid(jarnxmpp.connection.jid)) { if (bare_jid === Strophe.getBareJidFromJid(xmppchat.connection.jid)) {
return; return;
} }
if (existing_user_element.length) { if (existing_user_element.length) {
if (status === 'offline' && jarnxmpp.Presence.online.hasOwnProperty(user_id)) { if (status === 'offline' && xmppchat.Presence.online.hasOwnProperty(user_id)) {
existing_user_element.attr('class', status); existing_user_element.attr('class', status);
return; return;
} }
existing_user_element.attr('class', status); existing_user_element.attr('class', status);
} else { } else {
$.get(portal_url + '/xmpp-userDetails?jid=' + barejid, function (user_details) { if ($('#online-users-' + user_id).length > 0) {
// FIXME: this ajax call returns a bunch of unnecessary stuff... return;
if ($('#online-users-' + user_id).length > 0) { }
return; var li = $('<li></li>').attr('id', 'online-users-'+user_id).attr('data-recipient', jid);
} li.append($('<a></a>').addClass('user-details-toggle').text(user_id));
user_details = $(user_details); $('#online-users').append(li);
$('#online-users').append(user_details);
$('#online-users li[data-userid]').sortElements(function (a, b) {
return $('a.user-details-toggle', a).text().trim() > $('a.user-details-toggle', b).text().trim() ? 1 : -1;
});
});
// Pre-fetch user info if we have a session storage. // Pre-fetch user info if we have a session storage.
if (jarnxmpp.Storage.storage !== null) { if (xmppchat.Storage.storage !== null) {
jarnxmpp.Presence.getUserInfo(user_id, function (data) {}); xmppchat.Presence.getUserInfo(user_id, function (data) {});
} }
} }
online_count = jarnxmpp.Presence.onlineCount(); online_count = xmppchat.Presence.onlineCount();
if (online_count > 0) { if (online_count > 0) {
$('#no-users-online').hide(); $('#no-users-online').hide();
} else { } else {
...@@ -431,10 +426,8 @@ $(document).ready(function () { ...@@ -431,10 +426,8 @@ $(document).ready(function () {
}); });
$('a.user-details-toggle').live('click', function (e) { $('a.user-details-toggle').live('click', function (e) {
var $field = $('[name="message"]:input', $(this).parent()[0]),
jid = $field.attr('data-recipient');
e.preventDefault(); e.preventDefault();
xmppchat.UI.getChatbox(jid); xmppchat.UI.getChatbox($(this).parent().attr('data-recipient'));
}); });
$('textarea.chat-textarea').live('keypress', function (ev) { $('textarea.chat-textarea').live('keypress', function (ev) {
......
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