mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
Added option to highlight your own messages (#3833)
* Removed magic numbers when checking rowIndex * Swap from static ints to enum * Referred enum members by enum name * Fixed formatting * Added highlight option for self messages * Update CHANGELOG.md * Made disabled by default * Moved setting from Messages tab to Users tab * Moved checks to HighlightController * Set row index to 0 sillE silly me * Update CHANGELOG.md * Moved check outside of loop * Improved naming and documentation on variables * Fixed formatting * Fix compile errors * Update ColorProvider self message highlight color when it's changed Use the ColorProvider self message highlight color instead of rolling our own non-updating color * Update changelog entry * Remove unused `customColor` from user highlights builder * Use explicit lambda capture * Update comment for the color provider color * HighlightModelHpp: Future-proof custom row enum B) * Document UserHighlightModel color changes * Update colorprovider comment * Update enabled, show in mentions & color setting paths * Rename settings from `selfMessagesHighlight` to `selfMessageHighlight` --------- Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com>
This commit is contained in:
parent
bfa899c45e
commit
d6ccab2cdf
10 changed files with 154 additions and 0 deletions
|
@ -3,6 +3,7 @@
|
||||||
## Unversioned
|
## Unversioned
|
||||||
|
|
||||||
- Major: Added live emote updates for BTTV (#4147)
|
- Major: Added live emote updates for BTTV (#4147)
|
||||||
|
- Minor: Added option to highlight your own messages in Highlights page under Users tab. (#3833)
|
||||||
- Minor: Change the highlight order to prioritize Message highlights over User highlights. (#4303)
|
- Minor: Change the highlight order to prioritize Message highlights over User highlights. (#4303)
|
||||||
- Minor: Added ability to negate search options by prefixing it with an exclamation mark (e.g. `!badge:mod` to search for messages where the author does not have the moderator badge). (#4207)
|
- Minor: Added ability to negate search options by prefixing it with an exclamation mark (e.g. `!badge:mod` to search for messages where the author does not have the moderator badge). (#4207)
|
||||||
- Minor: Search window input will automatically use currently selected text if present. (#4178)
|
- Minor: Search window input will automatically use currently selected text if present. (#4178)
|
||||||
|
|
|
@ -210,6 +210,35 @@ void rebuildUserHighlights(Settings &settings,
|
||||||
{
|
{
|
||||||
auto userHighlights = settings.highlightedUsers.readOnly();
|
auto userHighlights = settings.highlightedUsers.readOnly();
|
||||||
|
|
||||||
|
if (settings.enableSelfMessageHighlight)
|
||||||
|
{
|
||||||
|
bool showInMentions = settings.showSelfMessageHighlightInMentions;
|
||||||
|
|
||||||
|
checks.emplace_back(HighlightCheck{
|
||||||
|
[showInMentions](
|
||||||
|
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
|
||||||
|
(void)originalMessage; //unused
|
||||||
|
|
||||||
|
if (!self)
|
||||||
|
{
|
||||||
|
return boost::none;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Highlight color is provided by the ColorProvider and will be updated accordingly
|
||||||
|
auto highlightColor = ColorProvider::instance().color(
|
||||||
|
ColorType::SelfMessageHighlight);
|
||||||
|
|
||||||
|
return HighlightResult{false, false, (QUrl) nullptr,
|
||||||
|
highlightColor, showInMentions};
|
||||||
|
}});
|
||||||
|
}
|
||||||
|
|
||||||
for (const auto &highlight : *userHighlights)
|
for (const auto &highlight : *userHighlights)
|
||||||
{
|
{
|
||||||
checks.emplace_back(HighlightCheck{
|
checks.emplace_back(HighlightCheck{
|
||||||
|
@ -391,6 +420,11 @@ void HighlightController::initialize(Settings &settings, Paths & /*paths*/)
|
||||||
this->rebuildListener_.addSetting(settings.enableSubHighlight);
|
this->rebuildListener_.addSetting(settings.enableSubHighlight);
|
||||||
this->rebuildListener_.addSetting(settings.enableSubHighlightSound);
|
this->rebuildListener_.addSetting(settings.enableSubHighlightSound);
|
||||||
this->rebuildListener_.addSetting(settings.enableSubHighlightTaskbar);
|
this->rebuildListener_.addSetting(settings.enableSubHighlightTaskbar);
|
||||||
|
this->rebuildListener_.addSetting(settings.enableSelfMessageHighlight);
|
||||||
|
this->rebuildListener_.addSetting(
|
||||||
|
settings.showSelfMessageHighlightInMentions);
|
||||||
|
// We do not need to rebuild the listener for the selfMessagesHighlightColor
|
||||||
|
// The color is dynamically fetched any time the self message highlight is triggered
|
||||||
this->rebuildListener_.addSetting(settings.subHighlightSoundUrl);
|
this->rebuildListener_.addSetting(settings.subHighlightSoundUrl);
|
||||||
|
|
||||||
this->rebuildListener_.addSetting(settings.enableThreadHighlight);
|
this->rebuildListener_.addSetting(settings.enableThreadHighlight);
|
||||||
|
|
|
@ -36,6 +36,10 @@ public:
|
||||||
ThreadMessageRow = 6,
|
ThreadMessageRow = 6,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum UserHighlightRowIndexes {
|
||||||
|
SelfMessageRow = 0,
|
||||||
|
};
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// turn a vector item into a model row
|
// turn a vector item into a model row
|
||||||
virtual HighlightPhrase getItemFromRow(
|
virtual HighlightPhrase getItemFromRow(
|
||||||
|
|
|
@ -10,6 +10,8 @@ namespace {
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
QColor HighlightPhrase::FALLBACK_HIGHLIGHT_COLOR = QColor(127, 63, 73, 127);
|
QColor HighlightPhrase::FALLBACK_HIGHLIGHT_COLOR = QColor(127, 63, 73, 127);
|
||||||
|
QColor HighlightPhrase::FALLBACK_SELF_MESSAGE_HIGHLIGHT_COLOR =
|
||||||
|
QColor(0, 118, 221, 115);
|
||||||
QColor HighlightPhrase::FALLBACK_REDEEMED_HIGHLIGHT_COLOR =
|
QColor HighlightPhrase::FALLBACK_REDEEMED_HIGHLIGHT_COLOR =
|
||||||
QColor(28, 126, 141, 60);
|
QColor(28, 126, 141, 60);
|
||||||
QColor HighlightPhrase::FALLBACK_FIRST_MESSAGE_HIGHLIGHT_COLOR =
|
QColor HighlightPhrase::FALLBACK_FIRST_MESSAGE_HIGHLIGHT_COLOR =
|
||||||
|
|
|
@ -79,6 +79,8 @@ public:
|
||||||
* Qt>=5.13.
|
* Qt>=5.13.
|
||||||
*/
|
*/
|
||||||
static QColor FALLBACK_HIGHLIGHT_COLOR;
|
static QColor FALLBACK_HIGHLIGHT_COLOR;
|
||||||
|
// Used for automatic self messages highlighing
|
||||||
|
static QColor FALLBACK_SELF_MESSAGE_HIGHLIGHT_COLOR;
|
||||||
static QColor FALLBACK_REDEEMED_HIGHLIGHT_COLOR;
|
static QColor FALLBACK_REDEEMED_HIGHLIGHT_COLOR;
|
||||||
static QColor FALLBACK_SUB_COLOR;
|
static QColor FALLBACK_SUB_COLOR;
|
||||||
static QColor FALLBACK_FIRST_MESSAGE_HIGHLIGHT_COLOR;
|
static QColor FALLBACK_FIRST_MESSAGE_HIGHLIGHT_COLOR;
|
||||||
|
|
|
@ -3,7 +3,9 @@
|
||||||
#include "Application.hpp"
|
#include "Application.hpp"
|
||||||
#include "controllers/highlights/HighlightModel.hpp"
|
#include "controllers/highlights/HighlightModel.hpp"
|
||||||
#include "controllers/highlights/HighlightPhrase.hpp"
|
#include "controllers/highlights/HighlightPhrase.hpp"
|
||||||
|
#include "providers/colors/ColorProvider.hpp"
|
||||||
#include "singletons/Settings.hpp"
|
#include "singletons/Settings.hpp"
|
||||||
|
#include "singletons/WindowManager.hpp"
|
||||||
#include "util/StandardItemHelper.hpp"
|
#include "util/StandardItemHelper.hpp"
|
||||||
|
|
||||||
namespace chatterino {
|
namespace chatterino {
|
||||||
|
@ -37,6 +39,86 @@ HighlightPhrase UserHighlightModel::getItemFromRow(
|
||||||
highlightColor};
|
highlightColor};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UserHighlightModel::afterInit()
|
||||||
|
{
|
||||||
|
// User highlight settings for your own messages
|
||||||
|
std::vector<QStandardItem *> messagesRow = this->createRow();
|
||||||
|
setBoolItem(messagesRow[Column::Pattern],
|
||||||
|
getSettings()->enableSelfMessageHighlight.getValue(), true,
|
||||||
|
false);
|
||||||
|
messagesRow[Column::Pattern]->setData("Your messages (automatic)",
|
||||||
|
Qt::DisplayRole);
|
||||||
|
setBoolItem(messagesRow[Column::ShowInMentions],
|
||||||
|
getSettings()->showSelfMessageHighlightInMentions.getValue(),
|
||||||
|
true, false);
|
||||||
|
messagesRow[Column::FlashTaskbar]->setFlags({});
|
||||||
|
messagesRow[Column::PlaySound]->setFlags({});
|
||||||
|
messagesRow[Column::UseRegex]->setFlags({});
|
||||||
|
messagesRow[Column::CaseSensitive]->setFlags({});
|
||||||
|
messagesRow[Column::SoundPath]->setFlags({});
|
||||||
|
|
||||||
|
auto selfColor =
|
||||||
|
ColorProvider::instance().color(ColorType::SelfMessageHighlight);
|
||||||
|
setColorItem(messagesRow[Column::Color], *selfColor, false);
|
||||||
|
|
||||||
|
this->insertCustomRow(
|
||||||
|
messagesRow, HighlightModel::UserHighlightRowIndexes::SelfMessageRow);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UserHighlightModel::customRowSetData(
|
||||||
|
const std::vector<QStandardItem *> &row, int column, const QVariant &value,
|
||||||
|
int role, int rowIndex)
|
||||||
|
{
|
||||||
|
switch (column)
|
||||||
|
{
|
||||||
|
case Column::Pattern: {
|
||||||
|
if (role == Qt::CheckStateRole)
|
||||||
|
{
|
||||||
|
if (rowIndex ==
|
||||||
|
HighlightModel::UserHighlightRowIndexes::SelfMessageRow)
|
||||||
|
{
|
||||||
|
getSettings()->enableSelfMessageHighlight.setValue(
|
||||||
|
value.toBool());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case Column::ShowInMentions: {
|
||||||
|
if (role == Qt::CheckStateRole)
|
||||||
|
{
|
||||||
|
if (rowIndex ==
|
||||||
|
HighlightModel::UserHighlightRowIndexes::SelfMessageRow)
|
||||||
|
{
|
||||||
|
getSettings()->showSelfMessageHighlightInMentions.setValue(
|
||||||
|
value.toBool());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case Column::Color: {
|
||||||
|
// Custom color
|
||||||
|
if (role == Qt::DecorationRole)
|
||||||
|
{
|
||||||
|
auto colorName = value.value<QColor>().name(QColor::HexArgb);
|
||||||
|
if (rowIndex ==
|
||||||
|
HighlightModel::UserHighlightRowIndexes::SelfMessageRow)
|
||||||
|
{
|
||||||
|
// Update the setting with the new value
|
||||||
|
getSettings()->selfMessageHighlightColor.setValue(
|
||||||
|
colorName);
|
||||||
|
// Update the color provider with the new color to be used for future
|
||||||
|
const_cast<ColorProvider &>(ColorProvider::instance())
|
||||||
|
.updateColor(ColorType::SelfMessageHighlight,
|
||||||
|
QColor(colorName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
getApp()->windows->forceLayoutChannelViews();
|
||||||
|
}
|
||||||
|
|
||||||
// row into vector item
|
// row into vector item
|
||||||
void UserHighlightModel::getRowFromItem(const HighlightPhrase &item,
|
void UserHighlightModel::getRowFromItem(const HighlightPhrase &item,
|
||||||
std::vector<QStandardItem *> &row)
|
std::vector<QStandardItem *> &row)
|
||||||
|
|
|
@ -22,6 +22,12 @@ protected:
|
||||||
|
|
||||||
virtual void getRowFromItem(const HighlightPhrase &item,
|
virtual void getRowFromItem(const HighlightPhrase &item,
|
||||||
std::vector<QStandardItem *> &row) override;
|
std::vector<QStandardItem *> &row) override;
|
||||||
|
|
||||||
|
virtual void afterInit() override;
|
||||||
|
|
||||||
|
virtual void customRowSetData(const std::vector<QStandardItem *> &row,
|
||||||
|
int column, const QVariant &value, int role,
|
||||||
|
int rowIndex) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace chatterino
|
} // namespace chatterino
|
||||||
|
|
|
@ -81,6 +81,20 @@ void ColorProvider::initTypeColorMap()
|
||||||
HighlightPhrase::FALLBACK_HIGHLIGHT_COLOR)});
|
HighlightPhrase::FALLBACK_HIGHLIGHT_COLOR)});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
customColor = getSettings()->selfMessageHighlightColor;
|
||||||
|
if (QColor(customColor).isValid())
|
||||||
|
{
|
||||||
|
this->typeColorMap_.insert({ColorType::SelfMessageHighlight,
|
||||||
|
std::make_shared<QColor>(customColor)});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this->typeColorMap_.insert(
|
||||||
|
{ColorType::SelfMessageHighlight,
|
||||||
|
std::make_shared<QColor>(
|
||||||
|
HighlightPhrase::FALLBACK_SELF_MESSAGE_HIGHLIGHT_COLOR)});
|
||||||
|
}
|
||||||
|
|
||||||
customColor = getSettings()->subHighlightColor;
|
customColor = getSettings()->subHighlightColor;
|
||||||
if (QColor(customColor).isValid())
|
if (QColor(customColor).isValid())
|
||||||
{
|
{
|
||||||
|
|
|
@ -16,6 +16,8 @@ enum class ColorType {
|
||||||
FirstMessageHighlight,
|
FirstMessageHighlight,
|
||||||
ElevatedMessageHighlight,
|
ElevatedMessageHighlight,
|
||||||
ThreadMessageHighlight,
|
ThreadMessageHighlight,
|
||||||
|
// Used in automatic highlights of your own messages
|
||||||
|
SelfMessageHighlight,
|
||||||
};
|
};
|
||||||
|
|
||||||
class ColorProvider
|
class ColorProvider
|
||||||
|
|
|
@ -288,6 +288,13 @@ public:
|
||||||
QStringSetting selfHighlightColor = {"/highlighting/selfHighlightColor",
|
QStringSetting selfHighlightColor = {"/highlighting/selfHighlightColor",
|
||||||
""};
|
""};
|
||||||
|
|
||||||
|
BoolSetting enableSelfMessageHighlight = {
|
||||||
|
"/highlighting/selfMessageHighlight/enabled", false};
|
||||||
|
BoolSetting showSelfMessageHighlightInMentions = {
|
||||||
|
"/highlighting/selfMessageHighlight/showInMentions", false};
|
||||||
|
QStringSetting selfMessageHighlightColor = {
|
||||||
|
"/highlighting/selfMessageHighlight/color", ""};
|
||||||
|
|
||||||
BoolSetting enableWhisperHighlight = {
|
BoolSetting enableWhisperHighlight = {
|
||||||
"/highlighting/whisperHighlight/whispersHighlighted", true};
|
"/highlighting/whisperHighlight/whispersHighlighted", true};
|
||||||
BoolSetting enableWhisperHighlightSound = {
|
BoolSetting enableWhisperHighlightSound = {
|
||||||
|
|
Loading…
Reference in a new issue