mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
parent
1c0ed6b1aa
commit
f94b44188d
|
@ -21,6 +21,14 @@ namespace {
|
||||||
return {urlTemplate.replace("{{id}}", id.string)
|
return {urlTemplate.replace("{{id}}", id.string)
|
||||||
.replace("{{image}}", emoteScale)};
|
.replace("{{image}}", emoteScale)};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Url getEmoteLinkV3(const EmoteId &id, const QString &emoteScale)
|
||||||
|
{
|
||||||
|
static const QString urlTemplate(
|
||||||
|
"https://cdn.betterttv.net/emote/%1/%2");
|
||||||
|
|
||||||
|
return {urlTemplate.arg(id.string, emoteScale)};
|
||||||
|
}
|
||||||
std::pair<Outcome, EmoteMap> parseGlobalEmotes(
|
std::pair<Outcome, EmoteMap> parseGlobalEmotes(
|
||||||
const QJsonObject &jsonRoot, const EmoteMap ¤tEmotes)
|
const QJsonObject &jsonRoot, const EmoteMap ¤tEmotes)
|
||||||
{
|
{
|
||||||
|
@ -60,9 +68,9 @@ namespace {
|
||||||
std::pair<Outcome, EmoteMap> parseChannelEmotes(const QJsonObject &jsonRoot)
|
std::pair<Outcome, EmoteMap> parseChannelEmotes(const QJsonObject &jsonRoot)
|
||||||
{
|
{
|
||||||
auto emotes = EmoteMap();
|
auto emotes = EmoteMap();
|
||||||
auto jsonEmotes = jsonRoot.value("emotes").toArray();
|
|
||||||
auto urlTemplate = "https:" + jsonRoot.value("urlTemplate").toString();
|
|
||||||
|
|
||||||
|
auto innerParse = [&jsonRoot, &emotes](const char *key) {
|
||||||
|
auto jsonEmotes = jsonRoot.value(key).toArray();
|
||||||
for (auto jsonEmote_ : jsonEmotes)
|
for (auto jsonEmote_ : jsonEmotes)
|
||||||
{
|
{
|
||||||
auto jsonEmote = jsonEmote_.toObject();
|
auto jsonEmote = jsonEmote_.toObject();
|
||||||
|
@ -74,14 +82,19 @@ namespace {
|
||||||
auto emote = Emote(
|
auto emote = Emote(
|
||||||
{name,
|
{name,
|
||||||
ImageSet{
|
ImageSet{
|
||||||
Image::fromUrl(getEmoteLink(urlTemplate, id, "1x"), 1),
|
Image::fromUrl(getEmoteLinkV3(id, "1x"), 1),
|
||||||
Image::fromUrl(getEmoteLink(urlTemplate, id, "2x"), 0.5),
|
Image::fromUrl(getEmoteLinkV3(id, "2x"), 0.5),
|
||||||
Image::fromUrl(getEmoteLink(urlTemplate, id, "3x"), 0.25)},
|
Image::fromUrl(getEmoteLinkV3(id, "3x"), 0.25),
|
||||||
|
},
|
||||||
Tooltip{name.string + "<br />Channel BetterTTV Emote"},
|
Tooltip{name.string + "<br />Channel BetterTTV Emote"},
|
||||||
Url{"https://manage.betterttv.net/emotes/" + id.string}});
|
Url{"https://manage.betterttv.net/emotes/" + id.string}});
|
||||||
|
|
||||||
emotes[name] = cachedOrMake(std::move(emote), id);
|
emotes[name] = cachedOrMake(std::move(emote), id);
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
innerParse("channelEmotes");
|
||||||
|
innerParse("sharedEmotes");
|
||||||
|
|
||||||
return {Success, std::move(emotes)};
|
return {Success, std::move(emotes)};
|
||||||
}
|
}
|
||||||
|
@ -125,10 +138,10 @@ void BttvEmotes::loadEmotes()
|
||||||
.execute();
|
.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BttvEmotes::loadChannel(const QString &channelName,
|
void BttvEmotes::loadChannel(const QString &channelId,
|
||||||
std::function<void(EmoteMap &&)> callback)
|
std::function<void(EmoteMap &&)> callback)
|
||||||
{
|
{
|
||||||
NetworkRequest(QString(bttvChannelEmoteApiUrl) + channelName)
|
NetworkRequest(QString(bttvChannelEmoteApiUrl) + channelId)
|
||||||
.timeout(3000)
|
.timeout(3000)
|
||||||
.onSuccess([callback = std::move(callback)](auto result) -> Outcome {
|
.onSuccess([callback = std::move(callback)](auto result) -> Outcome {
|
||||||
auto pair = parseChannelEmotes(result.parseJson());
|
auto pair = parseChannelEmotes(result.parseJson());
|
||||||
|
|
|
@ -16,7 +16,7 @@ class BttvEmotes final
|
||||||
static constexpr const char *globalEmoteApiUrl =
|
static constexpr const char *globalEmoteApiUrl =
|
||||||
"https://api.betterttv.net/2/emotes";
|
"https://api.betterttv.net/2/emotes";
|
||||||
static constexpr const char *bttvChannelEmoteApiUrl =
|
static constexpr const char *bttvChannelEmoteApiUrl =
|
||||||
"https://api.betterttv.net/2/channels/";
|
"https://api.betterttv.net/3/cached/users/twitch/";
|
||||||
|
|
||||||
public:
|
public:
|
||||||
BttvEmotes();
|
BttvEmotes();
|
||||||
|
@ -24,7 +24,7 @@ public:
|
||||||
std::shared_ptr<const EmoteMap> emotes() const;
|
std::shared_ptr<const EmoteMap> emotes() const;
|
||||||
boost::optional<EmotePtr> emote(const EmoteName &name) const;
|
boost::optional<EmotePtr> emote(const EmoteName &name) const;
|
||||||
void loadEmotes();
|
void loadEmotes();
|
||||||
static void loadChannel(const QString &channelName,
|
static void loadChannel(const QString &channelId,
|
||||||
std::function<void(EmoteMap &&)> callback);
|
std::function<void(EmoteMap &&)> callback);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -114,6 +114,7 @@ TwitchChannel::TwitchChannel(const QString &name,
|
||||||
this->refreshBadges();
|
this->refreshBadges();
|
||||||
this->refreshCheerEmotes();
|
this->refreshCheerEmotes();
|
||||||
this->refreshFFZChannelEmotes();
|
this->refreshFFZChannelEmotes();
|
||||||
|
this->refreshBTTVChannelEmotes();
|
||||||
});
|
});
|
||||||
|
|
||||||
// timers
|
// timers
|
||||||
|
@ -136,7 +137,6 @@ TwitchChannel::TwitchChannel(const QString &name,
|
||||||
void TwitchChannel::initialize()
|
void TwitchChannel::initialize()
|
||||||
{
|
{
|
||||||
this->refreshChatters();
|
this->refreshChatters();
|
||||||
this->refreshBTTVChannelEmotes();
|
|
||||||
this->refreshBadges();
|
this->refreshBadges();
|
||||||
this->ffzCustomModBadge_.loadCustomModBadge();
|
this->ffzCustomModBadge_.loadCustomModBadge();
|
||||||
}
|
}
|
||||||
|
@ -154,7 +154,7 @@ bool TwitchChannel::canSendMessage() const
|
||||||
void TwitchChannel::refreshBTTVChannelEmotes()
|
void TwitchChannel::refreshBTTVChannelEmotes()
|
||||||
{
|
{
|
||||||
BttvEmotes::loadChannel(
|
BttvEmotes::loadChannel(
|
||||||
this->getName(), [this, weak = weakOf<Channel>(this)](auto &&emoteMap) {
|
this->roomId(), [this, weak = weakOf<Channel>(this)](auto &&emoteMap) {
|
||||||
if (auto shared = weak.lock())
|
if (auto shared = weak.lock())
|
||||||
this->bttvEmotes_.set(
|
this->bttvEmotes_.set(
|
||||||
std::make_shared<EmoteMap>(std::move(emoteMap)));
|
std::make_shared<EmoteMap>(std::move(emoteMap)));
|
||||||
|
|
Loading…
Reference in a new issue