Browse Source

filter directmsgs by age

miguelfreitas
Denis Ryabov 10 years ago
parent
commit
4e47b5666e
  1. 45
      src/twister.cpp

45
src/twister.cpp

@ -2359,6 +2359,7 @@ public:
TextSearch(std::string const &keyword, libtorrent::entry const &params); TextSearch(std::string const &keyword, libtorrent::entry const &params);
bool matchText(std::string msg); bool matchText(std::string msg);
bool matchTime(int64_t time);
libtorrent::lazy_entry const* matchRawMessage(std::string const &rawMessage, libtorrent::lazy_entry &v); libtorrent::lazy_entry const* matchRawMessage(std::string const &rawMessage, libtorrent::lazy_entry &v);
private: private:
@ -2372,7 +2373,7 @@ private:
TextSearch::TextSearch(string const &keyword, entry const &params) : TextSearch::TextSearch(string const &keyword, entry const &params) :
mode(TEXTSEARCH_EXACT), mode(TEXTSEARCH_EXACT),
caseInsensitive(false), caseInsensitive(false),
timeMin(0), timeMin(numeric_limits<int64_t>::min()),
timeMax(numeric_limits<int64_t>::max()) timeMax(numeric_limits<int64_t>::max())
{ {
entry const *pMode = params.find_key("mode"); entry const *pMode = params.find_key("mode");
@ -2436,7 +2437,7 @@ bool TextSearch::matchText(string msg)
return false; return false;
} }
if( caseInsensitive ) { if( caseInsensitive ) { // that is why msg is passed by value
#ifdef HAVE_BOOST_LOCALE #ifdef HAVE_BOOST_LOCALE
msg = boost::locale::to_lower(msg); msg = boost::locale::to_lower(msg);
#else #else
@ -2465,7 +2466,12 @@ bool TextSearch::matchText(string msg)
return false; return false;
} }
lazy_entry const* TextSearch::matchRawMessage(string const &rawMessage, libtorrent::lazy_entry &v) inline bool TextSearch::matchTime(int64_t time)
{
return time >= timeMin && time <= timeMax;
}
lazy_entry const* TextSearch::matchRawMessage(string const &rawMessage, lazy_entry &v)
{ {
if( keywords.size() == 0 ) { if( keywords.size() == 0 ) {
return 0; return 0;
@ -2492,7 +2498,7 @@ lazy_entry const* TextSearch::matchRawMessage(string const &rawMessage, libtorre
} }
int64_t time = p->dict_find_int_value("time"); int64_t time = p->dict_find_int_value("time");
if( time < timeMin || time > timeMax ) { if( !matchTime(time) ) {
return 0; return 0;
} }
@ -2636,14 +2642,16 @@ Value search(const Array& params, bool fHelp)
string remoteUser = list.first; string remoteUser = list.first;
BOOST_FOREACH(const StoredDirectMsg& item, list.second) { BOOST_FOREACH(const StoredDirectMsg& item, list.second) {
if( searcher.matchText(item.m_text) ) { if( searcher.matchText(item.m_text) ) {
int64 time = item.m_utcTime; int64_t time = item.m_utcTime;
entry vEntry; if( searcher.matchTime(time) ) {
vEntry["remoteUser"] = remoteUser; entry vEntry;
vEntry["text"] = item.m_text; vEntry["remoteUser"] = remoteUser;
vEntry["time"] = time; vEntry["text"] = item.m_text;
vEntry["fromMe"] = item.m_fromMe; vEntry["time"] = time;
hexcapePost(vEntry); vEntry["fromMe"] = item.m_fromMe;
postsByTime.insert( pair<int64,entry>(time, vEntry) ); hexcapePost(vEntry);
postsByTime.insert( pair<int64,entry>(time, vEntry) );
}
} }
} }
} }
@ -2681,15 +2689,10 @@ Value search(const Array& params, bool fHelp)
if( resource == "profile" ) { if( resource == "profile" ) {
lazy_entry const* v = p.dict_find_dict("v"); lazy_entry const* v = p.dict_find_dict("v");
if( v ) { if( v ) {
string bio = v->dict_find_string_value("bio"); if( searcher.matchText(v->dict_find_string_value("bio")) ||
string fullname = v->dict_find_string_value("fullname"); searcher.matchText(v->dict_find_string_value("fullname")) ||
string location = v->dict_find_string_value("location"); searcher.matchText(v->dict_find_string_value("location")) ||
string url = v->dict_find_string_value("url"); searcher.matchText(v->dict_find_string_value("url")) ) {
if( searcher.matchText(bio) ||
searcher.matchText(fullname) ||
searcher.matchText(location) ||
searcher.matchText(url) ) {
string n = target->dict_find_string_value("n"); string n = target->dict_find_string_value("n");
entry vEntry; entry vEntry;

Loading…
Cancel
Save