2022-10-01 14:30:29 +02:00
|
|
|
#include "messages/search/SubtierPredicate.hpp"
|
|
|
|
|
2022-12-31 15:41:01 +01:00
|
|
|
#include "messages/Message.hpp"
|
|
|
|
#include "providers/twitch/TwitchBadge.hpp"
|
2022-10-01 14:30:29 +02:00
|
|
|
#include "util/Qt.hpp"
|
|
|
|
|
|
|
|
namespace chatterino {
|
|
|
|
|
2022-12-04 12:34:13 +01:00
|
|
|
SubtierPredicate::SubtierPredicate(const QString &subtiers, bool negate)
|
|
|
|
: MessagePredicate(negate)
|
2022-10-01 14:30:29 +02:00
|
|
|
{
|
|
|
|
// Check if any comma-seperated values were passed and transform those
|
2022-12-04 12:34:13 +01:00
|
|
|
for (const auto &subtier : subtiers.split(',', Qt::SkipEmptyParts))
|
2022-10-01 14:30:29 +02:00
|
|
|
{
|
2022-12-04 12:34:13 +01:00
|
|
|
this->subtiers_ << subtier;
|
2022-10-01 14:30:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-04 12:34:13 +01:00
|
|
|
bool SubtierPredicate::appliesToImpl(const Message &message)
|
2022-10-01 14:30:29 +02:00
|
|
|
{
|
|
|
|
for (const Badge &badge : message.badges)
|
|
|
|
{
|
|
|
|
if (badge.key_ == "subscriber")
|
|
|
|
{
|
|
|
|
const auto &subTier =
|
|
|
|
badge.value_.length() > 3 ? badge.value_.at(0) : '1';
|
|
|
|
|
|
|
|
return subtiers_.contains(subTier);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace chatterino
|