From 89bd7f37f17704af3114c80c57d89db6212748a3 Mon Sep 17 00:00:00 2001 From: RadRussianRus Date: Fri, 26 Aug 2022 22:32:27 +0300 Subject: [PATCH] [Option][JSON] Custom auto-replaces --- .../SourceFiles/kotato/kotato_settings.cpp | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/Telegram/SourceFiles/kotato/kotato_settings.cpp b/Telegram/SourceFiles/kotato/kotato_settings.cpp index b2a4bf772..1f96547f2 100644 --- a/Telegram/SourceFiles/kotato/kotato_settings.cpp +++ b/Telegram/SourceFiles/kotato/kotato_settings.cpp @@ -171,6 +171,33 @@ CheckHandler ScalesLimit() { }; } +CheckHandler ReplacesLimit() { + return [=] (QVariant value) -> QVariant { + auto newArrayValue = QJsonArray(); + if (value.canConvert()) { + auto arrayValue = value.toJsonArray(); + for (auto i = arrayValue.begin(); i != arrayValue.end(); ++i) { + if (!(*i).isArray()) { + continue; + } + + const auto a = (*i).toArray(); + if (a.size() != 2 || !a.at(0).isString() || !a.at(1).isString()) { + continue; + } + + const auto from = a.at(0).toString(); + const auto to = a.at(1).toString(); + Ui::AddCustomReplacement(from, to); + + newArrayValue.append(a); + } + } + + return newArrayValue; + }; +} + CheckHandler NetSpeedBoostConv(CheckHandler wrapped = nullptr) { return [=] (QVariant value) -> QVariant { @@ -319,6 +346,9 @@ const std::map> DefinitionMap { { "disable_up_edit", { .type = SettingType::BoolSetting, .defaultValue = false, }}, + { "replaces", { + .type = SettingType::QJsonArraySetting, + .limitHandler = ReplacesLimit(), }}, }; using OldOptionKey = QString;