diff options
author | Pablo Martin <caedes@sindominio.net> | 2012-10-25 09:21:15 +0000 |
---|---|---|
committer | root <root@migration.vz.lan> | 2012-10-25 09:21:54 +0000 |
commit | 71e189223b15882f836885623bd2255599c07469 (patch) | |
tree | e3f104406c4ec0830fff17ffdfc11e1fd328aca6 | |
parent | a6e20a9e85ac925de0ef59b4c69e5436f1661c5f (diff) | |
download | elgg-71e189223b15882f836885623bd2255599c07469.tar.gz elgg-71e189223b15882f836885623bd2255599c07469.tar.bz2 |
fix errors with jids with @, notices sometimes not showing and made things a bit more asynchronous. .
-rw-r--r-- | views/default/beechat/beechat.js.php | 74 |
1 files changed, 54 insertions, 20 deletions
diff --git a/views/default/beechat/beechat.js.php b/views/default/beechat/beechat.js.php index 1dacb6306..09f4e8852 100644 --- a/views/default/beechat/beechat.js.php +++ b/views/default/beechat/beechat.js.php @@ -520,7 +520,7 @@ BeeChat.Core.User = function(jid) if ($(presence).attr('type') != 'unavailable' && $(presence).attr('type') != 'error') { if (chatBoxElm.length == 0) { - BeeChat.UI.ScrollBoxes.addRoom(contactBareJid); + BeeChat.UI.ScrollBoxes.add(contactBareJid); } } return true; @@ -620,6 +620,15 @@ BeeChat.Core.Roster = function() { for (var key in items) { _items[key] = new BeeChat.Core.RosterItem(items[key]); + var contactBareJid = items[key].bareJid; + var chatBoxElm = BeeChat.UI.ChatBoxes.getChatBoxElm(contactBareJid); + var status = items[key].status; + /*if (status != 'unavailable' && status != 'error') { + if (chatBoxElm.length == 0) { + BeeChat.UI.ScrollBoxes.add(contactBareJid); + } + }*/ + } } @@ -1341,7 +1350,7 @@ BeeChat.UI = { g_beechat_user.getRoster().setItems(json.contacts); self.loadRosterItemsIcons(false); - self.loadRosterItemsStatuses(); + self.loadRosterItemsStatuses(false); g_beechat_roster_items = g_beechat_user.getRoster().getItems(); BeeChat.UI.ContactsList.update(g_beechat_user.getRoster().getOnlineItems()) g_beechat_user.setInitialized(true); @@ -1349,7 +1358,7 @@ BeeChat.UI = { var scrollBoxesElm = $('#' + BeeChat.UI.Resources.Elements.ID_DIV_SCROLLBOXES); var scrollBoxElmToShow = null; - // Load save chats + // Load saved chats for (var key in json.chats) { var isroom = (json.chats[key].isroom == 'true'); if (isroom) @@ -1358,6 +1367,7 @@ BeeChat.UI = { BeeChat.UI.ScrollBoxes.add(key); var chatBoxElm = BeeChat.UI.ChatBoxes.getChatBoxElm(key); + debugXMPP("load chat " + key); chatBoxElm.hide(); if (!json.chats[key].minimized) { @@ -1413,7 +1423,7 @@ BeeChat.UI = { /** Function: loadRosterItemsIcons * */ - loadRosterItemsIcons: function(is_async) + loadRosterItemsIcons: function(is_async, cb) { var data = g_beechat_user.getRoster().getItemsUsernamesAsList(); var self = this; @@ -1430,6 +1440,9 @@ BeeChat.UI = { g_beechat_roster_items = g_beechat_user.getRoster().getItems(); BeeChat.UI.ContactsList.update(g_beechat_user.getRoster().getOnlineItems()) + if (cb) { + cb(); + } } }); }, @@ -1437,7 +1450,7 @@ BeeChat.UI = { /** Function: loadRosterItemsStatuses * */ - loadRosterItemsStatuses: function() + loadRosterItemsStatuses: function(is_async, cb) { var data = g_beechat_user.getRoster().getItemsUsernamesAsList(); //alert(data) @@ -1445,7 +1458,7 @@ BeeChat.UI = { $.ajax({ type: 'POST', url: self.addActionTokens('<?php echo $vars['url'] . "action/beechat/get_statuses"; ?>'), - async: true, + async: true, // force cache: false, data: {'beechat_roster_items_usernames': data}, dataType: 'json', @@ -1453,6 +1466,9 @@ BeeChat.UI = { g_beechat_user.getRoster().setStatuses(json); g_beechat_roster_items = g_beechat_user.getRoster().getItems(); BeeChat.UI.ContactsList.update(g_beechat_user.getRoster().getOnlineItems()) + if (cb) { + cb(); + } } }); }, @@ -1467,9 +1483,11 @@ BeeChat.UI = { //alert("get roster"); if (!g_beechat_user.isInitialized()) { //alert("load roster" + rosterItems.length); - BeeChat.UI.loadRosterItemsStatuses(); - BeeChat.UI.loadRosterItemsIcons(true); - g_beechat_user.sendInitialPresence(); + BeeChat.UI.loadRosterItemsStatuses(true, + function() { BeeChat.UI.loadRosterItemsIcons(true, + function() {g_beechat_user.sendInitialPresence();}); }); + //BeeChat.UI.loadRosterItemsIcons(false); + //g_beechat_user.sendInitialPresence(); } }, @@ -1793,7 +1811,7 @@ BeeChat.UI.ScrollBoxes = { { var scrollBoxesElm = $('#' + BeeChat.UI.Resources.Elements.ID_DIV_SCROLLBOXES); var scrollBoxElm = scrollBoxesElm.find('ul').children().filter('[bareJid="' + contactBareJid + '"]'); - + debugXMPP("add " + contactBareJid + " " + scrollBoxElm.length); if (scrollBoxElm.length == 0) { var availClass = null; var pres = null; @@ -1822,7 +1840,9 @@ BeeChat.UI.ScrollBoxes = { var scrollBoxesElm = $('#' + BeeChat.UI.Resources.Elements.ID_DIV_SCROLLBOXES); BeeChat.UI.ChatBoxes.remove($(this).parent().attr('bareJid')); + BeeChat.UI.UnreadCountBox.remove($(this).parent().attr('bareJid')); scrollBoxesElm.trigger('goto', scrollBoxesElm.find('ul').children().index(BeeChat.UI.ScrollBoxes.getSelectedScrollBoxElm())); + BeeChat.UI.saveState(); })); scrollBoxesElm.find('ul').append(scrollBoxElm); @@ -1830,8 +1850,7 @@ BeeChat.UI.ScrollBoxes = { if (arguments.length == 3 && arguments[2]) scrollBoxesElm.trigger('goto', scrollBoxesElm.find('ul').children().index(scrollBoxElm)); if (!isroom) { - BeeChat.UI.loadRosterItemsStatuses(); - BeeChat.UI.loadRosterItemsIcons(true); + BeeChat.UI.loadRosterItemsStatuses(true, function () { BeeChat.UI.loadRosterItemsIcons(true); }); } } else { scrollBoxesElm.trigger('goto', scrollBoxesElm.find('ul').children().index(scrollBoxElm)); @@ -1938,6 +1957,7 @@ BeeChat.UI.ChatBoxes = { var chatBoxes = $('#' + BeeChat.UI.Resources.Elements.ID_DIV_CHATBOXES); if ($(chatBoxes).children().filter('[bareJid="' + contactBareJid + '"]').length == 0) { + debugXMPP("create chatbox " + contactBareJid); var chatBox = $('<div></div>') .attr('class', isroom ? BeeChat.UI.Resources.StyleClasses.ChatBox.MAIN : BeeChat.UI.Resources.StyleClasses.ChatBox.MAIN) .attr('bareJid', contactBareJid) @@ -1965,7 +1985,7 @@ BeeChat.UI.ChatBoxes = { .bind('click', function() { if (isroom) g_beechat_user.leaveRoom(contactBareJid); - BeeChat.UI.ChatBoxes.remove($(this).parent().parent().parent().attr('bareJid')); + BeeChat.UI.ChatBoxes.remove(contactBareJid); })) .append($('<span></span>') .attr('class', BeeChat.UI.Resources.StyleClasses.ChatBox.CONTROL) @@ -1993,7 +2013,7 @@ BeeChat.UI.ChatBoxes = { .bind('keypress', isroom?BeeChat.UI.ChatBoxes.onRoomTypingMessage:BeeChat.UI.ChatBoxes.onTypingMessage) .bind('keyup', function(e) { if ((e.keyCode ? e.keyCode : e.which) == 13) - $(this).val(''); + $(this).attr('value', ''); })); var chatBoxBottom = $('<div></div>') @@ -2012,6 +2032,11 @@ BeeChat.UI.ChatBoxes = { else chatBox.append(chatBoxTop).append(chatBoxSubTop).append(chatBoxContent).append(chatBoxInput).append(chatBoxBottom).appendTo(chatBoxes); } + else { + /*debugXMPP("show chatbox " + contactBareJid); + var chatBox = $(chatBoxes).children().filter('[bareJid="' + contactBareJid + '"]'); + chatBox.show();*/ + } }, /** Function: takeStand @@ -2030,7 +2055,7 @@ BeeChat.UI.ChatBoxes = { chatBoxElm.hide(); } else { // Hide all other chatboxes - $.each(chatBoxesElm.filter('[bareJid!=' + contactBareJid + ']'), function() { + $.each(chatBoxesElm.filter('[bareJid!="' + contactBareJid + '"]'), function() { BeeChat.UI.ScrollBoxes.unselect($(this).attr('bareJid')); $(this).hide(); }); @@ -2100,7 +2125,8 @@ BeeChat.UI.ChatBoxes = { var chatBoxElm = BeeChat.UI.ChatBoxes.getChatBoxElm(contactBareJid); if (chatBoxElm.length == 0) { - BeeChat.UI.ScrollBoxes.addRoom(contactBareJid); + BeeChat.UI.ScrollBoxes.add(contactBareJid); + //BeeChat.UI.ScrollBoxes.addRoom(contactBareJid); chatBoxElm = BeeChat.UI.ChatBoxes.getChatBoxElm(contactBareJid); } @@ -2128,12 +2154,18 @@ BeeChat.UI.ChatBoxes = { update: function(contactBareJid, fromName, msg, isroom) { var chatBoxElm = BeeChat.UI.ChatBoxes.getChatBoxElm(contactBareJid); - + debugXMPP(contactBareJid + " " + msg + " " + chatBoxElm.length); if (chatBoxElm.length == 0) { - if (isroom) + if (isroom) { BeeChat.UI.ScrollBoxes.addRoom(contactBareJid); - else - BeeChat.UI.ScrollBoxes.add(contactBareJid); + BeeChat.UI.ChatBoxes.show(contactBareJid); + BeeChat.UI.ChatBoxes.takeStand(contactBareJid); + } + else { + BeeChat.UI.ScrollBoxes.add(contactBareJid,false,true); + // BeeChat.UI.ChatBoxes.show(contactBareJid); + BeeChat.UI.ChatBoxes.takeStand(contactBareJid); + } chatBoxElm = BeeChat.UI.ChatBoxes.getChatBoxElm(contactBareJid); } @@ -2166,7 +2198,9 @@ BeeChat.UI.ChatBoxes = { scrollBoxesElm.trigger('goto', scrollBoxesElm.find('ul').children().index(scrollBoxElm)); } + debugXMPP("about to update number!"); if (chatBoxElm.is(':hidden')) { + debugXMPP("update number!"); BeeChat.UI.UnreadCountBox.update(contactBareJid); // if (BeeChat.UI.HAS_FOCUS) // document.getElementById(BeeChat.UI.Resources.Sounds.NEW_MESSAGE).Play(); |