mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
Add search predicates for badges and sub tiers (#4013)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com>
This commit is contained in:
parent
b5241670ae
commit
bfcc9ff7a4
|
@ -18,6 +18,8 @@
|
||||||
- Minor: Clicking `A message from x was deleted` messages will now jump to the message in question. (#3953)
|
- Minor: Clicking `A message from x was deleted` messages will now jump to the message in question. (#3953)
|
||||||
- Minor: Added `is:first-msg` search option. (#3700)
|
- Minor: Added `is:first-msg` search option. (#3700)
|
||||||
- Minor: Added `is:elevated-msg` search option. (#4018)
|
- Minor: Added `is:elevated-msg` search option. (#4018)
|
||||||
|
- Minor: Added `subtier:` search option (e.g. `subtier:3` to find Tier 3 subs). (#4013)
|
||||||
|
- Minor: Added `badge:` search option (e.g. `badge:mod` to users with the moderator badge). (#4013)
|
||||||
- Minor: Added AutoMod message flag filter. (#3938)
|
- Minor: Added AutoMod message flag filter. (#3938)
|
||||||
- Minor: Added chatter count for each category in viewer list. (#3683, #3719)
|
- Minor: Added chatter count for each category in viewer list. (#3683, #3719)
|
||||||
- Minor: Added option to open a user's chat in a new tab from the usercard profile picture context menu. (#3625)
|
- Minor: Added option to open a user's chat in a new tab from the usercard profile picture context menu. (#3625)
|
||||||
|
|
|
@ -156,6 +156,8 @@ set(SOURCE_FILES
|
||||||
messages/layouts/MessageLayoutElement.hpp
|
messages/layouts/MessageLayoutElement.hpp
|
||||||
messages/search/AuthorPredicate.cpp
|
messages/search/AuthorPredicate.cpp
|
||||||
messages/search/AuthorPredicate.hpp
|
messages/search/AuthorPredicate.hpp
|
||||||
|
messages/search/BadgePredicate.cpp
|
||||||
|
messages/search/BadgePredicate.hpp
|
||||||
messages/search/ChannelPredicate.cpp
|
messages/search/ChannelPredicate.cpp
|
||||||
messages/search/ChannelPredicate.hpp
|
messages/search/ChannelPredicate.hpp
|
||||||
messages/search/LinkPredicate.cpp
|
messages/search/LinkPredicate.cpp
|
||||||
|
@ -166,6 +168,8 @@ set(SOURCE_FILES
|
||||||
messages/search/RegexPredicate.hpp
|
messages/search/RegexPredicate.hpp
|
||||||
messages/search/SubstringPredicate.cpp
|
messages/search/SubstringPredicate.cpp
|
||||||
messages/search/SubstringPredicate.hpp
|
messages/search/SubstringPredicate.hpp
|
||||||
|
messages/search/SubtierPredicate.cpp
|
||||||
|
messages/search/SubtierPredicate.hpp
|
||||||
|
|
||||||
providers/IvrApi.cpp
|
providers/IvrApi.cpp
|
||||||
providers/IvrApi.hpp
|
providers/IvrApi.hpp
|
||||||
|
|
48
src/messages/search/BadgePredicate.cpp
Normal file
48
src/messages/search/BadgePredicate.cpp
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
#include "messages/search/BadgePredicate.hpp"
|
||||||
|
|
||||||
|
#include "util/Qt.hpp"
|
||||||
|
|
||||||
|
namespace chatterino {
|
||||||
|
|
||||||
|
BadgePredicate::BadgePredicate(const QStringList &badges)
|
||||||
|
{
|
||||||
|
// Check if any comma-seperated values were passed and transform those
|
||||||
|
for (const auto &entry : badges)
|
||||||
|
{
|
||||||
|
for (const auto &badge : entry.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::appliesTo(const Message &message)
|
||||||
|
{
|
||||||
|
for (const Badge &badge : message.badges)
|
||||||
|
{
|
||||||
|
if (badges_.contains(badge.key_, Qt::CaseInsensitive))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace chatterino
|
38
src/messages/search/BadgePredicate.hpp
Normal file
38
src/messages/search/BadgePredicate.hpp
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "messages/search/MessagePredicate.hpp"
|
||||||
|
|
||||||
|
namespace chatterino {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief MessagePredicate checking for the badges of a message.
|
||||||
|
*
|
||||||
|
* This predicate will only allow messages that are sent by a list of users,
|
||||||
|
* specified by their user names, who have a badge specified (i.e 'staff').
|
||||||
|
*/
|
||||||
|
class BadgePredicate : public MessagePredicate
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Create an BadgePredicate with a list of badges to search for.
|
||||||
|
*
|
||||||
|
* @param badges a list of badges that a message should contain
|
||||||
|
*/
|
||||||
|
BadgePredicate(const QStringList &badges);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Checks whether the message contains any of the badges passed
|
||||||
|
* in the constructor.
|
||||||
|
*
|
||||||
|
* @param message the message to check
|
||||||
|
* @return true if the message contains a badge listed in the specified badges,
|
||||||
|
* false otherwise
|
||||||
|
*/
|
||||||
|
bool appliesTo(const Message &message) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
/// Holds the badges that will be searched for
|
||||||
|
QStringList badges_;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace chatterino
|
35
src/messages/search/SubtierPredicate.cpp
Normal file
35
src/messages/search/SubtierPredicate.cpp
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
#include "messages/search/SubtierPredicate.hpp"
|
||||||
|
|
||||||
|
#include "util/Qt.hpp"
|
||||||
|
|
||||||
|
namespace chatterino {
|
||||||
|
|
||||||
|
SubtierPredicate::SubtierPredicate(const QStringList &subtiers)
|
||||||
|
{
|
||||||
|
// Check if any comma-seperated values were passed and transform those
|
||||||
|
for (const auto &entry : subtiers)
|
||||||
|
{
|
||||||
|
for (const auto &subtier : entry.split(',', Qt::SkipEmptyParts))
|
||||||
|
{
|
||||||
|
this->subtiers_ << subtier;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SubtierPredicate::appliesTo(const Message &message)
|
||||||
|
{
|
||||||
|
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
|
38
src/messages/search/SubtierPredicate.hpp
Normal file
38
src/messages/search/SubtierPredicate.hpp
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "messages/search/MessagePredicate.hpp"
|
||||||
|
|
||||||
|
namespace chatterino {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief MessagePredicate checking for the badges of a message.
|
||||||
|
*
|
||||||
|
* This predicate will only allow messages that are sent by a subscribed user
|
||||||
|
* who has a specified subtier (i.e. 1,2,3..)
|
||||||
|
*/
|
||||||
|
class SubtierPredicate : public MessagePredicate
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Create an SubtierPredicate with a list of subtiers to search for.
|
||||||
|
*
|
||||||
|
* @param subtiers a list of subtiers that a message should contain
|
||||||
|
*/
|
||||||
|
SubtierPredicate(const QStringList &subtiers);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Checks whether the message contains any of the subtiers passed
|
||||||
|
* in the constructor.
|
||||||
|
*
|
||||||
|
* @param message the message to check
|
||||||
|
* @return true if the message contains a subtier listed in the specified subtiers,
|
||||||
|
* false otherwise
|
||||||
|
*/
|
||||||
|
bool appliesTo(const Message &message) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
/// Holds the subtiers that will be searched for
|
||||||
|
QStringList subtiers_;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace chatterino
|
|
@ -7,11 +7,13 @@
|
||||||
#include "common/Channel.hpp"
|
#include "common/Channel.hpp"
|
||||||
#include "controllers/hotkeys/HotkeyController.hpp"
|
#include "controllers/hotkeys/HotkeyController.hpp"
|
||||||
#include "messages/search/AuthorPredicate.hpp"
|
#include "messages/search/AuthorPredicate.hpp"
|
||||||
|
#include "messages/search/BadgePredicate.hpp"
|
||||||
#include "messages/search/ChannelPredicate.hpp"
|
#include "messages/search/ChannelPredicate.hpp"
|
||||||
#include "messages/search/LinkPredicate.hpp"
|
#include "messages/search/LinkPredicate.hpp"
|
||||||
#include "messages/search/MessageFlagsPredicate.hpp"
|
#include "messages/search/MessageFlagsPredicate.hpp"
|
||||||
#include "messages/search/RegexPredicate.hpp"
|
#include "messages/search/RegexPredicate.hpp"
|
||||||
#include "messages/search/SubstringPredicate.hpp"
|
#include "messages/search/SubstringPredicate.hpp"
|
||||||
|
#include "messages/search/SubtierPredicate.hpp"
|
||||||
#include "singletons/WindowManager.hpp"
|
#include "singletons/WindowManager.hpp"
|
||||||
#include "widgets/helper/ChannelView.hpp"
|
#include "widgets/helper/ChannelView.hpp"
|
||||||
|
|
||||||
|
@ -297,6 +299,8 @@ std::vector<std::unique_ptr<MessagePredicate>> SearchPopup::parsePredicates(
|
||||||
std::vector<std::unique_ptr<MessagePredicate>> predicates;
|
std::vector<std::unique_ptr<MessagePredicate>> predicates;
|
||||||
QStringList authors;
|
QStringList authors;
|
||||||
QStringList channels;
|
QStringList channels;
|
||||||
|
QStringList badges;
|
||||||
|
QStringList subtiers;
|
||||||
|
|
||||||
while (it.hasNext())
|
while (it.hasNext())
|
||||||
{
|
{
|
||||||
|
@ -312,6 +316,14 @@ std::vector<std::unique_ptr<MessagePredicate>> SearchPopup::parsePredicates(
|
||||||
{
|
{
|
||||||
authors.append(value);
|
authors.append(value);
|
||||||
}
|
}
|
||||||
|
else if (name == "badge")
|
||||||
|
{
|
||||||
|
badges.append(value);
|
||||||
|
}
|
||||||
|
else if (name == "subtier")
|
||||||
|
{
|
||||||
|
subtiers.append(value);
|
||||||
|
}
|
||||||
else if (name == "has" && value == "link")
|
else if (name == "has" && value == "link")
|
||||||
{
|
{
|
||||||
predicates.push_back(std::make_unique<LinkPredicate>());
|
predicates.push_back(std::make_unique<LinkPredicate>());
|
||||||
|
@ -337,10 +349,24 @@ std::vector<std::unique_ptr<MessagePredicate>> SearchPopup::parsePredicates(
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!authors.empty())
|
if (!authors.empty())
|
||||||
|
{
|
||||||
predicates.push_back(std::make_unique<AuthorPredicate>(authors));
|
predicates.push_back(std::make_unique<AuthorPredicate>(authors));
|
||||||
|
}
|
||||||
|
|
||||||
if (!channels.empty())
|
if (!channels.empty())
|
||||||
|
{
|
||||||
predicates.push_back(std::make_unique<ChannelPredicate>(channels));
|
predicates.push_back(std::make_unique<ChannelPredicate>(channels));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!badges.empty())
|
||||||
|
{
|
||||||
|
predicates.push_back(std::make_unique<BadgePredicate>(badges));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!subtiers.empty())
|
||||||
|
{
|
||||||
|
predicates.push_back(std::make_unique<SubtierPredicate>(subtiers));
|
||||||
|
}
|
||||||
|
|
||||||
return predicates;
|
return predicates;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue