Squashed commit of the following:

commit ea07bbef0be589cc5412bff0a25735ac713128e3
Merge: 0b36f436 5cfcf114
Author: hemirt <hemirt@email.cz>
Date:   Sun Sep 23 20:05:14 2018 +0200

    Merge branch 'blacklist' into blacklistnew

commit 5cfcf114b65ea7c0fca9654393ac2faa78610098
Author: hemirt <hemirt@email.cz>
Date:   Sun Sep 23 20:00:16 2018 +0200

    rename second pattern to replacement

commit f08cc4cf88c49140a282d3d29af5ad8e7179bb7c
Author: hemirt <hemirt@email.cz>
Date:   Sun Sep 23 19:52:30 2018 +0200

    delete out commented code

commit 1acb1278aa0109359e0e349ae240d10b34de9d34
Author: hemirt <hemirt@email.cz>
Date:   Sun Sep 23 19:52:03 2018 +0200

    fix replacement with emotes issues

commit 646268ab1883a955291f152029fa37f4416e681e
Author: hemirt <hemirt@email.cz>
Date:   Sun Aug 19 01:06:36 2018 +0200

    fix build

commit ad711b4c15ef0660c554af5ceea82397769a2313
Merge: e8e059f8 8bcc9c48
Author: hemirt <hemirt@email.cz>
Date:   Sun Aug 19 00:52:38 2018 +0200

    Merge branch 'master' of https://github.com/fourtf/chatterino2 into blacklist

commit e8e059f8473271128086c5230cf1c40b235af380
Author: hemirt <hemirt@email.cz>
Date:   Sun Aug 19 00:25:58 2018 +0200

    add replaced emotes into twitchEmotes

commit a63454f00de479cee1ab1eca18a8b4ab93e37d52
Merge: e7f2f397 63eaf3b9
Author: hemirt <hemirt@email.cz>
Date:   Sat Aug 11 22:38:16 2018 +0200

    Merge branch 'master' of https://github.com/fourtf/chatterino2 into blacklist

commit e7f2f397378d0582d989ff8fcbe83bcec41449a1
Author: hemirt <hemirt@email.cz>
Date:   Sat Aug 11 21:54:01 2018 +0200

    emotedata

commit f00d3da537ec14aebd9cbb84d63f7b16c196f199
Author: hemirt <hemirt@email.cz>
Date:   Sat Jul 28 19:53:55 2018 +0200

    rename variables to fit better, emotes in capture groups from regex work

commit 00c9fa080aeb8a4a187743d708ba139cbed5a849
Author: hemirt <hemirt@email.cz>
Date:   Mon Jul 9 19:53:53 2018 +0200

    add case sensitivity checkbox and fix validity issues due to isValid
    that checked regex

commit 4385fcd13fe6e011b91a3f4a29fd440d019fc499
Author: hemirt <hemirt@email.cz>
Date:   Sun Jul 8 21:09:14 2018 +0200

    remove commented code

commit 1834342f74c4fbff38b81fa2c2fcfd6c55adc0d5
Author: hemirt <hemirt@email.cz>
Date:   Sun Jul 8 21:03:13 2018 +0200

    IgnorePhrase replacement

    also removes twitch emotes info about the matched and changed parts and
    shifts positions of other emotes from emote infos to the corresponding new
    position

commit d3b6e294ed38fa8587c367c5da6f257641c28b86
Author: hemirt <hemirt@email.cz>
Date:   Sun Jul 8 16:21:33 2018 +0200

    ignore phrases
This commit is contained in:
hemirt
2018-09-23 20:21:50 +02:00
committed by pajlada
parent 86024ade24
commit 3184234c19
8 changed files with 414 additions and 211 deletions
+8 -3
View File
@@ -8,7 +8,7 @@ namespace chatterino {
// commandmodel
IgnoreModel::IgnoreModel(QObject *parent)
: SignalVectorModel<IgnorePhrase>(2, parent)
: SignalVectorModel<IgnorePhrase>(5, parent)
{
}
@@ -18,8 +18,10 @@ IgnorePhrase IgnoreModel::getItemFromRow(std::vector<QStandardItem *> &row,
{
// key, regex
return IgnorePhrase{row[0]->data(Qt::DisplayRole).toString(),
row[1]->data(Qt::CheckStateRole).toBool()};
return IgnorePhrase{
row[0]->data(Qt::DisplayRole).toString(), row[1]->data(Qt::CheckStateRole).toBool(),
row[3]->data(Qt::CheckStateRole).toBool(), row[4]->data(Qt::DisplayRole).toString(),
row[2]->data(Qt::CheckStateRole).toBool()};
}
// turns a row in the model into a vector item
@@ -28,6 +30,9 @@ void IgnoreModel::getRowFromItem(const IgnorePhrase &item,
{
setStringItem(row[0], item.getPattern());
setBoolItem(row[1], item.isRegex());
setBoolItem(row[2], item.isCaseSensitive());
setBoolItem(row[3], item.isBlock());
setStringItem(row[4], item.getReplace());
}
} // namespace chatterino
+114 -36
View File
@@ -1,5 +1,9 @@
#pragma once
#include "Application.hpp"
#include "controllers/accounts/AccountController.hpp"
#include "singletons/Settings.hpp"
#include "util/RapidJsonSerializeQString.hpp"
#include "util/RapidjsonHelpers.hpp"
@@ -16,80 +20,154 @@ class IgnorePhrase
public:
bool operator==(const IgnorePhrase &other) const
{
return std::tie(this->pattern_, this->isRegex_) ==
std::tie(other.pattern_, other.isRegex_);
return std::tie(this->pattern_, this->isRegex_, this->isBlock_, this->replace_,
this->isCaseSensitive_) == std::tie(other.pattern_, other.isRegex_,
other.isBlock_, other.replace_,
other.isCaseSensitive_);
}
IgnorePhrase(const QString &pattern, bool isRegex)
IgnorePhrase(const QString &pattern, bool isRegex, bool isBlock, const QString &replace,
bool isCaseSensitive)
: pattern_(pattern)
, isRegex_(isRegex)
, regex_(isRegex_ ? pattern
: "\\b" + QRegularExpression::escape(pattern) + "\\b",
QRegularExpression::CaseInsensitiveOption |
QRegularExpression::UseUnicodePropertiesOption)
, regex_(pattern)
, isBlock_(isBlock)
, replace_(replace)
, isCaseSensitive_(isCaseSensitive)
{
if (this->isCaseSensitive_) {
regex_.setPatternOptions(QRegularExpression::UseUnicodePropertiesOption);
} else {
regex_.setPatternOptions(QRegularExpression::CaseInsensitiveOption |
QRegularExpression::UseUnicodePropertiesOption);
}
}
const QString &getPattern() const
{
return this->pattern_;
}
bool isRegex() const
{
return this->isRegex_;
}
bool isValid() const
bool isRegexValid() const
{
return !this->pattern_.isEmpty() && this->regex_.isValid();
return this->regex_.isValid();
}
bool isMatch(const QString &subject) const
{
return this->isValid() && this->regex_.match(subject).hasMatch();
return !this->pattern_.isEmpty() &&
(this->isRegex() ? (this->regex_.isValid() && this->regex_.match(subject).hasMatch())
: subject.contains(this->pattern_, this->caseSensitivity()));
}
const QRegularExpression &getRegex() const
{
return this->regex_;
}
bool isBlock() const
{
return this->isBlock_;
}
const QString &getReplace() const
{
return this->replace_;
}
bool isCaseSensitive() const
{
return this->isCaseSensitive_;
}
Qt::CaseSensitivity caseSensitivity() const
{
return this->isCaseSensitive_ ? Qt::CaseSensitive : Qt::CaseInsensitive;
}
const std::unordered_map<EmoteName, EmotePtr> &getEmotes() const
{
return this->emotes_;
}
bool containsEmote() const
{
if (!this->emotesChecked_) {
const auto &accvec = getApp()->accounts->twitch.accounts.getVector();
for (const auto &acc : accvec) {
const auto &accemotes = *acc->accessEmotes();
for (const auto &emote : accemotes.emotes) {
if (this->replace_.contains(emote.first.string, Qt::CaseSensitive)) {
this->emotes_.emplace(emote.first, emote.second);
}
}
}
this->emotesChecked_ = true;
}
return !this->emotes_.empty();
}
private:
QString pattern_;
bool isRegex_;
QRegularExpression regex_;
bool isBlock_;
QString replace_;
bool isCaseSensitive_;
mutable std::unordered_map<EmoteName, EmotePtr> emotes_;
mutable bool emotesChecked_{false};
};
} // namespace chatterino
namespace pajlada {
namespace Settings {
template <>
struct Serialize<chatterino::IgnorePhrase> {
static rapidjson::Value get(const chatterino::IgnorePhrase &value,
rapidjson::Document::AllocatorType &a)
{
rapidjson::Value ret(rapidjson::kObjectType);
template <>
struct Serialize<chatterino::IgnorePhrase> {
static rapidjson::Value get(const chatterino::IgnorePhrase &value,
rapidjson::Document::AllocatorType &a)
{
rapidjson::Value ret(rapidjson::kObjectType);
AddMember(ret, "pattern", value.getPattern(), a);
AddMember(ret, "regex", value.isRegex(), a);
AddMember(ret, "pattern", value.getPattern(), a);
AddMember(ret, "regex", value.isRegex(), a);
AddMember(ret, "isBlock", value.isBlock(), a);
AddMember(ret, "replaceWith", value.getReplace(), a);
AddMember(ret, "caseSensitive", value.isCaseSensitive(), a);
return ret;
return ret;
}
};
template <>
struct Deserialize<chatterino::IgnorePhrase> {
static chatterino::IgnorePhrase get(const rapidjson::Value &value)
{
if (!value.IsObject()) {
return chatterino::IgnorePhrase(
QString(), false, false,
::chatterino::getSettings()->ignoredPhraseReplace.getValue(), true);
}
};
template <>
struct Deserialize<chatterino::IgnorePhrase> {
static chatterino::IgnorePhrase get(const rapidjson::Value &value)
{
if (!value.IsObject()) {
return chatterino::IgnorePhrase(QString(), false);
}
QString _pattern;
bool _isRegex = false;
bool _isBlock = false;
QString _replace;
bool _caseSens = true;
QString _pattern;
bool _isRegex = false;
chatterino::rj::getSafe(value, "pattern", _pattern);
chatterino::rj::getSafe(value, "regex", _isRegex);
return chatterino::IgnorePhrase(_pattern, _isRegex);
}
};
chatterino::rj::getSafe(value, "pattern", _pattern);
chatterino::rj::getSafe(value, "regex", _isRegex);
chatterino::rj::getSafe(value, "isBlock", _isBlock);
chatterino::rj::getSafe(value, "replaceWith", _replace);
chatterino::rj::getSafe(value, "caseSensitive", _caseSens);
return chatterino::IgnorePhrase(_pattern, _isRegex, _isBlock, _replace, _caseSens);
}
};
} // namespace Settings
} // namespace pajlada