2017-06-13 21:13:58 +02:00
|
|
|
#include "application.hpp"
|
2018-02-05 15:11:50 +01:00
|
|
|
#include "providers/twitch/twitchserver.hpp"
|
2017-12-31 00:50:07 +01:00
|
|
|
#include "singletons/accountmanager.hpp"
|
2018-01-04 02:50:36 +01:00
|
|
|
#include "singletons/commandmanager.hpp"
|
2017-12-31 00:50:07 +01:00
|
|
|
#include "singletons/emotemanager.hpp"
|
2018-02-05 15:11:50 +01:00
|
|
|
#include "singletons/loggingmanager.hpp"
|
2018-04-09 22:59:19 +02:00
|
|
|
#include "singletons/nativemessagingmanager.hpp"
|
2018-04-20 00:15:57 +02:00
|
|
|
#include "singletons/pathmanager.hpp"
|
2018-04-15 15:09:31 +02:00
|
|
|
#include "singletons/pubsubmanager.hpp"
|
2017-12-31 00:50:07 +01:00
|
|
|
#include "singletons/settingsmanager.hpp"
|
|
|
|
#include "singletons/thememanager.hpp"
|
|
|
|
#include "singletons/windowmanager.hpp"
|
2018-04-25 14:53:54 +02:00
|
|
|
#include "util/posttothread.hpp"
|
2017-06-13 21:13:58 +02:00
|
|
|
|
2017-12-31 22:58:35 +01:00
|
|
|
using namespace chatterino::singletons;
|
|
|
|
|
2017-06-13 21:13:58 +02:00
|
|
|
namespace chatterino {
|
|
|
|
|
2017-06-26 16:41:20 +02:00
|
|
|
// this class is responsible for handling the workflow of Chatterino
|
|
|
|
// It will create the instances of the major classes, and connect their signals to each other
|
|
|
|
|
2017-06-13 21:13:58 +02:00
|
|
|
Application::Application()
|
|
|
|
{
|
2018-04-09 22:59:19 +02:00
|
|
|
singletons::NativeMessagingManager::getInstance().registerHost();
|
|
|
|
|
2017-12-31 22:58:35 +01:00
|
|
|
singletons::WindowManager::getInstance();
|
|
|
|
|
2018-01-28 14:23:55 +01:00
|
|
|
singletons::LoggingManager::getInstance();
|
2017-06-13 21:13:58 +02:00
|
|
|
|
2018-04-06 23:31:34 +02:00
|
|
|
singletons::SettingManager::getInstance().initialize();
|
2018-01-05 02:38:00 +01:00
|
|
|
singletons::CommandManager::getInstance().loadCommands();
|
2018-01-05 02:23:49 +01:00
|
|
|
|
2018-04-06 23:31:34 +02:00
|
|
|
singletons::WindowManager::getInstance().initialize();
|
2017-12-14 00:25:06 +01:00
|
|
|
|
2017-06-13 21:13:58 +02:00
|
|
|
// Initialize everything we need
|
2017-12-31 22:58:35 +01:00
|
|
|
singletons::EmoteManager::getInstance().loadGlobalEmotes();
|
2017-06-13 21:13:58 +02:00
|
|
|
|
2017-12-31 22:58:35 +01:00
|
|
|
singletons::AccountManager::getInstance().load();
|
2017-07-28 19:46:53 +02:00
|
|
|
|
2017-06-13 21:13:58 +02:00
|
|
|
// XXX
|
2017-12-31 22:58:35 +01:00
|
|
|
singletons::SettingManager::getInstance().updateWordTypeMask();
|
2018-04-12 00:33:55 +02:00
|
|
|
|
|
|
|
singletons::NativeMessagingManager::getInstance().openGuiMessageQueue();
|
2018-04-15 15:09:31 +02:00
|
|
|
auto &pubsub = singletons::PubSubManager::getInstance();
|
|
|
|
|
|
|
|
pubsub.sig.whisper.sent.connect([](const auto &msg) {
|
|
|
|
debug::Log("WHISPER SENT LOL"); //
|
|
|
|
});
|
|
|
|
|
|
|
|
pubsub.sig.whisper.received.connect([](const auto &msg) {
|
|
|
|
debug::Log("WHISPER RECEIVED LOL"); //
|
|
|
|
});
|
|
|
|
|
|
|
|
pubsub.sig.moderation.chatCleared.connect([&](const auto &action) {
|
|
|
|
debug::Log("Chat cleared by {}", action.source.name); //
|
|
|
|
});
|
|
|
|
|
|
|
|
pubsub.sig.moderation.modeChanged.connect([&](const auto &action) {
|
|
|
|
debug::Log("Mode {} was turned {} by {} (duration {})", (int &)action.mode,
|
|
|
|
(bool &)action.state, action.source.name, action.args.duration);
|
|
|
|
});
|
|
|
|
|
|
|
|
pubsub.sig.moderation.moderationStateChanged.connect([&](const auto &action) {
|
|
|
|
debug::Log("User {} was {} by {}", action.target.id, action.modded ? "modded" : "unmodded",
|
|
|
|
action.source.name);
|
|
|
|
});
|
|
|
|
|
2018-04-27 18:35:31 +02:00
|
|
|
pubsub.sig.moderation.userBanned.connect([&](const auto &action) {
|
2018-04-22 15:47:39 +02:00
|
|
|
auto &server = providers::twitch::TwitchServer::getInstance();
|
|
|
|
auto chan = server.getChannelOrEmptyByID(action.roomID);
|
|
|
|
|
|
|
|
if (chan->isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-04-27 18:35:31 +02:00
|
|
|
auto msg = messages::Message::createTimeoutMessage(action);
|
2018-04-22 15:47:39 +02:00
|
|
|
|
2018-04-25 14:53:54 +02:00
|
|
|
util::postToThread([chan, msg] { chan->addMessage(msg); });
|
2018-04-15 15:09:31 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
pubsub.sig.moderation.userUnbanned.connect([&](const auto &action) {
|
2018-04-27 18:35:31 +02:00
|
|
|
auto &server = providers::twitch::TwitchServer::getInstance();
|
|
|
|
auto chan = server.getChannelOrEmptyByID(action.roomID);
|
|
|
|
|
|
|
|
if (chan->isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto msg = messages::Message::createUntimeoutMessage(action);
|
|
|
|
|
|
|
|
util::postToThread([chan, msg] { chan->addMessage(msg); });
|
2018-04-15 15:09:31 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
auto &accountManager = singletons::AccountManager::getInstance();
|
|
|
|
|
|
|
|
pubsub.Start();
|
|
|
|
|
|
|
|
auto RequestModerationActions = [&]() {
|
|
|
|
pubsub.UnlistenAllModerationActions();
|
|
|
|
// TODO(pajlada): Unlisten to all authed topics instead of only moderation topics
|
|
|
|
// pubsub.UnlistenAllAuthedTopics();
|
|
|
|
|
|
|
|
pubsub.ListenToWhispers(singletons::AccountManager::getInstance().Twitch.getCurrent()); //
|
|
|
|
};
|
|
|
|
|
|
|
|
accountManager.Twitch.userChanged.connect(RequestModerationActions);
|
|
|
|
|
|
|
|
RequestModerationActions();
|
2017-06-13 21:13:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Application::~Application()
|
|
|
|
{
|
2017-12-22 14:44:31 +01:00
|
|
|
this->save();
|
2017-06-13 21:13:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int Application::run(QApplication &qtApp)
|
|
|
|
{
|
|
|
|
// Start connecting to the IRC Servers (Twitch only for now)
|
2018-02-05 15:11:50 +01:00
|
|
|
providers::twitch::TwitchServer::getInstance().connect();
|
2017-06-13 21:13:58 +02:00
|
|
|
|
|
|
|
// Show main window
|
2017-12-31 22:58:35 +01:00
|
|
|
singletons::WindowManager::getInstance().getMainWindow().show();
|
2017-06-13 21:13:58 +02:00
|
|
|
|
|
|
|
return qtApp.exec();
|
|
|
|
}
|
|
|
|
|
2017-12-22 14:44:31 +01:00
|
|
|
void Application::save()
|
|
|
|
{
|
2017-12-31 22:58:35 +01:00
|
|
|
singletons::WindowManager::getInstance().save();
|
2018-01-05 02:38:00 +01:00
|
|
|
|
|
|
|
singletons::CommandManager::getInstance().saveCommands();
|
2017-12-22 14:44:31 +01:00
|
|
|
}
|
|
|
|
|
2017-06-13 21:13:58 +02:00
|
|
|
} // namespace chatterino
|