diff options
author | Catalin Badea <catalin.badea392@gmail.com> | 2012-07-01 21:47:54 (GMT) |
---|---|---|
committer | Catalin Badea <catalin.badea392@gmail.com> | 2012-07-01 21:47:54 (GMT) |
commit | fbeef036efeabe1218490f5a7659d8779350af7c (patch) | |
tree | 7146244351d6375b40640f81cbc3580ade0808e6 /Swift | |
parent | 831075a8aeb15dc79c84d28d284b5cdbae2f60ea (diff) | |
download | swift-contrib-fbeef036efeabe1218490f5a7659d8779350af7c.zip swift-contrib-fbeef036efeabe1218490f5a7659d8779350af7c.tar.bz2 |
update history window on new message
Diffstat (limited to 'Swift')
-rw-r--r-- | Swift/Controllers/HistoryController.cpp | 1 | ||||
-rw-r--r-- | Swift/Controllers/HistoryController.h | 3 | ||||
-rw-r--r-- | Swift/Controllers/HistoryViewController.cpp | 28 | ||||
-rw-r--r-- | Swift/Controllers/HistoryViewController.h | 4 |
4 files changed, 33 insertions, 3 deletions
diff --git a/Swift/Controllers/HistoryController.cpp b/Swift/Controllers/HistoryController.cpp index a25c40f..5bd4ffa 100644 --- a/Swift/Controllers/HistoryController.cpp +++ b/Swift/Controllers/HistoryController.cpp @@ -22,6 +22,7 @@ HistoryController::~HistoryController() { void HistoryController::addMessage(const std::string& message, const JID& fromJID, const JID& toJID, bool isGroupChat, const boost::posix_time::ptime& timeStamp) { HistoryMessage historyMessage(message, fromJID, toJID, isGroupChat, timeStamp); localHistory_->addMessage(historyMessage); + onNewMessage(historyMessage); } std::vector<HistoryMessage> HistoryController::getMessages(const JID& selfJID, const JID& contactJID, bool isGroupChat) const { diff --git a/Swift/Controllers/HistoryController.h b/Swift/Controllers/HistoryController.h index 5c0378a..babda8a 100644 --- a/Swift/Controllers/HistoryController.h +++ b/Swift/Controllers/HistoryController.h @@ -10,6 +10,7 @@ #include <boost/date_time/posix_time/posix_time.hpp> #include <vector> #include <set> +#include <Swiften/Base/boost_bsignals.h> namespace Swift { class HistoryManager; @@ -25,6 +26,8 @@ namespace Swift { std::vector<HistoryMessage> getMessages(const JID& selfJID, const JID& contactJID, bool isGroupChat) const; void getAllContacts(const JID& selfJID, std::set<JID>& mucs, std::set<JID>& contacts) const; + boost::signal<void (const HistoryMessage&)> onNewMessage; + private: HistoryManager* localHistory_; bool remoteArchiveSupported_; diff --git a/Swift/Controllers/HistoryViewController.cpp b/Swift/Controllers/HistoryViewController.cpp index 9c10874..a67f6cd 100644 --- a/Swift/Controllers/HistoryViewController.cpp +++ b/Swift/Controllers/HistoryViewController.cpp @@ -29,17 +29,22 @@ HistoryViewController::HistoryViewController( nickResolver_(nickResolver), avatarManager_(avatarManager), historyWindowFactory_(historyWindowFactory), - historyWindow_(NULL) { + historyWindow_(NULL), + selectedItem_(NULL) { uiEventStream_->onUIEvent.connect(boost::bind(&HistoryViewController::handleUIEvent, this, _1)); + historyController_->onNewMessage.connect(boost::bind(&HistoryViewController::handleNewMessage, this, _1)); + + roster_ = new Roster(false, true); } HistoryViewController::~HistoryViewController() { uiEventStream_->onUIEvent.disconnect(boost::bind(&HistoryViewController::handleUIEvent, this, _1)); + historyController_->onNewMessage.disconnect(boost::bind(&HistoryViewController::handleNewMessage, this, _1)); if (historyWindow_) { historyWindow_->onSelectedContactChanged.disconnect(boost::bind(&HistoryViewController::handleSelectedContactChanged, this, _1)); delete historyWindow_; - delete roster_; } + delete roster_; } void HistoryViewController::handleUIEvent(boost::shared_ptr<UIEvent> rawEvent) { @@ -49,7 +54,6 @@ void HistoryViewController::handleUIEvent(boost::shared_ptr<UIEvent> rawEvent) { historyWindow_ = historyWindowFactory_->createHistoryWindow(uiEventStream_); historyWindow_->onSelectedContactChanged.connect(boost::bind(&HistoryViewController::handleSelectedContactChanged, this, _1)); - roster_ = new Roster(false, true); historyWindow_->setRosterModel(roster_); historyController_->getAllContacts(selfJID_, rooms_, contacts_); @@ -68,6 +72,8 @@ void HistoryViewController::handleUIEvent(boost::shared_ptr<UIEvent> rawEvent) { void HistoryViewController::handleSelectedContactChanged(RosterItem* newContact) { // FIXME: signal is triggerd twice. + selectedItem_ = dynamic_cast<ContactRosterItem*>(newContact); + if (newContact == NULL) { return; } @@ -84,4 +90,20 @@ void HistoryViewController::handleSelectedContactChanged(RosterItem* newContact) } } +void HistoryViewController::handleNewMessage(const HistoryMessage& message) { + JID contactJID = message.getFromJID().toBare() == selfJID_ ? message.getToJID() : message.getFromJID(); + + if (selectedItem_ && selectedItem_->getJID().toBare() == contactJID) { + bool senderIsSelf = message.getFromJID().toBare() == selfJID_; + std::string avatarPath = byteArrayToString(avatarManager_->getAvatar(message.getFromJID())); + historyWindow_->addMessage(message.getMessage(), nickResolver_->jidToNick(message.getFromJID()), senderIsSelf, avatarPath, message.getTime()); + } + else if (!rooms_.count(contactJID.toBare()) && message.isGroupChat()) { + roster_->addContact(contactJID.toBare(), contactJID.toBare(), nickResolver_->jidToNick(contactJID.toBare()), "MUC", byteArrayToString(avatarManager_->getAvatar(contactJID.toBare()))); + } + else if (!contacts_.count(contactJID) && !message.isGroupChat()) { + roster_->addContact(contactJID, contactJID, nickResolver_->jidToNick(contactJID), "Contacts", byteArrayToString(avatarManager_->getAvatar(contactJID))); + } +} + } diff --git a/Swift/Controllers/HistoryViewController.h b/Swift/Controllers/HistoryViewController.h index f1ff286..4f43f47 100644 --- a/Swift/Controllers/HistoryViewController.h +++ b/Swift/Controllers/HistoryViewController.h @@ -19,9 +19,11 @@ namespace Swift { class HistoryWindow; class Roster; class RosterItem; + class ContactRosterItem; class HistoryController; class NickResolver; class AvatarManager; + class HistoryMessage; class HistoryViewController { public: @@ -31,6 +33,7 @@ namespace Swift { private: void handleUIEvent(boost::shared_ptr<UIEvent> event); void handleSelectedContactChanged(RosterItem* item); + void handleNewMessage(const HistoryMessage& message); private: JID selfJID_; @@ -44,5 +47,6 @@ namespace Swift { std::set<JID> rooms_; std::set<JID> contacts_; + ContactRosterItem* selectedItem_; }; } |