2018-04-15 15:09:31 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <boost/asio.hpp>
|
|
|
|
#include <boost/asio/steady_timer.hpp>
|
|
|
|
#include <memory>
|
2020-11-21 16:20:10 +01:00
|
|
|
#include "common/QLogging.hpp"
|
2018-08-15 22:46:20 +02:00
|
|
|
#include "util/RapidjsonHelpers.hpp"
|
2018-04-15 15:09:31 +02:00
|
|
|
|
|
|
|
namespace chatterino {
|
|
|
|
|
2018-08-11 22:23:06 +02:00
|
|
|
class TwitchAccount;
|
2018-04-15 15:09:31 +02:00
|
|
|
struct ActionUser;
|
|
|
|
|
|
|
|
const rapidjson::Value &getArgs(const rapidjson::Value &data);
|
2019-01-20 14:45:59 +01:00
|
|
|
const rapidjson::Value &getMsgID(const rapidjson::Value &data);
|
2018-04-15 15:09:31 +02:00
|
|
|
|
|
|
|
bool getCreatedByUser(const rapidjson::Value &data, ActionUser &user);
|
|
|
|
|
|
|
|
bool getTargetUser(const rapidjson::Value &data, ActionUser &user);
|
2020-05-03 12:21:00 +02:00
|
|
|
bool getTargetUserName(const rapidjson::Value &data, ActionUser &user);
|
2018-04-15 15:09:31 +02:00
|
|
|
|
2020-01-03 20:51:37 +01:00
|
|
|
rapidjson::Document createListenMessage(const std::vector<QString> &topicsVec,
|
|
|
|
std::shared_ptr<TwitchAccount> account);
|
2018-08-06 21:17:03 +02:00
|
|
|
rapidjson::Document createUnlistenMessage(
|
2020-01-03 20:51:37 +01:00
|
|
|
const std::vector<QString> &topicsVec);
|
2018-04-15 15:09:31 +02:00
|
|
|
|
|
|
|
// Create timer using given ioService
|
|
|
|
template <typename Duration, typename Callback>
|
2018-08-06 21:17:03 +02:00
|
|
|
void runAfter(boost::asio::io_service &ioService, Duration duration,
|
|
|
|
Callback cb)
|
2018-04-15 15:09:31 +02:00
|
|
|
{
|
|
|
|
auto timer = std::make_shared<boost::asio::steady_timer>(ioService);
|
|
|
|
timer->expires_from_now(duration);
|
|
|
|
|
|
|
|
timer->async_wait([timer, cb](const boost::system::error_code &ec) {
|
2018-10-21 13:43:02 +02:00
|
|
|
if (ec)
|
|
|
|
{
|
2020-11-21 16:20:10 +01:00
|
|
|
qCDebug(chatterinoPubsub)
|
|
|
|
<< "Error in runAfter:" << ec.message().c_str();
|
2018-04-15 15:09:31 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
cb(timer);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// Use provided timer
|
|
|
|
template <typename Duration, typename Callback>
|
2018-08-06 21:17:03 +02:00
|
|
|
void runAfter(std::shared_ptr<boost::asio::steady_timer> timer,
|
|
|
|
Duration duration, Callback cb)
|
2018-04-15 15:09:31 +02:00
|
|
|
{
|
|
|
|
timer->expires_from_now(duration);
|
|
|
|
|
|
|
|
timer->async_wait([timer, cb](const boost::system::error_code &ec) {
|
2018-10-21 13:43:02 +02:00
|
|
|
if (ec)
|
|
|
|
{
|
2020-11-21 16:20:10 +01:00
|
|
|
qCDebug(chatterinoPubsub)
|
|
|
|
<< "Error in runAfter:" << ec.message().c_str();
|
2018-04-15 15:09:31 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
cb(timer);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace chatterino
|