Made cleanUpCode() as static TwitchEmotes's method.

This commit is contained in:
23rd 2018-11-05 19:04:52 +03:00 committed by pajlada
parent 23458aa1df
commit 0d48c04d8a
4 changed files with 31 additions and 33 deletions

View file

@ -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("&lt;", "<").replace("&gt;", ">");
str = TwitchEmotes::cleanUpEmoteCode(EmoteName{str});
if (this->hasTrailingSpace())
{
str += " ";

View file

@ -13,37 +13,6 @@
namespace chatterino {
namespace {
EmoteName cleanUpCode(const EmoteName &dirtyEmoteCode)
{
auto cleanCode = dirtyEmoteCode.string;
cleanCode.detach();
static QMap<QString, QString> emoteNameReplacements{
{"[oO](_|\\.)[oO]", "O_o"}, {"\\&gt\\;\\(", "&gt;("},
{"\\&lt\\;3", "&lt;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("&lt;", "<");
cleanCode.replace("&gt;", ">");
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);

View file

@ -13,6 +13,33 @@ TwitchEmotes::TwitchEmotes()
{
}
QString TwitchEmotes::cleanUpEmoteCode(const EmoteName &dirtyEmoteCode)
{
auto cleanCode = dirtyEmoteCode.string;
cleanCode.detach();
static QMap<QString, QString> emoteNameReplacements{
{"[oO](_|\\.)[oO]", "O_o"}, {"\\&gt\\;\\(", "&gt;("},
{"\\&lt\\;3", "&lt;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("&lt;", "<");
cleanCode.replace("&gt;", ">");
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,

View file

@ -32,6 +32,7 @@ struct CheerEmoteSet {
class TwitchEmotes
{
public:
static QString cleanUpEmoteCode(const EmoteName &dirtyEmoteCode);
TwitchEmotes();
EmotePtr getOrCreateEmote(const EmoteId &id, const EmoteName &name);