From 35db3a404be9bdf81a3749c346e603d841a0f697 Mon Sep 17 00:00:00 2001 From: Wolf Clement Date: Tue, 15 Dec 2020 22:32:52 +0100 Subject: [PATCH 1/7] Color mentions (#1963) --- CHANGELOG.md | 1 + src/common/ChannelChatters.cpp | 22 +++++++++++++++++++ src/common/ChannelChatters.hpp | 3 +++ src/providers/twitch/TwitchMessageBuilder.cpp | 12 ++++++---- 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 13cc1e73b27..62de85ac961 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) - 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) diff --git a/src/common/ChannelChatters.cpp b/src/common/ChannelChatters.cpp index ea50bee5856..857798e9d39 100644 --- a/src/common/ChannelChatters.cpp +++ b/src/common/ChannelChatters.cpp @@ -64,9 +64,31 @@ void ChannelChatters::addPartedUser(const QString &user) }); } } + +const QColor ChannelChatters::getUserColor(const QString &user) +{ + auto chatterColors = this->chatterColors_.access(); + + auto search = chatterColors->find(user.toLower()); + if (search == chatterColors->end()) + { + return QColor(MessageColor::Text); + } + else + { + return search->second; + } +} + void ChannelChatters::setChatters(UsernameSet &&set) { *this->chatters_.access() = set; } +void ChannelChatters::setUserColor(const QString &user, const QColor color) +{ + auto chatterColors = this->chatterColors_.access(); + chatterColors->emplace(user.toLower(), color); +} + } // namespace chatterino diff --git a/src/common/ChannelChatters.hpp b/src/common/ChannelChatters.hpp index 2aba51da821..d3a801c03c2 100644 --- a/src/common/ChannelChatters.hpp +++ b/src/common/ChannelChatters.hpp @@ -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); private: Channel &channel_; // maps 2 char prefix to set of names UniqueAccess chatters_; + UniqueAccess> chatterColors_; // combines multiple joins/parts into one message UniqueAccess joinedUsers_; diff --git a/src/providers/twitch/TwitchMessageBuilder.cpp b/src/providers/twitch/TwitchMessageBuilder.cpp index 000243f35fb..1070b87c089 100644 --- a/src/providers/twitch/TwitchMessageBuilder.cpp +++ b/src/providers/twitch/TwitchMessageBuilder.cpp @@ -479,13 +479,14 @@ void TwitchMessageBuilder::addTextOrEmoji(const QString &string_) if (match.hasMatch()) { QString username = match.captured(1); + auto userColor = this->twitchChannel->getUserColor(username); this->emplace(string, MessageElementFlag::BoldUsername, - textColor, FontStyle::ChatMediumBold) + userColor, FontStyle::ChatMediumBold) ->setLink({Link::UserInfo, username}); this->emplace( - string, MessageElementFlag::NonBoldUsername, textColor) + string, MessageElementFlag::NonBoldUsername, userColor) ->setLink({Link::UserInfo, username}); return; } @@ -499,12 +500,14 @@ void TwitchMessageBuilder::addTextOrEmoji(const QString &string_) if (match.hasMatch() && chatters->contains(username)) { + auto userColor = this->twitchChannel->getUserColor(username); + this->emplace(string, MessageElementFlag::BoldUsername, - textColor, FontStyle::ChatMediumBold) + userColor, FontStyle::ChatMediumBold) ->setLink({Link::UserInfo, username}); this->emplace( - string, MessageElementFlag::NonBoldUsername, textColor) + string, MessageElementFlag::NonBoldUsername, userColor) ->setLink({Link::UserInfo, username}); return; } @@ -580,6 +583,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(); From 3aedb0ff69f5d2bd63e68b0d813327c7b6ba8dd2 Mon Sep 17 00:00:00 2001 From: Wolf Clement Date: Fri, 18 Dec 2020 14:29:11 +0100 Subject: [PATCH 2/7] Add a setting for coloring mentions --- CHANGELOG.md | 2 +- src/common/ChannelChatters.cpp | 10 +++++----- src/common/ChannelChatters.hpp | 2 +- src/providers/twitch/TwitchMessageBuilder.cpp | 19 +++++++++++++------ src/singletons/Settings.hpp | 1 + src/widgets/settingspages/GeneralPage.cpp | 1 + 6 files changed, 22 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 62de85ac961..d17a42a121c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,7 +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) +- Minor: Color mentions to match the mentioned users (#1963, #2121, #2284) - 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) diff --git a/src/common/ChannelChatters.cpp b/src/common/ChannelChatters.cpp index 857798e9d39..b8b3faa69af 100644 --- a/src/common/ChannelChatters.cpp +++ b/src/common/ChannelChatters.cpp @@ -67,9 +67,9 @@ void ChannelChatters::addPartedUser(const QString &user) const QColor ChannelChatters::getUserColor(const QString &user) { - auto chatterColors = this->chatterColors_.access(); + const auto chatterColors = this->chatterColors_.access(); - auto search = chatterColors->find(user.toLower()); + const auto search = chatterColors->find(user.toLower()); if (search == chatterColors->end()) { return QColor(MessageColor::Text); @@ -85,10 +85,10 @@ void ChannelChatters::setChatters(UsernameSet &&set) *this->chatters_.access() = set; } -void ChannelChatters::setUserColor(const QString &user, const QColor color) +void ChannelChatters::setUserColor(const QString &user, const QColor &color) { - auto chatterColors = this->chatterColors_.access(); - chatterColors->emplace(user.toLower(), color); + const auto chatterColors = this->chatterColors_.access(); + chatterColors->insert_or_assign(user.toLower(), color); } } // namespace chatterino diff --git a/src/common/ChannelChatters.hpp b/src/common/ChannelChatters.hpp index d3a801c03c2..3db77451bba 100644 --- a/src/common/ChannelChatters.hpp +++ b/src/common/ChannelChatters.hpp @@ -19,7 +19,7 @@ class ChannelChatters void addPartedUser(const QString &user); const QColor getUserColor(const QString &user); void setChatters(UsernameSet &&set); - void setUserColor(const QString &user, const QColor color); + void setUserColor(const QString &user, const QColor &color); private: Channel &channel_; diff --git a/src/providers/twitch/TwitchMessageBuilder.cpp b/src/providers/twitch/TwitchMessageBuilder.cpp index 1070b87c089..819b1c91ede 100644 --- a/src/providers/twitch/TwitchMessageBuilder.cpp +++ b/src/providers/twitch/TwitchMessageBuilder.cpp @@ -479,14 +479,18 @@ void TwitchMessageBuilder::addTextOrEmoji(const QString &string_) if (match.hasMatch()) { QString username = match.captured(1); - auto userColor = this->twitchChannel->getUserColor(username); + + if (getSettings()->colorUsernames) + { + textColor = this->twitchChannel->getUserColor(username); + } this->emplace(string, MessageElementFlag::BoldUsername, - userColor, FontStyle::ChatMediumBold) + textColor, FontStyle::ChatMediumBold) ->setLink({Link::UserInfo, username}); this->emplace( - string, MessageElementFlag::NonBoldUsername, userColor) + string, MessageElementFlag::NonBoldUsername, textColor) ->setLink({Link::UserInfo, username}); return; } @@ -500,14 +504,17 @@ void TwitchMessageBuilder::addTextOrEmoji(const QString &string_) if (match.hasMatch() && chatters->contains(username)) { - auto userColor = this->twitchChannel->getUserColor(username); + if (getSettings()->colorUsernames) + { + textColor = this->twitchChannel->getUserColor(username); + } this->emplace(string, MessageElementFlag::BoldUsername, - userColor, FontStyle::ChatMediumBold) + textColor, FontStyle::ChatMediumBold) ->setLink({Link::UserInfo, username}); this->emplace( - string, MessageElementFlag::NonBoldUsername, userColor) + string, MessageElementFlag::NonBoldUsername, textColor) ->setLink({Link::UserInfo, username}); return; } diff --git a/src/singletons/Settings.hpp b/src/singletons/Settings.hpp index 86527fd5e8d..72214a1c313 100644 --- a/src/singletons/Settings.hpp +++ b/src/singletons/Settings.hpp @@ -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 diff --git a/src/widgets/settingspages/GeneralPage.cpp b/src/widgets/settingspages/GeneralPage.cpp index f80830fbf92..c1fb0bf2bc1 100644 --- a/src/widgets/settingspages/GeneralPage.cpp +++ b/src/widgets/settingspages/GeneralPage.cpp @@ -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( From 4faf736d1e2a9bac3c6d8bf4efb16ba597687a23 Mon Sep 17 00:00:00 2001 From: Wolf Clement Date: Sat, 19 Dec 2020 13:41:07 +0100 Subject: [PATCH 3/7] Update changelog --- CHANGELOG.md | 2 +- src/common/ChannelChatters.cpp | 10 +++++----- src/common/ChannelChatters.hpp | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d17a42a121c..53cad14dfc1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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, #2121, #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) @@ -40,7 +41,6 @@ - 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) - 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) diff --git a/src/common/ChannelChatters.cpp b/src/common/ChannelChatters.cpp index b8b3faa69af..717ddbf07dc 100644 --- a/src/common/ChannelChatters.cpp +++ b/src/common/ChannelChatters.cpp @@ -65,6 +65,11 @@ void ChannelChatters::addPartedUser(const QString &user) } } +void ChannelChatters::setChatters(UsernameSet &&set) +{ + *this->chatters_.access() = set; +} + const QColor ChannelChatters::getUserColor(const QString &user) { const auto chatterColors = this->chatterColors_.access(); @@ -80,11 +85,6 @@ const QColor ChannelChatters::getUserColor(const QString &user) } } -void ChannelChatters::setChatters(UsernameSet &&set) -{ - *this->chatters_.access() = set; -} - void ChannelChatters::setUserColor(const QString &user, const QColor &color) { const auto chatterColors = this->chatterColors_.access(); diff --git a/src/common/ChannelChatters.hpp b/src/common/ChannelChatters.hpp index 3db77451bba..a65dfe0d695 100644 --- a/src/common/ChannelChatters.hpp +++ b/src/common/ChannelChatters.hpp @@ -17,8 +17,8 @@ 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); + const QColor getUserColor(const QString &user); void setUserColor(const QString &user, const QColor &color); private: From 5fe7314677a5c5f1d11b8aaa226e1eebc3b9153f Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Sat, 19 Dec 2020 14:07:25 +0100 Subject: [PATCH 4/7] Return an invalid color if a chatters color cannot be found --- src/common/ChannelChatters.cpp | 3 ++- src/providers/twitch/TwitchMessageBuilder.cpp | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/common/ChannelChatters.cpp b/src/common/ChannelChatters.cpp index 717ddbf07dc..dd8ee580dec 100644 --- a/src/common/ChannelChatters.cpp +++ b/src/common/ChannelChatters.cpp @@ -77,7 +77,8 @@ const QColor ChannelChatters::getUserColor(const QString &user) const auto search = chatterColors->find(user.toLower()); if (search == chatterColors->end()) { - return QColor(MessageColor::Text); + // Returns an invalid color so we can decide not to override `textColor` + return QColor(); } else { diff --git a/src/providers/twitch/TwitchMessageBuilder.cpp b/src/providers/twitch/TwitchMessageBuilder.cpp index 819b1c91ede..5629ffcafea 100644 --- a/src/providers/twitch/TwitchMessageBuilder.cpp +++ b/src/providers/twitch/TwitchMessageBuilder.cpp @@ -482,7 +482,12 @@ void TwitchMessageBuilder::addTextOrEmoji(const QString &string_) if (getSettings()->colorUsernames) { - textColor = this->twitchChannel->getUserColor(username); + if (auto userColor = + this->twitchChannel->getUserColor(username); + userColor.isValid()) + { + textColor = userColor; + } } this->emplace(string, MessageElementFlag::BoldUsername, @@ -506,7 +511,12 @@ void TwitchMessageBuilder::addTextOrEmoji(const QString &string_) { if (getSettings()->colorUsernames) { - textColor = this->twitchChannel->getUserColor(username); + if (auto userColor = + this->twitchChannel->getUserColor(username); + userColor.isValid()) + { + textColor = userColor; + } } this->emplace(string, MessageElementFlag::BoldUsername, From 9531e6fc7725dadc0e1abc3ec7b23338b827615c Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Sat, 19 Dec 2020 14:07:42 +0100 Subject: [PATCH 5/7] flatten ChannelChatters::getUserColor --- src/common/ChannelChatters.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/common/ChannelChatters.cpp b/src/common/ChannelChatters.cpp index dd8ee580dec..be5bacb9bf1 100644 --- a/src/common/ChannelChatters.cpp +++ b/src/common/ChannelChatters.cpp @@ -80,10 +80,8 @@ const QColor ChannelChatters::getUserColor(const QString &user) // Returns an invalid color so we can decide not to override `textColor` return QColor(); } - else - { - return search->second; - } + + return search->second; } void ChannelChatters::setUserColor(const QString &user, const QColor &color) From 0994c8b2f8a7f95b525fc7e17d2ea075b7ceecf1 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Sat, 19 Dec 2020 14:10:10 +0100 Subject: [PATCH 6/7] Remove duplicate issue from changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 53cad14dfc1..ca4471d0ff9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +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, #2121, #2284) +- 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) From f28cec20d36879a6ed4549ce66720e895cc68e6e Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Sat, 19 Dec 2020 14:13:25 +0100 Subject: [PATCH 7/7] fix changelog entry --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ca4471d0ff9..fc5ca5edc0e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +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) +- 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)