Skip to content
Browse files

allow to retract more than items at once

  • Loading branch information...
1 parent cce1b2c commit 36f02d56a8944754e1ba6c87d0a134fd7e5facfa Antoine Mercadal committed
Showing with 16 additions and 5 deletions.
  1. +16 −5 PubSub/TNPubSubNode.j
View
21 PubSub/TNPubSubNode.j
@@ -443,6 +443,11 @@ TNStrophePubSubNodeUnsubscribedNotification = @"TNStrophePubSubNodeUnsubscribedN
*/
- (void)retractItemWithID:(CPString)anID
{
+ [self retractItemsWithIDs:[anID]];
+}
+
+- (void)retractItemsWithIDs:(CPArray)someIDs
+{
var uid = [_connection getUniqueId],
stanza = [TNStropheStanza iq],
params = [CPDictionary dictionaryWithObjectsAndKeys:uid, @"id"];
@@ -452,10 +457,16 @@ TNStrophePubSubNodeUnsubscribedNotification = @"TNStrophePubSubNodeUnsubscribedN
[stanza setID:uid];
[stanza addChildWithName:@"pubsub" andAttributes:{@"xmlns": Strophe.NS.PUBSUB}];
- [stanza addChildWithName:@"retract" andAttributes:{@"node": _nodeName}];
- [stanza addChildWithName:@"item" andAttributes:{@"id": anID}];
- [_connection registerSelector:@selector(_didRetractPubSubItem:) ofObject:self withDict:params];
+ for (var i = 0; i < [someIDs count]; i++)
+ {
+ [stanza addChildWithName:@"retract" andAttributes:{@"node": _nodeName}];
+ [stanza addChildWithName:@"item" andAttributes:{@"id": [someIDs objectAtIndex:i]}];
+ [stanza up];
+ [stanza up];
+ }
+
+ [_connection registerSelector:@selector(_didRetractPubSubItems:) ofObject:self withDict:params];
[_connection send:stanza];
}
@@ -463,7 +474,7 @@ TNStrophePubSubNodeUnsubscribedNotification = @"TNStrophePubSubNodeUnsubscribedN
@param aStanza TNStropheStanza contaning the response of the server
@return NO in order to unregister the selector from connection
*/
-- (BOOL)_didRetractPubSubItem:(TNStropheStanza)aStanza
+- (BOOL)_didRetractPubSubItems:(TNStropheStanza)aStanza
{
if ([aStanza type] == @"result")
{
@@ -473,7 +484,7 @@ TNStrophePubSubNodeUnsubscribedNotification = @"TNStrophePubSubNodeUnsubscribedN
else
{
[[CPNotificationCenter defaultCenter] postNotificationName:TNStrophePubSubItemRetractErrorNotification object:self userInfo:aStanza];
- CPLog.error("Cannot remove the pubsub item in node");
+ CPLog.error("Cannot remove the pubsub items from node");
CPLog.error(aStanza);
}

0 comments on commit 36f02d5

Please sign in to comment.
Something went wrong with that request. Please try again.