mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
renamed twitch api get functions
This commit is contained in:
parent
54eb07e116
commit
c74bc00106
6 changed files with 24 additions and 23 deletions
|
@ -23,7 +23,7 @@
|
||||||
|
|
||||||
namespace chatterino {
|
namespace chatterino {
|
||||||
|
|
||||||
static void get(QString url, const QObject *caller,
|
static void twitchApiGet(QString url, const QObject *caller,
|
||||||
std::function<void(const QJsonObject &)> successCallback)
|
std::function<void(const QJsonObject &)> successCallback)
|
||||||
{
|
{
|
||||||
NetworkRequest req(url);
|
NetworkRequest req(url);
|
||||||
|
@ -36,7 +36,7 @@ static void get(QString url, const QObject *caller,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
static void get2(QString url, const QObject *caller, bool useQuickLoadCache,
|
static void twitchApiGet2(QString url, const QObject *caller, bool useQuickLoadCache,
|
||||||
std::function<void(const rapidjson::Document &)> successCallback)
|
std::function<void(const rapidjson::Document &)> successCallback)
|
||||||
{
|
{
|
||||||
NetworkRequest req(url);
|
NetworkRequest req(url);
|
||||||
|
@ -50,7 +50,7 @@ static void get2(QString url, const QObject *caller, bool useQuickLoadCache,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
static void getAuthorized(QString url, const QString &clientID, const QString &oauthToken,
|
static void twitchApiGetAuthorized(QString url, const QString &clientID, const QString &oauthToken,
|
||||||
const QObject *caller,
|
const QObject *caller,
|
||||||
std::function<void(const QJsonObject &)> successCallback)
|
std::function<void(const QJsonObject &)> successCallback)
|
||||||
{
|
{
|
||||||
|
@ -65,10 +65,11 @@ static void getAuthorized(QString url, const QString &clientID, const QString &o
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
static void getUserID(QString username, const QObject *caller,
|
static void twitchApiGetUserID(QString username, const QObject *caller,
|
||||||
std::function<void(QString)> successCallback)
|
std::function<void(QString)> successCallback)
|
||||||
{
|
{
|
||||||
get("https://api.twitch.tv/kraken/users?login=" + username, caller,
|
twitchApiGet(
|
||||||
|
"https://api.twitch.tv/kraken/users?login=" + username, caller,
|
||||||
[=](const QJsonObject &root) {
|
[=](const QJsonObject &root) {
|
||||||
if (!root.value("users").isArray()) {
|
if (!root.value("users").isArray()) {
|
||||||
Log("API Error while getting user id, users is not an array");
|
Log("API Error while getting user id, users is not an array");
|
||||||
|
@ -94,7 +95,7 @@ static void getUserID(QString username, const QObject *caller,
|
||||||
successCallback(id.toString());
|
successCallback(id.toString());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
static void put(QUrl url, std::function<void(QJsonObject)> successCallback)
|
static void twitchApiPut(QUrl url, std::function<void(QJsonObject)> successCallback)
|
||||||
{
|
{
|
||||||
QNetworkRequest request(url);
|
QNetworkRequest request(url);
|
||||||
|
|
||||||
|
@ -124,7 +125,7 @@ static void put(QUrl url, std::function<void(QJsonObject)> successCallback)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
static void sendDelete(QUrl url, std::function<void()> successCallback)
|
static void twitchApiDelete(QUrl url, std::function<void()> successCallback)
|
||||||
{
|
{
|
||||||
QNetworkRequest request(url);
|
QNetworkRequest request(url);
|
||||||
|
|
||||||
|
|
|
@ -119,7 +119,7 @@ void TwitchAccount::loadIgnores()
|
||||||
void TwitchAccount::ignore(const QString &targetName,
|
void TwitchAccount::ignore(const QString &targetName,
|
||||||
std::function<void(IgnoreResult, const QString &)> onFinished)
|
std::function<void(IgnoreResult, const QString &)> onFinished)
|
||||||
{
|
{
|
||||||
getUserID(targetName, QThread::currentThread(), [=](QString targetUserID) {
|
twitchApiGetUserID(targetName, QThread::currentThread(), [=](QString targetUserID) {
|
||||||
this->ignoreByID(targetUserID, targetName, onFinished); //
|
this->ignoreByID(targetUserID, targetName, onFinished); //
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -179,7 +179,7 @@ void TwitchAccount::ignoreByID(const QString &targetUserID, const QString &targe
|
||||||
void TwitchAccount::unignore(const QString &targetName,
|
void TwitchAccount::unignore(const QString &targetName,
|
||||||
std::function<void(UnignoreResult, const QString &message)> onFinished)
|
std::function<void(UnignoreResult, const QString &message)> onFinished)
|
||||||
{
|
{
|
||||||
getUserID(targetName, QThread::currentThread(), [=](QString targetUserID) {
|
twitchApiGetUserID(targetName, QThread::currentThread(), [=](QString targetUserID) {
|
||||||
this->unignoreByID(targetUserID, targetName, onFinished); //
|
this->unignoreByID(targetUserID, targetName, onFinished); //
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,7 +83,7 @@ TwitchChannel::TwitchChannel(const QString &channelName, Communi::IrcConnection
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
get("https://tmi.twitch.tv/group/user/" + this->name + "/chatters",
|
twitchApiGet("https://tmi.twitch.tv/group/user/" + this->name + "/chatters",
|
||||||
QThread::currentThread(), refreshChatters);
|
QThread::currentThread(), refreshChatters);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -332,7 +332,7 @@ void TwitchChannel::refreshLiveStatus()
|
||||||
|
|
||||||
std::weak_ptr<Channel> weak = this->shared_from_this();
|
std::weak_ptr<Channel> weak = this->shared_from_this();
|
||||||
|
|
||||||
get2(url, QThread::currentThread(), false, [weak](const rapidjson::Document &d) {
|
twitchApiGet2(url, QThread::currentThread(), false, [weak](const rapidjson::Document &d) {
|
||||||
ChannelPtr shared = weak.lock();
|
ChannelPtr shared = weak.lock();
|
||||||
|
|
||||||
if (!shared) {
|
if (!shared) {
|
||||||
|
@ -432,7 +432,7 @@ void TwitchChannel::fetchRecentMessages()
|
||||||
|
|
||||||
std::weak_ptr<Channel> weak = this->shared_from_this();
|
std::weak_ptr<Channel> weak = this->shared_from_this();
|
||||||
|
|
||||||
get(genericURL.arg(roomID), QThread::currentThread(), [weak](QJsonObject obj) {
|
twitchApiGet(genericURL.arg(roomID), QThread::currentThread(), [weak](QJsonObject obj) {
|
||||||
ChannelPtr shared = weak.lock();
|
ChannelPtr shared = weak.lock();
|
||||||
|
|
||||||
if (!shared) {
|
if (!shared) {
|
||||||
|
|
|
@ -172,7 +172,7 @@ AdvancedLoginWidget::AdvancedLoginWidget()
|
||||||
this->ui.buttonLowerRow.layout.addWidget(&this->ui.buttonLowerRow.fillInUserIDButton);
|
this->ui.buttonLowerRow.layout.addWidget(&this->ui.buttonLowerRow.fillInUserIDButton);
|
||||||
|
|
||||||
connect(&this->ui.buttonLowerRow.fillInUserIDButton, &QPushButton::clicked, [=]() {
|
connect(&this->ui.buttonLowerRow.fillInUserIDButton, &QPushButton::clicked, [=]() {
|
||||||
getUserID(this->ui.usernameInput.text(), this, [=](const QString &userID) {
|
twitchApiGetUserID(this->ui.usernameInput.text(), this, [=](const QString &userID) {
|
||||||
this->ui.userIDInput.setText(userID); //
|
this->ui.userIDInput.setText(userID); //
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -171,10 +171,10 @@ void UserInfoPopup::installEvents()
|
||||||
|
|
||||||
this->ui_.follow->setEnabled(false);
|
this->ui_.follow->setEnabled(false);
|
||||||
if (this->ui_.follow->isChecked()) {
|
if (this->ui_.follow->isChecked()) {
|
||||||
put(requestUrl,
|
twitchApiPut(requestUrl,
|
||||||
[this](QJsonObject) { this->ui_.follow->setEnabled(true); });
|
[this](QJsonObject) { this->ui_.follow->setEnabled(true); });
|
||||||
} else {
|
} else {
|
||||||
sendDelete(requestUrl, [this] { this->ui_.follow->setEnabled(true); });
|
twitchApiDelete(requestUrl, [this] { this->ui_.follow->setEnabled(true); });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -234,13 +234,13 @@ void UserInfoPopup::updateUserData()
|
||||||
std::weak_ptr<bool> hack = this->hack_;
|
std::weak_ptr<bool> hack = this->hack_;
|
||||||
|
|
||||||
// get user info
|
// get user info
|
||||||
getUserID(this->userName_, this, [this, hack](QString id) {
|
twitchApiGetUserID(this->userName_, this, [this, hack](QString id) {
|
||||||
auto currentUser = getApp()->accounts->twitch.getCurrent();
|
auto currentUser = getApp()->accounts->twitch.getCurrent();
|
||||||
|
|
||||||
this->userId_ = id;
|
this->userId_ = id;
|
||||||
|
|
||||||
// get channel info
|
// get channel info
|
||||||
get(
|
twitchApiGet(
|
||||||
"https://api.twitch.tv/kraken/channels/" + id, this, [this](const QJsonObject &obj) {
|
"https://api.twitch.tv/kraken/channels/" + id, this, [this](const QJsonObject &obj) {
|
||||||
this->ui_.followerCountLabel->setText(
|
this->ui_.followerCountLabel->setText(
|
||||||
TEXT_FOLLOWERS + QString::number(obj.value("followers").toInt()));
|
TEXT_FOLLOWERS + QString::number(obj.value("followers").toInt()));
|
||||||
|
|
|
@ -449,7 +449,7 @@ void Split::doOpenViewerList()
|
||||||
}
|
}
|
||||||
auto loadingLabel = new QLabel("Loading...");
|
auto loadingLabel = new QLabel("Loading...");
|
||||||
|
|
||||||
get("https://tmi.twitch.tv/group/user/" + this->getChannel()->name + "/chatters",
|
twitchApiGet("https://tmi.twitch.tv/group/user/" + this->getChannel()->name + "/chatters",
|
||||||
this, [=](QJsonObject obj) {
|
this, [=](QJsonObject obj) {
|
||||||
QJsonObject chattersObj = obj.value("chatters").toObject();
|
QJsonObject chattersObj = obj.value("chatters").toObject();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue