From ac260cef3c8c035e3975a8c412553b25cb2b6c06 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Sun, 22 May 2016 21:25:29 -0400 Subject: Fixed retweet detection Because a retweet is a tweet referenced from another tweet, the current implementation dynamically allocates memory for the retweeted status and has to manually copy the pointed to data around. It's not a very pretty implementation and may get tweaked at some point soon. I don't like having to implement the big five. --- src/tweet.cpp | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 63 insertions(+), 2 deletions(-) (limited to 'src/tweet.cpp') diff --git a/src/tweet.cpp b/src/tweet.cpp index bf95bc0..2927018 100644 --- a/src/tweet.cpp +++ b/src/tweet.cpp @@ -17,7 +17,14 @@ namespace twitter { _id = _data.at("id"); _text = _data.at("text"); _author = user(_data.at("user").dump()); - _retweeted = _data.at("retweeted"); + + if (_data.find("retweeted_status") != _data.end()) + { + _is_retweet = true; + + std::string retweet = _data.at("retweeted_status").dump(); + _retweeted_status = new tweet(retweet); + } if (_data.find("entities") != _data.end()) { @@ -32,6 +39,53 @@ namespace twitter { } } + tweet::tweet(const tweet& other) + { + _valid = other._valid; + _id = other._id; + _text = other._text; + _author = other._author; + _is_retweet = other._is_retweet; + + if (_is_retweet) + { + _retweeted_status = new tweet(*other._retweeted_status); + } + + _mentions = other._mentions; + } + + tweet::tweet(tweet&& other) : tweet() + { + swap(*this, other); + } + + tweet::~tweet() + { + if (_is_retweet) + { + delete _retweeted_status; + } + } + + 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); + } + tweet_id tweet::getID() const { assert(_valid); @@ -57,7 +111,14 @@ namespace twitter { { assert(_valid); - return _retweeted; + return _is_retweet; + } + + tweet tweet::getRetweet() const + { + assert(_valid && _is_retweet); + + return *_retweeted_status; } std::vector> tweet::getMentions() const -- cgit 1.4.1