mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
Consider nicknames when searching for messages (#4663)
Co-authored-by: pajlada <rasmus.karlsson+github@pajlada.com>
This commit is contained in:
parent
e9432d3b65
commit
bf4148a370
8 changed files with 39 additions and 18 deletions
|
@ -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)
|
||||||
|
|
|
@ -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:
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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);
|
||||||
|
|
|
@ -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);
|
||||||
|
|
|
@ -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 =
|
||||||
|
|
Loading…
Reference in a new issue