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 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
- Minor: Don't show update button for nightly builds on macOS and Linux, this was already the case for Windows (#2163, #2164)
- Minor: Tab and split titles now use display/localized channel names (#2189)
- Minor: Add a setting to limit the amount of historical messages loaded from the Recent Messages API (#2250, #2252)
- Minor: Color mentions to match the mentioned users (#1963, #2121, #2284)
pajlada marked this conversation as resolved.
Show resolved Hide resolved
kiwec marked this conversation as resolved.
Show resolved Hide resolved
- Bugfix: Fix crash occurring when pressing Escape in the Color Picker Dialog (#1843)
- Bugfix: Fix bug where the "check user follow state" event could trigger a network request requesting the user to follow or unfollow a user. By itself its quite harmless as it just repeats to Twitch the same follow state we had, so no follows should have been lost by this but it meant there was a rogue network request that was fired that could cause a crash (#1906)
- Bugfix: /usercard command will now respect the "Automatically close user popup" setting (#1918)
Expand Down
22 changes: 22 additions & 0 deletions src/common/ChannelChatters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,31 @@ void ChannelChatters::addPartedUser(const QString &user)
});
}
}

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())
{
return QColor(MessageColor::Text);
}
else
{
return search->second;
}
}

kiwec marked this conversation as resolved.
Show resolved Hide resolved
void ChannelChatters::setChatters(UsernameSet &&set)
{
*this->chatters_.access() = set;
}

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 @@ -17,13 +17,16 @@ class ChannelChatters
void addRecentChatter(const QString &user);
void addJoinedUser(const QString &user);
void addPartedUser(const QString &user);
const QColor getUserColor(const QString &user);
void setChatters(UsernameSet &&set);
void setUserColor(const QString &user, const QColor &color);
kiwec marked this conversation as resolved.
Show resolved Hide resolved

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
11 changes: 11 additions & 0 deletions src/providers/twitch/TwitchMessageBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,11 @@ void TwitchMessageBuilder::addTextOrEmoji(const QString &string_)
{
QString username = match.captured(1);

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

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

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

this->emplace<TextElement>(string, MessageElementFlag::BoldUsername,
textColor, FontStyle::ChatMediumBold)
->setLink({Link::UserInfo, username});
Expand Down Expand Up @@ -580,6 +590,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