From c50791972d8134ca26dfcb85b2ae0d5fc5f4fe3b Mon Sep 17 00:00:00 2001 From: KleberPF <43550602+KleberPF@users.noreply.github.com> Date: Sat, 9 Mar 2024 08:03:36 -0300 Subject: [PATCH] Add highlight color and show in mentions to automod messages (#5215) --- CHANGELOG.md | 2 ++ src/Application.cpp | 8 ++++++++ .../highlights/HighlightController.cpp | 5 ++++- src/controllers/highlights/HighlightModel.cpp | 18 +++++++++++++++--- src/controllers/highlights/HighlightPhrase.cpp | 1 + src/controllers/highlights/HighlightPhrase.hpp | 1 + src/messages/Message.cpp | 8 ++++++++ src/messages/Message.hpp | 12 +++++++----- src/messages/layouts/MessageLayout.cpp | 14 +++++++++++++- src/providers/colors/ColorProvider.cpp | 3 +++ src/providers/colors/ColorProvider.hpp | 1 + src/providers/twitch/TwitchMessageBuilder.cpp | 1 + src/singletons/Settings.hpp | 5 +++++ 13 files changed, 69 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c19f6056a..731d39a4b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,8 @@ - Minor: Introduce `c2.later()` function to Lua API. (#5154) - Minor: Live streams that are marked as reruns now mark a tab as yellow instead of red. (#5176, #5237) - Minor: Updated to Emoji v15.1. Google emojis are now used as the fallback instead of Twitter emojis. (#5182) +- Minor: Added the ability to show AutoMod caught messages in mentions. (#5215) +- Minor: Added the ability to configure the color of highlighted AutoMod caught messages. (#5215) - Minor: Allow theming of tab live and rerun indicators. (#5188) - Minor: Added a fallback theme field to custom themes that will be used in case the custom theme does not contain a color Chatterino needs. If no fallback theme is specified, we'll pull the color from the included Dark or Light theme. (#5198) - Minor: Image links now reflect the scale of their image instead of an internal label. (#5201) diff --git a/src/Application.cpp b/src/Application.cpp index 929bedd08..bede3f433 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -867,6 +867,14 @@ void Application::initPubSub() p.first); getApp()->twitch->automodChannel->addMessage( p.second); + + if (getSettings()->showAutomodInMentions) + { + getApp()->twitch->mentionsChannel->addMessage( + p.first); + getApp()->twitch->mentionsChannel->addMessage( + p.second); + } }); } // "ALLOWED" and "DENIED" statuses remain unimplemented diff --git a/src/controllers/highlights/HighlightController.cpp b/src/controllers/highlights/HighlightController.cpp index 53062d08c..3e15d7580 100644 --- a/src/controllers/highlights/HighlightController.cpp +++ b/src/controllers/highlights/HighlightController.cpp @@ -213,6 +213,8 @@ void rebuildMessageHighlights(Settings &settings, settings.enableAutomodHighlightTaskbar.getValue(); const auto highlightSoundUrlValue = settings.automodHighlightSoundUrl.getValue(); + auto highlightColor = + ColorProvider::instance().color(ColorType::AutomodHighlight); checks.emplace_back(HighlightCheck{ [=](const auto & /*args*/, const auto & /*badges*/, @@ -234,7 +236,7 @@ void rebuildMessageHighlights(Settings &settings, highlightAlert, // alert highlightSound, // playSound highlightSoundUrl, // customSoundUrl - nullptr, // color + highlightColor, // color false, // showInMentions }; }}); @@ -471,6 +473,7 @@ void HighlightController::initialize(Settings &settings, this->rebuildListener_.addSetting(settings.showThreadHighlightInMentions); this->rebuildListener_.addSetting(settings.enableAutomodHighlight); + this->rebuildListener_.addSetting(settings.showAutomodInMentions); this->rebuildListener_.addSetting(settings.enableAutomodHighlightSound); this->rebuildListener_.addSetting(settings.enableAutomodHighlightTaskbar); this->rebuildListener_.addSetting(settings.automodHighlightSoundUrl); diff --git a/src/controllers/highlights/HighlightModel.cpp b/src/controllers/highlights/HighlightModel.cpp index c83657c86..974653115 100644 --- a/src/controllers/highlights/HighlightModel.cpp +++ b/src/controllers/highlights/HighlightModel.cpp @@ -238,9 +238,10 @@ void HighlightModel::afterInit() const std::vector automodRow = this->createRow(); setBoolItem(automodRow[Column::Pattern], getSettings()->enableAutomodHighlight.getValue(), true, false); + setBoolItem(automodRow[Column::ShowInMentions], + getSettings()->showAutomodInMentions.getValue(), true, false); automodRow[Column::Pattern]->setData("AutoMod Caught Messages", Qt::DisplayRole); - automodRow[Column::ShowInMentions]->setFlags({}); setBoolItem(automodRow[Column::FlashTaskbar], getSettings()->enableAutomodHighlightTaskbar.getValue(), true, false); @@ -253,8 +254,9 @@ void HighlightModel::afterInit() const auto automodSound = QUrl(getSettings()->automodHighlightSoundUrl.getValue()); setFilePathItem(automodRow[Column::SoundPath], automodSound, false); - - automodRow[Column::Color]->setFlags(Qt::ItemFlag::NoItemFlags); + auto automodColor = + ColorProvider::instance().color(ColorType::AutomodHighlight); + setColorItem(automodRow[Column::Color], *automodColor, false); this->insertCustomRow(automodRow, HighlightRowIndexes::AutomodRow); } @@ -322,6 +324,11 @@ void HighlightModel::customRowSetData(const std::vector &row, getSettings()->showThreadHighlightInMentions.setValue( value.toBool()); } + else if (rowIndex == HighlightRowIndexes::AutomodRow) + { + getSettings()->showAutomodInMentions.setValue( + value.toBool()); + } } } break; @@ -502,6 +509,11 @@ void HighlightModel::customRowSetData(const std::vector &row, setColor(getSettings()->threadHighlightColor, ColorType::ThreadMessageHighlight); } + else if (rowIndex == HighlightRowIndexes::AutomodRow) + { + setColor(getSettings()->automodHighlightColor, + ColorType::AutomodHighlight); + } } } break; diff --git a/src/controllers/highlights/HighlightPhrase.cpp b/src/controllers/highlights/HighlightPhrase.cpp index c8963e59c..7afd1a33b 100644 --- a/src/controllers/highlights/HighlightPhrase.cpp +++ b/src/controllers/highlights/HighlightPhrase.cpp @@ -21,6 +21,7 @@ QColor HighlightPhrase::FALLBACK_ELEVATED_MESSAGE_HIGHLIGHT_COLOR = QColor HighlightPhrase::FALLBACK_THREAD_HIGHLIGHT_COLOR = QColor(143, 48, 24, 60); QColor HighlightPhrase::FALLBACK_SUB_COLOR = QColor(196, 102, 255, 100); +QColor HighlightPhrase::FALLBACK_AUTOMOD_HIGHLIGHT_COLOR = QColor(64, 64, 64); bool HighlightPhrase::operator==(const HighlightPhrase &other) const { diff --git a/src/controllers/highlights/HighlightPhrase.hpp b/src/controllers/highlights/HighlightPhrase.hpp index d470d35f6..ed03fbe96 100644 --- a/src/controllers/highlights/HighlightPhrase.hpp +++ b/src/controllers/highlights/HighlightPhrase.hpp @@ -86,6 +86,7 @@ public: static QColor FALLBACK_FIRST_MESSAGE_HIGHLIGHT_COLOR; static QColor FALLBACK_ELEVATED_MESSAGE_HIGHLIGHT_COLOR; static QColor FALLBACK_THREAD_HIGHLIGHT_COLOR; + static QColor FALLBACK_AUTOMOD_HIGHLIGHT_COLOR; private: QString pattern_; diff --git a/src/messages/Message.cpp b/src/messages/Message.cpp index 73f8ccde0..8840c6919 100644 --- a/src/messages/Message.cpp +++ b/src/messages/Message.cpp @@ -69,6 +69,14 @@ ScrollbarHighlight Message::getScrollBarHighlight() const }; } + if (this->flags.has(MessageFlag::AutoModOffendingMessage) || + this->flags.has(MessageFlag::AutoModOffendingMessageHeader)) + { + return { + ColorProvider::instance().color(ColorType::AutomodHighlight), + }; + } + return {}; } diff --git a/src/messages/Message.hpp b/src/messages/Message.hpp index 73c7640a4..b9e0b2321 100644 --- a/src/messages/Message.hpp +++ b/src/messages/Message.hpp @@ -51,15 +51,17 @@ enum class MessageFlag : int64_t { LiveUpdatesAdd = (1LL << 28), LiveUpdatesRemove = (1LL << 29), LiveUpdatesUpdate = (1LL << 30), + /// The header of a message caught by AutoMod containing allow/disallow + AutoModOffendingMessageHeader = (1LL << 31), /// The message caught by AutoMod containing the user who sent the message & its contents - AutoModOffendingMessage = (1LL << 31), - LowTrustUsers = (1LL << 32), + AutoModOffendingMessage = (1LL << 32), + LowTrustUsers = (1LL << 33), /// The message is sent by a user marked as restricted with Twitch's "Low Trust"/"Suspicious User" feature - RestrictedMessage = (1LL << 33), + RestrictedMessage = (1LL << 34), /// The message is sent by a user marked as monitor with Twitch's "Low Trust"/"Suspicious User" feature - MonitoredMessage = (1LL << 34), + MonitoredMessage = (1LL << 35), /// The message is an ACTION message (/me) - Action = (1LL << 35), + Action = (1LL << 36), }; using MessageFlags = FlagsEnum; diff --git a/src/messages/layouts/MessageLayout.cpp b/src/messages/layouts/MessageLayout.cpp index a7c557639..efc1d1b56 100644 --- a/src/messages/layouts/MessageLayout.cpp +++ b/src/messages/layouts/MessageLayout.cpp @@ -373,7 +373,19 @@ void MessageLayout::updateBuffer(QPixmap *buffer, else if (this->message_->flags.has(MessageFlag::AutoMod) || this->message_->flags.has(MessageFlag::LowTrustUsers)) { - backgroundColor = QColor("#404040"); + if (ctx.preferences.enableAutomodHighlight && + (this->message_->flags.has(MessageFlag::AutoModOffendingMessage) || + this->message_->flags.has( + MessageFlag::AutoModOffendingMessageHeader))) + { + backgroundColor = blendColors( + backgroundColor, + *ctx.colorProvider.color(ColorType::AutomodHighlight)); + } + else + { + backgroundColor = QColor("#404040"); + } } else if (this->message_->flags.has(MessageFlag::Debug)) { diff --git a/src/providers/colors/ColorProvider.cpp b/src/providers/colors/ColorProvider.cpp index 72039a1f1..017dd0d83 100644 --- a/src/providers/colors/ColorProvider.cpp +++ b/src/providers/colors/ColorProvider.cpp @@ -128,6 +128,9 @@ void ColorProvider::initTypeColorMap() initColor(ColorType::ThreadMessageHighlight, getSettings()->threadHighlightColor, HighlightPhrase::FALLBACK_THREAD_HIGHLIGHT_COLOR); + + initColor(ColorType::AutomodHighlight, getSettings()->automodHighlightColor, + HighlightPhrase::FALLBACK_AUTOMOD_HIGHLIGHT_COLOR); } void ColorProvider::initDefaultColors() diff --git a/src/providers/colors/ColorProvider.hpp b/src/providers/colors/ColorProvider.hpp index dfd9b4b83..c35da0543 100644 --- a/src/providers/colors/ColorProvider.hpp +++ b/src/providers/colors/ColorProvider.hpp @@ -18,6 +18,7 @@ enum class ColorType { ThreadMessageHighlight, // Used in automatic highlights of your own messages SelfMessageHighlight, + AutomodHighlight, }; class ColorProvider diff --git a/src/providers/twitch/TwitchMessageBuilder.cpp b/src/providers/twitch/TwitchMessageBuilder.cpp index 8f416b8ee..af266889c 100644 --- a/src/providers/twitch/TwitchMessageBuilder.cpp +++ b/src/providers/twitch/TwitchMessageBuilder.cpp @@ -2009,6 +2009,7 @@ std::pair TwitchMessageBuilder::makeAutomodMessage( builder.message().flags.set(MessageFlag::PubSub); builder.message().flags.set(MessageFlag::Timeout); builder.message().flags.set(MessageFlag::AutoMod); + builder.message().flags.set(MessageFlag::AutoModOffendingMessageHeader); // AutoMod shield badge builder.emplace(makeAutoModBadge(), diff --git a/src/singletons/Settings.hpp b/src/singletons/Settings.hpp index d96b13f0e..3e0c693f2 100644 --- a/src/singletons/Settings.hpp +++ b/src/singletons/Settings.hpp @@ -394,6 +394,10 @@ public: "/highlighting/automod/enabled", true, }; + BoolSetting showAutomodInMentions = { + "/highlighting/automod/showInMentions", + false, + }; BoolSetting enableAutomodHighlightSound = { "/highlighting/automod/enableSound", false, @@ -406,6 +410,7 @@ public: "/highlighting/automod/soundUrl", "", }; + QStringSetting automodHighlightColor = {"/highlighting/automod/color", ""}; BoolSetting enableThreadHighlight = { "/highlighting/thread/nameIsHighlightKeyword", true};