summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Swift/Controllers/HistoryViewController.cpp64
-rw-r--r--Swift/Controllers/HistoryViewController.h4
-rw-r--r--Swift/Controllers/UIInterfaces/HistoryWindow.h4
-rw-r--r--Swift/QtUI/QtHistoryWindow.cpp8
4 files changed, 27 insertions, 53 deletions
diff --git a/Swift/Controllers/HistoryViewController.cpp b/Swift/Controllers/HistoryViewController.cpp
index baa7ebf..5f200f7 100644
--- a/Swift/Controllers/HistoryViewController.cpp
+++ b/Swift/Controllers/HistoryViewController.cpp
@@ -15,6 +15,7 @@
#include <Swiften/Avatars/AvatarManager.h>
namespace Swift {
+ static const std::string category[] = { "Contacts", "MUC", "Contacts" };
HistoryViewController::HistoryViewController(
const JID& selfJID,
@@ -91,20 +92,14 @@ void HistoryViewController::handleSelectedContactChanged(RosterItem* newContact)
JID contactJID = contact->getJID();
std::vector<HistoryMessage> messages;
- if (roomPrivateContacts_.count(contactJID)) {
- currentResultDate_ = *roomPrivateContacts_[contactJID].rbegin();
- messages = historyController_->getMessagesFromDate(selfJID_, contactJID, HistoryMessage::PrivateMessage, currentResultDate_);
- currentItemType_ = HistoryMessage::PrivateMessage;
- }
- else if (contacts_.count(contactJID)) {
- currentResultDate_ = *contacts_[contactJID].rbegin();
- messages = historyController_->getMessagesFromDate(selfJID_, contactJID, HistoryMessage::Chat, currentResultDate_);
- currentItemType_ = HistoryMessage::Chat;
- }
- else {
- currentResultDate_ = *rooms_[contactJID].rbegin();
- messages = historyController_->getMessagesFromDate(selfJID_, contactJID, HistoryMessage::Groupchat, currentResultDate_);
- currentItemType_ = HistoryMessage::Groupchat;
+ for (int it = HistoryMessage::Chat; it <= HistoryMessage::PrivateMessage; it++) {
+ HistoryMessage::Type type = static_cast<HistoryMessage::Type>(it);
+
+ if (contacts_[type].count(contactJID)) {
+ currentResultDate_ = *contacts_[type][contactJID].rbegin();
+ currentItemType_ = type;
+ messages = historyController_->getMessagesFromDate(selfJID_, contactJID, type, currentResultDate_);
+ }
}
historyWindow_->setDate(currentResultDate_);
@@ -129,20 +124,13 @@ void HistoryViewController::handleNewMessage(const HistoryMessage& message) {
if (selectedItem_ && selectedItem_->getJID() == displayJID) {
addNewMessage(message, false);
}
+
// add new contact
- else if (message.getType() == HistoryMessage::Groupchat && !rooms_.count(displayJID)) {
- roster_->addContact(displayJID, displayJID, nickResolver_->jidToNick(displayJID), "MUC", avatarManager_->getAvatarPath(displayJID).string());
+ else if (contacts_[message.getType()].count(displayJID)) {
+ roster_->addContact(displayJID, displayJID, nickResolver_->jidToNick(displayJID), category[message.getType()], avatarManager_->getAvatarPath(displayJID).string());
//
// TODO add message date here
- rooms_[displayJID] = std::set<boost::gregorian::date>();
- }
- else if (message.getType() == HistoryMessage::Chat && !contacts_.count(displayJID)) {
- roster_->addContact(displayJID, displayJID, nickResolver_->jidToNick(displayJID), "Contacts", avatarManager_->getAvatarPath(displayJID).string());
- contacts_[displayJID] = std::set<boost::gregorian::date>();
- }
- else if (message.getType() == HistoryMessage::PrivateMessage && !roomPrivateContacts_.count(displayJID)) {
- roster_->addContact(displayJID, displayJID, nickResolver_->jidToNick(displayJID), "Contacts", avatarManager_->getAvatarPath(displayJID).string());
- roomPrivateContacts_[displayJID] = std::set<boost::gregorian::date>();
+ contacts_[message.getType()][displayJID] = std::set<boost::gregorian::date>();
}
}
@@ -155,25 +143,15 @@ void HistoryViewController::addNewMessage(const HistoryMessage& message, bool ad
void HistoryViewController::handleReturnPressed(const std::string& keyword) {
reset();
- // MUCs
- rooms_ = historyController_->getContacts(selfJID_, HistoryMessage::Groupchat, keyword);
- for (ContactsMap::const_iterator room = rooms_.begin(); room != rooms_.end(); room++) {
- const JID& jid = room->first;
- roster_->addContact(jid, jid, nickResolver_->jidToNick(jid), "MUC", avatarManager_->getAvatarPath(jid).string());
- }
+ for (int it = HistoryMessage::Chat; it <= HistoryMessage::PrivateMessage; it++) {
+ HistoryMessage::Type type = static_cast<HistoryMessage::Type>(it);
- // Contacts
- contacts_ = historyController_->getContacts(selfJID_, HistoryMessage::Chat, keyword);
- for (ContactsMap::const_iterator contact = contacts_.begin(); contact != contacts_.end(); contact++) {
- const JID& jid = contact->first;
- roster_->addContact(jid, jid, nickResolver_->jidToNick(jid), "Contacts", avatarManager_->getAvatarPath(jid).string());
- }
+ contacts_[type] = historyController_->getContacts(selfJID_, type, keyword);
- // MUC contacts
- roomPrivateContacts_ = historyController_->getContacts(selfJID_, HistoryMessage::PrivateMessage, keyword);
- for (ContactsMap::const_iterator contact = roomPrivateContacts_.begin(); contact != roomPrivateContacts_.end(); contact++) {
- const JID& jid = contact->first;
- roster_->addContact(jid, jid, nickResolver_->jidToNick(jid), "Contacts", avatarManager_->getAvatarPath(jid).string());
+ 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());
+ }
}
}
@@ -203,9 +181,7 @@ void HistoryViewController::handleNextButtonClicked() {
void HistoryViewController::reset() {
roster_->removeAll();
- rooms_.clear();
contacts_.clear();
- roomPrivateContacts_.clear();
selectedItem_ = NULL;
historyWindow_->resetConversationView();
}
diff --git a/Swift/Controllers/HistoryViewController.h b/Swift/Controllers/HistoryViewController.h
index b4ae19d..a7667c4 100644
--- a/Swift/Controllers/HistoryViewController.h
+++ b/Swift/Controllers/HistoryViewController.h
@@ -54,9 +54,7 @@ namespace Swift {
HistoryWindow* historyWindow_;
Roster* roster_;
- ContactsMap contacts_;
- ContactsMap rooms_;
- ContactsMap roomPrivateContacts_;
+ std::map<HistoryMessage::Type, ContactsMap> contacts_;
ContactRosterItem* selectedItem_;
HistoryMessage::Type currentItemType_;
boost::gregorian::date currentResultDate_;
diff --git a/Swift/Controllers/UIInterfaces/HistoryWindow.h b/Swift/Controllers/UIInterfaces/HistoryWindow.h
index cb8225b..aa1a495 100644
--- a/Swift/Controllers/UIInterfaces/HistoryWindow.h
+++ b/Swift/Controllers/UIInterfaces/HistoryWindow.h
@@ -23,7 +23,7 @@ namespace Swift {
boost::signal<void (const std::string&)> onReturnPressed;
boost::signal<void (const boost::gregorian::date&)> onScrollReachedTop;
boost::signal<void (const boost::gregorian::date&)> onScrollReachedBottom;
- boost::signal<void ()> onPreviousButtonClicked();
- boost::signal<void ()> onNextButtonClicked();
+ boost::signal<void ()> onPreviousButtonClicked;
+ boost::signal<void ()> onNextButtonClicked;
};
}
diff --git a/Swift/QtUI/QtHistoryWindow.cpp b/Swift/QtUI/QtHistoryWindow.cpp
index ba463d3..a9a8997 100644
--- a/Swift/QtUI/QtHistoryWindow.cpp
+++ b/Swift/QtUI/QtHistoryWindow.cpp
@@ -60,8 +60,8 @@ QtHistoryWindow::QtHistoryWindow(SettingsProvider* settings, UIEventStream* even
connect(conversation_, SIGNAL(scrollReachedBottom()), this, SLOT(handleScrollReachedBottom()));
connect(ui_.searchBox_->lineEdit(), SIGNAL(returnPressed()), this, SLOT(handleReturnPressed()));
connect(ui_.calendarWidget_, SIGNAL(clicked(const QDate&)), this, SLOT(handleCalendarClicked(const QDate&)));
- connect(ui_.previousButton_, SIGNAL(clicked(bool)), this SLOT(handlePreviousButtonClicked()));
- connect(ui_.nextButton_, SIGNAL(clicked(bool)), this SLOT(handleNextButtonClicked()));
+ connect(ui_.previousButton_, SIGNAL(clicked(bool)), this, SLOT(handlePreviousButtonClicked()));
+ connect(ui_.nextButton_, SIGNAL(clicked(bool)), this, SLOT(handleNextButtonClicked()));
}
QtHistoryWindow::~QtHistoryWindow() {
@@ -70,8 +70,8 @@ QtHistoryWindow::~QtHistoryWindow() {
disconnect(conversation_, SIGNAL(scrollReachedBottom()), this, SLOT(handleScrollReachedBottom()));
disconnect(ui_.searchBox_->lineEdit(), SIGNAL(returnPressed()), this, SLOT(handleReturnPressed()));
disconnect(ui_.calendarWidget_, SIGNAL(clicked(const QDate&)), this, SLOT(handleCalendarClicked(const QDate&)));
- disconnect(ui_.previousButton_, SIGNAL(clicked(bool)), this SLOT(handlePreviousButtonClicked()));
- disconnect(ui_.nextButton_, SIGNAL(clicked(bool)), this SLOT(handleNextButtonClicked()));
+ disconnect(ui_.previousButton_, SIGNAL(clicked(bool)), this, SLOT(handlePreviousButtonClicked()));
+ disconnect(ui_.nextButton_, SIGNAL(clicked(bool)), this, SLOT(handleNextButtonClicked()));
delete theme_;
delete conversation_;