Changeset 2390 for sandbox/jabberit_messenger/trophy/js/trophyim.js
- Timestamp:
- 03/30/10 17:28:36 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sandbox/jabberit_messenger/trophy/js/trophyim.js
r2345 r2390 30 30 */ 31 31 32 var TROPHYIM_BOSH_SERVICE = '/proxy/xmpp-httpbind'; //Change to suit 32 var TROPHYIM_BOSH_SERVICE = "/proxy/xmpp-httpbind"; //Change to suit 33 33 34 var TROPHYIM_LOG_LINES = 200; 34 35 35 //0=debug, 1=info, 2=warn, 3=error, 4=fatal 36 var TROPHYIM_LOGLEVEL = 0; 36 var TROPHYIM_LOGLEVEL = 0; //0=debug, 1=info, 2=warn, 3=error, 4=fatal 37 37 38 38 var TROPHYIM_VERSION = "0.3"; … … 55 55 * auto-included by the client. 56 56 */ 57 58 /** Object: HTMLSnippets59 *60 * This is the repository for all the html snippets that TrophyIM uses61 *62 */63 64 HTMLSnippets = {65 66 //chatBox : loadIM.HTMLSnippets.chatBox( ),67 68 //chatTab : loadIM.HTMLSnippets.chatTab( ),69 70 loggingDiv : loadIM.HTMLSnippets.loggingDiv( ),71 72 rosterDiv : loadIM.HTMLSnippets.rosterDiv( ),73 };74 57 75 58 /** Object: DOMObjects … … 262 245 { 263 246 TrophyIM.cookies = TrophyIM.getCookies(); 264 265 TrophyIM.client_div = document.getElementById('trophyimclient'); 247 //TrophyIM.client_div = document.getElementById('trophyimclient'); 266 248 267 249 //Load other .js scripts needed … … 274 256 //Wait a second to give scripts time to load 275 257 setTimeout("TrophyIM.showLogin()", 500); 276 277 258 }, 278 259 … … 283 264 storeData : function() 284 265 { 285 if ( TrophyIM.connection && TrophyIM.connection.connected)266 if ( TrophyIM.connection && TrophyIM.connection.connected ) 286 267 { 287 268 TrophyIM.setCookie('trophyim_bosh_xid', TrophyIM.connection.jid + "|" + … … 296 277 * exists, or creating a new one of we are re-attaching. 297 278 */ 298 showLogin : function() { 279 showLogin : function() 280 { 299 281 //JSON is the last script to load, so we wait on it 300 282 //Added Strophe check too because of bug where it's sometimes missing … … 308 290 TrophyIM.delCookie('trophyim_bosh_xid'); 309 291 TrophyIM.constants.stale_roster = true; 310 if (TrophyIM.cookies['trophyimloglevel']) 311 { 312 TrophyIM.client_div.appendChild(DOMObjects.getHTML('loggingDiv')); 313 TrophyIM.logging_div = document.getElementById('trophyimlog'); 314 } 315 TrophyIM.connection = new Strophe.Connection(TROPHYIM_BOSH_SERVICE); 316 TrophyIM.connection.rawInput = TrophyIM.rawInput; 317 TrophyIM.connection.rawOutput = TrophyIM.rawOutput; 292 293 TrophyIM.connection = new Strophe.Connection(TROPHYIM_BOSH_SERVICE); 294 TrophyIM.connection.rawInput = TrophyIM.rawInput; 295 TrophyIM.connection.rawOutput = TrophyIM.rawOutput; 318 296 Strophe.log = TrophyIM.log; 319 297 Strophe.info('Attempting Strophe attach.'); … … 323 301 else 324 302 { 325 var logging_div = TrophyIM.clearClient(); 326 loadIM.HTMLSnippets.loginPage(); 303 // List Contact 304 loadIM.HTMLSnippets.rosterDiv(); 305 306 if ( loadIM.getUserCurrent() != null ) 307 { 308 TrophyIM.login( loadIM.getUserCurrent().jid, loadIM.getUserCurrent().password ); 309 } 310 else 311 { 312 loadIM.HTMLSnippets.loginPage(); 313 } 327 314 } 328 315 } … … 353 340 } 354 341 }, 342 355 343 /** Function: rawInput 356 344 * 357 345 * This logs the packets actually recieved by strophe at the debug level 358 346 */ 359 rawInput : function (data) { 347 rawInput : function (data) 348 { 360 349 Strophe.debug("RECV: " + data); 361 350 }, 351 362 352 /** Function: rawInput 363 353 * 364 354 * This logs the packets actually recieved by strophe at the debug level 365 355 */ 366 rawOutput : function (data) { 356 rawOutput : function (data) 357 { 367 358 Strophe.debug("SEND: " + data); 368 359 }, 360 369 361 /** Function: login 370 362 * … … 376 368 login : function() 377 369 { 378 if (document.getElementById('trophyimloglevel').checked) { 379 TrophyIM.setCookie('trophyimloglevel', 1); 380 if (!document.getElementById('trophyimlog')) { 381 TrophyIM.client_div.appendChild(DOMObjects.getHTML('loggingDiv')); 382 TrophyIM.logging_div = document.getElementById('trophyimlog'); 383 } 384 } else { 385 TrophyIM.delCookie('trophyimloglevel'); 386 if (document.getElementById('trophyimlog')) { 387 TrophyIM.client_div.removeChild(document.getElementById( 388 'trophyimlog')); 389 TrophyIM.logging_div = null; 390 } 391 } 392 if (TrophyIM.JSONStore.store_working) { //In case they never logged out 393 TrophyIM.JSONStore.delData(['groups','roster', 'active_chat', 394 'chat_history']); 395 } 396 TrophyIM.connection = new Strophe.Connection(TROPHYIM_BOSH_SERVICE); 397 TrophyIM.connection.rawInput = TrophyIM.rawInput; 398 TrophyIM.connection.rawOutput = TrophyIM.rawOutput; 370 if (TrophyIM.JSONStore.store_working) 371 { 372 //In case they never logged out 373 TrophyIM.JSONStore.delData(['groups','roster', 'active_chat', 'chat_history']); 374 } 375 376 TrophyIM.connection = new Strophe.Connection(TROPHYIM_BOSH_SERVICE); 377 TrophyIM.connection.rawInput = TrophyIM.rawInput; 378 TrophyIM.connection.rawOutput = TrophyIM.rawOutput; 399 379 Strophe.log = TrophyIM.log; 400 var barejid = document.getElementById('trophyimjid').value 401 var fulljid = barejid + TROPHYIM_RESOURCE; 402 TrophyIM.setCookie('trophyimjid', barejid); 403 var password = document.getElementById('trophyimpass').value; 404 var button = document.getElementById('trophyimconnect'); 405 if (button.value == 'connect') { 406 button.value = 'disconnect'; 407 TrophyIM.connection.connect(fulljid, password, TrophyIM.onConnect); 408 } else { 409 button.value = 'connect'; 410 TrophyIM.connection.disconnect(); 411 } 412 413 }, 414 /** Function: login 380 381 if ( arguments.length > 0 ) 382 { 383 var barejid = arguments[0]; 384 var password = arguments[1]; 385 386 TrophyIM.connection.connect(barejid + TROPHYIM_RESOURCE, password, TrophyIM.onConnect); 387 } 388 else 389 { 390 var barejid = document.getElementById('trophyimjid').value 391 var fulljid = barejid + TROPHYIM_RESOURCE; 392 var password = document.getElementById('trophyimpass').value; 393 var button = document.getElementById('trophyimconnect'); 394 395 loadIM.setUserCurrent( barejid, password); 396 397 if ( button.value == 'connect' ) 398 { 399 button.value = 'disconnect'; 400 TrophyIM.connection.connect(fulljid, password, TrophyIM.onConnect); 401 } 402 else 403 { 404 button.value = 'connect'; 405 TrophyIM.connection.disconnect(); 406 } 407 } 408 409 TrophyIM.setCookie('trophyimjid', barejid); 410 411 }, 412 413 /** Function: logout 415 414 * 416 415 * Logs into fresh session through Strophe, purging any old data. … … 420 419 TrophyIM.delCookie('trophyim_bosh_xid'); 421 420 delete TrophyIM['cookies']['trophyim_bosh_xid']; 422 if (TrophyIM.JSONStore.store_working) 421 422 if (TrophyIM.JSONStore.store_working) 423 423 { 424 424 TrophyIM.JSONStore.delData(['groups','roster', 'active_chat', 'chat_history']); … … 435 435 436 436 }, 437 437 438 /** Function onConnect 438 439 * … … 468 469 TrophyIM.setCookie('trophyim_bosh_xid', TrophyIM.connection.jid + "|" + 469 470 TrophyIM.connection.sid + "|" + TrophyIM.connection.rid); 470 var logging_div = TrophyIM.clearClient();471 //var logging_div = TrophyIM.clearClient(); 471 472 472 if( logging_div )473 /*if( logging_div ) 473 474 { 474 475 TrophyIM.client_div.appendChild(logging_div); 475 476 TrophyIM.logging_div = document.getElementById('trophyimlog'); 476 } 477 }*/ 477 478 478 479 TrophyIM.rosterObj = new TrophyIMRoster(); … … 528 529 onRoster : function(msg) 529 530 { 530 Strophe.debug("Roster handler"); 531 //Strophe.debug("Roster handler"); 532 531 533 var roster_items = msg.firstChild.getElementsByTagName('item'); 532 for (var i = 0; i < roster_items.length; i++) { 533 var groups = roster_items[i].getElementsByTagName('group'); 534 535 for (var i = 0; i < roster_items.length; i++) 536 { 537 var groups = roster_items[i].getElementsByTagName('group'); 534 538 var group_array = new Array(); 535 for (var g = 0; g < groups.length; g++) { 536 group_array[group_array.length] = 537 groups[g].firstChild.nodeValue; 538 } 539 TrophyIM.rosterObj.addContact(roster_items[i].getAttribute('jid'), 540 roster_items[i].getAttribute('subscription'), 541 roster_items[i].getAttribute('name'), group_array); 542 } 543 if (msg.getAttribute('type') == 'set') { 544 TrophyIM.connection.send($iq({type: 'reply', id: 539 540 for (var g = 0; g < groups.length; g++) 541 { 542 group_array[group_array.length] = groups[g].firstChild.nodeValue; 543 } 544 with ( roster_items[i] ) 545 { 546 TrophyIM.rosterObj.addContact(getAttribute('jid'), getAttribute('subscription'), getAttribute('name'), group_array); 547 } 548 } 549 550 if ( msg.getAttribute('type') == 'set' ) 551 { 552 TrophyIM.connection.send($iq({type: 'reply', id: 545 553 msg.getAttribute('id'), to: msg.getAttribute('from')}).tree()); 546 554 } 547 return true; 555 556 return true; 548 557 }, 549 558 /** Function: onPresence … … 657 666 */ 658 667 659 addContacts : function( jid , name, group )660 { 661 var newPresence = $pres({from: 'alexandrecorreia@ecelepar10612.celepar.parana', to: jid, type: 'subscribe'}).tree();668 addContacts : function( jidFrom, jidTo, name, group ) 669 { 670 var newPresence = $pres({from: jidFrom, to: jidTo, type: 'subscribe'}).tree(); 662 671 663 672 TrophyIM.connection.send(newPresence); … … 700 709 if( TrophyIM.rosterObj.changes.length > 0 ) 701 710 { 702 var roster_div = document.getElementById(' trophyimroster');711 var roster_div = document.getElementById('JabberIMRoster'); 703 712 704 713 if( roster_div ) 705 714 { 715 var users = new Array(); 716 717 for( var user in TrophyIM.rosterObj.roster ) 718 { 719 users[users.length] = TrophyIM.rosterObj.roster[user].contact.jid; 720 } 721 722 users.sort(); 723 706 724 var groups = new Array(); 707 725 708 726 for (var group in TrophyIM.rosterObj.groups) 709 727 { 710 groups[groups.length] = ( group ) ? group : "SEM GRUPO"; 728 if( group ) 729 groups[groups.length] = group; 711 730 } 712 731 713 732 groups.sort(); 714 733 715 734 for ( var i = 0; i < groups.length; i++ ) 716 735 { 717 718 TrophyIM.renderGroups( groups[i] , roster_div ); 736 TrophyIM.renderGroups( groups[i] , roster_div.lastChild ); 719 737 } 720 738 721 TrophyIM.renderItensGroup( roster_div);739 TrophyIM.renderItensGroup(users, roster_div); 722 740 } 723 741 } 724 742 725 setTimeout("TrophyIM.renderRoster()", 1000 ); 743 //setTimeout("TrophyIM.renderRoster()", 1000 ); 744 setTimeout("TrophyIM.renderRoster()", 2000 ); 726 745 }, 727 746 728 747 /** Function: renderGroups 729 748 * … … 731 750 */ 732 751 733 renderGroups: function( nameGroup, element Parent)752 renderGroups: function( nameGroup, element ) 734 753 { 735 754 var _addGroup = function() … … 738 757 { 739 758 'nameGroup' : arguments[0], 740 'id' : (( arguments[0] == "SEM GRUPO" ) ? "sem_grupo_jabber" : "" )741 759 } 742 760 743 elementParent.innerHTML += loadIM.parse("group","groups.xsl", paramsGroup); 761 element.innerHTML += loadIM.parse("group","groups.xsl", paramsGroup); 762 744 763 } 745 746 if( !element Parent.hasChildNodes() )764 765 if( !element.hasChildNodes() ) 747 766 { 748 767 _addGroup(nameGroup); … … 750 769 else 751 770 { 752 var elementChild = element Parent.firstChild;771 var elementChild = element; 753 772 var flag = false; 754 773 755 774 while ( elementChild ) 756 775 { 757 if ( elementChild.childNodes[0].childNodes[0]. nodeValue === nameGroup )776 if ( elementChild.childNodes[0].childNodes[0].firstChild.nodeValue === nameGroup ) 758 777 { 759 flag = true; 778 flag = true; 760 779 } 780 761 781 elementChild = elementChild.nextSibling; 762 782 } 763 783 764 784 if( !flag ) 765 _addGroup( nameGroup);785 _addGroup( nameGroup ); 766 786 } 767 787 768 788 }, 769 789 … … 773 793 */ 774 794 775 renderItensGroup : function( elementParent )776 { 777 var _addItensGroup = function()795 renderItensGroup : function( users, element ) 796 { 797 var addItemGroup = function() 778 798 { 779 799 if( arguments.length > 0 ) … … 781 801 var objContact = arguments[0]; 782 802 var element = arguments[1]; 783 var itens Group = document.getElementById('itenContact_' + objContact.contact.jid);784 785 if ( itensGroup== null )803 var itensJid = document.getElementById( 'itenContact_' + objContact.contact.jid ); 804 805 if( itensJid == null ) 786 806 { 787 807 // Name 788 808 var nameContact = ""; 789 809 790 if ( objContact.contact.name)810 if ( objContact.contact.name ) 791 811 nameContact = objContact.contact.name; 792 812 else … … 825 845 } 826 846 827 element.innerHTML += loadIM.parse("itens_group", "itensGroup.xsl", paramsContact); 847 if( element.id == "rosterIM_with_groups" ) 848 { 849 var elementChild = element; 850 851 while ( elementChild ) 852 { 853 if( elementChild.childNodes[0].childNodes[0].firstChild.nodeValue == objContact.contact.groups[0] ) 854 elementChild.childNodes[0].innerHTML += loadIM.parse("itens_group", "itensGroup.xsl", paramsContact); 855 856 elementChild = elementChild.nextSibling; 857 } 858 } 859 else 860 { 861 element.innerHTML += loadIM.parse("itens_group", "itensGroup.xsl", paramsContact); 862 } 828 863 } 829 864 else 830 865 { 866 831 867 // Presence e Status 832 868 var presence = "unavailable"; … … 848 884 } 849 885 850 itens Group.style.background = "url('images/" + presence + ".gif')no-repeat center left";851 itens Group.lastChild.style.display = statusDisplay;852 itens Group.lastChild.innerHTML = " ( " + status + " ) ";886 itensJid.style.background = "url('images/" + presence + ".gif')no-repeat center left"; 887 itensJid.lastChild.style.display = statusDisplay; 888 itensJid.lastChild.innerHTML = " ( " + status + " ) "; 853 889 } 854 890 } 855 891 } 856 892 857 for ( var userItem in TrophyIM.rosterObj.roster) 858 { 859 if ( TrophyIM.rosterObj.roster[userItem].contact.groups ) 860 { 861 var elementChild = elementParent.firstChild 862 863 while ( elementChild ) 864 { 865 if( elementChild.childNodes[0].childNodes[0].nodeValue == TrophyIM.rosterObj.roster[userItem].contact.groups ) 866 _addItensGroup( TrophyIM.rosterObj.roster[userItem], elementChild ); 867 868 elementChild = elementChild.nextSibling; 869 } 870 } 893 for( var i = 0 ; i < users.length; i++ ) 894 { 895 if( TrophyIM.rosterObj.roster[users[i]].contact.groups ) 896 if( TrophyIM.rosterObj.roster[users[i]].contact.groups[0] ) 897 addItemGroup(TrophyIM.rosterObj.roster[users[i]], element.lastChild ); 898 else 899 addItemGroup(TrophyIM.rosterObj.roster[users[i]], element.firstChild ); 871 900 else 872 { 873 var elementChild = document.getElementById("sem_grupo_jabber"); 874 875 _addItensGroup( TrophyIM.rosterObj.roster[userItem], elementChild ); 876 } 877 } 901 addItemGroup(TrophyIM.rosterObj.roster[users[i]], element.firstChild ); 902 } 878 903 }, 879 904 880 905 /** Function: rosterClick 881 906 * … … 888 913 }, 889 914 890 setPresence : function() 891 { 892 if( arguments.length > 0 ) 893 { 894 TrophyIM.connection.send($pres( ).c('show').t(arguments[0]).tree()); 895 } 915 916 /** Function SetAutorization 917 * 918 */ 919 920 setAutorization : function( jid ) 921 { 922 //<presence to='user@example.com' from='contact@example.org' type='subscribed'/> 923 //var _autorization = $pres( ).attrs( {to: jid, from: loadIM.getUserCurrent(), type:'subscribed'}).tree(); 924 925 TrophyIM.connection.send($pres( ).attrs( {to: jid, from: loadIM.getUserCurrent().jid, type:'subscribed'}).tree()); 926 }, 927 928 /** Function: setPresence 929 * 930 */ 931 932 setPresence : function( show ) 933 { 934 TrophyIM.connection.send($pres( ).c('show').t(show).tree()); 896 935 }, 897 936 … … 976 1015 */ 977 1016 978 this.addContact = function(jid, subscription, name, groups) { 979 var contact = {jid:jid, subscription:subscription, name:name, groups:groups} 1017 this.addContact = function(jid, subscription, name, groups) 1018 { 1019 var contact = { jid:jid, subscription:subscription, name:name, groups:groups } 980 1020 var jid_lower = jid.toLowerCase(); 981 if (this.roster[jid_lower]) { 1021 1022 if ( this.roster[jid_lower] ) 1023 { 982 1024 this.roster[jid_lower]['contact'] = contact; 983 } else { 1025 } 1026 else 1027 { 984 1028 this.roster[jid_lower] = {contact:contact}; 985 1029 } 986 groups = groups ? groups : ['']; 987 for (var g = 0; g < groups.length; g++) { 988 if (!this.groups[groups[g]]) { 1030 1031 groups = groups ? groups : ['']; 1032 1033 for ( var g = 0; g < groups.length; g++ ) 1034 { 1035 if ( !this.groups[groups[g]] ) 1036 { 989 1037 this.groups[groups[g]] = {}; 990 1038 } 991 this.groups[groups[g]][jid_lower] = jid_lower; 1039 1040 this.groups[groups[g]][jid_lower] = jid_lower; 992 1041 } 993 1042 } … … 998 1047 * Parameter: (String) jid - jid to return 999 1048 */ 1000 this.getContact = function(jid) { 1001 if (this.roster[jid.toLowerCase()]) { 1049 this.getContact = function(jid) 1050 { 1051 if (this.roster[jid.toLowerCase()]) 1052 { 1002 1053 return this.roster[jid.toLowerCase()]['contact']; 1003 1054 } … … 1013 1064 * (String) status: status attribute from presence 1014 1065 */ 1015 this.setPresence = function(fulljid, priority, show, status) 1066 1067 this.setPresence = function(fulljid, priority, show, status) 1016 1068 { 1017 1069 var barejid = Strophe.getBareJidFromJid(fulljid); … … 1344 1396 * Bootstrap self into window.onload and window.onunload 1345 1397 */ 1398 1399 /* 1346 1400 var oldonload = window.onload; 1347 window.onload = function() { 1348 if(oldonload) { 1401 window.onload = function() 1402 { 1403 if(oldonload) 1404 { 1349 1405 oldonload(); 1350 1406 } 1351 TrophyIM.load(); 1407 1408 TrophyIM.load(); 1352 1409 }; 1410 */ 1411 1353 1412 var oldonunload = window.onunload; 1354 window.onunload = function() { 1355 if(oldonunload) { 1413 window.onunload = function() 1414 { 1415 if(oldonunload) 1416 { 1356 1417 oldonunload(); 1357 1418 } 1358 TrophyIM.storeData(); 1419 1420 TrophyIM.storeData(); 1359 1421 }
Note: See TracChangeset
for help on using the changeset viewer.