removed unnecessary network request (#828)

This commit is contained in:
pphop 2018-10-26 02:27:45 +05:00 committed by fourtf
parent 3c9bcd581a
commit 92cc283160

View file

@ -19,58 +19,35 @@ FfzModBadge::FfzModBadge(const QString &channelName)
void FfzModBadge::loadCustomModBadge() void FfzModBadge::loadCustomModBadge()
{ {
static QString partialUrl("https://api.frankerfacez.com/v1/_room/"); static QString partialUrl("https://cdn.frankerfacez.com/room-badge/mod/");
QString url = partialUrl + channelName_; QString url = partialUrl + channelName_ + "/1";
NetworkRequest req(url); NetworkRequest req(url);
req.setCaller(QThread::currentThread()); req.setCaller(QThread::currentThread());
req.onSuccess([this](auto result) -> Outcome { req.onSuccess([this, url](auto result) -> Outcome {
auto root = result.parseJson(); auto data = result.getData();
auto modBadgeUrlField = QBuffer buffer(const_cast<QByteArray *>(&data));
root.value("room").toObject().value("moderator_badge"); buffer.open(QIODevice::ReadOnly);
if (modBadgeUrlField.isNull()) QImageReader reader(&buffer);
if (reader.imageCount() == 0)
return Failure; return Failure;
auto badgeUrl = "https:" + modBadgeUrlField.toString(); QPixmap badgeOverlay = QPixmap::fromImageReader(&reader);
/* doesnt work for some reason QPixmap badgePixmap(18, 18);
auto badgeOverlay =
Image::fromUrl({"https:" + modBadgeUrlField.toString()});
auto badgeOverlayPixmap = badgeOverlay->pixmap();
if (!badgeOverlayPixmap)
return Failure;
*/
NetworkRequest getBadge(badgeUrl);
getBadge.setCaller(QThread::currentThread());
getBadge.onSuccess([this, &badgeUrl](auto result) -> Outcome {
auto data = result.getData();
QBuffer buffer(const_cast<QByteArray *>(&data)); // the default mod badge green color
buffer.open(QIODevice::ReadOnly); badgePixmap.fill(QColor("#34AE0A"));
QImageReader reader(&buffer); QPainter painter(&badgePixmap);
if (reader.imageCount() == 0) QRectF rect(0, 0, 18, 18);
return Failure; painter.drawPixmap(rect, badgeOverlay, rect);
auto badgeOverlay = QPixmap::fromImageReader(&reader);
QPixmap badgePixmap(18, 18); auto emote = Emote{{""},
// the default mod badge green color ImageSet{Image::fromPixmap(badgePixmap)},
badgePixmap.fill(QColor("#34AE0A")); Tooltip{"Twitch Channel Moderator"},
Url{url}};
QPainter painter(&badgePixmap); this->badge_ = std::make_shared<Emote>(emote);
QRectF rect(0, 0, 18, 18);
painter.drawPixmap(rect, badgeOverlay, rect);
auto emote = Emote{{""},
ImageSet{Image::fromPixmap(badgePixmap)},
Tooltip{"Twitch Channel Moderator"},
Url{badgeUrl}};
this->badge_ = std::make_shared<Emote>(emote);
return Success;
});
getBadge.execute();
return Success; return Success;
}); });