2018-03-21 16:45:52 +01:00
|
|
|
/* This file is part of mastodon-cpp.
|
|
|
|
* Copyright © 2018 tastytea <tastytea@tastytea.de>
|
2018-03-21 20:29:33 +01:00
|
|
|
*
|
2018-03-21 16:45:52 +01:00
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2018-03-22 00:33:36 +01:00
|
|
|
#include "account.hpp"
|
2018-03-21 16:45:52 +01:00
|
|
|
#include "macros.hpp"
|
|
|
|
|
|
|
|
using namespace Mastodon;
|
|
|
|
using Account = Easy::Account;
|
|
|
|
|
|
|
|
Account::Account(const string &json)
|
2018-03-22 00:33:36 +01:00
|
|
|
: Entity(json)
|
2018-03-25 22:46:38 +02:00
|
|
|
{}
|
2018-03-21 16:45:52 +01:00
|
|
|
|
2018-03-30 20:16:31 +02:00
|
|
|
Account::Account()
|
|
|
|
: Entity()
|
|
|
|
{}
|
|
|
|
|
2018-03-21 16:45:52 +01:00
|
|
|
const string Account::acct() const
|
|
|
|
{
|
2018-03-25 22:46:38 +02:00
|
|
|
return get_string("acct");
|
2018-03-21 16:45:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const string Account::avatar() const
|
|
|
|
{
|
2018-03-25 22:46:38 +02:00
|
|
|
return get_string("avatar");
|
2018-03-21 16:45:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const string Account::avatar_static() const
|
|
|
|
{
|
2018-03-25 22:46:38 +02:00
|
|
|
return get_string("avatar_static");
|
2018-03-21 16:45:52 +01:00
|
|
|
}
|
|
|
|
|
2018-06-11 01:44:41 +02:00
|
|
|
const bool Account::bot() const
|
|
|
|
{
|
|
|
|
return get_bool("bot");
|
|
|
|
}
|
|
|
|
|
2018-03-25 22:46:38 +02:00
|
|
|
const system_clock::time_point Account::created_at() const
|
2018-03-21 16:45:52 +01:00
|
|
|
{
|
2018-03-25 22:46:38 +02:00
|
|
|
return get_time_point("created_at");
|
2018-03-21 16:45:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const string Account::display_name() const
|
|
|
|
{
|
2018-03-25 22:46:38 +02:00
|
|
|
return get_string("display_name");
|
2018-03-21 16:45:52 +01:00
|
|
|
}
|
|
|
|
|
2018-06-12 03:05:12 +02:00
|
|
|
const std::vector<Account::fields_pair> Account::fields() const
|
|
|
|
{
|
|
|
|
const Json::Value &node = get("fields");
|
|
|
|
|
|
|
|
if (node.isArray())
|
|
|
|
{
|
|
|
|
std::vector<Account::fields_pair> vec;
|
|
|
|
for (const Json::Value &value : node)
|
|
|
|
{
|
|
|
|
vec.push_back(Account::fields_pair(value["name"].asString(),
|
|
|
|
value["value"].asString()));
|
|
|
|
}
|
|
|
|
return vec;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2018-03-31 19:43:15 +02:00
|
|
|
const std::uint_fast64_t Account::followers_count() const
|
2018-03-21 16:45:52 +01:00
|
|
|
{
|
2018-03-25 22:46:38 +02:00
|
|
|
return get_uint64("followers_count");
|
2018-03-21 16:45:52 +01:00
|
|
|
}
|
|
|
|
|
2018-03-31 19:43:15 +02:00
|
|
|
const std::uint_fast64_t Account::following_count() const
|
2018-03-21 16:45:52 +01:00
|
|
|
{
|
2018-03-25 22:46:38 +02:00
|
|
|
return get_uint64("following_count");
|
2018-03-21 16:45:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const string Account::header() const
|
|
|
|
{
|
2018-03-25 22:46:38 +02:00
|
|
|
return get_string("header");
|
2018-03-21 16:45:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const string Account::header_static() const
|
|
|
|
{
|
2018-03-25 22:46:38 +02:00
|
|
|
return get_string("header_static");
|
2018-03-21 16:45:52 +01:00
|
|
|
}
|
|
|
|
|
2018-03-31 19:43:15 +02:00
|
|
|
const std::uint_fast64_t Account::id() const
|
2018-03-21 16:45:52 +01:00
|
|
|
{
|
2018-05-11 06:12:09 +02:00
|
|
|
return stouint64(get_string("id"));
|
2018-03-21 16:45:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const bool Account::locked() const
|
|
|
|
{
|
2018-03-25 22:46:38 +02:00
|
|
|
return get_bool("locked");
|
2018-03-21 16:45:52 +01:00
|
|
|
}
|
|
|
|
|
2018-03-21 20:29:33 +01:00
|
|
|
const bool Account::has_moved() const
|
|
|
|
{
|
2018-03-25 22:46:38 +02:00
|
|
|
if (get("moved").isObject())
|
2018-03-21 20:29:33 +01:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Account Account::moved() const
|
|
|
|
{
|
|
|
|
if (has_moved())
|
|
|
|
{
|
2018-03-21 23:28:48 +01:00
|
|
|
// TODO: Find an account with moved-node and test
|
2018-03-25 22:46:38 +02:00
|
|
|
return Account(get("moved").toStyledString());
|
2018-03-21 20:29:33 +01:00
|
|
|
}
|
|
|
|
|
2018-03-30 20:16:31 +02:00
|
|
|
return Account();
|
2018-03-21 20:29:33 +01:00
|
|
|
}
|
|
|
|
|
2018-03-21 16:45:52 +01:00
|
|
|
const string Account::note() const
|
|
|
|
{
|
2018-03-25 22:46:38 +02:00
|
|
|
return get_string("source.note");
|
2018-03-21 16:45:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const string Account::note_plain() const
|
|
|
|
{
|
2018-03-25 22:46:38 +02:00
|
|
|
return get_string("source.note");
|
2018-03-21 16:45:52 +01:00
|
|
|
}
|
|
|
|
|
2018-03-31 04:29:55 +02:00
|
|
|
const Easy::visibility_type Account::privacy() const
|
2018-03-21 16:45:52 +01:00
|
|
|
{
|
2018-03-25 22:46:38 +02:00
|
|
|
const string strprivacy = get_string("source.privacy");
|
|
|
|
if (strprivacy.compare("public") == 0)
|
2018-03-31 04:29:55 +02:00
|
|
|
return visibility_type::Public;
|
2018-03-25 22:46:38 +02:00
|
|
|
else if (strprivacy.compare("unlisted") == 0)
|
2018-03-31 04:29:55 +02:00
|
|
|
return visibility_type::Unlisted;
|
2018-03-25 22:46:38 +02:00
|
|
|
else if (strprivacy.compare("private") == 0)
|
2018-03-31 04:29:55 +02:00
|
|
|
return visibility_type::Private;
|
2018-03-25 22:46:38 +02:00
|
|
|
else if (strprivacy.compare("direct") == 0)
|
2018-03-31 04:29:55 +02:00
|
|
|
return visibility_type::Direct;
|
2018-03-21 16:45:52 +01:00
|
|
|
|
2018-03-31 00:12:34 +02:00
|
|
|
ttdebug << "Could not get data: source.privacy\n";
|
2018-03-31 04:29:55 +02:00
|
|
|
return visibility_type::Undefined;
|
2018-03-21 16:45:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const bool Account::sensitive() const
|
|
|
|
{
|
2018-03-25 22:46:38 +02:00
|
|
|
return get_bool("source.sensitive");
|
2018-03-21 16:45:52 +01:00
|
|
|
}
|
|
|
|
|
2018-03-31 19:43:15 +02:00
|
|
|
const std::uint_fast64_t Account::statuses_count() const
|
2018-03-21 16:45:52 +01:00
|
|
|
{
|
2018-03-25 22:46:38 +02:00
|
|
|
return get_uint64("statuses_count");
|
2018-03-21 16:45:52 +01:00
|
|
|
}
|
|
|
|
|
2018-03-31 05:02:03 +02:00
|
|
|
const string Account::url() const
|
|
|
|
{
|
|
|
|
return get_string("url");
|
|
|
|
}
|
|
|
|
|
2018-03-21 16:45:52 +01:00
|
|
|
const string Account::username() const
|
|
|
|
{
|
2018-03-25 22:46:38 +02:00
|
|
|
return get_string("username");
|
2018-03-21 16:45:52 +01:00
|
|
|
}
|