feat: add sound and flash alert for automod caught messages (#5026)
Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com>
This commit is contained in:
@@ -204,6 +204,41 @@ void rebuildMessageHighlights(Settings &settings,
|
||||
{
|
||||
checks.emplace_back(highlightPhraseCheck(highlight));
|
||||
}
|
||||
|
||||
if (settings.enableAutomodHighlight)
|
||||
{
|
||||
const auto highlightSound =
|
||||
settings.enableAutomodHighlightSound.getValue();
|
||||
const auto highlightAlert =
|
||||
settings.enableAutomodHighlightTaskbar.getValue();
|
||||
const auto highlightSoundUrlValue =
|
||||
settings.automodHighlightSoundUrl.getValue();
|
||||
|
||||
checks.emplace_back(HighlightCheck{
|
||||
[=](const auto & /*args*/, const auto & /*badges*/,
|
||||
const auto & /*senderName*/, const auto & /*originalMessage*/,
|
||||
const auto &flags,
|
||||
const auto /*self*/) -> std::optional<HighlightResult> {
|
||||
if (!flags.has(MessageFlag::AutoModOffendingMessage))
|
||||
{
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
std::optional<QUrl> highlightSoundUrl;
|
||||
if (!highlightSoundUrlValue.isEmpty())
|
||||
{
|
||||
highlightSoundUrl = highlightSoundUrlValue;
|
||||
}
|
||||
|
||||
return HighlightResult{
|
||||
highlightAlert, // alert
|
||||
highlightSound, // playSound
|
||||
highlightSoundUrl, // customSoundUrl
|
||||
nullptr, // color
|
||||
false, // showInMentions
|
||||
};
|
||||
}});
|
||||
}
|
||||
}
|
||||
|
||||
void rebuildUserHighlights(Settings &settings,
|
||||
@@ -434,6 +469,11 @@ void HighlightController::initialize(Settings &settings, Paths & /*paths*/)
|
||||
this->rebuildListener_.addSetting(settings.threadHighlightSoundUrl);
|
||||
this->rebuildListener_.addSetting(settings.showThreadHighlightInMentions);
|
||||
|
||||
this->rebuildListener_.addSetting(settings.enableAutomodHighlight);
|
||||
this->rebuildListener_.addSetting(settings.enableAutomodHighlightSound);
|
||||
this->rebuildListener_.addSetting(settings.enableAutomodHighlightTaskbar);
|
||||
this->rebuildListener_.addSetting(settings.automodHighlightSoundUrl);
|
||||
|
||||
this->rebuildListener_.setCB([this, &settings] {
|
||||
qCDebug(chatterinoHighlights)
|
||||
<< "Rebuild checks because a setting changed";
|
||||
|
||||
@@ -234,6 +234,30 @@ void HighlightModel::afterInit()
|
||||
|
||||
this->insertCustomRow(threadMessageRow,
|
||||
HighlightRowIndexes::ThreadMessageRow);
|
||||
|
||||
// Highlight settings for automod caught messages
|
||||
const std::vector<QStandardItem *> automodRow = this->createRow();
|
||||
setBoolItem(automodRow[Column::Pattern],
|
||||
getSettings()->enableAutomodHighlight.getValue(), true, false);
|
||||
automodRow[Column::Pattern]->setData("AutoMod Caught Messages",
|
||||
Qt::DisplayRole);
|
||||
automodRow[Column::ShowInMentions]->setFlags({});
|
||||
setBoolItem(automodRow[Column::FlashTaskbar],
|
||||
getSettings()->enableAutomodHighlightTaskbar.getValue(), true,
|
||||
false);
|
||||
setBoolItem(automodRow[Column::PlaySound],
|
||||
getSettings()->enableAutomodHighlightSound.getValue(), true,
|
||||
false);
|
||||
automodRow[Column::UseRegex]->setFlags({});
|
||||
automodRow[Column::CaseSensitive]->setFlags({});
|
||||
|
||||
const auto automodSound =
|
||||
QUrl(getSettings()->automodHighlightSoundUrl.getValue());
|
||||
setFilePathItem(automodRow[Column::SoundPath], automodSound, false);
|
||||
|
||||
automodRow[Column::Color]->setFlags(Qt::ItemFlag::NoItemFlags);
|
||||
|
||||
this->insertCustomRow(automodRow, HighlightRowIndexes::AutomodRow);
|
||||
}
|
||||
|
||||
void HighlightModel::customRowSetData(const std::vector<QStandardItem *> &row,
|
||||
@@ -278,6 +302,11 @@ void HighlightModel::customRowSetData(const std::vector<QStandardItem *> &row,
|
||||
getSettings()->enableThreadHighlight.setValue(
|
||||
value.toBool());
|
||||
}
|
||||
else if (rowIndex == HighlightRowIndexes::AutomodRow)
|
||||
{
|
||||
getSettings()->enableAutomodHighlight.setValue(
|
||||
value.toBool());
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -336,6 +365,11 @@ void HighlightModel::customRowSetData(const std::vector<QStandardItem *> &row,
|
||||
getSettings()->enableThreadHighlightTaskbar.setValue(
|
||||
value.toBool());
|
||||
}
|
||||
else if (rowIndex == HighlightRowIndexes::AutomodRow)
|
||||
{
|
||||
getSettings()->enableAutomodHighlightTaskbar.setValue(
|
||||
value.toBool());
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -377,6 +411,11 @@ void HighlightModel::customRowSetData(const std::vector<QStandardItem *> &row,
|
||||
getSettings()->enableThreadHighlightSound.setValue(
|
||||
value.toBool());
|
||||
}
|
||||
else if (rowIndex == HighlightRowIndexes::AutomodRow)
|
||||
{
|
||||
getSettings()->enableAutomodHighlightSound.setValue(
|
||||
value.toBool());
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -412,6 +451,11 @@ void HighlightModel::customRowSetData(const std::vector<QStandardItem *> &row,
|
||||
getSettings()->threadHighlightSoundUrl.setValue(
|
||||
value.toString());
|
||||
}
|
||||
else if (rowIndex == HighlightRowIndexes::AutomodRow)
|
||||
{
|
||||
getSettings()->automodHighlightSoundUrl.setValue(
|
||||
value.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -34,6 +34,7 @@ public:
|
||||
FirstMessageRow = 4,
|
||||
ElevatedMessageRow = 5,
|
||||
ThreadMessageRow = 6,
|
||||
AutomodRow = 7,
|
||||
};
|
||||
|
||||
enum UserHighlightRowIndexes {
|
||||
|
||||
Reference in New Issue
Block a user