summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Swift/Controllers/HistoryViewController.cpp34
-rw-r--r--Swift/Controllers/HistoryViewController.h6
-rw-r--r--Swift/Controllers/MainController.cpp2
3 files changed, 40 insertions, 2 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));
+}
+
}
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 <Swift/Controllers/UIEvents/UIEventStream.h>
#include <Swiften/History/HistoryManager.h>
#include <Swiften/JID/JID.h>
+#include <Swiften/Presence/PresenceOracle.h>
#include <set>
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 8b1c489..d132ac0 100644
--- a/Swift/Controllers/MainController.cpp
+++ b/Swift/Controllers/MainController.cpp
@@ -299,7 +299,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());