mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
Refactor IvrApi::getSubage to use APIRequest<T,U> as an example usage
This commit is contained in:
parent
f7194e820c
commit
0d3f0b7585
3 changed files with 29 additions and 26 deletions
|
@ -1,5 +1,9 @@
|
|||
#include "IvrApi.hpp"
|
||||
#include <qurl.h>
|
||||
|
||||
#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<IvrSubage> successCallback,
|
||||
IvrFailureCallback failureCallback)
|
||||
APIRequest<IvrSubage, APIRequestNoErrorValue> 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<IvrSubage, APIRequestNoErrorValue>(
|
||||
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,
|
||||
|
|
|
@ -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<IvrSubage> resultCallback,
|
||||
IvrFailureCallback failureCallback);
|
||||
APIRequest<IvrSubage, APIRequestNoErrorValue> 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,
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue