From 971326212c0ab909603e1f76bd565b113e7907be Mon Sep 17 00:00:00 2001 From: datguy Date: Wed, 4 Jul 2018 18:59:48 +0300 Subject: [PATCH] Rework to use controllers --- .../highlights/userhighlightmodel.cpp | 11 ++++--- src/providers/twitch/TwitchMessageBuilder.cpp | 30 ++++++++++++++----- .../settingspages/HighlightingPage.cpp | 4 +-- 3 files changed, 31 insertions(+), 14 deletions(-) diff --git a/src/controllers/highlights/userhighlightmodel.cpp b/src/controllers/highlights/userhighlightmodel.cpp index 50592d1c2..5aef0375d 100644 --- a/src/controllers/highlights/userhighlightmodel.cpp +++ b/src/controllers/highlights/userhighlightmodel.cpp @@ -8,7 +8,7 @@ namespace chatterino { // commandmodel UserHighlightModel::UserHighlightModel(QObject *parent) - : SignalVectorModel(2, parent) + : SignalVectorModel(4, parent) { } @@ -18,8 +18,9 @@ UserHighlight UserHighlightModel::getItemFromRow(std::vector &r { // key, regex - return UserHighlight{row[0]->data(Qt::DisplayRole).toString(), - row[1]->data(Qt::CheckStateRole).toBool()}; + return UserHighlight{ + row[0]->data(Qt::DisplayRole).toString(), row[1]->data(Qt::CheckStateRole).toBool(), + row[2]->data(Qt::CheckStateRole).toBool(), row[3]->data(Qt::CheckStateRole).toBool()}; } // row into vector item @@ -27,7 +28,9 @@ void UserHighlightModel::getRowFromItem(const UserHighlight &item, std::vector &row) { setStringItem(row[0], item.getPattern()); - setBoolItem(row[1], item.isRegex()); + setBoolItem(row[1], item.getAlert()); + setBoolItem(row[2], item.getSound()); + setBoolItem(row[3], item.isRegex()); } } // namespace chatterino diff --git a/src/providers/twitch/TwitchMessageBuilder.cpp b/src/providers/twitch/TwitchMessageBuilder.cpp index a4ccd06cf..4f9fef769 100644 --- a/src/providers/twitch/TwitchMessageBuilder.cpp +++ b/src/providers/twitch/TwitchMessageBuilder.cpp @@ -443,6 +443,7 @@ void TwitchMessageBuilder::parseHighlights() // TODO: This vector should only be rebuilt upon highlights being changed // fourtf: should be implemented in the HighlightsController std::vector activeHighlights = app->highlights->phrases.getVector(); + std::vector userHighlights = app->highlights->highlightedUsers.getVector(); if (app->settings->enableHighlightsSelf && currentUsername.size() > 0) { HighlightPhrase selfHighlight(currentUsername, app->settings->enableHighlightTaskbar, @@ -458,14 +459,9 @@ void TwitchMessageBuilder::parseHighlights() if (!app->highlights->blacklistContains(this->ircMessage->nick())) { for (const HighlightPhrase &highlight : activeHighlights) { - if (highlight.isMatch(this->originalMessage) || - app->highlights->userContains(this->ircMessage->nick())) { - if (app->highlights->userContains(this->ircMessage->nick())) { - Log("Highlight because user {} sent a message", this->ircMessage->nick()); - } else { - Log("Highlight because {} matches {}", this->originalMessage, - highlight.getPattern()); - } + if (highlight.isMatch(this->originalMessage)) { + Log("Highlight because {} matches {}", this->originalMessage, + highlight.getPattern()); doHighlight = true; if (highlight.getAlert()) { @@ -483,6 +479,24 @@ void TwitchMessageBuilder::parseHighlights() } } } + for (const UserHighlight &userHighlight : userHighlights) { + if (userHighlight.isMatch(this->ircMessage->nick())) { + Log("Highlight because user {} sent a message", this->ircMessage->nick()); + if (userHighlight.getAlert()) { + doAlert = true; + } + + if (userHighlight.getSound()) { + playSound = true; + } + + if (playSound && doAlert) { + // Break if no further action can be taken from other usernames + // Mostly used for regex stuff + break; + } + } + } this->setHighlight(doHighlight); diff --git a/src/widgets/settingspages/HighlightingPage.cpp b/src/widgets/settingspages/HighlightingPage.cpp index 06e1daa1f..be8bf83e3 100644 --- a/src/widgets/settingspages/HighlightingPage.cpp +++ b/src/widgets/settingspages/HighlightingPage.cpp @@ -96,7 +96,7 @@ HighlightingPage::HighlightingPage() pingUsers.emplace(app->highlights->createUserModel(nullptr)) .getElement(); - view->setTitles({"Username", "Regex"}); + view->setTitles({"Username", "Flash taskbar", "Play sound", "Regex"}); view->getTableView()->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed); view->getTableView()->horizontalHeader()->setSectionResizeMode( 0, QHeaderView::Stretch); @@ -109,7 +109,7 @@ HighlightingPage::HighlightingPage() view->addButtonPressed.connect([] { getApp()->highlights->highlightedUsers.appendItem( - UserHighlight{"highlighted user", false}); + UserHighlight{"highlighted user", true, false, false}); }); } }