2018-06-26 14:09:39 +02:00
|
|
|
#include "HighlightController.hpp"
|
2018-05-06 00:32:45 +02:00
|
|
|
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "Application.hpp"
|
2018-07-04 13:22:27 +02:00
|
|
|
#include "controllers/highlights/HighlightBlacklistModel.hpp"
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "controllers/highlights/HighlightModel.hpp"
|
2018-07-05 15:58:20 +02:00
|
|
|
#include "controllers/highlights/UserHighlightModel.hpp"
|
2018-06-26 15:11:45 +02:00
|
|
|
#include "widgets/dialogs/NotificationPopup.hpp"
|
2018-05-06 00:32:45 +02:00
|
|
|
|
|
|
|
namespace chatterino {
|
|
|
|
|
|
|
|
HighlightController::HighlightController()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-08-02 14:23:27 +02:00
|
|
|
void HighlightController::initialize(Settings &settings, Paths &paths)
|
2018-05-06 00:32:45 +02:00
|
|
|
{
|
2018-07-06 18:10:21 +02:00
|
|
|
assert(!this->initialized_);
|
|
|
|
this->initialized_ = true;
|
2018-05-06 00:32:45 +02:00
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
for (const HighlightPhrase &phrase : this->highlightsSetting_.getValue())
|
|
|
|
{
|
2018-05-06 00:32:45 +02:00
|
|
|
this->phrases.appendItem(phrase);
|
|
|
|
}
|
|
|
|
|
|
|
|
this->phrases.delayedItemsChanged.connect([this] { //
|
2018-07-06 18:10:21 +02:00
|
|
|
this->highlightsSetting_.setValue(this->phrases.getVector());
|
2018-05-06 00:32:45 +02:00
|
|
|
});
|
2018-07-16 17:09:29 +02:00
|
|
|
|
2018-08-06 21:17:03 +02:00
|
|
|
for (const HighlightBlacklistUser &blacklistedUser :
|
2018-10-21 13:43:02 +02:00
|
|
|
this->blacklistSetting_.getValue())
|
|
|
|
{
|
2018-07-16 17:09:29 +02:00
|
|
|
this->blacklistedUsers.appendItem(blacklistedUser);
|
|
|
|
}
|
|
|
|
|
2018-08-06 21:17:03 +02:00
|
|
|
this->blacklistedUsers.delayedItemsChanged.connect([this] {
|
|
|
|
this->blacklistSetting_.setValue(this->blacklistedUsers.getVector());
|
|
|
|
});
|
2019-01-19 15:45:25 +01:00
|
|
|
|
|
|
|
for (const HighlightPhrase &user : this->userSetting_.getValue())
|
|
|
|
{
|
|
|
|
this->highlightedUsers.appendItem(user);
|
|
|
|
}
|
|
|
|
|
|
|
|
this->highlightedUsers.delayedItemsChanged.connect([this] { //
|
|
|
|
this->userSetting_.setValue(this->highlightedUsers.getVector());
|
|
|
|
});
|
2018-05-06 00:32:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
HighlightModel *HighlightController::createModel(QObject *parent)
|
|
|
|
{
|
|
|
|
HighlightModel *model = new HighlightModel(parent);
|
|
|
|
model->init(&this->phrases);
|
|
|
|
|
|
|
|
return model;
|
|
|
|
}
|
|
|
|
|
2018-07-05 15:58:20 +02:00
|
|
|
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();
|
2018-10-21 13:43:02 +02:00
|
|
|
for (const auto &highlightedUser : userItems)
|
|
|
|
{
|
|
|
|
if (highlightedUser.isMatch(username))
|
|
|
|
{
|
2018-07-05 15:58:20 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-08-06 21:17:03 +02:00
|
|
|
HighlightBlacklistModel *HighlightController::createBlacklistModel(
|
|
|
|
QObject *parent)
|
2018-07-04 13:22:27 +02:00
|
|
|
{
|
|
|
|
auto *model = new HighlightBlacklistModel(parent);
|
|
|
|
model->init(&this->blacklistedUsers);
|
|
|
|
|
|
|
|
return model;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HighlightController::blacklistContains(const QString &username)
|
|
|
|
{
|
2018-08-06 21:17:03 +02:00
|
|
|
std::vector<HighlightBlacklistUser> blacklistItems =
|
|
|
|
this->blacklistedUsers.getVector();
|
2018-10-21 13:43:02 +02:00
|
|
|
for (const auto &blacklistedUser : blacklistItems)
|
|
|
|
{
|
|
|
|
if (blacklistedUser.isMatch(username))
|
|
|
|
{
|
2018-07-04 13:22:27 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-06-28 19:38:57 +02:00
|
|
|
void HighlightController::addHighlight(const MessagePtr &msg)
|
2018-05-23 22:27:29 +02:00
|
|
|
{
|
2018-06-26 17:06:17 +02:00
|
|
|
// static NotificationPopup popup;
|
2018-05-23 22:27:29 +02:00
|
|
|
|
|
|
|
// popup.updatePosition();
|
|
|
|
// popup.addMessage(msg);
|
|
|
|
// popup.show();
|
|
|
|
}
|
|
|
|
|
2018-05-06 00:32:45 +02:00
|
|
|
} // namespace chatterino
|