diff --git a/src/messages/layouts/MessageLayoutElement.cpp b/src/messages/layouts/MessageLayoutElement.cpp index 973c125a6..93e0afe93 100644 --- a/src/messages/layouts/MessageLayoutElement.cpp +++ b/src/messages/layouts/MessageLayoutElement.cpp @@ -4,6 +4,7 @@ #include "messages/Emote.hpp" #include "messages/Image.hpp" #include "messages/MessageElement.hpp" +#include "providers/twitch/TwitchEmotes.hpp" #include "singletons/Theme.hpp" #include "util/DebugCount.hpp" @@ -99,7 +100,7 @@ void ImageLayoutElement::addCopyTextToString(QString &str, int from, if (emoteElement) { str += emoteElement->getEmote()->getCopyString(); - str.replace("<", "<").replace(">", ">"); + str = TwitchEmotes::cleanUpEmoteCode(EmoteName{str}); if (this->hasTrailingSpace()) { str += " "; diff --git a/src/providers/twitch/TwitchAccount.cpp b/src/providers/twitch/TwitchAccount.cpp index abc95efd0..f6337d0c6 100644 --- a/src/providers/twitch/TwitchAccount.cpp +++ b/src/providers/twitch/TwitchAccount.cpp @@ -13,37 +13,6 @@ namespace chatterino { -namespace { - - EmoteName cleanUpCode(const EmoteName &dirtyEmoteCode) - { - auto cleanCode = dirtyEmoteCode.string; - cleanCode.detach(); - - static QMap emoteNameReplacements{ - {"[oO](_|\\.)[oO]", "O_o"}, {"\\>\\;\\(", ">("}, - {"\\<\\;3", "<3"}, {"\\:-?(o|O)", ":O"}, - {"\\:-?(p|P)", ":P"}, {"\\:-?[\\\\/]", ":/"}, - {"\\:-?[z|Z|\\|]", ":Z"}, {"\\:-?\\(", ":("}, - {"\\:-?\\)", ":)"}, {"\\:-?D", ":D"}, - {"\\;-?(p|P)", ";P"}, {"\\;-?\\)", ";)"}, - {"R-?\\)", "R)"}, {"B-?\\)", "B)"}, - }; - - auto it = emoteNameReplacements.find(dirtyEmoteCode.string); - if (it != emoteNameReplacements.end()) - { - cleanCode = it.value(); - } - - cleanCode.replace("<", "<"); - cleanCode.replace(">", ">"); - - return {cleanCode}; - } - -} // namespace - TwitchAccount::TwitchAccount(const QString &username, const QString &oauthToken, const QString &oauthClient, const QString &userID) : Account(ProviderId::Twitch) @@ -491,7 +460,7 @@ void TwitchAccount::parseEmotes(const rapidjson::Document &root) auto code = EmoteName{_code}; auto id = EmoteId{QString::number(idNumber)}; - auto cleanCode = cleanUpCode(code); + auto cleanCode = EmoteName{TwitchEmotes::cleanUpEmoteCode(code)}; emoteSet->emotes.emplace_back(TwitchEmote{id, cleanCode}); emoteData->allEmoteNames.push_back(cleanCode); diff --git a/src/providers/twitch/TwitchEmotes.cpp b/src/providers/twitch/TwitchEmotes.cpp index 4f757d456..a58849c6c 100644 --- a/src/providers/twitch/TwitchEmotes.cpp +++ b/src/providers/twitch/TwitchEmotes.cpp @@ -13,6 +13,33 @@ TwitchEmotes::TwitchEmotes() { } +QString TwitchEmotes::cleanUpEmoteCode(const EmoteName &dirtyEmoteCode) +{ + auto cleanCode = dirtyEmoteCode.string; + cleanCode.detach(); + + static QMap emoteNameReplacements{ + {"[oO](_|\\.)[oO]", "O_o"}, {"\\>\\;\\(", ">("}, + {"\\<\\;3", "<3"}, {"\\:-?(o|O)", ":O"}, + {"\\:-?(p|P)", ":P"}, {"\\:-?[\\\\/]", ":/"}, + {"\\:-?[z|Z|\\|]", ":Z"}, {"\\:-?\\(", ":("}, + {"\\:-?\\)", ":)"}, {"\\:-?D", ":D"}, + {"\\;-?(p|P)", ";P"}, {"\\;-?\\)", ";)"}, + {"R-?\\)", "R)"}, {"B-?\\)", "B)"}, + }; + + auto it = emoteNameReplacements.find(dirtyEmoteCode.string); + if (it != emoteNameReplacements.end()) + { + cleanCode = it.value(); + } + + cleanCode.replace("<", "<"); + cleanCode.replace(">", ">"); + + return cleanCode; +} + // id is used for lookup // emoteName is used for giving a name to the emote in case it doesn't exist EmotePtr TwitchEmotes::getOrCreateEmote(const EmoteId &id, diff --git a/src/providers/twitch/TwitchEmotes.hpp b/src/providers/twitch/TwitchEmotes.hpp index 1c1b0b216..a2ef16b05 100644 --- a/src/providers/twitch/TwitchEmotes.hpp +++ b/src/providers/twitch/TwitchEmotes.hpp @@ -32,6 +32,7 @@ struct CheerEmoteSet { class TwitchEmotes { public: + static QString cleanUpEmoteCode(const EmoteName &dirtyEmoteCode); TwitchEmotes(); EmotePtr getOrCreateEmote(const EmoteId &id, const EmoteName &name);