Ignore:
Timestamp:
08/03/10 14:27:44 (14 years ago)
Author:
alexandrecorreia
Message:

Ticket #1091 - Implementado a busca de salas para bate-papo no novo modulo Expresso messenger XEP-0045-MUC.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/jabberit_messenger/jmessenger/js/trophyim.js

    r3099 r3126  
    142142        autoConnection : { connect : true }, 
    143143 
     144        /** Active Chat Room 
     145         *  
     146         */ 
     147         
     148        activeChatRoom : { name : [] }, 
     149         
    144150        /** Object: chatHistory 
    145151    * 
     
    663669    { 
    664670        var xquery = msg.getElementsByTagName("x"); 
    665          
     671         
    666672        if ( xquery.length > 0 ) 
    667673        { 
     
    672678                if( xmlns.indexOf("http://jabber.org/protocol/muc#user") == 0 ) 
    673679                { 
    674                         var nameChatRoom = xquery[i].parentNode.getAttribute('from'); 
    675                                 nameChatRoom = Strophe.getBareJidFromJid(nameChatRoom); 
    676  
    677                         var nickName = xquery[i].parentNode.getAttribute('from'); 
    678                                 nickName = Strophe.getResourceFromJid(nickName); 
     680                        var _from       = xquery[i].parentNode.getAttribute('from'); 
     681                        var _to         = xquery[i].parentNode.getAttribute('to'); 
     682 
     683                        // Get NameChatRoom 
     684                        var nameChatRoom        = Strophe.getBareJidFromJid( _from ); 
    679685                         
    680                         var type = xquery[i].parentNode.getAttribute('type') ? xquery[i].parentNode.getAttribute('type') : 'available' ; 
     686                        // Get nickName 
     687                        var nickName            = Strophe.getResourceFromJid( _from ); 
    681688                         
    682                         var show = ( xquery[i].parentNode.firstChild.firstChild != null ) ? xquery[i].parentNode.firstChild.firstChild.nodeValue : type ; 
     689                        // Get Type/Show 
     690                        var type        = ( xquery[i].parentNode.getAttribute('type') != null ) ? xquery[i].parentNode.getAttribute('type') : 'available' ; 
     691                        var show        = ( xquery[i].parentNode.firstChild.nodeName == "show" ) ? xquery[i].parentNode.firstChild.firstChild.nodeValue : type; 
    683692                         
    684                         if( xquery[i].firstChild.getAttribute('jid') ) 
    685                         { 
    686                                 if ( Strophe.getBareJidFromJid( xquery[i].firstChild.getAttribute('jid') ) == Strophe.getBareJidFromJid( TrophyIM.connection.jid ) ) 
    687                                         show = loadscript.getStatusUserIM(); 
    688                         } 
    689                          
    690                         var _UserChatRoom = document.createElement("div"); 
    691                                 _UserChatRoom.id = nameChatRoom + "_UserChatRoom__" + xquery[i].firstChild.getAttribute('jid'); 
    692                                 _UserChatRoom.setAttribute("style","padding-left:18px ; margin:3px 0px 0px 2px; background: url('"+path_jabberit+"templates/default/images/" + show + ".gif')no-repeat center left"); 
    693                                 _UserChatRoom.appendChild( document.createTextNode(nickName) ); 
    694                  
    695                         var nodeUser = document.getElementById(nameChatRoom + "_UserChatRoom__" + xquery[i].firstChild.getAttribute('jid') );            
    696                                  
    697                         if( nodeUser == null && xquery[i].firstChild.getAttribute('jid') ) 
     693                        var _idElement = nameChatRoom + "_UserChatRoom__" + nickName; 
     694                           
     695                        var _UserChatRoom               = document.createElement("div"); 
     696                                _UserChatRoom.id        = _idElement; 
     697                                _UserChatRoom.setAttribute("style","padding-left:18px ; margin:3px 0px 0px 2px; background: url('"+path_jabberit+"templates/default/images/" + show + ".gif')no-repeat center left"); 
     698                                _UserChatRoom.appendChild( document.createTextNode( nickName ) ); 
     699 
     700                        var nodeUser = document.getElementById( _idElement );    
     701                                 
     702                        if( nodeUser == null ) 
    698703                        { 
    699704                                if( document.getElementById( nameChatRoom + '__roomChat__participants' ) != null ) 
     
    704709                                else 
    705710                                { 
    706                                         TrophyIM.makeChatRoom( nameChatRoom, nameChatRoom ); 
     711                                        TrophyIM.makeChatRoom( nameChatRoom, nameChatRoom.substring(0, nameChatRoom.indexOf('@'))); 
    707712                                        nameChatRoom = document.getElementById( nameChatRoom + '__roomChat__participants' ); 
    708713                                        nameChatRoom.appendChild( _UserChatRoom ); 
     
    713718                                if( type == 'unavailable' ) 
    714719                                { 
    715                                         var nodeUser = ""; 
    716                                          
    717                                         if( xquery[i].firstChild.getAttribute('jid') != null ) 
    718                                                 nodeUser = document.getElementById( nameChatRoom + "_UserChatRoom__" + xquery[i].firstChild.getAttribute('jid') ); 
    719                                         else 
    720                                                 nodeUser = document.getElementById( nameChatRoom + "_UserChatRoom__" + xquery[i].parentNode.getAttribute('to') ); 
    721                                          
    722720                                        nodeUser.parentNode.removeChild( nodeUser ); 
    723721                                } 
    724722                                else if( show ) 
    725723                                { 
    726                                         var _UserChatRoom = document.getElementById( nameChatRoom + "_UserChatRoom__" + xquery[i].firstChild.getAttribute('jid') ) 
    727                                                 _UserChatRoom.setAttribute("style","padding-left:18px ; margin:3px 0px 0px 2px; background: url('"+path_jabberit+"templates/default/images/" + show + ".gif')no-repeat center left");    
     724                                        nodeUser.setAttribute("style","padding-left:18px ; margin:3px 0px 0px 2px; background: url('"+path_jabberit+"templates/default/images/" + show + ".gif')no-repeat center left");         
    728725                                } 
    729726                        } 
     
    11021099        { 
    11031100                TrophyIM.leaveChatRoom( jidChatRoom ); 
     1101                 
     1102                if( TrophyIM.activeChatRoom.name.length > 0 ) 
     1103                { 
     1104                        for( var i = 0;  i < TrophyIM.activeChatRoom.name.length ; i++ ) 
     1105                        { 
     1106                                if( TrophyIM.activeChatRoom.name[i].indexOf( jidChatRoom ) >= 0 ) 
     1107                                { 
     1108                                        TrophyIM.activeChatRoom.name[i] = ""; 
     1109                                } 
     1110                        } 
     1111                } 
    11041112 
    11051113                setTimeout( function() 
     
    12751283    joinChatRoom : function( roomName ) 
    12761284    { 
    1277         var presence = $pres({from: TrophyIM.connection.jid, to: roomName}).c("x",{xmlns: Strophe.NS.MUC}); 
     1285        var presence = $pres( {from: TrophyIM.connection.jid, to: roomName} ).c("x",{xmlns: Strophe.NS.MUC}); 
    12781286         
    12791287                TrophyIM.connection.send( presence ); 
     
    13031311    getListRooms : function() 
    13041312    { 
    1305         var _error_return = function(element) 
     1313        if( TrophyIM.statusConn.connected ) 
    13061314        { 
    1307                 alert( " ERROR : " + element ); 
    1308         }; 
    1309          
    1310                 var iq = $iq({to: "conference.im.pr.gov.br", type: "get"}).c("query",{xmlns: Strophe.NS.DISCO_ITEMS});                   
    1311                  
    1312         TrophyIM.connection.sendIQ( iq, loadscript.listRooms, _error_return, 500 );              
     1315                var _error_return = function(element) 
     1316                { 
     1317                        alert("ERRO : Tente novamente !"); 
     1318                }; 
     1319                 
     1320                        var iq = $iq({ to: TROPHYIM_CHATROOM, type: "get" }).c("query",{xmlns: Strophe.NS.DISCO_ITEMS });                
     1321                         
     1322                TrophyIM.connection.sendIQ( iq, loadscript.listRooms, _error_return, 500 ); 
     1323        }else 
     1324                alert( "ERRO : Sem conexão com o servidor " + TROPHYIM_CHATROOM ); 
     1325                     
    13131326    }, 
    13141327     
     
    17481761        TrophyIM.connection.send($pres( ).attrs({ from: jidFrom, to: jidTo, type: _typeSubscription, id: _id }).tree()); 
    17491762        }, 
    1750      
     1763 
    17511764        /** Function: setPresence 
    17521765     * 
     
    17551768        setPresence : function( _type ) 
    17561769        { 
     1770                var presence_chatRoom = ""; 
     1771                 
    17571772                if( _type != 'status') 
    17581773                { 
     
    18041819                                                         
    18051820                                                        TrophyIM.connection.send( _presence.tree() ); 
     1821                                                         
     1822                                                        presence_chatRoom = _type; 
    18061823                                                } 
    18071824                                                else 
    18081825                                                { 
    18091826                                                        TrophyIM.connection.send($pres( ).c('show').t(_type).tree()); 
     1827                                                         
     1828                                                        presence_chatRoom = _type; 
    18101829                                                } 
    18111830                                        } 
     
    18511870                                 
    18521871                                TrophyIM.connection.send( _presence.tree() ); 
    1853                         } 
    1854                 } 
     1872                                 
     1873                                presence_chatRoom = _show; 
     1874                        } 
     1875                } 
     1876                 
     1877                // Send Presence Chat Room 
     1878                if( TrophyIM.activeChatRoom.name.length > 0 ) 
     1879                { 
     1880                        for( var i in TrophyIM.activeChatRoom.name ) 
     1881                        { 
     1882                                if( TrophyIM.activeChatRoom.name[i] != "" ) 
     1883                                        TrophyIM.connection.send($pres( { to : TrophyIM.activeChatRoom.name[i] } ).c('show').t( presence_chatRoom ) ); 
     1884                        } 
     1885                } 
     1886 
    18551887        }, 
    18561888         
Note: See TracChangeset for help on using the changeset viewer.