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()
{
QNetworkAccessManager *manager = new QNetworkAccessManager();
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();
QString url("https://api.betterttv.net/2/emotes");
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();
QString linkTemplate = "https:" + root.value("urlTemplate").toString();
@ -437,27 +431,18 @@ void EmoteManager::loadBTTVEmotes()
}
this->bttvGlobalEmoteCodes = codes;
}
reply->deleteLater();
manager->deleteLater();
});
}
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");
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 ffz emotes");
auto sets = root.value("sets").toObject();
@ -483,12 +468,8 @@ void EmoteManager::loadFFZEmotes()
this->ffzGlobalEmoteCodes = codes;
}
}
reply->deleteLater();
manager->deleteLater();
});
}
} // namespace chatterino
// id is used for lookup
// emoteName is used for giving a name to the emote in case it doesn't exist