diff --git a/CHANGELOG.md b/CHANGELOG.md index fd9a054f3..3103bd206 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Unversioned - Major: Added live emote updates for BTTV (#4147) +- Minor: Added option to highlight your own messages in Highlights page under Users tab. (#3833) - Minor: Change the highlight order to prioritize Message highlights over User highlights. (#4303) - Minor: Added ability to negate search options by prefixing it with an exclamation mark (e.g. `!badge:mod` to search for messages where the author does not have the moderator badge). (#4207) - Minor: Search window input will automatically use currently selected text if present. (#4178) diff --git a/src/controllers/highlights/HighlightController.cpp b/src/controllers/highlights/HighlightController.cpp index 6e94ebdca..bd517863f 100644 --- a/src/controllers/highlights/HighlightController.cpp +++ b/src/controllers/highlights/HighlightController.cpp @@ -210,6 +210,35 @@ void rebuildUserHighlights(Settings &settings, { auto userHighlights = settings.highlightedUsers.readOnly(); + if (settings.enableSelfMessageHighlight) + { + bool showInMentions = settings.showSelfMessageHighlightInMentions; + + checks.emplace_back(HighlightCheck{ + [showInMentions]( + const auto &args, const auto &badges, const auto &senderName, + const auto &originalMessage, const auto &flags, + const auto self) -> boost::optional { + (void)args; //unused + (void)badges; //unused + (void)senderName; //unused + (void)flags; //unused + (void)originalMessage; //unused + + if (!self) + { + return boost::none; + } + + // Highlight color is provided by the ColorProvider and will be updated accordingly + auto highlightColor = ColorProvider::instance().color( + ColorType::SelfMessageHighlight); + + return HighlightResult{false, false, (QUrl) nullptr, + highlightColor, showInMentions}; + }}); + } + for (const auto &highlight : *userHighlights) { checks.emplace_back(HighlightCheck{ @@ -391,6 +420,11 @@ void HighlightController::initialize(Settings &settings, Paths & /*paths*/) this->rebuildListener_.addSetting(settings.enableSubHighlight); this->rebuildListener_.addSetting(settings.enableSubHighlightSound); this->rebuildListener_.addSetting(settings.enableSubHighlightTaskbar); + this->rebuildListener_.addSetting(settings.enableSelfMessageHighlight); + this->rebuildListener_.addSetting( + settings.showSelfMessageHighlightInMentions); + // We do not need to rebuild the listener for the selfMessagesHighlightColor + // The color is dynamically fetched any time the self message highlight is triggered this->rebuildListener_.addSetting(settings.subHighlightSoundUrl); this->rebuildListener_.addSetting(settings.enableThreadHighlight); diff --git a/src/controllers/highlights/HighlightModel.hpp b/src/controllers/highlights/HighlightModel.hpp index 7f20a9c6c..4966950a1 100644 --- a/src/controllers/highlights/HighlightModel.hpp +++ b/src/controllers/highlights/HighlightModel.hpp @@ -36,6 +36,10 @@ public: ThreadMessageRow = 6, }; + enum UserHighlightRowIndexes { + SelfMessageRow = 0, + }; + protected: // turn a vector item into a model row virtual HighlightPhrase getItemFromRow( diff --git a/src/controllers/highlights/HighlightPhrase.cpp b/src/controllers/highlights/HighlightPhrase.cpp index d7b20e16f..c8963e59c 100644 --- a/src/controllers/highlights/HighlightPhrase.cpp +++ b/src/controllers/highlights/HighlightPhrase.cpp @@ -10,6 +10,8 @@ namespace { } // namespace QColor HighlightPhrase::FALLBACK_HIGHLIGHT_COLOR = QColor(127, 63, 73, 127); +QColor HighlightPhrase::FALLBACK_SELF_MESSAGE_HIGHLIGHT_COLOR = + QColor(0, 118, 221, 115); QColor HighlightPhrase::FALLBACK_REDEEMED_HIGHLIGHT_COLOR = QColor(28, 126, 141, 60); QColor HighlightPhrase::FALLBACK_FIRST_MESSAGE_HIGHLIGHT_COLOR = diff --git a/src/controllers/highlights/HighlightPhrase.hpp b/src/controllers/highlights/HighlightPhrase.hpp index 392f13e28..56d3499cc 100644 --- a/src/controllers/highlights/HighlightPhrase.hpp +++ b/src/controllers/highlights/HighlightPhrase.hpp @@ -79,6 +79,8 @@ public: * Qt>=5.13. */ static QColor FALLBACK_HIGHLIGHT_COLOR; + // Used for automatic self messages highlighing + static QColor FALLBACK_SELF_MESSAGE_HIGHLIGHT_COLOR; static QColor FALLBACK_REDEEMED_HIGHLIGHT_COLOR; static QColor FALLBACK_SUB_COLOR; static QColor FALLBACK_FIRST_MESSAGE_HIGHLIGHT_COLOR; diff --git a/src/controllers/highlights/UserHighlightModel.cpp b/src/controllers/highlights/UserHighlightModel.cpp index 42aeb819f..15ca70163 100644 --- a/src/controllers/highlights/UserHighlightModel.cpp +++ b/src/controllers/highlights/UserHighlightModel.cpp @@ -3,7 +3,9 @@ #include "Application.hpp" #include "controllers/highlights/HighlightModel.hpp" #include "controllers/highlights/HighlightPhrase.hpp" +#include "providers/colors/ColorProvider.hpp" #include "singletons/Settings.hpp" +#include "singletons/WindowManager.hpp" #include "util/StandardItemHelper.hpp" namespace chatterino { @@ -37,6 +39,86 @@ HighlightPhrase UserHighlightModel::getItemFromRow( highlightColor}; } +void UserHighlightModel::afterInit() +{ + // User highlight settings for your own messages + std::vector messagesRow = this->createRow(); + setBoolItem(messagesRow[Column::Pattern], + getSettings()->enableSelfMessageHighlight.getValue(), true, + false); + messagesRow[Column::Pattern]->setData("Your messages (automatic)", + Qt::DisplayRole); + setBoolItem(messagesRow[Column::ShowInMentions], + getSettings()->showSelfMessageHighlightInMentions.getValue(), + true, false); + messagesRow[Column::FlashTaskbar]->setFlags({}); + messagesRow[Column::PlaySound]->setFlags({}); + messagesRow[Column::UseRegex]->setFlags({}); + messagesRow[Column::CaseSensitive]->setFlags({}); + messagesRow[Column::SoundPath]->setFlags({}); + + auto selfColor = + ColorProvider::instance().color(ColorType::SelfMessageHighlight); + setColorItem(messagesRow[Column::Color], *selfColor, false); + + this->insertCustomRow( + messagesRow, HighlightModel::UserHighlightRowIndexes::SelfMessageRow); +} + +void UserHighlightModel::customRowSetData( + const std::vector &row, int column, const QVariant &value, + int role, int rowIndex) +{ + switch (column) + { + case Column::Pattern: { + if (role == Qt::CheckStateRole) + { + if (rowIndex == + HighlightModel::UserHighlightRowIndexes::SelfMessageRow) + { + getSettings()->enableSelfMessageHighlight.setValue( + value.toBool()); + } + } + } + break; + case Column::ShowInMentions: { + if (role == Qt::CheckStateRole) + { + if (rowIndex == + HighlightModel::UserHighlightRowIndexes::SelfMessageRow) + { + getSettings()->showSelfMessageHighlightInMentions.setValue( + value.toBool()); + } + } + } + break; + case Column::Color: { + // Custom color + if (role == Qt::DecorationRole) + { + auto colorName = value.value().name(QColor::HexArgb); + if (rowIndex == + HighlightModel::UserHighlightRowIndexes::SelfMessageRow) + { + // Update the setting with the new value + getSettings()->selfMessageHighlightColor.setValue( + colorName); + // Update the color provider with the new color to be used for future + const_cast(ColorProvider::instance()) + .updateColor(ColorType::SelfMessageHighlight, + QColor(colorName)); + } + } + } + break; + } + + getApp()->windows->forceLayoutChannelViews(); +} + // row into vector item void UserHighlightModel::getRowFromItem(const HighlightPhrase &item, std::vector &row) diff --git a/src/controllers/highlights/UserHighlightModel.hpp b/src/controllers/highlights/UserHighlightModel.hpp index fa2811ddc..928d4931d 100644 --- a/src/controllers/highlights/UserHighlightModel.hpp +++ b/src/controllers/highlights/UserHighlightModel.hpp @@ -22,6 +22,12 @@ protected: virtual void getRowFromItem(const HighlightPhrase &item, std::vector &row) override; + + virtual void afterInit() override; + + virtual void customRowSetData(const std::vector &row, + int column, const QVariant &value, int role, + int rowIndex) override; }; } // namespace chatterino diff --git a/src/providers/colors/ColorProvider.cpp b/src/providers/colors/ColorProvider.cpp index 94fb44451..5f47c2f68 100644 --- a/src/providers/colors/ColorProvider.cpp +++ b/src/providers/colors/ColorProvider.cpp @@ -81,6 +81,20 @@ void ColorProvider::initTypeColorMap() HighlightPhrase::FALLBACK_HIGHLIGHT_COLOR)}); } + customColor = getSettings()->selfMessageHighlightColor; + if (QColor(customColor).isValid()) + { + this->typeColorMap_.insert({ColorType::SelfMessageHighlight, + std::make_shared(customColor)}); + } + else + { + this->typeColorMap_.insert( + {ColorType::SelfMessageHighlight, + std::make_shared( + HighlightPhrase::FALLBACK_SELF_MESSAGE_HIGHLIGHT_COLOR)}); + } + customColor = getSettings()->subHighlightColor; if (QColor(customColor).isValid()) { diff --git a/src/providers/colors/ColorProvider.hpp b/src/providers/colors/ColorProvider.hpp index f6fdcde50..12745371d 100644 --- a/src/providers/colors/ColorProvider.hpp +++ b/src/providers/colors/ColorProvider.hpp @@ -16,6 +16,8 @@ enum class ColorType { FirstMessageHighlight, ElevatedMessageHighlight, ThreadMessageHighlight, + // Used in automatic highlights of your own messages + SelfMessageHighlight, }; class ColorProvider diff --git a/src/singletons/Settings.hpp b/src/singletons/Settings.hpp index cd10ce0ee..8b0b32f77 100644 --- a/src/singletons/Settings.hpp +++ b/src/singletons/Settings.hpp @@ -288,6 +288,13 @@ public: QStringSetting selfHighlightColor = {"/highlighting/selfHighlightColor", ""}; + BoolSetting enableSelfMessageHighlight = { + "/highlighting/selfMessageHighlight/enabled", false}; + BoolSetting showSelfMessageHighlightInMentions = { + "/highlighting/selfMessageHighlight/showInMentions", false}; + QStringSetting selfMessageHighlightColor = { + "/highlighting/selfMessageHighlight/color", ""}; + BoolSetting enableWhisperHighlight = { "/highlighting/whisperHighlight/whispersHighlighted", true}; BoolSetting enableWhisperHighlightSound = {