expandurl-mastodon/src/expandurl-mastodon.hpp

119 lines
2.7 KiB
C++
Raw Normal View History

/* This file is part of expandurl-mastodon.
2019-04-20 01:47:23 +02:00
* Copyright © 2018, 2019 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>
#include <jsoncpp/json/json.h>
2018-05-27 16:08:49 +02:00
#include "configjson.hpp"
2019-04-20 01:47:23 +02:00
using namespace Mastodon;
using std::string;
using Mastodon::API;
2018-05-27 16:08:49 +02:00
extern ConfigJSON configfile;
2018-05-11 06:57:41 +02:00
void signal_handler(int signum);
2018-05-14 21:44:44 +02:00
2018-05-11 06:57:41 +02:00
/*!
* @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
*/
const string expand(const string &url);
2018-05-11 02:36:49 +02:00
/*!
* @brief Filters out tracking stuff
2019-04-20 01:47:23 +02:00
*
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);
/*!
* @brief Initialize replacements for URLs
*
* If no replacements are found in the config file, a default list is
* inserted.
*
*/
2019-04-20 01:47:23 +02:00
void init_replacements();
2018-05-11 06:57:41 +02:00
class Listener
{
public:
Listener();
~Listener();
2018-05-11 06:57:41 +02:00
/*!
* @brief Starts listening on Mastodon
*/
2019-04-20 01:47:23 +02:00
void start();
2018-05-11 06:57:41 +02:00
/*!
* @brief Stops listening on Mastodon
*/
2019-04-20 01:47:23 +02:00
void stop();
2018-05-11 06:57:41 +02:00
const std::vector<Easy::Notification> get_new_messages();
const std::vector<Easy::Notification> catchup();
2019-01-27 04:51:03 +01:00
Easy::Status get_status(const string &id);
2019-04-20 01:47:23 +02:00
bool send_reply(const Easy::Status &to_status, const string &message);
2019-01-27 04:51:03 +01:00
const string get_parent_id(const Easy::Notification &notif);
2018-05-11 06:57:41 +02:00
2019-04-20 01:47:23 +02:00
bool stillrunning() const;
2018-05-11 06:57:41 +02:00
private:
string _instance;
string _access_token;
2019-04-20 01:47:23 +02:00
std::unique_ptr<Easy::API> _masto;
2018-05-11 06:57:41 +02:00
string _stream;
std::unique_ptr<API::http> _ptr;
2018-05-11 06:57:41 +02:00
std::thread _thread;
bool _running;
2018-05-26 23:52:22 +02:00
string _proxy;
string _proxy_user;
string _proxy_password;
2018-05-27 16:08:49 +02:00
Json::Value &_config;
2019-04-20 01:47:23 +02:00
void read_config();
bool write_config();
bool register_app();
void set_proxy(Easy::API &masto);
2018-05-11 06:57:41 +02:00
};
#endif // EXPANDURL_MASTODON_HPP