refactor: load Twitch emotes from Helix (#5239)
This commit is contained in:
@@ -1,10 +1,15 @@
|
||||
#include "providers/twitch/TwitchEmotes.hpp"
|
||||
|
||||
#include "common/Literals.hpp"
|
||||
#include "common/QLogging.hpp"
|
||||
#include "common/UniqueAccess.hpp"
|
||||
#include "messages/Emote.hpp"
|
||||
#include "messages/Image.hpp"
|
||||
#include "providers/twitch/api/Helix.hpp"
|
||||
#include "util/QStringHash.hpp"
|
||||
|
||||
#include <QStringBuilder>
|
||||
|
||||
namespace {
|
||||
|
||||
using namespace chatterino;
|
||||
@@ -399,6 +404,22 @@ qreal getEmote3xScaleFactor(const EmoteId &id)
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
using namespace literals;
|
||||
|
||||
QString TwitchEmoteSet::title() const
|
||||
{
|
||||
if (!this->owner || this->owner->name.isEmpty())
|
||||
{
|
||||
return "Twitch";
|
||||
}
|
||||
if (this->isBits)
|
||||
{
|
||||
return this->owner->name + " (Bits)";
|
||||
}
|
||||
|
||||
return this->owner->name;
|
||||
}
|
||||
|
||||
QString TwitchEmotes::cleanUpEmoteCode(const QString &dirtyEmoteCode)
|
||||
{
|
||||
auto cleanCode = dirtyEmoteCode;
|
||||
@@ -453,4 +474,44 @@ EmotePtr TwitchEmotes::getOrCreateEmote(const EmoteId &id,
|
||||
return shared;
|
||||
}
|
||||
|
||||
TwitchEmoteSetMeta getTwitchEmoteSetMeta(const HelixChannelEmote &emote)
|
||||
{
|
||||
// follower emotes are treated as sub emotes
|
||||
// A sub emote must have an owner or an emote-set id (otherwise it's a
|
||||
// global like "BopBop")
|
||||
bool isSub =
|
||||
(emote.type == u"subscriptions" || emote.type == u"follower") &&
|
||||
!(emote.ownerID.isEmpty() && emote.setID.isEmpty());
|
||||
bool isBits = emote.type == u"bitstier";
|
||||
bool isSubLike = isSub || isBits;
|
||||
|
||||
// A lot of emotes don't have their emote-set-id set, so we create a
|
||||
// virtual emote set that groups emotes by the owner.
|
||||
// Additionally, a lot of emote sets are small, so they're grouped together as globals.
|
||||
auto actualSetID = [&]() -> QString {
|
||||
if (!isSub && !isBits)
|
||||
{
|
||||
return u"x-c2-globals"_s;
|
||||
}
|
||||
|
||||
if (!emote.setID.isEmpty())
|
||||
{
|
||||
return emote.setID;
|
||||
}
|
||||
|
||||
if (isSub)
|
||||
{
|
||||
return TWITCH_SUB_EMOTE_SET_PREFIX % emote.ownerID;
|
||||
}
|
||||
// isBits
|
||||
return TWITCH_BIT_EMOTE_SET_PREFIX % emote.ownerID;
|
||||
}();
|
||||
|
||||
return {
|
||||
.setID = actualSetID,
|
||||
.isBits = isBits,
|
||||
.isSubLike = isSubLike,
|
||||
};
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
Reference in New Issue
Block a user