Allow highlights to be excluded from /mentions (#2036)

This commit is contained in:
Leon Richardt
2020-10-24 14:33:15 +02:00
committed by GitHub
parent 0049a5ebb2
commit ec94869480
12 changed files with 99 additions and 40 deletions
+20 -1
View File
@@ -9,7 +9,7 @@ namespace chatterino {
// commandmodel
HighlightModel::HighlightModel(QObject *parent)
: SignalVectorModel<HighlightPhrase>(7, parent)
: SignalVectorModel<HighlightPhrase>(Column::COUNT, parent)
{
}
@@ -25,6 +25,7 @@ HighlightPhrase HighlightModel::getItemFromRow(
return HighlightPhrase{
row[Column::Pattern]->data(Qt::DisplayRole).toString(),
row[Column::ShowInMentions]->data(Qt::DisplayRole).toBool(),
row[Column::FlashTaskbar]->data(Qt::CheckStateRole).toBool(),
row[Column::PlaySound]->data(Qt::CheckStateRole).toBool(),
row[Column::UseRegex]->data(Qt::CheckStateRole).toBool(),
@@ -38,6 +39,7 @@ void HighlightModel::getRowFromItem(const HighlightPhrase &item,
std::vector<QStandardItem *> &row)
{
setStringItem(row[Column::Pattern], item.getPattern());
setBoolItem(row[Column::ShowInMentions], item.showInMentions());
setBoolItem(row[Column::FlashTaskbar], item.hasAlert());
setBoolItem(row[Column::PlaySound], item.hasSound());
setBoolItem(row[Column::UseRegex], item.isRegex());
@@ -54,6 +56,9 @@ void HighlightModel::afterInit()
getSettings()->enableSelfHighlight.getValue(), true, false);
usernameRow[Column::Pattern]->setData("Your username (automatic)",
Qt::DisplayRole);
setBoolItem(usernameRow[Column::ShowInMentions],
getSettings()->showSelfHighlightInMentions.getValue(), true,
false);
setBoolItem(usernameRow[Column::FlashTaskbar],
getSettings()->enableSelfHighlightTaskbar.getValue(), true,
false);
@@ -76,6 +81,7 @@ void HighlightModel::afterInit()
setBoolItem(whisperRow[Column::Pattern],
getSettings()->enableWhisperHighlight.getValue(), true, false);
whisperRow[Column::Pattern]->setData("Whispers", Qt::DisplayRole);
whisperRow[Column::ShowInMentions]->setFlags(0); // We have /whispers
setBoolItem(whisperRow[Column::FlashTaskbar],
getSettings()->enableWhisperHighlightTaskbar.getValue(), true,
false);
@@ -100,6 +106,7 @@ void HighlightModel::afterInit()
setBoolItem(subRow[Column::Pattern],
getSettings()->enableSubHighlight.getValue(), true, false);
subRow[Column::Pattern]->setData("Subscriptions", Qt::DisplayRole);
subRow[Column::ShowInMentions]->setFlags(0);
setBoolItem(subRow[Column::FlashTaskbar],
getSettings()->enableSubHighlightTaskbar.getValue(), true,
false);
@@ -122,6 +129,7 @@ void HighlightModel::afterInit()
getSettings()->enableRedeemedHighlight.getValue(), true, false);
redeemedRow[Column::Pattern]->setData(
"Highlights redeemed with Channel Points", Qt::DisplayRole);
redeemedRow[Column::ShowInMentions]->setFlags(0);
// setBoolItem(redeemedRow[Column::FlashTaskbar],
// getSettings()->enableRedeemedHighlightTaskbar.getValue(), true,
// false);
@@ -174,6 +182,17 @@ void HighlightModel::customRowSetData(const std::vector<QStandardItem *> &row,
}
}
break;
case Column::ShowInMentions: {
if (role == Qt::CheckStateRole)
{
if (rowIndex == 0)
{
getSettings()->showSelfHighlightInMentions.setValue(
value.toBool());
}
}
}
break;
case Column::FlashTaskbar: {
if (role == Qt::CheckStateRole)
{
@@ -15,12 +15,14 @@ public:
// Used here, in HighlightingPage and in UserHighlightModel
enum Column {
Pattern = 0,
FlashTaskbar = 1,
PlaySound = 2,
UseRegex = 3,
CaseSensitive = 4,
SoundPath = 5,
Color = 6
ShowInMentions = 1,
FlashTaskbar = 2,
PlaySound = 3,
UseRegex = 4,
CaseSensitive = 5,
SoundPath = 6,
Color = 7,
COUNT // keep this as last member of enum
};
constexpr static int WHISPER_ROW = 1;
+17 -10
View File
@@ -16,19 +16,20 @@ QColor HighlightPhrase::FALLBACK_SUB_COLOR = QColor(196, 102, 255, 100);
bool HighlightPhrase::operator==(const HighlightPhrase &other) const
{
return std::tie(this->pattern_, this->hasSound_, this->hasAlert_,
this->isRegex_, this->isCaseSensitive_, this->soundUrl_,
this->color_) == std::tie(other.pattern_, other.hasSound_,
other.hasAlert_, other.isRegex_,
other.isCaseSensitive_,
other.soundUrl_, other.color_);
return std::tie(this->pattern_, this->showInMentions_, this->hasSound_,
this->hasAlert_, this->isRegex_, this->isCaseSensitive_,
this->soundUrl_, this->color_) ==
std::tie(other.pattern_, other.showInMentions_, other.hasSound_,
other.hasAlert_, other.isRegex_, other.isCaseSensitive_,
other.soundUrl_, other.color_);
}
HighlightPhrase::HighlightPhrase(const QString &pattern, bool hasAlert,
bool hasSound, bool isRegex,
HighlightPhrase::HighlightPhrase(const QString &pattern, bool showInMentions,
bool hasAlert, bool hasSound, bool isRegex,
bool isCaseSensitive, const QString &soundUrl,
QColor color)
: pattern_(pattern)
, showInMentions_(showInMentions)
, hasAlert_(hasAlert)
, hasSound_(hasSound)
, isRegex_(isRegex)
@@ -45,11 +46,12 @@ HighlightPhrase::HighlightPhrase(const QString &pattern, bool hasAlert,
this->color_ = std::make_shared<QColor>(color);
}
HighlightPhrase::HighlightPhrase(const QString &pattern, bool hasAlert,
bool hasSound, bool isRegex,
HighlightPhrase::HighlightPhrase(const QString &pattern, bool showInMentions,
bool hasAlert, bool hasSound, bool isRegex,
bool isCaseSensitive, const QString &soundUrl,
std::shared_ptr<QColor> color)
: pattern_(pattern)
, showInMentions_(showInMentions)
, hasAlert_(hasAlert)
, hasSound_(hasSound)
, isRegex_(isRegex)
@@ -71,6 +73,11 @@ const QString &HighlightPhrase::getPattern() const
return this->pattern_;
}
bool HighlightPhrase::showInMentions() const
{
return this->showInMentions_;
}
bool HighlightPhrase::hasAlert() const
{
return this->hasAlert_;
+23 -11
View File
@@ -24,20 +24,21 @@ public:
*
* Use this constructor when creating a new HighlightPhrase.
*/
HighlightPhrase(const QString &pattern, bool hasAlert, bool hasSound,
bool isRegex, bool isCaseSensitive, const QString &soundUrl,
QColor color);
HighlightPhrase(const QString &pattern, bool showInMentions, bool hasAlert,
bool hasSound, bool isRegex, bool isCaseSensitive,
const QString &soundUrl, QColor color);
/**
* @brief Create a new HighlightPhrase.
*
* Use this constructor when updating an existing HighlightPhrase's color.
*/
HighlightPhrase(const QString &pattern, bool hasAlert, bool hasSound,
bool isRegex, bool isCaseSensitive, const QString &soundUrl,
std::shared_ptr<QColor> color);
HighlightPhrase(const QString &pattern, bool showInMentions, bool hasAlert,
bool hasSound, bool isRegex, bool isCaseSensitive,
const QString &soundUrl, std::shared_ptr<QColor> color);
const QString &getPattern() const;
bool showInMentions() const;
bool hasAlert() const;
/**
@@ -84,6 +85,7 @@ public:
private:
QString pattern_;
bool showInMentions_;
bool hasAlert_;
bool hasSound_;
bool isRegex_;
@@ -97,6 +99,14 @@ private:
namespace pajlada {
namespace {
chatterino::HighlightPhrase constructError()
{
return chatterino::HighlightPhrase(QString(), false, false, false,
false, false, QString(), QColor());
}
} // namespace
template <>
struct Serialize<chatterino::HighlightPhrase> {
static rapidjson::Value get(const chatterino::HighlightPhrase &value,
@@ -105,6 +115,7 @@ struct Serialize<chatterino::HighlightPhrase> {
rapidjson::Value ret(rapidjson::kObjectType);
chatterino::rj::set(ret, "pattern", value.getPattern(), 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, "regex", value.isRegex(), a);
@@ -123,11 +134,11 @@ struct Deserialize<chatterino::HighlightPhrase> {
{
if (!value.IsObject())
{
return chatterino::HighlightPhrase(QString(), true, false, false,
false, "", QColor());
return constructError();
}
QString _pattern;
bool _showInMentions = true;
bool _hasAlert = true;
bool _hasSound = false;
bool _isRegex = false;
@@ -136,6 +147,7 @@ struct Deserialize<chatterino::HighlightPhrase> {
QString encodedColor;
chatterino::rj::getSafe(value, "pattern", _pattern);
chatterino::rj::getSafe(value, "showInMentions", _showInMentions);
chatterino::rj::getSafe(value, "alert", _hasAlert);
chatterino::rj::getSafe(value, "sound", _hasSound);
chatterino::rj::getSafe(value, "regex", _isRegex);
@@ -147,9 +159,9 @@ struct Deserialize<chatterino::HighlightPhrase> {
if (!_color.isValid())
_color = chatterino::HighlightPhrase::FALLBACK_HIGHLIGHT_COLOR;
return chatterino::HighlightPhrase(_pattern, _hasAlert, _hasSound,
_isRegex, _isCaseSensitive,
_soundUrl, _color);
return chatterino::HighlightPhrase(_pattern, _showInMentions, _hasAlert,
_hasSound, _isRegex,
_isCaseSensitive, _soundUrl, _color);
}
};
@@ -7,9 +7,11 @@
namespace chatterino {
using Column = HighlightModel::Column;
// commandmodel
UserHighlightModel::UserHighlightModel(QObject *parent)
: SignalVectorModel<HighlightPhrase>(7, parent)
: SignalVectorModel<HighlightPhrase>(Column::COUNT, parent)
{
}
@@ -17,8 +19,6 @@ UserHighlightModel::UserHighlightModel(QObject *parent)
HighlightPhrase UserHighlightModel::getItemFromRow(
std::vector<QStandardItem *> &row, const HighlightPhrase &original)
{
using Column = HighlightModel::Column;
// In order for old messages to update their highlight color, we need to
// update the highlight color here.
auto highlightColor = original.getColor();
@@ -27,6 +27,7 @@ HighlightPhrase UserHighlightModel::getItemFromRow(
return HighlightPhrase{
row[Column::Pattern]->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::UseRegex]->data(Qt::CheckStateRole).toBool(),
@@ -39,9 +40,8 @@ HighlightPhrase UserHighlightModel::getItemFromRow(
void UserHighlightModel::getRowFromItem(const HighlightPhrase &item,
std::vector<QStandardItem *> &row)
{
using Column = HighlightModel::Column;
setStringItem(row[Column::Pattern], item.getPattern());
setBoolItem(row[Column::ShowInMentions], item.showInMentions());
setBoolItem(row[Column::FlashTaskbar], item.hasAlert());
setBoolItem(row[Column::PlaySound], item.hasSound());
setBoolItem(row[Column::UseRegex], item.isRegex());