From 2c154cc4125bb114de1262833547715c09bf724e Mon Sep 17 00:00:00 2001 From: Steve Kemp Date: Mon, 13 May 2013 18:35:11 +0100 Subject: [PATCH] Updated the way that messges are handled. Read messages are now marked as such, which causes a bug, as expected. Issue #3 is real and will be a pain to fix. --- global.cc | 4 +++- message.cc | 15 +++++++++++++++ message.h | 5 +++++ screen.cc | 8 +++++--- 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/global.cc b/global.cc index 96f71d3..7105b48 100644 --- a/global.cc +++ b/global.cc @@ -257,6 +257,7 @@ std::vector CGlobal::get_messages() */ CGlobal *global = CGlobal::Instance(); std::vector folders = global->get_selected_folders(); + std::string * filter = global->get_index_limit(); /** * The sum of all messages we're going to display. @@ -280,7 +281,8 @@ std::vector CGlobal::get_messages() */ std::vector::iterator mit; for (mit = contents.begin(); mit != contents.end(); ++mit) { - messages.push_back(*mit); + if ( (*mit)->matches_filter( filter ) ) + messages.push_back(*mit) ; } } diff --git a/message.cc b/message.cc index d06c796..3c7aa2a 100644 --- a/message.cc +++ b/message.cc @@ -93,6 +93,21 @@ std::string CMessage::flags() return flags; } +/** + * Does this message match the given filter. + */ +bool CMessage::matches_filter( std::string *filter ) +{ + if ( strcmp( filter->c_str(), "all" ) == 0 ) + return true; + + if ( ( strcmp( filter->c_str(), "new" ) == 0 ) && + is_new() ) + return true; + + return false; +} + /** * Is this message new? diff --git a/message.h b/message.h index 9f0294d..9d81fc7 100644 --- a/message.h +++ b/message.h @@ -67,6 +67,11 @@ class CMessage */ std::string flags(); + /** + * Does this message match the given filter? + */ + bool matches_filter( std::string *filter ); + /** * Is this message new? */ diff --git a/screen.cc b/screen.cc index bc2335c..3044cbf 100644 --- a/screen.cc +++ b/screen.cc @@ -196,8 +196,8 @@ void CScreen::drawIndex() * Bound the selection. */ if (selected >= count) { - global->set_selected_message(0); - selected = 0; + selected = count-1; + global->set_selected_message(selected); } /** @@ -295,7 +295,7 @@ void CScreen::drawMessage() CMessage *cur = NULL; if ((selected) < count) - cur = messages[ selected]; + cur = messages[selected]; else { clear(); @@ -360,6 +360,8 @@ void CScreen::drawMessage() printw( "%s", body[i].c_str() ); } + if ( cur->is_new() ) + cur->mark_read(); } /**