Skip to content

Commit eeb58e4

Browse files
committed
Merge pull request #25 from allan-simon/add_friend_request_callbacks
Add friend request callbacks
2 parents c0f1ee3 + f737a3f commit eeb58e4

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "strophejs-plugins",
3-
"version": "0.0.2",
3+
"version": "0.0.3",
44
"ignore": [
55
".gitignore",
66
".jshintignore",

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)