Use New 7TV Cosmetics System (#4512)
* feat(seventv): use new cosmetics system * chore: add changelog entry * fix: old `clang-format` * fix: small suggestions pt1 * refactor: add 7tv api wrapper * fix: small clang-tidy things * fix: remove unused constants * fix: old clangtidy * refactor: rename * fix: increase interval to 60s * fix: newline * fix: Twitch * docs: add comment * fix: remove v2 badges endpoint * fix: deadlock This is actually really sad. * fix: remove api entry * fix: old clang-format * Sort functions in SeventvBadges.hpp/cpp * Remove unused vector include * Add comments to SeventvBadges.hpp functions * Rename `addBadge` to `registerBadge` * fix: cleanup eventloop * ci(test): add timeout --------- Co-authored-by: Felanbird <41973452+Felanbird@users.noreply.github.com> Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com>
This commit is contained in:
@@ -5,11 +5,11 @@
|
||||
#include "util/QStringHash.hpp"
|
||||
|
||||
#include <boost/optional.hpp>
|
||||
#include <QJsonObject>
|
||||
|
||||
#include <memory>
|
||||
#include <shared_mutex>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
@@ -19,18 +19,27 @@ using EmotePtr = std::shared_ptr<const Emote>;
|
||||
class SeventvBadges : public Singleton
|
||||
{
|
||||
public:
|
||||
void initialize(Settings &settings, Paths &paths) override;
|
||||
// Return the badge, if any, that is assigned to the user
|
||||
boost::optional<EmotePtr> getBadge(const UserId &id) const;
|
||||
|
||||
boost::optional<EmotePtr> getBadge(const UserId &id);
|
||||
// Assign the given badge to the user
|
||||
void assignBadgeToUser(const QString &badgeID, const UserId &userID);
|
||||
|
||||
// Remove the given badge from the user
|
||||
void clearBadgeFromUser(const QString &badgeID, const UserId &userID);
|
||||
|
||||
// Register a new known badge
|
||||
// The json object will contain all information about the badge, like its ID & its images
|
||||
void registerBadge(const QJsonObject &badgeJson);
|
||||
|
||||
private:
|
||||
void loadSeventvBadges();
|
||||
// Mutex for both `badgeMap_` and `knownBadges_`
|
||||
mutable std::shared_mutex mutex_;
|
||||
|
||||
// Mutex for both `badgeMap_` and `emotes_`
|
||||
std::shared_mutex mutex_;
|
||||
|
||||
std::unordered_map<QString, int> badgeMap_;
|
||||
std::vector<EmotePtr> emotes_;
|
||||
// user-id => badge
|
||||
std::unordered_map<QString, EmotePtr> badgeMap_;
|
||||
// badge-id => badge
|
||||
std::unordered_map<QString, EmotePtr> knownBadges_;
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
Reference in New Issue
Block a user