- Timestamp:
- 04/08/10 18:31:53 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sandbox/jabberit_messenger/trophy_expresso/js/trophyim.js
r2437 r2471 198 198 var cObj = {}; 199 199 var cookies = document.cookie.split(';'); 200 for (var c in cookies) { 201 while (cookies[c].charAt(0)==' ') { 200 for (var c in cookies) 201 { 202 while (cookies[c].charAt(0)==' ') 203 { 202 204 cookies[c] = cookies[c].substring(1,cookies[c].length); 203 205 } 204 if (cookies[c].substr(0, 8) == "trophyim") { 206 if (cookies[c].substr(0, 8) == "trophyim") 207 { 205 208 var nvpair = cookies[c].split("=", 2); 206 209 cObj[nvpair[0]] = nvpair[1]; … … 208 211 } 209 212 } 213 210 214 return cObj; 211 215 }, … … 242 246 * Store all our data in the JSONStore, if it is active 243 247 */ 248 244 249 storeData : function() 245 250 { … … 251 256 } 252 257 }, 258 253 259 /** Function: showlogin 254 260 * … … 257 263 * exists, or creating a new one of we are re-attaching. 258 264 */ 265 259 266 showLogin : function() 260 267 { … … 483 490 * one exists 484 491 */ 485 clearClient : function() { 486 if(TrophyIM.logging_div) { 487 var logging_div = TrophyIM.client_div.removeChild( 488 document.getElementById('trophyimlog')); 489 } else { 492 493 clearClient : function() 494 { 495 if(TrophyIM.logging_div) 496 { 497 var logging_div = TrophyIM.client_div.removeChild(document.getElementById('trophyimlog')); 498 } 499 else 500 { 490 501 var logging_div = null; 491 502 } 492 while(TrophyIM.client_div.childNodes.length > 0) { 503 504 while(TrophyIM.client_div.childNodes.length > 0) 505 { 493 506 TrophyIM.client_div.removeChild(TrophyIM.client_div.firstChild); 494 507 } 508 495 509 return logging_div; 496 510 }, 511 497 512 /** Function: onVersion 498 513 * 499 514 * jabber:iq:version query handler 500 515 */ 501 onVersion : function(msg) { 516 517 onVersion : function(msg) 518 { 502 519 Strophe.debug("Version handler"); 503 if (msg.getAttribute('type') == 'get') { 520 if (msg.getAttribute('type') == 'get') 521 { 504 522 var from = msg.getAttribute('from'); 505 523 var to = msg.getAttribute('to'); … … 512 530 return true; 513 531 }, 532 514 533 /** Function: onRoster 515 534 * 516 535 * Roster iq handler 517 536 */ 537 518 538 onRoster : function(msg) 519 539 { 520 //Strophe.debug("Roster handler"); 521 522 var roster_items = msg.firstChild.getElementsByTagName('item'); 540 var roster_items = msg.firstChild.getElementsByTagName('item'); 523 541 524 542 for (var i = 0; i < roster_items.length; i++) 525 543 { 544 with(roster_items[i]) 545 { 546 var groups = getElementsByTagName('group'); 547 var group_array = []; 548 549 for( var g = 0 ; g < groups.length; g++ ) 550 { 551 if( groups[g].hasChildNodes() ) 552 group_array[group_array.length] = groups[g].firstChild.nodeValue; 553 } 554 555 TrophyIM.rosterObj.addContact(getAttribute('jid'), getAttribute('subscription'), getAttribute('name'), group_array); 556 } 557 558 /* 526 559 var groups = roster_items[i].getElementsByTagName('group'); 527 var group_array = new Array(); 560 561 var group_array = new Array(); 528 562 529 563 for (var g = 0; g < groups.length; g++) 530 564 { 531 group_array[group_array.length] = groups[g].firstChild.nodeValue; 532 } 565 if( groups[g].firstChild != null ) 566 group_array[group_array.length] = groups[g].firstChild.nodeValue; 567 } 568 533 569 with ( roster_items[i] ) 534 570 { 571 alert(getAttribute('jid') + "\n" + getAttribute('subscription') + "\n" + getAttribute('name')); 535 572 TrophyIM.rosterObj.addContact(getAttribute('jid'), getAttribute('subscription'), getAttribute('name'), group_array); 536 573 } 537 } 538 574 */ 575 } 576 539 577 if ( msg.getAttribute('type') == 'set' ) 540 578 { 541 TrophyIM.connection.send($iq({type: 'reply', id:542 msg.getAttribute('id'), to: msg.getAttribute('from')}).tree());579 var _iq = $iq({type: 'reply', id: msg.getAttribute('id'), to: msg.getAttribute('from')}); 580 TrophyIM.connection.send( _iq.tree()); 543 581 } 544 582 … … 552 590 { 553 591 Strophe.debug("Presence handler"); 554 var type = msg.getAttribute('type') ? msg.getAttribute('type') : 'available'; 555 var show = msg.getElementsByTagName('show').length ? Strophe.getText(msg.getElementsByTagName('show')[0]) : type; 556 var status = msg.getElementsByTagName('status').length ? Strophe.getText(msg.getElementsByTagName('status')[0]) : ''; 557 var priority = msg.getElementsByTagName('priority').length ? parseInt(Strophe.getText(msg.getElementsByTagName('priority')[0])) : 0; 558 TrophyIM.rosterObj.setPresence(msg.getAttribute('from'), priority, show, status); 592 var type = msg.getAttribute('type') ? msg.getAttribute('type') : 'available'; 593 var show = msg.getElementsByTagName('show').length ? Strophe.getText(msg.getElementsByTagName('show')[0]) : type; 594 var status = msg.getElementsByTagName('status').length ? Strophe.getText(msg.getElementsByTagName('status')[0]) : ''; 595 var priority = msg.getElementsByTagName('priority').length ? parseInt(Strophe.getText(msg.getElementsByTagName('priority')[0])) : 0; 596 597 TrophyIM.rosterObj.setPresence(msg.getAttribute('from'), priority, show, status); 559 598 560 599 return true; … … 566 605 onMessage : function(msg) 567 606 { 568 Strophe.debug("Message handler");569 607 570 608 var from = msg.getAttribute('from'); … … 576 614 var barejid = Strophe.getBareJidFromJid(from); 577 615 var jid_lower = barejid.toLowerCase(); 578 var contact = "";616 var contact = ""; 579 617 580 if( TrophyIM.rosterObj.roster[barejid .toLowerCase()]['contact']['name'] )618 if( TrophyIM.rosterObj.roster[barejid] ) 581 619 { 582 contact = TrophyIM.rosterObj.roster[barejid.toLowerCase()]['contact']['name']; 620 if( TrophyIM.rosterObj.roster[barejid.toLowerCase()]['contact']['name'] ) 621 { 622 contact = TrophyIM.rosterObj.roster[barejid.toLowerCase()]['contact']['name']; 623 } 583 624 } 584 625 else … … 597 638 TrophyIM.addMessage(message, jid_lower); 598 639 } 640 599 641 return true; 600 642 }, 643 601 644 /** Function: makeChat 602 645 * … … 604 647 * given resource 605 648 */ 649 606 650 makeChat : function(fulljid) 607 651 { 608 609 var barjid = Strophe.getBareJidFromJid(fulljid);652 var barejid = Strophe.getBareJidFromJid(fulljid); 653 var titleWindow = ""; 610 654 611 655 var paramsChatBox = 612 656 { 613 'idChatBox' : bar jid + "__chatBox",614 'jidTo' : bar jid,657 'idChatBox' : barejid + "__chatBox", 658 'jidTo' : barejid, 615 659 'path_jabberit' : path_jabberit 616 660 }; 617 661 662 if( TrophyIM.rosterObj.roster[barejid] ) 663 { 664 if( TrophyIM.rosterObj.roster[barejid.toLowerCase()]['contact']['name'] ) 665 { 666 titleWindow = TrophyIM.rosterObj.roster[barejid.toLowerCase()]['contact']['name']; 667 } 668 } 669 else 670 { 671 titleWindow = barejid.toLowerCase(); 672 titleWindow = contact.substring(0, contact.indexOf('@')); 673 } 674 618 675 var winChatBox = 619 676 { 620 id_window : "window_chat_area_" + bar jid,677 id_window : "window_chat_area_" + barejid, 621 678 width : 387, 622 679 height : 365, … … 627 684 resizable : true, 628 685 zindex : loadIM.getZIndex(), 629 title : barjid.substring(0, barjid.indexOf('@')),686 title : titleWindow, 630 687 closeAction : "hidden", 631 688 content : loadIM.parse("chat_box","chatBox.xsl", paramsChatBox) 632 689 } 633 690 634 _winBuild(winChatBox) 691 _winBuild(winChatBox); 635 692 636 loadIM.configEvents( 637 document.getElementById( barjid + '__sendBox'), 693 loadIM.configEvents( document.getElementById( barejid + '__sendBox'), 638 694 'onkeyup', function(e) 639 695 { 640 696 if( e.keyCode == 13 ) 641 697 { 642 TrophyIM.sendMessage( bar jid );643 document.getElementById( bar jid + '__sendBox').value = '';698 TrophyIM.sendMessage( barejid ); 699 document.getElementById( barejid + '__sendBox').value = ''; 644 700 return false; 645 701 } … … 665 721 666 722 // Add Contact 667 var newContact = $iq({type: 'set', id: 'setAddContact'}); 723 var _id = TrophyIM.connection.getUniqueId(); 724 var newContact = $iq({type: 'set', id: _id }); 668 725 newContact = newContact.c('query').attrs({xmlns : 'jabber:iq:roster'}); 669 newContact = newContact.c('item').attrs({jid: jidTo, name:name , ask:'subscribe', subscription:'to'});726 newContact = newContact.c('item').attrs({jid: jidTo, name:name }); 670 727 newContact = newContact.c('group').t(group).tree(); 671 728 … … 704 761 if( ( divItenContact = document.getElementById('itenContact_' + jidTo))) 705 762 { 763 loadIM.removeGroup( divItenContact.parentNode ); 764 706 765 divItenContact.parentNode.removeChild(divItenContact); 707 766 708 // Delete Object groups709 for( var nameGroup in TrophyIM.rosterObj.groups )710 for(var Jid in TrophyIM.rosterObj.groups[nameGroup])711 if(TrophyIM.rosterObj.groups[nameGroup][Jid] == jidTo )712 delete TrophyIM.rosterObj.groups[nameGroup][Jid];713 714 // Delete Object roster715 if( TrophyIM.rosterObj.roster[jidTo] )716 delete TrophyIM.rosterObj.roster[jidTo];717 718 TrophyIM.rosterObj.save();719 720 767 // Remove Contact 721 var delContact = $iq({type: 'set', id: Date.parse( new Date )}) 768 var _id = TrophyIM.connection.getUniqueId(); 769 var delContact = $iq({type: 'set', id: _id}) 722 770 delContact = delContact.c('query').attrs({xmlns : 'jabber:iq:roster'}); 723 delContact = delContact.c('item').attrs({jid: jidTo, subscription:'remove'}) ;//.tree();771 delContact = delContact.c('item').attrs({jid: jidTo, subscription:'remove'}).tree(); 724 772 725 773 TrophyIM.connection.send(delContact); … … 735 783 renderRoster : function() 736 784 { 737 if( TrophyIM.rosterObj.changes.length > 0 ) 738 { 739 var roster_div = document.getElementById('JabberIMRoster'); 785 var roster_div = document.getElementById('JabberIMRoster'); 786 787 if( roster_div ) 788 { 789 var users = new Array(); 740 790 741 if( roster_div ) 742 { 743 var users = new Array(); 791 for( var user in TrophyIM.rosterObj.roster ) 792 { 793 users[users.length] = TrophyIM.rosterObj.roster[user].contact.jid; 794 } 795 796 users.sort(); 797 798 var groups = new Array(); 799 var flagGeral = false; 800 801 for (var group in TrophyIM.rosterObj.groups) 802 { 803 if( group ) 804 groups[groups.length] = group; 744 805 745 for( var user in TrophyIM.rosterObj.roster ) 746 { 747 users[users.length] = TrophyIM.rosterObj.roster[user].contact.jid; 748 } 806 if( group == "Geral" ) 807 flagGeral = true; 808 } 809 810 if( !flagGeral ) 811 groups[groups.length] = "Geral"; 749 812 750 users.sort(); 751 752 var groups = new Array(); 753 754 for (var group in TrophyIM.rosterObj.groups) 755 { 756 if( group ) 757 groups[groups.length] = group; 758 } 759 760 groups.sort(); 761 762 for ( var i = 0; i < groups.length; i++ ) 763 { 764 TrophyIM.renderGroups( groups[i] , roster_div.lastChild ); 765 } 766 767 TrophyIM.renderItensGroup(users, roster_div); 813 groups.sort(); 814 815 for ( var i = 0; i < groups.length; i++ ) 816 { 817 TrophyIM.renderGroups( groups[i] , roster_div ); 768 818 } 819 820 TrophyIM.renderItensGroup( users, roster_div ); 769 821 } 770 822 … … 781 833 var _addGroup = function() 782 834 { 835 var _nameGroup = nameGroup; 836 var _element = element; 837 783 838 var paramsGroup = 784 839 { 785 'nameGroup' : arguments[0],840 'nameGroup' : _nameGroup, 786 841 'path_jabberit' : path_jabberit 787 842 } 788 843 789 element.innerHTML += loadIM.parse("group","groups.xsl", paramsGroup); 790 844 _element.innerHTML += loadIM.parse("group","groups.xsl", paramsGroup); 791 845 } 792 846 793 847 if( !element.hasChildNodes() ) 794 848 { 795 _addGroup( nameGroup);849 _addGroup(); 796 850 } 797 851 else 798 852 { 799 var elementChild = element;800 var flag 853 var _NodeChild = element.firstChild; 854 var flagAdd = false; 801 855 802 while ( elementChild )803 { 804 if ( elementChild.childNodes[0].childNodes[0].firstChild.nodeValue === nameGroup)856 while( _NodeChild ) 857 { 858 if( _NodeChild.childNodes[0].nodeName.toLowerCase() === "span" ) 805 859 { 806 flag = true; 860 if( _NodeChild.childNodes[0].childNodes[0].nodeValue === nameGroup ) 861 { 862 flagAdd = true; 863 } 807 864 } 808 865 809 elementChild = elementChild.nextSibling;866 _NodeChild = _NodeChild.nextSibling; 810 867 } 811 812 if( !flag ) 813 _addGroup( nameGroup ); 868 869 if( !flagAdd ) 870 { 871 _addGroup(); 872 } 814 873 } 815 816 874 }, 817 875 … … 823 881 renderItensGroup : function( users, element ) 824 882 { 825 var addItem Group= function()883 var addItem = function() 826 884 { 827 885 if( arguments.length > 0 ) 828 886 { 829 887 var objContact = arguments[0]; 830 var element = arguments[1]; 831 var itensJid = document.getElementById( 'itenContact_' + objContact.contact.jid ); 888 var group = arguments[1]; 889 var element = arguments[2]; 890 var index = arguments[3]; 891 892 var itensJid = document.getElementById( 'itenContact_' + objContact.contact.jid + '_' + index ); 832 893 833 894 if( itensJid == null ) … … 853 914 for (var resource in objContact.presence) 854 915 { 855 presence = objContact.presence[resource].show; 856 916 if( objContact.presence[resource].show != 'invisible' ) 917 presence = objContact.presence[resource].show; 918 857 919 if( objContact.presence[resource].status ) 858 920 { … … 867 929 'nameContact' : nameContact, 868 930 'jid' : objContact.contact.jid, 869 'id' : 'itenContact_' + objContact.contact.jid, 931 'id' : 'itenContact_' + objContact.contact.jid + '_' + index , 932 'index' : index, 933 'path_jabberit' : path_jabberit, 870 934 'presence' : presence, 871 'path_jabberit' : path_jabberit,872 935 'status' : status, 873 936 'statusDisplay' : statusDisplay 874 937 } 875 938 876 if( element.id == "rosterIM_with_groups")939 if( group != "") 877 940 { 878 var elementChild = element;879 880 while ( elementChild )941 var _NodeChild = element.firstChild; 942 943 while( _NodeChild ) 881 944 { 882 if( elementChild.childNodes[0].childNodes[0].firstChild.nodeValue == objContact.contact.groups[0] ) 883 elementChild.childNodes[0].innerHTML += loadIM.parse("itens_group", "itensGroup.xsl", paramsContact); 884 885 elementChild = elementChild.nextSibling; 945 if( _NodeChild.childNodes[0].nodeName.toLowerCase() === "span" ) 946 { 947 if( _NodeChild.childNodes[0].childNodes[0].nodeValue === group ) 948 { 949 _NodeChild.innerHTML += loadIM.parse("itens_group", "itensGroup.xsl", paramsContact); 950 } 951 } 952 953 _NodeChild = _NodeChild.nextSibling; 886 954 } 887 } 888 else 889 { 890 element.innerHTML += loadIM.parse("itens_group", "itensGroup.xsl", paramsContact); 891 } 955 } 892 956 } 893 957 else 894 958 { 895 896 959 // Presence e Status 897 960 var presence = "unavailable"; … … 901 964 if (objContact.presence) 902 965 { 903 for ( var resource in objContact.presence)966 for ( var resource in objContact.presence ) 904 967 { 905 968 presence = objContact.presence[resource].show; … … 907 970 if( objContact.presence[resource].status ) 908 971 { 909 status = objContact.presence[resource].status;972 status = " ( " + objContact.presence[resource].status + " ) "; 910 973 statusDisplay = "block"; 911 974 } 975 } 976 } 977 978 var is_open = itensJid.parentNode.childNodes[0].style.backgroundImage; 979 is_open = is_open.indexOf("arrow_down.gif"); 980 981 with ( document.getElementById('span_show_' + 'itenContact_' + objContact.contact.jid + '_' + index ) ) 982 { 983 if( is_open > 0 ) 984 { 985 style.display = statusDisplay; 986 innerHTML = status; 912 987 } 913 988 } 914 915 itensJid.style.background = "url('"+path_jabberit+"templates/default/images/" + presence + ".gif')no-repeat center left"; 916 itensJid.lastChild.style.display = statusDisplay; 917 itensJid.lastChild.innerHTML = " ( " + status + " ) "; 989 990 itensJid.style.background = "url('"+path_jabberit+"templates/default/images/" + presence + ".gif')no-repeat center left"; 918 991 } 992 919 993 } 920 994 } … … 923 997 { 924 998 if( TrophyIM.rosterObj.roster[users[i]].contact.groups ) 925 if( TrophyIM.rosterObj.roster[users[i]].contact.groups[0] ) 926 addItemGroup(TrophyIM.rosterObj.roster[users[i]], element.lastChild ); 999 { 1000 var groups = TrophyIM.rosterObj.roster[users[i]].contact.groups; 1001 1002 if( groups.length > 0 ) 1003 { 1004 for( var j = 0; j < groups.length; j++ ) 1005 addItem( TrophyIM.rosterObj.roster[users[i]], groups[j], element, j ); 1006 } 927 1007 else 928 addItemGroup(TrophyIM.rosterObj.roster[users[i]], element.firstChild ); 1008 { 1009 addItem( TrophyIM.rosterObj.roster[users[i]], "Geral", element, 0 ); 1010 } 1011 } 929 1012 else 930 addItemGroup(TrophyIM.rosterObj.roster[users[i]], element.firstChild ); 1013 { 1014 addItem( TrophyIM.rosterObj.roster[users[i]], "Geral", element, 0 ); 1015 } 931 1016 } 932 1017 }, … … 1029 1114 } 1030 1115 } 1116 1117 /** Function: addChange 1118 * 1119 * Adds given jid to this.changes, keeping this.changes sorted and 1120 * preventing duplicates. 1121 * 1122 * Parameters 1123 * (String) jid : jid to add to this.changes 1124 */ 1125 1126 this.addChange = function(jid) 1127 { 1128 for (var c = 0; c < this.changes.length; c++) 1129 { 1130 if (this.changes[c] == jid) 1131 { 1132 return; 1133 } 1134 } 1135 1136 this.changes[this.changes.length] = jid; 1137 1138 this.changes.sort(); 1139 } 1031 1140 1032 1141 /** Function: addContact … … 1038 1147 * (String) subscription - subscription attribute for contact 1039 1148 * (String) name - name attribute for contact 1040 * (Array) groups - array of groups contact is member of 1041 */ 1042 1043 this.addContact = function(jid, subscription, name, groups) 1044 { 1045 var contact = { jid:jid, subscription:subscription, name:name, groups:groups } 1046 var jid_lower = jid.toLowerCase(); 1047 1048 if ( this.roster[jid_lower] ) 1049 { 1050 this.roster[jid_lower]['contact'] = contact; 1051 } 1052 else 1053 { 1054 this.roster[jid_lower] = {contact:contact}; 1055 } 1056 1057 groups = groups ? groups : ['']; 1058 1059 for ( var g = 0; g < groups.length; g++ ) 1060 { 1061 if ( !this.groups[groups[g]] ) 1062 { 1063 this.groups[groups[g]] = {}; 1064 } 1065 1066 this.groups[groups[g]][jid_lower] = jid_lower; 1067 } 1149 * (Array) groups - array of groups contact is member of 1150 */ 1151 1152 this.addContact = function(jid, subscription, name, groups ) 1153 { 1154 if( jid != loadIM.getUserCurrent().jid ) 1155 { 1156 if( subscription !== "remove" ) 1157 { 1158 var contact = { jid:jid, subscription:subscription, name:name, groups:groups } 1159 var jid_lower = jid.toLowerCase(); 1160 1161 if ( this.roster[jid_lower] ) 1162 { 1163 this.roster[jid_lower]['contact'] = contact; 1164 } 1165 else 1166 { 1167 this.roster[jid_lower] = {contact:contact}; 1168 } 1169 1170 groups = groups ? groups : ['']; 1171 1172 for ( var g = 0; g < groups.length; g++ ) 1173 { 1174 if ( !this.groups[groups[g]] ) 1175 { 1176 this.groups[groups[g]] = {}; 1177 } 1178 1179 this.groups[groups[g]][jid_lower] = jid_lower; 1180 } 1181 } 1182 else 1183 { 1184 this.removeContact(jid); 1185 } 1186 } 1068 1187 } 1188 1069 1189 /** Function: getContact 1070 1190 * … … 1073 1193 * Parameter: (String) jid - jid to return 1074 1194 */ 1195 1075 1196 this.getContact = function(jid) 1076 1197 { … … 1080 1201 } 1081 1202 } 1203 1204 /** Function: getPresence 1205 * 1206 * Returns best presence for given jid as Array(resource, priority, show, 1207 * status) 1208 * 1209 * Parameter: (String) fulljid - jid to return best presence for 1210 */ 1211 1212 this.getPresence = function(fulljid) 1213 { 1214 var jid = Strophe.getBareJidFromJid(fulljid); 1215 var current = null; 1216 1217 if (this.roster[jid.toLowerCase()] && this.roster[jid.toLowerCase()]['presence']) 1218 { 1219 for (var resource in this.roster[jid.toLowerCase()]['presence']) 1220 { 1221 var presence = this.roster[jid.toLowerCase()]['presence'][resource]; 1222 if (current == null) 1223 { 1224 current = presence 1225 } 1226 else 1227 { 1228 if(presence['priority'] > current['priority'] && ((presence['show'] == "chat" 1229 || presence['show'] == "available") || (current['show'] != "chat" || 1230 current['show'] != "available"))) 1231 { 1232 current = presence 1233 } 1234 } 1235 } 1236 } 1237 return current; 1238 } 1239 1240 /** Function: groupHasChanges 1241 * 1242 * Returns true if current group has members in this.changes 1243 * 1244 * Parameters: 1245 * (String) group - name of group to check 1246 */ 1247 1248 this.groupHasChanges = function(group) 1249 { 1250 for (var c = 0; c < this.changes.length; c++) 1251 { 1252 if (this.groups[group][this.changes[c]]) 1253 { 1254 return true; 1255 } 1256 } 1257 return false; 1258 } 1259 1260 /** Function removeContact 1261 * 1262 * Parameters 1263 * (String) jid 1264 */ 1265 1266 this.removeContact = function(jid) 1267 { 1268 var groups = this.roster[ jid ].contact.groups; 1269 1270 for ( var i = 0; i < groups.length; i++ ) 1271 { 1272 delete this.groups[ groups[ i ] ][ jid ]; 1273 } 1274 1275 for ( var i = 0; i < groups.length; i++ ) 1276 { 1277 var contacts = 0; 1278 for ( var contact in this.groups[ groups[ i ] ] ) 1279 contacts++; 1280 1281 if ( ! contacts ) 1282 delete this.groups[ groups[ i ] ]; 1283 } 1284 1285 // Delete Object roster 1286 if( this.roster[jid] ) 1287 delete this.roster[jid]; 1288 } 1289 1082 1290 /** Function: setPresence 1083 1291 * … … 1097 1305 var jid_lower = barejid.toLowerCase(); 1098 1306 1099 if( show != 'unavailable') 1100 { 1101 if (!this.roster[jid_lower]) 1102 { 1103 this.addContact(barejid, 'not-in-roster'); 1104 } 1105 var presence = 1106 { 1107 resource:resource, priority:priority, show:show, status:status 1108 } 1109 1110 if (!this.roster[jid_lower]['presence']) 1111 { 1112 this.roster[jid_lower]['presence'] = {} 1113 } 1114 this.roster[jid_lower]['presence'][resource] = presence 1115 } 1116 else if (this.roster[jid_lower] && this.roster[jid_lower]['presence'] && this.roster[jid_lower]['presence'][resource]) 1117 { 1118 delete this.roster[jid_lower]['presence'][resource]; 1119 } 1120 1121 this.addChange(jid_lower); 1122 1123 if (TrophyIM.activeChats['divs'][jid_lower]) 1124 { 1125 TrophyIM.setTabPresence(jid_lower, TrophyIM.activeChats['divs'][jid_lower]['tab']); 1307 if( barejid != loadIM.getUserCurrent().jid ) 1308 { 1309 if( show != 'unavailable') 1310 { 1311 if (!this.roster[jid_lower]) 1312 { 1313 this.addContact(barejid, 'not-in-roster'); 1314 } 1315 var presence = 1316 { 1317 resource:resource, priority:priority, show:show, status:status 1318 } 1319 1320 if (!this.roster[jid_lower]['presence']) 1321 { 1322 this.roster[jid_lower]['presence'] = {} 1323 } 1324 this.roster[jid_lower]['presence'][resource] = presence 1325 } 1326 else if (this.roster[jid_lower] && this.roster[jid_lower]['presence'] && this.roster[jid_lower]['presence'][resource]) 1327 { 1328 delete this.roster[jid_lower]['presence'][resource]; 1329 } 1330 1331 this.addChange(jid_lower); 1332 1333 if (TrophyIM.activeChats['divs'][jid_lower]) 1334 { 1335 TrophyIM.setTabPresence(jid_lower, TrophyIM.activeChats['divs'][jid_lower]['tab']); 1336 } 1126 1337 } 1127 1338 } 1128 /** Function: addChange 1129 * 1130 * Adds given jid to this.changes, keeping this.changes sorted and 1131 * preventing duplicates. 1132 * 1133 * Parameters 1134 * (String) jid : jid to add to this.changes 1135 */ 1136 this.addChange = function(jid) { 1137 for (var c = 0; c < this.changes.length; c++) { 1138 if (this.changes[c] == jid) { 1139 return; 1140 } 1141 } 1142 this.changes[this.changes.length] = jid; 1143 this.changes.sort(); 1144 } 1145 /** Function: getPresence 1146 * 1147 * Returns best presence for given jid as Array(resource, priority, show, 1148 * status) 1149 * 1150 * Parameter: (String) fulljid - jid to return best presence for 1151 */ 1152 this.getPresence = function(fulljid) { 1153 var jid = Strophe.getBareJidFromJid(fulljid); 1154 var current = null; 1155 if (this.roster[jid.toLowerCase()] && 1156 this.roster[jid.toLowerCase()]['presence']) { 1157 for (var resource in this.roster[jid.toLowerCase()]['presence']) { 1158 var presence = this.roster[jid.toLowerCase()]['presence'][resource]; 1159 if (current == null) { 1160 current = presence 1161 } else { 1162 if(presence['priority'] > current['priority'] && ((presence['show'] == "chat" 1163 || presence['show'] == "available") || (current['show'] != "chat" || 1164 current['show'] != "available"))) { 1165 current = presence 1166 } 1167 } 1168 } 1169 } 1170 return current; 1171 } 1172 /** Function: groupHasChanges 1173 * 1174 * Returns true if current group has members in this.changes 1175 * 1176 * Parameters: 1177 * (String) group - name of group to check 1178 */ 1179 this.groupHasChanges = function(group) { 1180 for (var c = 0; c < this.changes.length; c++) { 1181 if (this.groups[group][this.changes[c]]) { 1182 return true; 1183 } 1184 } 1185 return false; 1186 } 1187 /** Fuction: save 1188 * 1189 * Saves roster data to JSON store 1190 */ 1191 this.save = function() { 1192 if (TrophyIM.JSONStore.store_working) { 1193 TrophyIM.JSONStore.setData({roster:this.roster, 1194 groups:this.groups, active_chat:TrophyIM.activeChats['current'], 1195 chat_history:TrophyIM.chatHistory}); 1196 } 1197 } 1339 1340 /** Fuction: save 1341 * 1342 * Saves roster data to JSON store 1343 */ 1344 1345 this.save = function() 1346 { 1347 if (TrophyIM.JSONStore.store_working) 1348 { 1349 TrophyIM.JSONStore.setData({roster:this.roster, 1350 groups:this.groups, active_chat:TrophyIM.activeChats['current'], 1351 chat_history:TrophyIM.chatHistory}); 1352 } 1353 } 1354 1198 1355 } 1199 1356 /** Class: TrophyIMJSONStore
Note: See TracChangeset
for help on using the changeset viewer.