#pragma once #include #include #include #include "common/UniqueAccess.hpp" #include "messages/Image.hpp" #include "util/DisplayBadge.hpp" #include "util/QStringHash.hpp" #include "pajlada/signals/signal.hpp" #include namespace chatterino { struct Emote; using EmotePtr = std::shared_ptr; class Settings; class Paths; class TwitchBadges { using QIconPtr = std::shared_ptr; using ImagePtr = std::shared_ptr; using BadgeIconCallback = std::function; public: static TwitchBadges *instance(); // Get badge from name and version boost::optional badge(const QString &set, const QString &version) const; // Get first matching badge with name, regardless of version boost::optional badge(const QString &set) const; void getBadgeIcon(const QString &name, BadgeIconCallback callback); void getBadgeIcon(const DisplayBadge &badge, BadgeIconCallback callback); void getBadgeIcons(const QList &badges, BadgeIconCallback callback); private: static TwitchBadges *instance_; TwitchBadges(); void loadTwitchBadges(); void loaded(); void loadEmoteImage(const QString &name, ImagePtr image, BadgeIconCallback &&callback); std::shared_mutex badgesMutex_; QMap badgesMap_; std::mutex queueMutex_; std::queue> callbackQueue_; std::shared_mutex loadedMutex_; bool loaded_ = false; UniqueAccess< std::unordered_map>> badgeSets_; // "bits": { "100": ... "500": ... }; } // namespace chatterino