diff options
| author | hibby <d@vehibberd.com> | 2026-10-06 21:24:40 +0100 |
|---|---|---|
| committer | hibby <d@vehibberd.com> | 2026-10-06 21:24:40 +0100 |
| commit | c25cbdf6fb6d946175f4335fab77bfea601b56db (patch) | |
| tree | 6f7a94b7b81f999e434f61b73d47e337dfd26bf2 /MessageFilterRules.cpp | |
| parent | 71f5689252c9f13e70e1c24856904475b2307809 (diff) | |
| parent | 0685fcada9f95fe90f70b387cd7d757da8209624 (diff) | |
Merge tag 'debian/3.2.0_rc1+dfsg-2' into debian/trixie-backportsdebian/trixie-backports
tagging wsjtx 3.2.0~rc1+dfsg-2
Diffstat (limited to 'MessageFilterRules.cpp')
| -rw-r--r-- | MessageFilterRules.cpp | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/MessageFilterRules.cpp b/MessageFilterRules.cpp new file mode 100644 index 00000000..6208d998 --- /dev/null +++ b/MessageFilterRules.cpp @@ -0,0 +1,72 @@ +#include "MessageFilterRules.hpp" + +#include "MessageFilter.hpp" + +#include <QRegularExpression> +#include <QStringList> + +namespace +{ + using SpecOp = SpecialOperatingActivity; + +#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) + auto const SkipEmptyParts = Qt::SkipEmptyParts; +#else + auto const SkipEmptyParts = QString::SkipEmptyParts; +#endif + + QString msk144FilterText(QString const& text, MessageFilterLogic::FilterContext const& ctx) + { + if (!ctx.filtersForWord2) return text; + + QStringList const words = text.mid(24).split(" ", SkipEmptyParts); + if (words.size() < 2) return "___"; + if (words[1].length() == 2 && words[1].contains(QRegularExpression{"\\w\\w"})) { + return words.size() > 2 ? words[2] : "___"; + } + return words[1]; + } + + bool containsFilterMatch(QString const& filterText, QStringList const& keywords, bool startsWith) + { + return startsWith ? MessageFilter::startsWithAny(filterText, keywords) + : MessageFilter::containsAny(filterText, keywords); + } +} + +MessageFilterRules::Evaluation MessageFilterRules::evaluateMSK144Text(QString text, MessageFilterLogic::FilterContext const& ctx) +{ + Evaluation evaluation; + text = text.replace("<", "").replace(">", ""); + + bool const startsWith = ctx.filtersForWord2; + QString const filterText = msk144FilterText(text, ctx); + + if (SpecOp::NONE == ctx.specOp && ctx.alwaysPass && containsFilterMatch(filterText, ctx.passKeywords, startsWith)) { + return evaluation; + } + + evaluation.filtersApplied = true; + + if (SpecOp::NONE == ctx.specOp && ctx.blacklisted && containsFilterMatch(filterText, ctx.blacklistKeywords, startsWith)) { + if (!ctx.bypass) evaluation.result.filtered = true; + if (!(ctx.filtersForWaitAndPounceOnly || ctx.bypass)) { + evaluation.result.shouldReturn = true; + return evaluation; + } + if (ctx.pounce && isScoringAutoRespondPolicy (ctx.respondPolicy)) { + evaluation.result.resetPoints = true; + } + } else if (SpecOp::NONE == ctx.specOp && ctx.whitelisted && !containsFilterMatch(filterText, ctx.whitelistKeywords, startsWith)) { + if (!ctx.bypass) evaluation.result.filtered = true; + if (!(ctx.filtersForWaitAndPounceOnly || ctx.bypass)) { + evaluation.result.shouldReturn = true; + return evaluation; + } + if (ctx.pounce && isScoringAutoRespondPolicy (ctx.respondPolicy)) { + evaluation.result.resetPoints = true; + } + } + + return evaluation; +} |
