diff --git a/src/main.cpp b/src/main.cpp index e2212d5..32d6e2f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -30,6 +30,8 @@ void loadFilter() { filterlist.insert({"Filename", new FilenameFilter()}); filterlist.insert({"RegexFilename", new RegexFilenameFilter()}); filterlist.insert({"Date", new DateFilter()}); + filterlist.insert({"Chat", new FilterChat()}); + filterlist.insert({"ForwordedFrom", new ForwardedFromChatFilter()}); } void removeFilter() { diff --git a/src/mediafilter.cpp b/src/mediafilter.cpp index c2b5194..a6988c3 100644 --- a/src/mediafilter.cpp +++ b/src/mediafilter.cpp @@ -12,4 +12,24 @@ void HasMediaFilter::setup(std::ostream& o, std::istream& str) { bool HasMediaFilter::filter(const Message& m) const { return m.hasFile() == needMedia; +} + +void FilterChat::setup(std::ostream& o, std::istream& str) { + o << "Enter Chatid: "; + + str >> chatid; +} + +bool FilterChat::filter(const Message& m) const { + return m.chatid == chatid; +} + +void ForwardedFromChatFilter::setup(std::ostream& o, std::istream& str) { + o << "Enter ChatName: "; + + std::getline(str, chatname); +} + +bool ForwardedFromChatFilter::filter(const Message& m) const { + return m.fwdFrom == chatname; } \ No newline at end of file diff --git a/src/mediafilter.h b/src/mediafilter.h index 376b496..89c29aa 100644 --- a/src/mediafilter.h +++ b/src/mediafilter.h @@ -7,4 +7,18 @@ struct HasMediaFilter : public Filter { virtual bool filter(const Message& m) const; protected: bool needMedia; // true = msg should have media; false = mmessage should not have media +}; + +struct FilterChat : public Filter { + virtual void setup(std::ostream& o, std::istream& str); + virtual bool filter(const Message& m) const; +protected: + int64_t chatid; +}; + +struct ForwardedFromChatFilter : public Filter { + virtual void setup(std::ostream& o, std::istream& str); + virtual bool filter(const Message& m) const; +protected: + std::string chatname; }; \ No newline at end of file diff --git a/src/message.cpp b/src/message.cpp index 5c32122..b6a7f0b 100644 --- a/src/message.cpp +++ b/src/message.cpp @@ -32,6 +32,9 @@ Message::Message(const json& m, int64_t chatid) : chatid(chatid) { if(m.contains("from_id") && m["from_id"].is_number_unsigned()) senderid = m["from_id"]; + if(m.contains("forwarded_from") && m["forwarded_from"].is_string()) + fwdFrom = m["forwarded_from"]; + if(m.contains("date")) { tm parsedTime; ::strptime(m["date"].get_ref().c_str(), "%Y-%m-%dT%T", &parsedTime); diff --git a/src/message.h b/src/message.h index a6e3b84..b3cc5b2 100644 --- a/src/message.h +++ b/src/message.h @@ -8,6 +8,7 @@ struct Message { int64_t chatid = 0; int64_t messageid = 0; int64_t senderid = 0; + std::string fwdFrom; std::string text = ""; std::string filename = ""; //empty filename = no file time_t date = 0;