Skip to content

Commit

Permalink
fix: use static version of 7tv badges (#5674)
Browse files Browse the repository at this point in the history
  • Loading branch information
pajlada authored Oct 24, 2024
1 parent 9e8281b commit f66bc37
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
- Bugfix: Fixed event emotes not showing up in autocomplete and popups. (#5239, #5580, #5582, #5632)
- Bugfix: Fixed tab visibility being controllable in the emote popup. (#5530)
- Bugfix: Fixed account switch not being saved if no other settings were changed. (#5558)
- Bugfix: Fixed 7TV badges being inadvertently animated. (#5674)
- Bugfix: Fixed some tooltips not being readable. (#5578)
- Bugfix: Fixed log files being locked longer than needed. (#5592)
- Bugfix: Fixed global badges not showing in anonymous mode. (#5599)
Expand Down
2 changes: 1 addition & 1 deletion src/providers/seventv/SeventvBadges.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void SeventvBadges::registerBadge(const QJsonObject &badgeJson)

auto emote = Emote{
.name = EmoteName{},
.images = SeventvEmotes::createImageSet(badgeJson),
.images = SeventvEmotes::createImageSet(badgeJson, true),
.tooltip = Tooltip{badgeJson["tooltip"].toString()},
.homePage = Url{},
.id = EmoteId{badgeID},
Expand Down
39 changes: 29 additions & 10 deletions src/providers/seventv/SeventvEmotes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,18 @@ CreateEmoteResult createEmote(const QJsonObject &activeEmote,
? createAliasedTooltip(emoteName.string, baseEmoteName.string,
author.string, isGlobal)
: createTooltip(emoteName.string, author.string, isGlobal);
auto imageSet = SeventvEmotes::createImageSet(emoteData);

auto emote =
Emote({emoteName, imageSet, tooltip,
Url{EMOTE_LINK_FORMAT.arg(emoteId.string)}, zeroWidth, emoteId,
author, makeConditionedOptional(aliasedName, baseEmoteName)});
auto imageSet = SeventvEmotes::createImageSet(emoteData, false);

auto emote = Emote({
emoteName,
imageSet,
tooltip,
Url{EMOTE_LINK_FORMAT.arg(emoteId.string)},
zeroWidth,
emoteId,
author,
makeConditionedOptional(aliasedName, baseEmoteName),
});

return {emote, emoteId, emoteName, !emote.images.getImage1()->isEmpty()};
}
Expand Down Expand Up @@ -427,7 +433,8 @@ void SeventvEmotes::getEmoteSet(
});
}

ImageSet SeventvEmotes::createImageSet(const QJsonObject &emoteData)
ImageSet SeventvEmotes::createImageSet(const QJsonObject &emoteData,
bool useStatic)
{
auto host = emoteData["host"].toObject();
// "//cdn.7tv[...]"
Expand Down Expand Up @@ -463,9 +470,21 @@ ImageSet SeventvEmotes::createImageSet(const QJsonObject &emoteData)
baseWidth = width;
}

auto image = Image::fromUrl(
{QString("https:%1/%2").arg(baseUrl, file["name"].toString())},
scale, {static_cast<int>(width), file["height"].toInt(16)});
auto name = [&] {
if (useStatic)
{
auto staticName = file["static_name"].toString();
if (!staticName.isEmpty())
{
return staticName;
}
}
return file["name"].toString();
}();

auto image =
Image::fromUrl({QString("https:%1/%2").arg(baseUrl, name)}, scale,
{static_cast<int>(width), file["height"].toInt(16)});

sizes.at(nextSize) = image;
nextSize++;
Expand Down
4 changes: 3 additions & 1 deletion src/providers/seventv/SeventvEmotes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,10 @@ class SeventvEmotes final
* Creates an image set from a 7TV emote or badge.
*
* @param emoteData { host: { files: [], url } }
* @param useStatic use static version if possible
*/
static ImageSet createImageSet(const QJsonObject &emoteData);
static ImageSet createImageSet(const QJsonObject &emoteData,
bool useStatic);

private:
Atomic<std::shared_ptr<const EmoteMap>> global_;
Expand Down

0 comments on commit f66bc37

Please sign in to comment.