Add showInMentions option for Badge Highlights (#4034)

Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com>
This commit is contained in:
Felanbird 2022-10-02 07:25:10 -04:00 committed by GitHub
parent 2deed8e1cb
commit 9816722b5e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 97 additions and 38 deletions

View file

@ -21,6 +21,7 @@
- Minor: Added `subtier:` search option (e.g. `subtier:3` to find Tier 3 subs). (#4013) - 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 `badge:` search option (e.g. `badge:mod` to users with the moderator badge). (#4013)
- Minor: Added AutoMod message flag filter. (#3938) - 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 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 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) - Minor: Added scrollbar to `Select filters` dialog. (#3737)

View file

@ -9,7 +9,7 @@ namespace chatterino {
// commandmodel // commandmodel
BadgeHighlightModel::BadgeHighlightModel(QObject *parent) BadgeHighlightModel::BadgeHighlightModel(QObject *parent)
: SignalVectorModel<HighlightBadge>(5, parent) : SignalVectorModel<HighlightBadge>(6, parent)
{ {
} }
@ -28,6 +28,7 @@ HighlightBadge BadgeHighlightModel::getItemFromRow(
return HighlightBadge{ return HighlightBadge{
original.badgeName(), original.badgeName(),
row[Column::Badge]->data(Qt::DisplayRole).toString(), row[Column::Badge]->data(Qt::DisplayRole).toString(),
row[Column::ShowInMentions]->data(Qt::CheckStateRole).toBool(),
row[Column::FlashTaskbar]->data(Qt::CheckStateRole).toBool(), row[Column::FlashTaskbar]->data(Qt::CheckStateRole).toBool(),
row[Column::PlaySound]->data(Qt::CheckStateRole).toBool(), row[Column::PlaySound]->data(Qt::CheckStateRole).toBool(),
row[Column::SoundPath]->data(Qt::UserRole).toString(), row[Column::SoundPath]->data(Qt::UserRole).toString(),
@ -42,6 +43,7 @@ void BadgeHighlightModel::getRowFromItem(const HighlightBadge &item,
using Column = BadgeHighlightModel::Column; using Column = BadgeHighlightModel::Column;
setStringItem(row[Column::Badge], item.displayName(), false, true); setStringItem(row[Column::Badge], item.displayName(), false, true);
setBoolItem(row[Column::ShowInMentions], item.showInMentions());
setBoolItem(row[Column::FlashTaskbar], item.hasAlert()); setBoolItem(row[Column::FlashTaskbar], item.hasAlert());
setBoolItem(row[Column::PlaySound], item.hasSound()); setBoolItem(row[Column::PlaySound], item.hasSound());
setFilePathItem(row[Column::SoundPath], item.getSoundUrl()); setFilePathItem(row[Column::SoundPath], item.getSoundUrl());

View file

@ -17,10 +17,11 @@ public:
enum Column { enum Column {
Badge = 0, Badge = 0,
FlashTaskbar = 1, ShowInMentions = 1,
PlaySound = 2, FlashTaskbar = 2,
SoundPath = 3, PlaySound = 3,
Color = 4 SoundPath = 4,
Color = 5
}; };
protected: protected:

View file

@ -9,27 +9,31 @@ QColor HighlightBadge::FALLBACK_HIGHLIGHT_COLOR = QColor(127, 63, 73, 127);
bool HighlightBadge::operator==(const HighlightBadge &other) const bool HighlightBadge::operator==(const HighlightBadge &other) const
{ {
return std::tie(this->badgeName_, this->displayName_, this->hasSound_, return std::tie(this->badgeName_, this->displayName_, this->showInMentions_,
this->hasAlert_, this->soundUrl_, this->color_) == this->hasSound_, this->hasAlert_, this->soundUrl_,
std::tie(other.badgeName_, other.displayName_, other.hasSound_, this->color_) ==
other.hasAlert_, other.soundUrl_, other.color_); std::tie(other.badgeName_, other.displayName_, other.showInMentions_,
other.hasSound_, other.hasAlert_, other.soundUrl_,
other.color_);
} }
HighlightBadge::HighlightBadge(const QString &badgeName, HighlightBadge::HighlightBadge(const QString &badgeName,
const QString &displayName, bool hasAlert, const QString &displayName, bool showInMentions,
bool hasSound, const QString &soundUrl, bool hasAlert, bool hasSound,
QColor color) const QString &soundUrl, QColor color)
: HighlightBadge(badgeName, displayName, hasAlert, hasSound, soundUrl, : HighlightBadge(badgeName, displayName, showInMentions, hasAlert, hasSound,
std::make_shared<QColor>(color)) soundUrl, std::make_shared<QColor>(color))
{ {
} }
HighlightBadge::HighlightBadge(const QString &badgeName, HighlightBadge::HighlightBadge(const QString &badgeName,
const QString &displayName, bool hasAlert, const QString &displayName, bool showInMentions,
bool hasSound, const QString &soundUrl, bool hasAlert, bool hasSound,
const QString &soundUrl,
std::shared_ptr<QColor> color) std::shared_ptr<QColor> color)
: badgeName_(badgeName) : badgeName_(badgeName)
, displayName_(displayName) , displayName_(displayName)
, showInMentions_(showInMentions)
, hasAlert_(hasAlert) , hasAlert_(hasAlert)
, hasSound_(hasSound) , hasSound_(hasSound)
, soundUrl_(soundUrl) , soundUrl_(soundUrl)
@ -54,6 +58,11 @@ const QString &HighlightBadge::displayName() const
return this->displayName_; return this->displayName_;
} }
bool HighlightBadge::showInMentions() const
{
return this->showInMentions_;
}
bool HighlightBadge::hasAlert() const bool HighlightBadge::hasAlert() const
{ {
return this->hasAlert_; return this->hasAlert_;

View file

@ -15,15 +15,16 @@ public:
bool operator==(const HighlightBadge &other) const; bool operator==(const HighlightBadge &other) const;
HighlightBadge(const QString &badgeName, const QString &displayName, HighlightBadge(const QString &badgeName, const QString &displayName,
bool hasAlert, bool hasSound, const QString &soundUrl, bool showInMentions, bool hasAlert, bool hasSound,
QColor color); const QString &soundUrl, QColor color);
HighlightBadge(const QString &badgeName, const QString &displayName, HighlightBadge(const QString &badgeName, const QString &displayName,
bool hasAlert, bool hasSound, const QString &soundUrl, bool showInMentions, bool hasAlert, bool hasSound,
std::shared_ptr<QColor> color); const QString &soundUrl, std::shared_ptr<QColor> color);
const QString &badgeName() const; const QString &badgeName() const;
const QString &displayName() const; const QString &displayName() const;
bool showInMentions() const;
bool hasAlert() const; bool hasAlert() const;
bool hasSound() const; bool hasSound() const;
bool isMatch(const Badge &badge) const; bool isMatch(const Badge &badge) const;
@ -53,6 +54,7 @@ private:
QString badgeName_; QString badgeName_;
QString displayName_; QString displayName_;
bool showInMentions_;
bool hasAlert_; bool hasAlert_;
bool hasSound_; bool hasSound_;
QUrl soundUrl_; QUrl soundUrl_;
@ -75,6 +77,7 @@ struct Serialize<chatterino::HighlightBadge> {
chatterino::rj::set(ret, "name", value.badgeName(), a); chatterino::rj::set(ret, "name", value.badgeName(), a);
chatterino::rj::set(ret, "displayName", value.displayName(), 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, "alert", value.hasAlert(), a);
chatterino::rj::set(ret, "sound", value.hasSound(), a); chatterino::rj::set(ret, "sound", value.hasSound(), a);
chatterino::rj::set(ret, "soundUrl", value.getSoundUrl().toString(), a); chatterino::rj::set(ret, "soundUrl", value.getSoundUrl().toString(), a);
@ -94,11 +97,12 @@ struct Deserialize<chatterino::HighlightBadge> {
{ {
PAJLADA_REPORT_ERROR(error); PAJLADA_REPORT_ERROR(error);
return chatterino::HighlightBadge(QString(), QString(), false, return chatterino::HighlightBadge(QString(), QString(), false,
false, "", QColor()); false, false, "", QColor());
} }
QString _name; QString _name;
QString _displayName; QString _displayName;
bool _showInMentions = false;
bool _hasAlert = true; bool _hasAlert = true;
bool _hasSound = false; bool _hasSound = false;
QString _soundUrl; QString _soundUrl;
@ -106,6 +110,7 @@ struct Deserialize<chatterino::HighlightBadge> {
chatterino::rj::getSafe(value, "name", _name); chatterino::rj::getSafe(value, "name", _name);
chatterino::rj::getSafe(value, "displayName", _displayName); chatterino::rj::getSafe(value, "displayName", _displayName);
chatterino::rj::getSafe(value, "showInMentions", _showInMentions);
chatterino::rj::getSafe(value, "alert", _hasAlert); chatterino::rj::getSafe(value, "alert", _hasAlert);
chatterino::rj::getSafe(value, "sound", _hasSound); chatterino::rj::getSafe(value, "sound", _hasSound);
chatterino::rj::getSafe(value, "soundUrl", _soundUrl); chatterino::rj::getSafe(value, "soundUrl", _soundUrl);
@ -115,8 +120,9 @@ struct Deserialize<chatterino::HighlightBadge> {
if (!_color.isValid()) if (!_color.isValid())
_color = chatterino::HighlightBadge::FALLBACK_HIGHLIGHT_COLOR; _color = chatterino::HighlightBadge::FALLBACK_HIGHLIGHT_COLOR;
return chatterino::HighlightBadge(_name, _displayName, _hasAlert, return chatterino::HighlightBadge(_name, _displayName, _showInMentions,
_hasSound, _soundUrl, _color); _hasAlert, _hasSound, _soundUrl,
_color);
} }
}; };

View file

@ -181,9 +181,11 @@ void rebuildUserHighlights(Settings &settings,
} }
return HighlightResult{ return HighlightResult{
highlight.hasAlert(), highlight.hasSound(), highlight.hasAlert(), //
highlightSoundUrl, highlight.getColor(), highlight.hasSound(), //
highlight.showInMentions(), highlightSoundUrl, //
highlight.getColor(), //
highlight.showInMentions(), //
}; };
}}); }});
} }
@ -216,11 +218,11 @@ void rebuildBadgeHighlights(Settings &settings,
} }
return HighlightResult{ return HighlightResult{
highlight.hasAlert(), highlight.hasAlert(), //
highlight.hasSound(), highlight.hasSound(), //
highlightSoundUrl, highlightSoundUrl, //
highlight.getColor(), highlight.getColor(), //
false, // showInMentions highlight.showInMentions(), //
}; };
} }
} }

View file

@ -169,8 +169,8 @@ HighlightingPage::HighlightingPage()
->initialized( ->initialized(
&getSettings()->highlightedBadges)) &getSettings()->highlightedBadges))
.getElement(); .getElement();
view->setTitles({"Name", "Flash\ntaskbar", "Play\nsound", view->setTitles({"Name", "Show In\nMentions", "Flash\ntaskbar",
"Custom\nsound", "Color"}); "Play\nsound", "Custom\nsound", "Color"});
view->getTableView()->horizontalHeader()->setSectionResizeMode( view->getTableView()->horizontalHeader()->setSectionResizeMode(
QHeaderView::Fixed); QHeaderView::Fixed);
view->getTableView()->horizontalHeader()->setSectionResizeMode( view->getTableView()->horizontalHeader()->setSectionResizeMode(
@ -195,10 +195,11 @@ HighlightingPage::HighlightingPage()
{ {
return; return;
} }
getSettings()->highlightedBadges.append(HighlightBadge{ getSettings()->highlightedBadges.append(
s->badgeName(), s->displayName(), false, false, "", HighlightBadge{s->badgeName(), s->displayName(),
*ColorProvider::instance().color( false, false, false, "",
ColorType::SelfHighlight)}); *ColorProvider::instance().color(
ColorType::SelfHighlight)});
} }
}); });

View file

@ -367,6 +367,15 @@ static QString DEFAULT_SETTINGS = R"!(
"sound": false, "sound": false,
"soundUrl": "", "soundUrl": "",
"color": "#7fe8b7eb" "color": "#7fe8b7eb"
},
{
"name": "vip",
"displayName": "VIP",
"showInMentions": true,
"alert": false,
"sound": false,
"soundUrl": "",
"color": "#7fe8b7ec"
} }
], ],
"subHighlightColor": "#64ffd641" "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<QColor>("#7fe8b7ec"), // color
true, // showInMentions
},
},
},
{ {
// User mention with showInMentions // User mention with showInMentions
{ {
@ -602,6 +637,8 @@ TEST_F(HighlightControllerTest, A)
EXPECT_EQ(isMatch, expected.state) EXPECT_EQ(isMatch, expected.state)
<< qUtf8Printable(input.senderName) << ": " << qUtf8Printable(input.senderName) << ": "
<< qUtf8Printable(input.originalMessage); << qUtf8Printable(input.originalMessage);
EXPECT_EQ(matchResult, expected.result); EXPECT_EQ(matchResult, expected.result)
<< qUtf8Printable(input.senderName) << ": "
<< qUtf8Printable(input.originalMessage);
} }
} }