Migrated block, unblock and get user block list methods to Helix (#2370)
Co-authored-by: pajlada <rasmus.karlsson@pajlada.com>
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include "controllers/highlights/HighlightBlacklistUser.hpp"
|
||||
#include "messages/Message.hpp"
|
||||
#include "providers/IvrApi.hpp"
|
||||
#include "providers/irc/IrcMessageBuilder.hpp"
|
||||
#include "providers/twitch/TwitchChannel.hpp"
|
||||
#include "providers/twitch/api/Helix.hpp"
|
||||
#include "providers/twitch/api/Kraken.hpp"
|
||||
@@ -188,7 +189,7 @@ UserInfoPopup::UserInfoPopup(bool closeAutomatically, QWidget *parent)
|
||||
user->addStretch(1);
|
||||
|
||||
user.emplace<QCheckBox>("Follow").assign(&this->ui_.follow);
|
||||
user.emplace<QCheckBox>("Ignore").assign(&this->ui_.ignore);
|
||||
user.emplace<QCheckBox>("Block").assign(&this->ui_.block);
|
||||
user.emplace<QCheckBox>("Ignore highlights")
|
||||
.assign(&this->ui_.ignoreHighlights);
|
||||
auto usercard = user.emplace<EffectLabel2>(this);
|
||||
@@ -414,50 +415,71 @@ void UserInfoPopup::installEvents()
|
||||
|
||||
std::shared_ptr<bool> ignoreNext = std::make_shared<bool>(false);
|
||||
|
||||
// ignore
|
||||
// block
|
||||
QObject::connect(
|
||||
this->ui_.ignore, &QCheckBox::stateChanged,
|
||||
[this, ignoreNext, hack](int) mutable {
|
||||
if (*ignoreNext)
|
||||
this->ui_.block, &QCheckBox::stateChanged,
|
||||
[this](int newState) mutable {
|
||||
auto currentUser = getApp()->accounts->twitch.getCurrent();
|
||||
|
||||
const auto reenableBlockCheckbox = [this] {
|
||||
this->ui_.block->setEnabled(true);
|
||||
};
|
||||
|
||||
if (!this->ui_.block->isEnabled())
|
||||
{
|
||||
*ignoreNext = false;
|
||||
reenableBlockCheckbox();
|
||||
return;
|
||||
}
|
||||
|
||||
this->ui_.ignore->setEnabled(false);
|
||||
switch (newState)
|
||||
{
|
||||
case Qt::CheckState::Unchecked: {
|
||||
this->ui_.block->setEnabled(false);
|
||||
|
||||
auto currentUser = getApp()->accounts->twitch.getCurrent();
|
||||
if (this->ui_.ignore->isChecked())
|
||||
{
|
||||
currentUser->ignoreByID(
|
||||
this->userId_, this->userName_,
|
||||
[=](auto result, const auto &message) mutable {
|
||||
if (hack.lock())
|
||||
{
|
||||
if (result == IgnoreResult_Failed)
|
||||
{
|
||||
*ignoreNext = true;
|
||||
this->ui_.ignore->setChecked(false);
|
||||
}
|
||||
this->ui_.ignore->setEnabled(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
currentUser->unignoreByID(
|
||||
this->userId_, this->userName_,
|
||||
[=](auto result, const auto &message) mutable {
|
||||
if (hack.lock())
|
||||
{
|
||||
if (result == UnignoreResult_Failed)
|
||||
{
|
||||
*ignoreNext = true;
|
||||
this->ui_.ignore->setChecked(true);
|
||||
}
|
||||
this->ui_.ignore->setEnabled(true);
|
||||
}
|
||||
});
|
||||
getApp()->accounts->twitch.getCurrent()->unblockUser(
|
||||
this->userId_,
|
||||
[this, reenableBlockCheckbox, currentUser] {
|
||||
this->channel_->addMessage(makeSystemMessage(
|
||||
QString("You successfully unblocked user %1")
|
||||
.arg(this->userName_)));
|
||||
reenableBlockCheckbox();
|
||||
},
|
||||
[this, reenableBlockCheckbox] {
|
||||
this->channel_->addMessage(
|
||||
makeSystemMessage(QString(
|
||||
"User %1 couldn't be unblocked, an unknown "
|
||||
"error occurred!")));
|
||||
reenableBlockCheckbox();
|
||||
});
|
||||
}
|
||||
break;
|
||||
|
||||
case Qt::CheckState::PartiallyChecked: {
|
||||
// We deliberately ignore this state
|
||||
}
|
||||
break;
|
||||
|
||||
case Qt::CheckState::Checked: {
|
||||
this->ui_.block->setEnabled(false);
|
||||
|
||||
getApp()->accounts->twitch.getCurrent()->blockUser(
|
||||
this->userId_,
|
||||
[this, reenableBlockCheckbox, currentUser] {
|
||||
this->channel_->addMessage(makeSystemMessage(
|
||||
QString("You successfully blocked user %1")
|
||||
.arg(this->userName_)));
|
||||
reenableBlockCheckbox();
|
||||
},
|
||||
[this, reenableBlockCheckbox] {
|
||||
this->channel_->addMessage(makeSystemMessage(
|
||||
QString(
|
||||
"User %1 couldn't be blocked, an unknown "
|
||||
"error occurred!")
|
||||
.arg(this->userName_)));
|
||||
reenableBlockCheckbox();
|
||||
});
|
||||
}
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -634,9 +656,9 @@ void UserInfoPopup::updateUserData()
|
||||
|
||||
// get ignore state
|
||||
bool isIgnoring = false;
|
||||
for (const auto &ignoredUser : currentUser->getIgnores())
|
||||
for (const auto &blockedUser : currentUser->getBlocks())
|
||||
{
|
||||
if (user.id == ignoredUser.id)
|
||||
if (user.id == blockedUser.id)
|
||||
{
|
||||
isIgnoring = true;
|
||||
break;
|
||||
@@ -663,8 +685,8 @@ void UserInfoPopup::updateUserData()
|
||||
{
|
||||
this->ui_.ignoreHighlights->setEnabled(true);
|
||||
}
|
||||
this->ui_.ignore->setEnabled(true);
|
||||
this->ui_.ignore->setChecked(isIgnoring);
|
||||
this->ui_.block->setChecked(isIgnoring);
|
||||
this->ui_.block->setEnabled(true);
|
||||
this->ui_.ignoreHighlights->setChecked(isIgnoringHighlights);
|
||||
|
||||
// get followage and subage
|
||||
@@ -711,7 +733,7 @@ void UserInfoPopup::updateUserData()
|
||||
onUserFetchFailed);
|
||||
|
||||
this->ui_.follow->setEnabled(false);
|
||||
this->ui_.ignore->setEnabled(false);
|
||||
this->ui_.block->setEnabled(false);
|
||||
this->ui_.ignoreHighlights->setEnabled(false);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user