Permalink
Browse files

Tidy up roster sets for contact group/nickname and don't keep changes…

… until confirmed by a roster push

* Also use roster set method when adding a contact
  • Loading branch information...
1 parent 3c3cd44 commit 329b4ebb468280aa2b7f506b5b84f2653d9936ae @benlangfeld committed Jan 15, 2011
Showing with 17 additions and 36 deletions.
  1. +14 −26 TNStropheContact.j
  2. +3 −7 TNStropheRoster.j
  3. +0 −3 TNStropheRosterBase.j
View
@@ -353,50 +353,38 @@
*/
- (void)changeNickname:(CPString)newNickname
{
+ var oldNickname = _nickname;
_nickname = newNickname;
-
- var stanza = [TNStropheStanza iqWithAttributes:{"type": "set"}];
- [stanza addChildWithName:@"query" andAttributes: {'xmlns':Strophe.NS.ROSTER}];
- [stanza addChildWithName:@"item" andAttributes:{"JID": [_JID bare], "name": _nickname}];
- [stanza addChildWithName:@"group" andAttributes:nil];
- [stanza addTextNode:_groupName];
-
- [_connection send:stanza];
-
+ [self sendRosterSet];
[[CPNotificationCenter defaultCenter] postNotificationName:TNStropheContactNicknameUpdatedNotification object:self];
+ _nickname = oldNickname;
}
/*! this allows to change the group of the contact. Will post TNStropheContactGroupUpdatedNotification
*/
- (void)changeGroup:(TNStropheGroup)newGroup
{
- var stanza = [TNStropheStanza iqWithAttributes:{"type": "set"}];
- [stanza addChildWithName:@"query" andAttributes: {'xmlns':Strophe.NS.ROSTER}];
- [stanza addChildWithName:@"item" andAttributes:{"JID": [_JID bare], "name": _nickname}];
- [stanza addChildWithName:@"group" andAttributes:nil];
- [stanza addTextNode:[newGroup name]];
-
- [_connection send:stanza];
-
- _groupName = [newGroup name];
+ [self changeGroupName:[newGroup name]];
+}
+- (void)changeGroupName:(CPString)aNewName
+{
+ var oldGroupName = _groupName;
+ _groupName = aNewName;
+ [self sendRosterSet];
[[CPNotificationCenter defaultCenter] postNotificationName:TNStropheContactGroupUpdatedNotification object:self];
+ _groupName = oldGroupName;
}
-- (void)changeGroupName:(CPString)aNewName
+- (void)sendRosterSet
{
var stanza = [TNStropheStanza iqWithAttributes:{"type": "set"}];
-
- [stanza addChildWithName:@"query" andAttributes: {'xmlns':Strophe.NS.ROSTER}];
+ [stanza addChildWithName:@"query" andAttributes:{'xmlns':Strophe.NS.ROSTER}];
[stanza addChildWithName:@"item" andAttributes:{"JID": [_JID bare], "name": _nickname}];
- [stanza addChildWithName:@"group" andAttributes:nil];
+ [stanza addChildWithName:@"group"];
[stanza addTextNode:aNewName];
[_connection send:stanza];
-
- _groupName = aNewName;
-
- [[CPNotificationCenter defaultCenter] postNotificationName:TNStropheContactGroupUpdatedNotification object:self];
}
View
@@ -313,16 +313,12 @@
var uid = [_connection getUniqueId],
addReq = [TNStropheStanza iqWithAttributes:{"type": "set", "id": uid}],
- params = [CPDictionary dictionaryWithObjectsAndKeys:uid, @"id"];
-
- [addReq addChildWithName:@"query" andAttributes: {'xmlns':Strophe.NS.ROSTER}];
- [addReq addChildWithName:@"item" andAttributes:{"JID": [aJID full], "name": aName}];
- [addReq addChildWithName:@"group" andAttributes:nil];
- [addReq addTextNode:aGroupName];
+ params = [CPDictionary dictionaryWithObjectsAndKeys:uid, @"id"],
+ contact = [TNStropheContact contactWithConnection:_connection JID:aJID groupName:aGroupName];
[_connection registerSelector:@selector(_didAddContact:userInfo:) ofObject:self withDict:params userInfo:aJID];
- [_connection send:addReq];
+ [contact sendRosterSet];
}
- (BOOL)_didAddContact:(TNStropheStanza)aStanza userInfo:(TNStropheJID)theJID
View
@@ -226,9 +226,6 @@
*/
- (void)changeGroup:(TNStropheGroup)newGroup ofContact:(TNStropheContact)aContact
{
- [[self groupOfContact:aContact] removeContact:aContact];
-
- [newGroup addContact:aContact];
[aContact changeGroup:newGroup];
}

0 comments on commit 329b4eb

Please sign in to comment.