summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCatalin Badea <catalin.badea392@gmail.com>2012-07-22 10:33:04 (GMT)
committerCătălin Badea <catalin.badea392@gmail.com>2012-08-11 15:59:12 (GMT)
commita158169f9143904d8d1dd18609563505f1c49c75 (patch)
tree7427765f69bf02b80dbab0849edb943a89fefbc1
parent88d6b5d7a0867cbb045dedb59d18f9795ee3701e (diff)
downloadswift-contrib-a158169f9143904d8d1dd18609563505f1c49c75.zip
swift-contrib-a158169f9143904d8d1dd18609563505f1c49c75.tar.bz2
jump to the next matching day using the next/previous buttons
-rw-r--r--Swift/Controllers/HistoryViewController.cpp44
-rw-r--r--Swift/Controllers/HistoryViewController.h2
2 files changed, 40 insertions, 6 deletions
diff --git a/Swift/Controllers/HistoryViewController.cpp b/Swift/Controllers/HistoryViewController.cpp
index 5f200f7..0c8cfcd 100644
--- a/Swift/Controllers/HistoryViewController.cpp
+++ b/Swift/Controllers/HistoryViewController.cpp
@@ -97,7 +97,7 @@ void HistoryViewController::handleSelectedContactChanged(RosterItem* newContact)
if (contacts_[type].count(contactJID)) {
currentResultDate_ = *contacts_[type][contactJID].rbegin();
- currentItemType_ = type;
+ selectedItemType_ = type;
messages = historyController_->getMessagesFromDate(selfJID_, contactJID, type, currentResultDate_);
}
}
@@ -156,7 +156,7 @@ void HistoryViewController::handleReturnPressed(const std::string& keyword) {
}
void HistoryViewController::handleScrollReachedTop(const boost::gregorian::date& date) {
- std::vector<HistoryMessage> messages = historyController_->getMessagesFromPreviousDate(selfJID_, selectedItem_->getJID(), currentItemType_, date);
+ std::vector<HistoryMessage> messages = historyController_->getMessagesFromPreviousDate(selfJID_, selectedItem_->getJID(), selectedItemType_, date);
reverse_foreach (const HistoryMessage& message, messages) {
addNewMessage(message, true);
@@ -164,7 +164,7 @@ void HistoryViewController::handleScrollReachedTop(const boost::gregorian::date&
}
void HistoryViewController::handleScrollReachedBottom(const boost::gregorian::date& date) {
- std::vector<HistoryMessage> messages = historyController_->getMessagesFromNextDate(selfJID_, selectedItem_->getJID(), currentItemType_, date);
+ std::vector<HistoryMessage> messages = historyController_->getMessagesFromNextDate(selfJID_, selectedItem_->getJID(), selectedItemType_, date);
foreach (const HistoryMessage& message, messages) {
addNewMessage(message, true);
@@ -172,11 +172,45 @@ void HistoryViewController::handleScrollReachedBottom(const boost::gregorian::da
}
void HistoryViewController::handlePreviousButtonClicked() {
- reset();
+ if (!selectedItem_) {
+ return;
+ }
+
+ std::set<boost::gregorian::date>::iterator date = contacts_[selectedItemType_][selectedItem_->getJID()].find(currentResultDate_);
+
+ if (*date == *contacts_[selectedItemType_][selectedItem_->getJID()].rbegin()) {
+ return;
+ }
+
+ historyWindow_->resetConversationView();
+ currentResultDate_ = *(++date);
+ std::vector<HistoryMessage> messages = historyController_->getMessagesFromDate(selfJID_, selectedItem_->getJID(), selectedItemType_, currentResultDate_);
+ historyWindow_->setDate(currentResultDate_);
+
+ foreach (const HistoryMessage& message, messages) {
+ addNewMessage(message, false);
+ }
}
void HistoryViewController::handleNextButtonClicked() {
- reset();
+ if (!selectedItem_) {
+ return;
+ }
+
+ std::set<boost::gregorian::date>::iterator date = contacts_[selectedItemType_][selectedItem_->getJID()].find(currentResultDate_);
+
+ if (date == contacts_[selectedItemType_][selectedItem_->getJID()].begin()) {
+ return;
+ }
+
+ historyWindow_->resetConversationView();
+ currentResultDate_ = *(--date);
+ std::vector<HistoryMessage> messages = historyController_->getMessagesFromDate(selfJID_, selectedItem_->getJID(), selectedItemType_, currentResultDate_);
+ historyWindow_->setDate(currentResultDate_);
+
+ foreach (const HistoryMessage& message, messages) {
+ addNewMessage(message, false);
+ }
}
void HistoryViewController::reset() {
diff --git a/Swift/Controllers/HistoryViewController.h b/Swift/Controllers/HistoryViewController.h
index a7667c4..e78b5be 100644
--- a/Swift/Controllers/HistoryViewController.h
+++ b/Swift/Controllers/HistoryViewController.h
@@ -56,7 +56,7 @@ namespace Swift {
std::map<HistoryMessage::Type, ContactsMap> contacts_;
ContactRosterItem* selectedItem_;
- HistoryMessage::Type currentItemType_;
+ HistoryMessage::Type selectedItemType_;
boost::gregorian::date currentResultDate_;
};
}