2018-05-23 20:21:41 +02:00
|
|
|
/* 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 "pushsubscription.hpp"
|
|
|
|
|
|
|
|
using namespace Mastodon;
|
|
|
|
using PushSubscription = Easy::PushSubscription;
|
|
|
|
|
|
|
|
PushSubscription::PushSubscription(const string &json)
|
|
|
|
: Entity(json)
|
|
|
|
{}
|
|
|
|
|
|
|
|
const uint_fast64_t PushSubscription::id() const
|
|
|
|
{
|
|
|
|
return stouint64(get_string("id"));
|
|
|
|
}
|
|
|
|
|
|
|
|
PushSubscription::PushSubscription()
|
|
|
|
: Entity()
|
|
|
|
{}
|
|
|
|
|
2018-07-14 11:44:30 +02:00
|
|
|
const bool PushSubscription::valid() const
|
|
|
|
{
|
|
|
|
const std::vector<string> attributes =
|
|
|
|
{{
|
|
|
|
"id",
|
|
|
|
"endpoint",
|
|
|
|
"server_key"
|
|
|
|
}};
|
|
|
|
|
|
|
|
return Entity::check_valid(attributes);
|
|
|
|
}
|
|
|
|
|
2018-05-23 20:21:41 +02:00
|
|
|
const string PushSubscription::endpoint() const
|
|
|
|
{
|
|
|
|
return get_string("endpoint");
|
|
|
|
}
|
|
|
|
|
|
|
|
const string PushSubscription::server_key() const
|
|
|
|
{
|
|
|
|
return get_string("server_key");
|
|
|
|
}
|
|
|
|
|
|
|
|
const Easy::alertmap PushSubscription::alerts() const
|
|
|
|
{
|
|
|
|
alertmap alerts;
|
|
|
|
const Json::Value node = get("alerts");
|
|
|
|
for (auto it = node.begin(); it != node.end(); ++it)
|
|
|
|
{
|
|
|
|
const string &str = it.name();
|
|
|
|
Easy::notification_type type;
|
|
|
|
if (str.compare("mention") == 0)
|
|
|
|
{
|
|
|
|
type = notification_type::Mention;
|
|
|
|
}
|
|
|
|
else if (str.compare("reblog") == 0)
|
|
|
|
{
|
|
|
|
type = notification_type::Reblog;
|
|
|
|
}
|
|
|
|
else if (str.compare("favourite") == 0)
|
|
|
|
{
|
|
|
|
type = notification_type::Favourite;
|
|
|
|
}
|
|
|
|
else if (str.compare("follow") == 0)
|
|
|
|
{
|
|
|
|
type = notification_type::Follow;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
type = notification_type::Undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
alerts.insert({{ type, s_to_b(it->asString()) }});
|
|
|
|
}
|
|
|
|
return alerts;
|
|
|
|
}
|
|
|
|
|
|
|
|
const bool PushSubscription::s_to_b(const string &str) const
|
|
|
|
{
|
|
|
|
if (str.compare("true") == 0)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|