Refactor NetworkRequest class
Add followUser and unfollowUser methods to TwitchAccount
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
#include "widgets/dialogs/LoginDialog.hpp"
|
||||
|
||||
#include "common/Common.hpp"
|
||||
#include "common/UrlFetch.hpp"
|
||||
#include "controllers/accounts/AccountController.hpp"
|
||||
#include "providers/twitch/PartialTwitchUser.hpp"
|
||||
|
||||
#ifdef USEWINSDK
|
||||
#include <Windows.h>
|
||||
#endif
|
||||
@@ -173,9 +177,10 @@ AdvancedLoginWidget::AdvancedLoginWidget()
|
||||
this->ui_.buttonLowerRow.layout.addWidget(&this->ui_.buttonLowerRow.fillInUserIDButton);
|
||||
|
||||
connect(&this->ui_.buttonLowerRow.fillInUserIDButton, &QPushButton::clicked, [=]() {
|
||||
twitchApiGetUserID(this->ui_.usernameInput.text(), this, [=](const QString &userID) {
|
||||
const auto onIdFetched = [=](const QString &userID) {
|
||||
this->ui_.userIDInput.setText(userID); //
|
||||
});
|
||||
};
|
||||
PartialTwitchUser::byName(this->ui_.usernameInput.text()).getId(onIdFetched, this);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "widgets/helper/ChannelView.hpp"
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QJsonArray>
|
||||
#include <QMessageBox>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
@@ -65,8 +66,8 @@ void LogsPopup::getLogviewerLogs()
|
||||
return true;
|
||||
});
|
||||
|
||||
req.getJSON([this, channelName](QJsonObject &data) {
|
||||
|
||||
req.onSuccess([this, channelName](auto result) {
|
||||
auto data = result.parseJson();
|
||||
std::vector<MessagePtr> messages;
|
||||
ChannelPtr logsChannel(new Channel("logs", Channel::Type::None));
|
||||
|
||||
@@ -87,6 +88,8 @@ void LogsPopup::getLogviewerLogs()
|
||||
messages.push_back(builder.build());
|
||||
};
|
||||
this->setMessages(messages);
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
req.execute();
|
||||
@@ -113,10 +116,12 @@ void LogsPopup::getOverrustleLogs()
|
||||
box->setAttribute(Qt::WA_DeleteOnClose);
|
||||
box->show();
|
||||
box->raise();
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
req.getJSON([this, channelName](QJsonObject &data) {
|
||||
req.onSuccess([this, channelName](auto result) {
|
||||
auto data = result.parseJson();
|
||||
std::vector<MessagePtr> messages;
|
||||
if (data.contains("lines")) {
|
||||
QJsonArray dataMessages = data.value("lines").toArray();
|
||||
@@ -135,7 +140,10 @@ void LogsPopup::getOverrustleLogs()
|
||||
}
|
||||
}
|
||||
this->setMessages(messages);
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
req.execute();
|
||||
}
|
||||
} // namespace chatterino
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
#include "Application.hpp"
|
||||
#include "common/UrlFetch.hpp"
|
||||
#include "controllers/accounts/AccountController.hpp"
|
||||
#include "providers/twitch/PartialTwitchUser.hpp"
|
||||
#include "providers/twitch/TwitchChannel.hpp"
|
||||
#include "singletons/Resources.hpp"
|
||||
#include "util/LayoutCreator.hpp"
|
||||
@@ -176,11 +178,15 @@ void UserInfoPopup::installEvents()
|
||||
QUrl requestUrl("https://api.twitch.tv/kraken/users/" + currentUser->getUserId() +
|
||||
"/follows/channels/" + this->userId_);
|
||||
|
||||
const auto reenableFollowCheckbox = [this] {
|
||||
this->ui_.follow->setEnabled(true); //
|
||||
};
|
||||
|
||||
this->ui_.follow->setEnabled(false);
|
||||
if (this->ui_.follow->isChecked()) {
|
||||
twitchApiPut(requestUrl, [this](const auto &) { this->ui_.follow->setEnabled(true); });
|
||||
currentUser->followUser(this->userId_, reenableFollowCheckbox);
|
||||
} else {
|
||||
twitchApiDelete(requestUrl, [this] { this->ui_.follow->setEnabled(true); });
|
||||
currentUser->unfollowUser(this->userId_, reenableFollowCheckbox);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -239,24 +245,28 @@ void UserInfoPopup::updateUserData()
|
||||
{
|
||||
std::weak_ptr<bool> hack = this->hack_;
|
||||
|
||||
// get user info
|
||||
twitchApiGetUserID(this->userName_, this, [this, hack](QString id) {
|
||||
const auto onIdFetched = [this, hack](QString id) {
|
||||
auto currentUser = getApp()->accounts->twitch.getCurrent();
|
||||
|
||||
this->userId_ = id;
|
||||
|
||||
// get channel info
|
||||
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()));
|
||||
this->ui_.viewCountLabel->setText(TEXT_VIEWS +
|
||||
QString::number(obj.value("views").toInt()));
|
||||
this->ui_.createdDateLabel->setText(
|
||||
TEXT_CREATED + obj.value("created_at").toString().section("T", 0, 0));
|
||||
auto request = makeGetChannelRequest(id, this);
|
||||
|
||||
this->loadAvatar(QUrl(obj.value("logo").toString()));
|
||||
});
|
||||
request.onSuccess([this](auto result) {
|
||||
auto obj = result.parseJson();
|
||||
this->ui_.followerCountLabel->setText(TEXT_FOLLOWERS +
|
||||
QString::number(obj.value("followers").toInt()));
|
||||
this->ui_.viewCountLabel->setText(TEXT_VIEWS +
|
||||
QString::number(obj.value("views").toInt()));
|
||||
this->ui_.createdDateLabel->setText(
|
||||
TEXT_CREATED + obj.value("created_at").toString().section("T", 0, 0));
|
||||
|
||||
this->loadAvatar(QUrl(obj.value("logo").toString()));
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
request.execute();
|
||||
|
||||
// get follow state
|
||||
currentUser->checkFollow(id, [this, hack](auto result) {
|
||||
@@ -279,7 +289,9 @@ void UserInfoPopup::updateUserData()
|
||||
|
||||
this->ui_.ignore->setEnabled(true);
|
||||
this->ui_.ignore->setChecked(isIgnoring);
|
||||
});
|
||||
};
|
||||
|
||||
PartialTwitchUser::byName(this->userName_).getId(onIdFetched, this);
|
||||
|
||||
this->ui_.follow->setEnabled(false);
|
||||
this->ui_.ignore->setEnabled(false);
|
||||
@@ -386,16 +398,21 @@ UserInfoPopup::TimeoutWidget::TimeoutWidget()
|
||||
|
||||
addTimeouts("sec", {{"1", 1}});
|
||||
addTimeouts("min", {
|
||||
{"1", 1 * 60}, {"5", 5 * 60}, {"10", 10 * 60},
|
||||
{"1", 1 * 60},
|
||||
{"5", 5 * 60},
|
||||
{"10", 10 * 60},
|
||||
});
|
||||
addTimeouts("hour", {
|
||||
{"1", 1 * 60 * 60}, {"4", 4 * 60 * 60},
|
||||
{"1", 1 * 60 * 60},
|
||||
{"4", 4 * 60 * 60},
|
||||
});
|
||||
addTimeouts("days", {
|
||||
{"1", 1 * 60 * 60 * 24}, {"3", 3 * 60 * 60 * 24},
|
||||
{"1", 1 * 60 * 60 * 24},
|
||||
{"3", 3 * 60 * 60 * 24},
|
||||
});
|
||||
addTimeouts("weeks", {
|
||||
{"1", 1 * 60 * 60 * 24 * 7}, {"2", 2 * 60 * 60 * 24 * 7},
|
||||
{"1", 1 * 60 * 60 * 24 * 7},
|
||||
{"2", 2 * 60 * 60 * 24 * 7},
|
||||
});
|
||||
|
||||
addButton(Ban, "ban", getApp()->resources->buttons.ban);
|
||||
|
||||
@@ -451,18 +451,25 @@ void Split::doOpenViewerList()
|
||||
}
|
||||
auto loadingLabel = new QLabel("Loading...");
|
||||
|
||||
twitchApiGet("https://tmi.twitch.tv/group/user/" + this->getChannel()->name + "/chatters", this,
|
||||
[=](QJsonObject obj) {
|
||||
QJsonObject chattersObj = obj.value("chatters").toObject();
|
||||
auto request = NetworkRequest::twitchRequest("https://tmi.twitch.tv/group/user/" +
|
||||
this->getChannel()->name + "/chatters");
|
||||
|
||||
loadingLabel->hide();
|
||||
for (int i = 0; i < jsonLabels.size(); i++) {
|
||||
chattersList->addItem(labelList.at(i));
|
||||
foreach (const QJsonValue &v,
|
||||
chattersObj.value(jsonLabels.at(i)).toArray())
|
||||
chattersList->addItem(v.toString());
|
||||
}
|
||||
});
|
||||
request.setCaller(this);
|
||||
request.onSuccess([=](auto result) {
|
||||
auto obj = result.parseJson();
|
||||
QJsonObject chattersObj = obj.value("chatters").toObject();
|
||||
|
||||
loadingLabel->hide();
|
||||
for (int i = 0; i < jsonLabels.size(); i++) {
|
||||
chattersList->addItem(labelList.at(i));
|
||||
foreach (const QJsonValue &v, chattersObj.value(jsonLabels.at(i)).toArray())
|
||||
chattersList->addItem(v.toString());
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
request.execute();
|
||||
|
||||
searchBar->setPlaceholderText("Search User...");
|
||||
QObject::connect(searchBar, &QLineEdit::textEdited, this, [=]() {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include "Application.hpp"
|
||||
#include "common/UrlFetch.hpp"
|
||||
#include "controllers/accounts/AccountController.hpp"
|
||||
#include "providers/twitch/TwitchChannel.hpp"
|
||||
#include "providers/twitch/TwitchServer.hpp"
|
||||
#include "singletons/Resources.hpp"
|
||||
@@ -323,13 +324,13 @@ void SplitHeader::updateChannelText()
|
||||
if (streamStatus.live) {
|
||||
this->isLive_ = true;
|
||||
this->tooltip_ = "<style>.center { text-align: center; }</style>"
|
||||
"<p class = \"center\">" +
|
||||
streamStatus.title + "<br><br>" + streamStatus.game + "<br>" +
|
||||
(streamStatus.rerun ? "Vod-casting" : "Live") + " for " +
|
||||
streamStatus.uptime + " with " +
|
||||
QString::number(streamStatus.viewerCount) +
|
||||
" viewers"
|
||||
"</p>";
|
||||
"<p class = \"center\">" +
|
||||
streamStatus.title + "<br><br>" + streamStatus.game + "<br>" +
|
||||
(streamStatus.rerun ? "Vod-casting" : "Live") + " for " +
|
||||
streamStatus.uptime + " with " +
|
||||
QString::number(streamStatus.viewerCount) +
|
||||
" viewers"
|
||||
"</p>";
|
||||
if (streamStatus.rerun) {
|
||||
title += " (rerun)";
|
||||
} else if (streamStatus.streamType.isEmpty()) {
|
||||
@@ -355,8 +356,8 @@ void SplitHeader::updateModerationModeIcon()
|
||||
auto app = getApp();
|
||||
|
||||
this->moderationButton_->setPixmap(this->split_->getModerationMode()
|
||||
? *app->resources->moderationmode_enabled->getPixmap()
|
||||
: *app->resources->moderationmode_disabled->getPixmap());
|
||||
? *app->resources->moderationmode_enabled->getPixmap()
|
||||
: *app->resources->moderationmode_disabled->getPixmap());
|
||||
|
||||
bool modButtonVisible = false;
|
||||
ChannelPtr channel = this->split_->getChannel();
|
||||
|
||||
Reference in New Issue
Block a user