refactored HighlightController

This commit is contained in:
fourtf
2020-02-23 19:31:43 +01:00
parent 4a5dc80bc6
commit 843e2ad994
17 changed files with 34 additions and 100 deletions
@@ -1,17 +1,10 @@
#include "HighlightController.hpp"
#include "Application.hpp"
#include "controllers/highlights/HighlightBlacklistModel.hpp"
#include "controllers/highlights/HighlightModel.hpp"
#include "controllers/highlights/UserHighlightModel.hpp"
#include "widgets/dialogs/NotificationPopup.hpp"
#include "common/ChatterinoSetting.hpp"
namespace chatterino {
HighlightController::HighlightController()
{
}
template <typename T>
inline void persist(SignalVector<T> &vec, const std::string &name)
{
@@ -24,7 +17,7 @@ inline void persist(SignalVector<T> &vec, const std::string &name)
setting->setValue(vec->raw());
});
// TODO
// TODO: Delete when appropriate.
setting.release();
}
@@ -38,65 +31,26 @@ void HighlightController::initialize(Settings &settings, Paths &paths)
persist(this->highlightedUsers, "/highlighting/users");
}
HighlightModel *HighlightController::createModel(QObject *parent)
{
HighlightModel *model = new HighlightModel(parent);
model->init(&this->phrases);
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;
for (const auto &highlightedUser : userItems)
for (const auto &highlightedUser : this->highlightedUsers)
{
if (highlightedUser.isMatch(username))
{
return true;
}
}
return false;
}
HighlightBlacklistModel *HighlightController::createBlacklistModel(
QObject *parent)
{
auto *model = new HighlightBlacklistModel(parent);
model->init(&this->blacklistedUsers);
return model;
}
bool HighlightController::blacklistContains(const QString &username)
{
for (const auto &blacklistedUser : *this->blacklistedUsers.readOnly())
{
if (blacklistedUser.isMatch(username))
{
return true;
}
}
return false;
}
void HighlightController::addHighlight(const MessagePtr &msg)
{
// static NotificationPopup popup;
// popup.updatePosition();
// popup.addMessage(msg);
// popup.show();
}
} // namespace chatterino