@ -98,92 +98,18 @@ var BasicClient = function(params, callback) {
try {
// This is a presences for a conference
if ( stanza . attrs . from . indexOf ( 'conference' ) === - 1 || stanza . attrs . from . indexOf ( 'conference' ) < stanza . attrs . from . indexOf ( '@' ) ) {
if ( stanza . attrs . from . toString ( ) . indexOf ( '/' ) > - 1 ) {
var user = stanza . attrs . from . split ( '/' ) [ 0 ] ;
var resource = stanza . attrs . from . substr ( stanza . attrs . from . indexOf ( '/' ) + 1 ) ;
} else {
var user = stanza . attrs . from . toString ( ) ;
var resource = "unknown" ;
}
if ( typeof jabber . presences . users === "undefined" || jabber . presences . users === null ) {
jabber . presences . users = { } ;
}
var user = stanza . attrs . from . toString ( ) ;
if ( stanza . attrs . type === "unavailable" ) {
if ( typeof jabber . presences . users [ user ] !== "undefined" && jabber . presences [ user ] !== null ) {
delete jabber . presences [ user ] [ resource ] ;
if ( Object . keys ( jabber . presences [ user ] ) . length === 0 ) {
delete jabber . presences [ user ] ;
}
if ( typeof jabber . presences [ user ] !== "undefined" ) {
delete jabber . presences [ user ] ;
}
} else {
if ( typeof jabber . presences . users [ user ] === "undefined" ) {
jabber . presences . users [ user ] = { } ;
}
if ( typeof jabber . presences . users [ user ] [ resource ] === "undefined" ) {
jabber . presences . users [ user ] [ resource ] = { } ;
newPresence = true ;
}
jabber . presences . users [ user ] [ resource ] = {
user : user ,
resource : resource ,
jid : stanza . attrs . from ,
priority : stanza . getChildText ( 'priority' ) ,
show : stanza . getChildText ( 'show' ) ,
status : stanza . getChildText ( 'status' )
} ;
jabber . presences [ user ] = stanza ;
}
} else {
var conference = stanza . attrs . from . split ( '/' ) [ 0 ] ;
var nickname = stanza . attrs . from . substr ( stanza . attrs . from . indexOf ( '/' ) + 1 ) ;
// Kill self references
if ( nickname === jabber . params . nickname ) {
return false ;
}
if ( stanza . attrs . type === "unavailable" ) {
delete jabber . presences . muc [ conference ] [ nickname ] ;
} else {
if ( typeof jabber . presences . muc [ conference ] === "undefined" ) {
jabber . presences . muc [ conference ] = { } ;
}
if ( typeof jabber . presences . muc [ conference ] [ nickname ] === "undefined" ) {
jabber . presences . muc [ conference ] [ nickname ] = { } ;
newPresence = true ;
}
jabber . presences . muc [ conference ] [ nickname ] = {
priority : stanza . getChildText ( "priority" ) ,
show : stanza . getChildText ( "show" ) ,
status : stanza . getChildText ( "status" )
} ;
// Look to see if we have access to the user"s full details or if this is an anonymous room
if ( typeof stanza . getChild ( "x" , "http://jabber.org/protocol/muc#user" ) !== "undefined" ) {
var userDetails = stanza . getChild ( "x" , "http://jabber.org/protocol/muc#user" ) . getChild ( "item" ) ;
jabber . presences . muc [ conference ] [ nickname ] . affiliation = userDetails . attrs . affiliation ;
jabber . presences . muc [ conference ] [ nickname ] . role = userDetails . attrs . role ;
if ( typeof userDetails . attrs . jid !== "undefined" ) {
var user = userDetails . attrs . jid . split ( "/" ) [ 0 ] ;
var resource = userDetails . attrs . jid . split ( "/" ) [ 1 ] ;
jabber . presences . muc [ conference ] [ nickname ] . jid = user ;
jabber . presences . muc [ conference ] [ nickname ] . resource = resource ;
}
}
}
}
jabber . emit ( 'presence' , stanza , newPresence );
jabber . emit ( 'presence' , stanza ) ;
} catch ( err ) {
console . log ( "Something went wrong parsing presences: " + err . toString ( ) ) ;
console . log ( stanza . toString ( ) ) ;