diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/client.cpp | 16 | ||||
| -rw-r--r-- | src/client.h | 2 | ||||
| -rw-r--r-- | src/tweet.cpp | 17 | ||||
| -rw-r--r-- | src/tweet.h | 4 | ||||
| -rw-r--r-- | src/user.cpp | 5 | ||||
| -rw-r--r-- | src/user.h | 1 |
6 files changed, 45 insertions, 0 deletions
| diff --git a/src/client.cpp b/src/client.cpp index bae563f..617af62 100644 --- a/src/client.cpp +++ b/src/client.cpp | |||
| @@ -420,6 +420,22 @@ namespace twitter { | |||
| 420 | _user_stream.stop(); | 420 | _user_stream.stop(); |
| 421 | } | 421 | } |
| 422 | 422 | ||
| 423 | std::string client::generateReplyPrefill(tweet _tweet) const | ||
| 424 | { | ||
| 425 | std::ostringstream output; | ||
| 426 | output << "@" << _tweet.getAuthor().getScreenName() << " "; | ||
| 427 | |||
| 428 | for (auto mention : _tweet.getMentions()) | ||
| 429 | { | ||
| 430 | if ((mention.first != _tweet.getAuthor().getID()) && (mention.first != _current_user.getID())) | ||
| 431 | { | ||
| 432 | output << "@" << mention.second << " "; | ||
| 433 | } | ||
| 434 | } | ||
| 435 | |||
| 436 | return output.str(); | ||
| 437 | } | ||
| 438 | |||
| 423 | bool client::performGet(std::string url, long& response_code, std::string& result) | 439 | bool client::performGet(std::string url, long& response_code, std::string& result) |
| 424 | { | 440 | { |
| 425 | std::ostringstream output; | 441 | std::ostringstream output; |
| diff --git a/src/client.h b/src/client.h index 750d603..901c7b5 100644 --- a/src/client.h +++ b/src/client.h | |||
| @@ -84,6 +84,8 @@ namespace twitter { | |||
| 84 | void startUserStream(); | 84 | void startUserStream(); |
| 85 | void stopUserStream(); | 85 | void stopUserStream(); |
| 86 | 86 | ||
| 87 | std::string generateReplyPrefill(tweet t) const; | ||
| 88 | |||
| 87 | private: | 89 | private: |
| 88 | friend class stream; | 90 | friend class stream; |
| 89 | 91 | ||
| diff --git a/src/tweet.cpp b/src/tweet.cpp index 5885b51..bf95bc0 100644 --- a/src/tweet.cpp +++ b/src/tweet.cpp | |||
| @@ -18,6 +18,18 @@ namespace twitter { | |||
| 18 | _text = _data.at("text"); | 18 | _text = _data.at("text"); |
| 19 | _author = user(_data.at("user").dump()); | 19 | _author = user(_data.at("user").dump()); |
| 20 | _retweeted = _data.at("retweeted"); | 20 | _retweeted = _data.at("retweeted"); |
| 21 | |||
| 22 | if (_data.find("entities") != _data.end()) | ||
| 23 | { | ||
| 24 | auto _entities = _data.at("entities"); | ||
| 25 | if (_entities.find("user_mentions") != _entities.end()) | ||
| 26 | { | ||
| 27 | for (auto _mention : _entities.at("user_mentions")) | ||
| 28 | { | ||
| 29 | _mentions.push_back(std::make_pair(_mention.at("id"), _mention.at("screen_name").get<std::string>())); | ||
| 30 | } | ||
| 31 | } | ||
| 32 | } | ||
| 21 | } | 33 | } |
| 22 | 34 | ||
| 23 | tweet_id tweet::getID() const | 35 | tweet_id tweet::getID() const |
| @@ -48,6 +60,11 @@ namespace twitter { | |||
| 48 | return _retweeted; | 60 | return _retweeted; |
| 49 | } | 61 | } |
| 50 | 62 | ||
| 63 | std::vector<std::pair<user_id, std::string>> tweet::getMentions() const | ||
| 64 | { | ||
| 65 | return _mentions; | ||
| 66 | } | ||
| 67 | |||
| 51 | tweet::operator bool() const | 68 | tweet::operator bool() const |
| 52 | { | 69 | { |
| 53 | return _valid; | 70 | return _valid; |
| diff --git a/src/tweet.h b/src/tweet.h index fba1ced..34a9cd7 100644 --- a/src/tweet.h +++ b/src/tweet.h | |||
| @@ -3,6 +3,8 @@ | |||
| 3 | 3 | ||
| 4 | #include <string> | 4 | #include <string> |
| 5 | #include "user.h" | 5 | #include "user.h" |
| 6 | #include <vector> | ||
| 7 | #include <utility> | ||
| 6 | 8 | ||
| 7 | namespace twitter { | 9 | namespace twitter { |
| 8 | 10 | ||
| @@ -17,6 +19,7 @@ namespace twitter { | |||
| 17 | std::string getText() const; | 19 | std::string getText() const; |
| 18 | const user& getAuthor() const; | 20 | const user& getAuthor() const; |
| 19 | bool isRetweet() const; | 21 | bool isRetweet() const; |
| 22 | std::vector<std::pair<user_id, std::string>> getMentions() const; | ||
| 20 | 23 | ||
| 21 | operator bool() const; | 24 | operator bool() const; |
| 22 | 25 | ||
| @@ -26,6 +29,7 @@ namespace twitter { | |||
| 26 | std::string _text; | 29 | std::string _text; |
| 27 | user _author; | 30 | user _author; |
| 28 | bool _retweeted; | 31 | bool _retweeted; |
| 32 | std::vector<std::pair<user_id, std::string>> _mentions; | ||
| 29 | }; | 33 | }; |
| 30 | 34 | ||
| 31 | }; | 35 | }; |
| diff --git a/src/user.cpp b/src/user.cpp index 9352938..0fa1e39 100644 --- a/src/user.cpp +++ b/src/user.cpp | |||
| @@ -42,5 +42,10 @@ namespace twitter { | |||
| 42 | { | 42 | { |
| 43 | return _id == other._id; | 43 | return _id == other._id; |
| 44 | } | 44 | } |
| 45 | |||
| 46 | bool user::operator!=(const user& other) const | ||
| 47 | { | ||
| 48 | return _id != other._id; | ||
| 49 | } | ||
| 45 | 50 | ||
| 46 | }; | 51 | }; |
| diff --git a/src/user.h b/src/user.h index 0af40d6..1d8be99 100644 --- a/src/user.h +++ b/src/user.h | |||
| @@ -18,6 +18,7 @@ namespace twitter { | |||
| 18 | 18 | ||
| 19 | operator bool() const; | 19 | operator bool() const; |
| 20 | bool operator==(const user& other) const; | 20 | bool operator==(const user& other) const; |
| 21 | bool operator!=(const user& other) const; | ||
| 21 | 22 | ||
| 22 | private: | 23 | private: |
| 23 | bool _valid = false; | 24 | bool _valid = false; |
