mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
removed unnecessary network request (#828)
This commit is contained in:
parent
3c9bcd581a
commit
92cc283160
1 changed files with 20 additions and 43 deletions
|
@ -19,30 +19,12 @@ 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 modBadgeUrlField =
|
|
||||||
root.value("room").toObject().value("moderator_badge");
|
|
||||||
if (modBadgeUrlField.isNull())
|
|
||||||
return Failure;
|
|
||||||
|
|
||||||
auto badgeUrl = "https:" + modBadgeUrlField.toString();
|
|
||||||
/* doesnt work for some reason
|
|
||||||
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();
|
auto data = result.getData();
|
||||||
|
|
||||||
QBuffer buffer(const_cast<QByteArray *>(&data));
|
QBuffer buffer(const_cast<QByteArray *>(&data));
|
||||||
|
@ -50,12 +32,12 @@ void FfzModBadge::loadCustomModBadge()
|
||||||
QImageReader reader(&buffer);
|
QImageReader reader(&buffer);
|
||||||
if (reader.imageCount() == 0)
|
if (reader.imageCount() == 0)
|
||||||
return Failure;
|
return Failure;
|
||||||
auto badgeOverlay = QPixmap::fromImageReader(&reader);
|
|
||||||
|
|
||||||
|
QPixmap badgeOverlay = QPixmap::fromImageReader(&reader);
|
||||||
QPixmap badgePixmap(18, 18);
|
QPixmap badgePixmap(18, 18);
|
||||||
|
|
||||||
// the default mod badge green color
|
// the default mod badge green color
|
||||||
badgePixmap.fill(QColor("#34AE0A"));
|
badgePixmap.fill(QColor("#34AE0A"));
|
||||||
|
|
||||||
QPainter painter(&badgePixmap);
|
QPainter painter(&badgePixmap);
|
||||||
QRectF rect(0, 0, 18, 18);
|
QRectF rect(0, 0, 18, 18);
|
||||||
painter.drawPixmap(rect, badgeOverlay, rect);
|
painter.drawPixmap(rect, badgeOverlay, rect);
|
||||||
|
@ -63,18 +45,13 @@ void FfzModBadge::loadCustomModBadge()
|
||||||
auto emote = Emote{{""},
|
auto emote = Emote{{""},
|
||||||
ImageSet{Image::fromPixmap(badgePixmap)},
|
ImageSet{Image::fromPixmap(badgePixmap)},
|
||||||
Tooltip{"Twitch Channel Moderator"},
|
Tooltip{"Twitch Channel Moderator"},
|
||||||
Url{badgeUrl}};
|
Url{url}};
|
||||||
|
|
||||||
this->badge_ = std::make_shared<Emote>(emote);
|
this->badge_ = std::make_shared<Emote>(emote);
|
||||||
|
|
||||||
return Success;
|
return Success;
|
||||||
});
|
});
|
||||||
|
|
||||||
getBadge.execute();
|
|
||||||
|
|
||||||
return Success;
|
|
||||||
});
|
|
||||||
|
|
||||||
req.execute();
|
req.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue