mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
Add showInMentions
option for Badge Highlights (#4034)
Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com>
This commit is contained in:
parent
2deed8e1cb
commit
9816722b5e
|
@ -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)
|
||||
|
|
|
@ -9,7 +9,7 @@ namespace chatterino {
|
|||
|
||||
// commandmodel
|
||||
BadgeHighlightModel::BadgeHighlightModel(QObject *parent)
|
||||
: SignalVectorModel<HighlightBadge>(5, parent)
|
||||
: SignalVectorModel<HighlightBadge>(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());
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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<QColor>(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<QColor>(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<QColor> 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_;
|
||||
|
|
|
@ -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<QColor> color);
|
||||
bool showInMentions, bool hasAlert, bool hasSound,
|
||||
const QString &soundUrl, std::shared_ptr<QColor> 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::HighlightBadge> {
|
|||
|
||||
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<chatterino::HighlightBadge> {
|
|||
{
|
||||
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::HighlightBadge> {
|
|||
|
||||
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<chatterino::HighlightBadge> {
|
|||
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);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -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(), //
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)});
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -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<QColor>("#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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue