From 8e5d1a11824d7a0900feb44ed5b5464d8d94ab2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Remko=20Tron=C3=A7on?= Date: Wed, 15 Sep 2010 20:45:37 +0200 Subject: Use NickResolver for nicks in notifications. diff --git a/Swift/Controllers/MainController.cpp b/Swift/Controllers/MainController.cpp index 4cd9be4..f7f2155 100644 --- a/Swift/Controllers/MainController.cpp +++ b/Swift/Controllers/MainController.cpp @@ -197,8 +197,6 @@ void MainController::resetClient() { chatsManager_ = NULL; delete rosterController_; rosterController_ = NULL; - delete nickResolver_; - nickResolver_ = NULL; delete presenceNotifier_; presenceNotifier_ = NULL; delete entityCapsManager_; @@ -207,6 +205,8 @@ void MainController::resetClient() { capsManager_ = NULL; delete avatarManager_; avatarManager_ = NULL; + delete nickResolver_; + nickResolver_ = NULL; delete vcardManager_; vcardManager_ = NULL; delete xmppRoster_; @@ -249,8 +249,6 @@ void MainController::handleConnected() { if (freshLogin) { serverDiscoInfo_ = boost::shared_ptr(new DiscoInfo()); - nickResolver_ = new NickResolver(this->jid_.toBare(), xmppRoster_, vcardManager_, mucRegistry_); - rosterController_ = new RosterController(jid_, xmppRoster_, avatarManager_, mainWindowFactory_, nickResolver_, presenceOracle_, presenceSender_, eventController_, uiEventStream_, client_->getIQRouter()); rosterController_->onChangeStatusRequest.connect(boost::bind(&MainController::handleChangeStatusRequest, this, _1, _2)); rosterController_->onSignOutRequest.connect(boost::bind(&MainController::signOut, this)); @@ -390,10 +388,11 @@ void MainController::performLoginFromCachedCredentials() { xmppRoster_ = new XMPPRoster(); vcardManager_ = new VCardManager(jid_, client_->getIQRouter(), getVCardStorageForProfile(jid_)); vcardManager_->onVCardChanged.connect(boost::bind(&MainController::handleVCardReceived, this, _1, _2)); + nickResolver_ = new NickResolver(this->jid_.toBare(), xmppRoster_, vcardManager_, mucRegistry_); avatarManager_ = new AvatarManagerImpl(vcardManager_, client_, avatarStorage_, mucRegistry_); capsManager_ = new CapsManager(capsStorage_, client_, client_->getIQRouter()); entityCapsManager_ = new EntityCapsManager(capsManager_, client_); - presenceNotifier_ = new PresenceNotifier(client_, notifier_, mucRegistry_, avatarManager_, xmppRoster_, presenceOracle_, &timerFactory_); + presenceNotifier_ = new PresenceNotifier(client_, notifier_, mucRegistry_, avatarManager_, nickResolver_, presenceOracle_, &timerFactory_); presenceNotifier_->onNotificationActivated.connect(boost::bind(&MainController::handleNotificationClicked, this, _1)); client_->onDataRead.connect(boost::bind( &XMLConsoleController::handleDataRead, xmlConsoleController_, _1)); diff --git a/Swift/Controllers/NickResolver.cpp b/Swift/Controllers/NickResolver.cpp index 8faada9..5029b7d 100644 --- a/Swift/Controllers/NickResolver.cpp +++ b/Swift/Controllers/NickResolver.cpp @@ -42,8 +42,7 @@ String NickResolver::jidToNick(const JID& jid) { return xmppRoster_->getNameForJID(jid); } - std::map::const_iterator it = map_.find(jid); - return (it == map_.end()) ? jid.toBare() : it->second; + return jid.toBare(); } void NickResolver::handleVCardReceived(const JID& jid, VCard::ref ownVCard) { diff --git a/Swift/Controllers/NickResolver.h b/Swift/Controllers/NickResolver.h index b5ed76f..ac58865 100644 --- a/Swift/Controllers/NickResolver.h +++ b/Swift/Controllers/NickResolver.h @@ -4,9 +4,6 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#ifndef SWIFTEN_NickResolver_H -#define SWIFTEN_NickResolver_H - #include #include #include @@ -29,15 +26,13 @@ namespace Swift { boost::signal onOwnNickChanged; private: void handleVCardReceived(const JID& jid, VCard::ref vCard); + + private: JID ownJID_; String ownNick_; - std::map map_; - XMPPRoster* xmppRoster_; MUCRegistry* mucRegistry_; VCardManager* vcardManager_; }; } -#endif - diff --git a/Swift/Controllers/PresenceNotifier.cpp b/Swift/Controllers/PresenceNotifier.cpp index 0c46f9b..74cb4b0 100644 --- a/Swift/Controllers/PresenceNotifier.cpp +++ b/Swift/Controllers/PresenceNotifier.cpp @@ -14,10 +14,11 @@ #include "Swiften/Roster/XMPPRoster.h" #include "Swiften/Presence/PresenceOracle.h" #include "Swiften/Network/TimerFactory.h" +#include "Swift/Controllers/NickResolver.h" namespace Swift { -PresenceNotifier::PresenceNotifier(StanzaChannel* stanzaChannel, Notifier* notifier, const MUCRegistry* mucRegistry, AvatarManager* avatarManager, const XMPPRoster* roster, const PresenceOracle* presenceOracle, TimerFactory* timerFactory) : stanzaChannel(stanzaChannel), notifier(notifier), mucRegistry(mucRegistry), avatarManager(avatarManager), roster(roster), presenceOracle(presenceOracle), timerFactory(timerFactory) { +PresenceNotifier::PresenceNotifier(StanzaChannel* stanzaChannel, Notifier* notifier, const MUCRegistry* mucRegistry, AvatarManager* avatarManager, NickResolver* nickResolver, const PresenceOracle* presenceOracle, TimerFactory* timerFactory) : stanzaChannel(stanzaChannel), notifier(notifier), mucRegistry(mucRegistry), avatarManager(avatarManager), nickResolver(nickResolver), presenceOracle(presenceOracle), timerFactory(timerFactory) { justInitialized = true; inQuietPeriod = false; stanzaChannel->onPresenceReceived.connect(boost::bind(&PresenceNotifier::handlePresenceReceived, this, _1)); @@ -84,7 +85,7 @@ void PresenceNotifier::handleStanzaChannelAvailableChanged(bool available) { } void PresenceNotifier::showNotification(const JID& jid, Notifier::Type type) { - String name = roster->getNameForJID(jid); + String name = nickResolver->jidToNick(jid); if (name.isEmpty()) { name = jid.toBare().toString(); } diff --git a/Swift/Controllers/PresenceNotifier.h b/Swift/Controllers/PresenceNotifier.h index f5bf3d4..9b2d9de 100644 --- a/Swift/Controllers/PresenceNotifier.h +++ b/Swift/Controllers/PresenceNotifier.h @@ -20,12 +20,12 @@ namespace Swift { class TimerFactory; class StanzaChannel; class MUCRegistry; - class XMPPRoster; + class NickResolver; class PresenceOracle; class PresenceNotifier { public: - PresenceNotifier(StanzaChannel* stanzaChannel, Notifier* notifier, const MUCRegistry* mucRegistry, AvatarManager* avatarManager, const XMPPRoster* roster, const PresenceOracle* presenceOracle, TimerFactory* timerFactory); + PresenceNotifier(StanzaChannel* stanzaChannel, Notifier* notifier, const MUCRegistry* mucRegistry, AvatarManager* avatarManager, NickResolver* nickResolver, const PresenceOracle* presenceOracle, TimerFactory* timerFactory); ~PresenceNotifier(); void setInitialQuietPeriodMS(int ms); @@ -48,7 +48,7 @@ namespace Swift { Notifier* notifier; const MUCRegistry* mucRegistry; AvatarManager* avatarManager; - const XMPPRoster* roster; + NickResolver* nickResolver; const PresenceOracle* presenceOracle; TimerFactory* timerFactory; boost::shared_ptr timer; diff --git a/Swift/Controllers/UnitTest/PresenceNotifierTest.cpp b/Swift/Controllers/UnitTest/PresenceNotifierTest.cpp index a410665..9addab2 100644 --- a/Swift/Controllers/UnitTest/PresenceNotifierTest.cpp +++ b/Swift/Controllers/UnitTest/PresenceNotifierTest.cpp @@ -10,6 +10,7 @@ #include #include "Swift/Controllers/PresenceNotifier.h" +#include "Swift/Controllers/NickResolver.h" #include "SwifTools/Notifier/LoggingNotifier.h" #include "Swiften/Client/DummyStanzaChannel.h" #include "Swiften/MUC/MUCRegistry.h" @@ -52,12 +53,15 @@ class PresenceNotifierTest : public CppUnit::TestFixture { user2 = JID("user2@foo.com/baz"); avatarManager = new DummyAvatarManager(); roster = new XMPPRoster(); + nickResolver = new NickResolver(JID("foo@bar.com"), roster, NULL, mucRegistry); presenceOracle = new PresenceOracle(stanzaChannel); timerFactory = new DummyTimerFactory(); } void tearDown() { + delete timerFactory; delete presenceOracle; + delete nickResolver; delete roster; delete avatarManager; delete mucRegistry; @@ -269,7 +273,7 @@ class PresenceNotifierTest : public CppUnit::TestFixture { private: std::auto_ptr createNotifier() { - std::auto_ptr result(new PresenceNotifier(stanzaChannel, notifier, mucRegistry, avatarManager, roster, presenceOracle, timerFactory)); + std::auto_ptr result(new PresenceNotifier(stanzaChannel, notifier, mucRegistry, avatarManager, nickResolver, presenceOracle, timerFactory)); result->onNotificationActivated.connect(boost::bind(&PresenceNotifierTest::handleNotificationActivated, this, _1)); result->setInitialQuietPeriodMS(0); return result; @@ -300,6 +304,7 @@ class PresenceNotifierTest : public CppUnit::TestFixture { MUCRegistry* mucRegistry; DummyAvatarManager* avatarManager; XMPPRoster* roster; + NickResolver* nickResolver; PresenceOracle* presenceOracle; DummyTimerFactory* timerFactory; JID user1; -- cgit v0.10.2-6-g49f6