2018-05-11 02:21:44 +02:00
|
|
|
/* This file is part of expandurl-mastodon.
|
|
|
|
* 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 EXPANDURL_MASTODON_HPP
|
|
|
|
#define EXPANDURL_MASTODON_HPP
|
|
|
|
|
|
|
|
#include <string>
|
2018-05-11 06:57:41 +02:00
|
|
|
#include <memory>
|
|
|
|
#include <thread>
|
|
|
|
#include <vector>
|
|
|
|
#include <cstdint>
|
|
|
|
#include <mastodon-cpp/mastodon-cpp.hpp>
|
|
|
|
#include <mastodon-cpp/easy/all.hpp>
|
2018-05-11 02:21:44 +02:00
|
|
|
|
|
|
|
using std::string;
|
|
|
|
|
2018-05-11 06:57:41 +02:00
|
|
|
void signal_handler(int signum);
|
|
|
|
/*!
|
|
|
|
* @brief Extract URLs from HTML
|
|
|
|
*
|
|
|
|
* @return vector of URLs
|
|
|
|
*/
|
|
|
|
const std::vector<string> get_urls(const string &html);
|
|
|
|
|
|
|
|
|
2018-05-11 02:36:49 +02:00
|
|
|
/*!
|
|
|
|
* @brief Expands shortened URLs
|
|
|
|
*
|
|
|
|
* @param url URL to expand
|
|
|
|
*
|
|
|
|
* @return Expanded URL
|
|
|
|
*/
|
2018-05-11 02:21:44 +02:00
|
|
|
const string expand(const string &url);
|
|
|
|
|
2018-05-11 02:36:49 +02:00
|
|
|
/*!
|
|
|
|
* @brief Filters out tracking stuff
|
|
|
|
*
|
2018-05-11 06:57:41 +02:00
|
|
|
* Currently removes all arguments beginning with `utm_`
|
2018-05-11 02:36:49 +02:00
|
|
|
*
|
|
|
|
* @param url URL to filter
|
|
|
|
*
|
|
|
|
* @return Filtered URL
|
|
|
|
*/
|
|
|
|
const string strip(const string &url);
|
|
|
|
|
2018-05-11 06:57:41 +02:00
|
|
|
|
|
|
|
class Listener
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Listener();
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* @brief Starts listening on Mastodon
|
|
|
|
*/
|
|
|
|
const bool start();
|
|
|
|
/*!
|
|
|
|
* @brief Stops listening on Mastodon
|
|
|
|
*/
|
|
|
|
const void stop();
|
|
|
|
|
|
|
|
std::vector<Mastodon::Easy::Notification> get_new_messages();
|
|
|
|
Mastodon::Easy::Status get_status(const std::uint_fast64_t &id);
|
|
|
|
const bool send_reply(const Mastodon::Easy::Status &status,
|
|
|
|
const string &message);
|
|
|
|
|
|
|
|
private:
|
|
|
|
string _instance;
|
|
|
|
string _access_token;
|
|
|
|
string _stream;
|
|
|
|
std::unique_ptr<Mastodon::API::http> _ptr;
|
|
|
|
std::thread _thread;
|
|
|
|
};
|
|
|
|
|
2018-05-11 02:21:44 +02:00
|
|
|
#endif // EXPANDURL_MASTODON_HPP
|