Skip to content

Commit

Permalink
fix: store currently displayed avatar url
Browse files Browse the repository at this point in the history
  • Loading branch information
Nerixyz committed Dec 24, 2024
1 parent 64b35a4 commit c8a096c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/widgets/dialogs/UserInfoPopup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ UserInfoPopup::UserInfoPopup(bool closeAutomatically, Split *split)
this->seventvAvatar_->start();
this->ui_.switchAvatars->getLabel().setText("Show Twitch");
}
this->updateAvatarUrl();
});

auto vbox = head.emplace<QVBoxLayout>();
Expand Down Expand Up @@ -910,7 +911,8 @@ void UserInfoPopup::updateUserData()
}

this->userId_ = user.id;
this->avatarUrl_ = user.profileImageUrl;
this->helixAvatarUrl_ = user.profileImageUrl;
this->updateAvatarUrl();

// copyable button for login name of users with a localized username
if (user.displayName.toLower() != user.login)
Expand Down Expand Up @@ -1119,7 +1121,8 @@ void UserInfoPopup::loadAvatar(const HelixUser &user)
});
}

this->avatarUrl_ = user.profileImageUrl;
this->helixAvatarUrl_ = user.profileImageUrl;
this->updateAvatarUrl();

if (getSettings()->displaySevenTVAnimatedProfile)
{
Expand Down Expand Up @@ -1158,7 +1161,7 @@ void UserInfoPopup::loadSevenTVAvatar(const HelixUser &user)
QFile cacheFile(filename);
if (cacheFile.exists())
{
this->avatarUrl_ = url;
this->seventvAvatarUrl_ = url;
this->setSevenTVAvatar(filename);
return;
}
Expand All @@ -1174,7 +1177,7 @@ void UserInfoPopup::loadSevenTVAvatar(const HelixUser &user)
[this, reply, url, filename] {
if (reply->error() == QNetworkReply::NoError)
{
this->avatarUrl_ = url;
this->seventvAvatarUrl_ = url;
this->saveCacheAvatar(reply->readAll(),
filename);
this->setSevenTVAvatar(filename);
Expand Down Expand Up @@ -1211,6 +1214,7 @@ void UserInfoPopup::setSevenTVAvatar(const QString &filename)
this->ui_.switchAvatars->show();
this->ui_.switchAvatars->getLabel().setText("Show Twitch");
this->isTwitchAvatarShown_ = false;
this->updateAvatarUrl();
}

void UserInfoPopup::saveCacheAvatar(const QByteArray &avatar,
Expand Down Expand Up @@ -1346,4 +1350,16 @@ void UserInfoPopup::TimeoutWidget::paintEvent(QPaintEvent *)
// / 2);
}

void UserInfoPopup::updateAvatarUrl()
{
if (this->isTwitchAvatarShown_)
{
this->avatarUrl_ = this->helixAvatarUrl_;
}
else
{
this->avatarUrl_ = this->seventvAvatarUrl_;
}
}

} // namespace chatterino
4 changes: 4 additions & 0 deletions src/widgets/dialogs/UserInfoPopup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ class UserInfoPopup final : public DraggablePopup
void saveCacheAvatar(const QByteArray &avatar,
const QString &filename) const;

void updateAvatarUrl();

bool isMod_{};
bool isBroadcaster_{};

Expand All @@ -66,6 +68,8 @@ class UserInfoPopup final : public DraggablePopup
QString userName_;
QString userId_;
QString avatarUrl_;
QString helixAvatarUrl_;
QString seventvAvatarUrl_;

// The channel the popup was opened from (e.g. /mentions or #forsen). Can be a special channel.
ChannelPtr channel_;
Expand Down

0 comments on commit c8a096c

Please sign in to comment.