fix: add more image sizes to shared chat badge (#6146)

This commit is contained in:
nerix
2025-04-13 11:48:13 +02:00
committed by GitHub
parent f56b7c05bf
commit e1863d64ee
5 changed files with 73 additions and 5 deletions
+11 -5
View File
@@ -391,8 +391,10 @@ EmotePtr makeSharedChatBadge(const QString &sourceName,
{
if (!sourceProfileURL.isEmpty())
{
QString modifiedUrl = sourceProfileURL;
modifiedUrl.replace("300x300", "28x28");
auto [urlBegin, urlEnd] = splitOnce(sourceProfileURL, u"300x300");
QString url28px = urlBegin % u"28x28" % urlEnd;
QString url70px = urlBegin % u"70x70" % urlEnd;
QString url150px = urlBegin % u"150x150" % urlEnd;
auto badgeLink = [&] {
if (sourceLogin.isEmpty())
@@ -405,9 +407,13 @@ EmotePtr makeSharedChatBadge(const QString &sourceName,
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
.images =
ImageSet{
// The images should be displayed like an 18x18 image
Image::fromUrl({url28px}, 18.F / 28.F),
Image::fromUrl({url70px}, 18.F / 70.F),
Image::fromUrl({url150px}, 18.F / 150.F),
},
.tooltip =
Tooltip{"Shared Message" +
(sourceName.isEmpty() ? "" : " from " + sourceName)},
+28
View File
@@ -438,4 +438,32 @@ bool readProviderEmotesCache(const QString &id, const QString &provider,
return false;
}
std::pair<QStringView, QStringView> splitOnce(QStringView haystack,
QStringView needle) noexcept
{
auto idx = haystack.indexOf(needle);
if (idx < 0)
{
return {haystack, {}};
}
return {
haystack.sliced(0, idx),
haystack.sliced(idx + needle.size()),
};
}
std::pair<QStringView, QStringView> splitOnce(QStringView haystack,
QChar needle) noexcept
{
auto idx = haystack.indexOf(needle);
if (idx < 0)
{
return {haystack, {}};
}
return {
haystack.sliced(0, idx),
haystack.sliced(idx + 1),
};
}
} // namespace chatterino
+10
View File
@@ -226,4 +226,14 @@ bool readProviderEmotesCache(
const QString &id, const QString &provider,
const std::function<void(QJsonDocument)> &callback);
/// Splits `haystack` by `needle`. If `needle` doesn't occur in `haystack`,
/// `{haystack, {}}` is returned.
std::pair<QStringView, QStringView> splitOnce(QStringView haystack,
QStringView needle) noexcept;
/// Splits `haystack` by `needle`. If `needle` doesn't occur in `haystack`,
/// `{haystack, {}}` is returned.
std::pair<QStringView, QStringView> splitOnce(QStringView haystack,
QChar needle) noexcept;
} // namespace chatterino