summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Smith <git@kismith.co.uk>2009-11-05 22:05:15 (GMT)
committerKevin Smith <git@kismith.co.uk>2009-11-05 22:06:16 (GMT)
commit3fbab3b40dfc31da46924f13984415b18087a8d4 (patch)
tree161e6a8f4479153120fc61548bd6407f260f347f /Swift/Controllers/RosterController.cpp
parentff9b04252cbdd3bda5f1d01e1bad4a077f99791b (diff)
downloadswift-contrib-3fbab3b40dfc31da46924f13984415b18087a8d4.zip
swift-contrib-3fbab3b40dfc31da46924f13984415b18087a8d4.tar.bz2
A block of the work for roster pushes.
Still needs unit testing
Diffstat (limited to 'Swift/Controllers/RosterController.cpp')
-rw-r--r--Swift/Controllers/RosterController.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/Swift/Controllers/RosterController.cpp b/Swift/Controllers/RosterController.cpp
index 07edcf3..063d2a7 100644
--- a/Swift/Controllers/RosterController.cpp
+++ b/Swift/Controllers/RosterController.cpp
@@ -35,6 +35,8 @@ RosterController::RosterController(const JID& jid, boost::shared_ptr<XMPPRoster>
mainWindow_->onSignOutRequest.connect(boost::bind(boost::ref(onSignOutRequest)));
roster_->onUserAction.connect(boost::bind(&RosterController::handleUserAction, this, _1));
xmppRoster_->onJIDAdded.connect(boost::bind(&RosterController::handleOnJIDAdded, this, _1));
+ xmppRoster_->onJIDUpdated.connect(boost::bind(&RosterController::handleOnJIDUpdated, this, _1, _2, _3));
+ xmppRoster_->onJIDRemoved.connect(boost::bind(&RosterController::handleOnJIDRemoved, this, _1));
avatarManager_ = NULL;
setAvatarManager(avatarManager);
setNickResolver(nickResolver);
@@ -103,6 +105,34 @@ void RosterController::handleOnJIDAdded(const JID& jid) {
}
}
+void RosterController::handleOnJIDRemoved(const JID& jid) {
+ roster_->removeContact(jid);
+}
+
+void RosterController::handleOnJIDUpdated(const JID& jid, const String& oldName, const std::vector<String> oldGroups) {
+ if (oldName != xmppRoster_->getNameForJID(jid)) {
+ handleOnJIDAdded(jid);
+ return;
+ }
+ std::vector<String> groups = xmppRoster_->getGroupsForJID(jid);
+ String name = xmppRoster_->getNameForJID(jid);
+ String contactsGroup = "Contacts";
+ if (groups.empty()) {
+ groups.push_back(contactsGroup);
+ }
+ foreach(const String& group, groups) {
+ if (std::find(oldGroups.begin(), oldGroups.end(), jid) == oldGroups.end()) {
+ roster_->addContact(jid, xmppRoster_->getNameForJID(jid), group);
+ }
+ }
+ foreach(const String& group, oldGroups) {
+ if (std::find(groups.begin(), groups.end(), group) == groups.end()) {
+ roster_->removeContactFromGroup(jid, group);
+ }
+ }
+
+}
+
void RosterController::handleIncomingPresence(boost::shared_ptr<Presence> presence) {
roster_->applyOnItems(SetPresence(presence));
}