From e34961aa9b20a745af6934c161ab956867602de2 Mon Sep 17 00:00:00 2001
From: Kevin Smith <git@kismith.co.uk>
Date: Mon, 12 Apr 2010 15:26:21 +0000
Subject: Allow roster items to be deleted.

Resolves: #296

diff --git a/Swift/Controllers/RosterController.cpp b/Swift/Controllers/RosterController.cpp
index ab1f1fb..c9ba612 100644
--- a/Swift/Controllers/RosterController.cpp
+++ b/Swift/Controllers/RosterController.cpp
@@ -103,7 +103,7 @@ void RosterController::handleChangeStatusRequest(StatusShow::Type show, const St
 
 void RosterController::handleUserAction(boost::shared_ptr<UserRosterAction> action) {
 	boost::shared_ptr<OpenChatRosterAction> chatAction = boost::dynamic_pointer_cast<OpenChatRosterAction>(action);
-	if (chatAction.get() != NULL) {
+	if (chatAction) {
 		ContactRosterItem *contactItem = dynamic_cast<ContactRosterItem*>(chatAction->getRosterItem());
 		assert(contactItem);
 		onStartChatRequest(contactItem->getJID().toBare());
@@ -111,10 +111,17 @@ void RosterController::handleUserAction(boost::shared_ptr<UserRosterAction> acti
 	}
 
 	boost::shared_ptr<RemoveItemRosterAction> removeAction = boost::dynamic_pointer_cast<RemoveItemRosterAction>(action);
-	if (removeAction.get() != NULL) {
-		ContactRosterItem *contactItem = dynamic_cast<ContactRosterItem*>(chatAction->getRosterItem());
+	if (removeAction) {
+		ContactRosterItem *contactItem = dynamic_cast<ContactRosterItem*>(removeAction->getRosterItem());
 		assert(contactItem);
-		//FIXME: remove it
+		
+		RosterItemPayload item(contactItem->getJID(), "", RosterItemPayload::Remove);
+		boost::shared_ptr<RosterPayload> roster(new RosterPayload());
+		roster->addItem(item);
+		boost::shared_ptr<SetRosterRequest> request(new SetRosterRequest(roster, iqRouter_));
+		request->onResponse.connect(boost::bind(&RosterController::handleRosterSetError, this, _1, roster));
+		request->send();
+
 		return;
 	}
 }
@@ -181,6 +188,9 @@ void RosterController::handleUIEvent(boost::shared_ptr<UIEvent> event) {
 }
 
 void RosterController::handleRosterSetError(boost::optional<ErrorPayload> error, boost::shared_ptr<RosterPayload> rosterPayload) {
+	if (!error) {
+		return;
+	}
 	String text = "Server " + myJID_.getDomain() + " rejected roster change to item '" + rosterPayload->getItems()[0].getJID() + "'";
 	if (!error->getText().isEmpty()) {
 		text += ": " + error->getText();
-- 
cgit v0.10.2-6-g49f6