fix: properly display global badges for anon users (#5599)
This commit is contained in:
@@ -79,59 +79,59 @@ void TwitchBadges::loadTwitchBadges()
|
||||
break;
|
||||
}
|
||||
qCWarning(chatterinoTwitch) << errorMessage;
|
||||
QFile file(":/twitch-badges.json");
|
||||
if (!file.open(QFile::ReadOnly))
|
||||
{
|
||||
// Despite erroring out, we still want to reach the same point
|
||||
// Loaded should still be set to true to not build up an endless queue, and the quuee should still be flushed.
|
||||
qCWarning(chatterinoTwitch)
|
||||
<< "Error loading Twitch Badges from the local backup file";
|
||||
this->loaded();
|
||||
return;
|
||||
}
|
||||
auto bytes = file.readAll();
|
||||
auto doc = QJsonDocument::fromJson(bytes);
|
||||
|
||||
this->parseTwitchBadges(doc.object());
|
||||
|
||||
this->loaded();
|
||||
this->loadLocalBadges();
|
||||
});
|
||||
}
|
||||
|
||||
void TwitchBadges::parseTwitchBadges(QJsonObject root)
|
||||
void TwitchBadges::loadLocalBadges()
|
||||
{
|
||||
auto badgeSets = this->badgeSets_.access();
|
||||
|
||||
auto jsonSets = root.value("badge_sets").toObject();
|
||||
for (auto sIt = jsonSets.begin(); sIt != jsonSets.end(); ++sIt)
|
||||
QFile file(":/twitch-badges.json");
|
||||
if (!file.open(QFile::ReadOnly))
|
||||
{
|
||||
auto key = sIt.key();
|
||||
auto versions = sIt.value().toObject().value("versions").toObject();
|
||||
// Despite erroring out, we still want to reach the same point
|
||||
// Loaded should still be set to true to not build up an endless queue, and the quuee should still be flushed.
|
||||
qCWarning(chatterinoTwitch)
|
||||
<< "Error loading Twitch Badges from the local backup file";
|
||||
this->loaded();
|
||||
return;
|
||||
}
|
||||
auto bytes = file.readAll();
|
||||
auto doc = QJsonDocument::fromJson(bytes);
|
||||
|
||||
for (auto vIt = versions.begin(); vIt != versions.end(); ++vIt)
|
||||
{
|
||||
const auto &root = doc.object();
|
||||
auto badgeSets = this->badgeSets_.access();
|
||||
|
||||
for (auto setIt = root.begin(); setIt != root.end(); setIt++)
|
||||
{
|
||||
auto versionObj = vIt.value().toObject();
|
||||
auto emote = Emote{
|
||||
.name = {""},
|
||||
.images =
|
||||
ImageSet{
|
||||
Image::fromUrl(
|
||||
{versionObj.value("image_url_1x").toString()}, 1,
|
||||
BADGE_BASE_SIZE),
|
||||
Image::fromUrl(
|
||||
{versionObj.value("image_url_2x").toString()}, .5,
|
||||
BADGE_BASE_SIZE * 2),
|
||||
Image::fromUrl(
|
||||
{versionObj.value("image_url_4x").toString()}, .25,
|
||||
BADGE_BASE_SIZE * 4),
|
||||
},
|
||||
.tooltip = Tooltip{versionObj.value("title").toString()},
|
||||
.homePage = Url{versionObj.value("click_url").toString()},
|
||||
};
|
||||
auto key = setIt.key();
|
||||
|
||||
(*badgeSets)[key][vIt.key()] = std::make_shared<Emote>(emote);
|
||||
for (auto versionValue : setIt.value().toArray())
|
||||
{
|
||||
const auto versionObj = versionValue.toObject();
|
||||
auto id = versionObj["id"].toString();
|
||||
auto baseImage = versionObj["image"].toString();
|
||||
auto emote = Emote{
|
||||
.name = {},
|
||||
.images =
|
||||
ImageSet{
|
||||
Image::fromUrl({baseImage + '1'}, 1,
|
||||
BADGE_BASE_SIZE),
|
||||
Image::fromUrl({baseImage + '2'}, .5,
|
||||
BADGE_BASE_SIZE * 2),
|
||||
Image::fromUrl({baseImage + '3'}, .25,
|
||||
BADGE_BASE_SIZE * 4),
|
||||
},
|
||||
.tooltip = Tooltip{versionObj["title"].toString()},
|
||||
.homePage = Url{versionObj["url"].toString()},
|
||||
};
|
||||
|
||||
(*badgeSets)[key][id] = std::make_shared<Emote>(emote);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this->loaded();
|
||||
}
|
||||
|
||||
void TwitchBadges::loaded()
|
||||
|
||||
@@ -46,7 +46,9 @@ public:
|
||||
void loadTwitchBadges();
|
||||
|
||||
private:
|
||||
void parseTwitchBadges(QJsonObject root);
|
||||
/// Loads the badges shipped with Chatterino (twitch-badges.json)
|
||||
void loadLocalBadges();
|
||||
|
||||
void loaded();
|
||||
void loadEmoteImage(const QString &name, const ImagePtr &image,
|
||||
BadgeIconCallback &&callback);
|
||||
|
||||
Reference in New Issue
Block a user