mastodon-cpp  0.101.1
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.
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 }
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
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 }
Class to hold applications.
Definition: application.hpp:42

◆ 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 }
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.
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:159

◆ 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 }
const string content() const
Returns content of status.
Definition: status.cpp:86

◆ created_at()

const Easy::time 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 get_time(const string &key) const
Returns the value of key as Easy::time.
Definition: entity.cpp:215

◆ 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 }
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
113 {
114  return get_bool("favourited");
115 }
bool get_bool(const string &key) const
Returns the value of key as bool.
Definition: entity.cpp:201

◆ 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:173

◆ 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:159

◆ 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:159

◆ 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:159

◆ 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 }
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:159

◆ 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 }
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 }
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
171 {
172  // FIXME: Needs writable Easy::Attachment()
173  Json::Value jsonarray(Json::arrayValue);
174 
175  for (const Attachment &att : media_attachments)
176  {
177  jsonarray.append(att.to_object());
178  }
179  set("media_attachments", jsonarray);
180  return *this;
181 }
Class to hold attachments.
Definition: attachment.hpp:46
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
184 {
185  const Json::Value node = get("mentions");
186  if (node.isArray())
187  {
188  std::vector<Easy::Mention> vec;
189  std::transform(node.begin(), node.end(), std::back_inserter(vec),
190  [](const Json::Value &value)
191  { return Easy::Mention(value); });
192  return vec;
193  }
194 
195  return {};
196 }
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
199 {
200  return get_bool("muted");
201 }
bool get_bool(const string &key) const
Returns the value of key as bool.
Definition: entity.cpp:201

◆ pinned()

bool Status::pinned ( ) const

Returns true if the status is pinned.

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

◆ reblog()

const Status Status::reblog ( ) const

Returns the reblogged Status.

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

◆ reblogs_count()

uint64_t Status::reblogs_count ( ) const

Returns the number of reblogs for the status.

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

◆ replies_count()

uint64_t Status::replies_count ( ) const

Returns the number of replies for the status.

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

◆ sensitive() [1/2]

bool Status::sensitive ( ) const

Returns true if the attachments should be hidden by default.

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

◆ sensitive() [2/2]

Status Status::sensitive ( const bool &  sensitive)

Sets sensitive flag for attachments.

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

◆ spoiler_text() [1/2]

const string Status::spoiler_text ( ) const

Returns the spoiler text.

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

◆ spoiler_text() [2/2]

Status Status::spoiler_text ( const string &  spoiler_text)

Sets the spoiler text.

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

◆ tags()

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

Returns the tags.

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

◆ url()

const string Status::url ( ) const

Returns the URL to the status page.

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

◆ 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  "reblogs_count",
36  "favourites_count",
37  "sensitive",
38  "spoiler_text",
39  "visibility",
40  "media_attachments",
41  "mentions",
42  "tags"
43  }};
44 
45  return Entity::check_valid(attributes);
46 }
bool check_valid(const std::vector< string > &attributes) const
Checks if an Entity is valid.
Definition: entity.cpp:94

◆ visibility() [1/2]

Easy::visibility_type Status::visibility ( ) const

Returns the visibility of the status.

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

◆ visibility() [2/2]

Status Status::visibility ( const visibility_type visibility)

Sets the visibility of the status.

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

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