fix: update color of usernames & boldness of usernames on the fly (#5300)

This commit is contained in:
pajlada
2024-05-12 14:37:47 +02:00
committed by GitHub
parent febcf464fe
commit 3d5acff907
7 changed files with 120 additions and 96 deletions
+38 -82
View File
@@ -51,6 +51,8 @@ using namespace chatterino::literals;
namespace {
const QColor AUTOMOD_USER_COLOR{"blue"};
using namespace std::chrono_literals;
const QString regexHelpString("(\\w+)[.,!?;:]*?$");
@@ -756,7 +758,7 @@ void TwitchMessageBuilder::addTextOrEmoji(const QString &string_)
QString username = match.captured(1);
auto originalTextColor = textColor;
if (this->twitchChannel != nullptr && getSettings()->colorUsernames)
if (this->twitchChannel != nullptr)
{
if (auto userColor =
this->twitchChannel->getUserColor(username);
@@ -767,21 +769,17 @@ void TwitchMessageBuilder::addTextOrEmoji(const QString &string_)
}
auto prefixedUsername = '@' + username;
this->emplace<TextElement>(prefixedUsername,
MessageElementFlag::BoldUsername,
textColor, FontStyle::ChatMediumBold)
auto remainder = string.remove(prefixedUsername);
this->emplace<MentionElement>(prefixedUsername, originalTextColor,
textColor)
->setLink({Link::UserInfo, username})
->setTrailingSpace(false);
->setTrailingSpace(remainder.isEmpty());
this->emplace<TextElement>(prefixedUsername,
MessageElementFlag::NonBoldUsername,
textColor)
->setLink({Link::UserInfo, username})
->setTrailingSpace(false);
this->emplace<TextElement>(string.remove(prefixedUsername),
MessageElementFlag::Text,
originalTextColor);
if (!remainder.isEmpty())
{
this->emplace<TextElement>(remainder, MessageElementFlag::Text,
originalTextColor);
}
return;
}
@@ -797,30 +795,23 @@ void TwitchMessageBuilder::addTextOrEmoji(const QString &string_)
{
auto originalTextColor = textColor;
if (getSettings()->colorUsernames)
if (auto userColor = this->twitchChannel->getUserColor(username);
userColor.isValid())
{
if (auto userColor =
this->twitchChannel->getUserColor(username);
userColor.isValid())
{
textColor = userColor;
}
textColor = userColor;
}
this->emplace<TextElement>(username,
MessageElementFlag::BoldUsername,
textColor, FontStyle::ChatMediumBold)
auto remainder = string.remove(username);
this->emplace<MentionElement>(username, originalTextColor,
textColor)
->setLink({Link::UserInfo, username})
->setTrailingSpace(false);
->setTrailingSpace(remainder.isEmpty());
this->emplace<TextElement>(
username, MessageElementFlag::NonBoldUsername, textColor)
->setLink({Link::UserInfo, username})
->setTrailingSpace(false);
this->emplace<TextElement>(string.remove(username),
MessageElementFlag::Text,
originalTextColor);
if (!remainder.isEmpty())
{
this->emplace<TextElement>(remainder, MessageElementFlag::Text,
originalTextColor);
}
return;
}
@@ -1821,7 +1812,7 @@ void TwitchMessageBuilder::listOfUsersSystemMessage(QString prefix,
MessageColor color = MessageColor::System;
if (tc && getSettings()->colorUsernames)
if (tc)
{
if (auto userColor = tc->getUserColor(username);
userColor.isValid())
@@ -1830,14 +1821,7 @@ void TwitchMessageBuilder::listOfUsersSystemMessage(QString prefix,
}
}
builder
->emplace<TextElement>(username, MessageElementFlag::BoldUsername,
color, FontStyle::ChatMediumBold)
->setLink({Link::UserInfo, username})
->setTrailingSpace(false);
builder
->emplace<TextElement>(username,
MessageElementFlag::NonBoldUsername, color)
builder->emplace<MentionElement>(username, MessageColor::System, color)
->setLink({Link::UserInfo, username})
->setTrailingSpace(false);
}
@@ -1873,7 +1857,7 @@ void TwitchMessageBuilder::listOfUsersSystemMessage(
MessageColor color = MessageColor::System;
if (tc && getSettings()->colorUsernames)
if (tc)
{
if (auto userColor = tc->getUserColor(user.userLogin);
userColor.isValid())
@@ -1883,14 +1867,8 @@ void TwitchMessageBuilder::listOfUsersSystemMessage(
}
builder
->emplace<TextElement>(user.userName,
MessageElementFlag::BoldUsername, color,
FontStyle::ChatMediumBold)
->setLink({Link::UserInfo, user.userLogin})
->setTrailingSpace(false);
builder
->emplace<TextElement>(user.userName,
MessageElementFlag::NonBoldUsername, color)
->emplace<MentionElement>(user.userName, MessageColor::System,
color)
->setLink({Link::UserInfo, user.userLogin})
->setTrailingSpace(false);
}
@@ -1960,12 +1938,8 @@ MessagePtr TwitchMessageBuilder::makeAutomodInfoMessage(
builder.emplace<BadgeElement>(makeAutoModBadge(),
MessageElementFlag::BadgeChannelAuthority);
// AutoMod "username"
builder.emplace<TextElement>("AutoMod:", MessageElementFlag::BoldUsername,
MessageColor(QColor("blue")),
FontStyle::ChatMediumBold);
builder.emplace<TextElement>(
"AutoMod:", MessageElementFlag::NonBoldUsername,
MessageColor(QColor("blue")));
builder.emplace<MentionElement>("AutoMod:", AUTOMOD_USER_COLOR,
AUTOMOD_USER_COLOR);
switch (action.type)
{
case AutomodInfoAction::OnHold: {
@@ -2019,12 +1993,8 @@ std::pair<MessagePtr, MessagePtr> TwitchMessageBuilder::makeAutomodMessage(
builder.emplace<BadgeElement>(makeAutoModBadge(),
MessageElementFlag::BadgeChannelAuthority);
// AutoMod "username"
builder.emplace<TextElement>("AutoMod:", MessageElementFlag::BoldUsername,
MessageColor(QColor("blue")),
FontStyle::ChatMediumBold);
builder.emplace<TextElement>(
"AutoMod:", MessageElementFlag::NonBoldUsername,
MessageColor(QColor("blue")));
builder2.emplace<MentionElement>("AutoMod:", AUTOMOD_USER_COLOR,
AUTOMOD_USER_COLOR);
// AutoMod header message
builder.emplace<TextElement>(
("Held a message for reason: " + action.reason +
@@ -2072,14 +2042,8 @@ std::pair<MessagePtr, MessagePtr> TwitchMessageBuilder::makeAutomodMessage(
// sender username
builder2
.emplace<TextElement>(
action.target.displayName + ":", MessageElementFlag::BoldUsername,
MessageColor(action.target.color), FontStyle::ChatMediumBold)
->setLink({Link::UserInfo, action.target.login});
builder2
.emplace<TextElement>(action.target.displayName + ":",
MessageElementFlag::NonBoldUsername,
MessageColor(action.target.color))
.emplace<MentionElement>(action.target.displayName + ":",
MessageColor::Text, action.target.color)
->setLink({Link::UserInfo, action.target.login});
// sender's message caught by AutoMod
builder2.emplace<TextElement>(action.message, MessageElementFlag::Text,
@@ -2275,17 +2239,9 @@ std::pair<MessagePtr, MessagePtr> TwitchMessageBuilder::makeLowTrustUserMessage(
appendBadges(&builder2, action.senderBadges, {}, twitchChannel);
// sender username
builder2
.emplace<TextElement>(action.suspiciousUserDisplayName + ":",
MessageElementFlag::BoldUsername,
MessageColor(action.suspiciousUserColor),
FontStyle::ChatMediumBold)
->setLink({Link::UserInfo, action.suspiciousUserLogin});
builder2
.emplace<TextElement>(action.suspiciousUserDisplayName + ":",
MessageElementFlag::NonBoldUsername,
MessageColor(action.suspiciousUserColor))
->setLink({Link::UserInfo, action.suspiciousUserLogin});
builder2.emplace<MentionElement>(action.suspiciousUserDisplayName + ":",
MessageColor::Text,
action.suspiciousUserColor);
// sender's message caught by AutoMod
for (const auto &fragment : action.fragments)