2018-04-15 15:09:31 +02:00
|
|
|
#pragma once
|
|
|
|
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "debug/Log.hpp"
|
|
|
|
#include "providers/twitch/TwitchAccount.hpp"
|
|
|
|
#include "util/RapidjsonHelpers.hpp"
|
2018-04-15 15:09:31 +02:00
|
|
|
|
|
|
|
#include <boost/asio.hpp>
|
|
|
|
#include <boost/asio/steady_timer.hpp>
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
namespace chatterino {
|
|
|
|
|
|
|
|
struct ActionUser;
|
|
|
|
|
|
|
|
const rapidjson::Value &getArgs(const rapidjson::Value &data);
|
|
|
|
|
|
|
|
bool getCreatedByUser(const rapidjson::Value &data, ActionUser &user);
|
|
|
|
|
|
|
|
bool getTargetUser(const rapidjson::Value &data, ActionUser &user);
|
|
|
|
|
2018-04-28 16:07:18 +02:00
|
|
|
rapidjson::Document createListenMessage(const std::vector<std::string> &topicsVec,
|
2018-04-15 15:09:31 +02:00
|
|
|
std::shared_ptr<providers::twitch::TwitchAccount> account);
|
2018-04-28 16:07:18 +02:00
|
|
|
rapidjson::Document createUnlistenMessage(const std::vector<std::string> &topicsVec);
|
2018-04-15 15:09:31 +02:00
|
|
|
|
|
|
|
// Create timer using given ioService
|
|
|
|
template <typename Duration, typename Callback>
|
2018-04-28 16:07:18 +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) {
|
|
|
|
if (ec) {
|
2018-04-28 16:07:18 +02:00
|
|
|
debug::Log("Error in runAfter: {}", ec.message());
|
2018-04-15 15:09:31 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
cb(timer);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// Use provided timer
|
|
|
|
template <typename Duration, typename Callback>
|
2018-04-28 16:07:18 +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) {
|
|
|
|
if (ec) {
|
2018-04-28 16:07:18 +02:00
|
|
|
debug::Log("Error in runAfter: {}", ec.message());
|
2018-04-15 15:09:31 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
cb(timer);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace chatterino
|