Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Color mentions to match the mentioned users color #2284

Merged
merged 8 commits into from
Dec 19, 2020
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- Major: Added "Channel Filters". See https://wiki.chatterino.com/Filters/ for how they work or how to configure them. (#1748, #2083, #2090, #2200)
- Major: Added Streamer Mode configuration (under `Settings -> General`), where you can select which features of Chatterino should behave differently when you are in Streamer Mode. (#2001)
- Major: Color mentions to match the mentioned users. You can disable this by unchecking "Color usernames" under `Settings -> General -> Advanced (misc.)`. (#1963, #2284)
- Minor: Made BetterTTV emote tooltips use authors' display name. (#2267)
- Minor: Added Ctrl + 1/2/3/... and Ctrl+9 shortcuts to Emote Popup (activated with Ctrl+E). They work exactly the same as shortcuts in main window. (#2263)
- Minor: Added reconnect link to the "You are banned" message. (#2266)
Expand Down
21 changes: 21 additions & 0 deletions src/common/ChannelChatters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,30 @@ void ChannelChatters::addPartedUser(const QString &user)
});
}
}

void ChannelChatters::setChatters(UsernameSet &&set)
{
*this->chatters_.access() = set;
}

const QColor ChannelChatters::getUserColor(const QString &user)
kiwec marked this conversation as resolved.
Show resolved Hide resolved
{
const auto chatterColors = this->chatterColors_.access();

const auto search = chatterColors->find(user.toLower());
if (search == chatterColors->end())
{
// Returns an invalid color so we can decide not to override `textColor`
return QColor();
}

return search->second;
}

void ChannelChatters::setUserColor(const QString &user, const QColor &color)
{
const auto chatterColors = this->chatterColors_.access();
chatterColors->insert_or_assign(user.toLower(), color);
}

} // namespace chatterino
3 changes: 3 additions & 0 deletions src/common/ChannelChatters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@ class ChannelChatters
void addJoinedUser(const QString &user);
void addPartedUser(const QString &user);
void setChatters(UsernameSet &&set);
const QColor getUserColor(const QString &user);
void setUserColor(const QString &user, const QColor &color);

private:
Channel &channel_;

// maps 2 char prefix to set of names
UniqueAccess<UsernameSet> chatters_;
UniqueAccess<std::map<QString, QColor>> chatterColors_;

// combines multiple joins/parts into one message
UniqueAccess<QStringList> joinedUsers_;
Expand Down
21 changes: 21 additions & 0 deletions src/providers/twitch/TwitchMessageBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,16 @@ void TwitchMessageBuilder::addTextOrEmoji(const QString &string_)
{
QString username = match.captured(1);

if (getSettings()->colorUsernames)
{
if (auto userColor =
this->twitchChannel->getUserColor(username);
userColor.isValid())
{
textColor = userColor;
}
}

this->emplace<TextElement>(string, MessageElementFlag::BoldUsername,
textColor, FontStyle::ChatMediumBold)
->setLink({Link::UserInfo, username});
Expand All @@ -499,6 +509,16 @@ void TwitchMessageBuilder::addTextOrEmoji(const QString &string_)

if (match.hasMatch() && chatters->contains(username))
{
if (getSettings()->colorUsernames)
{
if (auto userColor =
this->twitchChannel->getUserColor(username);
userColor.isValid())
{
textColor = userColor;
}
}

this->emplace<TextElement>(string, MessageElementFlag::BoldUsername,
textColor, FontStyle::ChatMediumBold)
->setLink({Link::UserInfo, username});
Expand Down Expand Up @@ -580,6 +600,7 @@ void TwitchMessageBuilder::parseUsername()
// }

this->message().loginName = this->userName;
this->twitchChannel->setUserColor(this->userName, this->usernameColor_);

// Update current user color if this is our message
auto currentUser = getApp()->accounts->twitch.getCurrent();
Expand Down
1 change: 1 addition & 0 deletions src/singletons/Settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ class Settings : public ABSettings, public ConcurrentSettings
BoolSetting enableSmoothScrollingNewMessages = {
"/appearance/smoothScrollingNewMessages", false};
BoolSetting boldUsernames = {"/appearance/messages/boldUsernames", true};
BoolSetting colorUsernames = {"/appearance/messages/colorUsernames", true};
BoolSetting findAllUsernames = {"/appearance/messages/findAllUsernames",
false};
// BoolSetting customizable splitheader
Expand Down
1 change: 1 addition & 0 deletions src/widgets/settingspages/GeneralPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,7 @@ void GeneralPage::initLayout(GeneralPageView &layout)
s.autoCloseUserPopup);
layout.addCheckbox("Lowercase domains (anti-phishing)", s.lowercaseDomains);
layout.addCheckbox("Bold @usernames", s.boldUsernames);
layout.addCheckbox("Color @usernames", s.colorUsernames);
layout.addCheckbox("Try to find usernames without @ prefix",
s.findAllUsernames);
layout.addDropdown<float>(
Expand Down