started to refactor Application

This commit is contained in:
fourtf
2018-07-07 11:41:01 +02:00
parent 6a418e6e59
commit c609a9fd37
32 changed files with 195 additions and 147 deletions
+10 -2
View File
@@ -1,9 +1,11 @@
#include "TwitchServer.hpp"
#include "Application.hpp"
#include "common/Common.hpp"
#include "controllers/accounts/AccountController.hpp"
#include "controllers/highlights/HighlightController.hpp"
#include "providers/twitch/IrcMessageHandler.hpp"
#include "providers/twitch/PubsubClient.hpp"
#include "providers/twitch/TwitchAccount.hpp"
#include "providers/twitch/TwitchHelpers.hpp"
#include "providers/twitch/TwitchMessageBuilder.hpp"
@@ -24,16 +26,22 @@ TwitchServer::TwitchServer()
, watchingChannel(Channel::getEmpty(), Channel::Type::TwitchWatching)
{
qDebug() << "init TwitchServer";
this->pubsub = new PubSub;
}
void TwitchServer::initialize()
void TwitchServer::initialize(Application &app)
{
getApp()->accounts->twitch.currentUserChanged.connect(
this->app = &app;
app.accounts->twitch.currentUserChanged.connect(
[this]() { postToThread([this] { this->connect(); }); });
}
void TwitchServer::initializeConnection(IrcConnection *connection, bool isRead, bool isWrite)
{
assert(this->app);
std::shared_ptr<TwitchAccount> account = getApp()->accounts->twitch.getCurrent();
qDebug() << "logging in as" << account->getUserName();
+10 -2
View File
@@ -1,6 +1,7 @@
#pragma once
#include "common/MutexValue.hpp"
#include "common/Singleton.hpp"
#include "providers/irc/AbstractIrcServer.hpp"
#include "providers/twitch/TwitchAccount.hpp"
#include "providers/twitch/TwitchChannel.hpp"
@@ -11,12 +12,15 @@
namespace chatterino {
class TwitchServer final : public AbstractIrcServer
class PubSub;
class TwitchServer : public AbstractIrcServer, public Singleton
{
public:
TwitchServer();
virtual ~TwitchServer() override = default;
void initialize();
virtual void initialize(Application &app) override;
// fourtf: ugh
void forEachChannelAndSpecialChannels(std::function<void(ChannelPtr)> func);
@@ -29,6 +33,8 @@ public:
const ChannelPtr mentionsChannel;
IndirectChannel watchingChannel;
PubSub *pubsub;
protected:
void initializeConnection(IrcConnection *connection, bool isRead, bool isWrite) override;
std::shared_ptr<Channel> createChannel(const QString &channelName) override;
@@ -44,6 +50,8 @@ protected:
private:
void onMessageSendRequested(TwitchChannel *channel, const QString &message, bool &sent);
Application *app = nullptr;
std::mutex lastMessageMutex_;
std::queue<std::chrono::steady_clock::time_point> lastMessagePleb_;
std::queue<std::chrono::steady_clock::time_point> lastMessageMod_;