mastodon-cpp  0.104.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 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 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 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.
51 {
52  const Json::Value node = get("account");
53  if (node.isObject())
54  {
55  return Easy::Account(node.toStyledString());
56  }
57 
58  return Easy::Account();
59 }
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
62 {
63  const Json::Value node = get("application");
64  if (node.isObject())
65  {
66  return Easy::Application(node.toStyledString());
67  }
68 
69  return Easy::Application();
70 }
Class to hold applications.
Definition: application.hpp:42

◆ card()

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

Returns card.

Since
0.19.0
73 {
74  const Json::Value node = get("card");
75  if (node.isObject())
76  {
77  return Easy::Card(node.toStyledString());
78  }
79 
80  return Easy::Card();
81 }
Class to hold cards.
Definition: card.hpp:44

◆ content() [1/2]

const string Status::content ( ) const

Returns content of status.

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

◆ content() [2/2]

Status Status::content ( const string &  content)

Sets content of status.

Since
0.17.0
94 {
95  set("content", Json::Value(content));
96  return *this;
97 }
const string content() const
Returns content of status.
Definition: status.cpp:88

◆ created_at()

const Easy::time Status::created_at ( ) const

Returns time of creation.

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

◆ emojis()

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

Returns an array of emojis.

Since
before 0.11.0
100 {
101  const Json::Value node = get("emojis");
102  if (node.isArray())
103  {
104  std::vector<Easy::Emoji> vec;
105  std::transform(node.begin(), node.end(), std::back_inserter(vec),
106  [](const Json::Value &value)
107  { return Easy::Emoji(value); });
108  return vec;
109  }
110 
111  return {};
112 }
Class to hold emojis.
Definition: emoji.hpp:42

◆ Entity() [1/3]

Easy::Entity::Entity
explicit

Constructs an Entity object from a JSON string.

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

◆ Entity() [2/3]

Easy::Entity::Entity
explicit

Constructs an Entity object from a JSON object.

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

◆ Entity() [3/3]

Easy::Entity::Entity

Constructs an empty Entity object.

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

◆ favourited()

bool Status::favourited ( ) const

Returns true if the user has favourited the status.

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

◆ favourites_count()

uint64_t Status::favourites_count ( ) const

Returns the number of favourites.

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

◆ id()

const string Status::id ( ) const

Returns the ID of the status.

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

◆ 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
141 {
142  return get_string("in_reply_to_account_id");
143 }
const string get_string(const string &key) const
Returns the value of key as std::string.
Definition: entity.cpp:173

◆ 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
130 {
131  return get_string("in_reply_to_id");
132 }
const string get_string(const string &key) const
Returns the value of key as std::string.
Definition: entity.cpp:173

◆ 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
135 {
136  set("in_reply_to_id", Json::Value(in_reply_to_id));
137  return *this;
138 }
const string in_reply_to_id() const
Returns the ID of the status it replies to.
Definition: status.cpp:129

◆ language() [1/2]

const string Status::language ( ) const

Returns the language of the status.

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

◆ language() [2/2]

Status Status::language ( const string &  language)

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

Since
0.17.0
151 {
152  set("language", Json::Value(language));
153  return *this;
154 }
const string language() const
Returns the language of the status.
Definition: status.cpp:145

◆ media_attachments() [1/2]

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

Returns the attachments.

Since
before 0.11.0
157 {
158  const Json::Value node = get("media_attachments");
159  if (node.isArray())
160  {
161  std::vector<Easy::Attachment> vec;
162  std::transform(node.begin(), node.end(), std::back_inserter(vec),
163  [](const Json::Value &value)
164  { return Easy::Attachment(value); });
165  return vec;
166  }
167 
168  return {};
169 }
Class to hold attachments.
Definition: attachment.hpp:46

◆ media_attachments() [2/2]

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

Sets the attachments.

Since
0.17.0
173 {
174  // FIXME: Needs writable Easy::Attachment()
175  Json::Value jsonarray(Json::arrayValue);
176 
177  for (const Attachment &att : media_attachments)
178  {
179  jsonarray.append(att.to_object());
180  }
181  set("media_attachments", jsonarray);
182  return *this;
183 }
Class to hold attachments.
Definition: attachment.hpp:46
const std::vector< Attachment > media_attachments() const
Returns the attachments.
Definition: status.cpp:156

◆ mentions()

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

Returns the mentions.

Since
before 0.11.0
186 {
187  const Json::Value node = get("mentions");
188  if (node.isArray())
189  {
190  std::vector<Easy::Mention> vec;
191  std::transform(node.begin(), node.end(), std::back_inserter(vec),
192  [](const Json::Value &value)
193  { return Easy::Mention(value); });
194  return vec;
195  }
196 
197  return {};
198 }
Class to hold mentions.
Definition: mention.hpp:45

◆ muted()

bool Status::muted ( ) const

Returns true if the user muted the conversation.

Since
before 0.11.0
201 {
202  return get_bool("muted");
203 }
bool get_bool(const string &key) const
Returns the value of key as bool.
Definition: entity.cpp:215

◆ pinned()

bool Status::pinned ( ) const

Returns true if the status is pinned.

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

◆ reblog()

const Status Status::reblog ( ) const

Returns the reblogged Status.

Since
before 0.11.0
211 {
212  const Json::Value node = get("reblog");
213  if (node.isObject())
214  {
215  return Easy::Status(node.toStyledString());
216  }
217 
218  return Easy::Status();
219 }
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
222 {
223  return get_bool("reblogged");
224 }
bool get_bool(const string &key) const
Returns the value of key as bool.
Definition: entity.cpp:215

◆ reblogs_count()

uint64_t Status::reblogs_count ( ) const

Returns the number of reblogs for the status.

Since
before 0.11.0
227 {
228  return get_uint64("reblogs_count");
229 }
uint64_t get_uint64(const string &key) const
Returns the value of key as std::uint64_t.
Definition: entity.cpp:187

◆ replies_count()

uint64_t Status::replies_count ( ) const

Returns the number of replies for the status.

Since
0.19.0
232 {
233  return get_uint64("replies_count");
234 }
uint64_t get_uint64(const string &key) const
Returns the value of key as std::uint64_t.
Definition: entity.cpp:187

◆ sensitive() [1/2]

bool Status::sensitive ( ) const

Returns true if the attachments should be hidden by default.

Since
before 0.11.0
237 {
238  return get_bool("sensitive");
239 }
bool get_bool(const string &key) const
Returns the value of key as bool.
Definition: entity.cpp:215

◆ sensitive() [2/2]

Status Status::sensitive ( const bool &  sensitive)

Sets sensitive flag for attachments.

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

◆ spoiler_text() [1/2]

const string Status::spoiler_text ( ) const

Returns the spoiler text.

Since
before 0.11.0
248 {
249  return get_string("spoiler_text");
250 }
const string get_string(const string &key) const
Returns the value of key as std::string.
Definition: entity.cpp:173

◆ spoiler_text() [2/2]

Status Status::spoiler_text ( const string &  spoiler_text)

Sets the spoiler text.

Since
0.17.0
253 {
254  set("spoiler_text", Json::Value(spoiler_text));
255  return *this;
256 }
const string spoiler_text() const
Returns the spoiler text.
Definition: status.cpp:247

◆ tags()

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

Returns the tags.

Since
before 0.11.0
259 {
260  const Json::Value node = get("tags");
261  if (node.isArray())
262  {
263  std::vector<Easy::Tag> vec;
264  std::transform(node.begin(), node.end(), std::back_inserter(vec),
265  [](const Json::Value &value)
266  { return Easy::Tag(value); });
267  return vec;
268  }
269 
270  return {};
271 }
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
274 {
275  return get_string("uri");
276 }
const string get_string(const string &key) const
Returns the value of key as std::string.
Definition: entity.cpp:173

◆ url()

const string Status::url ( ) const

Returns the URL to the status page.

Since
before 0.11.0
Examples:
example02_stream.cpp.
279 {
280  return get_string("url");
281 }
const string get_string(const string &key) const
Returns the value of key as std::string.
Definition: entity.cpp:173

◆ 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  const std::vector<string> attributes =
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 
47  return Entity::check_valid(attributes);
48 }
bool check_valid(const std::vector< string > &attributes) const
Checks if an Entity is valid.
Definition: entity.cpp:101

◆ visibility() [1/2]

Easy::visibility_type Status::visibility ( ) const

Returns the visibility of the status.

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

◆ visibility() [2/2]

Status Status::visibility ( const visibility_type visibility)

Sets the visibility of the status.

Since
0.17.0
299 {
300  switch (visibility)
301  {
302  case visibility_type::Direct:
303  set("visibility", "direct");
304  break;
305  case visibility_type::Private:
306  set("visibility", "private");
307  break;
308  case visibility_type::Unlisted:
309  set("visibility", "unlisted");
310  break;
311  case visibility_type::Public:
312  set("visibility", "public");
313  break;
314  default:
315  std::cerr << "WARNING: setting visibility to Undefined "
316  "has no effect.\n";
317  break;
318  };
319  return *this;
320 }
visibility_type visibility() const
Returns the visibility of the status.
Definition: status.cpp:283

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