Overhaul highlight system (#3399)
Checks have been moved into a Controller allowing for easier tests.
This commit is contained in:
@@ -34,6 +34,7 @@ struct MessageParseArgs {
|
||||
bool isSentWhisper = false;
|
||||
bool trimSubscriberUsername = false;
|
||||
bool isStaffOrBroadcaster = false;
|
||||
bool isSubscriptionMessage = false;
|
||||
QString channelPointRewardId = "";
|
||||
};
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include "Application.hpp"
|
||||
#include "common/QLogging.hpp"
|
||||
#include "controllers/highlights/HighlightController.hpp"
|
||||
#include "controllers/ignores/IgnoreController.hpp"
|
||||
#include "controllers/ignores/IgnorePhrase.hpp"
|
||||
#include "messages/MessageElement.hpp"
|
||||
@@ -140,259 +141,50 @@ void SharedMessageBuilder::parseUsername()
|
||||
|
||||
void SharedMessageBuilder::parseHighlights()
|
||||
{
|
||||
auto app = getApp();
|
||||
|
||||
if (getCSettings().isBlacklistedUser(this->ircMessage->nick()))
|
||||
{
|
||||
// Do nothing. We ignore highlights from this user.
|
||||
return;
|
||||
}
|
||||
|
||||
// Highlight because it's a whisper
|
||||
if (this->args.isReceivedWhisper && getSettings()->enableWhisperHighlight)
|
||||
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
|
||||
if (this->ircMessage->nick() == currentUser->getUserName())
|
||||
{
|
||||
if (getSettings()->enableWhisperHighlightTaskbar)
|
||||
{
|
||||
this->highlightAlert_ = true;
|
||||
}
|
||||
|
||||
if (getSettings()->enableWhisperHighlightSound)
|
||||
{
|
||||
this->highlightSound_ = true;
|
||||
|
||||
// Use custom sound if set, otherwise use fallback
|
||||
if (!getSettings()->whisperHighlightSoundUrl.getValue().isEmpty())
|
||||
{
|
||||
this->highlightSoundUrl_ =
|
||||
QUrl(getSettings()->whisperHighlightSoundUrl.getValue());
|
||||
}
|
||||
else
|
||||
{
|
||||
this->highlightSoundUrl_ = getFallbackHighlightSound();
|
||||
}
|
||||
}
|
||||
|
||||
this->message().highlightColor =
|
||||
ColorProvider::instance().color(ColorType::Whisper);
|
||||
|
||||
/*
|
||||
* Do _NOT_ return yet, we might want to apply phrase/user name
|
||||
* highlights (which override whisper color/sound).
|
||||
*/
|
||||
}
|
||||
|
||||
// Highlight because of sender
|
||||
auto userHighlights = getCSettings().highlightedUsers.readOnly();
|
||||
for (const HighlightPhrase &userHighlight : *userHighlights)
|
||||
{
|
||||
if (!userHighlight.isMatch(this->ircMessage->nick()))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
qCDebug(chatterinoMessage)
|
||||
<< "Highlight because user" << this->ircMessage->nick()
|
||||
<< "sent a message";
|
||||
|
||||
this->message().flags.set(MessageFlag::Highlighted);
|
||||
if (!(this->message().flags.has(MessageFlag::Subscription) &&
|
||||
getSettings()->enableSubHighlight))
|
||||
{
|
||||
this->message().highlightColor = userHighlight.getColor();
|
||||
}
|
||||
|
||||
if (userHighlight.showInMentions())
|
||||
{
|
||||
this->message().flags.set(MessageFlag::ShowInMentions);
|
||||
}
|
||||
|
||||
if (userHighlight.hasAlert())
|
||||
{
|
||||
this->highlightAlert_ = true;
|
||||
}
|
||||
|
||||
if (userHighlight.hasSound())
|
||||
{
|
||||
this->highlightSound_ = true;
|
||||
// Use custom sound if set, otherwise use the fallback sound
|
||||
if (userHighlight.hasCustomSound())
|
||||
{
|
||||
this->highlightSoundUrl_ = userHighlight.getSoundUrl();
|
||||
}
|
||||
else
|
||||
{
|
||||
this->highlightSoundUrl_ = getFallbackHighlightSound();
|
||||
}
|
||||
}
|
||||
|
||||
if (this->highlightAlert_ && this->highlightSound_)
|
||||
{
|
||||
/*
|
||||
* User name highlights "beat" highlight phrases: If a message has
|
||||
* all attributes (color, taskbar flashing, sound) set, highlight
|
||||
* phrases will not be checked.
|
||||
*/
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
auto currentUser = app->accounts->twitch.getCurrent();
|
||||
QString currentUsername = currentUser->getUserName();
|
||||
|
||||
if (this->ircMessage->nick() == currentUsername)
|
||||
{
|
||||
// Do nothing. Highlights cannot be triggered by yourself
|
||||
// Do nothing. We ignore any potential highlights from the logged in user
|
||||
return;
|
||||
}
|
||||
|
||||
// Highlight because it's a subscription
|
||||
if (this->message().flags.has(MessageFlag::Subscription) &&
|
||||
getSettings()->enableSubHighlight)
|
||||
auto badges = SharedMessageBuilder::parseBadgeTag(this->tags);
|
||||
auto [highlighted, highlightResult] = getApp()->highlights->check(
|
||||
this->args, badges, this->ircMessage->nick(), this->originalMessage_);
|
||||
|
||||
if (!highlighted)
|
||||
{
|
||||
if (getSettings()->enableSubHighlightTaskbar)
|
||||
{
|
||||
this->highlightAlert_ = true;
|
||||
}
|
||||
|
||||
if (getSettings()->enableSubHighlightSound)
|
||||
{
|
||||
this->highlightSound_ = true;
|
||||
|
||||
// Use custom sound if set, otherwise use fallback
|
||||
if (!getSettings()->subHighlightSoundUrl.getValue().isEmpty())
|
||||
{
|
||||
this->highlightSoundUrl_ =
|
||||
QUrl(getSettings()->subHighlightSoundUrl.getValue());
|
||||
}
|
||||
else
|
||||
{
|
||||
this->highlightSoundUrl_ = getFallbackHighlightSound();
|
||||
}
|
||||
}
|
||||
|
||||
this->message().flags.set(MessageFlag::Highlighted);
|
||||
this->message().highlightColor =
|
||||
ColorProvider::instance().color(ColorType::Subscription);
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: This vector should only be rebuilt upon highlights being changed
|
||||
// fourtf: should be implemented in the HighlightsController
|
||||
std::vector<HighlightPhrase> activeHighlights =
|
||||
getSettings()->highlightedMessages.cloneVector();
|
||||
// This message triggered one or more highlights, act upon the highlight result
|
||||
|
||||
if (!currentUser->isAnon() && getSettings()->enableSelfHighlight &&
|
||||
currentUsername.size() > 0)
|
||||
this->message().flags.set(MessageFlag::Highlighted);
|
||||
|
||||
this->highlightAlert_ = highlightResult.alert;
|
||||
|
||||
this->highlightSound_ = highlightResult.playSound;
|
||||
|
||||
this->message().highlightColor = highlightResult.color;
|
||||
|
||||
if (highlightResult.customSoundUrl)
|
||||
{
|
||||
HighlightPhrase selfHighlight(
|
||||
currentUsername, getSettings()->showSelfHighlightInMentions,
|
||||
getSettings()->enableSelfHighlightTaskbar,
|
||||
getSettings()->enableSelfHighlightSound, false, false,
|
||||
getSettings()->selfHighlightSoundUrl.getValue(),
|
||||
ColorProvider::instance().color(ColorType::SelfHighlight));
|
||||
activeHighlights.emplace_back(std::move(selfHighlight));
|
||||
this->highlightSoundUrl_ = highlightResult.customSoundUrl.get();
|
||||
}
|
||||
else
|
||||
{
|
||||
this->highlightSoundUrl_ = getFallbackHighlightSound();
|
||||
}
|
||||
|
||||
// Highlight because of message
|
||||
for (const HighlightPhrase &highlight : activeHighlights)
|
||||
if (highlightResult.showInMentions)
|
||||
{
|
||||
if (!highlight.isMatch(this->originalMessage_))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
this->message().flags.set(MessageFlag::Highlighted);
|
||||
if (!(this->message().flags.has(MessageFlag::Subscription) &&
|
||||
getSettings()->enableSubHighlight))
|
||||
{
|
||||
this->message().highlightColor = highlight.getColor();
|
||||
}
|
||||
|
||||
if (highlight.showInMentions())
|
||||
{
|
||||
this->message().flags.set(MessageFlag::ShowInMentions);
|
||||
}
|
||||
|
||||
if (highlight.hasAlert())
|
||||
{
|
||||
this->highlightAlert_ = true;
|
||||
}
|
||||
|
||||
// Only set highlightSound_ if it hasn't been set by username
|
||||
// highlights already.
|
||||
if (highlight.hasSound() && !this->highlightSound_)
|
||||
{
|
||||
this->highlightSound_ = true;
|
||||
|
||||
// Use custom sound if set, otherwise use fallback sound
|
||||
if (highlight.hasCustomSound())
|
||||
{
|
||||
this->highlightSoundUrl_ = highlight.getSoundUrl();
|
||||
}
|
||||
else
|
||||
{
|
||||
this->highlightSoundUrl_ = getFallbackHighlightSound();
|
||||
}
|
||||
}
|
||||
|
||||
if (this->highlightAlert_ && this->highlightSound_)
|
||||
{
|
||||
/*
|
||||
* Break once no further attributes (taskbar, sound) can be
|
||||
* applied.
|
||||
*/
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Highlight because of badge
|
||||
auto badges = this->parseBadgeTag(this->tags);
|
||||
auto badgeHighlights = getCSettings().highlightedBadges.readOnly();
|
||||
bool badgeHighlightSet = false;
|
||||
for (const HighlightBadge &highlight : *badgeHighlights)
|
||||
{
|
||||
for (const Badge &badge : badges)
|
||||
{
|
||||
if (!highlight.isMatch(badge))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!badgeHighlightSet)
|
||||
{
|
||||
this->message().flags.set(MessageFlag::Highlighted);
|
||||
if (!(this->message().flags.has(MessageFlag::Subscription) &&
|
||||
getSettings()->enableSubHighlight))
|
||||
{
|
||||
this->message().highlightColor = highlight.getColor();
|
||||
}
|
||||
|
||||
badgeHighlightSet = true;
|
||||
}
|
||||
|
||||
if (highlight.hasAlert())
|
||||
{
|
||||
this->highlightAlert_ = true;
|
||||
}
|
||||
|
||||
// Only set highlightSound_ if it hasn't been set by badge
|
||||
// highlights already.
|
||||
if (highlight.hasSound() && !this->highlightSound_)
|
||||
{
|
||||
this->highlightSound_ = true;
|
||||
// Use custom sound if set, otherwise use fallback sound
|
||||
this->highlightSoundUrl_ = highlight.hasCustomSound()
|
||||
? highlight.getSoundUrl()
|
||||
: getFallbackHighlightSound();
|
||||
}
|
||||
|
||||
if (this->highlightAlert_ && this->highlightSound_)
|
||||
{
|
||||
/*
|
||||
* Break once no further attributes (taskbar, sound) can be
|
||||
* applied.
|
||||
*/
|
||||
break;
|
||||
}
|
||||
}
|
||||
this->message().flags.set(MessageFlag::ShowInMentions);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user