diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2016-05-22 21:25:29 -0400 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2016-05-22 21:25:29 -0400 |
commit | ac260cef3c8c035e3975a8c412553b25cb2b6c06 (patch) | |
tree | ef4b7ab7f981d4c31b36b8146cc66d7ad2f723bf /src/tweet.cpp | |
parent | 62f6aae6c313b2a2a493c5147ec831a66eba01ff (diff) | |
download | libtwittercpp-ac260cef3c8c035e3975a8c412553b25cb2b6c06.tar.gz libtwittercpp-ac260cef3c8c035e3975a8c412553b25cb2b6c06.tar.bz2 libtwittercpp-ac260cef3c8c035e3975a8c412553b25cb2b6c06.zip |
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.
Diffstat (limited to 'src/tweet.cpp')
-rw-r--r-- | src/tweet.cpp | 65 |
1 files changed, 63 insertions, 2 deletions
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 { | |||
17 | _id = _data.at("id"); | 17 | _id = _data.at("id"); |
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 | |
21 | if (_data.find("retweeted_status") != _data.end()) | ||
22 | { | ||
23 | _is_retweet = true; | ||
24 | |||
25 | std::string retweet = _data.at("retweeted_status").dump(); | ||
26 | _retweeted_status = new tweet(retweet); | ||
27 | } | ||
21 | 28 | ||
22 | if (_data.find("entities") != _data.end()) | 29 | if (_data.find("entities") != _data.end()) |
23 | { | 30 | { |
@@ -32,6 +39,53 @@ namespace twitter { | |||
32 | } | 39 | } |
33 | } | 40 | } |
34 | 41 | ||
42 | tweet::tweet(const tweet& other) | ||
43 | { | ||
44 | _valid = other._valid; | ||
45 | _id = other._id; | ||
46 | _text = other._text; | ||
47 | _author = other._author; | ||
48 | _is_retweet = other._is_retweet; | ||
49 | |||
50 | if (_is_retweet) | ||
51 | { | ||
52 | _retweeted_status = new tweet(*other._retweeted_status); | ||
53 | } | ||
54 | |||
55 | _mentions = other._mentions; | ||
56 | } | ||
57 | |||
58 | tweet::tweet(tweet&& other) : tweet() | ||
59 | { | ||
60 | swap(*this, other); | ||
61 | } | ||
62 | |||
63 | tweet::~tweet() | ||
64 | { | ||
65 | if (_is_retweet) | ||
66 | { | ||
67 | delete _retweeted_status; | ||
68 | } | ||
69 | } | ||
70 | |||
71 | tweet& tweet::operator=(tweet other) | ||
72 | { | ||
73 | swap(*this, other); | ||
74 | |||
75 | return *this; | ||
76 | } | ||
77 | |||
78 | void swap(tweet& first, tweet& second) | ||
79 | { | ||
80 | std::swap(first._valid, second._valid); | ||
81 | std::swap(first._id, second._id); | ||
82 | std::swap(first._text, second._text); | ||
83 | std::swap(first._author, second._author); | ||
84 | std::swap(first._is_retweet, second._is_retweet); | ||
85 | std::swap(first._retweeted_status, second._retweeted_status); | ||
86 | std::swap(first._mentions, second._mentions); | ||
87 | } | ||
88 | |||
35 | tweet_id tweet::getID() const | 89 | tweet_id tweet::getID() const |
36 | { | 90 | { |
37 | assert(_valid); | 91 | assert(_valid); |
@@ -57,7 +111,14 @@ namespace twitter { | |||
57 | { | 111 | { |
58 | assert(_valid); | 112 | assert(_valid); |
59 | 113 | ||
60 | return _retweeted; | 114 | return _is_retweet; |
115 | } | ||
116 | |||
117 | tweet tweet::getRetweet() const | ||
118 | { | ||
119 | assert(_valid && _is_retweet); | ||
120 | |||
121 | return *_retweeted_status; | ||
61 | } | 122 | } |
62 | 123 | ||
63 | std::vector<std::pair<user_id, std::string>> tweet::getMentions() const | 124 | std::vector<std::pair<user_id, std::string>> tweet::getMentions() const |