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'); 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( $('