From 103e5d04240fa6c9decf54802bca083c2cd65744 Mon Sep 17 00:00:00 2001 From: Kevin Smith Date: Wed, 26 May 2010 19:30:52 +0100 Subject: Do JID Map lookups for MUC rosters. In the same way as was already done for user rosters. Resolves: #395 diff --git a/Swift/Controllers/Chat/MUCController.cpp b/Swift/Controllers/Chat/MUCController.cpp index dbf03c9..e582f1b 100644 --- a/Swift/Controllers/Chat/MUCController.cpp +++ b/Swift/Controllers/Chat/MUCController.cpp @@ -48,7 +48,7 @@ MUCController::MUCController ( parting_ = false; events_ = uiEventStream; - roster_ = new Roster(); + roster_ = new Roster(true); chatWindow_->setRosterModel(roster_); chatWindow_->onClosed.connect(boost::bind(&MUCController::handleWindowClosed, this)); muc_->onJoinComplete.connect(boost::bind(&MUCController::handleJoinComplete, this, _1)); @@ -125,7 +125,7 @@ void MUCController::handleJoinComplete(const String& nick) { } void MUCController::handleAvatarChanged(const JID& jid, const String&) { - if (parting_) { + if (parting_ || !jid.equals(toJID_, JID::WithoutResource)) { return; } String path = avatarManager_->getAvatarPath(jid).string(); diff --git a/Swiften/Roster/Roster.cpp b/Swiften/Roster/Roster.cpp index a83ea89..9291421 100644 --- a/Swiften/Roster/Roster.cpp +++ b/Swiften/Roster/Roster.cpp @@ -21,7 +21,8 @@ namespace Swift { -Roster::Roster() { +Roster::Roster(bool fullJIDMapping) { + fullJIDMapping_ = fullJIDMapping; root_ = new GroupRosterItem("Dummy-Root", NULL); root_->onChildrenChanged.connect(boost::bind(&Roster::handleChildrenChanged, this, root_)); } @@ -70,7 +71,7 @@ void Roster::addContact(const JID& jid, const String& name, const String& groupN GroupRosterItem* group(getGroup(groupName)); ContactRosterItem *item = new ContactRosterItem(jid, name, group); group->addChild(item); - itemMap_[jid.toBare()].push_back(item); + itemMap_[fullJIDMapping_ ? jid : jid.toBare()].push_back(item); item->onDataChanged.connect(boost::bind(&Roster::handleDataChanged, this, item)); filterContact(item, group); } @@ -82,10 +83,10 @@ struct JIDEqualsTo { }; void Roster::removeContact(const JID& jid) { - std::vector* items = &itemMap_[jid.toBare()]; + std::vector* items = &itemMap_[fullJIDMapping_ ? jid : jid.toBare()]; items->erase(std::remove_if(items->begin(), items->end(), JIDEqualsTo(jid)), items->end()); if (items->size() == 0) { - itemMap_.erase(jid.toBare()); + itemMap_.erase(fullJIDMapping_ ? jid : jid.toBare()); } //Causes the delete root_->removeChild(jid); @@ -98,7 +99,7 @@ void Roster::removeContactFromGroup(const JID& jid, const String& groupName) { GroupRosterItem* group = dynamic_cast(*it); if (group && group->getDisplayName() == groupName) { ContactRosterItem* deleted = group->removeChild(jid); - std::vector* items = &itemMap_[jid.toBare()]; + std::vector* items = &itemMap_[fullJIDMapping_ ? jid : jid.toBare()]; items->erase(std::remove(items->begin(), items->end(), deleted), items->end()); } it++; @@ -115,8 +116,8 @@ void Roster::applyOnItems(const RosterItemOperation& operation) { } void Roster::applyOnItem(const RosterItemOperation& operation, const JID& jid) { - foreach (ContactRosterItem* item, itemMap_[jid.toBare()]) { - //std::cout << "Applying on item " << item << " : " << item->getDisplayName() << std::endl; + + foreach (ContactRosterItem* item, itemMap_[fullJIDMapping_ ? jid : jid.toBare()]) { operation(item); filterContact(item, item->getParent()); } diff --git a/Swiften/Roster/Roster.h b/Swiften/Roster/Roster.h index 3af89d7..fcc075a 100644 --- a/Swiften/Roster/Roster.h +++ b/Swiften/Roster/Roster.h @@ -25,7 +25,7 @@ class ContactRosterItem; class Roster { public: - Roster(); + Roster(bool fullJIDMapping = false); ~Roster(); void addContact(const JID& jid, const String& name, const String& group); @@ -51,6 +51,7 @@ class Roster { GroupRosterItem* root_; std::vector filters_; std::map > itemMap_; + bool fullJIDMapping_; }; } diff --git a/Swiften/Roster/SetPresence.h b/Swiften/Roster/SetPresence.h index 134a63d..9bbf326 100644 --- a/Swiften/Roster/SetPresence.h +++ b/Swiften/Roster/SetPresence.h @@ -17,7 +17,7 @@ class RosterItem; class SetPresence : public RosterItemOperation { public: - SetPresence(boost::shared_ptr presence, JID::CompareType compareType = JID::WithoutResource) : RosterItemOperation(true, presence->getFrom().toBare()), presence_(presence), compareType_(compareType) { + SetPresence(boost::shared_ptr presence, JID::CompareType compareType = JID::WithoutResource) : RosterItemOperation(true, compareType == JID::WithoutResource ? presence->getFrom().toBare() : presence->getFrom()), presence_(presence), compareType_(compareType) { } virtual void operator() (RosterItem* item) const { -- cgit v0.10.2-6-g49f6