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
@@ -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);
@@ -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);
@@ -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
@@ -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