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.updateOnPresence = function (jid, status, presence) { var user_id = Strophe.getNodeFromJid(jid), bare_jid = Strophe.getBareJidFromJid(jid), resource, existing_user_element, online_count; if (xmppchat.isOwnUser(jid)) { return; } existing_user_element = $('#online-users-' + user_id); if ((status === 'offline') || (status === 'unavailable')) { // Remove the resource. bare_jid = Strophe.getBareJidFromJid(jid); resource = Strophe.getResourceFromJid(jid); if (xmppchat.ChatPartners.remove(bare_jid, resource) === 0) { // Only set the status offline if there aren't any other resources for that user if (existing_user_element.length > 0) { existing_user_element.attr('class', status); } return; } } else { if (existing_user_element.length > 0) { existing_user_element.attr('class', status); } else { xmppchat.Presence.getUserInfo(user_id, function (data) { if ($('#online-users-' + user_id).length > 0) { return; } var li = $('
  • ').attr('id', 'online-users-'+user_id).attr('data-recipient', bare_jid); li.append($('').addClass('user-details-toggle').text(data.fullname)); $('#online-users').append(li); }); } } $('#online-count').text(xmppchat.Presence.onlineCount()); }; ob.positionNewChat = function ($chat) { var open_chats = 0, offset; for (var i=0; i'); if (el.tagName == 'to') { message_html = div.append( ''+time+' me:  ' + ''+text+'' ); } else { message_html = div.append( ''+time+' '+recipient_name+':  ' + ''+text+'' ); } $content.append(message_html); $content.scrollTop($content[0].scrollHeight); } }); callback($chat); }); }; ob.insertClientStoredMessages = function ($chat, bare_jid, recipient_name) { xmppchat.Messages.getMessages(bare_jid, function (msgs) { $(msgs).each(function (idx, msg) { var msg_array = msg.split(' ', 2), date = msg_array[0], time = new Date(Date.parse(date)).toLocaleTimeString().substring(0,5), direction = msg_array[1], text = String(msg).replace(/(.*?\s.*?\s)/, ''); $content = $chat.find('.chat-content'); div = $('
    '); if (direction == 'to') { message_html = div.append( ''+time+' me:  ' + ''+text+'' ); } else { message_html = div.append( ''+time+' '+recipient_name+':  ' + ''+text+'' ); } $content.append(message_html); $content.scrollTop($content[0].scrollHeight); }); }); }; ob.createChatbox = function (bare_jid, callback) { var user_id = Strophe.getNodeFromJid(bare_jid), that = this; xmppchat.Presence.getUserInfo(user_id, function (data) { var chat_id = helpers.hash(bare_jid); var $chat = $('
    ').attr('id', chat_id).hide(); var $head = $('
    ') .append($('
    ').text(data.fullname)) .append($('X') .attr('data-recipient', bare_jid)) .append('
    '); var $content = $('
    '); var $form = $('
    ') .append( $('