Added Easy::Status

This commit is contained in:
tastytea 2018-03-31 04:29:55 +02:00
parent 7e2c2b0359
commit d78c699955
Signed by: tastytea
GPG Key ID: 59346E0EA35C67E5
8 changed files with 440 additions and 13 deletions

View File

@ -1,6 +1,6 @@
cmake_minimum_required (VERSION 3.7)
project (mastodon-cpp
VERSION 0.7.11
VERSION 0.7.12
LANGUAGES CXX
)

View File

@ -114,20 +114,20 @@ const string Account::note_plain() const
return get_string("source.note");
}
const Easy::visibility Account::privacy() const
const Easy::visibility_type Account::privacy() const
{
const string strprivacy = get_string("source.privacy");
if (strprivacy.compare("public") == 0)
return visibility::Public;
return visibility_type::Public;
else if (strprivacy.compare("unlisted") == 0)
return visibility::Unlisted;
return visibility_type::Unlisted;
else if (strprivacy.compare("private") == 0)
return visibility::Private;
return visibility_type::Private;
else if (strprivacy.compare("direct") == 0)
return visibility::Direct;
return visibility_type::Direct;
ttdebug << "Could not get data: source.privacy\n";
return visibility::Undefined;
return visibility_type::Undefined;
}
const bool Account::sensitive() const

View File

@ -136,7 +136,7 @@ namespace Mastodon
/*!
* @brief Returns default privacy of new toots
*/
const visibility privacy() const;
const visibility_type privacy() const;
/*!
* @brief Returns if media is marked as sensitive by default

View File

@ -29,10 +29,10 @@ Application::Application()
const string Application::name() const
{
get_string("name");
return get_string("name");
}
const string Application::website() const
{
get_string("website");
return get_string("website");
}

View File

@ -48,7 +48,7 @@ public:
* The names begin with a capital letter because some of them
* are reserved keywords when written in all-lowercase.
*/
enum class visibility
enum class visibility_type
{
Direct,
Private,

230
src/easy/status.cpp Normal file
View File

@ -0,0 +1,230 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <jsoncpp/json/json.h>
#include "status.hpp"
#include "macros.hpp"
using namespace Mastodon;
using Status = Easy::Status;
Status::Status(const string &json)
: Entity(json)
{}
Status::Status()
: Entity()
{}
const Easy::Account Status::account() const
{
const Json::Value node = get("account");
if (node.isObject())
{
return Easy::Account(node.toStyledString());
}
ttdebug << "Could not get data: account\n";
return Easy::Account();
}
const Easy::Application Status::application() const
{
const Json::Value node = get("application");
if (node.isObject())
{
return Easy::Application(node.toStyledString());
}
ttdebug << "Could not get data: application\n";
return Easy::Application();
}
const system_clock::time_point Status::created_at() const
{
return get_time_point("created_at");
}
const string Status::content() const
{
return get_string("content");
}
const std::vector<Easy::Emoji> Status::emojis() const
{
const Json::Value node = get("emojis");
if (node.isArray())
{
std::vector<Easy::Emoji> vec;
for (const Json::Value &value : node)
{
vec.push_back(Easy::Emoji(value.toStyledString()));
}
return vec;
}
ttdebug << "Could not get data: emojis\n";
return {};
}
const bool Status::favourited() const
{
return get_bool("favourited");
}
const uint64_t Status::favourites_count() const
{
return get_uint64("favourites_count");
}
const uint64_t Status::id() const
{
return get_uint64("id");
}
const uint64_t Status::in_reply_to_id() const
{
return get_uint64("in_reply_to_id");
}
const uint64_t Status::in_reply_to_account_id() const
{
return get_uint64("in_reply_to_account_id");
}
const string Status::language() const
{
return get_string("language");
}
const std::vector<Easy::Attachment> Status::media_attachments() const
{
const Json::Value node = get("media_attachments");
if (node.isArray())
{
std::vector<Easy::Attachment> vec;
for (const Json::Value &value : node)
{
vec.push_back(Easy::Attachment(value.toStyledString()));
}
return vec;
}
ttdebug << "Could not get data: media_attachments\n";
return {};
}
const std::vector<Easy::Mention> Status::mentions() const
{
const Json::Value node = get("mentions");
if (node.isArray())
{
std::vector<Easy::Mention> vec;
for (const Json::Value &value : node)
{
vec.push_back(Easy::Mention(value.toStyledString()));
}
return vec;
}
ttdebug << "Could not get data: mentions\n";
return {};
}
const bool Status::muted() const
{
return get_bool("muted");
}
const bool Status::pinned() const
{
return get_bool("pinned");
}
const Easy::Status Status::reblog() const
{
const Json::Value node = get("reblog");
if (node.isObject())
{
return Easy::Status(node.toStyledString());
}
ttdebug << "Could not get data: reblog\n";
return Easy::Status();
}
const bool Status::reblogged() const
{
return get_bool("reblogged");
}
const uint64_t Status::reblogs_count() const
{
return get_uint64("reblogs_count");
}
const bool Status::sensitive() const
{
return get_bool("sensitive");
}
const string Status::spoiler_text() const
{
return get_string("spoiler_text");
}
const std::vector<Easy::Tag> Status::tags() const
{
const Json::Value node = get("tags");
if (node.isArray())
{
std::vector<Easy::Tag> vec;
for (const Json::Value &value : node)
{
vec.push_back(Easy::Tag(value.toStyledString()));
}
return vec;
}
ttdebug << "Could not get data: tags\n";
return {};
}
const string Status::uri() const
{
return get_string("uri");
}
const string Status::url() const
{
return get_string("url");
}
const Easy::visibility_type Status::visibility() const
{
const string strvisibility = get_string("visibility");
if (strvisibility.compare("public") == 0)
return visibility_type::Public;
else if (strvisibility.compare("unlisted") == 0)
return visibility_type::Unlisted;
else if (strvisibility.compare("private") == 0)
return visibility_type::Private;
else if (strvisibility.compare("direct") == 0)
return visibility_type::Direct;
ttdebug << "Could not get data: visibility\n";
return visibility_type::Undefined;
}

197
src/easy/status.hpp Normal file
View File

@ -0,0 +1,197 @@
/* This file is part of mastodon-cpp.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MASTODON_CPP_EASY_STATUS_HPP
#define MASTODON_CPP_EASY_STATUS_HPP
#include <string>
#include <cstdint>
#include <chrono>
#include <vector>
// If we are compiling mastodon-cpp, use another include path
#ifdef MASTODON_CPP
#include "mastodon-cpp.hpp"
#include "easy.hpp"
#include "account.hpp"
#include "emoji.hpp"
#include "attachment.hpp"
#include "mention.hpp"
#include "tag.hpp"
#include "application.hpp"
#else
#include <mastodon-cpp/mastodon-cpp.hpp>
#include <mastodon-cpp/easy.hpp>
#include <mastodon-cpp/account.hpp>
#include <mastodon-cpp/emoji.hpp>
#include <mastodon-cpp/attachment.hpp>
#include <mastodon-cpp/mention.hpp>
#include <mastodon-cpp/tag.hpp>
#include <mastodon-cpp/application.hpp>
#endif
using std::string;
using std::uint64_t;
using std::chrono::system_clock;
namespace Mastodon
{
/*!
* @brief Class to hold statuses
*/
class Easy::Status : public Easy::Entity
{
public:
/*!
* @brief Constructs a Status object from a JSON string.
*
* @param json JSON string
*/
explicit Status(const string &json);
/*!
* @brief Constructs an empty Status object.
*/
Status();
/*!
* @brief Returns an array of matched accounts
*/
const Account account() const;
/*!
* @brief Returns application from which the status was posted
*/
const Application application() const;
/*!
* @brief Returns time of creation
*/
const system_clock::time_point created_at() const;
/*!
* @brief Returns content of status
*/
const string content() const;
/*!
* @brief Returns an array of emojis
*/
const std::vector<Emoji> emojis() const;
/*!
* @brief Returns true if the user has favourited the status
*/
const bool favourited() const;
/*!
* @brief Returns the number of favourites
*/
const uint64_t favourites_count() const;
/*!
* @brief Returns the ID of the status
*/
const uint64_t id() const;
/*!
* @brief Returns the ID of the status it replies to
*/
const uint64_t in_reply_to_id() const;
/*!
* @brief Returns the ID of the account it replies to
*/
const uint64_t in_reply_to_account_id() const;
/*!
* @brief Returns the language of the status
*/
const string language() const;
/*!
* @brief Returns the attachments
*/
const std::vector<Attachment> media_attachments() const;
/*!
* @brief Returns the mentions
*/
const std::vector<Mention> mentions() const;
/*!
* @brief Returns true if the user muted the conversation
*/
const bool muted() const;
/*!
* @brief Returns true if the status is pinned
*/
const bool pinned() const;
/*!
* @brief Returns the reblogged Status
*/
const Status reblog() const;
/*!
* @brief Returns true if the user has reblogged the status
*/
const bool reblogged() const;
/*!
* @brief Returns the number of reblogs for the status
*/
const uint64_t reblogs_count() const;
/*!
* @brief Returns true if the attachments should be hidden by default
*/
const bool sensitive() const;
/*!
* @brief Returns the spoiler text
*/
const string spoiler_text() const;
/*!
* @brief Returns the tags
*/
const std::vector<Tag> tags() const;
/*!
* @brief Returns the Fediverse-unique resource ID
*/
const string uri() const;
/*!
* @brief Returns the URL to the status page
*/
const string url() const;
/*!
* @brief Returns the visibility of the status
*/
const visibility_type visibility() const;
/*!
* @brief Returns the
*/
};
}
#endif // MASTODON_CPP_EASY_STATUS_HPP

View File

@ -29,10 +29,10 @@ Tag::Tag()
const string Tag::name() const
{
get_string("name");
return get_string("name");
}
const string Tag::url() const
{
get_string("url");
return get_string("url");
}