From c74bc001060dc3c82a366ffe05ede0c961b09097 Mon Sep 17 00:00:00 2001 From: fourtf Date: Tue, 26 Jun 2018 17:12:50 +0200 Subject: [PATCH] renamed twitch api get functions --- src/common/UrlFetch.hpp | 25 +++++++++++++------------ src/providers/twitch/TwitchAccount.cpp | 4 ++-- src/providers/twitch/TwitchChannel.cpp | 6 +++--- src/widgets/dialogs/LoginDialog.cpp | 2 +- src/widgets/dialogs/UserInfoPopup.cpp | 8 ++++---- src/widgets/splits/Split.cpp | 2 +- 6 files changed, 24 insertions(+), 23 deletions(-) diff --git a/src/common/UrlFetch.hpp b/src/common/UrlFetch.hpp index a1b3e204e..3086bd3c3 100644 --- a/src/common/UrlFetch.hpp +++ b/src/common/UrlFetch.hpp @@ -23,8 +23,8 @@ namespace chatterino { -static void get(QString url, const QObject *caller, - std::function successCallback) +static void twitchApiGet(QString url, const QObject *caller, + std::function successCallback) { NetworkRequest req(url); req.setCaller(caller); @@ -36,8 +36,8 @@ static void get(QString url, const QObject *caller, }); } -static void get2(QString url, const QObject *caller, bool useQuickLoadCache, - std::function successCallback) +static void twitchApiGet2(QString url, const QObject *caller, bool useQuickLoadCache, + std::function successCallback) { NetworkRequest req(url); req.setCaller(caller); @@ -50,9 +50,9 @@ static void get2(QString url, const QObject *caller, bool useQuickLoadCache, }); } -static void getAuthorized(QString url, const QString &clientID, const QString &oauthToken, - const QObject *caller, - std::function successCallback) +static void twitchApiGetAuthorized(QString url, const QString &clientID, const QString &oauthToken, + const QObject *caller, + std::function successCallback) { NetworkRequest req(url); req.setCaller(caller); @@ -65,10 +65,11 @@ static void getAuthorized(QString url, const QString &clientID, const QString &o }); } -static void getUserID(QString username, const QObject *caller, - std::function successCallback) +static void twitchApiGetUserID(QString username, const QObject *caller, + std::function successCallback) { - get("https://api.twitch.tv/kraken/users?login=" + username, caller, + twitchApiGet( + "https://api.twitch.tv/kraken/users?login=" + username, caller, [=](const QJsonObject &root) { if (!root.value("users").isArray()) { 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()); }); } -static void put(QUrl url, std::function successCallback) +static void twitchApiPut(QUrl url, std::function successCallback) { QNetworkRequest request(url); @@ -124,7 +125,7 @@ static void put(QUrl url, std::function successCallback) }); } -static void sendDelete(QUrl url, std::function successCallback) +static void twitchApiDelete(QUrl url, std::function successCallback) { QNetworkRequest request(url); diff --git a/src/providers/twitch/TwitchAccount.cpp b/src/providers/twitch/TwitchAccount.cpp index 24cd8cd7d..754ed22f7 100644 --- a/src/providers/twitch/TwitchAccount.cpp +++ b/src/providers/twitch/TwitchAccount.cpp @@ -119,7 +119,7 @@ void TwitchAccount::loadIgnores() void TwitchAccount::ignore(const QString &targetName, std::function onFinished) { - getUserID(targetName, QThread::currentThread(), [=](QString targetUserID) { + twitchApiGetUserID(targetName, QThread::currentThread(), [=](QString targetUserID) { this->ignoreByID(targetUserID, targetName, onFinished); // }); } @@ -179,7 +179,7 @@ void TwitchAccount::ignoreByID(const QString &targetUserID, const QString &targe void TwitchAccount::unignore(const QString &targetName, std::function onFinished) { - getUserID(targetName, QThread::currentThread(), [=](QString targetUserID) { + twitchApiGetUserID(targetName, QThread::currentThread(), [=](QString targetUserID) { this->unignoreByID(targetUserID, targetName, onFinished); // }); } diff --git a/src/providers/twitch/TwitchChannel.cpp b/src/providers/twitch/TwitchChannel.cpp index 6fe7a270a..2a5abe4ae 100644 --- a/src/providers/twitch/TwitchChannel.cpp +++ b/src/providers/twitch/TwitchChannel.cpp @@ -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); }; @@ -332,7 +332,7 @@ void TwitchChannel::refreshLiveStatus() std::weak_ptr 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(); if (!shared) { @@ -432,7 +432,7 @@ void TwitchChannel::fetchRecentMessages() std::weak_ptr 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(); if (!shared) { diff --git a/src/widgets/dialogs/LoginDialog.cpp b/src/widgets/dialogs/LoginDialog.cpp index 0d3476678..76410b254 100644 --- a/src/widgets/dialogs/LoginDialog.cpp +++ b/src/widgets/dialogs/LoginDialog.cpp @@ -172,7 +172,7 @@ AdvancedLoginWidget::AdvancedLoginWidget() this->ui.buttonLowerRow.layout.addWidget(&this->ui.buttonLowerRow.fillInUserIDButton); 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); // }); }); diff --git a/src/widgets/dialogs/UserInfoPopup.cpp b/src/widgets/dialogs/UserInfoPopup.cpp index 4ca58bcca..101136898 100644 --- a/src/widgets/dialogs/UserInfoPopup.cpp +++ b/src/widgets/dialogs/UserInfoPopup.cpp @@ -171,10 +171,10 @@ void UserInfoPopup::installEvents() this->ui_.follow->setEnabled(false); if (this->ui_.follow->isChecked()) { - put(requestUrl, + twitchApiPut(requestUrl, [this](QJsonObject) { this->ui_.follow->setEnabled(true); }); } 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 hack = this->hack_; // 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(); this->userId_ = id; // get channel info - get( + twitchApiGet( "https://api.twitch.tv/kraken/channels/" + id, this, [this](const QJsonObject &obj) { this->ui_.followerCountLabel->setText( TEXT_FOLLOWERS + QString::number(obj.value("followers").toInt())); diff --git a/src/widgets/splits/Split.cpp b/src/widgets/splits/Split.cpp index 2e72a829f..2c6f5c917 100644 --- a/src/widgets/splits/Split.cpp +++ b/src/widgets/splits/Split.cpp @@ -449,7 +449,7 @@ void Split::doOpenViewerList() } 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) { QJsonObject chattersObj = obj.value("chatters").toObject();