diff options
Diffstat (limited to 'Swift/Controllers')
-rw-r--r-- | Swift/Controllers/RosterController.cpp | 30 | ||||
-rw-r--r-- | Swift/Controllers/RosterController.h | 2 | ||||
-rw-r--r-- | Swift/Controllers/XMPPRosterController.cpp | 1 |
3 files changed, 33 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)); } diff --git a/Swift/Controllers/RosterController.h b/Swift/Controllers/RosterController.h index 0da00ac..f3d96e1 100644 --- a/Swift/Controllers/RosterController.h +++ b/Swift/Controllers/RosterController.h @@ -37,6 +37,8 @@ namespace Swift { void setEnabled(bool enabled); private: void handleOnJIDAdded(const JID &jid); + void handleOnJIDRemoved(const JID &jid); + void handleOnJIDUpdated(const JID &jid, const String& oldName, const std::vector<String> oldGroups); void handleStartChatRequest(const JID& contact); void handleJoinMUCRequest(const JID &muc, const String &nick); void handleUserAction(boost::shared_ptr<UserRosterAction> action); diff --git a/Swift/Controllers/XMPPRosterController.cpp b/Swift/Controllers/XMPPRosterController.cpp index e1716e6..d089cff 100644 --- a/Swift/Controllers/XMPPRosterController.cpp +++ b/Swift/Controllers/XMPPRosterController.cpp @@ -33,6 +33,7 @@ void XMPPRosterController::requestRoster() { void XMPPRosterController::handleRosterReceived(boost::shared_ptr<RosterPayload> rosterPayload) { foreach(const RosterItemPayload& item, rosterPayload->getItems()) { + //Don't worry about the updated case, the XMPPRoster sorts that out. if (item.getSubscription() == RosterItemPayload::Remove) { xmppRoster_->removeContact(item.getJID()); } else { |