From 1556a4b182346990e4df3ab3ea59617c166426b1 Mon Sep 17 00:00:00 2001 From: iProdigy Date: Thu, 14 Dec 2023 21:32:38 -0800 Subject: [PATCH 01/19] feat: trigger sound and highlight for automod channel --- src/Application.cpp | 11 ++++++++++ src/singletons/Settings.hpp | 5 +++++ src/widgets/helper/ChannelView.cpp | 14 +++++++----- src/widgets/splits/SplitHeader.cpp | 35 ++++++++++++++++++++++++++++++ 4 files changed, 59 insertions(+), 6 deletions(-) diff --git a/src/Application.cpp b/src/Application.cpp index d8a7a575469..d2444b40aac 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -555,6 +555,17 @@ void Application::initPubSub() p.first); getApp()->twitch->automodChannel->addMessage( p.second); + + if (getSettings()->automodPlaySound && + !isInStreamerMode()) + { + getApp()->notifications->playSound(); + } + if (getSettings()->automodFlashTaskbar && + !isInStreamerMode()) + { + getApp()->windows->sendAlert(); + } }); } // "ALLOWED" and "DENIED" statuses remain unimplemented diff --git a/src/singletons/Settings.hpp b/src/singletons/Settings.hpp index 8e650de873d..c65b69a01d9 100644 --- a/src/singletons/Settings.hpp +++ b/src/singletons/Settings.hpp @@ -431,6 +431,11 @@ class Settings IntSetting openFromToast = {"/notifications/openFromToast", static_cast(ToastReaction::OpenInBrowser)}; + BoolSetting automodPlaySound = {"/notifications/automod/enableSound", + false}; + BoolSetting automodFlashTaskbar = { + "/notifications/automod/enableTaskbarFlashing", true}; + /// External tools // Streamlink BoolSetting streamlinkUseCustomPath = {"/external/streamlink/useCustomPath", diff --git a/src/widgets/helper/ChannelView.cpp b/src/widgets/helper/ChannelView.cpp index 171f05e65c5..873823ff048 100644 --- a/src/widgets/helper/ChannelView.cpp +++ b/src/widgets/helper/ChannelView.cpp @@ -1076,12 +1076,14 @@ void ChannelView::messageAppended(MessagePtr &message, if (!messageFlags->has(MessageFlag::DoNotTriggerNotification)) { - if (messageFlags->has(MessageFlag::Highlighted) && - messageFlags->has(MessageFlag::ShowInMentions) && - !messageFlags->has(MessageFlag::Subscription) && - (getSettings()->highlightMentions || - this->channel_->getType() != Channel::Type::TwitchMentions)) - + if ((messageFlags->has(MessageFlag::Highlighted) && + messageFlags->has(MessageFlag::ShowInMentions) && + !messageFlags->has(MessageFlag::Subscription) && + (getSettings()->highlightMentions || + this->channel_->getType() != Channel::Type::TwitchMentions)) || + (this->channel_->getType() == Channel::Type::TwitchAutomod && + (getSettings()->automodPlaySound || + getSettings()->automodFlashTaskbar))) { this->tabHighlightRequested.invoke(HighlightState::Highlighted); } diff --git a/src/widgets/splits/SplitHeader.cpp b/src/widgets/splits/SplitHeader.cpp index 58d75b44b18..8fbd1d6c9f6 100644 --- a/src/widgets/splits/SplitHeader.cpp +++ b/src/widgets/splits/SplitHeader.cpp @@ -509,6 +509,41 @@ std::unique_ptr SplitHeader::createMainMenu() moreMenu->addAction(action); } + if (this->split_->getChannel()->getType() == Channel::Type::TwitchAutomod) + { + { + auto *action = new QAction(this); + action->setText("Play sound on caught messages"); + action->setCheckable(true); + + QObject::connect(moreMenu, &QMenu::aboutToShow, this, [action] { + action->setChecked(getSettings()->automodPlaySound); + }); + QObject::connect(action, &QAction::triggered, this, [] { + getSettings()->automodPlaySound = + !getSettings()->automodPlaySound; + }); + + moreMenu->addAction(action); + } + + { + auto *action = new QAction(this); + action->setText("Flash taskbar on caught messages"); + action->setCheckable(true); + + QObject::connect(moreMenu, &QMenu::aboutToShow, this, [action] { + action->setChecked(getSettings()->automodFlashTaskbar); + }); + QObject::connect(action, &QAction::triggered, this, [] { + getSettings()->automodFlashTaskbar = + !getSettings()->automodFlashTaskbar; + }); + + moreMenu->addAction(action); + } + } + if (twitchChannel) { moreMenu->addAction( From 07346f77827537e93c55059bda215e43dd9c8db2 Mon Sep 17 00:00:00 2001 From: iProdigy <8106344+iProdigy@users.noreply.github.com> Date: Thu, 14 Dec 2023 22:01:30 -0800 Subject: [PATCH 02/19] chore: update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cd00604d3bd..76193dc056d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ ## Unversioned - Major: Allow use of Twitch follower emotes in other channels if subscribed. (#4922) -- Major: Add `/automod` split to track automod caught messages across all open channels the user moderates. (#4986) +- Major: Add `/automod` split to track automod caught messages across all open channels the user moderates. (#4986, #5026) - Minor: Migrate to the new Get Channel Followers Helix endpoint, fixing follower count not showing up in usercards. (#4809) - Minor: The account switcher is now styled to match your theme. (#4817) - Minor: Add an invisible resize handle to the bottom of frameless user info popups and reply thread popups. (#4795) From 42bf0daf469997409419e235e0a54f76b3a5c8f4 Mon Sep 17 00:00:00 2001 From: iProdigy Date: Sat, 23 Dec 2023 21:32:09 -0800 Subject: [PATCH 03/19] feat: create automod row in highlights settings --- src/Application.cpp | 11 ---- .../highlights/HighlightController.cpp | 45 ++++++++++++++++ src/controllers/highlights/HighlightModel.cpp | 53 +++++++++++++++++++ src/controllers/highlights/HighlightModel.hpp | 1 + .../highlights/HighlightPhrase.cpp | 2 + .../highlights/HighlightPhrase.hpp | 1 + src/messages/Message.cpp | 8 +++ src/messages/layouts/MessageLayoutContext.cpp | 6 +++ src/messages/layouts/MessageLayoutContext.hpp | 1 + src/providers/colors/ColorProvider.cpp | 17 ++++++ src/providers/colors/ColorProvider.hpp | 1 + src/singletons/Settings.hpp | 16 ++++-- src/widgets/helper/ChannelView.cpp | 6 +-- src/widgets/splits/SplitHeader.cpp | 35 ------------ 14 files changed, 149 insertions(+), 54 deletions(-) diff --git a/src/Application.cpp b/src/Application.cpp index d2444b40aac..d8a7a575469 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -555,17 +555,6 @@ void Application::initPubSub() p.first); getApp()->twitch->automodChannel->addMessage( p.second); - - if (getSettings()->automodPlaySound && - !isInStreamerMode()) - { - getApp()->notifications->playSound(); - } - if (getSettings()->automodFlashTaskbar && - !isInStreamerMode()) - { - getApp()->windows->sendAlert(); - } }); } // "ALLOWED" and "DENIED" statuses remain unimplemented diff --git a/src/controllers/highlights/HighlightController.cpp b/src/controllers/highlights/HighlightController.cpp index 6e91f706b71..11b577a9657 100644 --- a/src/controllers/highlights/HighlightController.cpp +++ b/src/controllers/highlights/HighlightController.cpp @@ -204,6 +204,46 @@ void rebuildMessageHighlights(Settings &settings, { checks.emplace_back(highlightPhraseCheck(highlight)); } + + if (settings.enableAutomodHighlight) + { + const auto highlightSound = + settings.enableAutomodHighlightSound.getValue(); + const auto highlightAlert = + settings.enableAutomodHighlightTaskbar.getValue(); + const auto highlightSoundUrlValue = + settings.automodHighlightSoundUrl.getValue(); + + checks.emplace_back(HighlightCheck{ + [=](const auto & /*args*/, const auto &badges, + const auto & /*senderName*/, const auto & /*originalMessage*/, + const auto &flags, + const auto /*self*/) -> std::optional { + if (!flags.has(MessageFlag::AutoMod)) + { + return std::nullopt; + } + + const auto offender = badges.empty(); + + std::optional highlightSoundUrl; + if (offender && !highlightSoundUrlValue.isEmpty()) + { + highlightSoundUrl = highlightSoundUrlValue; + } + + const auto highlightColor = ColorProvider::instance().color( + ColorType::AutomodHighlight); + + return HighlightResult{ + highlightAlert && offender, // alert + highlightSound && offender, // playSound + highlightSoundUrl, // customSoundUrl + highlightColor, // color + false, // showInMentions + }; + }}); + } } void rebuildUserHighlights(Settings &settings, @@ -434,6 +474,11 @@ void HighlightController::initialize(Settings &settings, Paths & /*paths*/) this->rebuildListener_.addSetting(settings.threadHighlightSoundUrl); this->rebuildListener_.addSetting(settings.showThreadHighlightInMentions); + this->rebuildListener_.addSetting(settings.enableAutomodHighlight); + this->rebuildListener_.addSetting(settings.enableAutomodHighlightSound); + this->rebuildListener_.addSetting(settings.enableAutomodHighlightTaskbar); + this->rebuildListener_.addSetting(settings.automodHighlightSoundUrl); + this->rebuildListener_.setCB([this, &settings] { qCDebug(chatterinoHighlights) << "Rebuild checks because a setting changed"; diff --git a/src/controllers/highlights/HighlightModel.cpp b/src/controllers/highlights/HighlightModel.cpp index 7c7b08e9bd9..4ac4ea4ddee 100644 --- a/src/controllers/highlights/HighlightModel.cpp +++ b/src/controllers/highlights/HighlightModel.cpp @@ -234,6 +234,32 @@ void HighlightModel::afterInit() this->insertCustomRow(threadMessageRow, HighlightRowIndexes::ThreadMessageRow); + + // Highlight settings for automod caught messages + const std::vector automodRow = this->createRow(); + setBoolItem(automodRow[Column::Pattern], + getSettings()->enableAutomodHighlight.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); + setBoolItem(automodRow[Column::PlaySound], + getSettings()->enableAutomodHighlightSound.getValue(), true, + false); + automodRow[Column::UseRegex]->setFlags({}); + automodRow[Column::CaseSensitive]->setFlags({}); + + const auto automodSound = + QUrl(getSettings()->automodHighlightSoundUrl.getValue()); + setFilePathItem(automodRow[Column::SoundPath], automodSound, false); + + const auto automodMessageColor = + ColorProvider::instance().color(ColorType::AutomodHighlight); + setColorItem(automodRow[Column::Color], *automodMessageColor, false); + + this->insertCustomRow(automodRow, HighlightRowIndexes::AutomodRow); } void HighlightModel::customRowSetData(const std::vector &row, @@ -278,6 +304,11 @@ void HighlightModel::customRowSetData(const std::vector &row, getSettings()->enableThreadHighlight.setValue( value.toBool()); } + else if (rowIndex == HighlightRowIndexes::AutomodRow) + { + getSettings()->enableAutomodHighlight.setValue( + value.toBool()); + } } } break; @@ -336,6 +367,11 @@ void HighlightModel::customRowSetData(const std::vector &row, getSettings()->enableThreadHighlightTaskbar.setValue( value.toBool()); } + else if (rowIndex == HighlightRowIndexes::AutomodRow) + { + getSettings()->enableAutomodHighlightTaskbar.setValue( + value.toBool()); + } } } break; @@ -377,6 +413,11 @@ void HighlightModel::customRowSetData(const std::vector &row, getSettings()->enableThreadHighlightSound.setValue( value.toBool()); } + else if (rowIndex == HighlightRowIndexes::AutomodRow) + { + getSettings()->enableAutomodHighlightSound.setValue( + value.toBool()); + } } } break; @@ -412,6 +453,11 @@ void HighlightModel::customRowSetData(const std::vector &row, getSettings()->threadHighlightSoundUrl.setValue( value.toString()); } + else if (rowIndex == HighlightRowIndexes::AutomodRow) + { + getSettings()->automodHighlightSoundUrl.setValue( + value.toString()); + } } } break; @@ -462,6 +508,13 @@ void HighlightModel::customRowSetData(const std::vector &row, .updateColor(ColorType::ThreadMessageHighlight, QColor(colorName)); } + else if (rowIndex == HighlightRowIndexes::AutomodRow) + { + getSettings()->automodHighlightColor.setValue(colorName); + const_cast(ColorProvider::instance()) + .updateColor(ColorType::AutomodHighlight, + QColor(colorName)); + } } } break; diff --git a/src/controllers/highlights/HighlightModel.hpp b/src/controllers/highlights/HighlightModel.hpp index 0ee5192cf16..be807d33e54 100644 --- a/src/controllers/highlights/HighlightModel.hpp +++ b/src/controllers/highlights/HighlightModel.hpp @@ -34,6 +34,7 @@ class HighlightModel : public SignalVectorModel FirstMessageRow = 4, ElevatedMessageRow = 5, ThreadMessageRow = 6, + AutomodRow = 7, }; enum UserHighlightRowIndexes { diff --git a/src/controllers/highlights/HighlightPhrase.cpp b/src/controllers/highlights/HighlightPhrase.cpp index c8963e59c39..5f86f2ef987 100644 --- a/src/controllers/highlights/HighlightPhrase.cpp +++ b/src/controllers/highlights/HighlightPhrase.cpp @@ -20,6 +20,8 @@ QColor HighlightPhrase::FALLBACK_ELEVATED_MESSAGE_HIGHLIGHT_COLOR = QColor(255, 174, 66, 60); QColor HighlightPhrase::FALLBACK_THREAD_HIGHLIGHT_COLOR = QColor(143, 48, 24, 60); +QColor HighlightPhrase::FALLBACK_AUTOMOD_HIGHLIGHT_COLOR = + QColor(0, 255, 3, 100); QColor HighlightPhrase::FALLBACK_SUB_COLOR = QColor(196, 102, 255, 100); bool HighlightPhrase::operator==(const HighlightPhrase &other) const diff --git a/src/controllers/highlights/HighlightPhrase.hpp b/src/controllers/highlights/HighlightPhrase.hpp index 56d3499ccb9..fab0ecd98aa 100644 --- a/src/controllers/highlights/HighlightPhrase.hpp +++ b/src/controllers/highlights/HighlightPhrase.hpp @@ -86,6 +86,7 @@ class HighlightPhrase 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 73f8ccde038..01d26cd9d4f 100644 --- a/src/messages/Message.cpp +++ b/src/messages/Message.cpp @@ -69,6 +69,14 @@ ScrollbarHighlight Message::getScrollBarHighlight() const }; } + if (this->flags.has(MessageFlag::AutoMod) && + getSettings()->enableAutomodHighlight) + { + return { + ColorProvider::instance().color(ColorType::AutomodHighlight), + }; + } + return {}; } diff --git a/src/messages/layouts/MessageLayoutContext.cpp b/src/messages/layouts/MessageLayoutContext.cpp index 82b158485fe..98c963919d5 100644 --- a/src/messages/layouts/MessageLayoutContext.cpp +++ b/src/messages/layouts/MessageLayoutContext.cpp @@ -47,6 +47,12 @@ void MessagePreferences::connectSettings(Settings *settings, }, holder); + settings->enableAutomodHighlight.connect( + [this](const auto &newValue) { + this->enableAutomodHighlight = newValue; + }, + holder); + settings->alternateMessages.connect( [this](const auto &newValue) { this->alternateMessages = newValue; diff --git a/src/messages/layouts/MessageLayoutContext.hpp b/src/messages/layouts/MessageLayoutContext.hpp index a64d98bb448..d8f08ab3abf 100644 --- a/src/messages/layouts/MessageLayoutContext.hpp +++ b/src/messages/layouts/MessageLayoutContext.hpp @@ -39,6 +39,7 @@ struct MessagePreferences { bool enableElevatedMessageHighlight{}; bool enableFirstMessageHighlight{}; bool enableSubHighlight{}; + bool enableAutomodHighlight{}; bool alternateMessages{}; bool separateMessages{}; diff --git a/src/providers/colors/ColorProvider.cpp b/src/providers/colors/ColorProvider.cpp index fbda9c6ee79..66deee169bc 100644 --- a/src/providers/colors/ColorProvider.cpp +++ b/src/providers/colors/ColorProvider.cpp @@ -51,6 +51,7 @@ QSet ColorProvider::recentColors() const } // Insert preset highlight colors + retVal.insert(*this->color(ColorType::AutomodHighlight)); retVal.insert(*this->color(ColorType::SelfHighlight)); retVal.insert(*this->color(ColorType::Subscription)); retVal.insert(*this->color(ColorType::Whisper)); @@ -178,6 +179,20 @@ void ColorProvider::initTypeColorMap() std::make_shared( HighlightPhrase::FALLBACK_THREAD_HIGHLIGHT_COLOR)}); } + + customColor = getSettings()->automodHighlightColor; + if (QColor(customColor).isValid()) + { + this->typeColorMap_.insert({ColorType::AutomodHighlight, + std::make_shared(customColor)}); + } + else + { + this->typeColorMap_.insert( + {ColorType::AutomodHighlight, + std::make_shared( + HighlightPhrase::FALLBACK_AUTOMOD_HIGHLIGHT_COLOR)}); + } } void ColorProvider::initDefaultColors() @@ -196,6 +211,8 @@ void ColorProvider::initDefaultColors() this->defaultColors_.push_back(HighlightPhrase::FALLBACK_HIGHLIGHT_COLOR); this->defaultColors_.push_back(HighlightPhrase::FALLBACK_SUB_COLOR); + this->defaultColors_.push_back( + HighlightPhrase::FALLBACK_AUTOMOD_HIGHLIGHT_COLOR); } } // namespace chatterino diff --git a/src/providers/colors/ColorProvider.hpp b/src/providers/colors/ColorProvider.hpp index 12745371d1e..0c7b094fd21 100644 --- a/src/providers/colors/ColorProvider.hpp +++ b/src/providers/colors/ColorProvider.hpp @@ -12,6 +12,7 @@ enum class ColorType { SelfHighlight, Subscription, Whisper, + AutomodHighlight, RedeemedHighlight, FirstMessageHighlight, ElevatedMessageHighlight, diff --git a/src/singletons/Settings.hpp b/src/singletons/Settings.hpp index c65b69a01d9..ef72c9f62de 100644 --- a/src/singletons/Settings.hpp +++ b/src/singletons/Settings.hpp @@ -375,6 +375,17 @@ class Settings ""}; QStringSetting subHighlightColor = {"/highlighting/subHighlightColor", ""}; + BoolSetting enableAutomodHighlight = { + "/highlighting/automodHighlight/automodHighlighted", true}; + BoolSetting enableAutomodHighlightSound = { + "/highlighting/automodHighlight/enableSound", false}; + BoolSetting enableAutomodHighlightTaskbar = { + "/highlighting/automodHighlight/enableTaskbarFlashing", false}; + QStringSetting automodHighlightSoundUrl = { + "/highlighting/automodHighlightSoundUrl", ""}; + QStringSetting automodHighlightColor = { + "/highlighting/automodHighlightColor", ""}; + BoolSetting enableThreadHighlight = { "/highlighting/thread/nameIsHighlightKeyword", true}; BoolSetting showThreadHighlightInMentions = { @@ -431,11 +442,6 @@ class Settings IntSetting openFromToast = {"/notifications/openFromToast", static_cast(ToastReaction::OpenInBrowser)}; - BoolSetting automodPlaySound = {"/notifications/automod/enableSound", - false}; - BoolSetting automodFlashTaskbar = { - "/notifications/automod/enableTaskbarFlashing", true}; - /// External tools // Streamlink BoolSetting streamlinkUseCustomPath = {"/external/streamlink/useCustomPath", diff --git a/src/widgets/helper/ChannelView.cpp b/src/widgets/helper/ChannelView.cpp index 1a4d035047d..6e565f7d5a0 100644 --- a/src/widgets/helper/ChannelView.cpp +++ b/src/widgets/helper/ChannelView.cpp @@ -811,7 +811,8 @@ ChannelPtr ChannelView::channel() bool ChannelView::showScrollbarHighlights() const { - return this->channel_->getType() != Channel::Type::TwitchMentions; + return this->channel_->getType() != Channel::Type::TwitchMentions && + this->channel_->getType() != Channel::Type::TwitchAutomod; } void ChannelView::setChannel(const ChannelPtr &underlyingChannel) @@ -1082,8 +1083,7 @@ void ChannelView::messageAppended(MessagePtr &message, (getSettings()->highlightMentions || this->channel_->getType() != Channel::Type::TwitchMentions)) || (this->channel_->getType() == Channel::Type::TwitchAutomod && - (getSettings()->automodPlaySound || - getSettings()->automodFlashTaskbar))) + getSettings()->enableAutomodHighlight)) { this->tabHighlightRequested.invoke(HighlightState::Highlighted); } diff --git a/src/widgets/splits/SplitHeader.cpp b/src/widgets/splits/SplitHeader.cpp index dbd47843526..2589b9b25f3 100644 --- a/src/widgets/splits/SplitHeader.cpp +++ b/src/widgets/splits/SplitHeader.cpp @@ -509,41 +509,6 @@ std::unique_ptr SplitHeader::createMainMenu() moreMenu->addAction(action); } - if (this->split_->getChannel()->getType() == Channel::Type::TwitchAutomod) - { - { - auto *action = new QAction(this); - action->setText("Play sound on caught messages"); - action->setCheckable(true); - - QObject::connect(moreMenu, &QMenu::aboutToShow, this, [action] { - action->setChecked(getSettings()->automodPlaySound); - }); - QObject::connect(action, &QAction::triggered, this, [] { - getSettings()->automodPlaySound = - !getSettings()->automodPlaySound; - }); - - moreMenu->addAction(action); - } - - { - auto *action = new QAction(this); - action->setText("Flash taskbar on caught messages"); - action->setCheckable(true); - - QObject::connect(moreMenu, &QMenu::aboutToShow, this, [action] { - action->setChecked(getSettings()->automodFlashTaskbar); - }); - QObject::connect(action, &QAction::triggered, this, [] { - getSettings()->automodFlashTaskbar = - !getSettings()->automodFlashTaskbar; - }); - - moreMenu->addAction(action); - } - } - if (twitchChannel) { moreMenu->addAction( From ccba4dbf775163b1c8bdc562605a8d39e8de5be0 Mon Sep 17 00:00:00 2001 From: iProdigy Date: Sat, 23 Dec 2023 21:34:32 -0800 Subject: [PATCH 04/19] chore: reformat --- src/widgets/helper/ChannelView.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/widgets/helper/ChannelView.cpp b/src/widgets/helper/ChannelView.cpp index 6e565f7d5a0..52cabe6fa93 100644 --- a/src/widgets/helper/ChannelView.cpp +++ b/src/widgets/helper/ChannelView.cpp @@ -812,7 +812,7 @@ ChannelPtr ChannelView::channel() bool ChannelView::showScrollbarHighlights() const { return this->channel_->getType() != Channel::Type::TwitchMentions && - this->channel_->getType() != Channel::Type::TwitchAutomod; + this->channel_->getType() != Channel::Type::TwitchAutomod; } void ChannelView::setChannel(const ChannelPtr &underlyingChannel) From 3466b3f8431d1ecdd55a634fefd5eac429191dfb Mon Sep 17 00:00:00 2001 From: iProdigy Date: Sun, 24 Dec 2023 20:35:22 -0800 Subject: [PATCH 05/19] fix: call highlight controller for automod caught message --- src/Application.cpp | 9 +- src/messages/MessageBuilder.cpp | 153 ---------------- src/messages/MessageBuilder.hpp | 3 - src/messages/SharedMessageBuilder.cpp | 30 +++- src/messages/SharedMessageBuilder.hpp | 3 + src/providers/twitch/TwitchMessageBuilder.cpp | 164 ++++++++++++++++++ src/providers/twitch/TwitchMessageBuilder.hpp | 4 + 7 files changed, 201 insertions(+), 165 deletions(-) diff --git a/src/Application.cpp b/src/Application.cpp index d8a7a575469..db04ffffb0f 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -547,7 +547,8 @@ void Application::initPubSub() senderDisplayName, senderColor}; postToThread([chan, action] { const auto p = - makeAutomodMessage(action, chan->getName()); + TwitchMessageBuilder::makeAutomodMessage( + action, chan->getName()); chan->addMessage(p.first); chan->addMessage(p.second); @@ -579,7 +580,8 @@ void Application::initPubSub() } postToThread([chan, action] { - const auto p = makeAutomodMessage(action, chan->getName()); + const auto p = TwitchMessageBuilder::makeAutomodMessage( + action, chan->getName()); chan->addMessage(p.first); chan->addMessage(p.second); }); @@ -621,7 +623,8 @@ void Application::initPubSub() } postToThread([chan, action] { - const auto p = makeAutomodInfoMessage(action); + const auto p = + TwitchMessageBuilder::makeAutomodInfoMessage(action); chan->addMessage(p); }); }); diff --git a/src/messages/MessageBuilder.cpp b/src/messages/MessageBuilder.cpp index b605544b904..d5ba0ff79fe 100644 --- a/src/messages/MessageBuilder.cpp +++ b/src/messages/MessageBuilder.cpp @@ -78,159 +78,6 @@ MessagePtr makeSystemMessage(const QString &text, const QTime &time) return MessageBuilder(systemMessage, text, time).release(); } -EmotePtr makeAutoModBadge() -{ - return std::make_shared(Emote{ - EmoteName{}, - ImageSet{Image::fromResourcePixmap(getResources().twitch.automod)}, - Tooltip{"AutoMod"}, - Url{"https://dashboard.twitch.tv/settings/moderation/automod"}}); -} - -MessagePtr makeAutomodInfoMessage(const AutomodInfoAction &action) -{ - auto builder = MessageBuilder(); - QString text("AutoMod: "); - - builder.emplace(); - builder.message().flags.set(MessageFlag::PubSub); - - // AutoMod shield badge - builder.emplace(makeAutoModBadge(), - MessageElementFlag::BadgeChannelAuthority); - // AutoMod "username" - builder.emplace("AutoMod:", MessageElementFlag::BoldUsername, - MessageColor(QColor("blue")), - FontStyle::ChatMediumBold); - builder.emplace( - "AutoMod:", MessageElementFlag::NonBoldUsername, - MessageColor(QColor("blue"))); - switch (action.type) - { - case AutomodInfoAction::OnHold: { - QString info("Hey! Your message is being checked " - "by mods and has not been sent."); - text += info; - builder.emplace(info, MessageElementFlag::Text, - MessageColor::Text); - } - break; - case AutomodInfoAction::Denied: { - QString info("Mods have removed your message."); - text += info; - builder.emplace(info, MessageElementFlag::Text, - MessageColor::Text); - } - break; - case AutomodInfoAction::Approved: { - QString info("Mods have accepted your message."); - text += info; - builder.emplace(info, MessageElementFlag::Text, - MessageColor::Text); - } - break; - } - - builder.message().flags.set(MessageFlag::AutoMod); - builder.message().messageText = text; - builder.message().searchText = text; - - auto message = builder.release(); - - return message; -} - -std::pair makeAutomodMessage( - const AutomodAction &action, const QString &channelName) -{ - MessageBuilder builder, builder2; - - // - // Builder for AutoMod message with explanation - builder.message().loginName = "automod"; - builder.message().channelName = channelName; - builder.message().flags.set(MessageFlag::PubSub); - builder.message().flags.set(MessageFlag::Timeout); - builder.message().flags.set(MessageFlag::AutoMod); - - // AutoMod shield badge - builder.emplace(makeAutoModBadge(), - MessageElementFlag::BadgeChannelAuthority); - // AutoMod "username" - builder.emplace("AutoMod:", MessageElementFlag::BoldUsername, - MessageColor(QColor("blue")), - FontStyle::ChatMediumBold); - builder.emplace( - "AutoMod:", MessageElementFlag::NonBoldUsername, - MessageColor(QColor("blue"))); - // AutoMod header message - builder.emplace( - ("Held a message for reason: " + action.reason + - ". Allow will post it in chat. "), - MessageElementFlag::Text, MessageColor::Text); - // Allow link button - builder - .emplace("Allow", MessageElementFlag::Text, - MessageColor(QColor("green")), - FontStyle::ChatMediumBold) - ->setLink({Link::AutoModAllow, action.msgID}); - // Deny link button - builder - .emplace(" Deny", MessageElementFlag::Text, - MessageColor(QColor("red")), - FontStyle::ChatMediumBold) - ->setLink({Link::AutoModDeny, action.msgID}); - // ID of message caught by AutoMod - // builder.emplace(action.msgID, MessageElementFlag::Text, - // MessageColor::Text); - auto text1 = - QString("AutoMod: Held a message for reason: %1. Allow will post " - "it in chat. Allow Deny") - .arg(action.reason); - builder.message().messageText = text1; - builder.message().searchText = text1; - - auto message1 = builder.release(); - - // - // Builder for offender's message - builder2.message().channelName = channelName; - builder2 - .emplace("#" + channelName, - MessageElementFlag::ChannelName, - MessageColor::System) - ->setLink({Link::JumpToChannel, channelName}); - builder2.emplace(); - builder2.emplace(); - builder2.message().loginName = action.target.login; - builder2.message().flags.set(MessageFlag::PubSub); - builder2.message().flags.set(MessageFlag::Timeout); - builder2.message().flags.set(MessageFlag::AutoMod); - - // sender username - builder2 - .emplace( - action.target.displayName + ":", MessageElementFlag::BoldUsername, - MessageColor(action.target.color), FontStyle::ChatMediumBold) - ->setLink({Link::UserInfo, action.target.login}); - builder2 - .emplace(action.target.displayName + ":", - MessageElementFlag::NonBoldUsername, - MessageColor(action.target.color)) - ->setLink({Link::UserInfo, action.target.login}); - // sender's message caught by AutoMod - builder2.emplace(action.message, MessageElementFlag::Text, - MessageColor::Text); - auto text2 = - QString("%1: %2").arg(action.target.displayName, action.message); - builder2.message().messageText = text2; - builder2.message().searchText = text2; - - auto message2 = builder2.release(); - - return std::make_pair(message1, message2); -} - MessageBuilder::MessageBuilder() : message_(std::make_shared()) { diff --git a/src/messages/MessageBuilder.hpp b/src/messages/MessageBuilder.hpp index 333d2346904..c7277997a27 100644 --- a/src/messages/MessageBuilder.hpp +++ b/src/messages/MessageBuilder.hpp @@ -53,9 +53,6 @@ const ImageUploaderResultTag imageUploaderResultMessage{}; MessagePtr makeSystemMessage(const QString &text); MessagePtr makeSystemMessage(const QString &text, const QTime &time); -std::pair makeAutomodMessage( - const AutomodAction &action, const QString &channelName); -MessagePtr makeAutomodInfoMessage(const AutomodInfoAction &action); struct MessageParseArgs { bool disablePingSounds = false; diff --git a/src/messages/SharedMessageBuilder.cpp b/src/messages/SharedMessageBuilder.cpp index 719ec1bedd4..ca8d9d88700 100644 --- a/src/messages/SharedMessageBuilder.cpp +++ b/src/messages/SharedMessageBuilder.cpp @@ -199,6 +199,14 @@ void SharedMessageBuilder::appendChannelName() } void SharedMessageBuilder::triggerHighlights() +{ + triggerHighlights(this->channel->getName(), this->highlightSound_, + this->highlightSoundUrl_, this->highlightAlert_); +} + +void SharedMessageBuilder::triggerHighlights( + const QString &channelName, bool playSound, + const std::optional &customSoundUrl, bool windowAlert) { if (isInStreamerMode() && getSettings()->streamerModeMuteMentions) { @@ -206,21 +214,31 @@ void SharedMessageBuilder::triggerHighlights() return; } - if (getSettings()->isMutedChannel(this->channel->getName())) + if (getSettings()->isMutedChannel(channelName)) { // Do nothing. Pings are muted in this channel. return; } - bool hasFocus = (QApplication::focusWidget() != nullptr); - bool resolveFocus = !hasFocus || getSettings()->highlightAlwaysPlaySound; + const bool hasFocus = (QApplication::focusWidget() != nullptr); + const bool resolveFocus = + !hasFocus || getSettings()->highlightAlwaysPlaySound; - if (this->highlightSound_ && resolveFocus) + if (playSound && resolveFocus) { - getIApp()->getSound()->play(this->highlightSoundUrl_); + QUrl soundUrl; + if (customSoundUrl) + { + soundUrl = *customSoundUrl; + } + else + { + soundUrl = getFallbackHighlightSound(); + } + getIApp()->getSound()->play(soundUrl); } - if (this->highlightAlert_) + if (windowAlert) { getApp()->windows->sendAlert(); } diff --git a/src/messages/SharedMessageBuilder.hpp b/src/messages/SharedMessageBuilder.hpp index 5dce1ad9f95..6d4cf6d4bf5 100644 --- a/src/messages/SharedMessageBuilder.hpp +++ b/src/messages/SharedMessageBuilder.hpp @@ -57,6 +57,9 @@ class SharedMessageBuilder : public MessageBuilder // parseHighlights only updates the visual state of the message, but leaves the playing of alerts and sounds to the triggerHighlights function virtual void parseHighlights(); + static void triggerHighlights(const QString &channelName, bool playSound, + const std::optional &customSoundUrl, + bool windowAlert); void appendChannelName(); diff --git a/src/providers/twitch/TwitchMessageBuilder.cpp b/src/providers/twitch/TwitchMessageBuilder.cpp index 8ef6bcc66e2..b453f0b7ad6 100644 --- a/src/providers/twitch/TwitchMessageBuilder.cpp +++ b/src/providers/twitch/TwitchMessageBuilder.cpp @@ -5,6 +5,7 @@ #include "common/Literals.hpp" #include "common/QLogging.hpp" #include "controllers/accounts/AccountController.hpp" +#include "controllers/highlights/HighlightController.hpp" #include "controllers/ignores/IgnoreController.hpp" #include "controllers/ignores/IgnorePhrase.hpp" #include "controllers/userdata/UserDataController.hpp" @@ -1765,6 +1766,169 @@ MessagePtr TwitchMessageBuilder::buildHypeChatMessage( return builder.release(); } +EmotePtr makeAutoModBadge() +{ + return std::make_shared(Emote{ + EmoteName{}, + ImageSet{Image::fromResourcePixmap(getResources().twitch.automod)}, + Tooltip{"AutoMod"}, + Url{"https://dashboard.twitch.tv/settings/moderation/automod"}}); +} + +MessagePtr TwitchMessageBuilder::makeAutomodInfoMessage( + const AutomodInfoAction &action) +{ + auto builder = MessageBuilder(); + QString text("AutoMod: "); + + builder.emplace(); + builder.message().flags.set(MessageFlag::PubSub); + + // AutoMod shield badge + builder.emplace(makeAutoModBadge(), + MessageElementFlag::BadgeChannelAuthority); + // AutoMod "username" + builder.emplace("AutoMod:", MessageElementFlag::BoldUsername, + MessageColor(QColor("blue")), + FontStyle::ChatMediumBold); + builder.emplace( + "AutoMod:", MessageElementFlag::NonBoldUsername, + MessageColor(QColor("blue"))); + switch (action.type) + { + case AutomodInfoAction::OnHold: { + QString info("Hey! Your message is being checked " + "by mods and has not been sent."); + text += info; + builder.emplace(info, MessageElementFlag::Text, + MessageColor::Text); + } + break; + case AutomodInfoAction::Denied: { + QString info("Mods have removed your message."); + text += info; + builder.emplace(info, MessageElementFlag::Text, + MessageColor::Text); + } + break; + case AutomodInfoAction::Approved: { + QString info("Mods have accepted your message."); + text += info; + builder.emplace(info, MessageElementFlag::Text, + MessageColor::Text); + } + break; + } + + builder.message().flags.set(MessageFlag::AutoMod); + builder.message().messageText = text; + builder.message().searchText = text; + + auto message = builder.release(); + + return message; +} + +std::pair TwitchMessageBuilder::makeAutomodMessage( + const AutomodAction &action, const QString &channelName) +{ + MessageBuilder builder, builder2; + + // + // Builder for AutoMod message with explanation + builder.message().loginName = "automod"; + builder.message().channelName = channelName; + builder.message().flags.set(MessageFlag::PubSub); + builder.message().flags.set(MessageFlag::Timeout); + builder.message().flags.set(MessageFlag::AutoMod); + + // AutoMod shield badge + builder.emplace(makeAutoModBadge(), + MessageElementFlag::BadgeChannelAuthority); + // AutoMod "username" + builder.emplace("AutoMod:", MessageElementFlag::BoldUsername, + MessageColor(QColor("blue")), + FontStyle::ChatMediumBold); + builder.emplace( + "AutoMod:", MessageElementFlag::NonBoldUsername, + MessageColor(QColor("blue"))); + // AutoMod header message + builder.emplace( + ("Held a message for reason: " + action.reason + + ". Allow will post it in chat. "), + MessageElementFlag::Text, MessageColor::Text); + // Allow link button + builder + .emplace("Allow", MessageElementFlag::Text, + MessageColor(QColor("green")), + FontStyle::ChatMediumBold) + ->setLink({Link::AutoModAllow, action.msgID}); + // Deny link button + builder + .emplace(" Deny", MessageElementFlag::Text, + MessageColor(QColor("red")), + FontStyle::ChatMediumBold) + ->setLink({Link::AutoModDeny, action.msgID}); + // ID of message caught by AutoMod + // builder.emplace(action.msgID, MessageElementFlag::Text, + // MessageColor::Text); + auto text1 = + QString("AutoMod: Held a message for reason: %1. Allow will post " + "it in chat. Allow Deny") + .arg(action.reason); + builder.message().messageText = text1; + builder.message().searchText = text1; + + auto message1 = builder.release(); + + // + // Builder for offender's message + builder2.message().channelName = channelName; + builder2 + .emplace("#" + channelName, + MessageElementFlag::ChannelName, + MessageColor::System) + ->setLink({Link::JumpToChannel, channelName}); + builder2.emplace(); + builder2.emplace(); + builder2.message().loginName = action.target.login; + builder2.message().flags.set(MessageFlag::PubSub); + builder2.message().flags.set(MessageFlag::Timeout); + builder2.message().flags.set(MessageFlag::AutoMod); + + // sender username + builder2 + .emplace( + action.target.displayName + ":", MessageElementFlag::BoldUsername, + MessageColor(action.target.color), FontStyle::ChatMediumBold) + ->setLink({Link::UserInfo, action.target.login}); + builder2 + .emplace(action.target.displayName + ":", + MessageElementFlag::NonBoldUsername, + MessageColor(action.target.color)) + ->setLink({Link::UserInfo, action.target.login}); + // sender's message caught by AutoMod + builder2.emplace(action.message, MessageElementFlag::Text, + MessageColor::Text); + auto text2 = + QString("%1: %2").arg(action.target.displayName, action.message); + builder2.message().messageText = text2; + builder2.message().searchText = text2; + + auto message2 = builder2.release(); + + auto [highlighted, highlightResult] = getIApp()->getHighlights()->check( + {}, {}, action.target.login, action.message, message2->flags); + if (highlighted) + { + SharedMessageBuilder::triggerHighlights( + channelName, highlightResult.playSound, + highlightResult.customSoundUrl, highlightResult.alert); + } + + return std::make_pair(message1, message2); +} + void TwitchMessageBuilder::setThread(std::shared_ptr thread) { this->thread_ = std::move(thread); diff --git a/src/providers/twitch/TwitchMessageBuilder.hpp b/src/providers/twitch/TwitchMessageBuilder.hpp index cc1681acb1b..92f4dc3fc6b 100644 --- a/src/providers/twitch/TwitchMessageBuilder.hpp +++ b/src/providers/twitch/TwitchMessageBuilder.hpp @@ -89,6 +89,10 @@ class TwitchMessageBuilder : public SharedMessageBuilder static MessagePtr buildHypeChatMessage(Communi::IrcPrivateMessage *message); + static std::pair makeAutomodMessage( + const AutomodAction &action, const QString &channelName); + static MessagePtr makeAutomodInfoMessage(const AutomodInfoAction &action); + // Shares some common logic from SharedMessageBuilder::parseBadgeTag static std::unordered_map parseBadgeInfoTag( const QVariantMap &tags); From df7b5c4569826b3a3e8e0d5b99970683d7b1b1f6 Mon Sep 17 00:00:00 2001 From: iProdigy Date: Sun, 24 Dec 2023 21:00:08 -0800 Subject: [PATCH 06/19] chore: include std optional --- src/messages/SharedMessageBuilder.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/messages/SharedMessageBuilder.cpp b/src/messages/SharedMessageBuilder.cpp index ca8d9d88700..f9ae3f389e4 100644 --- a/src/messages/SharedMessageBuilder.cpp +++ b/src/messages/SharedMessageBuilder.cpp @@ -18,6 +18,8 @@ #include +#include + namespace { using namespace chatterino; From 45340609847515ad98f8a613edc201f220c62c57 Mon Sep 17 00:00:00 2001 From: iProdigy <8106344+iProdigy@users.noreply.github.com> Date: Sun, 24 Dec 2023 21:08:16 -0800 Subject: [PATCH 07/19] chore: another optional include --- src/messages/SharedMessageBuilder.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/messages/SharedMessageBuilder.hpp b/src/messages/SharedMessageBuilder.hpp index 6d4cf6d4bf5..4c78a78aba8 100644 --- a/src/messages/SharedMessageBuilder.hpp +++ b/src/messages/SharedMessageBuilder.hpp @@ -8,6 +8,8 @@ #include #include +#include + namespace chatterino { class Badge; From 0db205be92755d9e685d64cdced487815dcc35e5 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Mon, 25 Dec 2023 12:24:38 +0100 Subject: [PATCH 08/19] nit: Flag the offending message & use that for highlights This allows us to rely on something other than the badges, in case we forward badges somehow later --- .../highlights/HighlightController.cpp | 18 ++++++++---------- src/messages/Message.hpp | 2 ++ src/providers/twitch/TwitchMessageBuilder.cpp | 1 + 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/controllers/highlights/HighlightController.cpp b/src/controllers/highlights/HighlightController.cpp index 11b577a9657..e4a2f412013 100644 --- a/src/controllers/highlights/HighlightController.cpp +++ b/src/controllers/highlights/HighlightController.cpp @@ -215,19 +215,17 @@ void rebuildMessageHighlights(Settings &settings, settings.automodHighlightSoundUrl.getValue(); checks.emplace_back(HighlightCheck{ - [=](const auto & /*args*/, const auto &badges, + [=](const auto & /*args*/, const auto & /*badges*/, const auto & /*senderName*/, const auto & /*originalMessage*/, const auto &flags, const auto /*self*/) -> std::optional { - if (!flags.has(MessageFlag::AutoMod)) + if (!flags.has(MessageFlag::AutoModOffendingMessage)) { return std::nullopt; } - const auto offender = badges.empty(); - std::optional highlightSoundUrl; - if (offender && !highlightSoundUrlValue.isEmpty()) + if (!highlightSoundUrlValue.isEmpty()) { highlightSoundUrl = highlightSoundUrlValue; } @@ -236,11 +234,11 @@ void rebuildMessageHighlights(Settings &settings, ColorType::AutomodHighlight); return HighlightResult{ - highlightAlert && offender, // alert - highlightSound && offender, // playSound - highlightSoundUrl, // customSoundUrl - highlightColor, // color - false, // showInMentions + highlightAlert, // alert + highlightSound, // playSound + highlightSoundUrl, // customSoundUrl + highlightColor, // color + false, // showInMentions }; }}); } diff --git a/src/messages/Message.hpp b/src/messages/Message.hpp index a503ea2757a..88d0d09345c 100644 --- a/src/messages/Message.hpp +++ b/src/messages/Message.hpp @@ -50,6 +50,8 @@ enum class MessageFlag : int64_t { LiveUpdatesAdd = (1LL << 28), LiveUpdatesRemove = (1LL << 29), LiveUpdatesUpdate = (1LL << 30), + /// The message caught by AutoMod containing the user who sent the message & its contents + AutoModOffendingMessage = (1LL << 31), }; using MessageFlags = FlagsEnum; diff --git a/src/providers/twitch/TwitchMessageBuilder.cpp b/src/providers/twitch/TwitchMessageBuilder.cpp index b453f0b7ad6..d665042f9ee 100644 --- a/src/providers/twitch/TwitchMessageBuilder.cpp +++ b/src/providers/twitch/TwitchMessageBuilder.cpp @@ -1895,6 +1895,7 @@ std::pair TwitchMessageBuilder::makeAutomodMessage( builder2.message().flags.set(MessageFlag::PubSub); builder2.message().flags.set(MessageFlag::Timeout); builder2.message().flags.set(MessageFlag::AutoMod); + builder2.message().flags.set(MessageFlag::AutoModOffendingMessage); // sender username builder2 From d80f1021ca77d8445de15a08bab7c5232c0c6633 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Mon, 25 Dec 2023 13:22:08 +0100 Subject: [PATCH 09/19] nit: move fallback sound logic to the static triggerHighlights method --- src/messages/SharedMessageBuilder.cpp | 13 +++---------- src/messages/SharedMessageBuilder.hpp | 3 +-- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/src/messages/SharedMessageBuilder.cpp b/src/messages/SharedMessageBuilder.cpp index f9ae3f389e4..bb02dce0e50 100644 --- a/src/messages/SharedMessageBuilder.cpp +++ b/src/messages/SharedMessageBuilder.cpp @@ -172,18 +172,10 @@ void SharedMessageBuilder::parseHighlights() this->highlightAlert_ = highlightResult.alert; this->highlightSound_ = highlightResult.playSound; + this->highlightSoundCustomUrl_ = highlightResult.customSoundUrl; this->message().highlightColor = highlightResult.color; - if (highlightResult.customSoundUrl) - { - this->highlightSoundUrl_ = *highlightResult.customSoundUrl; - } - else - { - this->highlightSoundUrl_ = getFallbackHighlightSound(); - } - if (highlightResult.showInMentions) { this->message().flags.set(MessageFlag::ShowInMentions); @@ -203,7 +195,7 @@ void SharedMessageBuilder::appendChannelName() void SharedMessageBuilder::triggerHighlights() { triggerHighlights(this->channel->getName(), this->highlightSound_, - this->highlightSoundUrl_, this->highlightAlert_); + this->highlightSoundCustomUrl_, this->highlightAlert_); } void SharedMessageBuilder::triggerHighlights( @@ -228,6 +220,7 @@ void SharedMessageBuilder::triggerHighlights( if (playSound && resolveFocus) { + // TODO(C++23): optional or_else QUrl soundUrl; if (customSoundUrl) { diff --git a/src/messages/SharedMessageBuilder.hpp b/src/messages/SharedMessageBuilder.hpp index 4c78a78aba8..b6e99e61bca 100644 --- a/src/messages/SharedMessageBuilder.hpp +++ b/src/messages/SharedMessageBuilder.hpp @@ -77,8 +77,7 @@ class SharedMessageBuilder : public MessageBuilder bool highlightAlert_ = false; bool highlightSound_ = false; - - QUrl highlightSoundUrl_; + std::optional highlightSoundCustomUrl_{}; }; } // namespace chatterino From bf2f7b0bc4db0656246819b91d3aecf1209d1f52 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Mon, 25 Dec 2023 13:23:03 +0100 Subject: [PATCH 10/19] nit: Call `triggerHighlights` like a static method --- src/messages/SharedMessageBuilder.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/messages/SharedMessageBuilder.cpp b/src/messages/SharedMessageBuilder.cpp index bb02dce0e50..addeb05b8a3 100644 --- a/src/messages/SharedMessageBuilder.cpp +++ b/src/messages/SharedMessageBuilder.cpp @@ -194,8 +194,9 @@ void SharedMessageBuilder::appendChannelName() void SharedMessageBuilder::triggerHighlights() { - triggerHighlights(this->channel->getName(), this->highlightSound_, - this->highlightSoundCustomUrl_, this->highlightAlert_); + SharedMessageBuilder::triggerHighlights( + this->channel->getName(), this->highlightSound_, + this->highlightSoundCustomUrl_, this->highlightAlert_); } void SharedMessageBuilder::triggerHighlights( From 64c2e957b5075d301280f96060da6f3c9cc6ff46 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Mon, 25 Dec 2023 13:25:28 +0100 Subject: [PATCH 11/19] Add comment explaining our weird way to use triggerHighlights --- src/providers/twitch/TwitchMessageBuilder.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/providers/twitch/TwitchMessageBuilder.cpp b/src/providers/twitch/TwitchMessageBuilder.cpp index d665042f9ee..e5f003a05a3 100644 --- a/src/providers/twitch/TwitchMessageBuilder.cpp +++ b/src/providers/twitch/TwitchMessageBuilder.cpp @@ -1918,6 +1918,9 @@ std::pair TwitchMessageBuilder::makeAutomodMessage( auto message2 = builder2.release(); + // Normally highlights would be checked & triggered during the builder parse steps + // and when the message is added to the channel + // We do this a bit weird since the message comes in from PubSub and not the normal message route auto [highlighted, highlightResult] = getIApp()->getHighlights()->check( {}, {}, action.target.login, action.message, message2->flags); if (highlighted) From 7b8d5c6519adec21e33a05de47267e0a2b627b86 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Mon, 25 Dec 2023 13:34:23 +0100 Subject: [PATCH 12/19] nit: settings reformat --- src/singletons/Settings.hpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/singletons/Settings.hpp b/src/singletons/Settings.hpp index 138e10c3f30..3c112454218 100644 --- a/src/singletons/Settings.hpp +++ b/src/singletons/Settings.hpp @@ -376,15 +376,25 @@ class Settings QStringSetting subHighlightColor = {"/highlighting/subHighlightColor", ""}; BoolSetting enableAutomodHighlight = { - "/highlighting/automodHighlight/automodHighlighted", true}; + "/highlighting/automodHighlight/automodHighlighted", + true, + }; BoolSetting enableAutomodHighlightSound = { - "/highlighting/automodHighlight/enableSound", false}; + "/highlighting/automodHighlight/enableSound", + false, + }; BoolSetting enableAutomodHighlightTaskbar = { - "/highlighting/automodHighlight/enableTaskbarFlashing", false}; + "/highlighting/automodHighlight/enableTaskbarFlashing", + false, + }; QStringSetting automodHighlightSoundUrl = { - "/highlighting/automodHighlightSoundUrl", ""}; + "/highlighting/automodHighlightSoundUrl", + "", + }; QStringSetting automodHighlightColor = { - "/highlighting/automodHighlightColor", ""}; + "/highlighting/automodHighlightColor", + "", + }; BoolSetting enableThreadHighlight = { "/highlighting/thread/nameIsHighlightKeyword", true}; From 1e163ddce9befc6ed2ec611a333fd263eae2224c Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Mon, 25 Dec 2023 13:34:33 +0100 Subject: [PATCH 13/19] nit: settings key change everything is now under `/highlighting/automodHighlight/` --- src/singletons/Settings.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/singletons/Settings.hpp b/src/singletons/Settings.hpp index 3c112454218..2af85506393 100644 --- a/src/singletons/Settings.hpp +++ b/src/singletons/Settings.hpp @@ -388,11 +388,11 @@ class Settings false, }; QStringSetting automodHighlightSoundUrl = { - "/highlighting/automodHighlightSoundUrl", + "/highlighting/automodHighlight/soundUrl", "", }; QStringSetting automodHighlightColor = { - "/highlighting/automodHighlightColor", + "/highlighting/automodHighlight/color", "", }; From 25c887fffb96c8fd43540fbe6cb41c3778b3e0b5 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Mon, 25 Dec 2023 13:43:16 +0100 Subject: [PATCH 14/19] nit2: change setting keys again --- src/singletons/Settings.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/singletons/Settings.hpp b/src/singletons/Settings.hpp index 2af85506393..e1b4502eb4c 100644 --- a/src/singletons/Settings.hpp +++ b/src/singletons/Settings.hpp @@ -376,7 +376,7 @@ class Settings QStringSetting subHighlightColor = {"/highlighting/subHighlightColor", ""}; BoolSetting enableAutomodHighlight = { - "/highlighting/automodHighlight/automodHighlighted", + "/highlighting/automodHighlight/enabled", true, }; BoolSetting enableAutomodHighlightSound = { From 63a9b500647b7fa96753a44b5f5491bd948b130f Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Mon, 25 Dec 2023 13:52:32 +0100 Subject: [PATCH 15/19] nit3: another setting key change --- src/singletons/Settings.hpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/singletons/Settings.hpp b/src/singletons/Settings.hpp index e1b4502eb4c..c097e384a76 100644 --- a/src/singletons/Settings.hpp +++ b/src/singletons/Settings.hpp @@ -376,23 +376,23 @@ class Settings QStringSetting subHighlightColor = {"/highlighting/subHighlightColor", ""}; BoolSetting enableAutomodHighlight = { - "/highlighting/automodHighlight/enabled", + "/highlighting/automod/enabled", true, }; BoolSetting enableAutomodHighlightSound = { - "/highlighting/automodHighlight/enableSound", + "/highlighting/automod/enableSound", false, }; BoolSetting enableAutomodHighlightTaskbar = { - "/highlighting/automodHighlight/enableTaskbarFlashing", + "/highlighting/automod/enableTaskbarFlashing", false, }; QStringSetting automodHighlightSoundUrl = { - "/highlighting/automodHighlight/soundUrl", + "/highlighting/automod/soundUrl", "", }; QStringSetting automodHighlightColor = { - "/highlighting/automodHighlight/color", + "/highlighting/automod/color", "", }; From c2431158bf82126fd15494ac308c6e7ed14aa36d Mon Sep 17 00:00:00 2001 From: iProdigy Date: Mon, 25 Dec 2023 14:09:31 -0800 Subject: [PATCH 16/19] chore: remove scrollbar highlight color --- .../highlights/HighlightController.cpp | 5 +---- src/controllers/highlights/HighlightModel.cpp | 11 +---------- src/controllers/highlights/HighlightPhrase.cpp | 2 -- src/controllers/highlights/HighlightPhrase.hpp | 1 - src/messages/Message.cpp | 8 -------- src/providers/colors/ColorProvider.cpp | 17 ----------------- src/providers/colors/ColorProvider.hpp | 1 - src/singletons/Settings.hpp | 4 ---- src/widgets/helper/ChannelView.cpp | 3 +-- 9 files changed, 3 insertions(+), 49 deletions(-) diff --git a/src/controllers/highlights/HighlightController.cpp b/src/controllers/highlights/HighlightController.cpp index e4a2f412013..9dee5504712 100644 --- a/src/controllers/highlights/HighlightController.cpp +++ b/src/controllers/highlights/HighlightController.cpp @@ -230,14 +230,11 @@ void rebuildMessageHighlights(Settings &settings, highlightSoundUrl = highlightSoundUrlValue; } - const auto highlightColor = ColorProvider::instance().color( - ColorType::AutomodHighlight); - return HighlightResult{ highlightAlert, // alert highlightSound, // playSound highlightSoundUrl, // customSoundUrl - highlightColor, // color + nullptr, // color false, // showInMentions }; }}); diff --git a/src/controllers/highlights/HighlightModel.cpp b/src/controllers/highlights/HighlightModel.cpp index 4ac4ea4ddee..d7b76adf347 100644 --- a/src/controllers/highlights/HighlightModel.cpp +++ b/src/controllers/highlights/HighlightModel.cpp @@ -255,9 +255,7 @@ void HighlightModel::afterInit() QUrl(getSettings()->automodHighlightSoundUrl.getValue()); setFilePathItem(automodRow[Column::SoundPath], automodSound, false); - const auto automodMessageColor = - ColorProvider::instance().color(ColorType::AutomodHighlight); - setColorItem(automodRow[Column::Color], *automodMessageColor, false); + automodRow[Column::Color]->setFlags(Qt::ItemFlag::NoItemFlags); this->insertCustomRow(automodRow, HighlightRowIndexes::AutomodRow); } @@ -508,13 +506,6 @@ void HighlightModel::customRowSetData(const std::vector &row, .updateColor(ColorType::ThreadMessageHighlight, QColor(colorName)); } - else if (rowIndex == HighlightRowIndexes::AutomodRow) - { - getSettings()->automodHighlightColor.setValue(colorName); - const_cast(ColorProvider::instance()) - .updateColor(ColorType::AutomodHighlight, - QColor(colorName)); - } } } break; diff --git a/src/controllers/highlights/HighlightPhrase.cpp b/src/controllers/highlights/HighlightPhrase.cpp index 5f86f2ef987..c8963e59c39 100644 --- a/src/controllers/highlights/HighlightPhrase.cpp +++ b/src/controllers/highlights/HighlightPhrase.cpp @@ -20,8 +20,6 @@ QColor HighlightPhrase::FALLBACK_ELEVATED_MESSAGE_HIGHLIGHT_COLOR = QColor(255, 174, 66, 60); QColor HighlightPhrase::FALLBACK_THREAD_HIGHLIGHT_COLOR = QColor(143, 48, 24, 60); -QColor HighlightPhrase::FALLBACK_AUTOMOD_HIGHLIGHT_COLOR = - QColor(0, 255, 3, 100); QColor HighlightPhrase::FALLBACK_SUB_COLOR = QColor(196, 102, 255, 100); bool HighlightPhrase::operator==(const HighlightPhrase &other) const diff --git a/src/controllers/highlights/HighlightPhrase.hpp b/src/controllers/highlights/HighlightPhrase.hpp index fab0ecd98aa..56d3499ccb9 100644 --- a/src/controllers/highlights/HighlightPhrase.hpp +++ b/src/controllers/highlights/HighlightPhrase.hpp @@ -86,7 +86,6 @@ class HighlightPhrase 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 01d26cd9d4f..73f8ccde038 100644 --- a/src/messages/Message.cpp +++ b/src/messages/Message.cpp @@ -69,14 +69,6 @@ ScrollbarHighlight Message::getScrollBarHighlight() const }; } - if (this->flags.has(MessageFlag::AutoMod) && - getSettings()->enableAutomodHighlight) - { - return { - ColorProvider::instance().color(ColorType::AutomodHighlight), - }; - } - return {}; } diff --git a/src/providers/colors/ColorProvider.cpp b/src/providers/colors/ColorProvider.cpp index 66deee169bc..fbda9c6ee79 100644 --- a/src/providers/colors/ColorProvider.cpp +++ b/src/providers/colors/ColorProvider.cpp @@ -51,7 +51,6 @@ QSet ColorProvider::recentColors() const } // Insert preset highlight colors - retVal.insert(*this->color(ColorType::AutomodHighlight)); retVal.insert(*this->color(ColorType::SelfHighlight)); retVal.insert(*this->color(ColorType::Subscription)); retVal.insert(*this->color(ColorType::Whisper)); @@ -179,20 +178,6 @@ void ColorProvider::initTypeColorMap() std::make_shared( HighlightPhrase::FALLBACK_THREAD_HIGHLIGHT_COLOR)}); } - - customColor = getSettings()->automodHighlightColor; - if (QColor(customColor).isValid()) - { - this->typeColorMap_.insert({ColorType::AutomodHighlight, - std::make_shared(customColor)}); - } - else - { - this->typeColorMap_.insert( - {ColorType::AutomodHighlight, - std::make_shared( - HighlightPhrase::FALLBACK_AUTOMOD_HIGHLIGHT_COLOR)}); - } } void ColorProvider::initDefaultColors() @@ -211,8 +196,6 @@ void ColorProvider::initDefaultColors() this->defaultColors_.push_back(HighlightPhrase::FALLBACK_HIGHLIGHT_COLOR); this->defaultColors_.push_back(HighlightPhrase::FALLBACK_SUB_COLOR); - this->defaultColors_.push_back( - HighlightPhrase::FALLBACK_AUTOMOD_HIGHLIGHT_COLOR); } } // namespace chatterino diff --git a/src/providers/colors/ColorProvider.hpp b/src/providers/colors/ColorProvider.hpp index 0c7b094fd21..12745371d1e 100644 --- a/src/providers/colors/ColorProvider.hpp +++ b/src/providers/colors/ColorProvider.hpp @@ -12,7 +12,6 @@ enum class ColorType { SelfHighlight, Subscription, Whisper, - AutomodHighlight, RedeemedHighlight, FirstMessageHighlight, ElevatedMessageHighlight, diff --git a/src/singletons/Settings.hpp b/src/singletons/Settings.hpp index c097e384a76..c66fcb2187d 100644 --- a/src/singletons/Settings.hpp +++ b/src/singletons/Settings.hpp @@ -391,10 +391,6 @@ class Settings "/highlighting/automod/soundUrl", "", }; - QStringSetting automodHighlightColor = { - "/highlighting/automod/color", - "", - }; BoolSetting enableThreadHighlight = { "/highlighting/thread/nameIsHighlightKeyword", true}; diff --git a/src/widgets/helper/ChannelView.cpp b/src/widgets/helper/ChannelView.cpp index 853ea08ff00..2d7c9765b78 100644 --- a/src/widgets/helper/ChannelView.cpp +++ b/src/widgets/helper/ChannelView.cpp @@ -825,8 +825,7 @@ ChannelPtr ChannelView::channel() bool ChannelView::showScrollbarHighlights() const { - return this->channel_->getType() != Channel::Type::TwitchMentions && - this->channel_->getType() != Channel::Type::TwitchAutomod; + return this->channel_->getType() != Channel::Type::TwitchMentions; } void ChannelView::setChannel(const ChannelPtr &underlyingChannel) From 5a40a9ca715cf74ac82a18de7b2901a0ab621d54 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Mon, 25 Dec 2023 23:39:12 +0100 Subject: [PATCH 17/19] highlighting: Disable sound & color dialog on all cells that are disabled --- src/widgets/settingspages/HighlightingPage.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/widgets/settingspages/HighlightingPage.cpp b/src/widgets/settingspages/HighlightingPage.cpp index 1b6e61f7305..fbad47561cf 100644 --- a/src/widgets/settingspages/HighlightingPage.cpp +++ b/src/widgets/settingspages/HighlightingPage.cpp @@ -370,21 +370,22 @@ void HighlightingPage::tableCellClicked(const QModelIndex &clicked, EditableModelView *view, HighlightTab tab) { + if (!clicked.flags().testFlag(Qt::ItemIsEnabled)) + { + return; + } + switch (tab) { case HighlightTab::Messages: case HighlightTab::Users: { using Column = HighlightModel::Column; - bool restrictColorRow = - (tab == HighlightTab::Messages && - clicked.row() == - HighlightModel::HighlightRowIndexes::WhisperRow); - if (clicked.column() == Column::SoundPath && - clicked.flags().testFlag(Qt::ItemIsEnabled)) + + if (clicked.column() == Column::SoundPath) { this->openSoundDialog(clicked, view, Column::SoundPath); } - else if (clicked.column() == Column::Color && !restrictColorRow) + else if (clicked.column() == Column::Color) { this->openColorDialog(clicked, view, tab); } From dfa1496b7198db305d94da1ed30259cbdc0902fd Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Mon, 25 Dec 2023 23:59:17 +0100 Subject: [PATCH 18/19] Assert/check message highlightColor --- src/messages/layouts/MessageLayout.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/messages/layouts/MessageLayout.cpp b/src/messages/layouts/MessageLayout.cpp index 160ea51ca5b..0e8228485e9 100644 --- a/src/messages/layouts/MessageLayout.cpp +++ b/src/messages/layouts/MessageLayout.cpp @@ -342,9 +342,13 @@ void MessageLayout::updateBuffer(QPixmap *buffer, this->message_->flags.has(MessageFlag::HighlightedWhisper)) && !this->flags.has(MessageLayoutFlag::IgnoreHighlights)) { - // Blend highlight color with usual background color - backgroundColor = - blendColors(backgroundColor, *this->message_->highlightColor); + assert(this->message_->highlightColor); + if (this->message_->highlightColor) + { + // Blend highlight color with usual background color + backgroundColor = + blendColors(backgroundColor, *this->message_->highlightColor); + } } else if (this->message_->flags.has(MessageFlag::Subscription) && ctx.preferences.enableSubHighlight) From dfaee6ac9d3d40b2aed4b5a9c4726c88bb819e87 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Tue, 26 Dec 2023 00:01:20 +0100 Subject: [PATCH 19/19] another color assert --- src/widgets/helper/ScrollbarHighlight.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/widgets/helper/ScrollbarHighlight.cpp b/src/widgets/helper/ScrollbarHighlight.cpp index efd50e43db1..5216f2d66b7 100644 --- a/src/widgets/helper/ScrollbarHighlight.cpp +++ b/src/widgets/helper/ScrollbarHighlight.cpp @@ -26,6 +26,7 @@ ScrollbarHighlight::ScrollbarHighlight(const std::shared_ptr color, QColor ScrollbarHighlight::getColor() const { + assert(this->color_); return *this->color_; }