did some more things and stuff

This commit is contained in:
fourtf
2020-02-23 23:07:28 +01:00
parent 5ad427bd61
commit e537277fa8
17 changed files with 98 additions and 174 deletions
+55 -5
View File
@@ -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 -6
View File
@@ -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
{