diff --git a/channel.cpp b/channel.cpp index 702956bb1..ec7b178a9 100644 --- a/channel.cpp +++ b/channel.cpp @@ -1,7 +1,15 @@ #include "channel.h" +#include "emotes.h" #include "messages/message.h" #include "windows.h" +#include +#include +#include +#include +#include +#include +#include #include namespace chatterino { @@ -27,9 +35,10 @@ Channel::Channel(const QString &channel) void Channel::reloadBttvEmotes() { + // bttv QNetworkAccessManager *manager = new QNetworkAccessManager(); - QUrl url("https://api.frankerfacez.com/v1/set/global"); + QUrl url("https://api.betterttv.net/2/channels/" + this->name); QNetworkRequest request(url); QNetworkReply *reply = manager->get(request); @@ -40,26 +49,26 @@ Channel::reloadBttvEmotes() QJsonDocument jsonDoc(QJsonDocument::fromJson(data)); QJsonObject root = jsonDoc.object(); - auto sets = root.value("sets").toObject(); + auto emotes = root.value("emotes").toArray(); - for (const QJsonValue &set : sets) { - auto emoticons = set.toObject().value("emoticons").toArray(); + QString _template = "https:" + root.value("urlTemplate").toString(); - for (const QJsonValue &emote : emoticons) { - QJsonObject object = emote.toObject(); + for (const QJsonValue &emote : emotes) { + QString id = emote.toObject().value("id").toString(); + QString code = emote.toObject().value("code").toString(); + // emote.value("imageType").toString(); - // margins + QString tmp = _template; + tmp.detach(); + QString url = + tmp.replace("{{id}}", id).replace("{{image}}", "1x"); - int id = object.value("id").toInt(); - QString code = object.value("name").toString(); - - QJsonObject urls = object.value("urls").toObject(); - QString url1 = "http:" + urls.value("1").toString(); - - Emotes::getBttvEmotes().insert( - code, new messages::LazyLoadedImage( - url1, 1, code, code + "\nGlobal Ffz Emote")); - } + this->getBttvChannelEmotes().insert( + code, + Emotes::getBttvChannelEmoteFromCaches().getOrAdd(id, [=] { + return new messages::LazyLoadedImage( + url, 1, code, code + "\nChannel Bttv Emote"); + })); } } diff --git a/channel.h b/channel.h index fa864d635..e2da2b076 100644 --- a/channel.h +++ b/channel.h @@ -22,13 +22,13 @@ public: // properties const ConcurrentMap & - getBttvChannelEmotes() const + getBttvChannelEmotes() { return bttvChannelEmotes; } const ConcurrentMap & - getFfzChannelEmotes() const + getFfzChannelEmotes() { return ffzChannelEmotes; } diff --git a/messages/message.cpp b/messages/message.cpp index d160d7719..97b125cfd 100644 --- a/messages/message.cpp +++ b/messages/message.cpp @@ -33,7 +33,7 @@ Message::Message(const QString &text) QString())); } -Message::Message(const IrcPrivateMessage &ircMessage, const Channel &channel, +Message::Message(const IrcPrivateMessage &ircMessage, Channel &channel, bool enablePingSound, bool isReceivedWhisper, bool isSentWhisper, bool includeChannel) : wordParts() diff --git a/messages/message.h b/messages/message.h index a9f954a16..d5b2428ea 100644 --- a/messages/message.h +++ b/messages/message.h @@ -16,7 +16,7 @@ class Message { public: Message(const QString &text); - Message(const IrcPrivateMessage &ircMessage, const Channel &Channel, + Message(const IrcPrivateMessage &ircMessage, Channel &Channel, bool enablePingSound = true, bool isReceivedWhisper = false, bool isSentWhisper = false, bool includeChannel = false);