Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix some bugs, add setGroups: and setGroupNames: to the API; comments…

…; fix accidental global
  • Loading branch information...
commit 973fa1adb19b6cbfbd8f41ea524b1cfe78187bde 1 parent d51b3a6
Antoine Mercadal authored
Showing with 56 additions and 16 deletions.
  1. +49 −13 TNStropheContact.j
  2. +7 −3 TNStropheRoster.j
View
62 TNStropheContact.j
@@ -363,42 +363,77 @@
_nickname = oldNickname;
}
-/*! this allows to change the group of the contact. Will post TNStropheContactGroupUpdatedNotification
+/*! add contact to the given group
+ @param aGroup the group to add the contact in
*/
-- (void)addGroup:(TNStropheGroup)newGroup
+- (void)addGroup:(TNStropheGroup)aGroup
{
- [self changeGroupName:[newGroup name]];
+ [self addGroupName:[aGroup name]];
}
-- (void)addGroupName:(CPString)aNewName
+/*! add contact to the given group identified by name
+ @param aGroupName the group name to add the contact in
+*/
+- (void)addGroupName:(CPString)aGroupName
{
- if ([_groupNames containsObject:aNewName])
+ if ([_groupNames containsObject:aGroupName])
return;
- [_groupNames addObject:aNewName];
+ [_groupNames addObject:aGroupName];
[self sendRosterSet];
- [_groupNames removeObject:aNewName];
+ [_groupNames removeObject:aGroupName];
[[CPNotificationCenter defaultCenter] postNotificationName:TNStropheContactGroupUpdatedNotification object:self];
}
-- (void)removeGroup:(TNStropheGroup)newGroup
+/*! remove contact from the given group
+ @param aGroup the group to remove the contact from
+*/
+- (void)removeGroup:(TNStropheGroup)aGroup
{
- [self changeGroupName:[newGroup name]];
+ [self removeGroupName:[aGroup name]];
}
-- (void)removeGroupName:(CPString)aNewName
+/*! remove contact from the given group identified by name
+ @param aGroupName the group name to remove the contact from
+*/
+- (void)removeGroupName:(CPString)aGroupName
{
- if (![_groupNames containsObject:aNewName])
+ if (![_groupNames containsObject:aGroupName])
return;
- [_groupNames removeObject:aNewName];
+ [_groupNames removeObject:aGroupName];
[self sendRosterSet];
- [_groupNames addObject:aNewName];
+ [_groupNames addObject:aGroupName];
[[CPNotificationCenter defaultCenter] postNotificationName:TNStropheContactGroupUpdatedNotification object:self];
}
+/*! set the groups of the contact
+ @param someGroups array of groups
+*/
+- (void)setGroups:(CPArray)someGroups
+{
+ var groupNames = [CPArray array];
+ for (var i = 0; i < [someGroups count]; i++)
+ [groupNames addObject:[[someGroups objectAtIndex:i] name]];
+
+ [self setGroupNames:groupNames];
+}
+
+/*! set the groups names of the contact
+ @param someGroupNames array of group names
+*/
+- (void)setGroupNames:(CPArray)someGroupNames
+{
+ var oldGroupNames = [someGroupNames copy];
+ _groupNames = someGroupNames;
+ [self sendRosterSet];
+ _groupNames = oldGroupNames;
+}
+
+/*! send a roster SET to the XMPP server according to the content of _groupNames
+*/
- (void)sendRosterSet
{
var stanza = [TNStropheStanza iqWithAttributes:{"type": "set"}];
@@ -409,6 +444,7 @@
{
[stanza addChildWithName:@"group"];
[stanza addTextNode:[_groupNames objectAtIndex:i]];
+ [stanza up];
}
[_connection send:stanza];
View
10 TNStropheRoster.j
@@ -222,8 +222,12 @@
*/
- (void)removeGroup:(TNStropheGroup)aGroup
{
- for (var i = 0; i < [aGroup count]; i++)
- [self changeGroup:_defaultGroup ofContact:[[aGroup contacts] objectAtIndex:i]];
+ for (var i = 0; i < [_contacts count]; i++)
+ {
+ var contact = [_contacts objectAtIndex:i];
+ [contact removeGroup:aGroup];
+ }
+
[_groups removeObject:aGroup];
[[CPNotificationCenter defaultCenter] postNotificationName:TNStropheRosterRemovedGroupNotification object:aGroup];
}
@@ -486,7 +490,7 @@
- (void)removeContact:(TNStropheContact)aContact
{
var uid = [_connection getUniqueIdWithSuffix:@"roster"],
- removeReq = [TNStropheStanza iqWithAttributes:{"type": "set", "id": uid}];
+ removeReq = [TNStropheStanza iqWithAttributes:{"type": "set", "id": uid}],
params = [CPDictionary dictionaryWithObjectsAndKeys:uid, @"id"];
[removeReq addChildWithName:@"query" andAttributes: {'xmlns':Strophe.NS.ROSTER}];
Please sign in to comment.
Something went wrong with that request. Please try again.