diff options
Diffstat (limited to 'src/tweet.cpp')
-rw-r--r-- | src/tweet.cpp | 65 |
1 files changed, 48 insertions, 17 deletions
diff --git a/src/tweet.cpp b/src/tweet.cpp index 4abe2f8..864bcd8 100644 --- a/src/tweet.cpp +++ b/src/tweet.cpp | |||
@@ -6,19 +6,19 @@ | |||
6 | 6 | ||
7 | namespace twitter { | 7 | namespace twitter { |
8 | 8 | ||
9 | tweet::tweet(const client& tclient, std::string data) try | 9 | tweet::tweet(std::string data) try |
10 | : _client(tclient) | 10 | : _valid(true) |
11 | { | 11 | { |
12 | auto json = nlohmann::json::parse(data); | 12 | auto json = nlohmann::json::parse(data); |
13 | _id = json["id"].get<tweet_id>(); | 13 | _id = json["id"].get<tweet_id>(); |
14 | _text = json["text"].get<std::string>(); | 14 | _text = json["text"].get<std::string>(); |
15 | _author = make_unique<user>(_client, json["user"].dump()); | 15 | _author = make_unique<user>(json["user"].dump()); |
16 | 16 | ||
17 | if (!json["retweeted_status"].is_null()) | 17 | if (!json["retweeted_status"].is_null()) |
18 | { | 18 | { |
19 | _is_retweet = true; | 19 | _is_retweet = true; |
20 | 20 | ||
21 | _retweeted_status = make_unique<tweet>(_client, json["retweeted_status"].dump()); | 21 | _retweeted_status = make_unique<tweet>(json["retweeted_status"].dump()); |
22 | } | 22 | } |
23 | 23 | ||
24 | if (!json["entities"].is_null()) | 24 | if (!json["entities"].is_null()) |
@@ -40,14 +40,53 @@ namespace twitter { | |||
40 | std::throw_with_nested(malformed_object("tweet", data)); | 40 | std::throw_with_nested(malformed_object("tweet", data)); |
41 | } | 41 | } |
42 | 42 | ||
43 | std::string tweet::generateReplyPrefill() const | 43 | tweet::tweet(const tweet& other) |
44 | { | ||
45 | _valid = other._valid; | ||
46 | _id = other._id; | ||
47 | _text = other._text; | ||
48 | _author = make_unique<user>(*other._author); | ||
49 | _is_retweet = other._is_retweet; | ||
50 | |||
51 | if (_is_retweet) | ||
52 | { | ||
53 | _retweeted_status = make_unique<tweet>(*other._retweeted_status); | ||
54 | } | ||
55 | |||
56 | _mentions = other._mentions; | ||
57 | } | ||
58 | |||
59 | tweet::tweet(tweet&& other) : tweet() | ||
60 | { | ||
61 | swap(*this, other); | ||
62 | } | ||
63 | |||
64 | tweet& tweet::operator=(tweet other) | ||
65 | { | ||
66 | swap(*this, other); | ||
67 | |||
68 | return *this; | ||
69 | } | ||
70 | |||
71 | void swap(tweet& first, tweet& second) | ||
72 | { | ||
73 | std::swap(first._valid, second._valid); | ||
74 | std::swap(first._id, second._id); | ||
75 | std::swap(first._text, second._text); | ||
76 | std::swap(first._author, second._author); | ||
77 | std::swap(first._is_retweet, second._is_retweet); | ||
78 | std::swap(first._retweeted_status, second._retweeted_status); | ||
79 | std::swap(first._mentions, second._mentions); | ||
80 | } | ||
81 | |||
82 | std::string tweet::generateReplyPrefill(const user& me) const | ||
44 | { | 83 | { |
45 | std::ostringstream output; | 84 | std::ostringstream output; |
46 | output << "@" << _author->getScreenName() << " "; | 85 | output << "@" << _author->getScreenName() << " "; |
47 | 86 | ||
48 | for (auto mention : _mentions) | 87 | for (auto mention : _mentions) |
49 | { | 88 | { |
50 | if ((mention.first != _author->getID()) && (mention.first != _client.getUser().getID())) | 89 | if ((mention.first != _author->getID()) && (mention.first != me.getID())) |
51 | { | 90 | { |
52 | output << "@" << mention.second << " "; | 91 | output << "@" << mention.second << " "; |
53 | } | 92 | } |
@@ -56,20 +95,12 @@ namespace twitter { | |||
56 | return output.str(); | 95 | return output.str(); |
57 | } | 96 | } |
58 | 97 | ||
59 | tweet tweet::reply(std::string message, std::list<long> media_ids) const | ||
60 | { | ||
61 | return _client.replyToTweet(message, _id, media_ids); | ||
62 | } | ||
63 | |||
64 | bool tweet::isMyTweet() const | ||
65 | { | ||
66 | return *_author == _client.getUser(); | ||
67 | } | ||
68 | |||
69 | std::string tweet::getURL() const | 98 | std::string tweet::getURL() const |
70 | { | 99 | { |
100 | assert(_valid); | ||
101 | |||
71 | std::ostringstream urlstr; | 102 | std::ostringstream urlstr; |
72 | urlstr << "https://twitter.com"; | 103 | urlstr << "https://twitter.com/"; |
73 | urlstr << _author->getScreenName(); | 104 | urlstr << _author->getScreenName(); |
74 | urlstr << "/statuses/"; | 105 | urlstr << "/statuses/"; |
75 | urlstr << _id; | 106 | urlstr << _id; |