xmppchat.UI = (function (xmppUI, $, console) { var ob = xmppUI; ob.chats = []; ob.chat_focus = []; ob.chatbox_width = 205; ob.sanitizePath = function (call) { return xmppchat.base_url + call; }; ob.addUserToRosterUI = function (user_id, bare_jid, fullname, userstatus) { if ($('#online-users-' + user_id).length > 0) { return; } var li = $('
').addClass(userstatus).attr('id', 'online-users-'+user_id).attr('data-recipient', bare_jid); li.append($('').addClass('user-details-toggle').text(fullname)); li.append($('').addClass('remove-xmpp-contact')); $('#xmpp-contacts').append(li); }; ob.updateOnPresence = function (jid, status, presence) { var user_id = Strophe.getNodeFromJid(jid), bare_jid = Strophe.getBareJidFromJid(jid), resource, online_count, $chat = $("#"+helpers.hash(bare_jid)), $chat_content, existing_user_element = $('#online-users-' + user_id); if (xmppchat.isOwnUser(jid)) { return; } if ($chat.length > 0) { $chat_content = $chat.find(".chat-content"); $chat_content.find('div.chat-event').remove(); if (status === 'offline') { xmppchat.Presence.getUserInfo(user_id, function (data) { $chat_content.append($('').addClass('chat-event').text(data.fullname + ' has gone offline.')); $chat_content.scrollTop($content[0].scrollHeight); }); } else if (status === 'unsubscribe') { xmppchat.Presence.getUserInfo(user_id, function (data) { $chat_content.append($('').addClass('chat-event').text(data.fullname + ' has removed you as a contact.')); $chat_content.scrollTop($content[0].scrollHeight); }); if (existing_user_element.length > 0) { existing_user_element.remove(); } $('#online-count').text(xmppchat.Presence.onlineCount()); return; } } if (existing_user_element.length > 0) { existing_user_element.attr('class', status); } else if ((status !== 'offline') && (status !== 'unavailable')) { xmppchat.Presence.getUserInfo(user_id, function (data) { xmppchat.UI.addUserToRosterUI(user_id, bare_jid, data.fullname, status); }); } else { // status is offline and the user isn't shown as online return; } $('#online-count').text(xmppchat.Presence.onlineCount()); }; ob.positionNewChat = function ($chat) { var open_chats = 0, offset; for (var i=0; i