Add highlighting of all messages from a certain user (#564)

* Rework to use controllers

* Rework to use controllers

* Add doHighlight

* Cherry pick?

* Fixes per PR

* Remove file
This commit is contained in:
DatGuy1 2018-07-05 16:58:20 +03:00 committed by fourtf
parent eb69cbf5f5
commit 9c7c99928f
7 changed files with 135 additions and 0 deletions

View file

@ -113,6 +113,7 @@ SOURCES += \
src/controllers/highlights/HighlightController.cpp \
src/controllers/highlights/HighlightModel.cpp \
src/controllers/highlights/HighlightBlacklistModel.cpp \
src/controllers/highlights/UserHighlightModel.cpp \
src/controllers/ignores/IgnoreController.cpp \
src/controllers/ignores/IgnoreModel.cpp \
src/controllers/taggedusers/TaggedUser.cpp \
@ -260,6 +261,7 @@ HEADERS += \
src/controllers/highlights/HighlightBlacklistModel.hpp \
src/controllers/highlights/HighlightPhrase.hpp \
src/controllers/highlights/HighlightBlacklistUser.hpp \
src/controllers/highlights/UserHighlightModel.hpp \
src/controllers/ignores/IgnoreController.hpp \
src/controllers/ignores/IgnoreModel.hpp \
src/controllers/ignores/IgnorePhrase.hpp \

View file

@ -3,6 +3,7 @@
#include "Application.hpp"
#include "controllers/highlights/HighlightBlacklistModel.hpp"
#include "controllers/highlights/HighlightModel.hpp"
#include "controllers/highlights/UserHighlightModel.hpp"
#include "widgets/dialogs/NotificationPopup.hpp"
namespace chatterino {
@ -33,6 +34,26 @@ HighlightModel *HighlightController::createModel(QObject *parent)
return model;
}
UserHighlightModel *HighlightController::createUserModel(QObject *parent)
{
auto *model = new UserHighlightModel(parent);
model->init(&this->highlightedUsers);
return model;
}
bool HighlightController::isHighlightedUser(const QString &username)
{
const auto &userItems = this->highlightedUsers.getVector();
for (const auto &highlightedUser : userItems) {
if (highlightedUser.isMatch(username)) {
return true;
}
}
return false;
}
HighlightBlacklistModel *HighlightController::createBlacklistModel(QObject *parent)
{
auto *model = new HighlightBlacklistModel(parent);

View file

@ -8,6 +8,7 @@
namespace chatterino {
class UserHighlightModel;
class HighlightModel;
class HighlightBlacklistModel;
@ -20,10 +21,13 @@ public:
UnsortedSignalVector<HighlightPhrase> phrases;
UnsortedSignalVector<HighlightBlacklistUser> blacklistedUsers;
UnsortedSignalVector<HighlightPhrase> highlightedUsers;
HighlightModel *createModel(QObject *parent);
HighlightBlacklistModel *createBlacklistModel(QObject *parent);
UserHighlightModel *createUserModel(QObject *parent);
bool isHighlightedUser(const QString &username);
bool blacklistContains(const QString &username);
void addHighlight(const MessagePtr &msg);

View file

@ -0,0 +1,27 @@
#pragma once
#include <QObject>
#include "common/SignalVectorModel.hpp"
#include "controllers/highlights/HighlightPhrase.hpp"
namespace chatterino {
class HighlightController;
class UserHighlightModel : public SignalVectorModel<HighlightPhrase>
{
explicit UserHighlightModel(QObject *parent);
protected:
// vector into model row
virtual HighlightPhrase getItemFromRow(std::vector<QStandardItem *> &row,
const HighlightPhrase &original) override;
virtual void getRowFromItem(const HighlightPhrase &item,
std::vector<QStandardItem *> &row) override;
friend class HighlightController;
};
} // namespace chatterino

View file

@ -0,0 +1,36 @@
#include "UserHighlightModel.hpp"
#include "Application.hpp"
#include "singletons/Settings.hpp"
#include "util/StandardItemHelper.hpp"
namespace chatterino {
// commandmodel
UserHighlightModel::UserHighlightModel(QObject *parent)
: SignalVectorModel<HighlightPhrase>(4, parent)
{
}
// turn vector item into model row
HighlightPhrase UserHighlightModel::getItemFromRow(std::vector<QStandardItem *> &row,
const HighlightPhrase &original)
{
// key, regex
return HighlightPhrase{
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
void UserHighlightModel::getRowFromItem(const HighlightPhrase &item,
std::vector<QStandardItem *> &row)
{
setStringItem(row[0], item.getPattern());
setBoolItem(row[1], item.getAlert());
setBoolItem(row[2], item.getSound());
setBoolItem(row[3], item.isRegex());
}
} // namespace chatterino

View file

@ -465,6 +465,7 @@ void TwitchMessageBuilder::parseHighlights()
// TODO: This vector should only be rebuilt upon highlights being changed
// fourtf: should be implemented in the HighlightsController
std::vector<HighlightPhrase> activeHighlights = app->highlights->phrases.getVector();
std::vector<HighlightPhrase> userHighlights = app->highlights->highlightedUsers.getVector();
if (app->settings->enableHighlightsSelf && currentUsername.size() > 0) {
HighlightPhrase selfHighlight(currentUsername, app->settings->enableHighlightTaskbar,
@ -500,6 +501,26 @@ void TwitchMessageBuilder::parseHighlights()
}
}
}
for (const HighlightPhrase &userHighlight : userHighlights) {
if (userHighlight.isMatch(this->ircMessage->nick())) {
Log("Highlight because user {} sent a message", this->ircMessage->nick());
doHighlight = true;
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);

View file

@ -4,6 +4,7 @@
#include "controllers/highlights/HighlightBlacklistModel.hpp"
#include "controllers/highlights/HighlightController.hpp"
#include "controllers/highlights/HighlightModel.hpp"
#include "controllers/highlights/UserHighlightModel.hpp"
#include "debug/Log.hpp"
#include "singletons/Settings.hpp"
#include "util/LayoutCreator.hpp"
@ -88,6 +89,29 @@ HighlightingPage::HighlightingPage()
HighlightBlacklistUser{"blacklisted user", false});
});
}
auto pingUsers = tabs.appendTab(new QVBoxLayout, "Highlight on message");
{
EditableModelView *view =
pingUsers.emplace<EditableModelView>(app->highlights->createUserModel(nullptr))
.getElement();
view->setTitles({"Username", "Flash taskbar", "Play sound", "Regex"});
view->getTableView()->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed);
view->getTableView()->horizontalHeader()->setSectionResizeMode(
0, QHeaderView::Stretch);
// fourtf: make class extrend BaseWidget and add this to dpiChanged
QTimer::singleShot(1, [view] {
view->getTableView()->resizeColumnsToContents();
view->getTableView()->setColumnWidth(0, 200);
});
view->addButtonPressed.connect([] {
getApp()->highlights->highlightedUsers.appendItem(
HighlightPhrase{"highlighted user", true, false, false});
});
}
}
// MISC