2018-03-21 16:45:52 +01:00
|
|
|
/* This file is part of mastodon-cpp.
|
2019-03-20 06:15:43 +01:00
|
|
|
* Copyright © 2018, 2019 tastytea <tastytea@tastytea.de>
|
2019-03-29 14:44:39 +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/>.
|
|
|
|
*/
|
|
|
|
|
2019-03-30 23:42:06 +01:00
|
|
|
#include <algorithm>
|
2018-03-22 00:33:36 +01:00
|
|
|
#include "account.hpp"
|
2019-02-22 11:35:06 +01:00
|
|
|
#include "debug.hpp"
|
2019-05-01 00:57:00 +02:00
|
|
|
#include "easy/easy.hpp"
|
2018-03-21 16:45:52 +01:00
|
|
|
|
|
|
|
using namespace Mastodon;
|
|
|
|
using Account = Easy::Account;
|
|
|
|
|
2018-12-04 11:26:28 +01:00
|
|
|
bool Account::valid() const
|
2018-07-14 11:44:30 +02:00
|
|
|
{
|
2019-04-25 14:53:44 +02:00
|
|
|
return Entity::check_valid(
|
|
|
|
{
|
|
|
|
"id",
|
|
|
|
"username",
|
|
|
|
"acct",
|
|
|
|
"display_name",
|
|
|
|
"locked",
|
|
|
|
"created_at",
|
|
|
|
"followers_count",
|
|
|
|
"following_count",
|
|
|
|
"statuses_count",
|
|
|
|
"note",
|
|
|
|
"url",
|
|
|
|
"avatar",
|
|
|
|
"avatar_static",
|
|
|
|
"header",
|
|
|
|
"header_static",
|
|
|
|
"emojis"
|
|
|
|
});
|
2018-07-14 11:44:30 +02:00
|
|
|
}
|
|
|
|
|
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-12-04 11:26:28 +01:00
|
|
|
bool Account::bot() const
|
2018-06-11 01:44:41 +02:00
|
|
|
{
|
|
|
|
return get_bool("bot");
|
|
|
|
}
|
|
|
|
|
2019-05-13 21:26:55 +02:00
|
|
|
const Easy::time_type Account::created_at() const
|
2018-03-21 16:45:52 +01:00
|
|
|
{
|
2019-03-29 14:44:39 +01:00
|
|
|
return get_time("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
|
|
|
}
|
|
|
|
|
2019-05-01 00:57:00 +02:00
|
|
|
const std::vector<Easy::Emoji> Account::emojis()
|
2018-06-12 03:05:12 +02:00
|
|
|
{
|
2019-05-01 00:57:00 +02:00
|
|
|
const Json::Value &node = get("emojis");
|
2018-06-12 03:05:12 +02:00
|
|
|
|
|
|
|
if (node.isArray())
|
|
|
|
{
|
2019-05-01 00:57:00 +02:00
|
|
|
std::vector<Easy::Emoji> vec;
|
2019-03-30 23:42:06 +01:00
|
|
|
std::transform(node.begin(), node.end(), std::back_inserter(vec),
|
2019-03-30 23:49:08 +01:00
|
|
|
[](const Json::Value &value)
|
2019-05-01 00:57:00 +02:00
|
|
|
{
|
|
|
|
return Easy::Emoji(value);
|
|
|
|
});
|
2018-06-12 03:05:12 +02:00
|
|
|
return vec;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2019-05-13 21:26:55 +02:00
|
|
|
const vector<Easy::account_field_type> Account::fields() const
|
2018-09-16 02:45:24 +02:00
|
|
|
{
|
2019-05-01 00:57:00 +02:00
|
|
|
const Json::Value &node = get("fields");
|
2018-09-16 02:45:24 +02:00
|
|
|
|
2019-05-01 00:57:00 +02:00
|
|
|
if (node.isArray())
|
2018-09-16 02:45:24 +02:00
|
|
|
{
|
2019-05-13 21:26:55 +02:00
|
|
|
vector<Easy::account_field_type> vec;
|
2019-05-01 00:57:00 +02:00
|
|
|
std::transform(node.begin(), node.end(), std::back_inserter(vec),
|
|
|
|
[](const Json::Value &value)
|
|
|
|
{
|
|
|
|
return Easy::account_field_type(
|
|
|
|
{
|
|
|
|
value["name"].asString(),
|
|
|
|
value["value"].asString(),
|
|
|
|
Easy::string_to_time(
|
|
|
|
value["verified_at"].asString())
|
|
|
|
});
|
|
|
|
});
|
|
|
|
return vec;
|
2018-09-16 02:45:24 +02:00
|
|
|
}
|
2019-05-01 00:57:00 +02:00
|
|
|
|
|
|
|
return {};
|
2018-09-16 02:45:24 +02:00
|
|
|
}
|
|
|
|
|
2019-02-22 08:29:54 +01:00
|
|
|
std::uint64_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
|
|
|
}
|
|
|
|
|
2019-02-22 08:29:54 +01:00
|
|
|
std::uint64_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
|
|
|
}
|
|
|
|
|
2019-01-27 03:44:08 +01:00
|
|
|
const string Account::id() const
|
2018-03-21 16:45:52 +01:00
|
|
|
{
|
2019-01-27 03:44:08 +01:00
|
|
|
return get_string("id");
|
2018-03-21 16:45:52 +01:00
|
|
|
}
|
|
|
|
|
2018-12-04 11:26:28 +01:00
|
|
|
bool Account::locked() const
|
2018-03-21 16:45:52 +01:00
|
|
|
{
|
2018-03-25 22:46:38 +02:00
|
|
|
return get_bool("locked");
|
2018-03-21 16:45:52 +01:00
|
|
|
}
|
|
|
|
|
2018-12-04 11:26:28 +01:00
|
|
|
bool Account::has_moved() const
|
2018-03-21 20:29:33 +01:00
|
|
|
{
|
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())
|
|
|
|
{
|
2019-05-01 00:57:00 +02:00
|
|
|
return Account(get("moved"));
|
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-09-16 02:45:24 +02:00
|
|
|
return get_string("note");
|
|
|
|
}
|
|
|
|
|
2018-12-04 11:26:28 +01:00
|
|
|
Easy::visibility_type Account::privacy() const
|
2018-03-21 16:45:52 +01:00
|
|
|
{
|
2019-05-01 12:43:02 +02:00
|
|
|
const string strprivacy = get_string("privacy");
|
2019-05-01 00:57:00 +02:00
|
|
|
if (strprivacy == "public")
|
2018-03-31 04:29:55 +02:00
|
|
|
return visibility_type::Public;
|
2019-05-01 00:57:00 +02:00
|
|
|
else if (strprivacy == "unlisted")
|
2018-03-31 04:29:55 +02:00
|
|
|
return visibility_type::Unlisted;
|
2019-05-01 00:57:00 +02:00
|
|
|
else if (strprivacy == "private")
|
2018-03-31 04:29:55 +02:00
|
|
|
return visibility_type::Private;
|
2019-05-01 00:57:00 +02:00
|
|
|
else if (strprivacy == "direct")
|
2018-03-31 04:29:55 +02:00
|
|
|
return visibility_type::Direct;
|
2018-03-21 16:45:52 +01:00
|
|
|
|
2018-03-31 04:29:55 +02:00
|
|
|
return visibility_type::Undefined;
|
2018-03-21 16:45:52 +01:00
|
|
|
}
|
|
|
|
|
2018-12-04 11:26:28 +01:00
|
|
|
bool Account::sensitive() const
|
2018-03-21 16:45:52 +01:00
|
|
|
{
|
2018-03-25 22:46:38 +02:00
|
|
|
return get_bool("source.sensitive");
|
2018-03-21 16:45:52 +01:00
|
|
|
}
|
|
|
|
|
2019-05-01 00:57:00 +02:00
|
|
|
const Account::Source Account::source() const
|
|
|
|
{
|
|
|
|
return Account::Source(get("source"));
|
|
|
|
}
|
|
|
|
|
|
|
|
std::uint64_t Account::statuses_count() const
|
|
|
|
{
|
|
|
|
return get_uint64("statuses_count");
|
|
|
|
}
|
|
|
|
|
|
|
|
const string Account::url() const
|
|
|
|
{
|
|
|
|
return get_string("url");
|
|
|
|
}
|
|
|
|
|
|
|
|
const string Account::username() const
|
|
|
|
{
|
|
|
|
return get_string("username");
|
|
|
|
}
|
|
|
|
|
2018-12-04 11:26:28 +01:00
|
|
|
bool Account::Source::valid() const
|
2018-09-16 02:45:24 +02:00
|
|
|
{
|
2019-05-01 00:57:00 +02:00
|
|
|
return Entity::check_valid(
|
|
|
|
{
|
|
|
|
"note",
|
|
|
|
"fields"
|
|
|
|
});
|
2018-09-16 02:45:24 +02:00
|
|
|
}
|
|
|
|
|
2019-05-13 21:26:55 +02:00
|
|
|
const vector<Easy::account_field_type> Account::Source::fields() const
|
2018-09-16 02:45:24 +02:00
|
|
|
{
|
|
|
|
const Json::Value &node = get("fields");
|
|
|
|
|
|
|
|
if (node.isArray())
|
|
|
|
{
|
2019-05-13 21:26:55 +02:00
|
|
|
vector<Easy::account_field_type> vec;
|
2019-03-30 23:42:06 +01:00
|
|
|
std::transform(node.begin(), node.end(), std::back_inserter(vec),
|
2019-03-30 23:49:08 +01:00
|
|
|
[](const Json::Value &value)
|
2019-05-01 00:57:00 +02:00
|
|
|
{
|
|
|
|
return Easy::account_field_type(
|
|
|
|
{
|
|
|
|
value["name"].asString(),
|
|
|
|
value["value"].asString(),
|
|
|
|
Easy::string_to_time(
|
|
|
|
value["verified_at"].asString())
|
|
|
|
});
|
2019-03-30 23:42:06 +01:00
|
|
|
});
|
2018-09-16 02:45:24 +02:00
|
|
|
return vec;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2019-05-01 00:57:00 +02:00
|
|
|
const string Account::Source::language() const
|
2018-09-16 02:45:24 +02:00
|
|
|
{
|
2019-05-01 00:57:00 +02:00
|
|
|
return get_string("language");
|
2018-09-16 02:45:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const string Account::Source::note() const
|
|
|
|
{
|
|
|
|
return get_string("note");
|
|
|
|
}
|
|
|
|
|
2018-12-04 11:26:28 +01:00
|
|
|
Easy::visibility_type Account::Source::privacy() const
|
2018-09-16 02:45:24 +02:00
|
|
|
{
|
|
|
|
const string strprivacy = get_string("privacy");
|
2019-05-01 00:57:00 +02:00
|
|
|
if (strprivacy == "public")
|
2018-09-16 02:45:24 +02:00
|
|
|
return visibility_type::Public;
|
2019-05-01 00:57:00 +02:00
|
|
|
else if (strprivacy == "unlisted")
|
2018-09-16 02:45:24 +02:00
|
|
|
return visibility_type::Unlisted;
|
2019-05-01 00:57:00 +02:00
|
|
|
else if (strprivacy == "private")
|
2018-09-16 02:45:24 +02:00
|
|
|
return visibility_type::Private;
|
2019-05-01 00:57:00 +02:00
|
|
|
else if (strprivacy == "direct")
|
2018-09-16 02:45:24 +02:00
|
|
|
return visibility_type::Direct;
|
|
|
|
|
|
|
|
return visibility_type::Undefined;
|
|
|
|
}
|
|
|
|
|
2018-12-04 11:26:28 +01:00
|
|
|
bool Account::Source::sensitive() const
|
2018-09-16 02:45:24 +02:00
|
|
|
{
|
|
|
|
return get_bool("sensitive");
|
|
|
|
}
|