refactor: Make ChatterinoBadges a non-singleton

This commit is contained in:
Rasmus Karlsson 2024-01-18 00:23:23 +01:00 committed by pajlada
parent 5bf1a5a7dd
commit 54da03a5bd
4 changed files with 15 additions and 16 deletions

View file

@ -127,7 +127,6 @@ Application::Application(Settings &_settings, const Paths &paths,
, notifications(&this->emplace<NotificationController>()) , notifications(&this->emplace<NotificationController>())
, highlights(&this->emplace<HighlightController>()) , highlights(&this->emplace<HighlightController>())
, twitch(&this->emplace<TwitchIrcServer>()) , twitch(&this->emplace<TwitchIrcServer>())
, chatterinoBadges(&this->emplace<ChatterinoBadges>())
, ffzBadges(&this->emplace<FfzBadges>()) , ffzBadges(&this->emplace<FfzBadges>())
, seventvBadges(&this->emplace<SeventvBadges>()) , seventvBadges(&this->emplace<SeventvBadges>())
, userData(&this->emplace(new UserDataController(paths))) , userData(&this->emplace(new UserDataController(paths)))
@ -135,6 +134,7 @@ Application::Application(Settings &_settings, const Paths &paths,
, twitchLiveController(&this->emplace<TwitchLiveController>()) , twitchLiveController(&this->emplace<TwitchLiveController>())
, twitchPubSub(new PubSub(TWITCH_PUBSUB_URL)) , twitchPubSub(new PubSub(TWITCH_PUBSUB_URL))
, twitchBadges(new TwitchBadges) , twitchBadges(new TwitchBadges)
, chatterinoBadges(new ChatterinoBadges)
, logging(new Logging(_settings)) , logging(new Logging(_settings))
#ifdef CHATTERINO_HAVE_PLUGINS #ifdef CHATTERINO_HAVE_PLUGINS
, plugins(&this->emplace(new PluginController(paths))) , plugins(&this->emplace(new PluginController(paths)))
@ -156,6 +156,7 @@ void Application::fakeDtor()
{ {
this->twitchPubSub.reset(); this->twitchPubSub.reset();
this->twitchBadges.reset(); this->twitchBadges.reset();
this->chatterinoBadges.reset();
} }
void Application::initialize(Settings &settings, const Paths &paths) void Application::initialize(Settings &settings, const Paths &paths)
@ -339,6 +340,14 @@ TwitchBadges *Application::getTwitchBadges()
return this->twitchBadges.get(); return this->twitchBadges.get();
} }
ChatterinoBadges *Application::getChatterinoBadges()
{
assertInGuiThread();
assert(this->chatterinoBadges);
return this->chatterinoBadges.get();
}
ITwitchIrcServer *Application::getTwitch() ITwitchIrcServer *Application::getTwitch()
{ {
assertInGuiThread(); assertInGuiThread();

View file

@ -136,7 +136,6 @@ public:
NotificationController *const notifications{}; NotificationController *const notifications{};
HighlightController *const highlights{}; HighlightController *const highlights{};
TwitchIrcServer *const twitch{}; TwitchIrcServer *const twitch{};
ChatterinoBadges *const chatterinoBadges{};
FfzBadges *const ffzBadges{}; FfzBadges *const ffzBadges{};
SeventvBadges *const seventvBadges{}; SeventvBadges *const seventvBadges{};
UserDataController *const userData{}; UserDataController *const userData{};
@ -146,6 +145,7 @@ private:
TwitchLiveController *const twitchLiveController{}; TwitchLiveController *const twitchLiveController{};
std::unique_ptr<PubSub> twitchPubSub; std::unique_ptr<PubSub> twitchPubSub;
std::unique_ptr<TwitchBadges> twitchBadges; std::unique_ptr<TwitchBadges> twitchBadges;
std::unique_ptr<ChatterinoBadges> chatterinoBadges;
const std::unique_ptr<Logging> logging; const std::unique_ptr<Logging> logging;
public: public:
@ -225,12 +225,6 @@ public:
ITwitchIrcServer *getTwitch() override; ITwitchIrcServer *getTwitch() override;
PubSub *getTwitchPubSub() override; PubSub *getTwitchPubSub() override;
Logging *getChatLogger() override; Logging *getChatLogger() override;
ChatterinoBadges *getChatterinoBadges() override
{
assertInGuiThread();
return this->chatterinoBadges;
}
FfzBadges *getFfzBadges() override FfzBadges *getFfzBadges() override
{ {
assertInGuiThread(); assertInGuiThread();
@ -247,6 +241,7 @@ public:
ISoundController *getSound() override; ISoundController *getSound() override;
ITwitchLiveController *getTwitchLiveController() override; ITwitchLiveController *getTwitchLiveController() override;
TwitchBadges *getTwitchBadges() override; TwitchBadges *getTwitchBadges() override;
ChatterinoBadges *getChatterinoBadges() override;
ImageUploader *getImageUploader() override ImageUploader *getImageUploader() override
{ {
assertInGuiThread(); assertInGuiThread();

View file

@ -1,4 +1,4 @@
#include "ChatterinoBadges.hpp" #include "providers/chatterino/ChatterinoBadges.hpp"
#include "common/network/NetworkRequest.hpp" #include "common/network/NetworkRequest.hpp"
#include "common/network/NetworkResult.hpp" #include "common/network/NetworkResult.hpp"
@ -11,13 +11,10 @@
#include <QUrl> #include <QUrl>
namespace chatterino { namespace chatterino {
void ChatterinoBadges::initialize(Settings &settings, const Paths &paths)
{
this->loadChatterinoBadges();
}
ChatterinoBadges::ChatterinoBadges() ChatterinoBadges::ChatterinoBadges()
{ {
this->loadChatterinoBadges();
} }
std::optional<EmotePtr> ChatterinoBadges::getBadge(const UserId &id) std::optional<EmotePtr> ChatterinoBadges::getBadge(const UserId &id)

View file

@ -1,7 +1,6 @@
#pragma once #pragma once
#include "common/Aliases.hpp" #include "common/Aliases.hpp"
#include "common/Singleton.hpp"
#include "util/QStringHash.hpp" #include "util/QStringHash.hpp"
#include <memory> #include <memory>
@ -15,10 +14,9 @@ namespace chatterino {
struct Emote; struct Emote;
using EmotePtr = std::shared_ptr<const Emote>; using EmotePtr = std::shared_ptr<const Emote>;
class ChatterinoBadges : public Singleton class ChatterinoBadges
{ {
public: public:
void initialize(Settings &settings, const Paths &paths) override;
ChatterinoBadges(); ChatterinoBadges();
std::optional<EmotePtr> getBadge(const UserId &id); std::optional<EmotePtr> getBadge(const UserId &id);