refactor: mini reorganization of FfzEmotes.cpp (#5117)

This commit is contained in:
pajlada 2024-01-21 12:28:20 +01:00 committed by GitHub
parent 075a7c5af0
commit 65d3e73c5d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -10,9 +10,13 @@
#include "providers/twitch/TwitchChannel.hpp"
#include "singletons/Settings.hpp"
namespace chatterino {
namespace {
using namespace chatterino;
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
const auto &LOG = chatterinoFfzemotes;
const QString CHANNEL_HAS_NO_EMOTES(
"This channel has no FrankerFaceZ channel emotes.");
@ -38,10 +42,9 @@ namespace {
//, code, tooltip
emoteData.name = name;
emoteData.images =
ImageSet{Image::fromUrl(url1x, 1),
url2x.string.isEmpty() ? Image::getEmpty()
: Image::fromUrl(url2x, 0.5),
emoteData.images = ImageSet{
Image::fromUrl(url1x, 1),
url2x.string.isEmpty() ? Image::getEmpty() : Image::fromUrl(url2x, 0.5),
url3x.string.isEmpty() ? Image::getEmpty()
: Image::fromUrl(url3x, 0.25)};
emoteData.tooltip = {tooltip};
@ -106,8 +109,7 @@ namespace {
auto emoteSetID = emoteSet["id"].toInt();
if (!defaultSets.contains(emoteSetID))
{
qCDebug(chatterinoFfzemotes)
<< "Skipping global emote set" << emoteSetID
qCDebug(LOG) << "Skipping global emote set" << emoteSetID
<< "as it's not part of the default sets";
continue;
}
@ -140,10 +142,10 @@ namespace {
};
authorityBadge = std::make_shared<Emote>(Emote{
{""},
authorityBadgeImageSet,
Tooltip{tooltip},
authorityBadge1x,
.name = {""},
.images = authorityBadgeImageSet,
.tooltip = Tooltip{tooltip},
.homePage = authorityBadge1x,
});
}
return authorityBadge;
@ -151,6 +153,8 @@ namespace {
} // namespace
namespace chatterino {
using namespace ffz::detail;
EmoteMap ffz::detail::parseChannelEmotes(const QJsonObject &jsonRoot)
@ -218,8 +222,7 @@ void FfzEmotes::loadChannel(
std::function<void(std::optional<EmotePtr>)> vipBadgeCallback,
bool manualRefresh)
{
qCDebug(chatterinoFfzemotes)
<< "[FFZEmotes] Reload FFZ Channel Emotes for channel" << channelID;
qCDebug(LOG) << "Reload FFZ Channel Emotes for channel" << channelID;
NetworkRequest("https://api.frankerfacez.com/v1/room/id/" + channelID)
@ -275,9 +278,8 @@ void FfzEmotes::loadChannel(
{
// TODO: Auto retry in case of a timeout, with a delay
auto errorString = result.formatError();
qCWarning(chatterinoFfzemotes)
<< "Error fetching FFZ emotes for channel" << channelID
<< ", error" << errorString;
qCWarning(LOG) << "Error fetching FFZ emotes for channel"
<< channelID << ", error" << errorString;
shared->addMessage(makeSystemMessage(
QStringLiteral("Failed to fetch FrankerFaceZ channel "
"emotes. (Error: %1)")