fix: don't include blocked users in join/part messages (#6181)

This commit is contained in:
pajlada
2025-05-03 11:32:55 +02:00
committed by GitHub
parent 555b921f65
commit e38c64bac3
12 changed files with 98 additions and 34 deletions
+1
View File
@@ -20,6 +20,7 @@
- Bugfix: Fixed the emote popup erroneously logging messages to the `Other` directory. (#6165) - Bugfix: Fixed the emote popup erroneously logging messages to the `Other` directory. (#6165)
- Bugfix: Handle <kbd>CMD</kbd> + <kbd>BACKSPACE</kbd> behavior explicitly in main chat dialog input for macOS. (#6111) - Bugfix: Handle <kbd>CMD</kbd> + <kbd>BACKSPACE</kbd> behavior explicitly in main chat dialog input for macOS. (#6111)
- Bugfix: Fixed a small typo in the settings page. (#6134) - Bugfix: Fixed a small typo in the settings page. (#6134)
- Bugfix: Fixed blocked users showing up in "Users joined:" and "Users parted:" messages. (#6181)
- Bugfix: Fixed an issue where Splits could get lost by dragging it onto your Recycle Bin. (#6147) - Bugfix: Fixed an issue where Splits could get lost by dragging it onto your Recycle Bin. (#6147)
- Bugfix: Fixed some Twitch commands not getting tab-completed correctly. (#6143) - Bugfix: Fixed some Twitch commands not getting tab-completed correctly. (#6143)
- Bugfix: Fixed shared chat badges displaying pixelated when Chatterino is scaled too much. (#6146) - Bugfix: Fixed shared chat badges displaying pixelated when Chatterino is scaled too much. (#6146)
+31 -7
View File
@@ -1,8 +1,10 @@
#include "common/ChannelChatters.hpp" #include "common/ChannelChatters.hpp"
#include "common/Channel.hpp" #include "common/Channel.hpp"
#include "messages/Message.hpp" #include "controllers/ignores/IgnoreController.hpp"
#include "debug/AssertInGuiThread.hpp"
#include "messages/MessageBuilder.hpp" #include "messages/MessageBuilder.hpp"
#include "providers/twitch/TwitchAccount.hpp"
#include <QColor> #include <QColor>
@@ -25,10 +27,21 @@ void ChannelChatters::addRecentChatter(const QString &user)
chatters->addRecentChatter(user); chatters->addRecentChatter(user);
} }
void ChannelChatters::addJoinedUser(const QString &user) void ChannelChatters::addJoinedUser(const QString &user, bool isMod,
bool isBroadcaster)
{ {
auto joinedUsers = this->joinedUsers_.access(); assertInGuiThread();
joinedUsers->append(user);
if (isIgnoredMessage(IgnoredMessageParameters{
.twitchUserLogin = user,
.isMod = isMod,
.isBroadcaster = isBroadcaster,
}))
{
return;
}
this->joinedUsers_.access()->append(user);
if (!this->joinedUsersMergeQueued_) if (!this->joinedUsersMergeQueued_)
{ {
@@ -50,10 +63,21 @@ void ChannelChatters::addJoinedUser(const QString &user)
} }
} }
void ChannelChatters::addPartedUser(const QString &user) void ChannelChatters::addPartedUser(const QString &user, bool isMod,
bool isBroadcaster)
{ {
auto partedUsers = this->partedUsers_.access(); assertInGuiThread();
partedUsers->append(user);
if (isIgnoredMessage(IgnoredMessageParameters{
.twitchUserLogin = user,
.isMod = isMod,
.isBroadcaster = isBroadcaster,
}))
{
return;
}
this->partedUsers_.access()->append(user);
if (!this->partedUsersMergeQueued_) if (!this->partedUsersMergeQueued_)
{ {
+2 -2
View File
@@ -22,8 +22,8 @@ public:
SharedAccessGuard<const ChatterSet> accessChatters() const; SharedAccessGuard<const ChatterSet> accessChatters() const;
void addRecentChatter(const QString &user); void addRecentChatter(const QString &user);
void addJoinedUser(const QString &user); void addJoinedUser(const QString &user, bool isMod, bool isBroadcaster);
void addPartedUser(const QString &user); void addPartedUser(const QString &user, bool isMod, bool isBroadcaster);
const QColor getUserColor(const QString &user); const QColor getUserColor(const QString &user);
void setUserColor(const QString &user, const QColor &color); void setUserColor(const QString &user, const QColor &color);
void updateOnlineChatters(const std::unordered_set<QString> &usernames); void updateOnlineChatters(const std::unordered_set<QString> &usernames);
@@ -53,7 +53,7 @@ QString blockUser(const CommandContext &ctx)
[currentUser, channel{ctx.channel}, [currentUser, channel{ctx.channel},
target](const HelixUser &targetUser) { target](const HelixUser &targetUser) {
getApp()->getAccounts()->twitch.getCurrent()->blockUser( getApp()->getAccounts()->twitch.getCurrent()->blockUser(
targetUser.id, nullptr, targetUser.id, targetUser.login, nullptr,
[channel, target, targetUser] { [channel, target, targetUser] {
channel->addSystemMessage( channel->addSystemMessage(
QString("You successfully blocked user %1") QString("You successfully blocked user %1")
@@ -125,7 +125,7 @@ QString unblockUser(const CommandContext &ctx)
target, target,
[currentUser, channel{ctx.channel}, target](const auto &targetUser) { [currentUser, channel{ctx.channel}, target](const auto &targetUser) {
getApp()->getAccounts()->twitch.getCurrent()->unblockUser( getApp()->getAccounts()->twitch.getCurrent()->unblockUser(
targetUser.id, nullptr, targetUser.id, targetUser.login, nullptr,
[channel, target, targetUser] { [channel, target, targetUser] {
channel->addSystemMessage( channel->addSystemMessage(
QString("You successfully unblocked user %1") QString("You successfully unblocked user %1")
+19 -8
View File
@@ -149,16 +149,27 @@ bool isIgnoredMessage(IgnoredMessageParameters &&params)
} }
} }
if (!params.twitchUserID.isEmpty() && if (getSettings()->enableTwitchBlockedUsers)
getSettings()->enableTwitchBlockedUsers)
{ {
auto sourceUserID = params.twitchUserID; bool isBlocked = false;
if (!params.twitchUserID.isEmpty())
{
isBlocked = getApp()
->getAccounts()
->twitch.getCurrent()
->blockedUserIds()
.contains(params.twitchUserID);
}
else if (!params.twitchUserLogin.isEmpty())
{
isBlocked = getApp()
->getAccounts()
->twitch.getCurrent()
->blockedUserLogins()
.contains(params.twitchUserLogin);
}
bool isBlocked = getApp()
->getAccounts()
->twitch.getCurrent()
->blockedUserIds()
.contains(sourceUserID);
if (isBlocked) if (isBlocked)
{ {
switch (static_cast<ShowIgnoredUsersMessages>( switch (static_cast<ShowIgnoredUsersMessages>(
@@ -15,6 +15,7 @@ struct IgnoredMessageParameters {
QString message; QString message;
QString twitchUserID; QString twitchUserID;
QString twitchUserLogin;
bool isMod; bool isMod;
bool isBroadcaster; bool isBroadcaster;
}; };
+4 -2
View File
@@ -934,7 +934,8 @@ void IrcMessageHandler::handleJoinMessage(Communi::IrcMessage *message)
} }
else if (getSettings()->showJoins.getValue()) else if (getSettings()->showJoins.getValue())
{ {
twitchChannel->addJoinedUser(message->nick()); twitchChannel->addJoinedUser(message->nick(), twitchChannel->isMod(),
twitchChannel->isBroadcaster());
} }
} }
@@ -954,7 +955,8 @@ void IrcMessageHandler::handlePartMessage(Communi::IrcMessage *message)
if (message->nick() != selfAccountName && if (message->nick() != selfAccountName &&
getSettings()->showParts.getValue()) getSettings()->showParts.getValue())
{ {
twitchChannel->addPartedUser(message->nick()); twitchChannel->addPartedUser(message->nick(), twitchChannel->isMod(),
twitchChannel->isBroadcaster());
} }
if (message->nick() == selfAccountName) if (message->nick() == selfAccountName)
+22 -5
View File
@@ -117,6 +117,7 @@ void TwitchAccount::loadBlocks()
this->blockToken_ = token; this->blockToken_ = token;
this->ignores_.clear(); this->ignores_.clear();
this->ignoresUserIds_.clear(); this->ignoresUserIds_.clear();
this->ignoresUserLogins_.clear();
getHelix()->loadBlocks( getHelix()->loadBlocks(
getApp()->getAccounts()->twitch.getCurrent()->userId_, getApp()->getAccounts()->twitch.getCurrent()->userId_,
@@ -129,6 +130,7 @@ void TwitchAccount::loadBlocks()
blockedUser.fromHelixBlock(block); blockedUser.fromHelixBlock(block);
this->ignores_.insert(blockedUser); this->ignores_.insert(blockedUser);
this->ignoresUserIds_.insert(blockedUser.id); this->ignoresUserIds_.insert(blockedUser.id);
this->ignoresUserLogins_.insert(blockedUser.name);
} }
}, },
[](auto error) { [](auto error) {
@@ -138,51 +140,60 @@ void TwitchAccount::loadBlocks()
std::move(token)); std::move(token));
} }
void TwitchAccount::blockUser(const QString &userId, const QObject *caller, void TwitchAccount::blockUser(const QString &userId, const QString &userLogin,
const QObject *caller,
std::function<void()> onSuccess, std::function<void()> onSuccess,
std::function<void()> onFailure) std::function<void()> onFailure)
{ {
getHelix()->blockUser( getHelix()->blockUser(
userId, caller, userId, caller,
[this, userId, onSuccess = std::move(onSuccess)] { [this, userId, userLogin, onSuccess = std::move(onSuccess)] {
assertInGuiThread(); assertInGuiThread();
TwitchUser blockedUser; TwitchUser blockedUser;
blockedUser.id = userId; blockedUser.id = userId;
blockedUser.name = userLogin;
this->ignores_.insert(blockedUser); this->ignores_.insert(blockedUser);
this->ignoresUserIds_.insert(blockedUser.id); this->ignoresUserIds_.insert(blockedUser.id);
this->ignoresUserLogins_.insert(blockedUser.name);
onSuccess(); onSuccess();
}, },
std::move(onFailure)); std::move(onFailure));
} }
void TwitchAccount::unblockUser(const QString &userId, const QObject *caller, void TwitchAccount::unblockUser(const QString &userId, const QString &userLogin,
const QObject *caller,
std::function<void()> onSuccess, std::function<void()> onSuccess,
std::function<void()> onFailure) std::function<void()> onFailure)
{ {
getHelix()->unblockUser( getHelix()->unblockUser(
userId, caller, userId, caller,
[this, userId, onSuccess = std::move(onSuccess)] { [this, userId, userLogin, onSuccess = std::move(onSuccess)] {
assertInGuiThread(); assertInGuiThread();
TwitchUser ignoredUser; TwitchUser ignoredUser;
ignoredUser.id = userId; ignoredUser.id = userId;
ignoredUser.name = userLogin;
this->ignores_.erase(ignoredUser); this->ignores_.erase(ignoredUser);
this->ignoresUserIds_.erase(ignoredUser.id); this->ignoresUserIds_.erase(ignoredUser.id);
this->ignoresUserLogins_.erase(ignoredUser.name);
onSuccess(); onSuccess();
}, },
std::move(onFailure)); std::move(onFailure));
} }
void TwitchAccount::blockUserLocally(const QString &userID) void TwitchAccount::blockUserLocally(const QString &userID,
const QString &userLogin)
{ {
assertInGuiThread(); assertInGuiThread();
assert(getApp()->isTest()); assert(getApp()->isTest());
TwitchUser blockedUser; TwitchUser blockedUser;
blockedUser.id = userID; blockedUser.id = userID;
blockedUser.name = userLogin;
this->ignores_.insert(blockedUser); this->ignores_.insert(blockedUser);
this->ignoresUserIds_.insert(blockedUser.id); this->ignoresUserIds_.insert(blockedUser.id);
this->ignoresUserLogins_.insert(blockedUser.name);
} }
const std::unordered_set<TwitchUser> &TwitchAccount::blocks() const const std::unordered_set<TwitchUser> &TwitchAccount::blocks() const
@@ -197,6 +208,12 @@ const std::unordered_set<QString> &TwitchAccount::blockedUserIds() const
return this->ignoresUserIds_; return this->ignoresUserIds_;
} }
const std::unordered_set<QString> &TwitchAccount::blockedUserLogins() const
{
assertInGuiThread();
return this->ignoresUserLogins_;
}
// AutoModActions // AutoModActions
void TwitchAccount::autoModAllow(const QString msgID, ChannelPtr channel) void TwitchAccount::autoModAllow(const QString msgID, ChannelPtr channel)
{ {
+7 -5
View File
@@ -64,17 +64,18 @@ public:
bool isAnon() const; bool isAnon() const;
void loadBlocks(); void loadBlocks();
void blockUser(const QString &userId, const QObject *caller, void blockUser(const QString &userId, const QString &userLogin,
std::function<void()> onSuccess, const QObject *caller, std::function<void()> onSuccess,
std::function<void()> onFailure); std::function<void()> onFailure);
void unblockUser(const QString &userId, const QObject *caller, void unblockUser(const QString &userId, const QString &userLogin,
std::function<void()> onSuccess, const QObject *caller, std::function<void()> onSuccess,
std::function<void()> onFailure); std::function<void()> onFailure);
void blockUserLocally(const QString &userID); void blockUserLocally(const QString &userID, const QString &userLogin);
[[nodiscard]] const std::unordered_set<TwitchUser> &blocks() const; [[nodiscard]] const std::unordered_set<TwitchUser> &blocks() const;
[[nodiscard]] const std::unordered_set<QString> &blockedUserIds() const; [[nodiscard]] const std::unordered_set<QString> &blockedUserIds() const;
[[nodiscard]] const std::unordered_set<QString> &blockedUserLogins() const;
// Automod actions // Automod actions
void autoModAllow(const QString msgID, ChannelPtr channel); void autoModAllow(const QString msgID, ChannelPtr channel);
@@ -120,6 +121,7 @@ private:
ScopedCancellationToken blockToken_; ScopedCancellationToken blockToken_;
std::unordered_set<TwitchUser> ignores_; std::unordered_set<TwitchUser> ignores_;
std::unordered_set<QString> ignoresUserIds_; std::unordered_set<QString> ignoresUserIds_;
std::unordered_set<QString> ignoresUserLogins_;
ScopedCancellationToken emoteToken_; ScopedCancellationToken emoteToken_;
UniqueAccess<std::shared_ptr<const TwitchEmoteSetMap>> emoteSets_; UniqueAccess<std::shared_ptr<const TwitchEmoteSetMap>> emoteSets_;
+6
View File
@@ -15,9 +15,15 @@ struct HelixBlock;
struct HelixUser; struct HelixUser;
struct TwitchUser { struct TwitchUser {
/// The Twitch User ID (e.g. `117166826`)
QString id; QString id;
/// The Twitch User Login (e.g. `testaccount_420`)
mutable QString name; mutable QString name;
// The Twitch User Display Name (e.g. `테스트계정420`)
mutable QString displayName; mutable QString displayName;
mutable QString profilePictureUrl; mutable QString profilePictureUrl;
void update(const TwitchUser &other) const void update(const TwitchUser &other) const
+2 -2
View File
@@ -661,7 +661,7 @@ void UserInfoPopup::installEvents()
this->ui_.block->setEnabled(false); this->ui_.block->setEnabled(false);
getApp()->getAccounts()->twitch.getCurrent()->unblockUser( getApp()->getAccounts()->twitch.getCurrent()->unblockUser(
this->userId_, this, this->userId_, this->userName_, this,
[this, reenableBlockCheckbox, currentUser] { [this, reenableBlockCheckbox, currentUser] {
this->channel_->addSystemMessage( this->channel_->addSystemMessage(
QString("You successfully unblocked user %1") QString("You successfully unblocked user %1")
@@ -702,7 +702,7 @@ void UserInfoPopup::installEvents()
} }
getApp()->getAccounts()->twitch.getCurrent()->blockUser( getApp()->getAccounts()->twitch.getCurrent()->blockUser(
this->userId_, this, this->userId_, this->userName_, this,
[this, reenableBlockCheckbox, currentUser] { [this, reenableBlockCheckbox, currentUser] {
this->channel_->addSystemMessage( this->channel_->addSystemMessage(
QString("You successfully blocked user %1") QString("You successfully blocked user %1")
+1 -1
View File
@@ -469,7 +469,7 @@ public:
this->mockApplication->getAccounts() this->mockApplication->getAccounts()
->twitch.getCurrent() ->twitch.getCurrent()
->blockUserLocally(u"12345"_s); ->blockUserLocally(u"12345"_s, u"blocked"_s);
auto makeBadge = [](QStringView platform) { auto makeBadge = [](QStringView platform) {
return std::make_shared<Emote>(Emote{ return std::make_shared<Emote>(Emote{