mastodon-cpp  0.110.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

virtual bool valid () const override
 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 Easy::time_type 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...
 
uint64_t favourites_count () const
 Returns the number of favourites. More...
 
const string id () const
 Returns the ID of the status. More...
 
const string in_reply_to_id () const
 Returns the ID of the status it replies to. More...
 
Status in_reply_to_id (const string &in_reply_to_id)
 Sets the ID of the status it replies to. More...
 
const string 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...
 
uint64_t reblogs_count () const
 Returns the number of reblogs for the status. More...
 
uint64_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...
 
 Entity (const string &json)
 Constructs an Entity object from a JSON string. More...
 
 Entity (const Json::Value &object)
 Constructs an Entity object from a JSON object. More...
 
 Entity ()
 Constructs an empty Entity object. More...
 
- Public Member Functions inherited from Mastodon::Easy::Entity
 Entity (const string &json)
 Constructs an Entity object from a JSON string. More...
 
 Entity (const Json::Value &object)
 Constructs an Entity object from a JSON object. More...
 
 Entity ()
 Constructs an empty Entity object. More...
 
virtual ~Entity ()
 Destroys the object. More...
 
 operator const Json::Value () const
 
void from_string (const string &json)
 Replaces the Entity with a new one from a JSON string. More...
 
const string to_string () const
 Returns the JSON of the Entity as formatted string. More...
 
void from_object (const Json::Value &object)
 Replaces the Entity with a new one from a JSON object. 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...
 
uint64_t get_uint64 (const string &key) const
 Returns the value of key as std::uint64_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 Easy::time_type get_time (const string &key) const
 Returns the value of key as Easy::time. 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::uint64_t stouint64 (const string &str) const
 Returns value of str as uint64_t.
 
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
Examples
example01_get_public_timeline.cpp, and example02_stream.cpp.

Member Function Documentation

◆ account()

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

Returns an array of matched accounts.

Since
before 0.11.0
Examples
example01_get_public_timeline.cpp, and example02_stream.cpp.
49 {
50  const Json::Value node = get("account");
51  if (node.isObject())
52  {
53  return Easy::Account(node.toStyledString());
54  }
55 
56  return Easy::Account();
57 }
const Json::Value get(const string &key) const
Returns the value of key as Json::Value.
Definition: entity.cpp:133
Class to hold accounts.
Definition: account.hpp:42

◆ application()

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

Returns application from which the status was posted.

Since
before 0.11.0
60 {
61  const Json::Value node = get("application");
62  if (node.isObject())
63  {
64  return Easy::Application(node.toStyledString());
65  }
66 
67  return Easy::Application();
68 }
const Json::Value get(const string &key) const
Returns the value of key as Json::Value.
Definition: entity.cpp:133
Class to hold applications.
Definition: application.hpp:36

◆ card()

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

Returns card.

Since
0.19.0
71 {
72  const Json::Value node = get("card");
73  if (node.isObject())
74  {
75  return Easy::Card(node.toStyledString());
76  }
77 
78  return Easy::Card();
79 }
const Json::Value get(const string &key) const
Returns the value of key as Json::Value.
Definition: entity.cpp:133
Class to hold cards.
Definition: card.hpp:38

◆ content() [1/2]

const string Status::content ( ) const

Returns content of status.

Since
before 0.11.0
Examples
example01_get_public_timeline.cpp.
87 {
88  return get_string("content");
89 }
const string get_string(const string &key) const
Returns the value of key as std::string.
Definition: entity.cpp:174

◆ content() [2/2]

Status Status::content ( const string &  content)

Sets content of status.

Since
0.17.0
92 {
93  set("content", Json::Value(content));
94  return *this;
95 }
void set(const string &key, const Json::Value &value)
Sets the value of key.
Definition: entity.cpp:263
const string content() const
Returns content of status.
Definition: status.cpp:86

◆ created_at()

const Easy::time_type Status::created_at ( ) const

Returns time of creation.

Since
before 0.11.0
Examples
example02_stream.cpp.
82 {
83  return get_time("created_at");
84 }
const Easy::time_type get_time(const string &key) const
Returns the value of key as Easy::time.
Definition: entity.cpp:230

◆ emojis()

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

Returns an array of emojis.

Since
before 0.11.0
98 {
99  const Json::Value node = get("emojis");
100  if (node.isArray())
101  {
102  std::vector<Easy::Emoji> vec;
103  std::transform(node.begin(), node.end(), std::back_inserter(vec),
104  [](const Json::Value &value)
105  { return Easy::Emoji(value); });
106  return vec;
107  }
108 
109  return {};
110 }
const Json::Value get(const string &key) const
Returns the value of key as Json::Value.
Definition: entity.cpp:133
Class to hold emojis.
Definition: emoji.hpp:36

◆ Entity() [1/3]

Easy::Entity::Entity
explicit

Constructs an Entity object from a JSON string.

Parameters
jsonJSON string
Since
before 0.11.0
32 : _tree(Json::nullValue)
33 ,_was_set(false)
34 {
35  from_string(json);
36 }
void from_string(const string &json)
Replaces the Entity with a new one from a JSON string.
Definition: entity.cpp:56

◆ Entity() [2/3]

Easy::Entity::Entity
explicit

Constructs an Entity object from a JSON object.

Parameters
objectJSON object
Since
0.100.0
39 : _tree(object)
40 ,_was_set(false)
41 {}

◆ Entity() [3/3]

Easy::Entity::Entity

Constructs an empty Entity object.

Since
before 0.11.0
44 : _tree(Json::nullValue)
45 , _was_set(false)
46 {}

◆ favourited()

bool Status::favourited ( ) const

Returns true if the user has favourited the status.

Since
before 0.11.0
113 {
114  return get_bool("favourited");
115 }
bool get_bool(const string &key) const
Returns the value of key as bool.
Definition: entity.cpp:216

◆ favourites_count()

uint64_t Status::favourites_count ( ) const

Returns the number of favourites.

Since
before 0.11.0
118 {
119  return get_uint64("favourites_count");
120 }
uint64_t get_uint64(const string &key) const
Returns the value of key as std::uint64_t.
Definition: entity.cpp:188

◆ id()

const string Status::id ( ) const

Returns the ID of the status.

Since
before 0.11.0
123 {
124  return get_string("id");
125 }
const string get_string(const string &key) const
Returns the value of key as std::string.
Definition: entity.cpp:174

◆ in_reply_to_account_id()

const string Status::in_reply_to_account_id ( ) const

Returns the ID of the account it replies to.

Since
before 0.11.0
139 {
140  return get_string("in_reply_to_account_id");
141 }
const string get_string(const string &key) const
Returns the value of key as std::string.
Definition: entity.cpp:174

◆ in_reply_to_id() [1/2]

const string Status::in_reply_to_id ( ) const

Returns the ID of the status it replies to.

Since
before 0.11.0
128 {
129  return get_string("in_reply_to_id");
130 }
const string get_string(const string &key) const
Returns the value of key as std::string.
Definition: entity.cpp:174

◆ in_reply_to_id() [2/2]

Status Status::in_reply_to_id ( const string &  in_reply_to_id)

Sets the ID of the status it replies to.

Since
0.17.0
133 {
134  set("in_reply_to_id", Json::Value(in_reply_to_id));
135  return *this;
136 }
void set(const string &key, const Json::Value &value)
Sets the value of key.
Definition: entity.cpp:263
const string in_reply_to_id() const
Returns the ID of the status it replies to.
Definition: status.cpp:127

◆ language() [1/2]

const string Status::language ( ) const

Returns the language of the status.

Since
before 0.11.0
144 {
145  return get_string("language");
146 }
const string get_string(const string &key) const
Returns the value of key as std::string.
Definition: entity.cpp:174

◆ language() [2/2]

Status Status::language ( const string &  language)

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

Since
0.17.0
149 {
150  set("language", Json::Value(language));
151  return *this;
152 }
void set(const string &key, const Json::Value &value)
Sets the value of key.
Definition: entity.cpp:263
const string language() const
Returns the language of the status.
Definition: status.cpp:143

◆ media_attachments() [1/2]

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

Returns the attachments.

Since
before 0.11.0
155 {
156  const Json::Value node = get("media_attachments");
157  if (node.isArray())
158  {
159  std::vector<Easy::Attachment> vec;
160  std::transform(node.begin(), node.end(), std::back_inserter(vec),
161  [](const Json::Value &value)
162  { return Easy::Attachment(value); });
163  return vec;
164  }
165 
166  return {};
167 }
const Json::Value get(const string &key) const
Returns the value of key as Json::Value.
Definition: entity.cpp:133
Class to hold attachments.
Definition: attachment.hpp:40

◆ media_attachments() [2/2]

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

Sets the attachments.

Since
0.17.0
171 {
172  Json::Value jsonarray(Json::arrayValue);
173 
174  for (const Attachment &att : media_attachments)
175  {
176  jsonarray.append(att.to_object());
177  }
178  set("media_attachments", jsonarray);
179  return *this;
180 }
Class to hold attachments.
Definition: attachment.hpp:40
void set(const string &key, const Json::Value &value)
Sets the value of key.
Definition: entity.cpp:263
const std::vector< Attachment > media_attachments() const
Returns the attachments.
Definition: status.cpp:154

◆ mentions()

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

Returns the mentions.

Since
before 0.11.0
183 {
184  const Json::Value node = get("mentions");
185  if (node.isArray())
186  {
187  std::vector<Easy::Mention> vec;
188  std::transform(node.begin(), node.end(), std::back_inserter(vec),
189  [](const Json::Value &value)
190  { return Easy::Mention(value); });
191  return vec;
192  }
193 
194  return {};
195 }
const Json::Value get(const string &key) const
Returns the value of key as Json::Value.
Definition: entity.cpp:133
Class to hold mentions.
Definition: mention.hpp:39

◆ muted()

bool Status::muted ( ) const

Returns true if the user muted the conversation.

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

◆ pinned()

bool Status::pinned ( ) const

Returns true if the status is pinned.

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

◆ 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 }
const Json::Value get(const string &key) const
Returns the value of key as Json::Value.
Definition: entity.cpp:133
Class to hold statuses.
Definition: status.hpp:46

◆ reblogged()

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 }
bool get_bool(const string &key) const
Returns the value of key as bool.
Definition: entity.cpp:216

◆ reblogs_count()

uint64_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 }
uint64_t get_uint64(const string &key) const
Returns the value of key as std::uint64_t.
Definition: entity.cpp:188

◆ replies_count()

uint64_t Status::replies_count ( ) const

Returns the number of replies for the status.

Since
0.19.0
229 {
230  return get_uint64("replies_count");
231 }
uint64_t get_uint64(const string &key) const
Returns the value of key as std::uint64_t.
Definition: entity.cpp:188

◆ sensitive() [1/2]

bool Status::sensitive ( ) const

Returns true if the attachments should be hidden by default.

Since
before 0.11.0
234 {
235  return get_bool("sensitive");
236 }
bool get_bool(const string &key) const
Returns the value of key as bool.
Definition: entity.cpp:216

◆ sensitive() [2/2]

Status Status::sensitive ( const bool &  sensitive)

Sets sensitive flag for attachments.

Since
0.17.0
239 {
240  set("sensitive", Json::Value(sensitive));
241  return *this;
242 }
bool sensitive() const
Returns true if the attachments should be hidden by default.
Definition: status.cpp:233
void set(const string &key, const Json::Value &value)
Sets the value of key.
Definition: entity.cpp:263

◆ spoiler_text() [1/2]

const string Status::spoiler_text ( ) const

Returns the spoiler text.

Since
before 0.11.0
245 {
246  return get_string("spoiler_text");
247 }
const string get_string(const string &key) const
Returns the value of key as std::string.
Definition: entity.cpp:174

◆ spoiler_text() [2/2]

Status Status::spoiler_text ( const string &  spoiler_text)

Sets the spoiler text.

Since
0.17.0
250 {
251  set("spoiler_text", Json::Value(spoiler_text));
252  return *this;
253 }
void set(const string &key, const Json::Value &value)
Sets the value of key.
Definition: entity.cpp:263
const string spoiler_text() const
Returns the spoiler text.
Definition: status.cpp:244

◆ tags()

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

Returns the tags.

Since
before 0.11.0
256 {
257  const Json::Value node = get("tags");
258  if (node.isArray())
259  {
260  std::vector<Easy::Tag> vec;
261  std::transform(node.begin(), node.end(), std::back_inserter(vec),
262  [](const Json::Value &value)
263  { return Easy::Tag(value); });
264  return vec;
265  }
266 
267  return {};
268 }
const Json::Value get(const string &key) const
Returns the value of key as Json::Value.
Definition: entity.cpp:133
Class to hold tags.
Definition: tag.hpp:38

◆ uri()

const string Status::uri ( ) const

Returns the Fediverse-unique resource ID.

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

◆ url()

const string Status::url ( ) const

Returns the URL to the status page.

Since
before 0.11.0
Examples
example02_stream.cpp.
276 {
277  return get_string("url");
278 }
const string get_string(const string &key) const
Returns the value of key as std::string.
Definition: entity.cpp:174

◆ valid()

bool Status::valid ( ) const
overridevirtual

Returns true if the Entity holds valid data.

Since
before 0.11.0 (virtual since 0.18.2)

Implements Mastodon::Easy::Entity.

26 {
27  return Entity::check_valid(
28  {
29  "id",
30  "uri",
31  "account",
32  "content",
33  "created_at",
34  "emojis",
35  "replies_count",
36  "reblogs_count",
37  "favourites_count",
38  "sensitive",
39  "spoiler_text",
40  "visibility",
41  "media_attachments",
42  "mentions",
43  "tags",
44  "application"
45  });
46 }
bool check_valid(const std::vector< string > &attributes) const
Checks if an Entity is valid.
Definition: entity.cpp:102

◆ visibility() [1/2]

Easy::visibility_type Status::visibility ( ) const

Returns the visibility of the status.

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

◆ visibility() [2/2]

Status Status::visibility ( const visibility_type visibility)

Sets the visibility of the status.

Since
0.17.0
296 {
297  switch (visibility)
298  {
299  case visibility_type::Direct:
300  set("visibility", "direct");
301  break;
302  case visibility_type::Private:
303  set("visibility", "private");
304  break;
305  case visibility_type::Unlisted:
306  set("visibility", "unlisted");
307  break;
308  case visibility_type::Public:
309  set("visibility", "public");
310  break;
311  default:
312  std::cerr << "WARNING: setting visibility to Undefined "
313  "has no effect.\n";
314  break;
315  };
316  return *this;
317 }
void set(const string &key, const Json::Value &value)
Sets the value of key.
Definition: entity.cpp:263
visibility_type visibility() const
Returns the visibility of the status.
Definition: status.cpp:280

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