refactor: move event api initializations to TwitchIrcServer (#6198)

This commit is contained in:
pajlada
2025-05-10 15:17:00 +02:00
committed by GitHub
parent aa7630af71
commit e86ecf5d0b
6 changed files with 128 additions and 106 deletions
+2 -98
View File
@@ -289,8 +289,8 @@ void Application::initialize(Settings &settings, const Paths &paths)
}
this->twitchPubSub->initialize();
this->initBttvLiveUpdates();
this->initSeventvEventAPI();
this->twitch->initEventAPIs(this->bttvLiveUpdates.get(),
this->seventvEventAPI.get());
this->streamerMode->start();
@@ -613,102 +613,6 @@ void Application::initNm(const Paths &paths)
#endif
}
void Application::initBttvLiveUpdates()
{
if (!this->bttvLiveUpdates)
{
qCDebug(chatterinoBttv)
<< "Skipping initialization of Live Updates as it's disabled";
return;
}
// We can safely ignore these signal connections since the twitch object will always
// be destroyed before the Application
std::ignore = this->bttvLiveUpdates->signals_.emoteAdded.connect(
[&](const auto &data) {
auto chan = this->twitch->getChannelOrEmptyByID(data.channelID);
postToThread([chan, data] {
if (auto *channel = dynamic_cast<TwitchChannel *>(chan.get()))
{
channel->addBttvEmote(data);
}
});
});
std::ignore = this->bttvLiveUpdates->signals_.emoteUpdated.connect(
[&](const auto &data) {
auto chan = this->twitch->getChannelOrEmptyByID(data.channelID);
postToThread([chan, data] {
if (auto *channel = dynamic_cast<TwitchChannel *>(chan.get()))
{
channel->updateBttvEmote(data);
}
});
});
std::ignore = this->bttvLiveUpdates->signals_.emoteRemoved.connect(
[&](const auto &data) {
auto chan = this->twitch->getChannelOrEmptyByID(data.channelID);
postToThread([chan, data] {
if (auto *channel = dynamic_cast<TwitchChannel *>(chan.get()))
{
channel->removeBttvEmote(data);
}
});
});
this->bttvLiveUpdates->start();
}
void Application::initSeventvEventAPI()
{
if (!this->seventvEventAPI)
{
qCDebug(chatterinoSeventvEventAPI)
<< "Skipping initialization as the EventAPI is disabled";
return;
}
// We can safely ignore these signal connections since the twitch object will always
// be destroyed before the Application
std::ignore = this->seventvEventAPI->signals_.emoteAdded.connect(
[&](const auto &data) {
postToThread([this, data] {
this->twitch->forEachSeventvEmoteSet(
data.emoteSetID, [data](TwitchChannel &chan) {
chan.addSeventvEmote(data);
});
});
});
std::ignore = this->seventvEventAPI->signals_.emoteUpdated.connect(
[&](const auto &data) {
postToThread([this, data] {
this->twitch->forEachSeventvEmoteSet(
data.emoteSetID, [data](TwitchChannel &chan) {
chan.updateSeventvEmote(data);
});
});
});
std::ignore = this->seventvEventAPI->signals_.emoteRemoved.connect(
[&](const auto &data) {
postToThread([this, data] {
this->twitch->forEachSeventvEmoteSet(
data.emoteSetID, [data](TwitchChannel &chan) {
chan.removeSeventvEmote(data);
});
});
});
std::ignore = this->seventvEventAPI->signals_.userUpdated.connect(
[&](const auto &data) {
this->twitch->forEachSeventvUser(data.userID,
[data](TwitchChannel &chan) {
chan.updateSeventvUser(data);
});
});
this->seventvEventAPI->start();
}
IApplication *getApp()
{
assert(INSTANCE != nullptr);