mastodon-cpp  0.20.0
Public Member Functions | List of all members
Mastodon::Easy::Status Class Reference

Class to hold statuses. More...

#include <status.hpp>

Inheritance diagram for Mastodon::Easy::Status:
Mastodon::Easy::Entity

Public Member Functions

 Status (const string &json)
 Constructs a Status object from a JSON string. More...
 
 Status ()
 Constructs an empty Status object. More...
 
virtual bool valid () const
 Returns true if the Entity holds valid data. More...
 
const Account account () const
 Returns an array of matched accounts. More...
 
const Application application () const
 Returns application from which the status was posted. More...
 
const Card card () const
 Returns card. More...
 
const system_clock::time_point created_at () const
 Returns time of creation. More...
 
const string content () const
 Returns content of status. More...
 
Status content (const string &content)
 Sets content of status. More...
 
const std::vector< Emojiemojis () const
 Returns an array of emojis. More...
 
bool favourited () const
 Returns true if the user has favourited the status. More...
 
uint_fast64_t favourites_count () const
 Returns the number of favourites. More...
 
uint_fast64_t id () const
 Returns the ID of the status. More...
 
uint_fast64_t in_reply_to_id () const
 Returns the ID of the status it replies to. More...
 
Status in_reply_to_id (const uint_fast64_t &in_reply_to_id)
 Sets the ID of the status it replies to. More...
 
uint_fast64_t in_reply_to_account_id () const
 Returns the ID of the account it replies to. More...
 
const string language () const
 Returns the language of the status. More...
 
Status language (const string &language)
 Overrides the language of the status (ISO 639-2) More...
 
const std::vector< Attachmentmedia_attachments () const
 Returns the attachments. More...
 
Status media_attachments (const std::vector< Attachment > &media_attachments)
 Sets the attachments. More...
 
const std::vector< Mentionmentions () const
 Returns the mentions. More...
 
bool muted () const
 Returns true if the user muted the conversation. More...
 
bool pinned () const
 Returns true if the status is pinned. More...
 
const Status reblog () const
 Returns the reblogged Status. More...
 
bool reblogged () const
 Returns true if the user has reblogged the status. More...
 
uint_fast64_t reblogs_count () const
 Returns the number of reblogs for the status. More...
 
uint_fast64_t replies_count () const
 Returns the number of replies for the status. More...
 
bool sensitive () const
 Returns true if the attachments should be hidden by default. More...
 
Status sensitive (const bool &sensitive)
 Sets sensitive flag for attachments. More...
 
const string spoiler_text () const
 Returns the spoiler text. More...
 
Status spoiler_text (const string &spoiler_text)
 Sets the spoiler text. More...
 
const std::vector< Tagtags () const
 Returns the tags. More...
 
const string uri () const
 Returns the Fediverse-unique resource ID. More...
 
const string url () const
 Returns the URL to the status page. More...
 
visibility_type visibility () const
 Returns the visibility of the status. More...
 
Status visibility (const visibility_type &visibility)
 Sets the visibility of the status. More...
 
- Public Member Functions inherited from Mastodon::Easy::Entity
 Entity (const string &json)
 Constructs an Entity object from a JSON string. More...
 
 Entity ()
 Constructs an empty Entity object. More...
 
void from_string (const string &json)
 Replaces the Entity with a new one from a JSON string. More...
 
const Json::Value to_object () const
 Returns the JSON object of the Entity. More...
 
const string error () const
 Returns error string sent by the server. More...
 
bool was_set () const
 Returns true if the last requested value was set, false if it was unset. More...
 

Additional Inherited Members

- Protected Member Functions inherited from Mastodon::Easy::Entity
const Json::Value get (const string &key) const
 Returns the value of key as Json::Value. More...
 
const string get_string (const string &key) const
 Returns the value of key as std::string. More...
 
uint_fast64_t get_uint64 (const string &key) const
 Returns the value of key as std::uint_fast64_t. More...
 
double get_double (const string &key) const
 Returns the value of key as double. More...
 
bool get_bool (const string &key) const
 Returns the value of key as bool. More...
 
const system_clock::time_point get_time_point (const string &key) const
 Returns the value of key as time_point. More...
 
const std::vector< string > get_vector (const string &key) const
 Returns the value of key as vector. More...
 
void set (const string &key, const Json::Value &value)
 Sets the value of key. More...
 
std::uint_fast64_t stouint64 (const string &str) const
 
bool check_valid (const std::vector< string > &attributes) const
 Checks if an Entity is valid. More...
 

Detailed Description

Class to hold statuses.

Since
before 0.11.0

Constructor & Destructor Documentation

◆ Status() [1/2]

Status::Status ( const string &  json)
explicit

Constructs a Status object from a JSON string.

Parameters
jsonJSON string
Since
before 0.11.0
25 : Entity(json)
26 {}
Entity()
Constructs an empty Entity object.
Definition: entity.cpp:65

◆ Status() [2/2]

Status::Status ( )

Constructs an empty Status object.

Since
before 0.11.0
29 : Entity()
30 {}
Entity()
Constructs an empty Entity object.
Definition: entity.cpp:65

Member Function Documentation

◆ account()

const Easy::Account Status::account ( ) const

Returns an array of matched accounts.

Since
before 0.11.0
56 {
57  const Json::Value node = get("account");
58  if (node.isObject())
59  {
60  return Easy::Account(node.toStyledString());
61  }
62 
63  return Easy::Account();
64 }
Class to hold accounts.
Definition: account.hpp:46

◆ application()

const Easy::Application Status::application ( ) const

Returns application from which the status was posted.

Since
before 0.11.0
67 {
68  const Json::Value node = get("application");
69  if (node.isObject())
70  {
71  return Easy::Application(node.toStyledString());
72  }
73 
74  return Easy::Application();
75 }
Class to hold applications.
Definition: application.hpp:40

◆ card()

const Easy::Card Status::card ( ) const

Returns card.

Since
0.19.0
78 {
79  const Json::Value node = get("card");
80  if (node.isObject())
81  {
82  return Easy::Card(node.toStyledString());
83  }
84 
85  return Easy::Card();
86 }
Class to hold cards.
Definition: card.hpp:42

◆ content() [1/2]

const string Status::content ( ) const

Returns content of status.

Since
before 0.11.0
94 {
95  return get_string("content");
96 }
const string get_string(const string &key) const
Returns the value of key as std::string.
Definition: entity.cpp:134

◆ content() [2/2]

Status Status::content ( const string &  content)

Sets content of status.

Since
0.17.0
99 {
100  set("content", Json::Value(content));
101  return *this;
102 }
const string content() const
Returns content of status.
Definition: status.cpp:93

◆ created_at()

const system_clock::time_point Status::created_at ( ) const

Returns time of creation.

Since
before 0.11.0
89 {
90  return get_time_point("created_at");
91 }
const system_clock::time_point get_time_point(const string &key) const
Returns the value of key as time_point.
Definition: entity.cpp:191

◆ emojis()

const std::vector< Easy::Emoji > Status::emojis ( ) const

Returns an array of emojis.

Since
before 0.11.0
105 {
106  const Json::Value node = get("emojis");
107  if (node.isArray())
108  {
109  std::vector<Easy::Emoji> vec;
110  for (const Json::Value &value : node)
111  {
112  vec.push_back(Easy::Emoji(value.toStyledString()));
113  }
114  return vec;
115  }
116 
117  return {};
118 }
Class to hold emojis.
Definition: emoji.hpp:40

◆ favourited()

bool Status::favourited ( ) const

Returns true if the user has favourited the status.

Since
before 0.11.0
121 {
122  return get_bool("favourited");
123 }
bool get_bool(const string &key) const
Returns the value of key as bool.
Definition: entity.cpp:176

◆ favourites_count()

uint_fast64_t Status::favourites_count ( ) const

Returns the number of favourites.

Since
before 0.11.0
126 {
127  return get_uint64("favourites_count");
128 }
uint_fast64_t get_uint64(const string &key) const
Returns the value of key as std::uint_fast64_t.
Definition: entity.cpp:148

◆ id()

uint_fast64_t Status::id ( ) const

Returns the ID of the status.

Since
before 0.11.0
131 {
132  return stouint64(get_string("id"));
133 }
const string get_string(const string &key) const
Returns the value of key as std::string.
Definition: entity.cpp:134

◆ in_reply_to_account_id()

uint_fast64_t Status::in_reply_to_account_id ( ) const

Returns the ID of the account it replies to.

Since
before 0.11.0
147 {
148  return stouint64(get_string("in_reply_to_account_id"));
149 }
const string get_string(const string &key) const
Returns the value of key as std::string.
Definition: entity.cpp:134

◆ in_reply_to_id() [1/2]

uint_fast64_t Status::in_reply_to_id ( ) const

Returns the ID of the status it replies to.

Since
before 0.11.0
136 {
137  return stouint64(get_string("in_reply_to_id"));
138 }
const string get_string(const string &key) const
Returns the value of key as std::string.
Definition: entity.cpp:134

◆ in_reply_to_id() [2/2]

Status Status::in_reply_to_id ( const uint_fast64_t &  in_reply_to_id)

Sets the ID of the status it replies to.

Since
0.17.0
141 {
142  set("in_reply_to_id", Json::Value(std::to_string(in_reply_to_id)));
143  return *this;
144 }
uint_fast64_t in_reply_to_id() const
Returns the ID of the status it replies to.
Definition: status.cpp:135

◆ language() [1/2]

const string Status::language ( ) const

Returns the language of the status.

Since
before 0.11.0
152 {
153  return get_string("language");
154 }
const string get_string(const string &key) const
Returns the value of key as std::string.
Definition: entity.cpp:134

◆ language() [2/2]

Status Status::language ( const string &  language)

Overrides the language of the status (ISO 639-2)

Since
0.17.0
157 {
158  set("language", Json::Value(language));
159  return *this;
160 }
const string language() const
Returns the language of the status.
Definition: status.cpp:151

◆ media_attachments() [1/2]

const std::vector< Easy::Attachment > Status::media_attachments ( ) const

Returns the attachments.

Since
before 0.11.0
163 {
164  const Json::Value node = get("media_attachments");
165  if (node.isArray())
166  {
167  std::vector<Easy::Attachment> vec;
168  for (const Json::Value &value : node)
169  {
170  vec.push_back(Easy::Attachment(value.toStyledString()));
171  }
172  return vec;
173  }
174 
175  return {};
176 }
Class to hold attachments.
Definition: attachment.hpp:44

◆ media_attachments() [2/2]

Status Status::media_attachments ( const std::vector< Attachment > &  media_attachments)

Sets the attachments.

Since
0.17.0
180 {
181  // FIXME: Needs writable Easy::Attachment()
182  Json::Value jsonarray(Json::arrayValue);
183 
184  for (const Attachment &att : media_attachments)
185  {
186  jsonarray.append(att.to_object());
187  }
188  set("media_attachments", jsonarray);
189  return *this;
190 }
Class to hold attachments.
Definition: attachment.hpp:44
const std::vector< Attachment > media_attachments() const
Returns the attachments.
Definition: status.cpp:162

◆ mentions()

const std::vector< Easy::Mention > Status::mentions ( ) const

Returns the mentions.

Since
before 0.11.0
193 {
194  const Json::Value node = get("mentions");
195  if (node.isArray())
196  {
197  std::vector<Easy::Mention> vec;
198  for (const Json::Value &value : node)
199  {
200  vec.push_back(Easy::Mention(value.toStyledString()));
201  }
202  return vec;
203  }
204 
205  return {};
206 }
Class to hold mentions.
Definition: mention.hpp:43

◆ muted()

bool Status::muted ( ) const

Returns true if the user muted the conversation.

Since
before 0.11.0
209 {
210  return get_bool("muted");
211 }
bool get_bool(const string &key) const
Returns the value of key as bool.
Definition: entity.cpp:176

◆ pinned()

bool Status::pinned ( ) const

Returns true if the status is pinned.

Since
before 0.11.0
214 {
215  return get_bool("pinned");
216 }
bool get_bool(const string &key) const
Returns the value of key as bool.
Definition: entity.cpp:176

◆ reblog()

const Status Status::reblog ( ) const

Returns the reblogged Status.

Since
before 0.11.0
219 {
220  const Json::Value node = get("reblog");
221  if (node.isObject())
222  {
223  return Easy::Status(node.toStyledString());
224  }
225 
226  return Easy::Status();
227 }
Class to hold statuses.
Definition: status.hpp:59

◆ reblogged()

bool Status::reblogged ( ) const

Returns true if the user has reblogged the status.

Since
before 0.11.0
230 {
231  return get_bool("reblogged");
232 }
bool get_bool(const string &key) const
Returns the value of key as bool.
Definition: entity.cpp:176

◆ reblogs_count()

uint_fast64_t Status::reblogs_count ( ) const

Returns the number of reblogs for the status.

Since
before 0.11.0
235 {
236  return get_uint64("reblogs_count");
237 }
uint_fast64_t get_uint64(const string &key) const
Returns the value of key as std::uint_fast64_t.
Definition: entity.cpp:148

◆ replies_count()

uint_fast64_t Status::replies_count ( ) const

Returns the number of replies for the status.

Since
0.19.0
240 {
241  return get_uint64("replies_count");
242 }
uint_fast64_t get_uint64(const string &key) const
Returns the value of key as std::uint_fast64_t.
Definition: entity.cpp:148

◆ sensitive() [1/2]

bool Status::sensitive ( ) const

Returns true if the attachments should be hidden by default.

Since
before 0.11.0
245 {
246  return get_bool("sensitive");
247 }
bool get_bool(const string &key) const
Returns the value of key as bool.
Definition: entity.cpp:176

◆ sensitive() [2/2]

Status Status::sensitive ( const bool &  sensitive)

Sets sensitive flag for attachments.

Since
0.17.0
250 {
251  set("sensitive", Json::Value(sensitive));
252  return *this;
253 }
bool sensitive() const
Returns true if the attachments should be hidden by default.
Definition: status.cpp:244

◆ spoiler_text() [1/2]

const string Status::spoiler_text ( ) const

Returns the spoiler text.

Since
before 0.11.0
256 {
257  return get_string("spoiler_text");
258 }
const string get_string(const string &key) const
Returns the value of key as std::string.
Definition: entity.cpp:134

◆ spoiler_text() [2/2]

Status Status::spoiler_text ( const string &  spoiler_text)

Sets the spoiler text.

Since
0.17.0
261 {
262  set("spoiler_text", Json::Value(spoiler_text));
263  return *this;
264 }
const string spoiler_text() const
Returns the spoiler text.
Definition: status.cpp:255

◆ tags()

const std::vector< Easy::Tag > Status::tags ( ) const

Returns the tags.

Since
before 0.11.0
267 {
268  const Json::Value node = get("tags");
269  if (node.isArray())
270  {
271  std::vector<Easy::Tag> vec;
272  for (const Json::Value &value : node)
273  {
274  vec.push_back(Easy::Tag(value.toStyledString()));
275  }
276  return vec;
277  }
278 
279  return {};
280 }
Class to hold tags.
Definition: tag.hpp:44

◆ uri()

const string Status::uri ( ) const

Returns the Fediverse-unique resource ID.

Since
before 0.11.0
283 {
284  return get_string("uri");
285 }
const string get_string(const string &key) const
Returns the value of key as std::string.
Definition: entity.cpp:134

◆ url()

const string Status::url ( ) const

Returns the URL to the status page.

Since
before 0.11.0
288 {
289  return get_string("url");
290 }
const string get_string(const string &key) const
Returns the value of key as std::string.
Definition: entity.cpp:134

◆ valid()

bool Status::valid ( ) const
virtual

Returns true if the Entity holds valid data.

Since
before 0.11.0 (virtual since 0.18.2)

Implements Mastodon::Easy::Entity.

33 {
34  const std::vector<string> attributes =
35  {{
36  "id",
37  "uri",
38  "account",
39  "content",
40  "created_at",
41  "emojis",
42  "reblogs_count",
43  "favourites_count",
44  "sensitive",
45  "spoiler_text",
46  "visibility",
47  "media_attachments",
48  "mentions",
49  "tags"
50  }};
51 
52  return Entity::check_valid(attributes);
53 }
bool check_valid(const std::vector< string > &attributes) const
Checks if an Entity is valid.
Definition: entity.cpp:69

◆ visibility() [1/2]

Easy::visibility_type Status::visibility ( ) const

Returns the visibility of the status.

Since
before 0.11.0
293 {
294  const string strvisibility = get_string("visibility");
295  if (strvisibility.compare("public") == 0)
296  return visibility_type::Public;
297  else if (strvisibility.compare("unlisted") == 0)
298  return visibility_type::Unlisted;
299  else if (strvisibility.compare("private") == 0)
300  return visibility_type::Private;
301  else if (strvisibility.compare("direct") == 0)
302  return visibility_type::Direct;
303 
304  return visibility_type::Undefined;
305 }
const string get_string(const string &key) const
Returns the value of key as std::string.
Definition: entity.cpp:134

◆ visibility() [2/2]

Status Status::visibility ( const visibility_type visibility)

Sets the visibility of the status.

Since
0.17.0
308 {
309  switch (visibility)
310  {
311  case visibility_type::Direct:
312  set("visibility", "direct");
313  break;
314  case visibility_type::Private:
315  set("visibility", "private");
316  break;
317  case visibility_type::Unlisted:
318  set("visibility", "unlisted");
319  break;
320  case visibility_type::Public:
321  set("visibility", "public");
322  break;
323  default:
324  std::cerr << "WARNING: setting visibility to Undefined "
325  "has no effect.\n";
326  break;
327  };
328  return *this;
329 }
visibility_type visibility() const
Returns the visibility of the status.
Definition: status.cpp:292

The documentation for this class was generated from the following files: