refactor: Remove Leading Mention in Replies and Highlight Participated Threads (#4047)
This commit is contained in:
@@ -11,10 +11,12 @@ auto highlightPhraseCheck(const HighlightPhrase &highlight) -> HighlightCheck
|
||||
return HighlightCheck{
|
||||
[highlight](const auto &args, const auto &badges,
|
||||
const auto &senderName, const auto &originalMessage,
|
||||
const auto &flags,
|
||||
const auto self) -> boost::optional<HighlightResult> {
|
||||
(void)args; // unused
|
||||
(void)badges; // unused
|
||||
(void)senderName; // unused
|
||||
(void)flags; // unused
|
||||
|
||||
if (self)
|
||||
{
|
||||
@@ -60,11 +62,12 @@ void rebuildSubscriptionHighlights(Settings &settings,
|
||||
|
||||
checks.emplace_back(HighlightCheck{
|
||||
[=](const auto &args, const auto &badges, const auto &senderName,
|
||||
const auto &originalMessage,
|
||||
const auto &originalMessage, const auto &flags,
|
||||
const auto self) -> boost::optional<HighlightResult> {
|
||||
(void)badges; // unused
|
||||
(void)senderName; // unused
|
||||
(void)originalMessage; // unused
|
||||
(void)flags; // unused
|
||||
(void)self; // unused
|
||||
|
||||
if (!args.isSubscriptionMessage)
|
||||
@@ -105,11 +108,12 @@ void rebuildWhisperHighlights(Settings &settings,
|
||||
|
||||
checks.emplace_back(HighlightCheck{
|
||||
[=](const auto &args, const auto &badges, const auto &senderName,
|
||||
const auto &originalMessage,
|
||||
const auto &originalMessage, const auto &flags,
|
||||
const auto self) -> boost::optional<HighlightResult> {
|
||||
(void)badges; // unused
|
||||
(void)senderName; // unused
|
||||
(void)originalMessage; // unused
|
||||
(void)flags; // unused
|
||||
(void)self; // unused
|
||||
|
||||
if (!args.isReceivedWhisper)
|
||||
@@ -128,6 +132,44 @@ void rebuildWhisperHighlights(Settings &settings,
|
||||
}
|
||||
}
|
||||
|
||||
void rebuildReplyThreadHighlight(Settings &settings,
|
||||
std::vector<HighlightCheck> &checks)
|
||||
{
|
||||
if (settings.enableThreadHighlight)
|
||||
{
|
||||
auto highlightSound = settings.enableThreadHighlightSound.getValue();
|
||||
auto highlightAlert = settings.enableThreadHighlightTaskbar.getValue();
|
||||
auto highlightSoundUrlValue =
|
||||
settings.threadHighlightSoundUrl.getValue();
|
||||
boost::optional<QUrl> highlightSoundUrl;
|
||||
if (!highlightSoundUrlValue.isEmpty())
|
||||
{
|
||||
highlightSoundUrl = highlightSoundUrlValue;
|
||||
}
|
||||
auto highlightInMentions =
|
||||
settings.showThreadHighlightInMentions.getValue();
|
||||
checks.emplace_back(HighlightCheck{
|
||||
[=](const auto & /*args*/, const auto & /*badges*/,
|
||||
const auto & /*senderName*/, const auto & /*originalMessage*/,
|
||||
const auto &flags,
|
||||
const auto self) -> boost::optional<HighlightResult> {
|
||||
if (flags.has(MessageFlag::ParticipatedThread) && !self)
|
||||
{
|
||||
return HighlightResult{
|
||||
highlightAlert,
|
||||
highlightSound,
|
||||
highlightSoundUrl,
|
||||
ColorProvider::instance().color(
|
||||
ColorType::ThreadMessageHighlight),
|
||||
highlightInMentions,
|
||||
};
|
||||
}
|
||||
|
||||
return boost::none;
|
||||
}});
|
||||
}
|
||||
}
|
||||
|
||||
void rebuildMessageHighlights(Settings &settings,
|
||||
std::vector<HighlightCheck> &checks)
|
||||
{
|
||||
@@ -163,10 +205,12 @@ void rebuildUserHighlights(Settings &settings,
|
||||
checks.emplace_back(HighlightCheck{
|
||||
[highlight](const auto &args, const auto &badges,
|
||||
const auto &senderName, const auto &originalMessage,
|
||||
const auto &flags,
|
||||
const auto self) -> boost::optional<HighlightResult> {
|
||||
(void)args; // unused
|
||||
(void)badges; // unused
|
||||
(void)originalMessage; // unused
|
||||
(void)flags; // unused
|
||||
(void)self; // unused
|
||||
|
||||
if (!highlight.isMatch(senderName))
|
||||
@@ -201,10 +245,12 @@ void rebuildBadgeHighlights(Settings &settings,
|
||||
checks.emplace_back(HighlightCheck{
|
||||
[highlight](const auto &args, const auto &badges,
|
||||
const auto &senderName, const auto &originalMessage,
|
||||
const auto &flags,
|
||||
const auto self) -> boost::optional<HighlightResult> {
|
||||
(void)args; // unused
|
||||
(void)senderName; // unused
|
||||
(void)originalMessage; // unused
|
||||
(void)flags; // unused
|
||||
(void)self; // unused
|
||||
|
||||
for (const Badge &badge : badges)
|
||||
@@ -247,6 +293,11 @@ void HighlightController::initialize(Settings &settings, Paths & /*paths*/)
|
||||
this->rebuildListener_.addSetting(settings.enableSubHighlight);
|
||||
this->rebuildListener_.addSetting(settings.enableSubHighlightSound);
|
||||
this->rebuildListener_.addSetting(settings.enableSubHighlightTaskbar);
|
||||
this->rebuildListener_.addSetting(settings.enableThreadHighlight);
|
||||
this->rebuildListener_.addSetting(settings.enableThreadHighlightSound);
|
||||
this->rebuildListener_.addSetting(settings.enableThreadHighlightTaskbar);
|
||||
this->rebuildListener_.addSetting(settings.threadHighlightSoundUrl);
|
||||
this->rebuildListener_.addSetting(settings.showThreadHighlightInMentions);
|
||||
|
||||
this->rebuildListener_.setCB([this, &settings] {
|
||||
qCDebug(chatterinoHighlights)
|
||||
@@ -294,7 +345,7 @@ void HighlightController::rebuildChecks(Settings &settings)
|
||||
checks->clear();
|
||||
|
||||
// CURRENT ORDER:
|
||||
// Subscription -> Whisper -> User -> Message -> Badge
|
||||
// Subscription -> Whisper -> User -> Message -> Reply Threads -> Badge
|
||||
|
||||
rebuildSubscriptionHighlights(settings, *checks);
|
||||
|
||||
@@ -304,12 +355,15 @@ void HighlightController::rebuildChecks(Settings &settings)
|
||||
|
||||
rebuildMessageHighlights(settings, *checks);
|
||||
|
||||
rebuildReplyThreadHighlight(settings, *checks);
|
||||
|
||||
rebuildBadgeHighlights(settings, *checks);
|
||||
}
|
||||
|
||||
std::pair<bool, HighlightResult> HighlightController::check(
|
||||
const MessageParseArgs &args, const std::vector<Badge> &badges,
|
||||
const QString &senderName, const QString &originalMessage) const
|
||||
const QString &senderName, const QString &originalMessage,
|
||||
const MessageFlags &messageFlags) const
|
||||
{
|
||||
bool highlighted = false;
|
||||
auto result = HighlightResult::emptyResult();
|
||||
@@ -322,8 +376,8 @@ std::pair<bool, HighlightResult> HighlightController::check(
|
||||
|
||||
for (const auto &check : *checks)
|
||||
{
|
||||
if (auto checkResult =
|
||||
check.cb(args, badges, senderName, originalMessage, self);
|
||||
if (auto checkResult = check.cb(args, badges, senderName,
|
||||
originalMessage, messageFlags, self);
|
||||
checkResult)
|
||||
{
|
||||
highlighted = true;
|
||||
|
||||
@@ -142,7 +142,8 @@ struct HighlightResult {
|
||||
struct HighlightCheck {
|
||||
using Checker = std::function<boost::optional<HighlightResult>(
|
||||
const MessageParseArgs &args, const std::vector<Badge> &badges,
|
||||
const QString &senderName, const QString &originalMessage, bool self)>;
|
||||
const QString &senderName, const QString &originalMessage,
|
||||
const MessageFlags &messageFlags, bool self)>;
|
||||
Checker cb;
|
||||
};
|
||||
|
||||
@@ -156,7 +157,8 @@ public:
|
||||
**/
|
||||
[[nodiscard]] std::pair<bool, HighlightResult> check(
|
||||
const MessageParseArgs &args, const std::vector<Badge> &badges,
|
||||
const QString &senderName, const QString &originalMessage) const;
|
||||
const QString &senderName, const QString &originalMessage,
|
||||
const MessageFlags &messageFlags) const;
|
||||
|
||||
private:
|
||||
/**
|
||||
|
||||
@@ -213,6 +213,36 @@ void HighlightModel::afterInit()
|
||||
|
||||
this->insertCustomRow(elevatedMessageRow,
|
||||
HighlightRowIndexes::ElevatedMessageRow);
|
||||
|
||||
// Highlight settings for reply threads
|
||||
std::vector<QStandardItem *> threadMessageRow = this->createRow();
|
||||
setBoolItem(threadMessageRow[Column::Pattern],
|
||||
getSettings()->enableThreadHighlight.getValue(), true, false);
|
||||
threadMessageRow[Column::Pattern]->setData("Participated Reply Threads",
|
||||
Qt::DisplayRole);
|
||||
setBoolItem(threadMessageRow[Column::ShowInMentions],
|
||||
getSettings()->showThreadHighlightInMentions.getValue(), true,
|
||||
false);
|
||||
setBoolItem(threadMessageRow[Column::FlashTaskbar],
|
||||
getSettings()->enableThreadHighlightTaskbar.getValue(), true,
|
||||
false);
|
||||
setBoolItem(threadMessageRow[Column::PlaySound],
|
||||
getSettings()->enableThreadHighlightSound.getValue(), true,
|
||||
false);
|
||||
threadMessageRow[Column::UseRegex]->setFlags({});
|
||||
threadMessageRow[Column::CaseSensitive]->setFlags({});
|
||||
|
||||
QUrl threadMessageSound =
|
||||
QUrl(getSettings()->threadHighlightSoundUrl.getValue());
|
||||
setFilePathItem(threadMessageRow[Column::SoundPath], threadMessageSound,
|
||||
false);
|
||||
|
||||
auto threadMessageColor =
|
||||
ColorProvider::instance().color(ColorType::ThreadMessageHighlight);
|
||||
setColorItem(threadMessageRow[Column::Color], *threadMessageColor, false);
|
||||
|
||||
this->insertCustomRow(threadMessageRow,
|
||||
HighlightRowIndexes::ThreadMessageRow);
|
||||
}
|
||||
|
||||
void HighlightModel::customRowSetData(const std::vector<QStandardItem *> &row,
|
||||
@@ -252,6 +282,11 @@ void HighlightModel::customRowSetData(const std::vector<QStandardItem *> &row,
|
||||
getSettings()->enableElevatedMessageHighlight.setValue(
|
||||
value.toBool());
|
||||
}
|
||||
else if (rowIndex == HighlightRowIndexes::ThreadMessageRow)
|
||||
{
|
||||
getSettings()->enableThreadHighlight.setValue(
|
||||
value.toBool());
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -263,6 +298,11 @@ void HighlightModel::customRowSetData(const std::vector<QStandardItem *> &row,
|
||||
getSettings()->showSelfHighlightInMentions.setValue(
|
||||
value.toBool());
|
||||
}
|
||||
else if (rowIndex == HighlightRowIndexes::ThreadMessageRow)
|
||||
{
|
||||
getSettings()->showThreadHighlightInMentions.setValue(
|
||||
value.toBool());
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -300,6 +340,11 @@ void HighlightModel::customRowSetData(const std::vector<QStandardItem *> &row,
|
||||
// ->enableElevatedMessageHighlightTaskbar.setvalue(
|
||||
// value.toBool());
|
||||
}
|
||||
else if (rowIndex == HighlightRowIndexes::ThreadMessageRow)
|
||||
{
|
||||
getSettings()->enableThreadHighlightTaskbar.setValue(
|
||||
value.toBool());
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -336,6 +381,11 @@ void HighlightModel::customRowSetData(const std::vector<QStandardItem *> &row,
|
||||
// getSettings()->enableElevatedMessageHighlightSound.setValue(
|
||||
// value.toBool());
|
||||
}
|
||||
else if (rowIndex == HighlightRowIndexes::ThreadMessageRow)
|
||||
{
|
||||
getSettings()->enableThreadHighlightSound.setValue(
|
||||
value.toBool());
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -381,6 +431,11 @@ void HighlightModel::customRowSetData(const std::vector<QStandardItem *> &row,
|
||||
getSettings()->elevatedMessageHighlightSoundUrl.setValue(
|
||||
value.toString());
|
||||
}
|
||||
else if (rowIndex == HighlightRowIndexes::ThreadMessageRow)
|
||||
{
|
||||
getSettings()->threadHighlightSoundUrl.setValue(
|
||||
value.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -424,6 +479,13 @@ void HighlightModel::customRowSetData(const std::vector<QStandardItem *> &row,
|
||||
.updateColor(ColorType::ElevatedMessageHighlight,
|
||||
QColor(colorName));
|
||||
}
|
||||
else if (rowIndex == HighlightRowIndexes::ThreadMessageRow)
|
||||
{
|
||||
getSettings()->threadHighlightColor.setValue(colorName);
|
||||
const_cast<ColorProvider &>(ColorProvider::instance())
|
||||
.updateColor(ColorType::ThreadMessageHighlight,
|
||||
QColor(colorName));
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -32,6 +32,7 @@ public:
|
||||
RedeemedRow = 3,
|
||||
FirstMessageRow = 4,
|
||||
ElevatedMessageRow = 5,
|
||||
ThreadMessageRow = 6,
|
||||
};
|
||||
|
||||
protected:
|
||||
|
||||
@@ -16,6 +16,8 @@ QColor HighlightPhrase::FALLBACK_FIRST_MESSAGE_HIGHLIGHT_COLOR =
|
||||
QColor(72, 127, 63, 60);
|
||||
QColor HighlightPhrase::FALLBACK_ELEVATED_MESSAGE_HIGHLIGHT_COLOR =
|
||||
QColor(255, 174, 66, 60);
|
||||
QColor HighlightPhrase::FALLBACK_THREAD_HIGHLIGHT_COLOR =
|
||||
QColor(143, 48, 24, 60);
|
||||
QColor HighlightPhrase::FALLBACK_SUB_COLOR = QColor(196, 102, 255, 100);
|
||||
|
||||
bool HighlightPhrase::operator==(const HighlightPhrase &other) const
|
||||
|
||||
@@ -84,6 +84,7 @@ public:
|
||||
static QColor FALLBACK_SUB_COLOR;
|
||||
static QColor FALLBACK_FIRST_MESSAGE_HIGHLIGHT_COLOR;
|
||||
static QColor FALLBACK_ELEVATED_MESSAGE_HIGHLIGHT_COLOR;
|
||||
static QColor FALLBACK_THREAD_HIGHLIGHT_COLOR;
|
||||
|
||||
private:
|
||||
QString pattern_;
|
||||
|
||||
Reference in New Issue
Block a user