Added is:<flags> search predicate (#2671)
Co-authored-by: Paweł <zneix@zneix.eu> Co-authored-by: pajlada <rasmus.karlsson@pajlada.com>
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
#include "messages/search/MessageFlagsPredicate.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
MessageFlagsPredicate::MessageFlagsPredicate(const QString &flags)
|
||||
: flags_()
|
||||
{
|
||||
// Check if any comma-seperated values were passed and transform those
|
||||
for (const auto &flag : flags.split(',', QString::SkipEmptyParts))
|
||||
{
|
||||
if (flag == "deleted" || flag == "disabled")
|
||||
{
|
||||
this->flags_.set(MessageFlag::Disabled);
|
||||
}
|
||||
else if (flag == "sub" || flag == "subscription")
|
||||
{
|
||||
this->flags_.set(MessageFlag::Subscription);
|
||||
}
|
||||
else if (flag == "timeout" || flag == "ban")
|
||||
{
|
||||
this->flags_.set(MessageFlag::Timeout);
|
||||
}
|
||||
else if (flag == "highlighted")
|
||||
{
|
||||
this->flags_.set(MessageFlag::Highlighted);
|
||||
}
|
||||
else if (flag == "system")
|
||||
{
|
||||
this->flags_.set(MessageFlag::System);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool MessageFlagsPredicate::appliesTo(const Message &message)
|
||||
{
|
||||
// Exclude timeout messages from system flag when timeout flag isn't present
|
||||
if (this->flags_.has(MessageFlag::System) &&
|
||||
!this->flags_.has(MessageFlag::Timeout))
|
||||
return message.flags.hasAny(flags_) &&
|
||||
!message.flags.has(MessageFlag::Timeout);
|
||||
return message.flags.hasAny(flags_);
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
||||
@@ -0,0 +1,48 @@
|
||||
#pragma once
|
||||
|
||||
#include "common/FlagsEnum.hpp"
|
||||
#include "messages/search/MessagePredicate.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
using MessageFlags = FlagsEnum<MessageFlag>;
|
||||
|
||||
/**
|
||||
* @brief MessagePredicate checking for message flags.
|
||||
*
|
||||
* This predicate will only allow messages with a list of flags.
|
||||
* Specified by user-friendly names for the flags.
|
||||
*/
|
||||
class MessageFlagsPredicate : public MessagePredicate
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Create a MessageFlagsPredicate with a list of flags to search for.
|
||||
*
|
||||
* The flags can be specified by user-friendly names.
|
||||
* "deleted" and "disabled" are used for the "Disabled" flag.
|
||||
* "sub" and "subscription" are used for the "Subscription" flag.
|
||||
* "timeout" is used for the "Timeout" flag.
|
||||
* "highlighted" is used for the "Highlighted" flag.
|
||||
* "system" is used for the "System" flag.
|
||||
*
|
||||
* @param flags a string comma seperated list of names for the flags a message should have
|
||||
*/
|
||||
MessageFlagsPredicate(const QString &flags);
|
||||
|
||||
/**
|
||||
* @brief Checks whether the message has any of the flags passed
|
||||
* in the constructor.
|
||||
*
|
||||
* @param message the message to check
|
||||
* @return true if the message has at least one of the specified flags,
|
||||
* false otherwise
|
||||
*/
|
||||
bool appliesTo(const Message &message);
|
||||
|
||||
private:
|
||||
/// Holds the flags that will be searched for
|
||||
MessageFlags flags_;
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
||||
Reference in New Issue
Block a user