Addedd Easy::Notification (without status() for now)
This commit is contained in:
parent
fa03cb7ed2
commit
2f7da8a99a
|
@ -1,6 +1,6 @@
|
|||
cmake_minimum_required (VERSION 3.7)
|
||||
project (mastodon-cpp
|
||||
VERSION 0.7.8
|
||||
VERSION 0.7.9
|
||||
LANGUAGES CXX
|
||||
)
|
||||
|
||||
|
|
|
@ -0,0 +1,73 @@
|
|||
/* 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 "notification.hpp"
|
||||
#include "macros.hpp"
|
||||
|
||||
using namespace Mastodon;
|
||||
using Notification = Easy::Notification;
|
||||
using std::string;
|
||||
using std::uint64_t;
|
||||
|
||||
Notification::Notification(const string &json)
|
||||
: Entity(json)
|
||||
{}
|
||||
|
||||
Notification::Notification()
|
||||
: Entity()
|
||||
{}
|
||||
|
||||
const Easy::Account Notification::account() const
|
||||
{
|
||||
const Json::Value node = _tree["account"];
|
||||
if (node.isObject())
|
||||
{
|
||||
return Easy::Account(node.toStyledString());
|
||||
}
|
||||
|
||||
ttdebug << "Could not get data: account\n";
|
||||
return Easy::Account();
|
||||
}
|
||||
|
||||
const system_clock::time_point Notification::created_at() const
|
||||
{
|
||||
return get_time_point("created_at");
|
||||
}
|
||||
|
||||
const uint64_t Notification::id() const
|
||||
{
|
||||
return get_uint64("id");
|
||||
}
|
||||
|
||||
// const Status Notification::status() const
|
||||
// {
|
||||
// //
|
||||
// }
|
||||
|
||||
const Easy::notification_type Notification::type() const
|
||||
{
|
||||
const string strtype = get_string("type");
|
||||
if (strtype.compare("mention") == 0)
|
||||
return notification_type::mention;
|
||||
else if (strtype.compare("reblog") == 0)
|
||||
return notification_type::reblog;
|
||||
else if (strtype.compare("favourite") == 0)
|
||||
return notification_type::favourite;
|
||||
else if (strtype.compare("follow") == 0)
|
||||
return notification_type::follow;
|
||||
|
||||
return notification_type::unknown;
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
/* 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/>.
|
||||
*/
|
||||
|
||||
#ifndef MASTODON_CPP_EASY_NOTIFICATION_HPP
|
||||
#define MASTODON_CPP_EASY_NOTIFICATION_HPP
|
||||
|
||||
#include <string>
|
||||
#include <cstdint>
|
||||
#include <chrono>
|
||||
|
||||
// If we are compiling mastodon-cpp, use another include path
|
||||
#ifdef MASTODON_CPP
|
||||
#include "mastodon-cpp.hpp"
|
||||
#include "easy.hpp"
|
||||
#include "account.hpp"
|
||||
#else
|
||||
#include <mastodon-cpp/mastodon-cpp.hpp>
|
||||
#include <mastodon-cpp/easy.hpp>
|
||||
#include <mastodon-cpp/easy/account.hpp>
|
||||
#endif
|
||||
|
||||
using std::string;
|
||||
using std::uint64_t;
|
||||
using std::chrono::system_clock;
|
||||
|
||||
namespace Mastodon
|
||||
{
|
||||
/*!
|
||||
* @brief Class to hold notifications
|
||||
*/
|
||||
class Easy::Notification : public Easy::Entity
|
||||
{
|
||||
public:
|
||||
/*!
|
||||
* @brief Constructs a Notification object from a JSON string.
|
||||
*
|
||||
* @param json JSON string
|
||||
*/
|
||||
explicit Notification(const string &json);
|
||||
|
||||
/*!
|
||||
* @brief Constructs an empty Notification object.
|
||||
*/
|
||||
Notification();
|
||||
|
||||
/*!
|
||||
* @brief Returns the Account sending the notification to the user
|
||||
*/
|
||||
const Account account() const;
|
||||
|
||||
/*!
|
||||
* @brief Returns time of creation
|
||||
*/
|
||||
const system_clock::time_point created_at() const;
|
||||
|
||||
/*!
|
||||
* @brief Returns notification ID
|
||||
*/
|
||||
const uint64_t id() const;
|
||||
|
||||
/*!
|
||||
* @brief Returns the Status associated with the notification, if
|
||||
* applicable
|
||||
*/
|
||||
// const Status status() const;
|
||||
|
||||
/*!
|
||||
* @brief Returns notification type
|
||||
*/
|
||||
const Easy::notification_type type() const;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // MASTODON_CPP_EASY_NOTIFICATION_HPP
|
Reference in New Issue