removed old NetworkRequest api

This commit is contained in:
fourtf
2019-08-20 21:50:36 +02:00
parent a7cd1fbf97
commit 7697ec01b4
23 changed files with 954 additions and 1101 deletions
+39 -45
View File
@@ -137,20 +137,18 @@ void FfzEmotes::loadEmotes()
{
QString url("https://api.frankerfacez.com/v1/set/global");
NetworkRequest request(url);
request.setCaller(QThread::currentThread());
request.setTimeout(30000);
request.onSuccess([this](auto result) -> Outcome {
auto emotes = this->emotes();
auto pair = parseGlobalEmotes(result.parseJson(), *emotes);
if (pair.first)
this->global_.set(
std::make_shared<EmoteMap>(std::move(pair.second)));
return pair.first;
});
request.execute();
NetworkRequest(url)
.caller(QThread::currentThread())
.timeout(30000)
.onSuccess([this](auto result) -> Outcome {
auto emotes = this->emotes();
auto pair = parseGlobalEmotes(result.parseJson(), *emotes);
if (pair.first)
this->global_.set(
std::make_shared<EmoteMap>(std::move(pair.second)));
return pair.first;
})
.execute();
}
void FfzEmotes::loadChannel(const QString &channelName,
@@ -158,40 +156,36 @@ void FfzEmotes::loadChannel(const QString &channelName,
{
log("[FFZEmotes] Reload FFZ Channel Emotes for channel {}\n", channelName);
NetworkRequest request("https://api.frankerfacez.com/v1/room/" +
channelName);
request.setCaller(QThread::currentThread());
request.setTimeout(20000);
NetworkRequest("https://api.frankerfacez.com/v1/room/" + channelName)
.caller(QThread::currentThread())
.timeout(20000)
.onSuccess([callback = std::move(callback)](auto result) -> Outcome {
auto pair = parseChannelEmotes(result.parseJson());
if (pair.first)
callback(std::move(pair.second));
return pair.first;
})
.onError([channelName](int result) {
if (result == 203)
{
// User does not have any FFZ emotes
return true;
}
request.onSuccess([callback = std::move(callback)](auto result) -> Outcome {
auto pair = parseChannelEmotes(result.parseJson());
if (pair.first)
callback(std::move(pair.second));
return pair.first;
});
if (result == -2)
{
// TODO: Auto retry in case of a timeout, with a delay
log("Fetching FFZ emotes for channel {} failed due to timeout",
channelName);
return true;
}
log("Error fetching FFZ emotes for channel {}, error {}",
channelName, result);
request.onError([channelName](int result) {
if (result == 203)
{
// User does not have any FFZ emotes
return true;
}
if (result == -2)
{
// TODO: Auto retry in case of a timeout, with a delay
log("Fetching FFZ emotes for channel {} failed due to timeout",
channelName);
return true;
}
log("Error fetching FFZ emotes for channel {}, error {}", channelName,
result);
return true;
});
request.execute();
})
.execute();
}
} // namespace chatterino
+25 -26
View File
@@ -22,38 +22,37 @@ void FfzModBadge::loadCustomModBadge()
static QString partialUrl("https://cdn.frankerfacez.com/room-badge/mod/");
QString url = partialUrl + channelName_ + "/1";
NetworkRequest req(url);
req.setCaller(QThread::currentThread());
req.onSuccess([this, url](auto result) -> Outcome {
auto data = result.getData();
NetworkRequest(url)
.caller(QThread::currentThread())
.onSuccess([this, url](auto result) -> Outcome {
auto data = result.getData();
QBuffer buffer(const_cast<QByteArray *>(&data));
buffer.open(QIODevice::ReadOnly);
QImageReader reader(&buffer);
if (reader.imageCount() == 0)
return Failure;
QBuffer buffer(const_cast<QByteArray *>(&data));
buffer.open(QIODevice::ReadOnly);
QImageReader reader(&buffer);
if (reader.imageCount() == 0)
return Failure;
QPixmap badgeOverlay = QPixmap::fromImageReader(&reader);
QPixmap badgePixmap(18, 18);
QPixmap badgeOverlay = QPixmap::fromImageReader(&reader);
QPixmap badgePixmap(18, 18);
// the default mod badge green color
badgePixmap.fill(QColor("#34AE0A"));
QPainter painter(&badgePixmap);
QRectF rect(0, 0, 18, 18);
painter.drawPixmap(rect, badgeOverlay, rect);
// the default mod badge green color
badgePixmap.fill(QColor("#34AE0A"));
QPainter painter(&badgePixmap);
QRectF rect(0, 0, 18, 18);
painter.drawPixmap(rect, badgeOverlay, rect);
auto emote = Emote{{""},
ImageSet{Image::fromPixmap(badgePixmap)},
Tooltip{"Twitch Channel Moderator"},
Url{url}};
auto emote = Emote{{""},
ImageSet{Image::fromPixmap(badgePixmap)},
Tooltip{"Twitch Channel Moderator"},
Url{url}};
this->badge_ = std::make_shared<Emote>(emote);
// getBadge.execute();
this->badge_ = std::make_shared<Emote>(emote);
// getBadge.execute();
return Success;
});
req.execute();
return Success;
})
.execute();
}
EmotePtr FfzModBadge::badge() const