feat: Use streamer profile picture for shared chat badge (#5760)

Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com>
Co-authored-by: Nerixyz <nerixdev@outlook.de>
This commit is contained in:
treuks
2025-03-22 13:45:47 +02:00
committed by GitHub
parent 584cd275fa
commit 9d0de1c373
5 changed files with 53 additions and 9 deletions
+1
View File
@@ -2,6 +2,7 @@
## Unversioned
- Minor: Shared chat messages now use the source channel's profile picture to denote it's a shared chat message. (#5760)
- Minor: Moved the "Delete message" menu option into a "Moderate" sub-menu. (#6100)
- Bugfix: Fixed the channel name input not being focused when opening the select-channel dialog. (#6096)
- Bugfix: Fixed inputs in dialogs not having a border around and padding in them. (#6098)
+48 -9
View File
@@ -385,8 +385,36 @@ EmotePtr makeAutoModBadge()
Url{"https://dashboard.twitch.tv/settings/moderation/automod"}});
}
EmotePtr makeSharedChatBadge(const QString &sourceName)
EmotePtr makeSharedChatBadge(const QString &sourceName,
const QString &sourceProfileURL,
const QString &sourceLogin)
{
if (!sourceProfileURL.isEmpty())
{
QString modifiedUrl = sourceProfileURL;
modifiedUrl.replace("300x300", "28x28");
auto badgeLink = [&] {
if (sourceLogin.isEmpty())
{
return Url{"https://link.twitch.tv/SharedChatViewer"};
}
return Url{u"https://twitch.tv/%1"_s.arg(sourceLogin)};
}();
return std::make_shared<Emote>(Emote{
.name = EmoteName{},
.images = ImageSet{Image::fromUrl(
Url{modifiedUrl},
18.F / 28.F)}, // get as close to 18x18 as possible
.tooltip =
Tooltip{"Shared Message" +
(sourceName.isEmpty() ? "" : " from " + sourceName)},
.homePage = badgeLink,
});
}
return std::make_shared<Emote>(Emote{
.name = EmoteName{},
.images = ImageSet{Image::fromResourcePixmap(
@@ -2985,22 +3013,33 @@ void MessageBuilder::appendTwitchBadges(const QVariantMap &tags,
{
const QString sourceId = tags["source-room-id"].toString();
QString sourceName;
QString sourceProfilePicture;
QString sourceLogin;
if (sourceId.isEmpty())
{
sourceName = "";
}
else if (twitchChannel->roomId() == sourceId)
{
sourceName = twitchChannel->getName();
}
else
{
sourceName =
getApp()->getTwitchUsers()->resolveID({sourceId})->displayName;
auto twitchUser = getApp()->getTwitchUsers()->resolveID({sourceId});
sourceProfilePicture = twitchUser->profilePictureUrl;
sourceLogin = twitchUser->name;
if (twitchChannel->roomId() == sourceId)
{
// We have the source channel open, but we still need to load the profile picture URL
sourceName = twitchChannel->getName();
}
else
{
sourceName = twitchUser->displayName;
}
}
this->emplace<BadgeElement>(makeSharedChatBadge(sourceName),
MessageElementFlag::BadgeSharedChannel);
this->emplace<BadgeElement>(
makeSharedChatBadge(sourceName, sourceProfilePicture, sourceLogin),
MessageElementFlag::BadgeSharedChannel);
}
auto badgeInfos = parseBadgeInfoTag(tags);
+1
View File
@@ -18,6 +18,7 @@ void TwitchUser::update(const HelixUser &user) const
assert(this->id == user.id);
this->name = user.login;
this->displayName = user.displayName;
this->profilePictureUrl = user.profileImageUrl;
}
} // namespace chatterino
+2
View File
@@ -18,6 +18,7 @@ struct TwitchUser {
QString id;
mutable QString name;
mutable QString displayName;
mutable QString profilePictureUrl;
void update(const TwitchUser &other) const
{
@@ -25,6 +26,7 @@ struct TwitchUser {
this->name = other.name;
this->displayName = other.displayName;
this->profilePictureUrl = other.profilePictureUrl;
}
void update(const HelixUser &user) const;
+1
View File
@@ -82,6 +82,7 @@ std::shared_ptr<TwitchUser> TwitchUsersPrivate::makeUnresolved(const UserId &id)
.id = id.string,
.name = {},
.displayName = {},
.profilePictureUrl = {},
}))
.first->second;
if (id.string.isEmpty())