Files
chatterino2/src/controllers/ignores/IgnoreController.cpp
nerix fca57696bb Increase max number of blocked users loaded from 100 to 1,000 (#4721)
Also includes a little refactor of how the requests are made & how the blocked users are stored
2023-07-23 11:26:12 +00:00

67 lines
2.0 KiB
C++

#include "controllers/ignores/IgnoreController.hpp"
#include "Application.hpp"
#include "common/QLogging.hpp"
#include "controllers/accounts/AccountController.hpp"
#include "controllers/ignores/IgnorePhrase.hpp"
#include "providers/twitch/TwitchAccount.hpp"
#include "singletons/Settings.hpp"
namespace chatterino {
bool isIgnoredMessage(IgnoredMessageParameters &&params)
{
if (!params.message.isEmpty())
{
// TODO(pajlada): Do we need to check if the phrase is valid first?
auto phrases = getCSettings().ignoredMessages.readOnly();
for (const auto &phrase : *phrases)
{
if (phrase.isBlock() && phrase.isMatch(params.message))
{
qCDebug(chatterinoMessage)
<< "Blocking message because it contains ignored phrase"
<< phrase.getPattern();
return true;
}
}
}
if (!params.twitchUserID.isEmpty() &&
getSettings()->enableTwitchBlockedUsers)
{
auto sourceUserID = params.twitchUserID;
bool isBlocked =
getApp()->accounts->twitch.getCurrent()->blockedUserIds().contains(
sourceUserID);
if (isBlocked)
{
switch (static_cast<ShowIgnoredUsersMessages>(
getSettings()->showBlockedUsersMessages.getValue()))
{
case ShowIgnoredUsersMessages::IfModerator:
if (params.isMod || params.isBroadcaster)
{
return false;
}
break;
case ShowIgnoredUsersMessages::IfBroadcaster:
if (params.isBroadcaster)
{
return false;
}
break;
case ShowIgnoredUsersMessages::Never:
break;
}
return true;
}
}
return false;
}
} // namespace chatterino