Skip to content

Commit a1824c1

Browse files
author
Allan Simon
committed
now we have callbacks for 'friend request' presence
and a way for people using the plugin to register their own callbacks on that event
1 parent 6ccb087 commit a1824c1

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

roster/strophe.roster.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)