diff --git a/src/providers/IvrApi.cpp b/src/providers/IvrApi.cpp index dff138ef9..28191a39d 100644 --- a/src/providers/IvrApi.cpp +++ b/src/providers/IvrApi.cpp @@ -1,5 +1,9 @@ #include "IvrApi.hpp" +#include +#include "common/APIRequest.hpp" +#include "common/NetworkCommon.hpp" +#include "common/NetworkResult.hpp" #include "common/Outcome.hpp" #include "common/QLogging.hpp" @@ -9,28 +13,24 @@ namespace chatterino { static IvrApi *instance = nullptr; -void IvrApi::getSubage(QString userName, QString channelName, - ResultCallback successCallback, - IvrFailureCallback failureCallback) +APIRequest IvrApi::subage( + const QString &userName, const QString &channelName) { assert(!userName.isEmpty() && !channelName.isEmpty()); - - this->makeRequest( - QString("twitch/subage/%1/%2").arg(userName).arg(channelName), {}) - .onSuccess([successCallback, failureCallback](auto result) -> Outcome { - auto root = result.parseJson(); - - successCallback(root); - - return Success; - }) - .onError([failureCallback](auto result) { + auto url = QString("https://api.ivr.fi/twitch/subage/%1/%2") + .arg(userName) + .arg(channelName); + return APIRequest( + QUrl(url), NetworkRequestType::Get, + [](NetworkResult result) -> IvrSubage { + return result.parseJson(); + }, + [](NetworkResult result) { qCWarning(chatterinoIvr) << "Failed IVR API Call!" << result.status() << QString(result.getData()); - failureCallback(); - }) - .execute(); + return APIRequestNoErrorValue{}; + }); } void IvrApi::getBulkEmoteSets(QString emoteSetList, diff --git a/src/providers/IvrApi.hpp b/src/providers/IvrApi.hpp index 7008b240f..fff2a6435 100644 --- a/src/providers/IvrApi.hpp +++ b/src/providers/IvrApi.hpp @@ -1,5 +1,6 @@ #pragma once +#include "common/APIRequest.hpp" #include "common/NetworkRequest.hpp" #include "messages/Link.hpp" #include "providers/twitch/TwitchEmotes.hpp" @@ -77,9 +78,8 @@ class IvrApi final : boost::noncopyable { public: // https://api.ivr.fi/docs#tag/Twitch/paths/~1twitch~1subage~1{username}~1{channel}/get - void getSubage(QString userName, QString channelName, - ResultCallback resultCallback, - IvrFailureCallback failureCallback); + APIRequest subage( + const QString &userName, const QString &channelName); // https://api.ivr.fi/v2/docs/static/index.html#/Twitch/get_twitch_emotes_sets void getBulkEmoteSets(QString emoteSetList, diff --git a/src/widgets/dialogs/UserInfoPopup.cpp b/src/widgets/dialogs/UserInfoPopup.cpp index a57fcedc5..579c701d9 100644 --- a/src/widgets/dialogs/UserInfoPopup.cpp +++ b/src/widgets/dialogs/UserInfoPopup.cpp @@ -3,6 +3,7 @@ #include "Application.hpp" #include "common/Channel.hpp" #include "common/NetworkRequest.hpp" +#include "common/Outcome.hpp" #include "common/QLogging.hpp" #include "controllers/accounts/AccountController.hpp" #include "controllers/highlights/HighlightBlacklistUser.hpp" @@ -821,12 +822,13 @@ void UserInfoPopup::updateUserData() this->ui_.ignoreHighlights->setChecked(isIgnoringHighlights); // get followage and subage - getIvr()->getSubage( - this->userName_, this->underlyingChannel_->getName(), - [this, hack](const IvrSubage &subageInfo) { + getIvr() + ->subage(this->userName_, this->underlyingChannel_->getName()) + .onSuccess([this, hack](NetworkResult, + const IvrSubage &subageInfo) -> Outcome { if (!hack.lock()) { - return; + return Success; } if (!subageInfo.followingSince.isEmpty()) @@ -856,8 +858,9 @@ void UserInfoPopup::updateUserData() QString("★ Previously subscribed for %1 months") .arg(subageInfo.totalSubMonths)); } - }, - [] {}); + return Success; + }) + .execute(); }; getHelix()->getUserByName(this->userName_, onUserFetched,