@@ -25,6 +25,7 @@ Strophe.addConnectionPlugin('roster',
2525 {
2626 this . _connection = conn ;
2727 this . _callbacks = [ ] ;
28+ this . _callbacks_request = [ ] ;
2829 /** Property: items
2930 * Roster items
3031 * [
@@ -141,6 +142,12 @@ Strophe.addConnectionPlugin('roster',
141142 {
142143 this . _callbacks . push ( call_back ) ;
143144 } ,
145+
146+ registerRequestCallback : function ( call_back )
147+ {
148+ this . _callbacks_request . push ( call_back ) ;
149+ } ,
150+
144151 /** Function: findItem
145152 * Find item by JID
146153 *
@@ -323,12 +330,16 @@ Strophe.addConnectionPlugin('roster',
323330 var jid = presence . getAttribute ( 'from' ) ;
324331 var from = Strophe . getBareJidFromJid ( jid ) ;
325332 var item = this . findItem ( from ) ;
333+ var type = presence . getAttribute ( 'type' ) ;
326334 // not in roster
327335 if ( ! item )
328336 {
337+ // if 'friend request' presence
338+ if ( type === 'subscribe' ) {
339+ this . _call_backs_request ( from ) ;
340+ }
329341 return true ;
330342 }
331- var type = presence . getAttribute ( 'type' ) ;
332343 if ( type == 'unavailable' )
333344 {
334345 delete item . resources [ Strophe . getResourceFromJid ( jid ) ] ;
@@ -350,6 +361,17 @@ Strophe.addConnectionPlugin('roster',
350361 this . _call_backs ( this . items , item ) ;
351362 return true ;
352363 } ,
364+ /** PrivateFunction: _call_backs_request
365+ * call all the callbacks waiting for 'friend request' presences
366+ */
367+ _call_backs_request : function ( from )
368+ {
369+ for ( var i = 0 ; i < this . _callbacks_request . length ; i ++ ) // [].forEach my love ...
370+ {
371+ this . _callbacks_request [ i ] ( from ) ;
372+ }
373+ } ,
374+
353375 /** PrivateFunction: _call_backs
354376 *
355377 */
0 commit comments