This repository has been archived on 2020-05-10. You can view files and clone it, but cannot push or open issues or pull requests.
mastodon-cpp/src/easy/entities/pushsubscription.cpp

93 lines
2.3 KiB
C++
Raw Normal View History

2018-05-23 20:21:41 +02: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-05-23 20:21:41 +02:00
* This program is free software: you can redistribute it and/or modify
2019-08-15 22:53:38 +02:00
* it under the terms of the GNU Affero General Public License as published by
2018-05-23 20:21:41 +02:00
* 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
2019-08-15 22:53:38 +02:00
* GNU Affero General Public License for more details.
2018-05-23 20:21:41 +02:00
*
2019-08-15 22:53:38 +02:00
* You should have received a copy of the GNU Affero General Public License
2018-05-23 20:21:41 +02:00
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "pushsubscription.hpp"
using namespace Mastodon;
using PushSubscription = Easy::PushSubscription;
const string PushSubscription::id() const
2018-05-23 20:21:41 +02:00
{
return get_string("id");
2018-05-23 20:21:41 +02:00
}
2018-12-04 11:26:28 +01:00
bool PushSubscription::valid() const
{
return Entity::check_valid(
{
"id",
"endpoint",
"server_key",
"alerts"
});
}
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");
}
2019-05-13 21:26:55 +02:00
const vector<Easy::alert_type> PushSubscription::alerts() const
2018-05-23 20:21:41 +02:00
{
2019-05-13 21:26:55 +02:00
vector<Easy::alert_type> alerts;
2018-05-23 20:21:41 +02:00
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.push_back({ type, s_to_b(it->asString()) });
2018-05-23 20:21:41 +02:00
}
return alerts;
}
2018-12-04 11:26:28 +01:00
bool PushSubscription::s_to_b(const string &str) const
2018-05-23 20:21:41 +02:00
{
if (str.compare("true") == 0)
{
return true;
}
else
{
return false;
}
}