mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
absorbed HighlightController into Application
This commit is contained in:
parent
d0a81f3fe7
commit
f8a9850151
11 changed files with 70 additions and 103 deletions
|
@ -131,7 +131,6 @@ SOURCES += \
|
|||
src/controllers/commands/CommandController.cpp \
|
||||
src/controllers/commands/CommandModel.cpp \
|
||||
src/controllers/highlights/HighlightBlacklistModel.cpp \
|
||||
src/controllers/highlights/HighlightController.cpp \
|
||||
src/controllers/highlights/HighlightModel.cpp \
|
||||
src/controllers/highlights/HighlightPhrase.cpp \
|
||||
src/controllers/highlights/UserHighlightModel.cpp \
|
||||
|
@ -326,7 +325,6 @@ HEADERS += \
|
|||
src/controllers/commands/CommandModel.hpp \
|
||||
src/controllers/highlights/HighlightBlacklistModel.hpp \
|
||||
src/controllers/highlights/HighlightBlacklistUser.hpp \
|
||||
src/controllers/highlights/HighlightController.hpp \
|
||||
src/controllers/highlights/HighlightModel.hpp \
|
||||
src/controllers/highlights/HighlightPhrase.hpp \
|
||||
src/controllers/highlights/UserHighlightModel.hpp \
|
||||
|
|
|
@ -5,7 +5,8 @@
|
|||
#include "common/Args.hpp"
|
||||
#include "controllers/accounts/AccountController.hpp"
|
||||
#include "controllers/commands/CommandController.hpp"
|
||||
#include "controllers/highlights/HighlightController.hpp"
|
||||
#include "controllers/highlights/HighlightBlacklistUser.hpp"
|
||||
#include "controllers/highlights/HighlightPhrase.hpp"
|
||||
#include "controllers/ignores/IgnoreController.hpp"
|
||||
#include "controllers/moderationactions/ModerationActions.hpp"
|
||||
#include "controllers/notifications/NotificationController.hpp"
|
||||
|
@ -30,6 +31,7 @@
|
|||
#include "singletons/Updates.hpp"
|
||||
#include "singletons/WindowManager.hpp"
|
||||
#include "util/IsBigEndian.hpp"
|
||||
#include "util/PersistSignalVector.hpp"
|
||||
#include "util/PostToThread.hpp"
|
||||
#include "widgets/Notebook.hpp"
|
||||
#include "widgets/Window.hpp"
|
||||
|
@ -46,7 +48,11 @@ Application *Application::instance = nullptr;
|
|||
// to each other
|
||||
|
||||
Application::Application(Settings &_settings, Paths &_paths)
|
||||
: themes(&this->emplace<Theme>())
|
||||
: highlightedMessages(*new SignalVector<HighlightPhrase>())
|
||||
, highlightedUsers(*new SignalVector<HighlightPhrase>())
|
||||
, blacklistedUsers(*new SignalVector<HighlightBlacklistUser>())
|
||||
|
||||
, themes(&this->emplace<Theme>())
|
||||
, fonts(&this->emplace<Fonts>())
|
||||
, emotes(&this->emplace<Emotes>())
|
||||
, windows(&this->emplace<WindowManager>())
|
||||
|
@ -54,7 +60,6 @@ Application::Application(Settings &_settings, Paths &_paths)
|
|||
|
||||
, accounts(&this->emplace<AccountController>())
|
||||
, commands(&this->emplace<CommandController>())
|
||||
, highlights(&this->emplace<HighlightController>())
|
||||
, notifications(&this->emplace<NotificationController>())
|
||||
, pings(&this->emplace<MutedChannelController>())
|
||||
, ignores(&this->emplace<IgnoreController>())
|
||||
|
@ -63,10 +68,13 @@ Application::Application(Settings &_settings, Paths &_paths)
|
|||
, twitch2(&this->emplace<TwitchIrcServer>())
|
||||
, chatterinoBadges(&this->emplace<ChatterinoBadges>())
|
||||
, logging(&this->emplace<Logging>())
|
||||
|
||||
{
|
||||
this->instance = this;
|
||||
|
||||
persist(this->highlightedMessages, "/highlighting/highlights");
|
||||
persist(this->blacklistedUsers, "/highlighting/blacklist");
|
||||
persist(this->highlightedUsers, "/highlighting/users");
|
||||
|
||||
this->fonts->fontChanged.connect(
|
||||
[this]() { this->windows->layoutChannelViews(); });
|
||||
|
||||
|
@ -321,4 +329,28 @@ Application *getApp()
|
|||
return Application::instance;
|
||||
}
|
||||
|
||||
bool Application::isHighlightedUser(const QString &username)
|
||||
{
|
||||
for (const auto &highlightedUser : this->highlightedUsers)
|
||||
{
|
||||
if (highlightedUser.isMatch(username))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Application::isBlacklistedUser(const QString &username)
|
||||
{
|
||||
auto items = this->blacklistedUsers.readOnly();
|
||||
|
||||
for (const auto &blacklistedUser : *items)
|
||||
{
|
||||
if (blacklistedUser.isMatch(username))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include <QApplication>
|
||||
#include <memory>
|
||||
|
||||
#include "common/SignalVector.hpp"
|
||||
#include "common/Singleton.hpp"
|
||||
#include "singletons/NativeMessaging.hpp"
|
||||
|
||||
|
@ -31,6 +32,9 @@ class Fonts;
|
|||
class Toasts;
|
||||
class ChatterinoBadges;
|
||||
|
||||
class HighlightPhrase;
|
||||
class HighlightBlacklistUser;
|
||||
|
||||
class Application
|
||||
{
|
||||
std::vector<std::unique_ptr<Singleton>> singletons_;
|
||||
|
@ -50,6 +54,15 @@ public:
|
|||
|
||||
friend void test();
|
||||
|
||||
// clang-format off
|
||||
SignalVector<HighlightPhrase> &highlightedMessages;
|
||||
SignalVector<HighlightPhrase> &highlightedUsers;
|
||||
SignalVector<HighlightBlacklistUser> &blacklistedUsers;
|
||||
// clang-format on
|
||||
|
||||
bool isHighlightedUser(const QString &username);
|
||||
bool isBlacklistedUser(const QString &username);
|
||||
|
||||
Theme *const themes{};
|
||||
Fonts *const fonts{};
|
||||
Emotes *const emotes{};
|
||||
|
@ -58,7 +71,6 @@ public:
|
|||
|
||||
AccountController *const accounts{};
|
||||
CommandController *const commands{};
|
||||
HighlightController *const highlights{};
|
||||
NotificationController *const notifications{};
|
||||
MutedChannelController *const pings{};
|
||||
IgnoreController *const ignores{};
|
||||
|
|
|
@ -1,40 +0,0 @@
|
|||
#include "HighlightController.hpp"
|
||||
|
||||
#include "Application.hpp"
|
||||
#include "util/PersistSignalVector.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
void HighlightController::initialize(Settings &settings, Paths &paths)
|
||||
{
|
||||
assert(!this->initialized_);
|
||||
this->initialized_ = true;
|
||||
|
||||
persist(this->phrases, "/highlighting/highlights");
|
||||
persist(this->blacklistedUsers, "/highlighting/blacklist");
|
||||
persist(this->highlightedUsers, "/highlighting/users");
|
||||
}
|
||||
|
||||
bool HighlightController::isHighlightedUser(const QString &username)
|
||||
{
|
||||
for (const auto &highlightedUser : this->highlightedUsers)
|
||||
{
|
||||
if (highlightedUser.isMatch(username))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool HighlightController::blacklistContains(const QString &username)
|
||||
{
|
||||
for (const auto &blacklistedUser : *this->blacklistedUsers.readOnly())
|
||||
{
|
||||
if (blacklistedUser.isMatch(username))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
|
@ -1,26 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include "common/SignalVector.hpp"
|
||||
#include "common/Singleton.hpp"
|
||||
#include "controllers/highlights/HighlightBlacklistUser.hpp"
|
||||
#include "controllers/highlights/HighlightPhrase.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class HighlightController final : public Singleton
|
||||
{
|
||||
public:
|
||||
virtual void initialize(Settings &settings, Paths &paths) override;
|
||||
|
||||
SignalVector<HighlightPhrase> phrases;
|
||||
SignalVector<HighlightBlacklistUser> blacklistedUsers;
|
||||
SignalVector<HighlightPhrase> highlightedUsers;
|
||||
|
||||
bool isHighlightedUser(const QString &username);
|
||||
bool blacklistContains(const QString &username);
|
||||
|
||||
private:
|
||||
bool initialized_ = false;
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
|
@ -1,6 +1,5 @@
|
|||
#include "providers/colors/ColorProvider.hpp"
|
||||
|
||||
#include "controllers/highlights/HighlightController.hpp"
|
||||
#include "singletons/Theme.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
@ -38,12 +37,12 @@ QSet<QColor> ColorProvider::recentColors() const
|
|||
* Currently, only colors used in highlight phrases are considered. This
|
||||
* may change at any point in the future.
|
||||
*/
|
||||
for (auto phrase : getApp()->highlights->phrases)
|
||||
for (auto phrase : getApp()->highlightedMessages)
|
||||
{
|
||||
retVal.insert(*phrase.getColor());
|
||||
}
|
||||
|
||||
for (auto userHl : getApp()->highlights->highlightedUsers)
|
||||
for (auto userHl : getApp()->highlightedUsers)
|
||||
{
|
||||
retVal.insert(*userHl.getColor());
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
#include "Application.hpp"
|
||||
#include "controllers/accounts/AccountController.hpp"
|
||||
#include "controllers/highlights/HighlightController.hpp"
|
||||
#include "messages/LimitedQueue.hpp"
|
||||
#include "messages/Message.hpp"
|
||||
#include "providers/twitch/TwitchAccountManager.hpp"
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
#include "common/Common.hpp"
|
||||
#include "common/Env.hpp"
|
||||
#include "controllers/accounts/AccountController.hpp"
|
||||
#include "controllers/highlights/HighlightController.hpp"
|
||||
#include "messages/Message.hpp"
|
||||
#include "messages/MessageBuilder.hpp"
|
||||
#include "providers/twitch/IrcMessageHandler.hpp"
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
#include "Application.hpp"
|
||||
#include "controllers/accounts/AccountController.hpp"
|
||||
#include "controllers/highlights/HighlightController.hpp"
|
||||
#include "controllers/ignores/IgnoreController.hpp"
|
||||
#include "controllers/pings/MutedChannelController.hpp"
|
||||
#include "messages/Message.hpp"
|
||||
|
@ -1018,7 +1017,7 @@ void TwitchMessageBuilder::parseHighlights()
|
|||
|
||||
QString currentUsername = currentUser->getUserName();
|
||||
|
||||
if (app->highlights->blacklistContains(this->ircMessage->nick()))
|
||||
if (app->isBlacklistedUser(this->ircMessage->nick()))
|
||||
{
|
||||
// Do nothing. We ignore highlights from this user.
|
||||
return;
|
||||
|
@ -1058,7 +1057,7 @@ void TwitchMessageBuilder::parseHighlights()
|
|||
}
|
||||
|
||||
// Highlight because of sender
|
||||
auto userHighlights = app->highlights->highlightedUsers.readOnly();
|
||||
auto userHighlights = app->highlightedUsers.readOnly();
|
||||
for (const HighlightPhrase &userHighlight : *userHighlights)
|
||||
{
|
||||
if (!userHighlight.isMatch(this->ircMessage->nick()))
|
||||
|
@ -1110,7 +1109,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.cloneVector();
|
||||
app->highlightedMessages.cloneVector();
|
||||
|
||||
if (getSettings()->enableSelfHighlight && currentUsername.size() > 0)
|
||||
{
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include "common/Channel.hpp"
|
||||
#include "common/NetworkRequest.hpp"
|
||||
#include "controllers/accounts/AccountController.hpp"
|
||||
#include "controllers/highlights/HighlightController.hpp"
|
||||
#include "controllers/highlights/HighlightBlacklistUser.hpp"
|
||||
#include "providers/twitch/PartialTwitchUser.hpp"
|
||||
#include "providers/twitch/TwitchChannel.hpp"
|
||||
#include "singletons/Resources.hpp"
|
||||
|
@ -336,24 +336,23 @@ void UserInfoPopup::installEvents()
|
|||
|
||||
if (checked)
|
||||
{
|
||||
getApp()->highlights->blacklistedUsers.insert(
|
||||
getApp()->blacklistedUsers.insert(
|
||||
HighlightBlacklistUser{this->userName_, false});
|
||||
this->ui_.ignoreHighlights->setEnabled(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
const auto &vector =
|
||||
getApp()->highlights->blacklistedUsers.raw();
|
||||
const auto &vector = getApp()->blacklistedUsers.raw();
|
||||
|
||||
for (int i = 0; i < vector.size(); i++)
|
||||
{
|
||||
if (this->userName_ == vector[i].getPattern())
|
||||
{
|
||||
getApp()->highlights->blacklistedUsers.removeAt(i);
|
||||
getApp()->blacklistedUsers.removeAt(i);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
if (getApp()->highlights->blacklistContains(this->userName_))
|
||||
if (getApp()->isBlacklistedUser(this->userName_))
|
||||
{
|
||||
this->ui_.ignoreHighlights->setToolTip(
|
||||
"Name matched by regex");
|
||||
|
@ -456,7 +455,7 @@ void UserInfoPopup::updateUserData()
|
|||
|
||||
// get ignoreHighlights state
|
||||
bool isIgnoringHighlights = false;
|
||||
const auto &vector = getApp()->highlights->blacklistedUsers.raw();
|
||||
const auto &vector = getApp()->blacklistedUsers.raw();
|
||||
for (int i = 0; i < vector.size(); i++)
|
||||
{
|
||||
if (this->userName_ == vector[i].getPattern())
|
||||
|
@ -465,7 +464,7 @@ void UserInfoPopup::updateUserData()
|
|||
break;
|
||||
}
|
||||
}
|
||||
if (getApp()->highlights->blacklistContains(this->userName_) &&
|
||||
if (getApp()->isBlacklistedUser(this->userName_) &&
|
||||
!isIgnoringHighlights)
|
||||
{
|
||||
this->ui_.ignoreHighlights->setToolTip("Name matched by regex");
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
#include "Application.hpp"
|
||||
#include "controllers/highlights/HighlightBlacklistModel.hpp"
|
||||
#include "controllers/highlights/HighlightController.hpp"
|
||||
#include "controllers/highlights/HighlightModel.hpp"
|
||||
#include "controllers/highlights/UserHighlightModel.hpp"
|
||||
#include "singletons/Settings.hpp"
|
||||
|
@ -53,7 +52,7 @@ HighlightingPage::HighlightingPage()
|
|||
highlights
|
||||
.emplace<EditableModelView>(
|
||||
(new HighlightModel(nullptr))
|
||||
->initialized(&app->highlights->phrases))
|
||||
->initialized(&app->highlightedMessages))
|
||||
.getElement();
|
||||
view->addRegexHelpLink();
|
||||
view->setTitles({"Pattern", "Flash\ntaskbar", "Play\nsound",
|
||||
|
@ -72,7 +71,7 @@ HighlightingPage::HighlightingPage()
|
|||
});
|
||||
|
||||
view->addButtonPressed.connect([] {
|
||||
getApp()->highlights->phrases.append(HighlightPhrase{
|
||||
getApp()->highlightedMessages.append(HighlightPhrase{
|
||||
"my phrase", true, false, false, false, "",
|
||||
*ColorProvider::instance().color(
|
||||
ColorType::SelfHighlight)});
|
||||
|
@ -95,8 +94,7 @@ HighlightingPage::HighlightingPage()
|
|||
pingUsers
|
||||
.emplace<EditableModelView>(
|
||||
(new UserHighlightModel(nullptr))
|
||||
->initialized(
|
||||
&app->highlights->highlightedUsers))
|
||||
->initialized(&app->highlightedUsers))
|
||||
.getElement();
|
||||
|
||||
view->addRegexHelpLink();
|
||||
|
@ -120,11 +118,10 @@ HighlightingPage::HighlightingPage()
|
|||
});
|
||||
|
||||
view->addButtonPressed.connect([] {
|
||||
getApp()->highlights->highlightedUsers.append(
|
||||
HighlightPhrase{"highlighted user", true, false, false,
|
||||
false, "",
|
||||
*ColorProvider::instance().color(
|
||||
ColorType::SelfHighlight)});
|
||||
getApp()->highlightedUsers.append(HighlightPhrase{
|
||||
"highlighted user", true, false, false, false, "",
|
||||
*ColorProvider::instance().color(
|
||||
ColorType::SelfHighlight)});
|
||||
});
|
||||
|
||||
QObject::connect(view->getTableView(), &QTableView::clicked,
|
||||
|
@ -143,8 +140,7 @@ HighlightingPage::HighlightingPage()
|
|||
disabledUsers
|
||||
.emplace<EditableModelView>(
|
||||
(new HighlightBlacklistModel(nullptr))
|
||||
->initialized(
|
||||
&app->highlights->blacklistedUsers))
|
||||
->initialized(&app->blacklistedUsers))
|
||||
.getElement();
|
||||
|
||||
view->addRegexHelpLink();
|
||||
|
@ -162,7 +158,7 @@ HighlightingPage::HighlightingPage()
|
|||
});
|
||||
|
||||
view->addButtonPressed.connect([] {
|
||||
getApp()->highlights->blacklistedUsers.append(
|
||||
getApp()->blacklistedUsers.append(
|
||||
HighlightBlacklistUser{"blacklisted user", false});
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue