From 2b8f9e07d0aa0c119c6c2abf97c703008b213830 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C4=83t=C4=83lin=20Badea?= Date: Fri, 10 Aug 2012 14:06:06 +0300 Subject: Handle presence and avatar changes. diff --git a/Swift/Controllers/HistoryViewController.cpp b/Swift/Controllers/HistoryViewController.cpp index 43575d5..de63e74 100644 --- a/Swift/Controllers/HistoryViewController.cpp +++ b/Swift/Controllers/HistoryViewController.cpp @@ -13,6 +13,8 @@ #include #include #include +#include +#include namespace Swift { static const std::string category[] = { "Contacts", "MUC", "Contacts" }; @@ -23,12 +25,14 @@ HistoryViewController::HistoryViewController( HistoryController* historyController, NickResolver* nickResolver, AvatarManager* avatarManager, + PresenceOracle* presenceOracle, HistoryWindowFactory* historyWindowFactory) : selfJID_(selfJID), uiEventStream_(uiEventStream), historyController_(historyController), nickResolver_(nickResolver), avatarManager_(avatarManager), + presenceOracle_(presenceOracle), historyWindowFactory_(historyWindowFactory), historyWindow_(NULL), selectedItem_(NULL), @@ -49,6 +53,10 @@ HistoryViewController::~HistoryViewController() { historyWindow_->onNextButtonClicked.disconnect(boost::bind(&HistoryViewController::handleNextButtonClicked, this)); historyWindow_->onCalendarClicked.disconnect(boost::bind(&HistoryViewController::handleCalendarClicked, this, _1)); historyController_->onNewMessage.disconnect(boost::bind(&HistoryViewController::handleNewMessage, this, _1)); + + presenceOracle_->onPresenceChange.disconnect(boost::bind(&HistoryViewController::handlePresenceChanged, this, _1)); + avatarManager_->onAvatarChanged.disconnect(boost::bind(&HistoryViewController::handleAvatarChanged, this, _1)); + delete historyWindow_; } delete roster_; @@ -68,6 +76,9 @@ void HistoryViewController::handleUIEvent(boost::shared_ptr rawEvent) { historyWindow_->onCalendarClicked.connect(boost::bind(&HistoryViewController::handleCalendarClicked, this, _1)); historyController_->onNewMessage.connect(boost::bind(&HistoryViewController::handleNewMessage, this, _1)); + presenceOracle_->onPresenceChange.connect(boost::bind(&HistoryViewController::handlePresenceChanged, this, _1)); + avatarManager_->onAvatarChanged.connect(boost::bind(&HistoryViewController::handleAvatarChanged, this, _1)); + historyWindow_->setRosterModel(roster_); } @@ -160,6 +171,12 @@ void HistoryViewController::handleReturnPressed(const std::string& keyword) { for (ContactsMap::const_iterator contact = contacts_[type].begin(); contact != contacts_[type].end(); contact++) { const JID& jid = contact->first; roster_->addContact(jid, jid, nickResolver_->jidToNick(jid), category[type], avatarManager_->getAvatarPath(jid).string()); + + Presence::ref presence = presenceOracle_->getHighestPriorityPresence(jid); + + if (presence.get()) { + roster_->applyOnItem(SetPresence(presence, JID::WithoutResource), jid); + } } } } @@ -279,4 +296,21 @@ void HistoryViewController::handleCalendarClicked(const boost::gregorian::date& } } +void HistoryViewController::handlePresenceChanged(Presence::ref presence) { + JID jid = presence->getFrom(); + + if (contacts_[HistoryMessage::Chat].count(jid)) { + roster_->applyOnItems(SetPresence(presence, JID::WithoutResource)); + } + + if (contacts_[HistoryMessage::PrivateMessage].count(jid)) { + roster_->applyOnItems(SetPresence(presence, JID::WithResource)); + } +} + +void HistoryViewController::handleAvatarChanged(const JID& jid) { + std::string path = avatarManager_->getAvatarPath(jid).string(); + roster_->applyOnItems(SetAvatar(jid, path)); +} + } diff --git a/Swift/Controllers/HistoryViewController.h b/Swift/Controllers/HistoryViewController.h index 2302355..6ee94d9 100644 --- a/Swift/Controllers/HistoryViewController.h +++ b/Swift/Controllers/HistoryViewController.h @@ -13,6 +13,7 @@ #include #include #include +#include #include namespace Swift { @@ -28,7 +29,7 @@ namespace Swift { class HistoryViewController { public: - HistoryViewController(const JID& selfJID, UIEventStream* uiEventStream, HistoryController* historyController, NickResolver* nickResolver, AvatarManager* avatarManager, HistoryWindowFactory* historyWindowFactory); + HistoryViewController(const JID& selfJID, UIEventStream* uiEventStream, HistoryController* historyController, NickResolver* nickResolver, AvatarManager* avatarManager, PresenceOracle* presenceOracle, HistoryWindowFactory* historyWindowFactory); ~HistoryViewController(); private: @@ -41,6 +42,8 @@ namespace Swift { void handlePreviousButtonClicked(); void handleNextButtonClicked(); void handleCalendarClicked(const boost::gregorian::date& date); + void handlePresenceChanged(Presence::ref presence); + void handleAvatarChanged(const JID& jid); void addNewMessage(const HistoryMessage& message, bool addAtTheTop); void reset(); @@ -51,6 +54,7 @@ namespace Swift { HistoryController* historyController_; NickResolver* nickResolver_; AvatarManager* avatarManager_; + PresenceOracle* presenceOracle_; HistoryWindowFactory* historyWindowFactory_; HistoryWindow* historyWindow_; Roster* roster_; diff --git a/Swift/Controllers/MainController.cpp b/Swift/Controllers/MainController.cpp index 1fe1917..9ac97f4 100644 --- a/Swift/Controllers/MainController.cpp +++ b/Swift/Controllers/MainController.cpp @@ -304,7 +304,7 @@ void MainController::handleConnected() { chatsManager_ = new ChatsManager(jid_, client_->getStanzaChannel(), client_->getIQRouter(), eventController_, uiFactory_, uiFactory_, client_->getNickResolver(), client_->getPresenceOracle(), client_->getPresenceSender(), uiEventStream_, uiFactory_, useDelayForLatency_, networkFactories_->getTimerFactory(), client_->getMUCRegistry(), client_->getEntityCapsProvider(), client_->getMUCManager(), uiFactory_, profileSettings_, ftOverview_, client_->getRoster(), !settings_->getSetting(SettingConstants::REMEMBER_RECENT_CHATS), settings_, historyController_); - historyViewController_ = new HistoryViewController(jid_, uiEventStream_, historyController_, client_->getNickResolver(), client_->getAvatarManager(), uiFactory_); + historyViewController_ = new HistoryViewController(jid_, uiEventStream_, historyController_, client_->getNickResolver(), client_->getAvatarManager(), client_->getPresenceOracle(), uiFactory_); client_->onMessageReceived.connect(boost::bind(&ChatsManager::handleIncomingMessage, chatsManager_, _1)); chatsManager_->setAvatarManager(client_->getAvatarManager()); -- cgit v0.10.2-6-g49f6