Skip to content

Commit 5b5ffe8

Browse files
committed
Merge pull request #40 from allan-simon/more_precise_control_on_roster_update_events
now we send also in the 'roster updated' callback, the state
2 parents 8056cbc + 483e6b8 commit 5b5ffe8

File tree

1 file changed

+31
-12
lines changed

1 file changed

+31
-12
lines changed

roster/strophe.roster.js

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -374,13 +374,16 @@ Strophe.addConnectionPlugin('roster',
374374
},
375375

376376
/** PrivateFunction: _call_backs
377-
*
377+
* first parameter is the full roster
378+
* second is optional, newly added or updated item
379+
* third is otional, in case of update, send the previous state of the
380+
* update item
378381
*/
379-
_call_backs : function(items, item)
382+
_call_backs : function(items, item, previousItem)
380383
{
381384
for (var i = 0; i < this._callbacks.length; i++) // [].forEach my love ...
382385
{
383-
this._callbacks[i](items, item);
386+
this._callbacks[i](items, item, previousItem);
384387
}
385388
},
386389
/** PrivateFunction: _onReceiveIQ
@@ -419,24 +422,33 @@ Strophe.addConnectionPlugin('roster',
419422
/** PrivateFunction: _updateItem
420423
* Update internal representation of roster item
421424
*/
422-
_updateItem : function(item)
425+
_updateItem : function(itemTag)
423426
{
424-
var jid = item.getAttribute("jid");
425-
var name = item.getAttribute("name");
426-
var subscription = item.getAttribute("subscription");
427-
var ask = item.getAttribute("ask");
427+
var jid = itemTag.getAttribute("jid");
428+
var name = itemTag.getAttribute("name");
429+
var subscription = itemTag.getAttribute("subscription");
430+
var ask = itemTag.getAttribute("ask");
428431
var groups = [];
429-
Strophe.forEachChild(item, 'group',
432+
433+
Strophe.forEachChild(itemTag, 'group',
430434
function(group)
431435
{
432436
groups.push(Strophe.getText(group));
433437
}
434438
);
435439

440+
var item;
441+
var previousItem;
442+
436443
if (subscription == "remove")
437444
{
438-
this.removeItem(jid);
439-
this._call_backs(this.items, {jid: jid, subscription: 'remove'});
445+
var hashBeenRemoved = this.removeItem(jid);
446+
if (hashBeenRemoved) {
447+
this._call_backs(
448+
this.items,
449+
{jid: jid, subscription: 'remove'}
450+
);
451+
}
440452
return;
441453
}
442454

@@ -455,11 +467,18 @@ Strophe.addConnectionPlugin('roster',
455467
}
456468
else
457469
{
470+
previousItem = {
471+
name: item.name,
472+
subscription: item.subscription,
473+
ask: item.ask,
474+
groups: item.groups
475+
}
476+
458477
item.name = name;
459478
item.subscription = subscription;
460479
item.ask = ask;
461480
item.groups = groups;
462481
}
463-
this._call_backs(this.items, item);
482+
this._call_backs(this.items, item, previousItem);
464483
}
465484
});

0 commit comments

Comments
 (0)