From 2816116136ad44f8f9b2c95a39e11f31d64076e4 Mon Sep 17 00:00:00 2001 From: tastytea Date: Sat, 23 Jan 2021 23:18:03 +0100 Subject: [PATCH] =?UTF-8?q?Automatically=20add=20=E2=80=9Cfascism=E2=80=9D?= =?UTF-8?q?=20tag=20if=20=E2=80=9Cnazism=E2=80=9D=20is=20present.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/cgi.cpp | 15 +++++++++++++++ src/cgi.hpp | 9 +++++++++ 2 files changed, 24 insertions(+) diff --git a/src/cgi.cpp b/src/cgi.cpp index 87b8113..921c1e9 100644 --- a/src/cgi.cpp +++ b/src/cgi.cpp @@ -77,6 +77,7 @@ entry_type parse_formdata() } entry.instance = cgi("instance"); + if (!cgi("tags").empty()) // Old form. { entry.tags = string_to_vector(cgi("tags")); @@ -87,6 +88,8 @@ entry_type parse_formdata() } transform(entry.tags.begin(), entry.tags.end(), entry.tags.begin(), [](const auto &tag) { return tolower(tag); }); + add_tags(entry); + if (!cgi("receipts").empty()) // Old form. { entry.receipts = string_to_vector(cgi("receipts")); @@ -95,6 +98,7 @@ entry_type parse_formdata() { entry.receipts = get_array("receipts[]"); } + entry.description = cgi("description"); entry.report_time = time::to_string(system_clock::now()); @@ -237,6 +241,17 @@ bool is_spam(const entry_type &entry) return false; } +void add_tags(entry_type &entry) +{ + for (const auto &tag : entry.tags) + { + if (tag == "nazism") + { + entry.tags.emplace_back("fascism"); + } + } +} + } // namespace FediBlock::cgi const char *SpamException::what() const noexcept diff --git a/src/cgi.hpp b/src/cgi.hpp index 9929cf3..8c4ce51 100644 --- a/src/cgi.hpp +++ b/src/cgi.hpp @@ -56,6 +56,15 @@ bool captcha_valid(std::uint8_t id, string_view answer); bool is_spam(const entry_type &entry); +/*! + * @brief Add automatic tags. + * + * Example: If tag “nazism” is present, add “fascism”. + * + * @since 0.1.0 + */ +void add_tags(entry_type &entry); + } // namespace FediBlock::cgi class SpamException : public std::exception