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

View file

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

View file

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

View file

@ -64,7 +64,11 @@ MessagePtr IrcMessageBuilder::build()
// message
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_;
// highlights

View file

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

View file

@ -81,6 +81,22 @@ bool ConcurrentSettings::isMutedChannel(const QString &channelName)
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)
{
mutedChannels.append(channelName);

View file

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

View file

@ -18,7 +18,7 @@ NicknamesPage::NicknamesPage()
auto layout = layoutCreator.setLayoutType<QVBoxLayout>();
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 "
"name.");
EditableModelView *view =