Skip to content

Commit

Permalink
fix: ignore 7tv avatar if unset
Browse files Browse the repository at this point in the history
  • Loading branch information
Nerixyz committed Dec 24, 2024
1 parent 81d9638 commit 519a2c3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
31 changes: 24 additions & 7 deletions src/widgets/dialogs/UserInfoPopup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1152,6 +1152,24 @@ void UserInfoPopup::loadSevenTVAvatar(const HelixUser &user)
{
url.prepend(u"https:");
}
this->seventvAvatarUrl_ = url;
if (this->helixAvatarUrl_ == this->seventvAvatarUrl_)
{
return;
}

auto dotIdx = url.lastIndexOf('.') + 1;
QByteArray format;
if (dotIdx > 0)
{
auto end = url.size();
auto queryIdx = url.lastIndexOf('?');
if (queryIdx > dotIdx)
{
end = queryIdx;
}
format = QStringView(url).sliced(dotIdx, end - dotIdx).toUtf8();
}

// We're implementing custom caching here,
// because we need the cached file path.
Expand All @@ -1161,8 +1179,7 @@ void UserInfoPopup::loadSevenTVAvatar(const HelixUser &user)
QFile cacheFile(filename);
if (cacheFile.exists())
{
this->seventvAvatarUrl_ = url;
this->setSevenTVAvatar(filename);
this->setSevenTVAvatar(filename, format);
return;
}

Expand All @@ -1174,13 +1191,12 @@ void UserInfoPopup::loadSevenTVAvatar(const HelixUser &user)
auto *reply = manager->get(req);

QObject::connect(reply, &QNetworkReply::finished, this,
[this, reply, url, filename] {
[this, reply, url, filename, format] {
if (reply->error() == QNetworkReply::NoError)
{
this->seventvAvatarUrl_ = url;
this->saveCacheAvatar(reply->readAll(),
filename);
this->setSevenTVAvatar(filename);
this->setSevenTVAvatar(filename, format);
}
else
{
Expand All @@ -1195,9 +1211,10 @@ void UserInfoPopup::loadSevenTVAvatar(const HelixUser &user)
.execute();
}

void UserInfoPopup::setSevenTVAvatar(const QString &filename)
void UserInfoPopup::setSevenTVAvatar(const QString &filename,
const QByteArray &format)
{
auto *movie = new QMovie(filename, {}, this);
auto *movie = new QMovie(filename, format, this);
if (!movie->isValid())
{
qCWarning(chatterinoSeventv)
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/dialogs/UserInfoPopup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class UserInfoPopup final : public DraggablePopup
void loadAvatar(const HelixUser &user);

void loadSevenTVAvatar(const HelixUser &user);
void setSevenTVAvatar(const QString &filename);
void setSevenTVAvatar(const QString &filename, const QByteArray &format);

void saveCacheAvatar(const QByteArray &avatar,
const QString &filename) const;
Expand Down

0 comments on commit 519a2c3

Please sign in to comment.