summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Smith <git@kismith.co.uk>2010-09-24 15:38:29 (GMT)
committerKevin Smith <git@kismith.co.uk>2010-09-24 15:38:29 (GMT)
commitecc4dc5633b6d3b46ff2ef24d7d976172b9c01ae (patch)
tree74c9d7701b3d2e7ef1ead5892b1ec35d13dd59c0 /Swift/Controllers/RosterController.cpp
parent3a57283476de7d29d6652145336dc03964d5659c (diff)
downloadswift-ecc4dc5633b6d3b46ff2ef24d7d976172b9c01ae.zip
swift-ecc4dc5633b6d3b46ff2ef24d7d976172b9c01ae.tar.bz2
Add logic and tests for modifying roster items. No UI Yet.
(Partially) Resolves: #575 (Partially) Resolves: #272
Diffstat (limited to 'Swift/Controllers/RosterController.cpp')
-rw-r--r--Swift/Controllers/RosterController.cpp40
1 files changed, 38 insertions, 2 deletions
diff --git a/Swift/Controllers/RosterController.cpp b/Swift/Controllers/RosterController.cpp
index c8f94f1..79cf3b8 100644
--- a/Swift/Controllers/RosterController.cpp
+++ b/Swift/Controllers/RosterController.cpp
@@ -29,7 +29,8 @@
#include "Swiften/Roster/XMPPRoster.h"
#include "Swift/Controllers/UIEvents/AddContactUIEvent.h"
#include "Swift/Controllers/UIEvents/RemoveRosterItemUIEvent.h"
-
+#include "Swift/Controllers/UIEvents/RenameRosterItemUIEvent.h"
+#include "Swift/Controllers/UIEvents/RegroupRosterItemUIEvent.h"
namespace Swift {
@@ -172,7 +173,42 @@ void RosterController::handleUIEvent(boost::shared_ptr<UIEvent> event) {
return;
}
-
+ boost::shared_ptr<RenameRosterItemUIEvent> renameEvent = boost::dynamic_pointer_cast<RenameRosterItemUIEvent>(event);
+ if (renameEvent) {
+ JID contact(renameEvent->getJID());
+ RosterItemPayload item(contact, renameEvent->getNewName(), xmppRoster_->getSubscriptionStateForJID(contact));
+ item.setGroups(xmppRoster_->getGroupsForJID(contact));
+ 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;
+ }
+ boost::shared_ptr<RegroupRosterItemUIEvent> regroupEvent = boost::dynamic_pointer_cast<RegroupRosterItemUIEvent>(event);
+ if (regroupEvent) {
+ JID contact(regroupEvent->getJID());
+ RosterItemPayload item(contact, xmppRoster_->getNameForJID(contact), xmppRoster_->getSubscriptionStateForJID(contact));
+ std::vector<String> newGroups;
+ const std::vector<String> addedGroups = regroupEvent->getAddedGroups();
+ const std::vector<String> removedGroups = regroupEvent->getRemovedGroups();
+ foreach (const String& oldGroup, xmppRoster_->getGroupsForJID(contact)) {
+ if (std::find(removedGroups.begin(), removedGroups.end(), oldGroup) == removedGroups.end()
+ && std::find(addedGroups.begin(), addedGroups.end(), oldGroup) == addedGroups.end()) {
+ newGroups.push_back(oldGroup);
+ }
+ }
+ foreach (const String& newGroup, regroupEvent->getAddedGroups()) {
+ newGroups.push_back(newGroup);
+ }
+ item.setGroups(newGroups);
+ 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;
+ }
}
void RosterController::handleRosterSetError(boost::optional<ErrorPayload> error, boost::shared_ptr<RosterPayload> rosterPayload) {