Add ability to highlight messages based on user badges (#1704)
Co-authored-by: Paweł <zneix@zneix.eu> Co-authored-by: 23rd <23rd@vivaldi.net> Co-authored-by: pajlada <rasmus.karlsson@pajlada.com>
This commit is contained in:
@@ -5,8 +5,14 @@
|
||||
#include <unordered_map>
|
||||
|
||||
#include "common/UniqueAccess.hpp"
|
||||
#include "messages/Image.hpp"
|
||||
#include "util/DisplayBadge.hpp"
|
||||
#include "util/QStringHash.hpp"
|
||||
|
||||
#include "pajlada/signals/signal.hpp"
|
||||
|
||||
#include <shared_mutex>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
struct Emote;
|
||||
@@ -17,13 +23,42 @@ class Paths;
|
||||
|
||||
class TwitchBadges
|
||||
{
|
||||
public:
|
||||
void loadTwitchBadges();
|
||||
using QIconPtr = std::shared_ptr<QIcon>;
|
||||
using ImagePtr = std::shared_ptr<Image>;
|
||||
using BadgeIconCallback = std::function<void(QString, const QIconPtr)>;
|
||||
|
||||
public:
|
||||
static TwitchBadges *instance();
|
||||
|
||||
// Get badge from name and version
|
||||
boost::optional<EmotePtr> badge(const QString &set,
|
||||
const QString &version) const;
|
||||
// Get first matching badge with name, regardless of version
|
||||
boost::optional<EmotePtr> badge(const QString &set) const;
|
||||
|
||||
void getBadgeIcon(const QString &name, BadgeIconCallback callback);
|
||||
void getBadgeIcon(const DisplayBadge &badge, BadgeIconCallback callback);
|
||||
void getBadgeIcons(const QList<DisplayBadge> &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<QString, QIconPtr> badgesMap_;
|
||||
|
||||
std::mutex queueMutex_;
|
||||
std::queue<QPair<QString, BadgeIconCallback>> callbackQueue_;
|
||||
|
||||
std::shared_mutex loadedMutex_;
|
||||
bool loaded_ = false;
|
||||
|
||||
UniqueAccess<
|
||||
std::unordered_map<QString, std::unordered_map<QString, EmotePtr>>>
|
||||
badgeSets_; // "bits": { "100": ... "500": ...
|
||||
|
||||
Reference in New Issue
Block a user