From 7c44fd17bb6be54a2ea4b60761e91053ca988977 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Tue, 29 Nov 2016 16:18:25 -0500 Subject: Made tweets, users, and notifications into copyable objects Notifications are now also mutable. Users and tweets no longer have helper methods for interacting with the client. Fixed a bug (possibly introduced by a change to the Twitter API) that caused non-reply tweets to be marked as unknown notifications. --- src/tweet.cpp | 65 +++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 48 insertions(+), 17 deletions(-) (limited to 'src/tweet.cpp') 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 @@ namespace twitter { - tweet::tweet(const client& tclient, std::string data) try - : _client(tclient) + tweet::tweet(std::string data) try + : _valid(true) { auto json = nlohmann::json::parse(data); _id = json["id"].get(); _text = json["text"].get(); - _author = make_unique(_client, json["user"].dump()); + _author = make_unique(json["user"].dump()); if (!json["retweeted_status"].is_null()) { _is_retweet = true; - _retweeted_status = make_unique(_client, json["retweeted_status"].dump()); + _retweeted_status = make_unique(json["retweeted_status"].dump()); } if (!json["entities"].is_null()) @@ -40,14 +40,53 @@ namespace twitter { std::throw_with_nested(malformed_object("tweet", data)); } - std::string tweet::generateReplyPrefill() const + tweet::tweet(const tweet& other) + { + _valid = other._valid; + _id = other._id; + _text = other._text; + _author = make_unique(*other._author); + _is_retweet = other._is_retweet; + + if (_is_retweet) + { + _retweeted_status = make_unique(*other._retweeted_status); + } + + _mentions = other._mentions; + } + + tweet::tweet(tweet&& other) : tweet() + { + swap(*this, other); + } + + tweet& tweet::operator=(tweet other) + { + swap(*this, other); + + return *this; + } + + void swap(tweet& first, tweet& second) + { + std::swap(first._valid, second._valid); + std::swap(first._id, second._id); + std::swap(first._text, second._text); + std::swap(first._author, second._author); + std::swap(first._is_retweet, second._is_retweet); + std::swap(first._retweeted_status, second._retweeted_status); + std::swap(first._mentions, second._mentions); + } + + std::string tweet::generateReplyPrefill(const user& me) const { std::ostringstream output; output << "@" << _author->getScreenName() << " "; for (auto mention : _mentions) { - if ((mention.first != _author->getID()) && (mention.first != _client.getUser().getID())) + if ((mention.first != _author->getID()) && (mention.first != me.getID())) { output << "@" << mention.second << " "; } @@ -56,20 +95,12 @@ namespace twitter { return output.str(); } - tweet tweet::reply(std::string message, std::list media_ids) const - { - return _client.replyToTweet(message, _id, media_ids); - } - - bool tweet::isMyTweet() const - { - return *_author == _client.getUser(); - } - std::string tweet::getURL() const { + assert(_valid); + std::ostringstream urlstr; - urlstr << "https://twitter.com"; + urlstr << "https://twitter.com/"; urlstr << _author->getScreenName(); urlstr << "/statuses/"; urlstr << _id; -- cgit 1.4.1