mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
did some more things and stuff
This commit is contained in:
parent
5ad427bd61
commit
e537277fa8
17 changed files with 98 additions and 174 deletions
|
@ -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 \
|
||||
|
|
|
@ -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<AccountController>())
|
||||
, commands(&this->emplace<CommandController>())
|
||||
, notifications(&this->emplace<NotificationController>())
|
||||
, pings(&this->emplace<MutedChannelController>())
|
||||
, taggedUsers(&this->emplace<TaggedUsersController>())
|
||||
, moderationActions(&this->emplace<ModerationActions>())
|
||||
, twitch2(&this->emplace<TwitchIrcServer>())
|
||||
, chatterinoBadges(&this->emplace<ChatterinoBadges>())
|
||||
, logging(&this->emplace<Logging>())
|
||||
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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{};
|
||||
|
||||
|
|
|
@ -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<ImagePtr> &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_;
|
||||
}
|
||||
|
||||
|
|
|
@ -25,10 +25,11 @@ public:
|
|||
const QString &getAction() const;
|
||||
|
||||
private:
|
||||
boost::optional<ImagePtr> image_;
|
||||
mutable boost::optional<ImagePtr> image_;
|
||||
QString line1_;
|
||||
QString line2_;
|
||||
QString action_;
|
||||
int imageToLoad_{};
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
#include "ModerationActions.hpp"
|
||||
|
||||
#include "Application.hpp"
|
||||
#include "controllers/moderationactions/ModerationActionModel.hpp"
|
||||
#include "util/PersistSignalVector.hpp"
|
||||
|
||||
#include <QRegularExpression>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
void ModerationActions::initialize(Settings &settings, Paths &paths)
|
||||
{
|
||||
assert(!this->initialized_);
|
||||
this->initialized_ = true;
|
||||
|
||||
persist(this->items, "/moderation/actions");
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
|
@ -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<ModerationAction> items;
|
||||
|
||||
private:
|
||||
bool initialized_ = false;
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
|
@ -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<int>::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
|
||||
|
|
|
@ -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<QString> channels;
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
#include "TaggedUsersController.hpp"
|
||||
|
||||
#include "controllers/taggedusers/TaggedUsersModel.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
TaggedUsersController::TaggedUsersController()
|
||||
: users(std::less<TaggedUser>{})
|
||||
{
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
|
@ -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<TaggedUser> users;
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
|
@ -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())
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<HighlightPhrase>())
|
||||
, highlightedUsers(*new SignalVector<HighlightPhrase>())
|
||||
, blacklistedUsers(*new SignalVector<HighlightBlacklistUser>())
|
||||
, ignoredMessages(*new SignalVector<IgnorePhrase>())
|
||||
, mutedChannels(*new SignalVector<QString>())
|
||||
, moderationActions(*new SignalVector<ModerationAction>)
|
||||
{
|
||||
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<int>::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(
|
||||
|
|
|
@ -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<HighlightPhrase> &highlightedMessages;
|
||||
SignalVector<HighlightPhrase> &highlightedUsers;
|
||||
SignalVector<HighlightPhrase> &highlightedMessages;
|
||||
SignalVector<HighlightPhrase> &highlightedUsers;
|
||||
SignalVector<HighlightBlacklistUser> &blacklistedUsers;
|
||||
SignalVector<IgnorePhrase> &ignoredMessages;
|
||||
// clang-format on
|
||||
SignalVector<IgnorePhrase> &ignoredMessages;
|
||||
SignalVector<QString> &mutedChannels;
|
||||
//SignalVector<TaggedUser> &taggedUsers;
|
||||
SignalVector<ModerationAction> &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
|
||||
{
|
||||
|
|
|
@ -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<EditableModelView>(
|
||||
(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"));
|
||||
});
|
||||
|
||||
|
|
|
@ -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<QMenu> 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
|
||||
|
|
Loading…
Reference in a new issue