mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
fix: properly display global badges for anon users (#5599)
This commit is contained in:
parent
c4df31a226
commit
edf18a7a0f
|
@ -49,6 +49,7 @@
|
|||
- Bugfix: Fixed account switch not being saved if no other settings were changed. (#5558)
|
||||
- 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)
|
||||
- Bugfix: Fixed grammar in the user highlight page. (#5602)
|
||||
- Dev: Update Windows build from Qt 6.5.0 to Qt 6.7.1. (#5420)
|
||||
- Dev: Update vcpkg build Qt from 6.5.0 to 6.7.0, boost from 1.83.0 to 1.85.0, openssl from 3.1.3 to 3.3.0. (#5422)
|
||||
|
|
File diff suppressed because one or more lines are too long
28
scripts/update-badges.py
Normal file
28
scripts/update-badges.py
Normal file
|
@ -0,0 +1,28 @@
|
|||
import sys
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def trim_version(version):
|
||||
base_url = version["image_url_1x"].removesuffix("1")
|
||||
assert version["image_url_2x"] == base_url + "2"
|
||||
assert version["image_url_4x"] == base_url + "3"
|
||||
v = {
|
||||
"id": version["id"],
|
||||
"title": version["title"],
|
||||
"image": base_url,
|
||||
}
|
||||
if version["click_url"]:
|
||||
v["url"] = version["click_url"]
|
||||
return v
|
||||
|
||||
|
||||
raw = sys.stdin.read()
|
||||
assert len(raw) > 0, "Response from Helix' chat/badges/global needs to be piped"
|
||||
base = json.loads(raw)["data"]
|
||||
out = {set["set_id"]: [trim_version(v) for v in set["versions"]] for set in base}
|
||||
|
||||
with open(
|
||||
Path(__file__).parent.parent / "resources" / "twitch-badges.json", mode="w"
|
||||
) as f:
|
||||
f.write(json.dumps(out, separators=(",", ":")))
|
|
@ -79,6 +79,12 @@ void TwitchBadges::loadTwitchBadges()
|
|||
break;
|
||||
}
|
||||
qCWarning(chatterinoTwitch) << errorMessage;
|
||||
this->loadLocalBadges();
|
||||
});
|
||||
}
|
||||
|
||||
void TwitchBadges::loadLocalBadges()
|
||||
{
|
||||
QFile file(":/twitch-badges.json");
|
||||
if (!file.open(QFile::ReadOnly))
|
||||
{
|
||||
|
@ -92,48 +98,42 @@ void TwitchBadges::loadTwitchBadges()
|
|||
auto bytes = file.readAll();
|
||||
auto doc = QJsonDocument::fromJson(bytes);
|
||||
|
||||
this->parseTwitchBadges(doc.object());
|
||||
|
||||
this->loaded();
|
||||
});
|
||||
}
|
||||
|
||||
void TwitchBadges::parseTwitchBadges(QJsonObject root)
|
||||
{
|
||||
const auto &root = doc.object();
|
||||
auto badgeSets = this->badgeSets_.access();
|
||||
|
||||
auto jsonSets = root.value("badge_sets").toObject();
|
||||
for (auto sIt = jsonSets.begin(); sIt != jsonSets.end(); ++sIt)
|
||||
for (auto setIt = root.begin(); setIt != root.end(); setIt++)
|
||||
{
|
||||
auto key = sIt.key();
|
||||
auto versions = sIt.value().toObject().value("versions").toObject();
|
||||
auto key = setIt.key();
|
||||
|
||||
for (auto vIt = versions.begin(); vIt != versions.end(); ++vIt)
|
||||
for (auto versionValue : setIt.value().toArray())
|
||||
{
|
||||
auto versionObj = vIt.value().toObject();
|
||||
const auto versionObj = versionValue.toObject();
|
||||
auto id = versionObj["id"].toString();
|
||||
auto baseImage = versionObj["image"].toString();
|
||||
auto emote = Emote{
|
||||
.name = {""},
|
||||
.name = {},
|
||||
.images =
|
||||
ImageSet{
|
||||
Image::fromUrl(
|
||||
{versionObj.value("image_url_1x").toString()}, 1,
|
||||
Image::fromUrl({baseImage + '1'}, 1,
|
||||
BADGE_BASE_SIZE),
|
||||
Image::fromUrl(
|
||||
{versionObj.value("image_url_2x").toString()}, .5,
|
||||
Image::fromUrl({baseImage + '2'}, .5,
|
||||
BADGE_BASE_SIZE * 2),
|
||||
Image::fromUrl(
|
||||
{versionObj.value("image_url_4x").toString()}, .25,
|
||||
Image::fromUrl({baseImage + '3'}, .25,
|
||||
BADGE_BASE_SIZE * 4),
|
||||
},
|
||||
.tooltip = Tooltip{versionObj.value("title").toString()},
|
||||
.homePage = Url{versionObj.value("click_url").toString()},
|
||||
.tooltip = Tooltip{versionObj["title"].toString()},
|
||||
.homePage = Url{versionObj["url"].toString()},
|
||||
};
|
||||
|
||||
(*badgeSets)[key][vIt.key()] = std::make_shared<Emote>(emote);
|
||||
(*badgeSets)[key][id] = std::make_shared<Emote>(emote);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this->loaded();
|
||||
}
|
||||
|
||||
void TwitchBadges::loaded()
|
||||
{
|
||||
std::unique_lock loadedLock(this->loadedMutex_);
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue