Consider nicknames when searching for messages (#4663)

Co-authored-by: pajlada <rasmus.karlsson+github@pajlada.com>
This commit is contained in:
chrrs 2023-05-31 21:38:17 +02:00 committed by GitHub
parent e9432d3b65
commit bf4148a370
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 39 additions and 18 deletions

View file

@ -2,6 +2,7 @@
## Unversioned ## Unversioned
- Minor: Nicknames are now taken into consideration when searching for messages. (#4663)
- Minor: Add an icon showing when streamer mode is enabled (#4410) - Minor: Add an icon showing when streamer mode is enabled (#4410)
- Minor: Added `/shoutout <username>` commands to shoutout specified user. (#4638) - Minor: Added `/shoutout <username>` commands to shoutout specified user. (#4638)
- Minor: Improved editing hotkeys. (#4628) - Minor: Improved editing hotkeys. (#4628)

View file

@ -3,6 +3,7 @@
#include "util/RapidjsonHelpers.hpp" #include "util/RapidjsonHelpers.hpp"
#include "util/RapidJsonSerializeQString.hpp" #include "util/RapidJsonSerializeQString.hpp"
#include <boost/optional.hpp>
#include <pajlada/serialize.hpp> #include <pajlada/serialize.hpp>
#include <QRegularExpression> #include <QRegularExpression>
#include <QString> #include <QString>
@ -58,25 +59,25 @@ public:
return this->isCaseSensitive_; return this->isCaseSensitive_;
} }
[[nodiscard]] bool match(QString &usernameText) const [[nodiscard]] boost::optional<QString> match(
const QString &usernameText) const
{ {
if (this->isRegex()) if (this->isRegex())
{ {
if (!this->regex_.isValid()) if (!this->regex_.isValid())
{ {
return false; return boost::none;
} }
if (this->name().isEmpty()) if (this->name().isEmpty())
{ {
return false; return boost::none;
} }
auto workingCopy = usernameText; auto workingCopy = usernameText;
workingCopy.replace(this->regex_, this->replace()); workingCopy.replace(this->regex_, this->replace());
if (workingCopy != usernameText) if (workingCopy != usernameText)
{ {
usernameText = workingCopy; return workingCopy;
return true;
} }
} }
else else
@ -85,12 +86,11 @@ public:
this->name().compare(usernameText, this->caseSensitivity()); this->name().compare(usernameText, this->caseSensitivity());
if (res == 0) if (res == 0)
{ {
usernameText = this->replace(); return this->replace();
return true;
} }
} }
return false; return boost::none;
} }
private: private:

View file

@ -270,14 +270,9 @@ QString SharedMessageBuilder::stylizeUsername(const QString &username,
break; break;
} }
auto nicknames = getCSettings().nicknames.readOnly(); if (auto nicknameText = getCSettings().matchNickname(usernameText))
for (const auto &nickname : *nicknames)
{ {
if (nickname.match(usernameText)) usernameText = *nicknameText;
{
break;
}
} }
return usernameText; return usernameText;

View file

@ -64,7 +64,11 @@ MessagePtr IrcMessageBuilder::build()
// message // message
this->addIrcMessageText(this->originalMessage_); this->addIrcMessageText(this->originalMessage_);
this->message().searchText = this->message().localizedName + " " + QString stylizedUsername =
this->stylizeUsername(this->userName, this->message());
this->message().searchText = stylizedUsername + " " +
this->message().localizedName + " " +
this->userName + ": " + this->originalMessage_; this->userName + ": " + this->originalMessage_;
// highlights // highlights

View file

@ -294,8 +294,12 @@ MessagePtr TwitchMessageBuilder::build()
this->addWords(splits, twitchEmotes); this->addWords(splits, twitchEmotes);
QString stylizedUsername =
this->stylizeUsername(this->userName, this->message());
this->message().messageText = this->originalMessage_; this->message().messageText = this->originalMessage_;
this->message().searchText = this->message().localizedName + " " + this->message().searchText = stylizedUsername + " " +
this->message().localizedName + " " +
this->userName + ": " + this->originalMessage_; this->userName + ": " + this->originalMessage_;
// highlights // highlights

View file

@ -81,6 +81,22 @@ bool ConcurrentSettings::isMutedChannel(const QString &channelName)
return false; return false;
} }
boost::optional<QString> ConcurrentSettings::matchNickname(
const QString &usernameText)
{
auto nicknames = getCSettings().nicknames.readOnly();
for (const auto &nickname : *nicknames)
{
if (auto nicknameText = nickname.match(usernameText))
{
return nicknameText;
}
}
return boost::none;
}
void ConcurrentSettings::mute(const QString &channelName) void ConcurrentSettings::mute(const QString &channelName)
{ {
mutedChannels.append(channelName); mutedChannels.append(channelName);

View file

@ -47,6 +47,7 @@ public:
bool isBlacklistedUser(const QString &username); bool isBlacklistedUser(const QString &username);
bool isMutedChannel(const QString &channelName); bool isMutedChannel(const QString &channelName);
bool toggleMutedChannel(const QString &channelName); bool toggleMutedChannel(const QString &channelName);
boost::optional<QString> matchNickname(const QString &username);
private: private:
void mute(const QString &channelName); void mute(const QString &channelName);

View file

@ -18,7 +18,7 @@ NicknamesPage::NicknamesPage()
auto layout = layoutCreator.setLayoutType<QVBoxLayout>(); auto layout = layoutCreator.setLayoutType<QVBoxLayout>();
layout.emplace<QLabel>( layout.emplace<QLabel>(
"Nicknames do not work with features such as search or user highlights." "Nicknames do not work with features such as user highlights."
"\nWith those features you will still need to use the user's original " "\nWith those features you will still need to use the user's original "
"name."); "name.");
EditableModelView *view = EditableModelView *view =