changed to 80 max column
This commit is contained in:
@@ -13,11 +13,13 @@ namespace chatterino {
|
||||
|
||||
namespace {
|
||||
|
||||
Url getEmoteLink(QString urlTemplate, const EmoteId &id, const QString &emoteScale)
|
||||
Url getEmoteLink(QString urlTemplate, const EmoteId &id,
|
||||
const QString &emoteScale)
|
||||
{
|
||||
urlTemplate.detach();
|
||||
|
||||
return {urlTemplate.replace("{{id}}", id.string).replace("{{image}}", emoteScale)};
|
||||
return {urlTemplate.replace("{{id}}", id.string)
|
||||
.replace("{{image}}", emoteScale)};
|
||||
}
|
||||
|
||||
} // namespace
|
||||
@@ -76,23 +78,26 @@ void BttvEmotes::loadGlobalEmotes()
|
||||
request.execute();
|
||||
}
|
||||
|
||||
std::pair<Outcome, EmoteMap> BttvEmotes::parseGlobalEmotes(const QJsonObject &jsonRoot,
|
||||
const EmoteMap ¤tEmotes)
|
||||
std::pair<Outcome, EmoteMap> BttvEmotes::parseGlobalEmotes(
|
||||
const QJsonObject &jsonRoot, const EmoteMap ¤tEmotes)
|
||||
{
|
||||
auto emotes = EmoteMap();
|
||||
auto jsonEmotes = jsonRoot.value("emotes").toArray();
|
||||
auto urlTemplate = QString("https:" + jsonRoot.value("urlTemplate").toString());
|
||||
auto urlTemplate =
|
||||
QString("https:" + jsonRoot.value("urlTemplate").toString());
|
||||
|
||||
for (const QJsonValue &jsonEmote : jsonEmotes) {
|
||||
auto id = EmoteId{jsonEmote.toObject().value("id").toString()};
|
||||
auto name = EmoteName{jsonEmote.toObject().value("code").toString()};
|
||||
|
||||
auto emote = Emote({name,
|
||||
ImageSet{Image::fromUrl(getEmoteLink(urlTemplate, id, "1x"), 1),
|
||||
Image::fromUrl(getEmoteLink(urlTemplate, id, "2x"), 0.5),
|
||||
Image::fromUrl(getEmoteLink(urlTemplate, id, "3x"), 0.25)},
|
||||
Tooltip{name.string + "<br />Global Bttv Emote"},
|
||||
Url{"https://manage.betterttv.net/emotes/" + id.string}});
|
||||
auto emote = Emote(
|
||||
{name,
|
||||
ImageSet{
|
||||
Image::fromUrl(getEmoteLink(urlTemplate, id, "1x"), 1),
|
||||
Image::fromUrl(getEmoteLink(urlTemplate, id, "2x"), 0.5),
|
||||
Image::fromUrl(getEmoteLink(urlTemplate, id, "3x"), 0.25)},
|
||||
Tooltip{name.string + "<br />Global Bttv Emote"},
|
||||
Url{"https://manage.betterttv.net/emotes/" + id.string}});
|
||||
|
||||
auto it = currentEmotes.find(name);
|
||||
if (it != currentEmotes.end() && *it->second == emote) {
|
||||
|
||||
@@ -10,7 +10,8 @@ namespace chatterino {
|
||||
|
||||
class BttvEmotes final : std::enable_shared_from_this<BttvEmotes>
|
||||
{
|
||||
static constexpr const char *globalEmoteApiUrl = "https://api.betterttv.net/2/emotes";
|
||||
static constexpr const char *globalEmoteApiUrl =
|
||||
"https://api.betterttv.net/2/emotes";
|
||||
|
||||
public:
|
||||
// BttvEmotes();
|
||||
@@ -22,8 +23,8 @@ public:
|
||||
void loadGlobalEmotes();
|
||||
|
||||
private:
|
||||
std::pair<Outcome, EmoteMap> parseGlobalEmotes(const QJsonObject &jsonRoot,
|
||||
const EmoteMap ¤tEmotes);
|
||||
std::pair<Outcome, EmoteMap> parseGlobalEmotes(
|
||||
const QJsonObject &jsonRoot, const EmoteMap ¤tEmotes);
|
||||
|
||||
UniqueAccess<EmoteMap> globalEmotes_;
|
||||
// UniqueAccess<WeakEmoteIdMap> channelEmoteCache_;
|
||||
|
||||
@@ -11,12 +11,16 @@
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
static Url getEmoteLink(QString urlTemplate, const EmoteId &id, const QString &emoteScale);
|
||||
static std::pair<Outcome, EmoteMap> bttvParseChannelEmotes(const QJsonObject &jsonRoot);
|
||||
static Url getEmoteLink(QString urlTemplate, const EmoteId &id,
|
||||
const QString &emoteScale);
|
||||
static std::pair<Outcome, EmoteMap> bttvParseChannelEmotes(
|
||||
const QJsonObject &jsonRoot);
|
||||
|
||||
void loadBttvChannelEmotes(const QString &channelName, std::function<void(EmoteMap &&)> callback)
|
||||
void loadBttvChannelEmotes(const QString &channelName,
|
||||
std::function<void(EmoteMap &&)> callback)
|
||||
{
|
||||
auto request = NetworkRequest(QString(bttvChannelEmoteApiUrl) + channelName);
|
||||
auto request =
|
||||
NetworkRequest(QString(bttvChannelEmoteApiUrl) + channelName);
|
||||
|
||||
request.setCaller(QThread::currentThread());
|
||||
request.setTimeout(3000);
|
||||
@@ -31,14 +35,17 @@ void loadBttvChannelEmotes(const QString &channelName, std::function<void(EmoteM
|
||||
request.execute();
|
||||
}
|
||||
|
||||
static std::pair<Outcome, EmoteMap> bttvParseChannelEmotes(const QJsonObject &jsonRoot)
|
||||
static std::pair<Outcome, EmoteMap> bttvParseChannelEmotes(
|
||||
const QJsonObject &jsonRoot)
|
||||
{
|
||||
static UniqueAccess<std::unordered_map<EmoteId, std::weak_ptr<const Emote>>> cache_;
|
||||
static UniqueAccess<std::unordered_map<EmoteId, std::weak_ptr<const Emote>>>
|
||||
cache_;
|
||||
|
||||
auto cache = cache_.access();
|
||||
auto emotes = EmoteMap();
|
||||
auto jsonEmotes = jsonRoot.value("emotes").toArray();
|
||||
auto urlTemplate = QString("https:" + jsonRoot.value("urlTemplate").toString());
|
||||
auto urlTemplate =
|
||||
QString("https:" + jsonRoot.value("urlTemplate").toString());
|
||||
|
||||
for (auto jsonEmote_ : jsonEmotes) {
|
||||
auto jsonEmote = jsonEmote_.toObject();
|
||||
@@ -47,30 +54,35 @@ static std::pair<Outcome, EmoteMap> bttvParseChannelEmotes(const QJsonObject &js
|
||||
auto name = EmoteName{jsonEmote.value("code").toString()};
|
||||
// emoteObject.value("imageType").toString();
|
||||
|
||||
auto emote = Emote({name,
|
||||
ImageSet{Image::fromUrl(getEmoteLink(urlTemplate, id, "1x"), 1),
|
||||
Image::fromUrl(getEmoteLink(urlTemplate, id, "2x"), 0.5),
|
||||
Image::fromUrl(getEmoteLink(urlTemplate, id, "3x"), 0.25)},
|
||||
Tooltip{name.string + "<br />Channel Bttv Emote"},
|
||||
Url{"https://manage.betterttv.net/emotes/" + id.string}});
|
||||
auto emote = Emote(
|
||||
{name,
|
||||
ImageSet{
|
||||
Image::fromUrl(getEmoteLink(urlTemplate, id, "1x"), 1),
|
||||
Image::fromUrl(getEmoteLink(urlTemplate, id, "2x"), 0.5),
|
||||
Image::fromUrl(getEmoteLink(urlTemplate, id, "3x"), 0.25)},
|
||||
Tooltip{name.string + "<br />Channel Bttv Emote"},
|
||||
Url{"https://manage.betterttv.net/emotes/" + id.string}});
|
||||
|
||||
auto shared = (*cache)[id].lock();
|
||||
if (shared && *shared == emote) {
|
||||
// reuse old shared_ptr if nothing changed
|
||||
emotes[name] = shared;
|
||||
} else {
|
||||
(*cache)[id] = emotes[name] = std::make_shared<Emote>(std::move(emote));
|
||||
(*cache)[id] = emotes[name] =
|
||||
std::make_shared<Emote>(std::move(emote));
|
||||
}
|
||||
}
|
||||
|
||||
return {Success, std::move(emotes)};
|
||||
}
|
||||
|
||||
static Url getEmoteLink(QString urlTemplate, const EmoteId &id, const QString &emoteScale)
|
||||
static Url getEmoteLink(QString urlTemplate, const EmoteId &id,
|
||||
const QString &emoteScale)
|
||||
{
|
||||
urlTemplate.detach();
|
||||
|
||||
return {urlTemplate.replace("{{id}}", id.string).replace("{{image}}", emoteScale)};
|
||||
return {urlTemplate.replace("{{id}}", id.string)
|
||||
.replace("{{image}}", emoteScale)};
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
@@ -7,8 +7,10 @@ class QString;
|
||||
namespace chatterino {
|
||||
|
||||
class EmoteMap;
|
||||
constexpr const char *bttvChannelEmoteApiUrl = "https://api.betterttv.net/2/channels/";
|
||||
constexpr const char *bttvChannelEmoteApiUrl =
|
||||
"https://api.betterttv.net/2/channels/";
|
||||
|
||||
void loadBttvChannelEmotes(const QString &channelName, std::function<void(EmoteMap &&)> callback);
|
||||
void loadBttvChannelEmotes(const QString &channelName,
|
||||
std::function<void(EmoteMap &&)> callback);
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
Reference in New Issue
Block a user