Permalink
Browse files

Handle multiple groups when processing roster pushes

  • Loading branch information...
1 parent 7ca6b4a commit d163176c11795fdb69b31c634e816abcb2a3561d @benlangfeld committed Jan 15, 2011
Showing with 36 additions and 20 deletions.
  1. +34 −18 TNStropheRoster.j
  2. +2 −2 TNStropheRosterBase.j
View
@@ -285,7 +285,7 @@
@param aContact the contact
@return CPArray of TNStropheGroups of the the contact
*/
-- (TNStropheGroup)groupsOfContact:(TNStropheContact)aContact
+- (CPArray)groupsOfContact:(TNStropheContact)aContact
{
var tempArray = [CPArray array];
for (var i = 0; i < [_groups count]; i++)
@@ -353,21 +353,32 @@
var contact = [TNStropheContact contactWithConnection:_connection JID:theJID groupName:groupName],
nickname = [aRosterItem valueForAttribute:@"name"] || [theJID node],
- groupName = ([aRosterItem firstChildWithName:@"group"] != null) ? [[aRosterItem firstChildWithName:@"group"] text] : "General", // TODO: Handle multiple groups
- newGroup = [self groupWithName:groupName orCreate:YES],
+ groupNames = [aRosterItem childrenWithName:@"group"] || [CPArray array],
queuedPresence = [self pendingPresenceForJID:theJID];
- [_contacts addObject:newContact];
- [newGroup addContact:newContact];
+ [_contacts addObject:contact];
+
+ [groupNames addObject:[_defaultGroup name]];
+
+ for (var i = 0; i < [groupNames count]; i++)
+ {
+ var groupName = [groupNames objectAtIndex:i],
+ group = [self groupWithName:groupName orCreate:YES];
+
+ // Fix group names on contact
+ [[contact groupNames] addObject:groupName];
+ // Add contact to all new groups
+ [group addContact:contact];
+ }
for (var j = 0; j < [queuedPresence count]; j++)
[newContact _didReceivePresence:[queuedPresence objectAtIndex:j]];
- [newContact setNickname:nickname];
- [newContact getMessages];
- [newContact setSubscription:subscription];
+ [contact setNickname:nickname];
+ [contact getMessages];
+ [contact setSubscription:subscription];
- return newContact;
+ return contact;
}
/*! update a contact from a item XML node from roster iq
@@ -385,9 +396,6 @@
}
var contact = [self contactWithJID:theJID],
- nickname = [aRosterItem valueForAttribute:@"name"] || [theJID node],
- groupName = ([aRosterItem firstChildWithName:@"group"] != null) ? [[aRosterItem firstChildWithName:@"group"] text] : "General", // TODO: Handle multiple groups
- newGroup = [self groupWithName:groupName orCreate:YES],
subscription = [aRosterItem valueForAttribute:@"subscription"];
if (subscription === @"remove")
@@ -408,20 +416,28 @@
}
else
{
+ var nickname = [aRosterItem valueForAttribute:@"name"] || [theJID node],
+ groupNames = [aRosterItem childrenWithName:@"group"] || [CPArray array];
+
+ [groupNames addObject:[_defaultGroup name]];
+
[contact setNickname:nickname];
// Remove contact from all groups
var oldGroups = [self groupsOfContact:contact];
for (var i = 0; i < [oldGroups count]; i++)
[[oldGroup objectAtIndex:i] removeContact:contact];
- // Fix group names on contact
- [[contact groupNames] removeAllObjects];
- [[contact groupNames] addObject:groupName];
+ for (var i = 0; i < [groupNames count]; i++)
+ {
+ var groupName = [groupNames objectAtIndex:i],
+ group = [self groupWithName:groupName orCreate:YES];
- // Add contact to all new groups
- for (var i = 0; i < [[contact groupNames] count]; i++)
- [self groupWithName:[[contact groupNames] objectAtIndex:i] addContact:contact];
+ // Fix group names on contact
+ [[contact groupNames] addObject:groupName];
+ // Add contact to all new groups
+ [group addContact:contact];
+ }
[[CPNotificationCenter defaultCenter] postNotificationName:TNStropheRosterPushUpdatedContactNotification object:self userInfo:contact];
}
View
@@ -83,9 +83,9 @@
#pragma mark -
#pragma mark Contacts
-- (TNStropheGroup)groupOfContact:(TNStropheContact)aContact
+- (CPArray)groupsOfContact:(TNStropheContact)aContact
{
- CPLog.error('TNStropheRosterBase groupOfContact must be implemented in sub-classes.');
+ CPLog.error('TNStropheRosterBase groupsOfContact must be implemented in sub-classes.');
return;
}

0 comments on commit d163176

Please sign in to comment.