From e537277fa80692ba28e542681dcfb476086cd06e Mon Sep 17 00:00:00 2001 From: fourtf Date: Sun, 23 Feb 2020 23:07:28 +0100 Subject: [PATCH] did some more things and stuff --- chatterino.pro | 4 -- src/Application.cpp | 11 +--- src/Application.hpp | 8 --- .../moderationactions/ModerationAction.cpp | 14 ++++- .../moderationactions/ModerationAction.hpp | 3 +- .../moderationactions/ModerationActions.cpp | 19 ------ .../moderationactions/ModerationActions.hpp | 23 ------- .../pings/MutedChannelController.cpp | 45 -------------- .../pings/MutedChannelController.hpp | 5 -- .../taggedusers/TaggedUsersController.cpp | 12 ---- .../taggedusers/TaggedUsersController.hpp | 20 ------- src/messages/MessageElement.cpp | 5 +- src/providers/twitch/TwitchMessageBuilder.cpp | 2 +- src/singletons/Settings.cpp | 60 +++++++++++++++++-- src/singletons/Settings.hpp | 21 +++++-- src/widgets/settingspages/ModerationPage.cpp | 6 +- src/widgets/splits/SplitHeader.cpp | 14 ++--- 17 files changed, 98 insertions(+), 174 deletions(-) delete mode 100644 src/controllers/moderationactions/ModerationActions.cpp delete mode 100644 src/controllers/moderationactions/ModerationActions.hpp delete mode 100644 src/controllers/taggedusers/TaggedUsersController.cpp delete mode 100644 src/controllers/taggedusers/TaggedUsersController.hpp diff --git a/chatterino.pro b/chatterino.pro index d19b4fb83..755bc589d 100644 --- a/chatterino.pro +++ b/chatterino.pro @@ -138,13 +138,11 @@ SOURCES += \ src/controllers/ignores/IgnoreModel.cpp \ src/controllers/moderationactions/ModerationAction.cpp \ src/controllers/moderationactions/ModerationActionModel.cpp \ - src/controllers/moderationactions/ModerationActions.cpp \ src/controllers/notifications/NotificationController.cpp \ src/controllers/notifications/NotificationModel.cpp \ src/controllers/pings/MutedChannelController.cpp \ src/controllers/pings/MutedChannelModel.cpp \ src/controllers/taggedusers/TaggedUser.cpp \ - src/controllers/taggedusers/TaggedUsersController.cpp \ src/controllers/taggedusers/TaggedUsersModel.cpp \ src/debug/Benchmark.cpp \ src/main.cpp \ @@ -333,13 +331,11 @@ HEADERS += \ src/controllers/ignores/IgnorePhrase.hpp \ src/controllers/moderationactions/ModerationAction.hpp \ src/controllers/moderationactions/ModerationActionModel.hpp \ - src/controllers/moderationactions/ModerationActions.hpp \ src/controllers/notifications/NotificationController.hpp \ src/controllers/notifications/NotificationModel.hpp \ src/controllers/pings/MutedChannelController.hpp \ src/controllers/pings/MutedChannelModel.hpp \ src/controllers/taggedusers/TaggedUser.hpp \ - src/controllers/taggedusers/TaggedUsersController.hpp \ src/controllers/taggedusers/TaggedUsersModel.hpp \ src/debug/AssertInGuiThread.hpp \ src/debug/Benchmark.hpp \ diff --git a/src/Application.cpp b/src/Application.cpp index 62f8f392d..8f9425011 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -6,10 +6,7 @@ #include "controllers/accounts/AccountController.hpp" #include "controllers/commands/CommandController.hpp" #include "controllers/ignores/IgnoreController.hpp" -#include "controllers/moderationactions/ModerationActions.hpp" #include "controllers/notifications/NotificationController.hpp" -#include "controllers/pings/MutedChannelController.hpp" -#include "controllers/taggedusers/TaggedUsersController.hpp" #include "messages/MessageBuilder.hpp" #include "providers/bttv/BttvEmotes.hpp" #include "providers/chatterino/ChatterinoBadges.hpp" @@ -54,9 +51,6 @@ Application::Application(Settings &_settings, Paths &_paths) , accounts(&this->emplace()) , commands(&this->emplace()) , notifications(&this->emplace()) - , pings(&this->emplace()) - , taggedUsers(&this->emplace()) - , moderationActions(&this->emplace()) , twitch2(&this->emplace()) , chatterinoBadges(&this->emplace()) , logging(&this->emplace()) @@ -111,9 +105,6 @@ void Application::initialize(Settings &settings, Paths &paths) this->initNm(paths); this->initPubsub(); - - this->moderationActions->items.delayedItemsChanged.connect( - [this] { this->windows->forceLayoutChannelViews(); }); } int Application::run(QApplication &qtApp) @@ -126,6 +117,8 @@ int Application::run(QApplication &qtApp) getSettings()->betaUpdates.connect( [] { Updates::instance().checkForUpdates(); }, false); + getSettings()->moderationActions.delayedItemsChanged.connect( + [this] { this->windows->forceLayoutChannelViews(); }); return qtApp.exec(); } diff --git a/src/Application.hpp b/src/Application.hpp index fa04a34de..0c0e54bcb 100644 --- a/src/Application.hpp +++ b/src/Application.hpp @@ -13,13 +13,8 @@ class TwitchIrcServer; class PubSub; class CommandController; -class HighlightController; -class IgnoreController; -class TaggedUsersController; class AccountController; -class ModerationActions; class NotificationController; -class MutedChannelController; class Theme; class WindowManager; @@ -60,9 +55,6 @@ public: AccountController *const accounts{}; CommandController *const commands{}; NotificationController *const notifications{}; - MutedChannelController *const pings{}; - TaggedUsersController *const taggedUsers{}; - ModerationActions *const moderationActions{}; TwitchIrcServer *const twitch2{}; ChatterinoBadges *const chatterinoBadges{}; diff --git a/src/controllers/moderationactions/ModerationAction.cpp b/src/controllers/moderationactions/ModerationAction.cpp index dce01904c..d94cb234d 100644 --- a/src/controllers/moderationactions/ModerationAction.cpp +++ b/src/controllers/moderationactions/ModerationAction.cpp @@ -71,11 +71,11 @@ ModerationAction::ModerationAction(const QString &action) } else if (action.startsWith("/ban ")) { - this->image_ = Image::fromPixmap(getResources().buttons.ban); + this->imageToLoad_ = 1; } else if (action.startsWith("/delete ")) { - this->image_ = Image::fromPixmap(getResources().buttons.trashCan); + this->imageToLoad_ = 2; } else { @@ -100,6 +100,16 @@ bool ModerationAction::isImage() const const boost::optional &ModerationAction::getImage() const { + assertInGuiThread(); + + if (this->imageToLoad_ != 0) + { + if (this->imageToLoad_ == 1) + this->image_ = Image::fromPixmap(getResources().buttons.ban); + else if (this->imageToLoad_ == 2) + this->image_ = Image::fromPixmap(getResources().buttons.trashCan); + } + return this->image_; } diff --git a/src/controllers/moderationactions/ModerationAction.hpp b/src/controllers/moderationactions/ModerationAction.hpp index eed7579a5..3b4532d91 100644 --- a/src/controllers/moderationactions/ModerationAction.hpp +++ b/src/controllers/moderationactions/ModerationAction.hpp @@ -25,10 +25,11 @@ public: const QString &getAction() const; private: - boost::optional image_; + mutable boost::optional image_; QString line1_; QString line2_; QString action_; + int imageToLoad_{}; }; } // namespace chatterino diff --git a/src/controllers/moderationactions/ModerationActions.cpp b/src/controllers/moderationactions/ModerationActions.cpp deleted file mode 100644 index 6215c81b8..000000000 --- a/src/controllers/moderationactions/ModerationActions.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include "ModerationActions.hpp" - -#include "Application.hpp" -#include "controllers/moderationactions/ModerationActionModel.hpp" -#include "util/PersistSignalVector.hpp" - -#include - -namespace chatterino { - -void ModerationActions::initialize(Settings &settings, Paths &paths) -{ - assert(!this->initialized_); - this->initialized_ = true; - - persist(this->items, "/moderation/actions"); -} - -} // namespace chatterino diff --git a/src/controllers/moderationactions/ModerationActions.hpp b/src/controllers/moderationactions/ModerationActions.hpp deleted file mode 100644 index 8e6a4ded8..000000000 --- a/src/controllers/moderationactions/ModerationActions.hpp +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once - -#include "common/SignalVector.hpp" -#include "common/Singleton.hpp" -#include "controllers/moderationactions/ModerationAction.hpp" - -namespace chatterino { - -class Settings; -class Paths; - -class ModerationActions final : public Singleton -{ -public: - virtual void initialize(Settings &settings, Paths &paths) override; - - SignalVector items; - -private: - bool initialized_ = false; -}; - -} // namespace chatterino diff --git a/src/controllers/pings/MutedChannelController.cpp b/src/controllers/pings/MutedChannelController.cpp index 809097ab0..62555fd5e 100644 --- a/src/controllers/pings/MutedChannelController.cpp +++ b/src/controllers/pings/MutedChannelController.cpp @@ -7,51 +7,6 @@ namespace chatterino { void MutedChannelController::initialize(Settings &settings, Paths &paths) { this->initialized_ = true; - - persist(this->channels, "/pings/muted"); -} - -bool MutedChannelController::isMuted(const QString &channelName) -{ - for (const auto &channel : this->channels) - { - if (channelName.toLower() == channel.toLower()) - { - return true; - } - } - return false; -} - -void MutedChannelController::mute(const QString &channelName) -{ - channels.append(channelName); -} - -void MutedChannelController::unmute(const QString &channelName) -{ - for (std::vector::size_type i = 0; i != channels.raw().size(); i++) - { - if (channels.raw()[i].toLower() == channelName.toLower()) - { - channels.removeAt(i); - i--; - } - } -} - -bool MutedChannelController::toggleMuted(const QString &channelName) -{ - if (this->isMuted(channelName)) - { - unmute(channelName); - return false; - } - else - { - mute(channelName); - return true; - } } } // namespace chatterino diff --git a/src/controllers/pings/MutedChannelController.hpp b/src/controllers/pings/MutedChannelController.hpp index ff4a6f050..ea681fdc9 100644 --- a/src/controllers/pings/MutedChannelController.hpp +++ b/src/controllers/pings/MutedChannelController.hpp @@ -18,12 +18,7 @@ class MutedChannelController final : public Singleton, private QObject public: virtual void initialize(Settings &settings, Paths &paths) override; - bool isMuted(const QString &channelName); - bool toggleMuted(const QString &channelName); - private: - void mute(const QString &channelName); - void unmute(const QString &channelName); bool initialized_ = false; SignalVector channels; diff --git a/src/controllers/taggedusers/TaggedUsersController.cpp b/src/controllers/taggedusers/TaggedUsersController.cpp deleted file mode 100644 index a81b100c3..000000000 --- a/src/controllers/taggedusers/TaggedUsersController.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include "TaggedUsersController.hpp" - -#include "controllers/taggedusers/TaggedUsersModel.hpp" - -namespace chatterino { - -TaggedUsersController::TaggedUsersController() - : users(std::less{}) -{ -} - -} // namespace chatterino diff --git a/src/controllers/taggedusers/TaggedUsersController.hpp b/src/controllers/taggedusers/TaggedUsersController.hpp deleted file mode 100644 index dd9c4d897..000000000 --- a/src/controllers/taggedusers/TaggedUsersController.hpp +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once - -#include "common/Singleton.hpp" - -#include "common/SignalVector.hpp" -#include "controllers/taggedusers/TaggedUser.hpp" - -namespace chatterino { - -class TaggedUsersModel; - -class TaggedUsersController final : public Singleton -{ -public: - TaggedUsersController(); - - SignalVector users; -}; - -} // namespace chatterino diff --git a/src/messages/MessageElement.cpp b/src/messages/MessageElement.cpp index 0defed597..3849b8b43 100644 --- a/src/messages/MessageElement.cpp +++ b/src/messages/MessageElement.cpp @@ -1,7 +1,6 @@ #include "messages/MessageElement.hpp" #include "Application.hpp" -#include "controllers/moderationactions/ModerationActions.hpp" #include "debug/Benchmark.hpp" #include "messages/Emote.hpp" #include "messages/layouts/MessageLayoutContainer.hpp" @@ -374,8 +373,8 @@ void TwitchModerationElement::addToContainer(MessageLayoutContainer &container, { QSize size(int(container.getScale() * 16), int(container.getScale() * 16)); - - for (const auto &action : getApp()->moderationActions->items) + auto actions = getCSettings().moderationActions.readOnly(); + for (const auto &action : *actions) { if (auto image = action.getImage()) { diff --git a/src/providers/twitch/TwitchMessageBuilder.cpp b/src/providers/twitch/TwitchMessageBuilder.cpp index 730bf3ca3..76c42d662 100644 --- a/src/providers/twitch/TwitchMessageBuilder.cpp +++ b/src/providers/twitch/TwitchMessageBuilder.cpp @@ -238,7 +238,7 @@ void TwitchMessageBuilder::triggerHighlights() return; } - if (getApp()->pings->isMuted(this->channel->getName())) + if (getCSettings().isMutedChannel(this->channel->getName())) { // Do nothing. Pings are muted in this channel. return; diff --git a/src/singletons/Settings.cpp b/src/singletons/Settings.cpp index 0e42db012..95a121d64 100644 --- a/src/singletons/Settings.cpp +++ b/src/singletons/Settings.cpp @@ -4,6 +4,7 @@ #include "controllers/highlights/HighlightBlacklistUser.hpp" #include "controllers/highlights/HighlightPhrase.hpp" #include "controllers/ignores/IgnorePhrase.hpp" +#include "controllers/pings/MutedChannelController.hpp" #include "singletons/Paths.hpp" #include "singletons/Resources.hpp" #include "singletons/WindowManager.hpp" @@ -15,11 +16,21 @@ namespace chatterino { ConcurrentSettings *concurrentInstance_{}; ConcurrentSettings::ConcurrentSettings() + // NOTE: these do not get deleted : highlightedMessages(*new SignalVector()) , highlightedUsers(*new SignalVector()) , blacklistedUsers(*new SignalVector()) , ignoredMessages(*new SignalVector()) + , mutedChannels(*new SignalVector()) + , moderationActions(*new SignalVector) { + persist(this->highlightedMessages, "/highlighting/highlights"); + persist(this->blacklistedUsers, "/highlighting/blacklist"); + persist(this->highlightedUsers, "/highlighting/users"); + persist(this->ignoredMessages, "/ignore/phrases"); + persist(this->mutedChannels, "/pings/muted"); + // tagged users? + persist(this->moderationActions, "/moderation/actions"); } bool ConcurrentSettings::isHighlightedUser(const QString &username) @@ -46,6 +57,50 @@ bool ConcurrentSettings::isBlacklistedUser(const QString &username) return false; } +bool ConcurrentSettings::isMutedChannel(const QString &channelName) +{ + for (const auto &channel : this->mutedChannels) + { + if (channelName.toLower() == channel.toLower()) + { + return true; + } + } + return false; +} + +void ConcurrentSettings::mute(const QString &channelName) +{ + mutedChannels.append(channelName); +} + +void ConcurrentSettings::unmute(const QString &channelName) +{ + for (std::vector::size_type i = 0; i != mutedChannels.raw().size(); + i++) + { + if (mutedChannels.raw()[i].toLower() == channelName.toLower()) + { + mutedChannels.removeAt(i); + i--; + } + } +} + +bool ConcurrentSettings::toggleMutedChannel(const QString &channelName) +{ + if (this->isMutedChannel(channelName)) + { + unmute(channelName); + return false; + } + else + { + mute(channelName); + return true; + } +} + ConcurrentSettings &getCSettings() { // `concurrentInstance_` gets assigned in Settings ctor. @@ -62,11 +117,6 @@ Settings::Settings(const QString &settingsDirectory) instance_ = this; concurrentInstance_ = this; - persist(this->highlightedMessages, "/highlighting/highlights"); - persist(this->blacklistedUsers, "/highlighting/blacklist"); - persist(this->highlightedUsers, "/highlighting/users"); - persist(this->ignoredMessages, "/ignore/phrases"); - #ifdef USEWINSDK this->autorun = isRegisteredForStartup(); this->autorun.connect( diff --git a/src/singletons/Settings.hpp b/src/singletons/Settings.hpp index cc2e4e3c5..cb5613efc 100644 --- a/src/singletons/Settings.hpp +++ b/src/singletons/Settings.hpp @@ -15,26 +15,35 @@ namespace chatterino { class HighlightPhrase; class HighlightBlacklistUser; class IgnorePhrase; +class TaggedUser; -// Settings which are availlable for reading on all threads. +/// Settings which are availlable for reading on all threads. class ConcurrentSettings { public: ConcurrentSettings(); - // clang-format off - SignalVector &highlightedMessages; - SignalVector &highlightedUsers; + SignalVector &highlightedMessages; + SignalVector &highlightedUsers; SignalVector &blacklistedUsers; - SignalVector &ignoredMessages; - // clang-format on + SignalVector &ignoredMessages; + SignalVector &mutedChannels; + //SignalVector &taggedUsers; + SignalVector &moderationActions; bool isHighlightedUser(const QString &username); bool isBlacklistedUser(const QString &username); + bool isMutedChannel(const QString &channelName); + bool toggleMutedChannel(const QString &channelName); + +private: + void mute(const QString &channelName); + void unmute(const QString &channelName); }; ConcurrentSettings &getCSettings(); +/// Settings which are availlable for reading and writing on the gui thread. // These settings are still accessed concurrently in the code but it is bad practice. class Settings : public ABSettings, public ConcurrentSettings { diff --git a/src/widgets/settingspages/ModerationPage.cpp b/src/widgets/settingspages/ModerationPage.cpp index 8b1754d86..55f282c7a 100644 --- a/src/widgets/settingspages/ModerationPage.cpp +++ b/src/widgets/settingspages/ModerationPage.cpp @@ -2,8 +2,6 @@ #include "Application.hpp" #include "controllers/moderationactions/ModerationActionModel.hpp" -#include "controllers/moderationactions/ModerationActions.hpp" -#include "controllers/taggedusers/TaggedUsersController.hpp" #include "controllers/taggedusers/TaggedUsersModel.hpp" #include "singletons/Logging.hpp" #include "singletons/Paths.hpp" @@ -175,7 +173,7 @@ ModerationPage::ModerationPage() modMode .emplace( (new ModerationActionModel(nullptr)) - ->initialized(&app->moderationActions->items)) + ->initialized(&getSettings()->moderationActions)) .getElement(); view->setTitles({"Actions"}); @@ -185,7 +183,7 @@ ModerationPage::ModerationPage() 0, QHeaderView::Stretch); view->addButtonPressed.connect([] { - getApp()->moderationActions->items.append( + getSettings()->moderationActions.append( ModerationAction("/timeout {user} 300")); }); diff --git a/src/widgets/splits/SplitHeader.cpp b/src/widgets/splits/SplitHeader.cpp index 84a389aae..49a474e35 100644 --- a/src/widgets/splits/SplitHeader.cpp +++ b/src/widgets/splits/SplitHeader.cpp @@ -2,7 +2,6 @@ #include "Application.hpp" #include "controllers/accounts/AccountController.hpp" -#include "controllers/moderationactions/ModerationActions.hpp" #include "controllers/notifications/NotificationController.hpp" #include "controllers/pings/MutedChannelController.hpp" #include "providers/twitch/TwitchChannel.hpp" @@ -189,7 +188,7 @@ void SplitHeader::initializeLayout() switch (button) { case Qt::LeftButton: - if (getApp()->moderationActions->items.empty()) + if (getSettings()->moderationActions.empty()) { getApp()->windows->showSettingsDialog( SettingsDialogPreference:: @@ -233,9 +232,9 @@ void SplitHeader::initializeLayout() }); // update moderation button when items changed - this->managedConnect(getApp()->moderationActions->items.delayedItemsChanged, + this->managedConnect(getSettings()->moderationActions.delayedItemsChanged, [this] { - if (getApp()->moderationActions->items.empty()) + if (getSettings()->moderationActions.empty()) { if (this->split_->getModerationMode()) this->split_->setModerationMode(true); @@ -339,11 +338,12 @@ std::unique_ptr SplitHeader::createMainMenu() action->setCheckable(true); QObject::connect(moreMenu, &QMenu::aboutToShow, this, [action, this]() { - action->setChecked(getApp()->pings->isMuted( + action->setChecked(getSettings()->isMutedChannel( this->split_->getChannel()->getName())); }); action->connect(action, &QAction::triggered, this, [this]() { - getApp()->pings->toggleMuted(this->split_->getChannel()->getName()); + getSettings()->toggleMutedChannel( + this->split_->getChannel()->getName()); }); moreMenu->addAction(action); @@ -567,7 +567,7 @@ void SplitHeader::updateChannelText() void SplitHeader::updateModerationModeIcon() { auto moderationMode = this->split_->getModerationMode() && - !getApp()->moderationActions->items.empty(); + !getSettings()->moderationActions.empty(); this->moderationButton_->setPixmap( moderationMode ? getResources().buttons.modModeEnabled