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);
|
||||
}
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ private:
|
||||
Label *subageLabel = nullptr;
|
||||
|
||||
QCheckBox *follow = nullptr;
|
||||
QCheckBox *ignore = nullptr;
|
||||
QCheckBox *block = nullptr;
|
||||
QCheckBox *ignoreHighlights = nullptr;
|
||||
|
||||
Label *noMessagesLabel = nullptr;
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
#include <QVBoxLayout>
|
||||
|
||||
// clang-format off
|
||||
#define INFO "/ignore <user> in chat ignores a user.\n/unignore <user> in chat unignores a user.\nYou can also click on a user to open the usercard."
|
||||
#define INFO "/block <user> in chat blocks a user.\n/block <user> in chat unblocks a user.\nYou can also click on a user to open the usercard."
|
||||
// clang-format on
|
||||
|
||||
namespace chatterino {
|
||||
@@ -73,18 +73,18 @@ void addUsersTab(IgnoresPage &page, LayoutCreator<QVBoxLayout> users,
|
||||
{
|
||||
auto label = users.emplace<QLabel>(INFO);
|
||||
label->setWordWrap(true);
|
||||
users.append(page.createCheckBox("Enable twitch ignored users",
|
||||
getSettings()->enableTwitchIgnoredUsers));
|
||||
users.append(page.createCheckBox("Enable twitch blocked users",
|
||||
getSettings()->enableTwitchBlockedUsers));
|
||||
|
||||
auto anyways = users.emplace<QHBoxLayout>().withoutMargin();
|
||||
{
|
||||
anyways.emplace<QLabel>("Show messages from ignored users anyways:");
|
||||
anyways.emplace<QLabel>("Show messages from blocked users:");
|
||||
|
||||
auto combo = anyways.emplace<QComboBox>().getElement();
|
||||
combo->addItems(
|
||||
{"Never", "If you are Moderator", "If you are Broadcaster"});
|
||||
|
||||
auto &setting = getSettings()->showIgnoredUsersMessages;
|
||||
auto &setting = getSettings()->showBlockedUsersMessages;
|
||||
|
||||
setting.connect([combo](const int value) {
|
||||
combo->setCurrentIndex(value);
|
||||
@@ -102,12 +102,12 @@ void addUsersTab(IgnoresPage &page, LayoutCreator<QVBoxLayout> users,
|
||||
|
||||
/*auto addremove = users.emplace<QHBoxLayout>().withoutMargin();
|
||||
{
|
||||
auto add = addremove.emplace<QPushButton>("Ignore user");
|
||||
auto remove = addremove.emplace<QPushButton>("Unignore User");
|
||||
auto add = addremove.emplace<QPushButton>("Block user");
|
||||
auto remove = addremove.emplace<QPushButton>("Unblock User");
|
||||
addremove->addStretch(1);
|
||||
}*/
|
||||
|
||||
users.emplace<QLabel>("List of ignored users:");
|
||||
users.emplace<QLabel>("List of blocked users:");
|
||||
users.emplace<QListView>()->setModel(&userModel);
|
||||
}
|
||||
|
||||
@@ -123,9 +123,9 @@ void IgnoresPage::onShow()
|
||||
}
|
||||
|
||||
QStringList users;
|
||||
for (const auto &ignoredUser : user->getIgnores())
|
||||
for (const auto &blockedUser : user->getBlocks())
|
||||
{
|
||||
users << ignoredUser.name;
|
||||
users << blockedUser.name;
|
||||
}
|
||||
users.sort(Qt::CaseInsensitive);
|
||||
this->userListModel_.setStringList(users);
|
||||
|
||||
Reference in New Issue
Block a user