Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add a basic implementation of shared chat profile pictures #5760

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions src/messages/MessageBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,24 @@ EmotePtr makeAutoModBadge()
Url{"https://dashboard.twitch.tv/settings/moderation/automod"}});
}

EmotePtr makeSharedChatBadge(const QString &sourceName)
EmotePtr makeSharedChatBadge(const QString &sourceName, const QString &url)
{
if (!url.isEmpty())
{
QString modifiedUrl = url;

modifiedUrl.replace("300x300", "70x70");

return std::make_shared<Emote>(Emote{
.name = EmoteName{},
.images = ImageSet{Image::fromUrl(Url{modifiedUrl}, 0.35)},
.tooltip =
Tooltip{"Shared Message" +
(sourceName.isEmpty() ? "" : " from " + sourceName)},
.homePage = Url{"https://link.twitch.tv/SharedChatViewer"},
});
}

return std::make_shared<Emote>(Emote{
.name = EmoteName{},
.images = ImageSet{Image::fromResourcePixmap(
Expand Down Expand Up @@ -2844,6 +2860,8 @@ void MessageBuilder::appendTwitchBadges(const QVariantMap &tags,
{
const QString sourceId = tags["source-room-id"].toString();
QString sourceName;
QString sourceProfilePicture;

if (sourceId.isEmpty())
{
sourceName = "";
Expand All @@ -2854,12 +2872,14 @@ void MessageBuilder::appendTwitchBadges(const QVariantMap &tags,
}
else
{
sourceName =
getApp()->getTwitchUsers()->resolveID({sourceId})->displayName;
auto twitchUser = getApp()->getTwitchUsers()->resolveID({sourceId});
sourceName = twitchUser->displayName;
sourceProfilePicture = twitchUser->profilePictureUrl;
}

this->emplace<BadgeElement>(makeSharedChatBadge(sourceName),
MessageElementFlag::BadgeSharedChannel);
this->emplace<BadgeElement>(
makeSharedChatBadge(sourceName, sourceProfilePicture),
MessageElementFlag::BadgeSharedChannel);
}

auto badgeInfos = parseBadgeInfoTag(tags);
Expand Down
1 change: 1 addition & 0 deletions src/providers/twitch/TwitchUser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 2 additions & 0 deletions src/providers/twitch/TwitchUser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ struct TwitchUser {
QString id;
mutable QString name;
mutable QString displayName;
mutable QString profilePictureUrl;

void update(const TwitchUser &other) const
{
assert(this->id == other.id);

this->name = other.name;
this->displayName = other.displayName;
this->profilePictureUrl = other.profilePictureUrl;
}

void update(const HelixUser &user) const;
Expand Down
1 change: 1 addition & 0 deletions src/providers/twitch/TwitchUsers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
Loading