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/notification.cpp

82 lines
2.2 KiB
C++
Raw Normal View History

/* 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
*
* 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
* 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.
*
2019-08-15 22:53:38 +02:00
* You should have received a copy of the GNU Affero 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"
using namespace Mastodon;
using Notification = Easy::Notification;
2018-12-04 11:26:28 +01:00
bool Notification::valid() const
{
return Entity::check_valid(
{
"id",
"type",
"created_at",
"account"
});
}
const Easy::Account Notification::account() const
{
2018-04-04 04:38:04 +02:00
const Json::Value node = get("account");
if (node.isObject())
{
return Easy::Account(node.toStyledString());
}
ttdebug << "Could not get data: account\n";
return Easy::Account();
}
2019-05-13 21:26:55 +02:00
const Easy::time_type Notification::created_at() const
{
2019-03-29 14:44:39 +01:00
return get_time("created_at");
}
const string Notification::id() const
{
2019-01-27 04:15:52 +01:00
return get_string("id");
}
const Easy::Status Notification::status() const
{
const Json::Value node = get("status");
if (node.isObject())
{
return Easy::Status(node.toStyledString());
}
ttdebug << "Could not get data: status\n";
return Easy::Status();
}
2018-12-04 11:26:28 +01:00
Easy::notification_type Notification::type() const
{
const string strtype = get_string("type");
if (strtype.compare("mention") == 0)
2018-04-01 05:14:02 +02:00
return notification_type::Mention;
else if (strtype.compare("reblog") == 0)
2018-04-01 05:14:02 +02:00
return notification_type::Reblog;
else if (strtype.compare("favourite") == 0)
2018-04-01 05:14:02 +02:00
return notification_type::Favourite;
else if (strtype.compare("follow") == 0)
2018-04-01 05:14:02 +02:00
return notification_type::Follow;
2018-04-01 05:14:02 +02:00
return notification_type::Undefined;
}