2018-03-31 00:00:20 +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-03-31 00:00:20 +02: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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "notification.hpp"
|
2019-02-22 11:35:06 +01:00
|
|
|
#include "debug.hpp"
|
2018-03-31 00:00:20 +02:00
|
|
|
|
|
|
|
using namespace Mastodon;
|
|
|
|
using Notification = Easy::Notification;
|
|
|
|
|
2018-12-04 11:26:28 +01:00
|
|
|
bool Notification::valid() const
|
2018-07-14 11:44:30 +02:00
|
|
|
{
|
2019-04-25 14:53:44 +02:00
|
|
|
return Entity::check_valid(
|
|
|
|
{
|
|
|
|
"id",
|
|
|
|
"type",
|
|
|
|
"created_at",
|
|
|
|
"account"
|
|
|
|
});
|
2018-07-14 11:44:30 +02:00
|
|
|
}
|
|
|
|
|
2018-03-31 00:00:20 +02:00
|
|
|
const Easy::Account Notification::account() const
|
|
|
|
{
|
2018-04-04 04:38:04 +02:00
|
|
|
const Json::Value node = get("account");
|
2018-03-31 00:00:20 +02:00
|
|
|
if (node.isObject())
|
|
|
|
{
|
|
|
|
return Easy::Account(node.toStyledString());
|
|
|
|
}
|
|
|
|
|
|
|
|
ttdebug << "Could not get data: account\n";
|
|
|
|
return Easy::Account();
|
|
|
|
}
|
|
|
|
|
2019-03-29 14:44:39 +01:00
|
|
|
const Easy::time Notification::created_at() const
|
2018-03-31 00:00:20 +02:00
|
|
|
{
|
2019-03-29 14:44:39 +01:00
|
|
|
return get_time("created_at");
|
2018-03-31 00:00:20 +02:00
|
|
|
}
|
|
|
|
|
2019-01-27 03:44:08 +01:00
|
|
|
const string Notification::id() const
|
2018-03-31 00:00:20 +02:00
|
|
|
{
|
2019-01-27 04:15:52 +01:00
|
|
|
return get_string("id");
|
2018-03-31 00:00:20 +02:00
|
|
|
}
|
|
|
|
|
2018-03-31 04:37:36 +02:00
|
|
|
const Easy::Status Notification::status() const
|
|
|
|
{
|
2018-04-18 18:37:55 +02:00
|
|
|
const Json::Value node = get("status");
|
2018-03-31 04:37:36 +02:00
|
|
|
if (node.isObject())
|
|
|
|
{
|
|
|
|
return Easy::Status(node.toStyledString());
|
|
|
|
}
|
|
|
|
|
|
|
|
ttdebug << "Could not get data: status\n";
|
|
|
|
return Easy::Status();
|
|
|
|
}
|
2018-03-31 00:00:20 +02:00
|
|
|
|
2018-12-04 11:26:28 +01:00
|
|
|
Easy::notification_type Notification::type() const
|
2018-03-31 00:00:20 +02:00
|
|
|
{
|
|
|
|
const string strtype = get_string("type");
|
|
|
|
if (strtype.compare("mention") == 0)
|
2018-04-01 05:14:02 +02:00
|
|
|
return notification_type::Mention;
|
2018-03-31 00:00:20 +02:00
|
|
|
else if (strtype.compare("reblog") == 0)
|
2018-04-01 05:14:02 +02:00
|
|
|
return notification_type::Reblog;
|
2018-03-31 00:00:20 +02:00
|
|
|
else if (strtype.compare("favourite") == 0)
|
2018-04-01 05:14:02 +02:00
|
|
|
return notification_type::Favourite;
|
2018-03-31 00:00:20 +02:00
|
|
|
else if (strtype.compare("follow") == 0)
|
2018-04-01 05:14:02 +02:00
|
|
|
return notification_type::Follow;
|
2018-03-31 00:00:20 +02:00
|
|
|
|
2018-04-01 05:14:02 +02:00
|
|
|
return notification_type::Undefined;
|
2018-03-31 00:00:20 +02:00
|
|
|
}
|