2018-06-28 19:46:45 +02:00
|
|
|
#include "singletons/Settings.hpp"
|
2018-04-27 22:11:19 +02:00
|
|
|
|
2022-12-31 15:41:01 +01:00
|
|
|
#include "controllers/filters/FilterRecord.hpp"
|
|
|
|
#include "controllers/highlights/HighlightBadge.hpp"
|
2020-02-23 22:15:13 +01:00
|
|
|
#include "controllers/highlights/HighlightBlacklistUser.hpp"
|
|
|
|
#include "controllers/highlights/HighlightPhrase.hpp"
|
|
|
|
#include "controllers/ignores/IgnorePhrase.hpp"
|
2022-12-31 15:41:01 +01:00
|
|
|
#include "controllers/moderationactions/ModerationAction.hpp"
|
|
|
|
#include "controllers/nicknames/Nickname.hpp"
|
2020-02-23 22:15:13 +01:00
|
|
|
#include "util/PersistSignalVector.hpp"
|
2019-07-23 23:56:14 +02:00
|
|
|
#include "util/WindowsHelper.hpp"
|
2017-04-12 17:46:44 +02:00
|
|
|
|
2017-04-14 17:52:22 +02:00
|
|
|
namespace chatterino {
|
2017-04-12 17:46:44 +02:00
|
|
|
|
2020-02-23 22:15:13 +01:00
|
|
|
ConcurrentSettings *concurrentInstance_{};
|
|
|
|
|
|
|
|
ConcurrentSettings::ConcurrentSettings()
|
2020-02-23 23:07:28 +01:00
|
|
|
// NOTE: these do not get deleted
|
2020-02-23 22:15:13 +01:00
|
|
|
: highlightedMessages(*new SignalVector<HighlightPhrase>())
|
|
|
|
, highlightedUsers(*new SignalVector<HighlightPhrase>())
|
2021-05-03 00:08:08 +02:00
|
|
|
, highlightedBadges(*new SignalVector<HighlightBadge>())
|
2020-02-23 22:15:13 +01:00
|
|
|
, blacklistedUsers(*new SignalVector<HighlightBlacklistUser>())
|
|
|
|
, ignoredMessages(*new SignalVector<IgnorePhrase>())
|
2020-02-23 23:07:28 +01:00
|
|
|
, mutedChannels(*new SignalVector<QString>())
|
2020-10-18 15:16:56 +02:00
|
|
|
, filterRecords(*new SignalVector<FilterRecordPtr>())
|
2021-07-31 16:15:43 +02:00
|
|
|
, nicknames(*new SignalVector<Nickname>())
|
2020-02-23 23:07:28 +01:00
|
|
|
, moderationActions(*new SignalVector<ModerationAction>)
|
2020-02-23 22:15:13 +01:00
|
|
|
{
|
2020-02-23 23:07:28 +01:00
|
|
|
persist(this->highlightedMessages, "/highlighting/highlights");
|
|
|
|
persist(this->blacklistedUsers, "/highlighting/blacklist");
|
2021-05-03 00:08:08 +02:00
|
|
|
persist(this->highlightedBadges, "/highlighting/badges");
|
2020-02-23 23:07:28 +01:00
|
|
|
persist(this->highlightedUsers, "/highlighting/users");
|
|
|
|
persist(this->ignoredMessages, "/ignore/phrases");
|
|
|
|
persist(this->mutedChannels, "/pings/muted");
|
2020-10-18 15:16:56 +02:00
|
|
|
persist(this->filterRecords, "/filtering/filters");
|
2021-07-31 16:15:43 +02:00
|
|
|
persist(this->nicknames, "/nicknames");
|
2020-02-23 23:07:28 +01:00
|
|
|
// tagged users?
|
|
|
|
persist(this->moderationActions, "/moderation/actions");
|
2020-02-23 22:15:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ConcurrentSettings::isHighlightedUser(const QString &username)
|
|
|
|
{
|
2020-08-22 11:45:18 +02:00
|
|
|
auto items = this->highlightedUsers.readOnly();
|
|
|
|
|
|
|
|
for (const auto &highlightedUser : *items)
|
2020-02-23 22:15:13 +01:00
|
|
|
{
|
|
|
|
if (highlightedUser.isMatch(username))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ConcurrentSettings::isBlacklistedUser(const QString &username)
|
|
|
|
{
|
|
|
|
auto items = this->blacklistedUsers.readOnly();
|
|
|
|
|
|
|
|
for (const auto &blacklistedUser : *items)
|
|
|
|
{
|
|
|
|
if (blacklistedUser.isMatch(username))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-02-23 23:07:28 +01:00
|
|
|
bool ConcurrentSettings::isMutedChannel(const QString &channelName)
|
|
|
|
{
|
2020-08-22 11:45:18 +02:00
|
|
|
auto items = this->mutedChannels.readOnly();
|
|
|
|
|
|
|
|
for (const auto &channel : *items)
|
2020-02-23 23:07:28 +01:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-23 22:15:13 +01:00
|
|
|
ConcurrentSettings &getCSettings()
|
|
|
|
{
|
|
|
|
// `concurrentInstance_` gets assigned in Settings ctor.
|
|
|
|
assert(concurrentInstance_);
|
|
|
|
|
|
|
|
return *concurrentInstance_;
|
|
|
|
}
|
|
|
|
|
2019-10-07 22:42:34 +02:00
|
|
|
Settings *Settings::instance_ = nullptr;
|
2018-08-02 14:23:27 +02:00
|
|
|
|
2018-11-25 15:02:48 +01:00
|
|
|
Settings::Settings(const QString &settingsDirectory)
|
|
|
|
: ABSettings(settingsDirectory)
|
2018-06-28 19:38:57 +02:00
|
|
|
{
|
2019-10-07 22:42:34 +02:00
|
|
|
instance_ = this;
|
2020-02-23 22:15:13 +01:00
|
|
|
concurrentInstance_ = this;
|
|
|
|
|
2019-07-23 23:56:14 +02:00
|
|
|
#ifdef USEWINSDK
|
|
|
|
this->autorun = isRegisteredForStartup();
|
|
|
|
this->autorun.connect(
|
2020-11-08 12:02:19 +01:00
|
|
|
[](bool autorun) {
|
|
|
|
setRegisteredForStartup(autorun);
|
|
|
|
},
|
|
|
|
false);
|
2019-07-23 23:56:14 +02:00
|
|
|
#endif
|
2017-04-12 17:46:44 +02:00
|
|
|
}
|
|
|
|
|
2019-10-07 22:42:34 +02:00
|
|
|
Settings &Settings::instance()
|
2018-01-04 01:52:37 +01:00
|
|
|
{
|
2019-10-07 22:42:34 +02:00
|
|
|
return *instance_;
|
2018-01-04 01:52:37 +01:00
|
|
|
}
|
|
|
|
|
2018-06-28 19:51:07 +02:00
|
|
|
Settings *getSettings()
|
2018-01-17 14:14:31 +01:00
|
|
|
{
|
2019-10-07 22:42:34 +02:00
|
|
|
return &Settings::instance();
|
2018-01-17 14:14:31 +01:00
|
|
|
}
|
2018-01-23 21:33:49 +01:00
|
|
|
|
2017-04-14 17:52:22 +02:00
|
|
|
} // namespace chatterino
|