diff options
Diffstat (limited to 'Swift/Controllers/HistoryViewController.cpp')
-rw-r--r-- | Swift/Controllers/HistoryViewController.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
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 <Swiften/Base/foreach.h> #include <Swiften/Client/NickResolver.h> #include <Swiften/Avatars/AvatarManager.h> +#include <Swift/Controllers/Roster/SetPresence.h> +#include <Swift/Controllers/Roster/SetAvatar.h> 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<UIEvent> 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)); +} + } |