fix: mark global BTTV emotes as zero-width at creation (#6440)

* fix: mark global BTTV emotes as zero-width at creation

* changelog

* nit: slightly different formatting

---------

Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com>
This commit is contained in:
nerix
2025-09-05 10:01:21 +02:00
committed by GitHub
parent 445865d0d8
commit 5af6626e76
3 changed files with 31 additions and 52 deletions
+11 -43
View File
@@ -78,11 +78,6 @@ const QRegularExpression allUsernamesMentionRegex("^" + regexHelpString);
const QRegularExpression SPACE_REGEX("\\s");
const QSet<QString> zeroWidthEmotes{
"SoSnowy", "IceCold", "SantaHat", "TopHat",
"ReinDeer", "CandyCane", "cvMask", "cvHazmat",
};
struct HypeChatPaidLevel {
std::chrono::seconds duration;
uint8_t numeric;
@@ -421,7 +416,7 @@ EmotePtr makeSharedChatBadge(const QString &sourceName,
});
}
std::tuple<std::optional<EmotePtr>, MessageElementFlags, bool> parseEmote(
std::tuple<std::optional<EmotePtr>, MessageElementFlags> parseEmote(
TwitchChannel *twitchChannel, const EmoteName &name)
{
// Emote order:
@@ -445,31 +440,19 @@ std::tuple<std::optional<EmotePtr>, MessageElementFlags, bool> parseEmote(
emote = twitchChannel->ffzEmote(name);
if (emote)
{
return {
emote,
MessageElementFlag::FfzEmote,
false,
};
return {emote, MessageElementFlag::FfzEmote};
}
emote = twitchChannel->bttvEmote(name);
if (emote)
{
return {
emote,
MessageElementFlag::BttvEmote,
false,
};
return {emote, MessageElementFlag::BttvEmote};
}
emote = twitchChannel->seventvEmote(name);
if (emote)
{
return {
emote,
MessageElementFlag::SevenTVEmote,
emote.value()->zeroWidth,
};
return {emote, MessageElementFlag::SevenTVEmote};
}
}
@@ -478,38 +461,22 @@ std::tuple<std::optional<EmotePtr>, MessageElementFlags, bool> parseEmote(
emote = globalFfzEmotes->emote(name);
if (emote)
{
return {
emote,
MessageElementFlag::FfzEmote,
false,
};
return {emote, MessageElementFlag::FfzEmote};
}
emote = globalBttvEmotes->emote(name);
if (emote)
{
return {
emote,
MessageElementFlag::BttvEmote,
zeroWidthEmotes.contains(name.string),
};
return {emote, MessageElementFlag::BttvEmote};
}
emote = globalSeventvEmotes->globalEmote(name);
if (emote)
{
return {
emote,
MessageElementFlag::SevenTVEmote,
emote.value()->zeroWidth,
};
return {emote, MessageElementFlag::SevenTVEmote};
}
return {
{},
{},
false,
};
return {{}, {}};
}
} // namespace
@@ -2240,14 +2207,15 @@ void MessageBuilder::appendUsername(const QVariantMap &tags,
Outcome MessageBuilder::tryAppendEmote(TwitchChannel *twitchChannel,
const EmoteName &name)
{
auto [emote, flags, zeroWidth] = parseEmote(twitchChannel, name);
auto [emote, flags] = parseEmote(twitchChannel, name);
if (!emote)
{
return Failure;
}
if (zeroWidth && getSettings()->enableZeroWidthEmotes && !this->isEmpty())
if ((*emote)->zeroWidth && getSettings()->enableZeroWidthEmotes &&
!this->isEmpty())
{
// Attempt to merge current zero-width emote into any previous emotes
auto *asEmote = dynamic_cast<EmoteElement *>(&this->back());