global ffz and bttv now uses new NetworkRequest

This commit is contained in:
fourtf 2017-12-26 12:38:54 +01:00
parent 13b39e374b
commit a6be0c83bc

View file

@ -404,19 +404,13 @@ void EmoteManager::refreshTwitchEmotes(const std::shared_ptr<twitch::TwitchUser>
void EmoteManager::loadBTTVEmotes() void EmoteManager::loadBTTVEmotes()
{ {
QNetworkAccessManager *manager = new QNetworkAccessManager(); QString url("https://api.betterttv.net/2/emotes");
QUrl url("https://api.betterttv.net/2/emotes");
QNetworkRequest request(url);
QNetworkReply *reply = manager->get(request);
QObject::connect(reply, &QNetworkReply::finished, [=] {
if (reply->error() == QNetworkReply::NetworkError::NoError) {
QByteArray data = reply->readAll();
QJsonDocument jsonDoc(QJsonDocument::fromJson(data));
QJsonObject root = jsonDoc.object();
util::NetworkRequest req(url);
req.setCaller(QThread::currentThread());
req.setTimeout(30000);
req.getJSON([this](QJsonObject &root) {
debug::Log("Got global bttv emotes");
auto emotes = root.value("emotes").toArray(); auto emotes = root.value("emotes").toArray();
QString linkTemplate = "https:" + root.value("urlTemplate").toString(); QString linkTemplate = "https:" + root.value("urlTemplate").toString();
@ -437,27 +431,18 @@ void EmoteManager::loadBTTVEmotes()
} }
this->bttvGlobalEmoteCodes = codes; this->bttvGlobalEmoteCodes = codes;
}
reply->deleteLater();
manager->deleteLater();
}); });
} }
void EmoteManager::loadFFZEmotes() void EmoteManager::loadFFZEmotes()
{ {
QNetworkAccessManager *manager = new QNetworkAccessManager(); QString url("https://api.frankerfacez.com/v1/set/global");
QUrl url("https://api.frankerfacez.com/v1/set/global"); util::NetworkRequest req(url);
QNetworkRequest request(url); req.setCaller(QThread::currentThread());
req.setTimeout(30000);
QNetworkReply *reply = manager->get(request); req.getJSON([this](QJsonObject &root) {
debug::Log("Got global ffz emotes");
QObject::connect(reply, &QNetworkReply::finished, [=] {
if (reply->error() == QNetworkReply::NetworkError::NoError) {
QByteArray data = reply->readAll();
QJsonDocument jsonDoc(QJsonDocument::fromJson(data));
QJsonObject root = jsonDoc.object();
auto sets = root.value("sets").toObject(); auto sets = root.value("sets").toObject();
@ -483,12 +468,8 @@ void EmoteManager::loadFFZEmotes()
this->ffzGlobalEmoteCodes = codes; this->ffzGlobalEmoteCodes = codes;
} }
}
reply->deleteLater();
manager->deleteLater();
}); });
} } // namespace chatterino
// id is used for lookup // id is used for lookup
// emoteName is used for giving a name to the emote in case it doesn't exist // emoteName is used for giving a name to the emote in case it doesn't exist