mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
Clean up highlight code
Fix bug if no account is selected
This commit is contained in:
parent
626002c8ff
commit
51f81262d5
2 changed files with 87 additions and 37 deletions
|
@ -34,6 +34,10 @@ TwitchMessageBuilder::TwitchMessageBuilder(Channel *_channel, Resources &_resour
|
||||||
|
|
||||||
SharedMessage TwitchMessageBuilder::parse()
|
SharedMessage TwitchMessageBuilder::parse()
|
||||||
{
|
{
|
||||||
|
SettingsManager &settings = SettingsManager::getInstance();
|
||||||
|
|
||||||
|
this->originalMessage = this->ircMessage->content();
|
||||||
|
|
||||||
// The timestamp is always appended to the builder
|
// The timestamp is always appended to the builder
|
||||||
// Whether or not will be rendered is decided/checked later
|
// Whether or not will be rendered is decided/checked later
|
||||||
this->appendTimestamp();
|
this->appendTimestamp();
|
||||||
|
@ -53,42 +57,8 @@ SharedMessage TwitchMessageBuilder::parse()
|
||||||
this->parseUsername();
|
this->parseUsername();
|
||||||
|
|
||||||
// highlights
|
// highlights
|
||||||
const QString &originalMessage = ircMessage->content();
|
if (settings.enableHighlights.get()) {
|
||||||
this->originalMessage = originalMessage;
|
this->parseHighlights();
|
||||||
SettingsManager &settings = SettingsManager::getInstance();
|
|
||||||
static auto player = new QMediaPlayer;
|
|
||||||
if (settings.customHighlightSound.get()) {
|
|
||||||
player->setMedia(QUrl(settings.pathHighlightSound.get()));
|
|
||||||
} else {
|
|
||||||
player->setMedia(QUrl("qrc:/sounds/ping2.wav"));
|
|
||||||
}
|
|
||||||
if (settings.enableHighlights.get() &&
|
|
||||||
ircMessage->nick().compare(settings.selectedUser.get(), Qt::CaseInsensitive)) {
|
|
||||||
if (settings.enableHighlightsSelf.get() &&
|
|
||||||
originalMessage.contains(settings.selectedUser.get(), Qt::CaseInsensitive)) {
|
|
||||||
this->setHighlight(true);
|
|
||||||
if (settings.enableHighlightSound.get()) {
|
|
||||||
player->play();
|
|
||||||
}
|
|
||||||
if (settings.enableHighlightTaskbar.get()) {
|
|
||||||
QApplication::alert(windowManager.getMainWindow().window(), 2500);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
QStringList lines = settings.highlightProperties.get().keys();
|
|
||||||
for (QString string : lines) {
|
|
||||||
if (originalMessage.contains(string, Qt::CaseInsensitive)) {
|
|
||||||
this->setHighlight(true);
|
|
||||||
// Sound
|
|
||||||
if (settings.highlightProperties.get().value(string).first) {
|
|
||||||
player->play();
|
|
||||||
}
|
|
||||||
// Taskbar
|
|
||||||
if (settings.highlightProperties.get().value(string).second) {
|
|
||||||
QApplication::alert(windowManager.getMainWindow().window(), 2500);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// bits
|
// bits
|
||||||
|
@ -126,7 +96,7 @@ SharedMessage TwitchMessageBuilder::parse()
|
||||||
// words
|
// words
|
||||||
QColor textColor = ircMessage->isAction() ? this->usernameColor : this->colorScheme.Text;
|
QColor textColor = ircMessage->isAction() ? this->usernameColor : this->colorScheme.Text;
|
||||||
|
|
||||||
QStringList splits = originalMessage.split(' ');
|
QStringList splits = this->originalMessage.split(' ');
|
||||||
|
|
||||||
long int i = 0;
|
long int i = 0;
|
||||||
|
|
||||||
|
@ -367,6 +337,85 @@ void TwitchMessageBuilder::parseUsername()
|
||||||
QString(), Link(Link::UserInfo, this->userName)));
|
QString(), Link(Link::UserInfo, this->userName)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TwitchMessageBuilder::parseHighlights()
|
||||||
|
{
|
||||||
|
static auto player = new QMediaPlayer;
|
||||||
|
SettingsManager &settings = SettingsManager::getInstance();
|
||||||
|
|
||||||
|
if (this->ircMessage->nick() == settings.selectedUser.get()) {
|
||||||
|
// Do nothing. Highlights cannot be triggered by yourself
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (settings.customHighlightSound.get()) {
|
||||||
|
player->setMedia(QUrl(settings.pathHighlightSound.get()));
|
||||||
|
} else {
|
||||||
|
player->setMedia(QUrl("qrc:/sounds/ping2.wav"));
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Highlight {
|
||||||
|
Highlight(const QString &_target, bool _sound, bool _alert)
|
||||||
|
: target(_target)
|
||||||
|
, sound(_sound)
|
||||||
|
, alert(_alert)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
QString target;
|
||||||
|
bool sound;
|
||||||
|
bool alert;
|
||||||
|
};
|
||||||
|
|
||||||
|
// TODO: This vector should only be rebuilt upon highlights being changed
|
||||||
|
std::vector<Highlight> activeHighlights;
|
||||||
|
|
||||||
|
if (settings.enableHighlightsSelf.get() && settings.selectedUser.get().size() > 0) {
|
||||||
|
activeHighlights.emplace_back(settings.selectedUser.get(),
|
||||||
|
settings.enableHighlightSound.get(),
|
||||||
|
settings.enableHighlightTaskbar.get());
|
||||||
|
}
|
||||||
|
const auto &highlightProperties = settings.highlightProperties.get();
|
||||||
|
|
||||||
|
for (auto it = highlightProperties.begin(); it != highlightProperties.end(); ++it) {
|
||||||
|
auto properties = it.value();
|
||||||
|
activeHighlights.emplace_back(it.key(), properties.first, properties.second);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool doHighlight = true;
|
||||||
|
bool playSound = false;
|
||||||
|
bool doAlert = false;
|
||||||
|
|
||||||
|
for (const Highlight &highlight : activeHighlights) {
|
||||||
|
if (this->originalMessage.contains(highlight.target, Qt::CaseInsensitive)) {
|
||||||
|
doHighlight = true;
|
||||||
|
|
||||||
|
if (highlight.sound) {
|
||||||
|
playSound = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (highlight.alert) {
|
||||||
|
doAlert = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (playSound && doAlert) {
|
||||||
|
// Break if no further action can be taken from other highlights
|
||||||
|
// This might change if highlights can have custom colors/sounds/actions
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this->setHighlight(doHighlight);
|
||||||
|
|
||||||
|
if (playSound) {
|
||||||
|
player->play();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (doAlert) {
|
||||||
|
QApplication::alert(windowManager.getMainWindow().window(), 2500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void TwitchMessageBuilder::appendModerationButtons()
|
void TwitchMessageBuilder::appendModerationButtons()
|
||||||
{
|
{
|
||||||
// mod buttons
|
// mod buttons
|
||||||
|
|
|
@ -59,6 +59,7 @@ private:
|
||||||
void parseRoomID();
|
void parseRoomID();
|
||||||
void parseChannelName();
|
void parseChannelName();
|
||||||
void parseUsername();
|
void parseUsername();
|
||||||
|
void parseHighlights();
|
||||||
|
|
||||||
void appendModerationButtons();
|
void appendModerationButtons();
|
||||||
void appendTwitchEmote(const Communi::IrcPrivateMessage *ircMessage, const QString &emote,
|
void appendTwitchEmote(const Communi::IrcPrivateMessage *ircMessage, const QString &emote,
|
||||||
|
|
Loading…
Reference in a new issue