From 77d4eb7588e113beaa03f3347523b26adefdeb06 Mon Sep 17 00:00:00 2001
From: Kevin Smith <git@kismith.co.uk>
Date: Sun, 11 Apr 2010 19:17:06 +0100
Subject: Don't duplicate roster items for roster pushes.

Resolves: #218

diff --git a/Swift/Controllers/RosterController.cpp b/Swift/Controllers/RosterController.cpp
index ea7c7bb..9364e93 100644
--- a/Swift/Controllers/RosterController.cpp
+++ b/Swift/Controllers/RosterController.cpp
@@ -131,19 +131,25 @@ void RosterController::handleOnJIDRemoved(const JID& jid) {
 	roster_->removeContact(jid);
 }
 
-void RosterController::handleOnJIDUpdated(const JID& jid, const String& oldName, const std::vector<String> oldGroups) {
+void RosterController::handleOnJIDUpdated(const JID& jid, const String& oldName, const std::vector<String> passedOldGroups) {
 	if (oldName != xmppRoster_->getNameForJID(jid)) {
+		handleOnJIDRemoved(jid);
 		handleOnJIDAdded(jid);
+		//FIXME: use a roster visitor to avoid losing presence.
 		return;
 	}
 	std::vector<String> groups = xmppRoster_->getGroupsForJID(jid);
+	std::vector<String> oldGroups = passedOldGroups;
 	String name = xmppRoster_->getNameForJID(jid);
 	String contactsGroup = "Contacts";
+	if (oldGroups.empty()) {
+		oldGroups.push_back(contactsGroup);
+	}
 	if (groups.empty()) {
 		groups.push_back(contactsGroup);
 	}
 	foreach(const String& group, groups) {
-		if (std::find(oldGroups.begin(), oldGroups.end(), jid) == oldGroups.end()) {
+		if (std::find(oldGroups.begin(), oldGroups.end(), group) == oldGroups.end()) {
 			roster_->addContact(jid, xmppRoster_->getNameForJID(jid), group);
 		}
 	} 
-- 
cgit v0.10.2-6-g49f6