2018-06-26 14:09:39 +02:00
|
|
|
#include "Application.hpp"
|
|
|
|
|
2019-09-22 10:53:39 +02:00
|
|
|
#include <atomic>
|
|
|
|
|
2019-09-22 15:30:04 +02:00
|
|
|
#include "common/Args.hpp"
|
2020-11-21 16:20:10 +01:00
|
|
|
#include "common/QLogging.hpp"
|
2020-09-06 12:02:15 +02:00
|
|
|
#include "common/Version.hpp"
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "controllers/accounts/AccountController.hpp"
|
|
|
|
#include "controllers/commands/CommandController.hpp"
|
2022-06-05 17:40:57 +02:00
|
|
|
#include "controllers/highlights/HighlightController.hpp"
|
2021-11-21 18:46:21 +01:00
|
|
|
#include "controllers/hotkeys/HotkeyController.hpp"
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "controllers/ignores/IgnoreController.hpp"
|
2018-08-09 15:41:03 +02:00
|
|
|
#include "controllers/notifications/NotificationController.hpp"
|
2021-05-01 12:47:33 +02:00
|
|
|
#include "debug/AssertInGuiThread.hpp"
|
2018-08-07 01:35:24 +02:00
|
|
|
#include "messages/MessageBuilder.hpp"
|
2018-08-02 14:23:27 +02:00
|
|
|
#include "providers/bttv/BttvEmotes.hpp"
|
2018-09-16 17:27:51 +02:00
|
|
|
#include "providers/chatterino/ChatterinoBadges.hpp"
|
2020-10-25 10:36:00 +01:00
|
|
|
#include "providers/ffz/FfzBadges.hpp"
|
2018-08-02 14:23:27 +02:00
|
|
|
#include "providers/ffz/FfzEmotes.hpp"
|
2019-09-10 23:55:43 +02:00
|
|
|
#include "providers/irc/Irc2.hpp"
|
2022-10-16 13:22:17 +02:00
|
|
|
#include "providers/seventv/SeventvBadges.hpp"
|
|
|
|
#include "providers/seventv/SeventvEmotes.hpp"
|
2022-11-13 12:07:41 +01:00
|
|
|
#include "providers/seventv/SeventvEventAPI.hpp"
|
2022-05-07 17:22:39 +02:00
|
|
|
#include "providers/twitch/PubSubManager.hpp"
|
2019-09-15 13:02:02 +02:00
|
|
|
#include "providers/twitch/TwitchIrcServer.hpp"
|
2021-06-19 13:56:00 +02:00
|
|
|
#include "providers/twitch/TwitchMessageBuilder.hpp"
|
2018-08-11 22:23:06 +02:00
|
|
|
#include "singletons/Emotes.hpp"
|
2018-06-28 19:46:45 +02:00
|
|
|
#include "singletons/Fonts.hpp"
|
|
|
|
#include "singletons/Logging.hpp"
|
|
|
|
#include "singletons/NativeMessaging.hpp"
|
|
|
|
#include "singletons/Paths.hpp"
|
|
|
|
#include "singletons/Resources.hpp"
|
|
|
|
#include "singletons/Settings.hpp"
|
2018-06-28 20:03:04 +02:00
|
|
|
#include "singletons/Theme.hpp"
|
2018-08-11 12:47:03 +02:00
|
|
|
#include "singletons/Toasts.hpp"
|
2019-09-02 10:52:01 +02:00
|
|
|
#include "singletons/Updates.hpp"
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "singletons/WindowManager.hpp"
|
2022-05-07 17:22:39 +02:00
|
|
|
#include "util/Helpers.hpp"
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "util/PostToThread.hpp"
|
2020-08-08 15:37:22 +02:00
|
|
|
#include "util/RapidjsonHelpers.hpp"
|
2019-09-22 15:32:36 +02:00
|
|
|
#include "widgets/Notebook.hpp"
|
2018-08-11 22:23:06 +02:00
|
|
|
#include "widgets/Window.hpp"
|
2019-09-22 15:32:36 +02:00
|
|
|
#include "widgets/splits/Split.hpp"
|
2017-06-13 21:13:58 +02:00
|
|
|
|
2021-05-08 15:57:00 +02:00
|
|
|
#include <QDesktopServices>
|
|
|
|
|
2017-06-13 21:13:58 +02:00
|
|
|
namespace chatterino {
|
|
|
|
|
2018-04-27 22:11:19 +02:00
|
|
|
static std::atomic<bool> isAppInitialized{false};
|
|
|
|
|
2018-08-02 14:23:27 +02:00
|
|
|
Application *Application::instance = nullptr;
|
2022-05-22 15:00:18 +02:00
|
|
|
IApplication *IApplication::instance = nullptr;
|
|
|
|
|
|
|
|
IApplication::IApplication()
|
|
|
|
{
|
|
|
|
IApplication::instance = this;
|
|
|
|
}
|
2018-04-27 22:11:19 +02:00
|
|
|
|
2017-06-26 16:41:20 +02:00
|
|
|
// this class is responsible for handling the workflow of Chatterino
|
2018-08-06 21:17:03 +02:00
|
|
|
// It will create the instances of the major classes, and connect their signals
|
|
|
|
// to each other
|
2017-06-26 16:41:20 +02:00
|
|
|
|
2018-08-02 14:23:27 +02:00
|
|
|
Application::Application(Settings &_settings, Paths &_paths)
|
2020-02-23 22:15:13 +01:00
|
|
|
: themes(&this->emplace<Theme>())
|
2018-08-02 14:23:27 +02:00
|
|
|
, fonts(&this->emplace<Fonts>())
|
|
|
|
, emotes(&this->emplace<Emotes>())
|
2020-12-06 14:07:33 +01:00
|
|
|
, accounts(&this->emplace<AccountController>())
|
2021-11-21 18:46:21 +01:00
|
|
|
, hotkeys(&this->emplace<HotkeyController>())
|
2018-08-02 14:23:27 +02:00
|
|
|
, windows(&this->emplace<WindowManager>())
|
2018-08-19 15:09:00 +02:00
|
|
|
, toasts(&this->emplace<Toasts>())
|
2018-08-19 19:02:49 +02:00
|
|
|
|
2018-08-02 14:23:27 +02:00
|
|
|
, commands(&this->emplace<CommandController>())
|
2018-08-09 15:41:03 +02:00
|
|
|
, notifications(&this->emplace<NotificationController>())
|
2022-06-05 17:40:57 +02:00
|
|
|
, highlights(&this->emplace<HighlightController>())
|
2022-03-19 12:02:29 +01:00
|
|
|
, twitch(&this->emplace<TwitchIrcServer>())
|
2018-09-16 17:27:51 +02:00
|
|
|
, chatterinoBadges(&this->emplace<ChatterinoBadges>())
|
2020-10-25 10:36:00 +01:00
|
|
|
, ffzBadges(&this->emplace<FfzBadges>())
|
2022-10-16 13:22:17 +02:00
|
|
|
, seventvBadges(&this->emplace<SeventvBadges>())
|
2018-08-02 14:23:27 +02:00
|
|
|
, logging(&this->emplace<Logging>())
|
2017-06-13 21:13:58 +02:00
|
|
|
{
|
2018-08-02 14:23:27 +02:00
|
|
|
this->instance = this;
|
|
|
|
|
2020-11-08 12:02:19 +01:00
|
|
|
this->fonts->fontChanged.connect([this]() {
|
|
|
|
this->windows->layoutChannelViews();
|
|
|
|
});
|
2018-04-27 22:11:19 +02:00
|
|
|
}
|
|
|
|
|
2018-08-02 14:23:27 +02:00
|
|
|
void Application::initialize(Settings &settings, Paths &paths)
|
2018-04-27 22:11:19 +02:00
|
|
|
{
|
|
|
|
assert(isAppInitialized == false);
|
|
|
|
isAppInitialized = true;
|
2018-01-05 02:23:49 +01:00
|
|
|
|
2020-09-06 12:02:15 +02:00
|
|
|
// Show changelog
|
2021-04-17 16:15:23 +02:00
|
|
|
if (!getArgs().isFramelessEmbed &&
|
|
|
|
getSettings()->currentVersion.getValue() != "" &&
|
2020-09-06 12:02:15 +02:00
|
|
|
getSettings()->currentVersion.getValue() != CHATTERINO_VERSION)
|
|
|
|
{
|
|
|
|
auto box = new QMessageBox(QMessageBox::Information, "Chatterino 2",
|
|
|
|
"Show changelog?",
|
|
|
|
QMessageBox::Yes | QMessageBox::No);
|
|
|
|
box->setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
if (box->exec() == QMessageBox::Yes)
|
|
|
|
{
|
|
|
|
QDesktopServices::openUrl(
|
|
|
|
QUrl("https://www.chatterino.com/changelog"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-17 16:15:23 +02:00
|
|
|
if (!getArgs().isFramelessEmbed)
|
2019-10-03 17:36:44 +02:00
|
|
|
{
|
2021-04-17 16:15:23 +02:00
|
|
|
getSettings()->currentVersion.setValue(CHATTERINO_VERSION);
|
|
|
|
|
|
|
|
if (getSettings()->enableExperimentalIrc)
|
|
|
|
{
|
|
|
|
Irc::instance().load();
|
|
|
|
}
|
2019-10-03 17:36:44 +02:00
|
|
|
}
|
2019-09-14 20:45:01 +02:00
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
for (auto &singleton : this->singletons_)
|
|
|
|
{
|
2018-08-02 14:23:27 +02:00
|
|
|
singleton->initialize(settings, paths);
|
2018-07-07 11:41:01 +02:00
|
|
|
}
|
2018-04-28 15:20:18 +02:00
|
|
|
|
2019-09-22 15:32:36 +02:00
|
|
|
// add crash message
|
2021-04-17 16:15:23 +02:00
|
|
|
if (!getArgs().isFramelessEmbed && getArgs().crashRecovery)
|
2019-09-22 15:32:36 +02:00
|
|
|
{
|
|
|
|
if (auto selected =
|
|
|
|
this->windows->getMainWindow().getNotebook().getSelectedPage())
|
|
|
|
{
|
|
|
|
if (auto container = dynamic_cast<SplitContainer *>(selected))
|
|
|
|
{
|
|
|
|
for (auto &&split : container->getSplits())
|
|
|
|
{
|
|
|
|
if (auto channel = split->getChannel(); !channel->isEmpty())
|
|
|
|
{
|
|
|
|
channel->addMessage(makeSystemMessage(
|
|
|
|
"Chatterino unexpectedly crashed and restarted. "
|
|
|
|
"You can disable automatic restarts in the "
|
|
|
|
"settings."));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-28 19:38:57 +02:00
|
|
|
this->windows->updateWordTypeMask();
|
2018-04-12 00:33:55 +02:00
|
|
|
|
2021-04-17 16:15:23 +02:00
|
|
|
if (!getArgs().isFramelessEmbed)
|
|
|
|
{
|
|
|
|
this->initNm(paths);
|
|
|
|
}
|
2022-05-07 17:22:39 +02:00
|
|
|
this->initPubSub();
|
2022-11-13 12:07:41 +01:00
|
|
|
|
|
|
|
this->initSeventvEventAPI();
|
2018-08-02 14:23:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int Application::run(QApplication &qtApp)
|
|
|
|
{
|
|
|
|
assert(isAppInitialized);
|
|
|
|
|
2022-03-19 12:02:29 +01:00
|
|
|
this->twitch->connect();
|
2018-08-02 14:23:27 +02:00
|
|
|
|
2021-04-17 16:15:23 +02:00
|
|
|
if (!getArgs().isFramelessEmbed)
|
|
|
|
{
|
|
|
|
this->windows->getMainWindow().show();
|
|
|
|
}
|
2018-08-02 14:23:27 +02:00
|
|
|
|
2019-10-03 22:17:57 +02:00
|
|
|
getSettings()->betaUpdates.connect(
|
2020-11-08 12:02:19 +01:00
|
|
|
[] {
|
|
|
|
Updates::instance().checkForUpdates();
|
|
|
|
},
|
|
|
|
false);
|
|
|
|
getSettings()->moderationActions.delayedItemsChanged.connect([this] {
|
|
|
|
this->windows->forceLayoutChannelViews();
|
|
|
|
});
|
2019-09-02 10:52:01 +02:00
|
|
|
|
2020-11-08 12:02:19 +01:00
|
|
|
getSettings()->highlightedMessages.delayedItemsChanged.connect([this] {
|
|
|
|
this->windows->forceLayoutChannelViews();
|
|
|
|
});
|
|
|
|
getSettings()->highlightedUsers.delayedItemsChanged.connect([this] {
|
|
|
|
this->windows->forceLayoutChannelViews();
|
|
|
|
});
|
2020-04-15 23:15:45 +02:00
|
|
|
|
2021-04-26 00:25:23 +02:00
|
|
|
getSettings()->removeSpacesBetweenEmotes.connect([this] {
|
|
|
|
this->windows->forceLayoutChannelViews();
|
|
|
|
});
|
|
|
|
|
2022-09-14 13:21:01 +02:00
|
|
|
getSettings()->enableBTTVGlobalEmotes.connect(
|
|
|
|
[this] {
|
|
|
|
this->twitch->reloadBTTVGlobalEmotes();
|
|
|
|
},
|
|
|
|
false);
|
|
|
|
getSettings()->enableBTTVChannelEmotes.connect(
|
|
|
|
[this] {
|
|
|
|
this->twitch->reloadAllBTTVChannelEmotes();
|
|
|
|
},
|
|
|
|
false);
|
|
|
|
getSettings()->enableFFZGlobalEmotes.connect(
|
|
|
|
[this] {
|
|
|
|
this->twitch->reloadFFZGlobalEmotes();
|
|
|
|
},
|
|
|
|
false);
|
|
|
|
getSettings()->enableFFZChannelEmotes.connect(
|
|
|
|
[this] {
|
|
|
|
this->twitch->reloadAllFFZChannelEmotes();
|
|
|
|
},
|
2022-10-16 13:22:17 +02:00
|
|
|
false);
|
|
|
|
getSettings()->enableSevenTVGlobalEmotes.connect(
|
|
|
|
[this] {
|
|
|
|
this->twitch->reloadSevenTVGlobalEmotes();
|
|
|
|
},
|
|
|
|
false);
|
|
|
|
getSettings()->enableSevenTVChannelEmotes.connect(
|
|
|
|
[this] {
|
|
|
|
this->twitch->reloadAllSevenTVChannelEmotes();
|
|
|
|
},
|
2022-09-14 13:21:01 +02:00
|
|
|
false);
|
2022-08-28 12:20:47 +02:00
|
|
|
|
2018-08-02 14:23:27 +02:00
|
|
|
return qtApp.exec();
|
|
|
|
}
|
|
|
|
|
2022-11-05 11:04:35 +01:00
|
|
|
IEmotes *Application::getEmotes()
|
|
|
|
{
|
|
|
|
return this->emotes;
|
|
|
|
}
|
|
|
|
|
2018-08-02 14:23:27 +02:00
|
|
|
void Application::save()
|
|
|
|
{
|
2018-10-21 13:43:02 +02:00
|
|
|
for (auto &singleton : this->singletons_)
|
|
|
|
{
|
2018-08-02 14:23:27 +02:00
|
|
|
singleton->save();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-17 12:51:16 +02:00
|
|
|
void Application::initNm(Paths &paths)
|
2018-08-02 14:23:27 +02:00
|
|
|
{
|
2019-09-08 18:06:43 +02:00
|
|
|
(void)paths;
|
|
|
|
|
2018-06-24 14:03:26 +02:00
|
|
|
#ifdef Q_OS_WIN
|
2019-08-19 23:13:20 +02:00
|
|
|
# if defined QT_NO_DEBUG || defined C_DEBUG_NM
|
2018-09-17 12:51:16 +02:00
|
|
|
registerNmHost(paths);
|
|
|
|
this->nmServer.start();
|
2018-08-15 22:46:20 +02:00
|
|
|
# endif
|
2018-06-24 14:03:26 +02:00
|
|
|
#endif
|
2018-08-02 14:23:27 +02:00
|
|
|
}
|
2018-04-15 15:09:31 +02:00
|
|
|
|
2022-05-07 17:22:39 +02:00
|
|
|
void Application::initPubSub()
|
2018-08-02 14:23:27 +02:00
|
|
|
{
|
2022-03-19 12:02:29 +01:00
|
|
|
this->twitch->pubsub->signals_.moderation.chatCleared.connect(
|
2018-08-06 21:17:03 +02:00
|
|
|
[this](const auto &action) {
|
2022-03-19 12:02:29 +01:00
|
|
|
auto chan = this->twitch->getChannelOrEmptyByID(action.roomID);
|
2018-10-21 13:43:02 +02:00
|
|
|
if (chan->isEmpty())
|
|
|
|
{
|
2018-08-06 21:17:03 +02:00
|
|
|
return;
|
|
|
|
}
|
2018-04-29 13:24:37 +02:00
|
|
|
|
2018-08-06 21:17:03 +02:00
|
|
|
QString text =
|
2021-07-11 13:33:35 +02:00
|
|
|
QString("%1 cleared the chat").arg(action.source.login);
|
2018-04-29 13:24:37 +02:00
|
|
|
|
2018-08-07 01:35:24 +02:00
|
|
|
auto msg = makeSystemMessage(text);
|
2020-11-08 12:02:19 +01:00
|
|
|
postToThread([chan, msg] {
|
|
|
|
chan->addMessage(msg);
|
|
|
|
});
|
2018-08-06 21:17:03 +02:00
|
|
|
});
|
2018-04-15 15:09:31 +02:00
|
|
|
|
2022-03-19 12:02:29 +01:00
|
|
|
this->twitch->pubsub->signals_.moderation.modeChanged.connect(
|
2018-08-06 21:17:03 +02:00
|
|
|
[this](const auto &action) {
|
2022-03-19 12:02:29 +01:00
|
|
|
auto chan = this->twitch->getChannelOrEmptyByID(action.roomID);
|
2018-10-21 13:43:02 +02:00
|
|
|
if (chan->isEmpty())
|
|
|
|
{
|
2018-08-06 21:17:03 +02:00
|
|
|
return;
|
|
|
|
}
|
2018-04-29 13:24:37 +02:00
|
|
|
|
2018-08-06 21:17:03 +02:00
|
|
|
QString text =
|
2020-11-08 12:02:19 +01:00
|
|
|
QString("%1 turned %2 %3 mode")
|
2021-07-11 13:33:35 +02:00
|
|
|
.arg(action.source.login)
|
2018-08-06 21:17:03 +02:00
|
|
|
.arg(action.state == ModeChangedAction::State::On ? "on"
|
|
|
|
: "off")
|
|
|
|
.arg(action.getModeName());
|
2018-04-29 13:24:37 +02:00
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (action.duration > 0)
|
|
|
|
{
|
2021-07-11 13:33:35 +02:00
|
|
|
text += QString(" (%1 seconds)").arg(action.duration);
|
2018-08-06 21:17:03 +02:00
|
|
|
}
|
2018-04-29 13:24:37 +02:00
|
|
|
|
2018-08-07 01:35:24 +02:00
|
|
|
auto msg = makeSystemMessage(text);
|
2020-11-08 12:02:19 +01:00
|
|
|
postToThread([chan, msg] {
|
|
|
|
chan->addMessage(msg);
|
|
|
|
});
|
2018-08-06 21:17:03 +02:00
|
|
|
});
|
2018-04-15 15:09:31 +02:00
|
|
|
|
2022-03-19 12:02:29 +01:00
|
|
|
this->twitch->pubsub->signals_.moderation.moderationStateChanged.connect(
|
2018-06-26 17:42:35 +02:00
|
|
|
[this](const auto &action) {
|
2022-03-19 12:02:29 +01:00
|
|
|
auto chan = this->twitch->getChannelOrEmptyByID(action.roomID);
|
2018-10-21 13:43:02 +02:00
|
|
|
if (chan->isEmpty())
|
|
|
|
{
|
2018-06-26 17:42:35 +02:00
|
|
|
return;
|
|
|
|
}
|
2018-04-29 13:24:37 +02:00
|
|
|
|
2018-06-26 17:42:35 +02:00
|
|
|
QString text;
|
2018-04-29 13:24:37 +02:00
|
|
|
|
2021-07-11 13:33:35 +02:00
|
|
|
text = QString("%1 %2 %3")
|
|
|
|
.arg(action.source.login,
|
|
|
|
(action.modded ? "modded" : "unmodded"),
|
|
|
|
action.target.login);
|
2018-04-29 13:24:37 +02:00
|
|
|
|
2018-08-07 01:35:24 +02:00
|
|
|
auto msg = makeSystemMessage(text);
|
2020-11-08 12:02:19 +01:00
|
|
|
postToThread([chan, msg] {
|
|
|
|
chan->addMessage(msg);
|
|
|
|
});
|
2018-06-26 17:42:35 +02:00
|
|
|
});
|
2018-04-15 15:09:31 +02:00
|
|
|
|
2022-03-19 12:02:29 +01:00
|
|
|
this->twitch->pubsub->signals_.moderation.userBanned.connect(
|
2018-08-06 21:17:03 +02:00
|
|
|
[&](const auto &action) {
|
2022-03-19 12:02:29 +01:00
|
|
|
auto chan = this->twitch->getChannelOrEmptyByID(action.roomID);
|
2018-04-22 15:47:39 +02:00
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (chan->isEmpty())
|
|
|
|
{
|
2018-08-06 21:17:03 +02:00
|
|
|
return;
|
|
|
|
}
|
2018-04-22 15:47:39 +02:00
|
|
|
|
2022-04-09 13:58:18 +02:00
|
|
|
postToThread([chan, action] {
|
|
|
|
MessageBuilder msg(action);
|
|
|
|
msg->flags.set(MessageFlag::PubSub);
|
|
|
|
chan->addOrReplaceTimeout(msg.release());
|
2018-08-07 01:35:24 +02:00
|
|
|
});
|
2018-08-06 21:17:03 +02:00
|
|
|
});
|
2022-03-19 12:02:29 +01:00
|
|
|
this->twitch->pubsub->signals_.moderation.messageDeleted.connect(
|
2021-06-19 13:56:00 +02:00
|
|
|
[&](const auto &action) {
|
2022-03-19 12:02:29 +01:00
|
|
|
auto chan = this->twitch->getChannelOrEmptyByID(action.roomID);
|
2021-06-19 13:56:00 +02:00
|
|
|
|
2021-08-09 00:04:25 +02:00
|
|
|
if (chan->isEmpty() || getSettings()->hideDeletionActions)
|
2021-06-19 13:56:00 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
MessageBuilder msg;
|
|
|
|
TwitchMessageBuilder::deletionMessage(action, &msg);
|
|
|
|
msg->flags.set(MessageFlag::PubSub);
|
|
|
|
|
|
|
|
postToThread([chan, msg = msg.release()] {
|
|
|
|
auto replaced = false;
|
|
|
|
LimitedQueueSnapshot<MessagePtr> snapshot =
|
|
|
|
chan->getMessageSnapshot();
|
|
|
|
int snapshotLength = snapshot.size();
|
|
|
|
|
|
|
|
// without parens it doesn't build on windows
|
|
|
|
int end = (std::max)(0, snapshotLength - 200);
|
|
|
|
|
|
|
|
for (int i = snapshotLength - 1; i >= end; --i)
|
|
|
|
{
|
|
|
|
auto &s = snapshot[i];
|
|
|
|
if (!s->flags.has(MessageFlag::PubSub) &&
|
|
|
|
s->timeoutUser == msg->timeoutUser)
|
|
|
|
{
|
|
|
|
chan->replaceMessage(s, msg);
|
|
|
|
replaced = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!replaced)
|
|
|
|
{
|
|
|
|
chan->addMessage(msg);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2018-04-15 15:09:31 +02:00
|
|
|
|
2022-03-19 12:02:29 +01:00
|
|
|
this->twitch->pubsub->signals_.moderation.userUnbanned.connect(
|
2018-08-06 21:17:03 +02:00
|
|
|
[&](const auto &action) {
|
2022-03-19 12:02:29 +01:00
|
|
|
auto chan = this->twitch->getChannelOrEmptyByID(action.roomID);
|
2018-04-27 18:35:31 +02:00
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (chan->isEmpty())
|
|
|
|
{
|
2018-08-06 21:17:03 +02:00
|
|
|
return;
|
|
|
|
}
|
2018-04-27 18:35:31 +02:00
|
|
|
|
2018-08-07 01:35:24 +02:00
|
|
|
auto msg = MessageBuilder(action).release();
|
2018-04-27 18:35:31 +02:00
|
|
|
|
2020-11-08 12:02:19 +01:00
|
|
|
postToThread([chan, msg] {
|
|
|
|
chan->addMessage(msg);
|
|
|
|
});
|
2018-08-06 21:17:03 +02:00
|
|
|
});
|
2018-04-15 15:09:31 +02:00
|
|
|
|
2022-05-07 17:22:39 +02:00
|
|
|
this->twitch->pubsub->signals_.moderation.autoModMessageCaught.connect(
|
|
|
|
[&](const auto &msg, const QString &channelID) {
|
2022-05-07 20:48:10 +02:00
|
|
|
auto chan = this->twitch->getChannelOrEmptyByID(channelID);
|
|
|
|
if (chan->isEmpty())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-05-07 17:22:39 +02:00
|
|
|
switch (msg.type)
|
2019-01-20 01:02:04 +01:00
|
|
|
{
|
2022-05-07 17:22:39 +02:00
|
|
|
case PubSubAutoModQueueMessage::Type::AutoModCaughtMessage: {
|
|
|
|
if (msg.status == "PENDING")
|
|
|
|
{
|
|
|
|
AutomodAction action(msg.data, channelID);
|
|
|
|
action.reason = QString("%1 level %2")
|
|
|
|
.arg(msg.contentCategory)
|
|
|
|
.arg(msg.contentLevel);
|
|
|
|
|
|
|
|
action.msgID = msg.messageID;
|
|
|
|
action.message = msg.messageText;
|
|
|
|
|
|
|
|
// this message also contains per-word automod data, which could be implemented
|
|
|
|
|
|
|
|
// extract sender data manually because Twitch loves not being consistent
|
|
|
|
QString senderDisplayName =
|
|
|
|
msg.senderUserDisplayName; // Might be transformed later
|
|
|
|
bool hasLocalizedName = false;
|
|
|
|
if (!msg.senderUserDisplayName.isEmpty())
|
|
|
|
{
|
|
|
|
// check for non-ascii display names
|
|
|
|
if (QString::compare(msg.senderUserDisplayName,
|
|
|
|
msg.senderUserLogin,
|
|
|
|
Qt::CaseInsensitive) != 0)
|
|
|
|
{
|
|
|
|
hasLocalizedName = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
QColor senderColor = msg.senderUserChatColor;
|
|
|
|
QString senderColor_;
|
|
|
|
if (!senderColor.isValid() &&
|
|
|
|
getSettings()->colorizeNicknames)
|
|
|
|
{
|
|
|
|
// color may be not present if user is a grey-name
|
|
|
|
senderColor = getRandomColor(msg.senderUserID);
|
|
|
|
}
|
|
|
|
|
|
|
|
// handle username style based on prefered setting
|
|
|
|
switch (getSettings()->usernameDisplayMode.getValue())
|
|
|
|
{
|
|
|
|
case UsernameDisplayMode::Username: {
|
|
|
|
if (hasLocalizedName)
|
|
|
|
{
|
|
|
|
senderDisplayName = msg.senderUserLogin;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case UsernameDisplayMode::LocalizedName: {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case UsernameDisplayMode::
|
|
|
|
UsernameAndLocalizedName: {
|
|
|
|
if (hasLocalizedName)
|
|
|
|
{
|
|
|
|
senderDisplayName = QString("%1(%2)").arg(
|
|
|
|
msg.senderUserLogin,
|
|
|
|
msg.senderUserDisplayName);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
action.target =
|
|
|
|
ActionUser{msg.senderUserID, msg.senderUserLogin,
|
|
|
|
senderDisplayName, senderColor};
|
2022-05-07 20:48:10 +02:00
|
|
|
postToThread([chan, action] {
|
|
|
|
const auto p = makeAutomodMessage(action);
|
|
|
|
chan->addMessage(p.first);
|
|
|
|
chan->addMessage(p.second);
|
|
|
|
});
|
2022-05-07 17:22:39 +02:00
|
|
|
}
|
|
|
|
// "ALLOWED" and "DENIED" statuses remain unimplemented
|
|
|
|
// They are versions of automod_message_(denied|approved) but for mods.
|
|
|
|
}
|
|
|
|
break;
|
2019-01-20 01:02:04 +01:00
|
|
|
|
2022-05-07 17:22:39 +02:00
|
|
|
case PubSubAutoModQueueMessage::Type::INVALID:
|
|
|
|
default: {
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2019-01-20 01:02:04 +01:00
|
|
|
});
|
|
|
|
|
2022-05-07 17:22:39 +02:00
|
|
|
this->twitch->pubsub->signals_.moderation.autoModMessageBlocked.connect(
|
2022-05-07 20:48:10 +02:00
|
|
|
[&](const auto &action) {
|
|
|
|
auto chan = this->twitch->getChannelOrEmptyByID(action.roomID);
|
|
|
|
if (chan->isEmpty())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
postToThread([chan, action] {
|
|
|
|
const auto p = makeAutomodMessage(action);
|
|
|
|
chan->addMessage(p.first);
|
|
|
|
chan->addMessage(p.second);
|
|
|
|
});
|
|
|
|
});
|
2022-05-07 17:22:39 +02:00
|
|
|
|
2022-03-19 12:02:29 +01:00
|
|
|
this->twitch->pubsub->signals_.moderation.automodUserMessage.connect(
|
2019-01-21 18:33:57 +01:00
|
|
|
[&](const auto &action) {
|
2022-03-19 12:02:29 +01:00
|
|
|
auto chan = this->twitch->getChannelOrEmptyByID(action.roomID);
|
2019-01-21 18:33:57 +01:00
|
|
|
|
|
|
|
if (chan->isEmpty())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto msg = MessageBuilder(action).release();
|
|
|
|
|
2020-11-08 12:02:19 +01:00
|
|
|
postToThread([chan, msg] {
|
|
|
|
chan->addMessage(msg);
|
|
|
|
});
|
2019-04-19 22:44:02 +02:00
|
|
|
chan->deleteMessage(msg->id);
|
2019-01-21 18:33:57 +01:00
|
|
|
});
|
|
|
|
|
2022-03-19 12:02:29 +01:00
|
|
|
this->twitch->pubsub->signals_.moderation.automodInfoMessage.connect(
|
2021-05-08 14:49:30 +02:00
|
|
|
[&](const auto &action) {
|
2022-03-19 12:02:29 +01:00
|
|
|
auto chan = this->twitch->getChannelOrEmptyByID(action.roomID);
|
2021-05-08 14:49:30 +02:00
|
|
|
|
|
|
|
if (chan->isEmpty())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
postToThread([chan, action] {
|
|
|
|
const auto p = makeAutomodInfoMessage(action);
|
|
|
|
chan->addMessage(p);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-03-19 12:02:29 +01:00
|
|
|
this->twitch->pubsub->signals_.pointReward.redeemed.connect(
|
|
|
|
[&](auto &data) {
|
2022-05-07 17:22:39 +02:00
|
|
|
QString channelId = data.value("channel_id").toString();
|
|
|
|
if (channelId.isEmpty())
|
2022-03-19 12:02:29 +01:00
|
|
|
{
|
|
|
|
qCDebug(chatterinoApp)
|
|
|
|
<< "Couldn't find channel id of point reward";
|
2022-05-07 17:22:39 +02:00
|
|
|
return;
|
2022-03-19 12:02:29 +01:00
|
|
|
}
|
2022-05-07 17:22:39 +02:00
|
|
|
|
|
|
|
auto chan = this->twitch->getChannelOrEmptyByID(channelId);
|
|
|
|
|
|
|
|
auto reward = ChannelPointReward(data);
|
|
|
|
|
|
|
|
postToThread([chan, reward] {
|
|
|
|
if (auto channel = dynamic_cast<TwitchChannel *>(chan.get()))
|
|
|
|
{
|
|
|
|
channel->addChannelPointReward(reward);
|
|
|
|
}
|
|
|
|
});
|
2022-03-19 12:02:29 +01:00
|
|
|
});
|
2020-08-08 15:37:22 +02:00
|
|
|
|
2022-03-19 12:02:29 +01:00
|
|
|
this->twitch->pubsub->start();
|
2018-04-15 15:09:31 +02:00
|
|
|
|
2018-04-27 22:11:19 +02:00
|
|
|
auto RequestModerationActions = [=]() {
|
2022-05-07 17:22:39 +02:00
|
|
|
this->twitch->pubsub->setAccount(
|
|
|
|
getApp()->accounts->twitch.getCurrent());
|
2018-08-06 21:17:03 +02:00
|
|
|
// TODO(pajlada): Unlisten to all authed topics instead of only
|
2022-03-19 12:02:29 +01:00
|
|
|
// moderation topics this->twitch->pubsub->UnlistenAllAuthedTopics();
|
2018-04-15 15:09:31 +02:00
|
|
|
|
2022-05-07 17:22:39 +02:00
|
|
|
this->twitch->pubsub->listenToWhispers();
|
2018-04-15 15:09:31 +02:00
|
|
|
};
|
|
|
|
|
2022-05-07 17:22:39 +02:00
|
|
|
this->accounts->twitch.currentUserChanged.connect(
|
|
|
|
[=] {
|
|
|
|
this->twitch->pubsub->unlistenAllModerationActions();
|
2022-05-08 12:56:40 +02:00
|
|
|
this->twitch->pubsub->unlistenAutomod();
|
2022-05-07 17:22:39 +02:00
|
|
|
this->twitch->pubsub->unlistenWhispers();
|
|
|
|
},
|
|
|
|
boost::signals2::at_front);
|
|
|
|
|
2018-05-26 20:26:25 +02:00
|
|
|
this->accounts->twitch.currentUserChanged.connect(RequestModerationActions);
|
2018-04-15 15:09:31 +02:00
|
|
|
|
|
|
|
RequestModerationActions();
|
2017-06-13 21:13:58 +02:00
|
|
|
}
|
|
|
|
|
2022-11-13 12:07:41 +01:00
|
|
|
void Application::initSeventvEventAPI()
|
|
|
|
{
|
|
|
|
if (!this->twitch->seventvEventAPI)
|
|
|
|
{
|
|
|
|
qCDebug(chatterinoSeventvEventAPI)
|
|
|
|
<< "Skipping initialization as the EventAPI is disabled";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this->twitch->seventvEventAPI->signals_.emoteAdded.connect(
|
|
|
|
[&](const auto &data) {
|
|
|
|
postToThread([this, data] {
|
|
|
|
this->twitch->forEachSeventvEmoteSet(
|
|
|
|
data.emoteSetID, [data](TwitchChannel &chan) {
|
|
|
|
chan.addSeventvEmote(data);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
this->twitch->seventvEventAPI->signals_.emoteUpdated.connect(
|
|
|
|
[&](const auto &data) {
|
|
|
|
postToThread([this, data] {
|
|
|
|
this->twitch->forEachSeventvEmoteSet(
|
|
|
|
data.emoteSetID, [data](TwitchChannel &chan) {
|
|
|
|
chan.updateSeventvEmote(data);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
this->twitch->seventvEventAPI->signals_.emoteRemoved.connect(
|
|
|
|
[&](const auto &data) {
|
|
|
|
postToThread([this, data] {
|
|
|
|
this->twitch->forEachSeventvEmoteSet(
|
|
|
|
data.emoteSetID, [data](TwitchChannel &chan) {
|
|
|
|
chan.removeSeventvEmote(data);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
this->twitch->seventvEventAPI->signals_.userUpdated.connect(
|
|
|
|
[&](const auto &data) {
|
|
|
|
this->twitch->forEachSeventvUser(data.userID,
|
|
|
|
[data](TwitchChannel &chan) {
|
|
|
|
chan.updateSeventvUser(data);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
this->twitch->seventvEventAPI->start();
|
|
|
|
}
|
|
|
|
|
2018-04-27 22:11:19 +02:00
|
|
|
Application *getApp()
|
|
|
|
{
|
2018-08-02 14:23:27 +02:00
|
|
|
assert(Application::instance != nullptr);
|
2018-01-05 02:38:00 +01:00
|
|
|
|
2021-05-01 12:47:33 +02:00
|
|
|
assertInGuiThread();
|
|
|
|
|
2018-08-02 14:23:27 +02:00
|
|
|
return Application::instance;
|
2017-12-22 14:44:31 +01:00
|
|
|
}
|
|
|
|
|
2022-05-22 15:00:18 +02:00
|
|
|
IApplication *getIApp()
|
|
|
|
{
|
|
|
|
assert(IApplication::instance != nullptr);
|
|
|
|
|
|
|
|
assertInGuiThread();
|
|
|
|
|
|
|
|
return IApplication::instance;
|
|
|
|
}
|
|
|
|
|
2017-06-13 21:13:58 +02:00
|
|
|
} // namespace chatterino
|