mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
Added in:<channels> search predicate (#2634)
Co-authored-by: pajlada <rasmus.karlsson@pajlada.com>
This commit is contained in:
parent
b540bd0b69
commit
cceadf473a
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
## Unversioned
|
## Unversioned
|
||||||
|
|
||||||
|
- Minor: Added `in:<channels>` search filter to find messages sent in specific channels. (#2299, #2634)
|
||||||
- Minor: Allow for built-in Chatterino commands to be used in custom commands. (#2632)
|
- Minor: Allow for built-in Chatterino commands to be used in custom commands. (#2632)
|
||||||
- Bugfix: Fix crash that could occur when the user changed the "Custom stream player URI Scheme" setting if the user had closed down and splits in the application runtime. (#2592)
|
- Bugfix: Fix crash that could occur when the user changed the "Custom stream player URI Scheme" setting if the user had closed down and splits in the application runtime. (#2592)
|
||||||
|
|
||||||
|
|
|
@ -179,6 +179,7 @@ SOURCES += \
|
||||||
src/messages/MessageContainer.cpp \
|
src/messages/MessageContainer.cpp \
|
||||||
src/messages/MessageElement.cpp \
|
src/messages/MessageElement.cpp \
|
||||||
src/messages/search/AuthorPredicate.cpp \
|
src/messages/search/AuthorPredicate.cpp \
|
||||||
|
src/messages/search/ChannelPredicate.cpp \
|
||||||
src/messages/search/LinkPredicate.cpp \
|
src/messages/search/LinkPredicate.cpp \
|
||||||
src/messages/search/SubstringPredicate.cpp \
|
src/messages/search/SubstringPredicate.cpp \
|
||||||
src/messages/SharedMessageBuilder.cpp \
|
src/messages/SharedMessageBuilder.cpp \
|
||||||
|
@ -406,6 +407,7 @@ HEADERS += \
|
||||||
src/messages/MessageElement.hpp \
|
src/messages/MessageElement.hpp \
|
||||||
src/messages/MessageParseArgs.hpp \
|
src/messages/MessageParseArgs.hpp \
|
||||||
src/messages/search/AuthorPredicate.hpp \
|
src/messages/search/AuthorPredicate.hpp \
|
||||||
|
src/messages/search/ChannelPredicate.hpp \
|
||||||
src/messages/search/LinkPredicate.hpp \
|
src/messages/search/LinkPredicate.hpp \
|
||||||
src/messages/search/MessagePredicate.hpp \
|
src/messages/search/MessagePredicate.hpp \
|
||||||
src/messages/search/SubstringPredicate.hpp \
|
src/messages/search/SubstringPredicate.hpp \
|
||||||
|
|
|
@ -133,6 +133,8 @@ set(SOURCE_FILES main.cpp
|
||||||
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/ChannelPredicate.cpp
|
||||||
|
messages/search/ChannelPredicate.hpp
|
||||||
messages/search/LinkPredicate.cpp
|
messages/search/LinkPredicate.cpp
|
||||||
messages/search/LinkPredicate.hpp
|
messages/search/LinkPredicate.hpp
|
||||||
messages/search/SubstringPredicate.cpp
|
messages/search/SubstringPredicate.cpp
|
||||||
|
|
23
src/messages/search/ChannelPredicate.cpp
Normal file
23
src/messages/search/ChannelPredicate.cpp
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
#include "messages/search/ChannelPredicate.hpp"
|
||||||
|
|
||||||
|
namespace chatterino {
|
||||||
|
|
||||||
|
ChannelPredicate::ChannelPredicate(const QStringList &channels)
|
||||||
|
: channels_()
|
||||||
|
{
|
||||||
|
// Check if any comma-seperated values were passed and transform those
|
||||||
|
for (const auto &entry : channels)
|
||||||
|
{
|
||||||
|
for (const auto &channel : entry.split(',', QString::SkipEmptyParts))
|
||||||
|
{
|
||||||
|
this->channels_ << channel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ChannelPredicate::appliesTo(const Message &message)
|
||||||
|
{
|
||||||
|
return channels_.contains(message.channelName, Qt::CaseInsensitive);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace chatterino
|
38
src/messages/search/ChannelPredicate.hpp
Normal file
38
src/messages/search/ChannelPredicate.hpp
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "messages/search/MessagePredicate.hpp"
|
||||||
|
|
||||||
|
namespace chatterino {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief MessagePredicate checking for the channel a message was sent in.
|
||||||
|
*
|
||||||
|
* This predicate will only allow messages that are sent in a list of channels,
|
||||||
|
* specified by their names.
|
||||||
|
*/
|
||||||
|
class ChannelPredicate : public MessagePredicate
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Create a ChannelPredicate with a list of channels to search for.
|
||||||
|
*
|
||||||
|
* @param channels a list of channel names that a message should be sent in
|
||||||
|
*/
|
||||||
|
ChannelPredicate(const QStringList &channels);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Checks whether the message was sent in any of the channels passed
|
||||||
|
* in the constructor.
|
||||||
|
*
|
||||||
|
* @param message the message to check
|
||||||
|
* @return true if the message was sent in one of the specified channels,
|
||||||
|
* false otherwise
|
||||||
|
*/
|
||||||
|
bool appliesTo(const Message &message);
|
||||||
|
|
||||||
|
private:
|
||||||
|
/// Holds the channel names that will be searched for
|
||||||
|
QStringList channels_;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace chatterino
|
|
@ -8,6 +8,7 @@
|
||||||
#include "common/Channel.hpp"
|
#include "common/Channel.hpp"
|
||||||
#include "messages/Message.hpp"
|
#include "messages/Message.hpp"
|
||||||
#include "messages/search/AuthorPredicate.hpp"
|
#include "messages/search/AuthorPredicate.hpp"
|
||||||
|
#include "messages/search/ChannelPredicate.hpp"
|
||||||
#include "messages/search/LinkPredicate.hpp"
|
#include "messages/search/LinkPredicate.hpp"
|
||||||
#include "messages/search/SubstringPredicate.hpp"
|
#include "messages/search/SubstringPredicate.hpp"
|
||||||
#include "util/Shortcut.hpp"
|
#include "util/Shortcut.hpp"
|
||||||
|
@ -164,9 +165,10 @@ std::vector<std::unique_ptr<MessagePredicate>> SearchPopup::parsePredicates(
|
||||||
{
|
{
|
||||||
static QRegularExpression predicateRegex(R"(^(\w+):([\w,]+)$)");
|
static QRegularExpression predicateRegex(R"(^(\w+):([\w,]+)$)");
|
||||||
|
|
||||||
auto predicates = std::vector<std::unique_ptr<MessagePredicate>>();
|
std::vector<std::unique_ptr<MessagePredicate>> predicates;
|
||||||
auto words = input.split(' ', QString::SkipEmptyParts);
|
auto words = input.split(' ', QString::SkipEmptyParts);
|
||||||
auto authors = QStringList();
|
QStringList authors;
|
||||||
|
QStringList channels;
|
||||||
|
|
||||||
for (auto it = words.begin(); it != words.end();)
|
for (auto it = words.begin(); it != words.end();)
|
||||||
{
|
{
|
||||||
|
@ -186,6 +188,10 @@ std::vector<std::unique_ptr<MessagePredicate>> SearchPopup::parsePredicates(
|
||||||
{
|
{
|
||||||
predicates.push_back(std::make_unique<LinkPredicate>());
|
predicates.push_back(std::make_unique<LinkPredicate>());
|
||||||
}
|
}
|
||||||
|
else if (name == "in")
|
||||||
|
{
|
||||||
|
channels.append(value);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
remove = false;
|
remove = false;
|
||||||
|
@ -203,6 +209,9 @@ 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())
|
||||||
|
predicates.push_back(std::make_unique<ChannelPredicate>(channels));
|
||||||
|
|
||||||
if (!words.empty())
|
if (!words.empty())
|
||||||
predicates.push_back(
|
predicates.push_back(
|
||||||
std::make_unique<SubstringPredicate>(words.join(" ")));
|
std::make_unique<SubstringPredicate>(words.join(" ")));
|
||||||
|
|
Loading…
Reference in a new issue