From 9816722b5e44058773246e1af34aada075159927 Mon Sep 17 00:00:00 2001 From: Felanbird <41973452+Felanbird@users.noreply.github.com> Date: Sun, 2 Oct 2022 07:25:10 -0400 Subject: [PATCH] Add `showInMentions` option for Badge Highlights (#4034) Co-authored-by: Rasmus Karlsson --- CHANGELOG.md | 1 + .../highlights/BadgeHighlightModel.cpp | 4 +- .../highlights/BadgeHighlightModel.hpp | 9 +++-- src/controllers/highlights/HighlightBadge.cpp | 31 +++++++++------ src/controllers/highlights/HighlightBadge.hpp | 20 ++++++---- .../highlights/HighlightController.cpp | 18 +++++---- .../settingspages/HighlightingPage.cpp | 13 ++++--- tests/src/HighlightController.cpp | 39 ++++++++++++++++++- 8 files changed, 97 insertions(+), 38 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 62c460398..f8ff6b93d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ - Minor: Added `subtier:` search option (e.g. `subtier:3` to find Tier 3 subs). (#4013) - Minor: Added `badge:` search option (e.g. `badge:mod` to users with the moderator badge). (#4013) - Minor: Added AutoMod message flag filter. (#3938) +- Minor: Added `showInMentions` toggle for Badge Highlights. (#4034) - Minor: Added chatter count for each category in viewer list. (#3683, #3719) - Minor: Added option to open a user's chat in a new tab from the usercard profile picture context menu. (#3625) - Minor: Added scrollbar to `Select filters` dialog. (#3737) diff --git a/src/controllers/highlights/BadgeHighlightModel.cpp b/src/controllers/highlights/BadgeHighlightModel.cpp index 9ea8a2f93..3e1c10a20 100644 --- a/src/controllers/highlights/BadgeHighlightModel.cpp +++ b/src/controllers/highlights/BadgeHighlightModel.cpp @@ -9,7 +9,7 @@ namespace chatterino { // commandmodel BadgeHighlightModel::BadgeHighlightModel(QObject *parent) - : SignalVectorModel(5, parent) + : SignalVectorModel(6, parent) { } @@ -28,6 +28,7 @@ HighlightBadge BadgeHighlightModel::getItemFromRow( return HighlightBadge{ original.badgeName(), row[Column::Badge]->data(Qt::DisplayRole).toString(), + row[Column::ShowInMentions]->data(Qt::CheckStateRole).toBool(), row[Column::FlashTaskbar]->data(Qt::CheckStateRole).toBool(), row[Column::PlaySound]->data(Qt::CheckStateRole).toBool(), row[Column::SoundPath]->data(Qt::UserRole).toString(), @@ -42,6 +43,7 @@ void BadgeHighlightModel::getRowFromItem(const HighlightBadge &item, using Column = BadgeHighlightModel::Column; setStringItem(row[Column::Badge], item.displayName(), false, true); + setBoolItem(row[Column::ShowInMentions], item.showInMentions()); setBoolItem(row[Column::FlashTaskbar], item.hasAlert()); setBoolItem(row[Column::PlaySound], item.hasSound()); setFilePathItem(row[Column::SoundPath], item.getSoundUrl()); diff --git a/src/controllers/highlights/BadgeHighlightModel.hpp b/src/controllers/highlights/BadgeHighlightModel.hpp index ffe77d310..3038b2eba 100644 --- a/src/controllers/highlights/BadgeHighlightModel.hpp +++ b/src/controllers/highlights/BadgeHighlightModel.hpp @@ -17,10 +17,11 @@ public: enum Column { Badge = 0, - FlashTaskbar = 1, - PlaySound = 2, - SoundPath = 3, - Color = 4 + ShowInMentions = 1, + FlashTaskbar = 2, + PlaySound = 3, + SoundPath = 4, + Color = 5 }; protected: diff --git a/src/controllers/highlights/HighlightBadge.cpp b/src/controllers/highlights/HighlightBadge.cpp index 8195cbd36..899b59c39 100644 --- a/src/controllers/highlights/HighlightBadge.cpp +++ b/src/controllers/highlights/HighlightBadge.cpp @@ -9,27 +9,31 @@ QColor HighlightBadge::FALLBACK_HIGHLIGHT_COLOR = QColor(127, 63, 73, 127); bool HighlightBadge::operator==(const HighlightBadge &other) const { - return std::tie(this->badgeName_, this->displayName_, this->hasSound_, - this->hasAlert_, this->soundUrl_, this->color_) == - std::tie(other.badgeName_, other.displayName_, other.hasSound_, - other.hasAlert_, other.soundUrl_, other.color_); + return std::tie(this->badgeName_, this->displayName_, this->showInMentions_, + this->hasSound_, this->hasAlert_, this->soundUrl_, + this->color_) == + std::tie(other.badgeName_, other.displayName_, other.showInMentions_, + other.hasSound_, other.hasAlert_, other.soundUrl_, + other.color_); } HighlightBadge::HighlightBadge(const QString &badgeName, - const QString &displayName, bool hasAlert, - bool hasSound, const QString &soundUrl, - QColor color) - : HighlightBadge(badgeName, displayName, hasAlert, hasSound, soundUrl, - std::make_shared(color)) + const QString &displayName, bool showInMentions, + bool hasAlert, bool hasSound, + const QString &soundUrl, QColor color) + : HighlightBadge(badgeName, displayName, showInMentions, hasAlert, hasSound, + soundUrl, std::make_shared(color)) { } HighlightBadge::HighlightBadge(const QString &badgeName, - const QString &displayName, bool hasAlert, - bool hasSound, const QString &soundUrl, + const QString &displayName, bool showInMentions, + bool hasAlert, bool hasSound, + const QString &soundUrl, std::shared_ptr color) : badgeName_(badgeName) , displayName_(displayName) + , showInMentions_(showInMentions) , hasAlert_(hasAlert) , hasSound_(hasSound) , soundUrl_(soundUrl) @@ -54,6 +58,11 @@ const QString &HighlightBadge::displayName() const return this->displayName_; } +bool HighlightBadge::showInMentions() const +{ + return this->showInMentions_; +} + bool HighlightBadge::hasAlert() const { return this->hasAlert_; diff --git a/src/controllers/highlights/HighlightBadge.hpp b/src/controllers/highlights/HighlightBadge.hpp index c3daf3045..d20cbe815 100644 --- a/src/controllers/highlights/HighlightBadge.hpp +++ b/src/controllers/highlights/HighlightBadge.hpp @@ -15,15 +15,16 @@ public: bool operator==(const HighlightBadge &other) const; HighlightBadge(const QString &badgeName, const QString &displayName, - bool hasAlert, bool hasSound, const QString &soundUrl, - QColor color); + bool showInMentions, bool hasAlert, bool hasSound, + const QString &soundUrl, QColor color); HighlightBadge(const QString &badgeName, const QString &displayName, - bool hasAlert, bool hasSound, const QString &soundUrl, - std::shared_ptr color); + bool showInMentions, bool hasAlert, bool hasSound, + const QString &soundUrl, std::shared_ptr color); const QString &badgeName() const; const QString &displayName() const; + bool showInMentions() const; bool hasAlert() const; bool hasSound() const; bool isMatch(const Badge &badge) const; @@ -53,6 +54,7 @@ private: QString badgeName_; QString displayName_; + bool showInMentions_; bool hasAlert_; bool hasSound_; QUrl soundUrl_; @@ -75,6 +77,7 @@ struct Serialize { chatterino::rj::set(ret, "name", value.badgeName(), a); chatterino::rj::set(ret, "displayName", value.displayName(), a); + chatterino::rj::set(ret, "showInMentions", value.showInMentions(), a); chatterino::rj::set(ret, "alert", value.hasAlert(), a); chatterino::rj::set(ret, "sound", value.hasSound(), a); chatterino::rj::set(ret, "soundUrl", value.getSoundUrl().toString(), a); @@ -94,11 +97,12 @@ struct Deserialize { { PAJLADA_REPORT_ERROR(error); return chatterino::HighlightBadge(QString(), QString(), false, - false, "", QColor()); + false, false, "", QColor()); } QString _name; QString _displayName; + bool _showInMentions = false; bool _hasAlert = true; bool _hasSound = false; QString _soundUrl; @@ -106,6 +110,7 @@ struct Deserialize { chatterino::rj::getSafe(value, "name", _name); chatterino::rj::getSafe(value, "displayName", _displayName); + chatterino::rj::getSafe(value, "showInMentions", _showInMentions); chatterino::rj::getSafe(value, "alert", _hasAlert); chatterino::rj::getSafe(value, "sound", _hasSound); chatterino::rj::getSafe(value, "soundUrl", _soundUrl); @@ -115,8 +120,9 @@ struct Deserialize { if (!_color.isValid()) _color = chatterino::HighlightBadge::FALLBACK_HIGHLIGHT_COLOR; - return chatterino::HighlightBadge(_name, _displayName, _hasAlert, - _hasSound, _soundUrl, _color); + return chatterino::HighlightBadge(_name, _displayName, _showInMentions, + _hasAlert, _hasSound, _soundUrl, + _color); } }; diff --git a/src/controllers/highlights/HighlightController.cpp b/src/controllers/highlights/HighlightController.cpp index 632f76cc4..a01e5439f 100644 --- a/src/controllers/highlights/HighlightController.cpp +++ b/src/controllers/highlights/HighlightController.cpp @@ -181,9 +181,11 @@ void rebuildUserHighlights(Settings &settings, } return HighlightResult{ - highlight.hasAlert(), highlight.hasSound(), - highlightSoundUrl, highlight.getColor(), - highlight.showInMentions(), + highlight.hasAlert(), // + highlight.hasSound(), // + highlightSoundUrl, // + highlight.getColor(), // + highlight.showInMentions(), // }; }}); } @@ -216,11 +218,11 @@ void rebuildBadgeHighlights(Settings &settings, } return HighlightResult{ - highlight.hasAlert(), - highlight.hasSound(), - highlightSoundUrl, - highlight.getColor(), - false, // showInMentions + highlight.hasAlert(), // + highlight.hasSound(), // + highlightSoundUrl, // + highlight.getColor(), // + highlight.showInMentions(), // }; } } diff --git a/src/widgets/settingspages/HighlightingPage.cpp b/src/widgets/settingspages/HighlightingPage.cpp index d75a247a4..02d45f2f3 100644 --- a/src/widgets/settingspages/HighlightingPage.cpp +++ b/src/widgets/settingspages/HighlightingPage.cpp @@ -169,8 +169,8 @@ HighlightingPage::HighlightingPage() ->initialized( &getSettings()->highlightedBadges)) .getElement(); - view->setTitles({"Name", "Flash\ntaskbar", "Play\nsound", - "Custom\nsound", "Color"}); + view->setTitles({"Name", "Show In\nMentions", "Flash\ntaskbar", + "Play\nsound", "Custom\nsound", "Color"}); view->getTableView()->horizontalHeader()->setSectionResizeMode( QHeaderView::Fixed); view->getTableView()->horizontalHeader()->setSectionResizeMode( @@ -195,10 +195,11 @@ HighlightingPage::HighlightingPage() { return; } - getSettings()->highlightedBadges.append(HighlightBadge{ - s->badgeName(), s->displayName(), false, false, "", - *ColorProvider::instance().color( - ColorType::SelfHighlight)}); + getSettings()->highlightedBadges.append( + HighlightBadge{s->badgeName(), s->displayName(), + false, false, false, "", + *ColorProvider::instance().color( + ColorType::SelfHighlight)}); } }); diff --git a/tests/src/HighlightController.cpp b/tests/src/HighlightController.cpp index f818ea7a3..4aef0dbf3 100644 --- a/tests/src/HighlightController.cpp +++ b/tests/src/HighlightController.cpp @@ -367,6 +367,15 @@ static QString DEFAULT_SETTINGS = R"!( "sound": false, "soundUrl": "", "color": "#7fe8b7eb" + }, + { + "name": "vip", + "displayName": "VIP", + "showInMentions": true, + "alert": false, + "sound": false, + "soundUrl": "", + "color": "#7fe8b7ec" } ], "subHighlightColor": "#64ffd641" @@ -530,6 +539,32 @@ TEST_F(HighlightControllerTest, A) }, }, }, + { + // Badge highlight with showInMentions only + { + // input + MessageParseArgs{}, // no special args + { + { + "vip", + "0", + }, + }, + "badge", // sender name + "show in mentions only", // original message + }, + { + // expected + true, // state + { + false, // alert + false, // playsound + boost::none, // custom sound url + std::make_shared("#7fe8b7ec"), // color + true, // showInMentions + }, + }, + }, { // User mention with showInMentions { @@ -602,6 +637,8 @@ TEST_F(HighlightControllerTest, A) EXPECT_EQ(isMatch, expected.state) << qUtf8Printable(input.senderName) << ": " << qUtf8Printable(input.originalMessage); - EXPECT_EQ(matchResult, expected.result); + EXPECT_EQ(matchResult, expected.result) + << qUtf8Printable(input.senderName) << ": " + << qUtf8Printable(input.originalMessage); } }