Add support for Nicknames on IRC (#4170)

Co-authored-by: pajlada <rasmus.karlsson@pajlada.com>
This commit is contained in:
Mm2PL 2022-11-20 17:28:29 +01:00 committed by GitHub
parent ba4422b082
commit 01de4d4b5d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 66 additions and 60 deletions

View file

@ -86,6 +86,7 @@
- Minor: Add support for `echo-message` capabilities for IRC. (#4157) - Minor: Add support for `echo-message` capabilities for IRC. (#4157)
- Minor: Add proper support for IRC private messages. (#4158) - Minor: Add proper support for IRC private messages. (#4158)
- Minor: Improved look of tabs when using a layout other than top. (#3925, #4152) - Minor: Improved look of tabs when using a layout other than top. (#3925, #4152)
- Minor: Added support for Nicknames on IRC. (#4170)
- Bugfix: Fixed channels with two leading `#`s not being usable on IRC (#4154) - Bugfix: Fixed channels with two leading `#`s not being usable on IRC (#4154)
- Bugfix: Fixed `Add new account` dialog causing main chatterino window to be non movable. (#4121) - Bugfix: Fixed `Add new account` dialog causing main chatterino window to be non movable. (#4121)
- Bugfix: Connection to Twitch PubSub now recovers more reliably. (#3643, #3716) - Bugfix: Connection to Twitch PubSub now recovers more reliably. (#3643, #3716)

View file

@ -246,4 +246,60 @@ void SharedMessageBuilder::triggerHighlights()
} }
} }
QString SharedMessageBuilder::stylizeUsername(const QString &username,
const Message &message)
{
auto app = getApp();
const QString &localizedName = message.localizedName;
bool hasLocalizedName = !localizedName.isEmpty();
// The full string that will be rendered in the chat widget
QString usernameText;
switch (getSettings()->usernameDisplayMode.getValue())
{
case UsernameDisplayMode::Username: {
usernameText = username;
}
break;
case UsernameDisplayMode::LocalizedName: {
if (hasLocalizedName)
{
usernameText = localizedName;
}
else
{
usernameText = username;
}
}
break;
default:
case UsernameDisplayMode::UsernameAndLocalizedName: {
if (hasLocalizedName)
{
usernameText = username + "(" + localizedName + ")";
}
else
{
usernameText = username;
}
}
break;
}
auto nicknames = getCSettings().nicknames.readOnly();
for (const auto &nickname : *nicknames)
{
if (nickname.match(usernameText))
{
break;
}
}
return usernameText;
}
} // namespace chatterino } // namespace chatterino

View file

@ -38,6 +38,9 @@ public:
// Parses "badges" tag which contains a comma separated list of key-value elements // Parses "badges" tag which contains a comma separated list of key-value elements
static std::vector<Badge> parseBadgeTag(const QVariantMap &tags); static std::vector<Badge> parseBadgeTag(const QVariantMap &tags);
static QString stylizeUsername(const QString &username,
const Message &message);
protected: protected:
virtual void parse(); virtual void parse();

View file

@ -90,7 +90,8 @@ void IrcMessageBuilder::appendUsername()
this->message().displayName = username; this->message().displayName = username;
// The full string that will be rendered in the chat widget // The full string that will be rendered in the chat widget
QString usernameText = username; QString usernameText =
SharedMessageBuilder::stylizeUsername(username, this->message());
if (this->args.isReceivedWhisper) if (this->args.isReceivedWhisper)
{ {

View file

@ -52,62 +52,6 @@ namespace chatterino {
namespace { namespace {
QString stylizeUsername(const QString &username, const Message &message)
{
auto app = getApp();
const QString &localizedName = message.localizedName;
bool hasLocalizedName = !localizedName.isEmpty();
// The full string that will be rendered in the chat widget
QString usernameText;
switch (getSettings()->usernameDisplayMode.getValue())
{
case UsernameDisplayMode::Username: {
usernameText = username;
}
break;
case UsernameDisplayMode::LocalizedName: {
if (hasLocalizedName)
{
usernameText = localizedName;
}
else
{
usernameText = username;
}
}
break;
default:
case UsernameDisplayMode::UsernameAndLocalizedName: {
if (hasLocalizedName)
{
usernameText = username + "(" + localizedName + ")";
}
else
{
usernameText = username;
}
}
break;
}
auto nicknames = getCSettings().nicknames.readOnly();
for (const auto &nickname : *nicknames)
{
if (nickname.match(usernameText))
{
break;
}
}
return usernameText;
}
void appendTwitchEmoteOccurrences(const QString &emote, void appendTwitchEmoteOccurrences(const QString &emote,
std::vector<TwitchEmoteOccurrence> &vec, std::vector<TwitchEmoteOccurrence> &vec,
const std::vector<int> &correctPositions, const std::vector<int> &correctPositions,
@ -293,8 +237,8 @@ MessagePtr TwitchMessageBuilder::build()
const auto &threadRoot = this->thread_->root(); const auto &threadRoot = this->thread_->root();
QString usernameText = QString usernameText = SharedMessageBuilder::stylizeUsername(
stylizeUsername(threadRoot->loginName, *threadRoot.get()); threadRoot->loginName, *threadRoot.get());
this->emplace<ReplyCurveElement>(); this->emplace<ReplyCurveElement>();
@ -783,7 +727,8 @@ void TwitchMessageBuilder::appendUsername()
} }
} }
QString usernameText = stylizeUsername(username, this->message()); QString usernameText =
SharedMessageBuilder::stylizeUsername(username, this->message());
if (this->args.isSentWhisper) if (this->args.isSentWhisper)
{ {