mastodon-cpp  0.18.8
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 const 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 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...
 
const bool favourited () const
 Returns true if the user has favourited the status. More...
 
const uint_fast64_t favourites_count () const
 Returns the number of favourites. More...
 
const uint_fast64_t id () const
 Returns the ID of the status. More...
 
const 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...
 
const 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)
 Sets the language of the status. 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...
 
const bool muted () const
 Returns true if the user muted the conversation. More...
 
const bool pinned () const
 Returns true if the status is pinned. More...
 
const Status reblog () const
 Returns the reblogged Status. More...
 
const bool reblogged () const
 Returns true if the user has reblogged the status. More...
 
const uint_fast64_t reblogs_count () const
 Returns the number of reblogs for the status. More...
 
const 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...
 
const 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...
 
const 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...
 
const 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...
 
const uint_fast64_t get_uint64 (const string &key) const
 Returns the value of key as std::uint_fast64_t. More...
 
const double get_double (const string &key) const
 Returns the value of key as double. More...
 
const 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...
 
const void set (const string &key, const Json::Value &value)
 Sets the value of key. More...
 
const std::uint_fast64_t stouint64 (const string &str) const
 
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

◆ content() [1/2]

const string Status::content ( ) const

Returns content of status.

Since
before 0.11.0
83 {
84  return get_string("content");
85 }
const string get_string(const string &key) const
Returns the value of key as std::string.
Definition: entity.cpp:135

◆ content() [2/2]

Status Status::content ( const string &  content)

Sets content of status.

Since
0.17.0
88 {
89  set("content", Json::Value(content));
90  return *this;
91 }
const string content() const
Returns content of status.
Definition: status.cpp:82

◆ created_at()

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

Returns time of creation.

Since
before 0.11.0
78 {
79  return get_time_point("created_at");
80 }
const system_clock::time_point get_time_point(const string &key) const
Returns the value of key as time_point.
Definition: entity.cpp:192

◆ emojis()

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

Returns an array of emojis.

Since
before 0.11.0
94 {
95  const Json::Value node = get("emojis");
96  if (node.isArray())
97  {
98  std::vector<Easy::Emoji> vec;
99  for (const Json::Value &value : node)
100  {
101  vec.push_back(Easy::Emoji(value.toStyledString()));
102  }
103  return vec;
104  }
105 
106  return {};
107 }
Class to hold emojis.
Definition: emoji.hpp:40

◆ favourited()

const bool Status::favourited ( ) const

Returns true if the user has favourited the status.

Since
before 0.11.0
110 {
111  return get_bool("favourited");
112 }
const bool get_bool(const string &key) const
Returns the value of key as bool.
Definition: entity.cpp:177

◆ favourites_count()

const uint_fast64_t Status::favourites_count ( ) const

Returns the number of favourites.

Since
before 0.11.0
115 {
116  return get_uint64("favourites_count");
117 }
const uint_fast64_t get_uint64(const string &key) const
Returns the value of key as std::uint_fast64_t.
Definition: entity.cpp:149

◆ id()

const uint_fast64_t Status::id ( ) const

Returns the ID of the status.

Since
before 0.11.0
120 {
121  return stouint64(get_string("id"));
122 }
const string get_string(const string &key) const
Returns the value of key as std::string.
Definition: entity.cpp:135

◆ in_reply_to_account_id()

const uint_fast64_t Status::in_reply_to_account_id ( ) const

Returns the ID of the account it replies to.

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

◆ in_reply_to_id() [1/2]

const uint_fast64_t Status::in_reply_to_id ( ) const

Returns the ID of the status it replies to.

Since
before 0.11.0
125 {
126  return stouint64(get_string("in_reply_to_id"));
127 }
const string get_string(const string &key) const
Returns the value of key as std::string.
Definition: entity.cpp:135

◆ 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
130 {
131  set("in_reply_to_id", Json::Value(std::to_string(in_reply_to_id)));
132  return *this;
133 }
const uint_fast64_t in_reply_to_id() const
Returns the ID of the status it replies to.
Definition: status.cpp:124

◆ language() [1/2]

const string Status::language ( ) const

Returns the language of the status.

Since
before 0.11.0
141 {
142  return get_string("language");
143 }
const string get_string(const string &key) const
Returns the value of key as std::string.
Definition: entity.cpp:135

◆ language() [2/2]

Status Status::language ( const string &  language)

Sets the language of the status.

Since
0.17.0
146 {
147  set("language", Json::Value(language));
148  return *this;
149 }
const string language() const
Returns the language of the status.
Definition: status.cpp:140

◆ media_attachments() [1/2]

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

Returns the attachments.

Since
before 0.11.0
152 {
153  const Json::Value node = get("media_attachments");
154  if (node.isArray())
155  {
156  std::vector<Easy::Attachment> vec;
157  for (const Json::Value &value : node)
158  {
159  vec.push_back(Easy::Attachment(value.toStyledString()));
160  }
161  return vec;
162  }
163 
164  return {};
165 }
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
169 {
170  // FIXME: Needs writable Easy::Attachment()
171  Json::Value jsonarray(Json::arrayValue);
172 
173  for (const Attachment &att : media_attachments)
174  {
175  jsonarray.append(att.to_object());
176  }
177  set("media_attachments", jsonarray);
178  return *this;
179 }
Class to hold attachments.
Definition: attachment.hpp:44
const std::vector< Attachment > media_attachments() const
Returns the attachments.
Definition: status.cpp:151

◆ mentions()

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

Returns the mentions.

Since
before 0.11.0
182 {
183  const Json::Value node = get("mentions");
184  if (node.isArray())
185  {
186  std::vector<Easy::Mention> vec;
187  for (const Json::Value &value : node)
188  {
189  vec.push_back(Easy::Mention(value.toStyledString()));
190  }
191  return vec;
192  }
193 
194  return {};
195 }
Class to hold mentions.
Definition: mention.hpp:43

◆ muted()

const bool Status::muted ( ) const

Returns true if the user muted the conversation.

Since
before 0.11.0
198 {
199  return get_bool("muted");
200 }
const bool get_bool(const string &key) const
Returns the value of key as bool.
Definition: entity.cpp:177

◆ pinned()

const bool Status::pinned ( ) const

Returns true if the status is pinned.

Since
before 0.11.0
203 {
204  return get_bool("pinned");
205 }
const bool get_bool(const string &key) const
Returns the value of key as bool.
Definition: entity.cpp:177

◆ reblog()

const Status Status::reblog ( ) const

Returns the reblogged Status.

Since
before 0.11.0
208 {
209  const Json::Value node = get("reblog");
210  if (node.isObject())
211  {
212  return Easy::Status(node.toStyledString());
213  }
214 
215  return Easy::Status();
216 }
Class to hold statuses.
Definition: status.hpp:57

◆ reblogged()

const bool Status::reblogged ( ) const

Returns true if the user has reblogged the status.

Since
before 0.11.0
219 {
220  return get_bool("reblogged");
221 }
const bool get_bool(const string &key) const
Returns the value of key as bool.
Definition: entity.cpp:177

◆ reblogs_count()

const uint_fast64_t Status::reblogs_count ( ) const

Returns the number of reblogs for the status.

Since
before 0.11.0
224 {
225  return get_uint64("reblogs_count");
226 }
const uint_fast64_t get_uint64(const string &key) const
Returns the value of key as std::uint_fast64_t.
Definition: entity.cpp:149

◆ sensitive() [1/2]

const bool Status::sensitive ( ) const

Returns true if the attachments should be hidden by default.

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

◆ sensitive() [2/2]

Status Status::sensitive ( const bool &  sensitive)

Sets sensitive flag for attachments.

Since
0.17.0
234 {
235  set("sensitive", Json::Value(sensitive));
236  return *this;
237 }
const bool sensitive() const
Returns true if the attachments should be hidden by default.
Definition: status.cpp:228

◆ spoiler_text() [1/2]

const string Status::spoiler_text ( ) const

Returns the spoiler text.

Since
before 0.11.0
240 {
241  return get_string("spoiler_text");
242 }
const string get_string(const string &key) const
Returns the value of key as std::string.
Definition: entity.cpp:135

◆ spoiler_text() [2/2]

Status Status::spoiler_text ( const string &  spoiler_text)

Sets the spoiler text.

Since
0.17.0
245 {
246  set("spoiler_text", Json::Value(spoiler_text));
247  return *this;
248 }
const string spoiler_text() const
Returns the spoiler text.
Definition: status.cpp:239

◆ tags()

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

Returns the tags.

Since
before 0.11.0
251 {
252  const Json::Value node = get("tags");
253  if (node.isArray())
254  {
255  std::vector<Easy::Tag> vec;
256  for (const Json::Value &value : node)
257  {
258  vec.push_back(Easy::Tag(value.toStyledString()));
259  }
260  return vec;
261  }
262 
263  return {};
264 }
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
267 {
268  return get_string("uri");
269 }
const string get_string(const string &key) const
Returns the value of key as std::string.
Definition: entity.cpp:135

◆ url()

const string Status::url ( ) const

Returns the URL to the status page.

Since
before 0.11.0
272 {
273  return get_string("url");
274 }
const string get_string(const string &key) const
Returns the value of key as std::string.
Definition: entity.cpp:135

◆ valid()

const 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 }
const bool check_valid(const std::vector< string > &attributes) const
Checks if an Entity is valid.
Definition: entity.cpp:70

◆ visibility() [1/2]

const Easy::visibility_type Status::visibility ( ) const

Returns the visibility of the status.

Since
before 0.11.0
277 {
278  const string strvisibility = get_string("visibility");
279  if (strvisibility.compare("public") == 0)
280  return visibility_type::Public;
281  else if (strvisibility.compare("unlisted") == 0)
282  return visibility_type::Unlisted;
283  else if (strvisibility.compare("private") == 0)
284  return visibility_type::Private;
285  else if (strvisibility.compare("direct") == 0)
286  return visibility_type::Direct;
287 
288  return visibility_type::Undefined;
289 }
const string get_string(const string &key) const
Returns the value of key as std::string.
Definition: entity.cpp:135

◆ visibility() [2/2]

Status Status::visibility ( const visibility_type visibility)

Sets the visibility of the status.

Since
0.17.0
292 {
293  switch (visibility)
294  {
295  case visibility_type::Direct:
296  set("visibility", "direct");
297  break;
298  case visibility_type::Private:
299  set("visibility", "private");
300  break;
301  case visibility_type::Unlisted:
302  set("visibility", "unlisted");
303  break;
304  case visibility_type::Public:
305  set("visibility", "public");
306  break;
307  default:
308  std::cerr << "WARNING: setting visibility to Undefined "
309  "has no effect.\n";
310  break;
311  };
312  return *this;
313 }
const visibility_type visibility() const
Returns the visibility of the status.
Definition: status.cpp:276

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