refactor: Move Emotes to Application (#5120)

This commit is contained in:
pajlada 2024-01-21 14:20:21 +01:00 committed by GitHub
parent 65d3e73c5d
commit 5628605de4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 152 additions and 72 deletions

View file

@ -112,6 +112,7 @@
- Dev: Refactored the Image Uploader feature. (#4971)
- Dev: Refactored the SplitOverlay code. (#5082)
- Dev: Refactored the TwitchBadges structure, making it less of a singleton. (#5096)
- Dev: Refactored emotes out of TwitchIrcServer. (#5120)
- Dev: Refactored the ChatterinoBadges structure, making it less of a singleton. (#5103)
- Dev: Refactored the ColorProvider class a bit. (#5112)
- Dev: Moved the Network files to their own folder. (#5089)

View file

@ -191,6 +191,27 @@ public:
return this->updates_;
}
BttvEmotes *getBttvEmotes() override
{
assert(false && "EmptyApplication::getBttvEmotes was called without "
"being initialized");
return nullptr;
}
FfzEmotes *getFfzEmotes() override
{
assert(false && "EmptyApplication::getFfzEmotes was called without "
"being initialized");
return nullptr;
}
SeventvEmotes *getSeventvEmotes() override
{
assert(false && "EmptyApplication::getSeventvEmotes was called without "
"being initialized");
return nullptr;
}
private:
Paths paths_;
Args args_;

View file

@ -1,6 +1,9 @@
#pragma once
#include "mocks/Channel.hpp"
#include "providers/bttv/BttvEmotes.hpp"
#include "providers/ffz/FfzEmotes.hpp"
#include "providers/seventv/SeventvEmotes.hpp"
#include "providers/twitch/TwitchIrcServer.hpp"
namespace chatterino::mock {
@ -16,29 +19,11 @@ public:
{
}
const BttvEmotes &getBttvEmotes() const override
{
return this->bttv;
}
const FfzEmotes &getFfzEmotes() const override
{
return this->ffz;
}
const SeventvEmotes &getSeventvEmotes() const override
{
return this->seventv;
}
const IndirectChannel &getWatchingChannel() const override
{
return this->watchingChannel;
}
BttvEmotes bttv;
FfzEmotes ffz;
SeventvEmotes seventv;
ChannelPtr watchingChannelInner;
IndirectChannel watchingChannel;
};

View file

@ -11,7 +11,10 @@
#include "controllers/ignores/IgnoreController.hpp"
#include "controllers/notifications/NotificationController.hpp"
#include "controllers/sound/ISoundController.hpp"
#include "providers/bttv/BttvEmotes.hpp"
#include "providers/ffz/FfzEmotes.hpp"
#include "providers/seventv/SeventvAPI.hpp"
#include "providers/seventv/SeventvEmotes.hpp"
#include "providers/twitch/TwitchBadges.hpp"
#include "singletons/ImageUploader.hpp"
#ifdef CHATTERINO_HAVE_PLUGINS
@ -135,6 +138,9 @@ Application::Application(Settings &_settings, const Paths &paths,
, twitchPubSub(new PubSub(TWITCH_PUBSUB_URL))
, twitchBadges(new TwitchBadges)
, chatterinoBadges(new ChatterinoBadges)
, bttvEmotes(new BttvEmotes)
, ffzEmotes(new FfzEmotes)
, seventvEmotes(new SeventvEmotes)
, logging(new Logging(_settings))
#ifdef CHATTERINO_HAVE_PLUGINS
, plugins(&this->emplace(new PluginController(paths)))
@ -157,6 +163,9 @@ void Application::fakeDtor()
this->twitchPubSub.reset();
this->twitchBadges.reset();
this->chatterinoBadges.reset();
this->bttvEmotes.reset();
this->ffzEmotes.reset();
this->seventvEmotes.reset();
}
void Application::initialize(Settings &settings, const Paths &paths)
@ -481,6 +490,30 @@ Logging *Application::getChatLogger()
return this->logging.get();
}
BttvEmotes *Application::getBttvEmotes()
{
assertInGuiThread();
assert(this->bttvEmotes);
return this->bttvEmotes.get();
}
FfzEmotes *Application::getFfzEmotes()
{
assertInGuiThread();
assert(this->ffzEmotes);
return this->ffzEmotes.get();
}
SeventvEmotes *Application::getSeventvEmotes()
{
assertInGuiThread();
assert(this->seventvEmotes);
return this->seventvEmotes.get();
}
void Application::save()
{
for (auto &singleton : this->singletons_)

View file

@ -51,6 +51,9 @@ class SeventvBadges;
class ImageUploader;
class SeventvAPI;
class CrashHandler;
class BttvEmotes;
class FfzEmotes;
class SeventvEmotes;
class IApplication
{
@ -89,6 +92,9 @@ public:
virtual PluginController *getPlugins() = 0;
#endif
virtual Updates &getUpdates() = 0;
virtual BttvEmotes *getBttvEmotes() = 0;
virtual FfzEmotes *getFfzEmotes() = 0;
virtual SeventvEmotes *getSeventvEmotes() = 0;
};
class Application : public IApplication
@ -152,6 +158,9 @@ private:
std::unique_ptr<PubSub> twitchPubSub;
std::unique_ptr<TwitchBadges> twitchBadges;
std::unique_ptr<ChatterinoBadges> chatterinoBadges;
std::unique_ptr<BttvEmotes> bttvEmotes;
std::unique_ptr<FfzEmotes> ffzEmotes;
std::unique_ptr<SeventvEmotes> seventvEmotes;
const std::unique_ptr<Logging> logging;
#ifdef CHATTERINO_HAVE_PLUGINS
PluginController *const plugins{};
@ -199,6 +208,10 @@ public:
return this->updates;
}
BttvEmotes *getBttvEmotes() override;
FfzEmotes *getFfzEmotes() override;
SeventvEmotes *getSeventvEmotes() override;
pajlada::Signals::NoArgSignal streamerModeChanged;
private:

View file

@ -7,6 +7,8 @@
#include "messages/Message.hpp"
#include "messages/MessageBuilder.hpp"
#include "messages/MessageElement.hpp"
#include "providers/bttv/BttvEmotes.hpp"
#include "providers/ffz/FfzEmotes.hpp"
#include "providers/irc/IrcChannel2.hpp"
#include "providers/irc/IrcServer.hpp"
#include "providers/twitch/api/Helix.hpp"
@ -105,8 +107,8 @@ bool appendWhisperMessageWordsLocally(const QStringList &words)
const auto &acc = app->getAccounts()->twitch.getCurrent();
const auto &accemotes = *acc->accessEmotes();
const auto &bttvemotes = app->twitch->getBttvEmotes();
const auto &ffzemotes = app->twitch->getFfzEmotes();
const auto *bttvemotes = app->getBttvEmotes();
const auto *ffzemotes = app->getFfzEmotes();
auto flags = MessageElementFlags();
auto emote = std::optional<EmotePtr>{};
for (int i = 2; i < words.length(); i++)
@ -122,14 +124,15 @@ bool appendWhisperMessageWordsLocally(const QStringList &words)
} // Twitch emote
{ // bttv/ffz emote
if ((emote = bttvemotes.emote({words[i]})))
if ((emote = bttvemotes->emote({words[i]})))
{
flags = MessageElementFlag::BttvEmote;
}
else if ((emote = ffzemotes.emote({words[i]})))
else if ((emote = ffzemotes->emote({words[i]})))
{
flags = MessageElementFlag::FfzEmote;
}
// TODO: Load 7tv global emotes
if (emote)
{
b.emplace<EmoteElement>(*emote, flags);

View file

@ -3,7 +3,10 @@
#include "Application.hpp"
#include "controllers/accounts/AccountController.hpp"
#include "controllers/completion/sources/Helpers.hpp"
#include "providers/bttv/BttvEmotes.hpp"
#include "providers/emoji/Emojis.hpp"
#include "providers/ffz/FfzEmotes.hpp"
#include "providers/seventv/SeventvEmotes.hpp"
#include "providers/twitch/TwitchAccount.hpp"
#include "providers/twitch/TwitchChannel.hpp"
#include "providers/twitch/TwitchIrcServer.hpp"
@ -127,15 +130,15 @@ void EmoteSource::initializeFromChannel(const Channel *channel)
}
}
if (auto bttvG = app->getTwitch()->getBttvEmotes().emotes())
if (auto bttvG = app->getBttvEmotes()->emotes())
{
addEmotes(emotes, *bttvG, "Global BetterTTV");
}
if (auto ffzG = app->getTwitch()->getFfzEmotes().emotes())
if (auto ffzG = app->getFfzEmotes()->emotes())
{
addEmotes(emotes, *ffzG, "Global FrankerFaceZ");
}
if (auto seventvG = app->getTwitch()->getSeventvEmotes().globalEmotes())
if (auto seventvG = app->getSeventvEmotes()->globalEmotes())
{
addEmotes(emotes, *seventvG, "Global 7TV");
}

View file

@ -18,6 +18,7 @@
#include "providers/bttv/BttvEmotes.hpp"
#include "providers/bttv/BttvLiveUpdates.hpp"
#include "providers/bttv/liveupdates/BttvLiveUpdateMessages.hpp"
#include "providers/ffz/FfzEmotes.hpp"
#include "providers/recentmessages/Api.hpp"
#include "providers/seventv/eventapi/Dispatch.hpp"
#include "providers/seventv/SeventvAPI.hpp"

View file

@ -7,8 +7,11 @@
#include "controllers/accounts/AccountController.hpp"
#include "messages/Message.hpp"
#include "messages/MessageBuilder.hpp"
#include "providers/bttv/BttvEmotes.hpp"
#include "providers/bttv/BttvLiveUpdates.hpp"
#include "providers/ffz/FfzEmotes.hpp"
#include "providers/seventv/eventapi/Subscription.hpp"
#include "providers/seventv/SeventvEmotes.hpp"
#include "providers/seventv/SeventvEventAPI.hpp"
#include "providers/twitch/api/Helix.hpp"
#include "providers/twitch/ChannelPointReward.hpp"
@ -517,19 +520,6 @@ void TwitchIrcServer::onReplySendRequested(TwitchChannel *channel,
sent = true;
}
const BttvEmotes &TwitchIrcServer::getBttvEmotes() const
{
return this->bttv;
}
const FfzEmotes &TwitchIrcServer::getFfzEmotes() const
{
return this->ffz;
}
const SeventvEmotes &TwitchIrcServer::getSeventvEmotes() const
{
return this->seventv_;
}
const IndirectChannel &TwitchIrcServer::getWatchingChannel() const
{
return this->watchingChannel;
@ -537,7 +527,7 @@ const IndirectChannel &TwitchIrcServer::getWatchingChannel() const
void TwitchIrcServer::reloadBTTVGlobalEmotes()
{
this->bttv.loadEmotes();
getIApp()->getBttvEmotes()->loadEmotes();
}
void TwitchIrcServer::reloadAllBTTVChannelEmotes()
@ -552,7 +542,7 @@ void TwitchIrcServer::reloadAllBTTVChannelEmotes()
void TwitchIrcServer::reloadFFZGlobalEmotes()
{
this->ffz.loadEmotes();
getIApp()->getFfzEmotes()->loadEmotes();
}
void TwitchIrcServer::reloadAllFFZChannelEmotes()
@ -567,7 +557,7 @@ void TwitchIrcServer::reloadAllFFZChannelEmotes()
void TwitchIrcServer::reloadSevenTVGlobalEmotes()
{
this->seventv_.loadGlobalEmotes();
getIApp()->getSeventvEmotes()->loadGlobalEmotes();
}
void TwitchIrcServer::reloadAllSevenTVChannelEmotes()

View file

@ -3,10 +3,7 @@
#include "common/Atomic.hpp"
#include "common/Channel.hpp"
#include "common/Singleton.hpp"
#include "providers/bttv/BttvEmotes.hpp"
#include "providers/ffz/FfzEmotes.hpp"
#include "providers/irc/AbstractIrcServer.hpp"
#include "providers/seventv/SeventvEmotes.hpp"
#include <pajlada/signals/signalholder.hpp>
@ -21,15 +18,15 @@ class Paths;
class TwitchChannel;
class BttvLiveUpdates;
class SeventvEventAPI;
class BttvEmotes;
class FfzEmotes;
class SeventvEmotes;
class ITwitchIrcServer
{
public:
virtual ~ITwitchIrcServer() = default;
virtual const BttvEmotes &getBttvEmotes() const = 0;
virtual const FfzEmotes &getFfzEmotes() const = 0;
virtual const SeventvEmotes &getSeventvEmotes() const = 0;
virtual const IndirectChannel &getWatchingChannel() const = 0;
// Update this interface with TwitchIrcServer methods as needed
@ -82,9 +79,6 @@ public:
std::unique_ptr<BttvLiveUpdates> bttvLiveUpdates;
std::unique_ptr<SeventvEventAPI> seventvEventAPI;
const BttvEmotes &getBttvEmotes() const override;
const FfzEmotes &getFfzEmotes() const override;
const SeventvEmotes &getSeventvEmotes() const override;
const IndirectChannel &getWatchingChannel() const override;
protected:
@ -116,10 +110,6 @@ private:
std::chrono::steady_clock::time_point lastErrorTimeSpeed_;
std::chrono::steady_clock::time_point lastErrorTimeAmount_;
BttvEmotes bttv;
FfzEmotes ffz;
SeventvEmotes seventv_;
pajlada::Signals::SignalHolder signalHolder_;
};

View file

@ -13,10 +13,13 @@
#include "messages/Image.hpp"
#include "messages/Message.hpp"
#include "messages/MessageThread.hpp"
#include "providers/bttv/BttvEmotes.hpp"
#include "providers/chatterino/ChatterinoBadges.hpp"
#include "providers/colors/ColorProvider.hpp"
#include "providers/ffz/FfzBadges.hpp"
#include "providers/ffz/FfzEmotes.hpp"
#include "providers/seventv/SeventvBadges.hpp"
#include "providers/seventv/SeventvEmotes.hpp"
#include "providers/twitch/api/Helix.hpp"
#include "providers/twitch/ChannelPointReward.hpp"
#include "providers/twitch/PubSubActions.hpp"
@ -1140,9 +1143,9 @@ Outcome TwitchMessageBuilder::tryAppendEmote(const EmoteName &name)
{
auto *app = getIApp();
const auto &globalBttvEmotes = app->getTwitch()->getBttvEmotes();
const auto &globalFfzEmotes = app->getTwitch()->getFfzEmotes();
const auto &globalSeventvEmotes = app->getTwitch()->getSeventvEmotes();
const auto *globalBttvEmotes = app->getBttvEmotes();
const auto *globalFfzEmotes = app->getFfzEmotes();
const auto *globalSeventvEmotes = app->getSeventvEmotes();
auto flags = MessageElementFlags();
auto emote = std::optional<EmotePtr>{};
@ -1170,16 +1173,16 @@ Outcome TwitchMessageBuilder::tryAppendEmote(const EmoteName &name)
flags = MessageElementFlag::SevenTVEmote;
zeroWidth = emote.value()->zeroWidth;
}
else if ((emote = globalFfzEmotes.emote(name)))
else if ((emote = globalFfzEmotes->emote(name)))
{
flags = MessageElementFlag::FfzEmote;
}
else if ((emote = globalBttvEmotes.emote(name)))
else if ((emote = globalBttvEmotes->emote(name)))
{
flags = MessageElementFlag::BttvEmote;
zeroWidth = zeroWidthEmotes.contains(name.string);
}
else if ((emote = globalSeventvEmotes.globalEmote(name)))
else if ((emote = globalSeventvEmotes->globalEmote(name)))
{
flags = MessageElementFlag::SevenTVEmote;
zeroWidth = emote.value()->zeroWidth;

View file

@ -9,9 +9,11 @@
#include "messages/Message.hpp"
#include "messages/MessageBuilder.hpp"
#include "messages/MessageElement.hpp"
#include "providers/bttv/BttvEmotes.hpp"
#include "providers/ffz/FfzEmotes.hpp"
#include "providers/seventv/SeventvEmotes.hpp"
#include "providers/twitch/TwitchAccount.hpp"
#include "providers/twitch/TwitchChannel.hpp"
#include "providers/twitch/TwitchIrcServer.hpp"
#include "singletons/Emotes.hpp"
#include "singletons/Settings.hpp"
#include "singletons/WindowManager.hpp"
@ -404,19 +406,18 @@ void EmotePopup::loadChannel(ChannelPtr channel)
// global
if (Settings::instance().enableBTTVGlobalEmotes)
{
addEmotes(*globalChannel, *getApp()->twitch->getBttvEmotes().emotes(),
addEmotes(*globalChannel, *getApp()->getBttvEmotes()->emotes(),
"BetterTTV", MessageElementFlag::BttvEmote);
}
if (Settings::instance().enableFFZGlobalEmotes)
{
addEmotes(*globalChannel, *getApp()->twitch->getFfzEmotes().emotes(),
addEmotes(*globalChannel, *getApp()->getFfzEmotes()->emotes(),
"FrankerFaceZ", MessageElementFlag::FfzEmote);
}
if (Settings::instance().enableSevenTVGlobalEmotes)
{
addEmotes(*globalChannel,
*getApp()->twitch->getSeventvEmotes().globalEmotes(), "7TV",
MessageElementFlag::SevenTVEmote);
addEmotes(*globalChannel, *getApp()->getSeventvEmotes()->globalEmotes(),
"7TV", MessageElementFlag::SevenTVEmote);
}
// channel
@ -495,11 +496,11 @@ void EmotePopup::filterTwitchEmotes(std::shared_ptr<Channel> searchChannel,
}
auto bttvGlobalEmotes =
filterEmoteMap(searchText, getApp()->twitch->getBttvEmotes().emotes());
filterEmoteMap(searchText, getIApp()->getBttvEmotes()->emotes());
auto ffzGlobalEmotes =
filterEmoteMap(searchText, getApp()->twitch->getFfzEmotes().emotes());
filterEmoteMap(searchText, getIApp()->getFfzEmotes()->emotes());
auto seventvGlobalEmotes = filterEmoteMap(
searchText, getApp()->twitch->getSeventvEmotes().globalEmotes());
searchText, getIApp()->getSeventvEmotes()->globalEmotes());
// twitch
addTwitchEmoteSets(twitchGlobalEmotes, *searchChannel, *searchChannel,

View file

@ -49,9 +49,27 @@ public:
return &this->emotes;
}
BttvEmotes *getBttvEmotes() override
{
return &this->bttvEmotes;
}
FfzEmotes *getFfzEmotes() override
{
return &this->ffzEmotes;
}
SeventvEmotes *getSeventvEmotes() override
{
return &this->seventvEmotes;
}
AccountController accounts;
mock::MockTwitchIrcServer twitch;
Emotes emotes;
BttvEmotes bttvEmotes;
FfzEmotes ffzEmotes;
SeventvEmotes seventvEmotes;
};
} // namespace
@ -154,18 +172,18 @@ private:
addEmote(*bttvEmotes, ":-)");
addEmote(*bttvEmotes, "B-)");
addEmote(*bttvEmotes, "Clap");
this->mockApplication->twitch.bttv.setEmotes(std::move(bttvEmotes));
this->mockApplication->bttvEmotes.setEmotes(std::move(bttvEmotes));
auto ffzEmotes = std::make_shared<EmoteMap>();
addEmote(*ffzEmotes, "LilZ");
addEmote(*ffzEmotes, "ManChicken");
addEmote(*ffzEmotes, "CatBag");
this->mockApplication->twitch.ffz.setEmotes(std::move(ffzEmotes));
this->mockApplication->ffzEmotes.setEmotes(std::move(ffzEmotes));
auto seventvEmotes = std::make_shared<EmoteMap>();
addEmote(*seventvEmotes, "Clap");
addEmote(*seventvEmotes, "Clap2");
this->mockApplication->twitch.seventv.setGlobalEmotes(
this->mockApplication->seventvEmotes.setGlobalEmotes(
std::move(seventvEmotes));
}

View file

@ -70,6 +70,21 @@ public:
return &this->highlights;
}
BttvEmotes *getBttvEmotes() override
{
return &this->bttvEmotes;
}
FfzEmotes *getFfzEmotes() override
{
return &this->ffzEmotes;
}
SeventvEmotes *getSeventvEmotes() override
{
return &this->seventvEmotes;
}
AccountController accounts;
Emotes emotes;
mock::UserDataController userData;
@ -78,6 +93,9 @@ public:
FfzBadges ffzBadges;
SeventvBadges seventvBadges;
HighlightController highlights;
BttvEmotes bttvEmotes;
FfzEmotes ffzEmotes;
SeventvEmotes seventvEmotes;
};
} // namespace