diff options
Diffstat (limited to 'src/tweet.h')
-rw-r--r-- | src/tweet.h | 122 |
1 files changed, 50 insertions, 72 deletions
diff --git a/src/tweet.h b/src/tweet.h index 71a27bd..23882e2 100644 --- a/src/tweet.h +++ b/src/tweet.h | |||
@@ -4,94 +4,72 @@ | |||
4 | #include <string> | 4 | #include <string> |
5 | #include <vector> | 5 | #include <vector> |
6 | #include <utility> | 6 | #include <utility> |
7 | #include <cassert> | ||
8 | #include <list> | ||
9 | #include <memory> | ||
10 | #include <ctime> | 7 | #include <ctime> |
8 | #include "../vendor/hkutil/hkutil/recptr.h" | ||
11 | #include "user.h" | 9 | #include "user.h" |
12 | 10 | ||
13 | namespace twitter { | 11 | namespace twitter { |
14 | 12 | ||
15 | class client; | ||
16 | |||
17 | typedef unsigned long long tweet_id; | 13 | typedef unsigned long long tweet_id; |
18 | 14 | ||
19 | class tweet { | 15 | class tweet { |
20 | public: | 16 | public: |
21 | 17 | ||
22 | tweet() {} | 18 | tweet(std::string data); |
23 | tweet(std::string data); | 19 | |
24 | 20 | tweet_id getID() const | |
25 | tweet(const tweet& other); | 21 | { |
26 | tweet(tweet&& other); | 22 | return _id; |
27 | 23 | } | |
28 | tweet& operator=(tweet other); | 24 | |
29 | 25 | std::string getText() const | |
30 | friend void swap(tweet& first, tweet& second); | 26 | { |
31 | 27 | return _text; | |
32 | tweet_id getID() const | 28 | } |
29 | |||
30 | const user& getAuthor() const | ||
31 | { | ||
32 | return *_author; | ||
33 | } | ||
34 | |||
35 | const std::time_t& getCreatedAt() const | ||
36 | { | ||
37 | return _created_at; | ||
38 | } | ||
39 | |||
40 | bool isRetweet() const | ||
41 | { | ||
42 | return _is_retweet; | ||
43 | } | ||
44 | |||
45 | const tweet& getRetweet() const | ||
46 | { | ||
47 | if (!_is_retweet) | ||
33 | { | 48 | { |
34 | assert(_valid); | 49 | throw std::logic_error("Tweet is not a retweet"); |
35 | |||
36 | return _id; | ||
37 | } | 50 | } |
38 | 51 | ||
39 | std::string getText() const | 52 | return *_retweeted_status; |
40 | { | 53 | } |
41 | assert(_valid); | ||
42 | 54 | ||
43 | return _text; | 55 | const std::vector<std::pair<user_id, std::string>>& getMentions() const |
44 | } | 56 | { |
45 | 57 | return _mentions; | |
46 | const user& getAuthor() const | 58 | } |
47 | { | ||
48 | assert(_valid); | ||
49 | |||
50 | return *_author; | ||
51 | } | ||
52 | |||
53 | const std::time_t& getCreatedAt() const | ||
54 | { | ||
55 | assert(_valid); | ||
56 | |||
57 | return _created_at; | ||
58 | } | ||
59 | |||
60 | bool isRetweet() const | ||
61 | { | ||
62 | assert(_valid); | ||
63 | |||
64 | return _is_retweet; | ||
65 | } | ||
66 | |||
67 | const tweet& getRetweet() const | ||
68 | { | ||
69 | assert(_valid && _is_retweet); | ||
70 | |||
71 | return *_retweeted_status; | ||
72 | } | ||
73 | |||
74 | const std::vector<std::pair<user_id, std::string>>& getMentions() const | ||
75 | { | ||
76 | assert(_valid); | ||
77 | |||
78 | return _mentions; | ||
79 | } | ||
80 | 59 | ||
81 | std::string generateReplyPrefill(const user& me) const; | 60 | std::string generateReplyPrefill(const user& me) const; |
82 | 61 | ||
83 | std::string getURL() const; | 62 | std::string getURL() const; |
84 | 63 | ||
85 | private: | 64 | private: |
86 | 65 | ||
87 | bool _valid = false; | 66 | tweet_id _id; |
88 | tweet_id _id; | 67 | std::string _text; |
89 | std::string _text; | 68 | hatkirby::recptr<user> _author; |
90 | std::unique_ptr<user> _author; | 69 | std::time_t _created_at; |
91 | std::time_t _created_at; | 70 | bool _is_retweet = false; |
92 | bool _is_retweet = false; | 71 | hatkirby::recptr<tweet> _retweeted_status; |
93 | std::unique_ptr<tweet> _retweeted_status; | 72 | std::vector<std::pair<user_id, std::string>> _mentions; |
94 | std::vector<std::pair<user_id, std::string>> _mentions; | ||
95 | }; | 73 | }; |
96 | 74 | ||
97 | }; | 75 | }; |