mirror-chatterino2/src/messages/search/BadgePredicate.cpp
nerix 1043f9f803
Remove Unnecessary Includes in Headers (#4275)
* refactor: remove unnecessary includes in headers

* fix: formatting

* chore: changelog

* fix: scrollbar

* fix: suggestions and old appbase remains

* fix: suggestion

* fix: missing Qt forward declarations

* fix: another qt include

* fix: includes for precompiled-headers=off

* Add missing `<memory>` includes

* Add missing `#pragma once`

* Fix tests

Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com>
2022-12-31 14:41:01 +00:00

48 lines
1.2 KiB
C++

#include "messages/search/BadgePredicate.hpp"
#include "messages/Message.hpp"
#include "providers/twitch/TwitchBadge.hpp"
#include "util/Qt.hpp"
namespace chatterino {
BadgePredicate::BadgePredicate(const QString &badges, bool negate)
: MessagePredicate(negate)
{
// Check if any comma-seperated values were passed and transform those
for (const auto &badge : badges.split(',', Qt::SkipEmptyParts))
{
// convert short form name of certain badges to formal name
if (badge.compare("mod", Qt::CaseInsensitive) == 0)
{
this->badges_ << "moderator";
}
else if (badge.compare("sub", Qt::CaseInsensitive) == 0)
{
this->badges_ << "subscriber";
}
else if (badge.compare("prime", Qt::CaseInsensitive) == 0)
{
this->badges_ << "premium";
}
else
{
this->badges_ << badge;
}
}
}
bool BadgePredicate::appliesToImpl(const Message &message)
{
for (const Badge &badge : message.badges)
{
if (badges_.contains(badge.key_, Qt::CaseInsensitive))
{
return true;
}
}
return false;
}
} // namespace chatterino