From 32a2de1befaa82ab168ae1ca57ed360750a0caa4 Mon Sep 17 00:00:00 2001 From: ZavaruKitsu Date: Sun, 9 Jul 2023 18:09:01 +0000 Subject: [PATCH] feat: reformat ayu files with resharper --- Telegram/SourceFiles/ayu/ayu_lang.cpp | 222 ++--- Telegram/SourceFiles/ayu/ayu_lang.h | 36 +- Telegram/SourceFiles/ayu/ayu_settings.cpp | 348 ++++---- Telegram/SourceFiles/ayu/ayu_settings.h | 213 ++--- Telegram/SourceFiles/ayu/ayu_state.cpp | 23 +- Telegram/SourceFiles/ayu/ayu_state.h | 52 +- .../SourceFiles/ayu/database/ayu_database.cpp | 95 +-- .../SourceFiles/ayu/database/ayu_database.h | 35 +- Telegram/SourceFiles/ayu/database/entities.h | 17 +- Telegram/SourceFiles/ayu/libs/json_ext.hpp | 12 +- .../ayu/sync/ayu_sync_controller.cpp | 176 ++-- .../ayu/sync/ayu_sync_controller.h | 39 +- Telegram/SourceFiles/ayu/sync/models.h | 86 +- .../ayu/sync/utils/ayu_pipe_wrapper.cpp | 71 +- .../ayu/sync/utils/ayu_pipe_wrapper.h | 11 +- .../ayu/sync/utils/process_utils.hpp | 70 +- .../ayu/sync/utils/telegram_helpers.cpp | 31 +- .../ayu/sync/utils/telegram_helpers.h | 2 +- .../ayu/ui/boxes/confirmation_box.cpp | 88 +- .../ayu/ui/boxes/confirmation_box.h | 28 +- .../ayu/ui/boxes/edit_deleted_mark.cpp | 107 +-- .../ayu/ui/boxes/edit_deleted_mark.h | 19 +- .../ayu/ui/boxes/edit_edited_mark.cpp | 110 +-- .../ayu/ui/boxes/edit_edited_mark.h | 21 +- .../ayu/ui/boxes/voice_confirmation_box.cpp | 184 +++-- .../ayu/ui/boxes/voice_confirmation_box.h | 14 +- .../ayu/ui/context_menu/context_menu.cpp | 81 +- .../ayu/ui/context_menu/context_menu.h | 140 ++-- .../ui/context_menu/message_history_box.cpp | 99 +-- .../ayu/ui/context_menu/message_history_box.h | 36 +- .../ayu/ui/settings/settings_ayu.cpp | 764 ++++++++++-------- .../ayu/ui/settings/settings_ayu.h | 45 +- .../ayu/ui/utils/ayu_profile_values.cpp | 62 +- .../ayu/ui/utils/ayu_profile_values.h | 6 +- .../info/profile/info_profile_actions.cpp | 113 +-- 35 files changed, 1866 insertions(+), 1590 deletions(-) diff --git a/Telegram/SourceFiles/ayu/ayu_lang.cpp b/Telegram/SourceFiles/ayu/ayu_lang.cpp index 7343f75f6..974c3f332 100644 --- a/Telegram/SourceFiles/ayu/ayu_lang.cpp +++ b/Telegram/SourceFiles/ayu/ayu_lang.cpp @@ -8,127 +8,155 @@ #include "ayu_lang.h" #include "qjsondocument.h" -#include "lang/lang_instance.h" #include "core/application.h" #include "core/core_settings.h" +#include "lang/lang_instance.h" -CustomLangPack *CustomLangPack::instance = nullptr; +CustomLangPack* CustomLangPack::instance = nullptr; CustomLangPack::CustomLangPack() = default; -void CustomLangPack::initInstance() { - if (!instance) - instance = new CustomLangPack; +void CustomLangPack::initInstance() +{ + if (!instance) + instance = new CustomLangPack; } -CustomLangPack *CustomLangPack::currentInstance() { - return instance; +CustomLangPack* CustomLangPack::currentInstance() +{ + return instance; } -void CustomLangPack::fetchCustomLangPack(const QString &langPackId, const QString &langPackBaseId) { - LOG(("Current Language pack ID: %1, Base ID: %2").arg(langPackId, langPackBaseId)); +void CustomLangPack::fetchCustomLangPack(const QString& langPackId, const QString& langPackBaseId) +{ + LOG(("Current Language pack ID: %1, Base ID: %2").arg(langPackId, langPackBaseId)); - auto finalLangPackId = langPackId; - if (finalLangPackId == qsl("pt-br")) { // meh - finalLangPackId = qsl("pt"); - } + auto finalLangPackId = langPackId; + if (finalLangPackId == qsl("pt-br")) + { + // meh + finalLangPackId = qsl("pt"); + } - const auto proxy = Core::App().settings().proxy().isEnabled() ? Core::App().settings().proxy().selected() - : MTP::ProxyData(); - if (proxy.type == MTP::ProxyData::Type::Socks5 || proxy.type == MTP::ProxyData::Type::Http) { - QNetworkProxy LocaleProxy = MTP::ToNetworkProxy(MTP::ToDirectIpProxy(proxy)); - networkManager.setProxy(LocaleProxy); - } + const auto proxy = Core::App().settings().proxy().isEnabled() + ? Core::App().settings().proxy().selected() + : MTP::ProxyData(); + if (proxy.type == MTP::ProxyData::Type::Socks5 || proxy.type == MTP::ProxyData::Type::Http) + { + QNetworkProxy LocaleProxy = ToNetworkProxy(ToDirectIpProxy(proxy)); + networkManager.setProxy(LocaleProxy); + } - QUrl url; - if (!finalLangPackId.isEmpty() && !langPackBaseId.isEmpty() && !needFallback) { - url.setUrl(qsl("https://raw.githubusercontent.com/AyuGram/Languages/l10n_main/values/langs/%1/Shared.json").arg( - finalLangPackId)); - } else { - url.setUrl(qsl("https://raw.githubusercontent.com/AyuGram/Languages/l10n_main/values/langs/%1/Shared.json").arg( - needFallback ? langPackBaseId : finalLangPackId)); - } - _chkReply = networkManager.get(QNetworkRequest(url)); - connect(_chkReply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(fetchError(QNetworkReply::NetworkError))); - connect(_chkReply, SIGNAL(finished()), this, SLOT(fetchFinished())); - LOG(("Fetching %1 lang pack...").arg( - needFallback ? (langPackBaseId.isEmpty() ? finalLangPackId : langPackBaseId) : finalLangPackId)); + QUrl url; + if (!finalLangPackId.isEmpty() && !langPackBaseId.isEmpty() && !needFallback) + { + url.setUrl(qsl("https://raw.githubusercontent.com/AyuGram/Languages/l10n_main/values/langs/%1/Shared.json").arg( + finalLangPackId)); + } + else + { + url.setUrl(qsl("https://raw.githubusercontent.com/AyuGram/Languages/l10n_main/values/langs/%1/Shared.json").arg( + needFallback ? langPackBaseId : finalLangPackId)); + } + _chkReply = networkManager.get(QNetworkRequest(url)); + connect(_chkReply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(fetchError(QNetworkReply::NetworkError))); + connect(_chkReply, SIGNAL(finished()), this, SLOT(fetchFinished())); + LOG(("Fetching %1 lang pack...").arg( + needFallback ? (langPackBaseId.isEmpty() ? finalLangPackId : langPackBaseId) : finalLangPackId)); } -void CustomLangPack::fetchFinished() { - if (!_chkReply) return; +void CustomLangPack::fetchFinished() +{ + if (!_chkReply) return; - QString langPackBaseId = Lang::GetInstance().baseId(); - QString langPackId = Lang::GetInstance().id(); - auto statusCode = _chkReply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); + QString langPackBaseId = Lang::GetInstance().baseId(); + QString langPackId = Lang::GetInstance().id(); + auto statusCode = _chkReply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); - if (statusCode == 404 && !langPackId.isEmpty() && !langPackBaseId.isEmpty() && !needFallback) { - LOG(("AyuGram Language pack not found! Fallback to main language: %1...").arg(langPackBaseId)); - needFallback = true; - _chkReply->disconnect(); - fetchCustomLangPack("", langPackBaseId); - } else { - QByteArray result = _chkReply->readAll().trimmed(); - QJsonParseError error{}; - QJsonDocument str = QJsonDocument::fromJson(result, &error); - if (error.error == QJsonParseError::NoError) { - parseLangFile(str); - } else { - LOG(("Incorrect JSON File. Fallback to default language: English...")); - loadDefaultLangFile(); - } + if (statusCode == 404 && !langPackId.isEmpty() && !langPackBaseId.isEmpty() && !needFallback) + { + LOG(("AyuGram Language pack not found! Fallback to main language: %1...").arg(langPackBaseId)); + needFallback = true; + _chkReply->disconnect(); + fetchCustomLangPack("", langPackBaseId); + } + else + { + QByteArray result = _chkReply->readAll().trimmed(); + QJsonParseError error{}; + QJsonDocument str = QJsonDocument::fromJson(result, &error); + if (error.error == QJsonParseError::NoError) + { + parseLangFile(str); + } + else + { + LOG(("Incorrect JSON File. Fallback to default language: English...")); + loadDefaultLangFile(); + } - _chkReply = nullptr; - } + _chkReply = nullptr; + } } -void CustomLangPack::fetchError(QNetworkReply::NetworkError e) { - LOG(("Network error: %1").arg(e)); +void CustomLangPack::fetchError(QNetworkReply::NetworkError e) +{ + LOG(("Network error: %1").arg(e)); - if (e == QNetworkReply::NetworkError::ContentNotFoundError) { - QString langPackBaseId = Lang::GetInstance().baseId(); - QString langPackId = Lang::GetInstance().id(); + if (e == QNetworkReply::NetworkError::ContentNotFoundError) + { + QString langPackBaseId = Lang::GetInstance().baseId(); + QString langPackId = Lang::GetInstance().id(); - if (!langPackId.isEmpty() && !langPackBaseId.isEmpty() && !needFallback) { - LOG(("AyuGram Language pack not found! Fallback to main language: %1...").arg(langPackBaseId)); - needFallback = true; - _chkReply->disconnect(); - fetchCustomLangPack("", langPackBaseId); - } else { - LOG(("AyuGram Language pack not found! Fallback to default language: English...")); - loadDefaultLangFile(); - _chkReply = nullptr; - } - } + if (!langPackId.isEmpty() && !langPackBaseId.isEmpty() && !needFallback) + { + LOG(("AyuGram Language pack not found! Fallback to main language: %1...").arg(langPackBaseId)); + needFallback = true; + _chkReply->disconnect(); + fetchCustomLangPack("", langPackBaseId); + } + else + { + LOG(("AyuGram Language pack not found! Fallback to default language: English...")); + loadDefaultLangFile(); + _chkReply = nullptr; + } + } } -void CustomLangPack::loadDefaultLangFile() { - QFile file(":/localization/en.json"); - if (file.open(QIODevice::ReadOnly)) { - QJsonDocument str = QJsonDocument::fromJson(file.readAll()); - QJsonObject json = str.object(); - for (const QString &key: json.keys()) { - Lang::GetInstance().applyValue(key.toUtf8(), json.value(key).toString().toUtf8()); - } - Lang::GetInstance().updatePluralRules(); - file.close(); - } +void CustomLangPack::loadDefaultLangFile() +{ + QFile file(":/localization/en.json"); + if (file.open(QIODevice::ReadOnly)) + { + QJsonDocument str = QJsonDocument::fromJson(file.readAll()); + QJsonObject json = str.object(); + for (const QString& key : json.keys()) + { + Lang::GetInstance().applyValue(key.toUtf8(), json.value(key).toString().toUtf8()); + } + Lang::GetInstance().updatePluralRules(); + file.close(); + } } -void CustomLangPack::parseLangFile(QJsonDocument str) { - QJsonObject json = str.object(); - for (const QString &brokenKey: json.keys()) { - auto key = qsl("ayu_") + brokenKey; - auto val = json.value(brokenKey).toString().replace(qsl("&"), qsl("&")).toUtf8(); +void CustomLangPack::parseLangFile(QJsonDocument str) +{ + QJsonObject json = str.object(); + for (const QString& brokenKey : json.keys()) + { + auto key = qsl("ayu_") + brokenKey; + auto val = json.value(brokenKey).toString().replace(qsl("&"), qsl("&")).toUtf8(); - Lang::GetInstance().resetValue(key.toUtf8()); - Lang::GetInstance().applyValue(key.toUtf8(), val); - if (key.contains("#other")) { - Lang::GetInstance().resetValue(key.toUtf8().replace("#other", "#few")); - Lang::GetInstance().resetValue(key.toUtf8().replace("#other", "#few")); - Lang::GetInstance().applyValue(key.toUtf8().replace("#other", "#few"), val); - Lang::GetInstance().applyValue(key.toUtf8().replace("#other", "#many"), val); - } - } - Lang::GetInstance().updatePluralRules(); -} \ No newline at end of file + Lang::GetInstance().resetValue(key.toUtf8()); + Lang::GetInstance().applyValue(key.toUtf8(), val); + if (key.contains("#other")) + { + Lang::GetInstance().resetValue(key.toUtf8().replace("#other", "#few")); + Lang::GetInstance().resetValue(key.toUtf8().replace("#other", "#few")); + Lang::GetInstance().applyValue(key.toUtf8().replace("#other", "#few"), val); + Lang::GetInstance().applyValue(key.toUtf8().replace("#other", "#many"), val); + } + } + Lang::GetInstance().updatePluralRules(); +} diff --git a/Telegram/SourceFiles/ayu/ayu_lang.h b/Telegram/SourceFiles/ayu/ayu_lang.h index 5c5a82dde..6705d4843 100644 --- a/Telegram/SourceFiles/ayu/ayu_lang.h +++ b/Telegram/SourceFiles/ayu/ayu_lang.h @@ -10,36 +10,36 @@ #include #include -class CustomLangPack : public QObject { -Q_OBJECT +class CustomLangPack : public QObject +{ + Q_OBJECT - Q_DISABLE_COPY(CustomLangPack) + Q_DISABLE_COPY(CustomLangPack) public: - static CustomLangPack *currentInstance(); + static CustomLangPack* currentInstance(); - static void initInstance(); + static void initInstance(); - static CustomLangPack *instance; + static CustomLangPack* instance; - void fetchCustomLangPack(const QString &langPackId, const QString &langPackBaseId); + void fetchCustomLangPack(const QString& langPackId, const QString& langPackBaseId); - void loadDefaultLangFile(); + void loadDefaultLangFile(); - void parseLangFile(QJsonDocument str); + void parseLangFile(QJsonDocument str); public Q_SLOTS: + void fetchFinished(); - void fetchFinished(); - - void fetchError(QNetworkReply::NetworkError e); + void fetchError(QNetworkReply::NetworkError e); private: - CustomLangPack(); + CustomLangPack(); - ~CustomLangPack() = default; + ~CustomLangPack() override = default; - QNetworkAccessManager networkManager; - QNetworkReply *_chkReply = nullptr; - bool needFallback = false; -}; \ No newline at end of file + QNetworkAccessManager networkManager; + QNetworkReply* _chkReply = nullptr; + bool needFallback = false; +}; diff --git a/Telegram/SourceFiles/ayu/ayu_settings.cpp b/Telegram/SourceFiles/ayu/ayu_settings.cpp index 44eb016a6..3a2f60675 100644 --- a/Telegram/SourceFiles/ayu/ayu_settings.cpp +++ b/Telegram/SourceFiles/ayu/ayu_settings.cpp @@ -12,199 +12,239 @@ using json = nlohmann::json; -namespace AyuSettings { - const QString filename = "tdata/ayu_settings.json"; - std::optional settings = std::nullopt; +namespace AyuSettings +{ + const QString filename = "tdata/ayu_settings.json"; + std::optional settings = std::nullopt; - rpl::variable sendReadPacketsReactive; - rpl::variable sendOnlinePacketsReactive; - rpl::variable sendUploadProgressReactive; - rpl::variable sendOfflinePacketAfterOnlineReactive; + rpl::variable sendReadPacketsReactive; + rpl::variable sendOnlinePacketsReactive; + rpl::variable sendUploadProgressReactive; + rpl::variable sendOfflinePacketAfterOnlineReactive; - rpl::variable deletedMarkReactive; - rpl::variable editedMarkReactive; - rpl::variable showPeerIdReactive; + rpl::variable deletedMarkReactive; + rpl::variable editedMarkReactive; + rpl::variable showPeerIdReactive; - rpl::variable ghostModeEnabled; + rpl::variable ghostModeEnabled; - rpl::lifetime lifetime = rpl::lifetime(); + rpl::lifetime lifetime = rpl::lifetime(); - bool ghostModeEnabled_util(AyuGramSettings &settingsUtil) { - return (!settingsUtil.sendReadPackets - && !settingsUtil.sendOnlinePackets - && !settingsUtil.sendUploadProgress - && settingsUtil.sendOfflinePacketAfterOnline); - } + bool ghostModeEnabled_util(AyuGramSettings& settingsUtil) + { + return (!settingsUtil.sendReadPackets + && !settingsUtil.sendOnlinePackets + && !settingsUtil.sendUploadProgress + && settingsUtil.sendOfflinePacketAfterOnline); + } - void initialize() { - if (settings.has_value()) { - return; - } + void initialize() + { + if (settings.has_value()) + { + return; + } - settings = AyuGramSettings(); + settings = AyuGramSettings(); - sendReadPacketsReactive.value() | rpl::filter([=](bool val) { - return (val != settings->sendReadPackets); - }) | rpl::start_with_next([=](bool val) { - ghostModeEnabled = ghostModeEnabled_util(settings.value()); - }, lifetime); - sendOnlinePacketsReactive.value() | rpl::filter([=](bool val) { - return (val != settings->sendOnlinePackets); - }) | rpl::start_with_next([=](bool val) { - ghostModeEnabled = ghostModeEnabled_util(settings.value()); - }, lifetime); - sendUploadProgressReactive.value() | rpl::filter([=](bool val) { - return (val != settings->sendUploadProgress); - }) | rpl::start_with_next([=](bool val) { - ghostModeEnabled = ghostModeEnabled_util(settings.value()); - }, lifetime); - sendOfflinePacketAfterOnlineReactive.value() | rpl::filter([=](bool val) { - return (val != settings->sendOfflinePacketAfterOnline); - }) | rpl::start_with_next([=](bool val) { - ghostModeEnabled = ghostModeEnabled_util(settings.value()); - }, lifetime); - } + sendReadPacketsReactive.value() | rpl::filter([=](bool val) + { + return (val != settings->sendReadPackets); + }) | start_with_next([=](bool val) + { + ghostModeEnabled = ghostModeEnabled_util(settings.value()); + }, lifetime); + sendOnlinePacketsReactive.value() | rpl::filter([=](bool val) + { + return (val != settings->sendOnlinePackets); + }) | start_with_next([=](bool val) + { + ghostModeEnabled = ghostModeEnabled_util(settings.value()); + }, lifetime); + sendUploadProgressReactive.value() | rpl::filter([=](bool val) + { + return (val != settings->sendUploadProgress); + }) | start_with_next([=](bool val) + { + ghostModeEnabled = ghostModeEnabled_util(settings.value()); + }, lifetime); + sendOfflinePacketAfterOnlineReactive.value() | rpl::filter([=](bool val) + { + return (val != settings->sendOfflinePacketAfterOnline); + }) | start_with_next([=](bool val) + { + ghostModeEnabled = ghostModeEnabled_util(settings.value()); + }, lifetime); + } - void postinitialize() { - sendReadPacketsReactive = settings->sendReadPackets; - sendOnlinePacketsReactive = settings->sendOnlinePackets; + void postinitialize() + { + sendReadPacketsReactive = settings->sendReadPackets; + sendOnlinePacketsReactive = settings->sendOnlinePackets; - deletedMarkReactive = settings->deletedMark; - editedMarkReactive = settings->editedMark; - showPeerIdReactive = settings->showPeerId; + deletedMarkReactive = settings->deletedMark; + editedMarkReactive = settings->editedMark; + showPeerIdReactive = settings->showPeerId; - ghostModeEnabled = ghostModeEnabled_util(settings.value()); - } + ghostModeEnabled = ghostModeEnabled_util(settings.value()); + } - AyuGramSettings &getInstance() { - initialize(); - return settings.value(); - } + AyuGramSettings& getInstance() + { + initialize(); + return settings.value(); + } - void load() { - QFile file(filename); - if (!file.exists()) { - return; - } - file.open(QIODevice::ReadOnly); - QByteArray data = file.readAll(); - file.close(); + void load() + { + QFile file(filename); + if (!file.exists()) + { + return; + } + file.open(QIODevice::ReadOnly); + QByteArray data = file.readAll(); + file.close(); - initialize(); - json p = json::parse(data); - settings = p.template get(); - postinitialize(); - } + initialize(); + json p = json::parse(data); + settings = p.get(); + postinitialize(); + } - void save() { - initialize(); + void save() + { + initialize(); - json p = settings.value(); + json p = settings.value(); - QFile file(filename); - file.open(QIODevice::WriteOnly); - file.write(p.dump().c_str()); - file.close(); + QFile file(filename); + file.open(QIODevice::WriteOnly); + file.write(p.dump().c_str()); + file.close(); - postinitialize(); - } + postinitialize(); + } - void AyuGramSettings::set_sendReadPackets(bool val) { - sendReadPackets = val; - sendReadPacketsReactive = val; - } + void AyuGramSettings::set_sendReadPackets(bool val) + { + sendReadPackets = val; + sendReadPacketsReactive = val; + } - void AyuGramSettings::set_sendOnlinePackets(bool val) { - sendOnlinePackets = val; - sendOnlinePacketsReactive = val; - } + void AyuGramSettings::set_sendOnlinePackets(bool val) + { + sendOnlinePackets = val; + sendOnlinePacketsReactive = val; + } - void AyuGramSettings::set_sendUploadProgress(bool val) { - sendUploadProgress = val; - sendUploadProgressReactive = val; - } + void AyuGramSettings::set_sendUploadProgress(bool val) + { + sendUploadProgress = val; + sendUploadProgressReactive = val; + } - void AyuGramSettings::set_sendOfflinePacketAfterOnline(bool val) { - sendOfflinePacketAfterOnline = val; - sendOfflinePacketAfterOnlineReactive = val; - } + void AyuGramSettings::set_sendOfflinePacketAfterOnline(bool val) + { + sendOfflinePacketAfterOnline = val; + sendOfflinePacketAfterOnlineReactive = val; + } - void AyuGramSettings::set_markReadAfterSend(bool val) { - markReadAfterSend = val; - } + void AyuGramSettings::set_markReadAfterSend(bool val) + { + markReadAfterSend = val; + } - void AyuGramSettings::set_useScheduledMessages(bool val) { - useScheduledMessages = val; - } + void AyuGramSettings::set_useScheduledMessages(bool val) + { + useScheduledMessages = val; + } - void AyuGramSettings::set_keepDeletedMessages(bool val) { - keepDeletedMessages = val; - } + void AyuGramSettings::set_keepDeletedMessages(bool val) + { + keepDeletedMessages = val; + } - void AyuGramSettings::set_keepMessagesHistory(bool val) { - keepMessagesHistory = val; - } + void AyuGramSettings::set_keepMessagesHistory(bool val) + { + keepMessagesHistory = val; + } - void AyuGramSettings::set_enableAds(bool val) { - enableAds = val; - } + void AyuGramSettings::set_enableAds(bool val) + { + enableAds = val; + } - void AyuGramSettings::set_deletedMark(QString val) { - deletedMark = std::move(val); - deletedMarkReactive = deletedMark; - } + void AyuGramSettings::set_deletedMark(QString val) + { + deletedMark = std::move(val); + deletedMarkReactive = deletedMark; + } - void AyuGramSettings::set_editedMark(QString val) { - editedMark = std::move(val); - editedMarkReactive = editedMark; - } + void AyuGramSettings::set_editedMark(QString val) + { + editedMark = std::move(val); + editedMarkReactive = editedMark; + } - void AyuGramSettings::set_recentStickersCount(int val) { - recentStickersCount = val; - } + void AyuGramSettings::set_recentStickersCount(int val) + { + recentStickersCount = val; + } - void AyuGramSettings::set_showGhostToggleInDrawer(bool val) { - showGhostToggleInDrawer = val; - } + void AyuGramSettings::set_showGhostToggleInDrawer(bool val) + { + showGhostToggleInDrawer = val; + } - void AyuGramSettings::set_showPeerId(int val) { - showPeerId = val; - showPeerIdReactive = val; - } + void AyuGramSettings::set_showPeerId(int val) + { + showPeerId = val; + showPeerIdReactive = val; + } - void AyuGramSettings::set_showMessageSeconds(bool val) { - showMessageSeconds = val; - } + void AyuGramSettings::set_showMessageSeconds(bool val) + { + showMessageSeconds = val; + } - void AyuGramSettings::set_stickerConfirmation(bool val) { - stickerConfirmation = val; - } + void AyuGramSettings::set_stickerConfirmation(bool val) + { + stickerConfirmation = val; + } - void AyuGramSettings::set_GIFConfirmation(bool val) { - GIFConfirmation = val; - } + void AyuGramSettings::set_GIFConfirmation(bool val) + { + GIFConfirmation = val; + } - void AyuGramSettings::set_voiceConfirmation(bool val) { - voiceConfirmation = val; - } + void AyuGramSettings::set_voiceConfirmation(bool val) + { + voiceConfirmation = val; + } - bool get_ghostModeEnabled() { - return ghostModeEnabled.current(); - } + bool get_ghostModeEnabled() + { + return ghostModeEnabled.current(); + } - rpl::producer get_deletedMarkReactive() { - return deletedMarkReactive.value(); - } + rpl::producer get_deletedMarkReactive() + { + return deletedMarkReactive.value(); + } - rpl::producer get_editedMarkReactive() { - return editedMarkReactive.value(); - } + rpl::producer get_editedMarkReactive() + { + return editedMarkReactive.value(); + } - rpl::producer get_showPeerIdReactive() { - return showPeerIdReactive.value(); - } + rpl::producer get_showPeerIdReactive() + { + return showPeerIdReactive.value(); + } - rpl::producer get_ghostModeEnabledReactive() { - return ghostModeEnabled.value(); - } + rpl::producer get_ghostModeEnabledReactive() + { + return ghostModeEnabled.value(); + } } diff --git a/Telegram/SourceFiles/ayu/ayu_settings.h b/Telegram/SourceFiles/ayu/ayu_settings.h index 554d43a40..6e6aba0e1 100644 --- a/Telegram/SourceFiles/ayu/ayu_settings.h +++ b/Telegram/SourceFiles/ayu/ayu_settings.h @@ -7,149 +7,152 @@ #pragma once -#include "rpl/producer.h" #include "lang_auto.h" #include "ayu/libs/json.hpp" #include "ayu/libs/json_ext.hpp" +#include "rpl/producer.h" -namespace AyuSettings { - class AyuGramSettings { - public: - AyuGramSettings() { - // ~ Ghost essentials - sendReadPackets = true; - sendOnlinePackets = true; - sendUploadProgress = true; +namespace AyuSettings +{ + class AyuGramSettings + { + public: + AyuGramSettings() + { + // ~ Ghost essentials + sendReadPackets = true; + sendOnlinePackets = true; + sendUploadProgress = true; - sendOfflinePacketAfterOnline = false; - markReadAfterSend = true; + sendOfflinePacketAfterOnline = false; + markReadAfterSend = true; - useScheduledMessages = false; + useScheduledMessages = false; - // ~ Message edits & deletion history - keepDeletedMessages = true; - keepMessagesHistory = true; + // ~ Message edits & deletion history + keepDeletedMessages = true; + keepMessagesHistory = true; - // ~ QoL toggles - enableAds = false; + // ~ QoL toggles + enableAds = false; - // ~ Customization - deletedMark = "🧹"; - editedMark = tr::lng_edited(tr::now); - recentStickersCount = 20; - showGhostToggleInDrawer = true; + // ~ Customization + deletedMark = "🧹"; + editedMark = tr::lng_edited(tr::now); + recentStickersCount = 20; + showGhostToggleInDrawer = true; - // ~ Beta functionality - stickerConfirmation = false; - GIFConfirmation = false; - voiceConfirmation = false; + // ~ Beta functionality + stickerConfirmation = false; + GIFConfirmation = false; + voiceConfirmation = false; - /* - * showPeerId = 0 means no ID shown - * showPeerId = 1 means ID shown as for Telegram API devs - * showPeerId = 2 means ID shown as for Bot API devs (-100) - */ - showPeerId = 2; + /* + * showPeerId = 0 means no ID shown + * showPeerId = 1 means ID shown as for Telegram API devs + * showPeerId = 2 means ID shown as for Bot API devs (-100) + */ + showPeerId = 2; - showMessageSeconds = false; - stickerConfirmation = false; - GIFConfirmation = false; - voiceConfirmation = false; - } + showMessageSeconds = false; + stickerConfirmation = false; + GIFConfirmation = false; + voiceConfirmation = false; + } - bool sendReadPackets; - bool sendOnlinePackets; - bool sendUploadProgress; - bool sendOfflinePacketAfterOnline; - bool markReadAfterSend; - bool useScheduledMessages; - bool keepDeletedMessages; - bool keepMessagesHistory; - bool enableAds; - QString deletedMark; - QString editedMark; - int recentStickersCount; - bool showGhostToggleInDrawer; - int showPeerId; - bool showMessageSeconds; - bool stickerConfirmation; - bool GIFConfirmation; - bool voiceConfirmation; + bool sendReadPackets; + bool sendOnlinePackets; + bool sendUploadProgress; + bool sendOfflinePacketAfterOnline; + bool markReadAfterSend; + bool useScheduledMessages; + bool keepDeletedMessages; + bool keepMessagesHistory; + bool enableAds; + QString deletedMark; + QString editedMark; + int recentStickersCount; + bool showGhostToggleInDrawer; + int showPeerId; + bool showMessageSeconds; + bool stickerConfirmation; + bool GIFConfirmation; + bool voiceConfirmation; - public: - void set_sendReadPackets(bool val); + public: + void set_sendReadPackets(bool val); - void set_sendOnlinePackets(bool val); + void set_sendOnlinePackets(bool val); - void set_sendUploadProgress(bool val); + void set_sendUploadProgress(bool val); - void set_sendOfflinePacketAfterOnline(bool val); + void set_sendOfflinePacketAfterOnline(bool val); - void set_markReadAfterSend(bool val); + void set_markReadAfterSend(bool val); - void set_useScheduledMessages(bool val); + void set_useScheduledMessages(bool val); - void set_keepDeletedMessages(bool val); + void set_keepDeletedMessages(bool val); - void set_keepMessagesHistory(bool val); + void set_keepMessagesHistory(bool val); - void set_enableAds(bool val); + void set_enableAds(bool val); - void set_deletedMark(QString val); + void set_deletedMark(QString val); - void set_editedMark(QString val); + void set_editedMark(QString val); - void set_recentStickersCount(int val); + void set_recentStickersCount(int val); - void set_showGhostToggleInDrawer(bool val); + void set_showGhostToggleInDrawer(bool val); - void set_showPeerId(int val); + void set_showPeerId(int val); - void set_showMessageSeconds(bool val); + void set_showMessageSeconds(bool val); - void set_stickerConfirmation(bool val); + void set_stickerConfirmation(bool val); - void set_GIFConfirmation(bool val); + void set_GIFConfirmation(bool val); - void set_voiceConfirmation(bool val); - }; + void set_voiceConfirmation(bool val); + }; - NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE( - AyuGramSettings, - sendReadPackets, - sendOnlinePackets, - sendUploadProgress, - sendOfflinePacketAfterOnline, - markReadAfterSend, - useScheduledMessages, - keepDeletedMessages, - keepMessagesHistory, - enableAds, - deletedMark, - editedMark, - recentStickersCount, - showGhostToggleInDrawer, - showPeerId, - showMessageSeconds, - stickerConfirmation, - GIFConfirmation, - voiceConfirmation - ); + NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE( + AyuGramSettings, + sendReadPackets, + sendOnlinePackets, + sendUploadProgress, + sendOfflinePacketAfterOnline, + markReadAfterSend, + useScheduledMessages, + keepDeletedMessages, + keepMessagesHistory, + enableAds, + deletedMark, + editedMark, + recentStickersCount, + showGhostToggleInDrawer, + showPeerId, + showMessageSeconds, + stickerConfirmation, + GIFConfirmation, + voiceConfirmation + ); - AyuGramSettings &getInstance(); + AyuGramSettings& getInstance(); - void load(); + void load(); - void save(); + void save(); - rpl::producer get_deletedMarkReactive(); + rpl::producer get_deletedMarkReactive(); - rpl::producer get_editedMarkReactive(); + rpl::producer get_editedMarkReactive(); - rpl::producer get_showPeerIdReactive(); + rpl::producer get_showPeerIdReactive(); - // computed fields - bool get_ghostModeEnabled(); + // computed fields + bool get_ghostModeEnabled(); - rpl::producer get_ghostModeEnabledReactive(); + rpl::producer get_ghostModeEnabledReactive(); } diff --git a/Telegram/SourceFiles/ayu/ayu_state.cpp b/Telegram/SourceFiles/ayu/ayu_state.cpp index 862c289f2..2822755cd 100644 --- a/Telegram/SourceFiles/ayu/ayu_state.cpp +++ b/Telegram/SourceFiles/ayu/ayu_state.cpp @@ -7,14 +7,17 @@ #include "ayu_state.h" -namespace AyuState { - void setAllowSendReadPacket(bool val, int resetAfter) { - allowSendReadPacket.val = val; - allowSendReadPacket.resetAfter = resetAfter; - } +namespace AyuState +{ + void setAllowSendReadPacket(bool val, int resetAfter) + { + allowSendReadPacket.val = val; + allowSendReadPacket.resetAfter = resetAfter; + } - bool getAllowSendPacket() { - auto settings = &AyuSettings::getInstance(); - return settings->sendReadPackets || processVariable(allowSendReadPacket); - } -} \ No newline at end of file + bool getAllowSendPacket() + { + auto settings = &AyuSettings::getInstance(); + return settings->sendReadPackets || processVariable(allowSendReadPacket); + } +} diff --git a/Telegram/SourceFiles/ayu/ayu_state.h b/Telegram/SourceFiles/ayu/ayu_state.h index 164ade831..74ac2f7de 100644 --- a/Telegram/SourceFiles/ayu/ayu_state.h +++ b/Telegram/SourceFiles/ayu/ayu_state.h @@ -9,33 +9,39 @@ #include "ayu_settings.h" -namespace AyuState { - namespace { - class AyuStateVariable { - public: - bool val; - int resetAfter; - }; +namespace AyuState +{ + namespace + { + class AyuStateVariable + { + public: + bool val; + int resetAfter; + }; - AyuStateVariable allowSendReadPacket; + AyuStateVariable allowSendReadPacket; - bool processVariable(AyuStateVariable &variable) { - if (variable.resetAfter == -1) { - return variable.val; - } + bool processVariable(AyuStateVariable& variable) + { + if (variable.resetAfter == -1) + { + return variable.val; + } - variable.resetAfter -= 1; - auto val = variable.val; + variable.resetAfter -= 1; + auto val = variable.val; - if (variable.resetAfter == 0) { - variable.val = false; - } + if (variable.resetAfter == 0) + { + variable.val = false; + } - return val; - } - } + return val; + } + } - void setAllowSendReadPacket(bool val, int resetAfter = 1); + void setAllowSendReadPacket(bool val, int resetAfter = 1); - bool getAllowSendPacket(); -} \ No newline at end of file + bool getAllowSendPacket(); +} diff --git a/Telegram/SourceFiles/ayu/database/ayu_database.cpp b/Telegram/SourceFiles/ayu/database/ayu_database.cpp index 5f370c498..9c5631d84 100644 --- a/Telegram/SourceFiles/ayu/database/ayu_database.cpp +++ b/Telegram/SourceFiles/ayu/database/ayu_database.cpp @@ -27,56 +27,59 @@ auto storage = make_storage("ayugram.db", ); -namespace AyuDatabase { - void addEditedMessage( - long userId, - long dialogId, - long messageId, - const QString &text, - bool isDocument, - QString path, - long date) { +namespace AyuDatabase +{ + void addEditedMessage( + long userId, + long dialogId, + long messageId, + const QString& text, + bool isDocument, + QString path, + long date) + { + EditedMessage entity; + entity.userId = userId; + entity.dialogId = dialogId; + entity.messageId = messageId; + entity.text = text.toStdString(); + entity.isDocument = isDocument; + entity.path = path.toStdString(); + entity.date = date; - EditedMessage entity; - entity.userId = userId; - entity.dialogId = dialogId; - entity.messageId = messageId; - entity.text = text.toStdString(); - entity.isDocument = isDocument; - entity.path = path.toStdString(); - entity.date = date; + storage.sync_schema(); - storage.sync_schema(); + storage.begin_transaction(); + storage.insert(entity); + storage.commit(); + } - storage.begin_transaction(); - storage.insert(entity); - storage.commit(); - } + std::vector getEditedMessages( + long userId, + long dialogId, + long messageId + ) + { + return storage.get_all( + where( + c(&EditedMessage::userId) == userId and + c(&EditedMessage::dialogId) == dialogId and + c(&EditedMessage::messageId) == messageId) + ); + } - std::vector getEditedMessages( - long userId, - long dialogId, - long messageId - ) { + std::vector getEditedMessages(HistoryItem* item) + { + auto userId = item->displayFrom()->id.value; + auto dialogId = item->history()->peer->id.value; + auto msgId = item->id.bare; + // auto some = &item->history()->session().account(); - return storage.get_all( - where( - c(&EditedMessage::userId) == userId and - c(&EditedMessage::dialogId) == dialogId and - c(&EditedMessage::messageId) == messageId) - ); - } + return getEditedMessages(static_cast(userId), static_cast(dialogId), static_cast(msgId)); + } - std::vector getEditedMessages(HistoryItem *item) { - auto userId = item->displayFrom()->id.value; - auto dialogId = item->history()->peer->id.value; - auto msgId = item->id.bare; -// auto some = &item->history()->session().account(); - - return getEditedMessages((long) userId, (long) dialogId, (long) msgId); - } - - bool editedMessagesTableExists() { - return storage.table_exists("editedmessage"); - } + bool editedMessagesTableExists() + { + return storage.table_exists("editedmessage"); + } } diff --git a/Telegram/SourceFiles/ayu/database/ayu_database.h b/Telegram/SourceFiles/ayu/database/ayu_database.h index e050b9ca5..6bc48667e 100644 --- a/Telegram/SourceFiles/ayu/database/ayu_database.h +++ b/Telegram/SourceFiles/ayu/database/ayu_database.h @@ -8,26 +8,27 @@ #pragma once #include "entities.h" -#include "history/history_item.h" #include "history/history.h" +#include "history/history_item.h" -namespace AyuDatabase { - void addEditedMessage( - long userId, - long dialogId, - long messageId, - const QString &text, - bool isDocument, - QString path, - long date); +namespace AyuDatabase +{ + void addEditedMessage( + long userId, + long dialogId, + long messageId, + const QString& text, + bool isDocument, + QString path, + long date); - std::vector getEditedMessages( - long userId, - long dialogId, - long messageId - ); + std::vector getEditedMessages( + long userId, + long dialogId, + long messageId + ); - std::vector getEditedMessages(HistoryItem *item); + std::vector getEditedMessages(HistoryItem* item); - bool editedMessagesTableExists(); + bool editedMessagesTableExists(); } diff --git a/Telegram/SourceFiles/ayu/database/entities.h b/Telegram/SourceFiles/ayu/database/entities.h index d425cd32e..4631555b4 100644 --- a/Telegram/SourceFiles/ayu/database/entities.h +++ b/Telegram/SourceFiles/ayu/database/entities.h @@ -11,14 +11,15 @@ #include // https://github.com/AyuGram/AyuGram4A/blob/main/TMessagesProj/src/main/java/com/radolyn/ayugram/database/entities/EditedMessage.java -class EditedMessage { +class EditedMessage +{ public: - long userId; - long dialogId; - long messageId; + long userId; + long dialogId; + long messageId; - std::string text; - bool isDocument; - std::string path; - long date; + std::string text; + bool isDocument; + std::string path; + long date; }; diff --git a/Telegram/SourceFiles/ayu/libs/json_ext.hpp b/Telegram/SourceFiles/ayu/libs/json_ext.hpp index 6313a3321..6b343fc9a 100644 --- a/Telegram/SourceFiles/ayu/libs/json_ext.hpp +++ b/Telegram/SourceFiles/ayu/libs/json_ext.hpp @@ -10,10 +10,12 @@ #include #include "json.hpp" -inline void to_json(nlohmann::json &j, const QString &q) { - j = nlohmann::json(q.toStdString()); +inline void to_json(nlohmann::json& j, const QString& q) +{ + j = nlohmann::json(q.toStdString()); } -inline void from_json(const nlohmann::json &j, QString &q) { - q = QString::fromStdString(j.get()); -} \ No newline at end of file +inline void from_json(const nlohmann::json& j, QString& q) +{ + q = QString::fromStdString(j.get()); +} diff --git a/Telegram/SourceFiles/ayu/sync/ayu_sync_controller.cpp b/Telegram/SourceFiles/ayu/sync/ayu_sync_controller.cpp index be0acbf3e..a3ab024ef 100644 --- a/Telegram/SourceFiles/ayu/sync/ayu_sync_controller.cpp +++ b/Telegram/SourceFiles/ayu/sync/ayu_sync_controller.cpp @@ -7,110 +7,132 @@ #include "ayu_sync_controller.h" #include "ayu/libs/process.hpp" -#include "ayu/sync/utils/process_utils.hpp" #include "ayu/sync/models.h" +#include "ayu/sync/utils/process_utils.hpp" +#include "ayu/sync/utils/telegram_helpers.h" #include "data/data_session.h" #include "history/history.h" -#include "ayu/sync/utils/telegram_helpers.h" #include #include -namespace AyuSync { - std::optional controller = std::nullopt; +namespace AyuSync +{ + std::optional controller = std::nullopt; - bool isAgentDownloaded() { - return std::filesystem::exists(AgentPath); - } + bool isAgentDownloaded() + { + return std::filesystem::exists(AgentPath); + } - bool isAgentRunning() { - return is_process_running(AgentFilename); - } + bool isAgentRunning() + { + return is_process_running(AgentFilename); + } - void initialize() { - if (controller.has_value()) { - return; - } + void initialize() + { + if (controller.has_value()) + { + return; + } - controller = ayu_sync_controller(); - } + controller = ayu_sync_controller(); + } - ayu_sync_controller &getControllerInstance() { - initialize(); - return controller.value(); - } + ayu_sync_controller& getControllerInstance() + { + initialize(); + return controller.value(); + } - void ayu_sync_controller::initializeAgent() { - if (!isAgentDownloaded()) { - return; - } + void ayu_sync_controller::initializeAgent() + { + if (!isAgentDownloaded()) + { + return; + } - if (!isAgentRunning()) { - auto configPath = std::filesystem::absolute("./tdata/sync_preferences.json"); - auto process = nes::process{AgentPath, {configPath.string(), ""}, nes::process_options::none}; - process.detach(); - } + if (!isAgentRunning()) + { + auto configPath = std::filesystem::absolute("./tdata/sync_preferences.json"); + auto process = nes::process{AgentPath, {configPath.string(), ""}, nes::process_options::none}; + process.detach(); + } - std::thread receiverThread(&ayu_sync_controller::receiver, this); - receiverThread.detach(); - } + std::thread receiverThread(&ayu_sync_controller::receiver, this); + receiverThread.detach(); + } - void ayu_sync_controller::receiver() { - pipe = std::make_unique(); + void ayu_sync_controller::receiver() + { + pipe = std::make_unique(); - while (true) { - auto p = pipe->receive(); - if (p == std::nullopt) { - continue; - } + while (true) + { + auto p = pipe->receive(); + if (p == std::nullopt) + { + continue; + } - std::string s = p->dump(); - LOG(("[AyuSync] Received message: %1").arg(QString::fromStdString(s))); + std::string s = p->dump(); + LOG(("[AyuSync] Received message: %1").arg(QString::fromStdString(s))); - invokeHandler(p.value()); - } - } + invokeHandler(p.value()); + } + } - void ayu_sync_controller::invokeHandler(json p) { - LOG(("Invoking handler on %1").arg(p.dump().c_str())); + void ayu_sync_controller::invokeHandler(json p) + { + LOG(("Invoking handler on %1").arg(p.dump().c_str())); - auto userId = p["userId"].get(); - auto type = p["type"].get(); + auto userId = p["userId"].get(); + auto type = p["type"].get(); - LOG(("userId: %1, type: %2").arg(userId).arg(type.c_str())); + LOG(("userId: %1, type: %2").arg(userId).arg(type.c_str())); - // todo: check if account exists + // todo: check if account exists - if (type == "sync_force") { - auto ev = p.template get(); - onSyncForce(ev); - } else if (type == "sync_batch") { - onSyncBatch(p); - } else if (type == "sync_read") { - auto ev = p.template get(); - onSyncRead(ev); - } else { - LOG(("Unknown sync type: %1").arg(type.c_str())); - } - } + if (type == "sync_force") + { + auto ev = p.template get(); + onSyncForce(ev); + } + else if (type == "sync_batch") + { + onSyncBatch(p); + } + else if (type == "sync_read") + { + auto ev = p.template get(); + onSyncRead(ev); + } + else + { + LOG(("Unknown sync type: %1").arg(type.c_str())); + } + } - void ayu_sync_controller::onSyncForce(SyncForce ev) { + void ayu_sync_controller::onSyncForce(SyncForce ev) + { + } - } + void ayu_sync_controller::onSyncBatch(json ev) + { + } - void ayu_sync_controller::onSyncBatch(json ev) { + void ayu_sync_controller::onSyncRead(SyncRead ev) + { + auto session = getSession(ev.userId); - } + auto peer = PeerId(abs(ev.args.dialogId)); - void ayu_sync_controller::onSyncRead(SyncRead ev) { - auto session = getSession(ev.userId); - - auto peer = PeerId(abs(ev.args.dialogId)); - - auto history = session->data().history(peer); - if (history) { - history->inboxRead(ev.args.untilId, ev.args.unread); - } - } -} \ No newline at end of file + auto history = session->data().history(peer); + if (history) + { + history->inboxRead(ev.args.untilId, ev.args.unread); + } + } +} diff --git a/Telegram/SourceFiles/ayu/sync/ayu_sync_controller.h b/Telegram/SourceFiles/ayu/sync/ayu_sync_controller.h index 04dd6c32f..7e010d40d 100644 --- a/Telegram/SourceFiles/ayu/sync/ayu_sync_controller.h +++ b/Telegram/SourceFiles/ayu/sync/ayu_sync_controller.h @@ -7,39 +7,42 @@ #pragma once -#include "ayu/libs/json.hpp" #include "models.h" +#include "ayu/libs/json.hpp" #include "utils/ayu_pipe_wrapper.h" using json = nlohmann::json; const std::string AgentFilename = #ifdef _WIN32 - "AyuSync.Agent.exe"; + "AyuSync.Agent.exe"; #else - "AyuSync.Agent"; + "AyuSync.Agent"; #endif const std::string AgentPath = "./AyuSync/" + AgentFilename; -namespace AyuSync { - class ayu_sync_controller { - public: - void initializeAgent(); +namespace AyuSync +{ + class ayu_sync_controller + { + public: + void initializeAgent(); - void onSyncForce(SyncForce ev); - void onSyncBatch(json ev); - void onSyncRead(SyncRead ev); + void onSyncForce(SyncForce ev); + void onSyncBatch(json ev); + void onSyncRead(SyncRead ev); - void invokeHandler(json p); - private: - void receiver(); + void invokeHandler(json p); - std::unique_ptr pipe; - }; + private: + void receiver(); - ayu_sync_controller &getControllerInstance(); + std::unique_ptr pipe; + }; - bool isAgentDownloaded(); - bool isAgentRunning(); + ayu_sync_controller& getControllerInstance(); + + bool isAgentDownloaded(); + bool isAgentRunning(); } diff --git a/Telegram/SourceFiles/ayu/sync/models.h b/Telegram/SourceFiles/ayu/sync/models.h index 8bac6b26f..8575b7bb6 100644 --- a/Telegram/SourceFiles/ayu/sync/models.h +++ b/Telegram/SourceFiles/ayu/sync/models.h @@ -1,66 +1,77 @@ #pragma once +#include "ayu/libs/json.hpp" + #include #include -class SyncEvent { +class SyncEvent +{ public: - std::string type = "sync_unspecified"; - long userId = 0; + std::string type = "sync_unspecified"; + long userId = 0; }; -class SyncBatch : public SyncEvent { +class SyncBatch : public SyncEvent +{ public: - std::string type = "sync_batch"; - long userId; + std::string type = "sync_batch"; + long userId; - class SyncBatchArgs { - public: - std::vector events; - }; + class SyncBatchArgs + { + public: + std::vector events; + }; - SyncBatchArgs args; + SyncBatchArgs args; }; -class SyncRead : public SyncEvent { +class SyncRead : public SyncEvent +{ public: - std::string type = "sync_read"; - long userId; + std::string type = "sync_read"; + long userId; - class SyncReadArgs { - public: - long dialogId; - int untilId; - int unread; - }; + class SyncReadArgs + { + public: + long dialogId; + int untilId; + int unread; + }; - SyncReadArgs args; + SyncReadArgs args; }; -class SyncForce : public SyncEvent { +class SyncForce : public SyncEvent +{ public: - std::string type = "sync_force"; - long userId; + std::string type = "sync_force"; + long userId; - class SyncForceArgs { - public: - int fromDate; - }; + class SyncForceArgs + { + public: + int fromDate; + }; - SyncForceArgs args; + SyncForceArgs args; }; -class SyncForceFinish : public SyncEvent { +class SyncForceFinish : public SyncEvent +{ public: - std::string type = "sync_force_finish"; - long userId; + std::string type = "sync_force_finish"; + long userId; - class SyncForceFinishArgs { - public: - short dummy; // required to be JSON serializable - }; + class SyncForceFinishArgs + { + public: + short dummy; // required to be JSON serializable + }; - SyncForceFinishArgs args; + SyncForceFinishArgs args; }; @@ -73,4 +84,3 @@ NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(SyncForce::SyncForceArgs, fromDate) NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(SyncForce, type, userId, args) NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(SyncForceFinish::SyncForceFinishArgs, dummy) NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(SyncForceFinish, type, userId, args) - diff --git a/Telegram/SourceFiles/ayu/sync/utils/ayu_pipe_wrapper.cpp b/Telegram/SourceFiles/ayu/sync/utils/ayu_pipe_wrapper.cpp index d092cf006..dcba70843 100644 --- a/Telegram/SourceFiles/ayu/sync/utils/ayu_pipe_wrapper.cpp +++ b/Telegram/SourceFiles/ayu/sync/utils/ayu_pipe_wrapper.cpp @@ -5,47 +5,52 @@ // // Copyright @Radolyn, 2023 -#include #include "ayu_pipe_wrapper.h" +#include #include "ayu/libs/bit_converter.hpp" -template -void ayu_pipe_wrapper::send(T obj) { -// auto s = json(obj).dump(); -// auto length = s.length(); -// char lengthBuff[4]; -// bit_converter::i32_to_bytes(length, false, lengthBuff); -// -// os.write(lengthBuff, 4); -// os.write(s.c_str(), length); -// os.flush(); - throw std::logic_error("not implemented"); +template +void ayu_pipe_wrapper::send(T obj) +{ + // auto s = json(obj).dump(); + // auto length = s.length(); + // char lengthBuff[4]; + // bit_converter::i32_to_bytes(length, false, lengthBuff); + // + // os.write(lengthBuff, 4); + // os.write(s.c_str(), length); + // os.flush(); + throw std::logic_error("not implemented"); } -std::optional ayu_pipe_wrapper::receive() { - if (!is.is_open()) { - return std::nullopt; - } +std::optional ayu_pipe_wrapper::receive() +{ + if (!is.is_open()) + { + return std::nullopt; + } - char lengthBuff[4]; - is.read(lengthBuff, 4); + char lengthBuff[4]; + is.read(lengthBuff, 4); - auto length = bit_converter::bytes_to_i32(lengthBuff, false); + auto length = bit_converter::bytes_to_i32(lengthBuff, false); - if (length <= 0) { - return std::nullopt; - } + if (length <= 0) + { + return std::nullopt; + } - auto sb = std::stringbuf(); - char buff[4096]; + auto sb = std::stringbuf(); + char buff[4096]; - while (length > 0) { - auto readSize = std::min(length, (int) sizeof(buff)); - is.read(buff, readSize); - sb.sputn(buff, readSize); - length -= readSize; - } + while (length > 0) + { + auto readSize = std::min(length, static_cast(sizeof(buff))); + is.read(buff, readSize); + sb.sputn(buff, readSize); + length -= readSize; + } - auto p = json::parse(sb.str()); - return p; -} \ No newline at end of file + auto p = json::parse(sb.str()); + return p; +} diff --git a/Telegram/SourceFiles/ayu/sync/utils/ayu_pipe_wrapper.h b/Telegram/SourceFiles/ayu/sync/utils/ayu_pipe_wrapper.h index e1602fea2..524a5e05e 100644 --- a/Telegram/SourceFiles/ayu/sync/utils/ayu_pipe_wrapper.h +++ b/Telegram/SourceFiles/ayu/sync/utils/ayu_pipe_wrapper.h @@ -13,13 +13,14 @@ using json = nlohmann::json; -class ayu_pipe_wrapper { +class ayu_pipe_wrapper +{ public: - template - void send(T obj); + template + void send(T obj); - std::optional receive(); + std::optional receive(); private: - nes::pipe_istream is{"AyuSync"}; + nes::pipe_istream is{"AyuSync"}; }; diff --git a/Telegram/SourceFiles/ayu/sync/utils/process_utils.hpp b/Telegram/SourceFiles/ayu/sync/utils/process_utils.hpp index 958c0c485..73859d302 100644 --- a/Telegram/SourceFiles/ayu/sync/utils/process_utils.hpp +++ b/Telegram/SourceFiles/ayu/sync/utils/process_utils.hpp @@ -1,14 +1,14 @@ +#include +#include #include +#include #include #include -#include -#include -#include #ifdef _WIN32 -#include #include +#include #else #include @@ -17,34 +17,40 @@ // A function to check if a process is running by its name // Bing AI generated -bool is_process_running(const std::string &name) { +bool is_process_running(const std::string& name) +{ #ifdef _WIN32 - // Create a snapshot of all processes - HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); - if (snapshot == INVALID_HANDLE_VALUE) { - std::cerr << "Failed to create snapshot\n"; - return false; - } - // Iterate over the processes and compare the names - PROCESSENTRY32 entry; - entry.dwSize = sizeof(entry); - if (!Process32First(snapshot, &entry)) { - std::cerr << "Failed to get first process\n"; - CloseHandle(snapshot); - return false; - } - do { - std::wstring_convert> converter; - std::string entry_name = converter.to_bytes(entry.szExeFile); - if (name == entry_name) { - // Found a match - CloseHandle(snapshot); - return true; - } - } while (Process32Next(snapshot, &entry)); - // No match found - CloseHandle(snapshot); - return false; + // Create a snapshot of all processes + HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); + if (snapshot == INVALID_HANDLE_VALUE) + { + std::cerr << "Failed to create snapshot\n"; + return false; + } + // Iterate over the processes and compare the names + PROCESSENTRY32 entry; + entry.dwSize = sizeof(entry); + if (!Process32First(snapshot, &entry)) + { + std::cerr << "Failed to get first process\n"; + CloseHandle(snapshot); + return false; + } + do + { + std::wstring_convert> converter; + std::string entry_name = converter.to_bytes(entry.szExeFile); + if (name == entry_name) + { + // Found a match + CloseHandle(snapshot); + return true; + } + } + while (Process32Next(snapshot, &entry)); + // No match found + CloseHandle(snapshot); + return false; #else // Open the /proc directory DIR* dir = opendir("/proc"); @@ -83,4 +89,4 @@ bool is_process_running(const std::string &name) { closedir(dir); return false; #endif -} \ No newline at end of file +} diff --git a/Telegram/SourceFiles/ayu/sync/utils/telegram_helpers.cpp b/Telegram/SourceFiles/ayu/sync/utils/telegram_helpers.cpp index abf52a477..7027aa388 100644 --- a/Telegram/SourceFiles/ayu/sync/utils/telegram_helpers.cpp +++ b/Telegram/SourceFiles/ayu/sync/utils/telegram_helpers.cpp @@ -8,19 +8,24 @@ #include "telegram_helpers.h" #include "data/data_peer_id.h" -Main::Session* getSession(long userId) { - for (auto &[index, account] : Core::App().domain().accounts()) { - if (const auto session = account->maybeSession()) { - if (session->userId().bare == userId) { - return session; - } - } - } +Main::Session* getSession(long userId) +{ + for (auto& [index, account] : Core::App().domain().accounts()) + { + if (const auto session = account->maybeSession()) + { + if (session->userId().bare == userId) + { + return session; + } + } + } - return nullptr; + return nullptr; } -PeerId dialogIdToPeerId(long dialogId) { - auto peerId = PeerId(); - return peerId; -} \ No newline at end of file +PeerId dialogIdToPeerId(long dialogId) +{ + auto peerId = PeerId(); + return peerId; +} diff --git a/Telegram/SourceFiles/ayu/sync/utils/telegram_helpers.h b/Telegram/SourceFiles/ayu/sync/utils/telegram_helpers.h index 4d13ae085..68417a6f5 100644 --- a/Telegram/SourceFiles/ayu/sync/utils/telegram_helpers.h +++ b/Telegram/SourceFiles/ayu/sync/utils/telegram_helpers.h @@ -9,7 +9,7 @@ #include "core/application.h" #include "main/main_account.h" -#include "main/main_session.h" #include "main/main_domain.h" +#include "main/main_session.h" Main::Session* getSession(long userId); diff --git a/Telegram/SourceFiles/ayu/ui/boxes/confirmation_box.cpp b/Telegram/SourceFiles/ayu/ui/boxes/confirmation_box.cpp index e47103241..e8eebccf5 100644 --- a/Telegram/SourceFiles/ayu/ui/boxes/confirmation_box.cpp +++ b/Telegram/SourceFiles/ayu/ui/boxes/confirmation_box.cpp @@ -6,57 +6,63 @@ // Copyright @Radolyn, 2023 #include "confirmation_box.h" -#include "ayu/ayu_settings.h" -#include "window/window_session_controller.h" -#include "main/main_session.h" -#include "data/data_session.h" -#include "window/window_peer_menu.h" -#include "styles/style_layers.h" #include "lang_auto.h" +#include "ayu/ayu_settings.h" +#include "data/data_session.h" +#include "main/main_session.h" +#include "styles/style_layers.h" #include "ui/text/text_utilities.h" +#include "window/window_peer_menu.h" +#include "window/window_session_controller.h" -namespace AyuUi { - ConfirmationBox::ConfirmationBox( - QWidget *, - not_null controller) : _controller(controller) { - // - } +namespace AyuUi +{ + ConfirmationBox::ConfirmationBox( + QWidget*, + not_null controller) : _controller(controller) + { + // + } - void ConfirmationBox::prepare() { -// setTitle(rpl::single(QString("Confirmation for SRead"))); - auto details = TextWithEntities(); - details.text = QString("Do you want to read all messages?"); + void ConfirmationBox::prepare() + { + // setTitle(rpl::single(QString("Confirmation for SRead"))); + auto details = TextWithEntities(); + details.text = QString("Do you want to read all messages?"); - _text.create(this, rpl::single(std::move(details)), st::boxLabel); + _text.create(this, rpl::single(std::move(details)), st::boxLabel); - auto fullHeight = st::boxPadding.top() - + _text->height() - + st::boxPadding.bottom(); + auto fullHeight = st::boxPadding.top() + + _text->height() + + st::boxPadding.bottom(); - setDimensions(st::boxWidth, fullHeight); + setDimensions(st::boxWidth, fullHeight); - addButton(rpl::single(QString("Read")), [=, this] { - ReadAllPeers(); - closeBox(); - }); - addButton(tr::lng_cancel(), [=, this] { closeBox(); }); - } + addButton(rpl::single(QString("Read")), [=, this] + { + ReadAllPeers(); + closeBox(); + }); + addButton(tr::lng_cancel(), [=, this] { closeBox(); }); + } - void ConfirmationBox::resizeEvent(QResizeEvent *e) { - BoxContent::resizeEvent(e); + void ConfirmationBox::resizeEvent(QResizeEvent* e) + { + BoxContent::resizeEvent(e); - const auto &padding = st::boxPadding; - _text->moveToLeft(padding.left(), padding.top()); - } + const auto& padding = st::boxPadding; + _text->moveToLeft(padding.left(), padding.top()); + } - void ConfirmationBox::ReadAllPeers() { - auto settings = &AyuSettings::getInstance(); - auto prev = settings->sendReadPackets; - settings->set_sendReadPackets(true); + void ConfirmationBox::ReadAllPeers() + { + auto settings = &AyuSettings::getInstance(); + auto prev = settings->sendReadPackets; + settings->set_sendReadPackets(true); - auto chats = _controller->session().data().chatsList(); - Window::MarkAsReadChatListHack(chats); + auto chats = _controller->session().data().chatsList(); + Window::MarkAsReadChatListHack(chats); - settings->set_sendReadPackets(prev); - } -} \ No newline at end of file + settings->set_sendReadPackets(prev); + } +} diff --git a/Telegram/SourceFiles/ayu/ui/boxes/confirmation_box.h b/Telegram/SourceFiles/ayu/ui/boxes/confirmation_box.h index a9d53f1f6..da98a0ddf 100644 --- a/Telegram/SourceFiles/ayu/ui/boxes/confirmation_box.h +++ b/Telegram/SourceFiles/ayu/ui/boxes/confirmation_box.h @@ -8,20 +8,22 @@ #include "ui/layers/box_content.h" #include "window/window_main_menu.h" -namespace AyuUi { - class ConfirmationBox : public Ui::BoxContent { - public: - ConfirmationBox(QWidget *, not_null controller); +namespace AyuUi +{ + class ConfirmationBox : public Ui::BoxContent + { + public: + ConfirmationBox(QWidget*, not_null controller); - protected: - void prepare() override; + protected: + void prepare() override; - void resizeEvent(QResizeEvent *e) override; + void resizeEvent(QResizeEvent* e) override; - private: - void ReadAllPeers(); + private: + void ReadAllPeers(); - not_null _controller; - object_ptr _text = {nullptr}; - }; -} \ No newline at end of file + not_null _controller; + object_ptr _text = {nullptr}; + }; +} diff --git a/Telegram/SourceFiles/ayu/ui/boxes/edit_deleted_mark.cpp b/Telegram/SourceFiles/ayu/ui/boxes/edit_deleted_mark.cpp index 395145c2c..c69f50665 100644 --- a/Telegram/SourceFiles/ayu/ui/boxes/edit_deleted_mark.cpp +++ b/Telegram/SourceFiles/ayu/ui/boxes/edit_deleted_mark.cpp @@ -7,83 +7,92 @@ #include "edit_deleted_mark.h" -#include "lang/lang_keys.h" #include "base/random.h" #include "boxes/peer_list_controllers.h" #include "boxes/premium_limits_box.h" +#include "data/data_cloud_file.h" +#include "lang/lang_keys.h" +#include "main/main_session.h" +#include "styles/style_boxes.h" +#include "styles/style_layers.h" +#include "styles/style_widgets.h" +#include "ui/ui_utility.h" +#include "ui/unread_badge.h" #include "ui/controls/userpic_button.h" #include "ui/widgets/buttons.h" -#include "ui/widgets/fields/special_fields.h" #include "ui/widgets/popup_menu.h" -#include "ui/unread_badge.h" -#include "ui/ui_utility.h" -#include "data/data_cloud_file.h" -#include "main/main_session.h" -#include "styles/style_layers.h" -#include "styles/style_boxes.h" -#include "styles/style_widgets.h" +#include "ui/widgets/fields/special_fields.h" #include #include "storage/localstorage.h" #include "ayu/ayu_settings.h" -EditDeletedMarkBox::EditDeletedMarkBox(QWidget *) : - _text( - this, - st::defaultInputField, - rpl::single(QString("Deleted Mark")), - AyuSettings::getInstance().deletedMark) { +EditDeletedMarkBox::EditDeletedMarkBox(QWidget*) : + _text( + this, + st::defaultInputField, + rpl::single(QString("Deleted Mark")), + AyuSettings::getInstance().deletedMark) +{ } -void EditDeletedMarkBox::prepare() { - const auto defaultDeletedMark = "🧹"; - auto newHeight = st::contactPadding.top() + _text->height(); +void EditDeletedMarkBox::prepare() +{ + const auto defaultDeletedMark = "🧹"; + auto newHeight = st::contactPadding.top() + _text->height(); - setTitle(rpl::single(QString("Edit Deleted Mark"))); + setTitle(rpl::single(QString("Edit Deleted Mark"))); - newHeight += st::boxPadding.bottom() + st::contactPadding.bottom(); - setDimensions(st::boxWidth, newHeight); + newHeight += st::boxPadding.bottom() + st::contactPadding.bottom(); + setDimensions(st::boxWidth, newHeight); - addLeftButton(rpl::single(QString("Reset")), [=] { _text->setText(defaultDeletedMark); }); + addLeftButton(rpl::single(QString("Reset")), [=] { _text->setText(defaultDeletedMark); }); - addButton(tr::lng_settings_save(), [=] { save(); }); - addButton(tr::lng_cancel(), [=] { closeBox(); }); + addButton(tr::lng_settings_save(), [=] { save(); }); + addButton(tr::lng_cancel(), [=] { closeBox(); }); - connect(_text, &Ui::InputField::submitted, [=] { submit(); }); + connect(_text, &Ui::InputField::submitted, [=] { submit(); }); } -void EditDeletedMarkBox::setInnerFocus() { - _text->setFocusFast(); +void EditDeletedMarkBox::setInnerFocus() +{ + _text->setFocusFast(); } -void EditDeletedMarkBox::submit() { - if (_text->getLastText().trimmed().isEmpty()) { - _text->setFocus(); - _text->showError(); - } else { - save(); - } +void EditDeletedMarkBox::submit() +{ + if (_text->getLastText().trimmed().isEmpty()) + { + _text->setFocus(); + _text->showError(); + } + else + { + save(); + } } -void EditDeletedMarkBox::resizeEvent(QResizeEvent *e) { - BoxContent::resizeEvent(e); +void EditDeletedMarkBox::resizeEvent(QResizeEvent* e) +{ + BoxContent::resizeEvent(e); - _text->resize( - width() - - st::boxPadding.left() - - st::newGroupInfoPadding.left() - - st::boxPadding.right(), - _text->height()); + _text->resize( + width() + - st::boxPadding.left() + - st::newGroupInfoPadding.left() + - st::boxPadding.right(), + _text->height()); - const auto left = st::boxPadding.left() + st::newGroupInfoPadding.left(); - _text->moveToLeft(left, st::contactPadding.top()); + const auto left = st::boxPadding.left() + st::newGroupInfoPadding.left(); + _text->moveToLeft(left, st::contactPadding.top()); } -void EditDeletedMarkBox::save() { - const auto settings = &AyuSettings::getInstance(); - settings->set_deletedMark(_text->getLastText()); - AyuSettings::save(); +void EditDeletedMarkBox::save() +{ + const auto settings = &AyuSettings::getInstance(); + settings->set_deletedMark(_text->getLastText()); + AyuSettings::save(); - closeBox(); + closeBox(); } diff --git a/Telegram/SourceFiles/ayu/ui/boxes/edit_deleted_mark.h b/Telegram/SourceFiles/ayu/ui/boxes/edit_deleted_mark.h index e4d049084..839faf7dc 100644 --- a/Telegram/SourceFiles/ayu/ui/boxes/edit_deleted_mark.h +++ b/Telegram/SourceFiles/ayu/ui/boxes/edit_deleted_mark.h @@ -7,25 +7,26 @@ #pragma once -#include "boxes/abstract_box.h" #include "base/timer.h" +#include "boxes/abstract_box.h" #include "mtproto/sender.h" -class EditDeletedMarkBox : public Ui::BoxContent { +class EditDeletedMarkBox : public Ui::BoxContent +{ public: - EditDeletedMarkBox(QWidget *); + EditDeletedMarkBox(QWidget*); protected: - void setInnerFocus() override; + void setInnerFocus() override; - void prepare() override; + void prepare() override; - void resizeEvent(QResizeEvent *e) override; + void resizeEvent(QResizeEvent* e) override; private: - void submit(); + void submit(); - void save(); + void save(); - object_ptr _text; + object_ptr _text; }; diff --git a/Telegram/SourceFiles/ayu/ui/boxes/edit_edited_mark.cpp b/Telegram/SourceFiles/ayu/ui/boxes/edit_edited_mark.cpp index 6aefb0d7e..7a509501c 100644 --- a/Telegram/SourceFiles/ayu/ui/boxes/edit_edited_mark.cpp +++ b/Telegram/SourceFiles/ayu/ui/boxes/edit_edited_mark.cpp @@ -7,85 +7,93 @@ #include "edit_edited_mark.h" -#include "lang/lang_keys.h" #include "base/random.h" #include "boxes/peer_list_controllers.h" #include "boxes/premium_limits_box.h" +#include "data/data_cloud_file.h" +#include "lang/lang_keys.h" +#include "main/main_session.h" +#include "styles/style_boxes.h" +#include "styles/style_layers.h" +#include "styles/style_widgets.h" +#include "ui/ui_utility.h" +#include "ui/unread_badge.h" #include "ui/controls/userpic_button.h" #include "ui/widgets/buttons.h" -#include "ui/widgets/fields/special_fields.h" #include "ui/widgets/popup_menu.h" -#include "ui/unread_badge.h" -#include "ui/ui_utility.h" -#include "data/data_cloud_file.h" -#include "main/main_session.h" -#include "styles/style_layers.h" -#include "styles/style_boxes.h" -#include "styles/style_widgets.h" +#include "ui/widgets/fields/special_fields.h" #include #include "storage/localstorage.h" #include "ayu/ayu_settings.h" -EditEditedMarkBox::EditEditedMarkBox(QWidget *) : - _text( - this, - st::defaultInputField, - rpl::single(QString("Edited mark")), - AyuSettings::getInstance().editedMark) { - +EditEditedMarkBox::EditEditedMarkBox(QWidget*) : + _text( + this, + st::defaultInputField, + rpl::single(QString("Edited mark")), + AyuSettings::getInstance().editedMark) +{ } -void EditEditedMarkBox::prepare() { - const auto defaultEditedMark = tr::lng_edited(tr::now); - auto newHeight = st::contactPadding.top() + _text->height(); +void EditEditedMarkBox::prepare() +{ + const auto defaultEditedMark = tr::lng_edited(tr::now); + auto newHeight = st::contactPadding.top() + _text->height(); - setTitle(rpl::single(QString("Edit edited Mark"))); + setTitle(rpl::single(QString("Edit edited Mark"))); - newHeight += st::boxPadding.bottom() + st::contactPadding.bottom(); - setDimensions(st::boxWidth, newHeight); + newHeight += st::boxPadding.bottom() + st::contactPadding.bottom(); + setDimensions(st::boxWidth, newHeight); - addLeftButton(rpl::single(QString("Reset")), [=] { _text->setText(defaultEditedMark); }); - addButton(tr::lng_settings_save(), [=] { save(); }); - addButton(tr::lng_cancel(), [=] { closeBox(); }); + addLeftButton(rpl::single(QString("Reset")), [=] { _text->setText(defaultEditedMark); }); + addButton(tr::lng_settings_save(), [=] { save(); }); + addButton(tr::lng_cancel(), [=] { closeBox(); }); - connect(_text, &Ui::InputField::submitted, [=] { submit(); }); + connect(_text, &Ui::InputField::submitted, [=] { submit(); }); } -void EditEditedMarkBox::setInnerFocus() { - _text->setFocusFast(); +void EditEditedMarkBox::setInnerFocus() +{ + _text->setFocusFast(); } -void EditEditedMarkBox::submit() { - if (_text->getLastText().trimmed().isEmpty()) { - _text->setFocus(); - _text->showError(); - } else { - save(); - } +void EditEditedMarkBox::submit() +{ + if (_text->getLastText().trimmed().isEmpty()) + { + _text->setFocus(); + _text->showError(); + } + else + { + save(); + } } -void EditEditedMarkBox::resizeEvent(QResizeEvent *e) { - BoxContent::resizeEvent(e); +void EditEditedMarkBox::resizeEvent(QResizeEvent* e) +{ + BoxContent::resizeEvent(e); - _text->resize( - width() - - st::boxPadding.left() - - st::newGroupInfoPadding.left() - - st::boxPadding.right(), - _text->height()); + _text->resize( + width() + - st::boxPadding.left() + - st::newGroupInfoPadding.left() + - st::boxPadding.right(), + _text->height()); - const auto left = st::boxPadding.left() + st::newGroupInfoPadding.left(); - _text->moveToLeft(left, st::contactPadding.top()); + const auto left = st::boxPadding.left() + st::newGroupInfoPadding.left(); + _text->moveToLeft(left, st::contactPadding.top()); } -void EditEditedMarkBox::save() { - const auto settings = &AyuSettings::getInstance(); - settings->set_editedMark(_text->getLastText()); - AyuSettings::save(); +void EditEditedMarkBox::save() +{ + const auto settings = &AyuSettings::getInstance(); + settings->set_editedMark(_text->getLastText()); + AyuSettings::save(); - closeBox(); -} \ No newline at end of file + closeBox(); +} diff --git a/Telegram/SourceFiles/ayu/ui/boxes/edit_edited_mark.h b/Telegram/SourceFiles/ayu/ui/boxes/edit_edited_mark.h index 1e4ed27c2..c34fb20b4 100644 --- a/Telegram/SourceFiles/ayu/ui/boxes/edit_edited_mark.h +++ b/Telegram/SourceFiles/ayu/ui/boxes/edit_edited_mark.h @@ -7,25 +7,26 @@ #pragma once -#include "boxes/abstract_box.h" #include "base/timer.h" +#include "boxes/abstract_box.h" #include "mtproto/sender.h" -class EditEditedMarkBox : public Ui::BoxContent { +class EditEditedMarkBox : public Ui::BoxContent +{ public: - EditEditedMarkBox(QWidget *); + EditEditedMarkBox(QWidget*); protected: - void setInnerFocus() override; + void setInnerFocus() override; - void prepare() override; + void prepare() override; - void resizeEvent(QResizeEvent *e) override; + void resizeEvent(QResizeEvent* e) override; private: - void submit(); + void submit(); - void save(); + void save(); - object_ptr _text; -}; \ No newline at end of file + object_ptr _text; +}; diff --git a/Telegram/SourceFiles/ayu/ui/boxes/voice_confirmation_box.cpp b/Telegram/SourceFiles/ayu/ui/boxes/voice_confirmation_box.cpp index c0e20c475..2711055a7 100644 --- a/Telegram/SourceFiles/ayu/ui/boxes/voice_confirmation_box.cpp +++ b/Telegram/SourceFiles/ayu/ui/boxes/voice_confirmation_box.cpp @@ -6,97 +6,119 @@ // Copyright @Radolyn, 2023 #include "ui/boxes/confirm_box.h" -#include "lang/lang_keys.h" -#include "ui/widgets/buttons.h" -#include "styles/style_layers.h" #include "voice_confirmation_box.h" +#include "lang/lang_keys.h" +#include "styles/style_layers.h" +#include "ui/widgets/buttons.h" -namespace AyuUi { +namespace AyuUi +{ + void VoiceConfirmBox(not_null box, Ui::ConfirmBoxArgs&& args) + { + const auto weak = MakeWeak(box); + const auto lifetime = box->lifetime().make_state(); - void VoiceConfirmBox(not_null box, Ui::ConfirmBoxArgs &&args) { - const auto weak = Ui::MakeWeak(box); - const auto lifetime = box->lifetime().make_state(); + v::match(args.text, [](v::null_t) + { + }, [&](auto&&) + { + const auto label = box->addRow( + object_ptr( + box.get(), + v::text::take_marked(std::move(args.text)), + args.labelStyle ? *args.labelStyle : st::boxLabel), + st::boxPadding); + if (args.labelFilter) + { + label->setClickHandlerFilter(std::move(args.labelFilter)); + } + }); - v::match(args.text, [](v::null_t) { - }, [&](auto &&) { - const auto label = box->addRow( - object_ptr( - box.get(), - v::text::take_marked(std::move(args.text)), - args.labelStyle ? *args.labelStyle : st::boxLabel), - st::boxPadding); - if (args.labelFilter) { - label->setClickHandlerFilter(std::move(args.labelFilter)); - } - }); + const auto prepareCallback = [&](Ui::ConfirmBoxArgs::Callback& callback) + { + return [=, confirmed = std::move(callback)]() + { + if (const auto callbackPtr = std::get_if<1>(&confirmed)) + { + if (auto callback = (*callbackPtr)) + { + callback(); + } + } + else if (const auto callbackPtr = std::get_if<2>(&confirmed)) + { + if (auto callback = (*callbackPtr)) + { + callback(crl::guard(weak, [=] { weak->closeBox(); })); + } + } + else if (weak) + { + weak->closeBox(); + } + }; + }; - const auto prepareCallback = [&](Ui::ConfirmBoxArgs::Callback &callback) { - return [=, confirmed = std::move(callback)]() { - if (const auto callbackPtr = std::get_if<1>(&confirmed)) { - if (auto callback = (*callbackPtr)) { - callback(); - } - } else if (const auto callbackPtr = std::get_if<2>(&confirmed)) { - if (auto callback = (*callbackPtr)) { - callback(crl::guard(weak, [=] { weak->closeBox(); })); - } - } else if (weak) { - weak->closeBox(); - } - }; - }; + const auto& defaultButtonStyle = box->getDelegate()->style().button; - const auto &defaultButtonStyle = box->getDelegate()->style().button; + const auto confirmButton = box->addButton( + v::text::take_plain(std::move(args.confirmText), tr::lng_box_ok()), + [=, c = prepareCallback(args.confirmed)]() + { + lifetime->destroy(); + c(); - const auto confirmButton = box->addButton( - v::text::take_plain(std::move(args.confirmText), tr::lng_box_ok()), - [=, c = prepareCallback(args.confirmed)]() { - lifetime->destroy(); - c(); + weak->closeBox(); + }, + args.confirmStyle ? *args.confirmStyle : defaultButtonStyle); + box->events( + ) | start_with_next([=](not_null e) + { + if ((e->type() != QEvent::KeyPress) || !confirmButton) + { + return; + } + const auto k = static_cast(e.get()); + if (k->key() == Qt::Key_Enter || k->key() == Qt::Key_Return) + { + confirmButton->clicked(Qt::KeyboardModifiers(), Qt::LeftButton); + } + }, box->lifetime()); - weak->closeBox(); - }, - args.confirmStyle ? *args.confirmStyle : defaultButtonStyle); - box->events( - ) | rpl::start_with_next([=](not_null e) { - if ((e->type() != QEvent::KeyPress) || !confirmButton) { - return; - } - const auto k = static_cast(e.get()); - if (k->key() == Qt::Key_Enter || k->key() == Qt::Key_Return) { - confirmButton->clicked(Qt::KeyboardModifiers(), Qt::LeftButton); - } - }, box->lifetime()); + if (!args.inform) + { + const auto cancelButton = box->addButton( + v::text::take_plain(std::move(args.cancelText), tr::lng_cancel()), + crl::guard(weak, [=, c = prepareCallback(args.cancelled)]() + { + lifetime->destroy(); + c(); + }), + args.cancelStyle ? *args.cancelStyle : defaultButtonStyle); - if (!args.inform) { - const auto cancelButton = box->addButton( - v::text::take_plain(std::move(args.cancelText), tr::lng_cancel()), - crl::guard(weak, [=, c = prepareCallback(args.cancelled)]() { - lifetime->destroy(); - c(); - }), - args.cancelStyle ? *args.cancelStyle : defaultButtonStyle); + box->boxClosing( + ) | start_with_next(crl::guard(cancelButton, [=] + { + cancelButton->clicked(Qt::KeyboardModifiers(), Qt::LeftButton); + }), *lifetime); + } - box->boxClosing( - ) | rpl::start_with_next(crl::guard(cancelButton, [=] { - cancelButton->clicked(Qt::KeyboardModifiers(), Qt::LeftButton); - }), *lifetime); - } + if (args.strictCancel) + { + lifetime->destroy(); + } + } - if (args.strictCancel) { - lifetime->destroy(); - } - } - - object_ptr MakeConfirmBox(Ui::ConfirmBoxArgs &&args) { - return Box(VoiceConfirmBox, std::move(args)); - } - - object_ptr MakeInformBox(v::text::data text) { - return MakeConfirmBox({ - .text = std::move(text), - .inform = true, - }); - } + object_ptr MakeConfirmBox(Ui::ConfirmBoxArgs&& args) + { + return Box(VoiceConfirmBox, std::move(args)); + } + object_ptr MakeInformBox(v::text::data text) + { + return MakeConfirmBox({ + .text = std::move(text), + .inform = true, + }); + } } // namespace AyuUi diff --git a/Telegram/SourceFiles/ayu/ui/boxes/voice_confirmation_box.h b/Telegram/SourceFiles/ayu/ui/boxes/voice_confirmation_box.h index 9b1ce65a1..0751bcd4b 100644 --- a/Telegram/SourceFiles/ayu/ui/boxes/voice_confirmation_box.h +++ b/Telegram/SourceFiles/ayu/ui/boxes/voice_confirmation_box.h @@ -6,16 +6,16 @@ // Copyright @Radolyn, 2023 #pragma once +#include "ui/boxes/confirm_box.h" #include "ui/layers/generic_box.h" #include "ui/text/text_variant.h" -#include "ui/boxes/confirm_box.h" -namespace AyuUi { - void VoiceConfirmBox(not_null box, Ui::ConfirmBoxArgs &&args); +namespace AyuUi +{ + void VoiceConfirmBox(not_null box, Ui::ConfirmBoxArgs&& args); - [[nodiscard]] object_ptr MakeConfirmBox( - Ui::ConfirmBoxArgs &&args); - - [[nodiscard]] object_ptr MakeInformBox(v::text::data text); + [[nodiscard]] object_ptr MakeConfirmBox( + Ui::ConfirmBoxArgs&& args); + [[nodiscard]] object_ptr MakeInformBox(v::text::data text); } // namespace Ui diff --git a/Telegram/SourceFiles/ayu/ui/context_menu/context_menu.cpp b/Telegram/SourceFiles/ayu/ui/context_menu/context_menu.cpp index b303ba607..ff065da88 100644 --- a/Telegram/SourceFiles/ayu/ui/context_menu/context_menu.cpp +++ b/Telegram/SourceFiles/ayu/ui/context_menu/context_menu.cpp @@ -6,47 +6,56 @@ // Copyright @Radolyn, 2023 #include "context_menu.h" -#include "history/history_inner_widget.h" #include "lang_auto.h" -#include "ui/widgets/popup_menu.h" -#include "base/unixtime.h" -#include "styles/style_chat.h" -#include "settings/settings_common.h" #include "message_history_box.h" -#include "ayu/database/ayu_database.h" #include "ayu/ayu_state.h" +#include "ayu/database/ayu_database.h" +#include "base/unixtime.h" +#include "history/history_inner_widget.h" +#include "settings/settings_common.h" +#include "styles/style_chat.h" +#include "ui/widgets/popup_menu.h" -namespace AyuUi { - AyuPopupMenu::AyuPopupMenu(HistoryInner *parent) { - _ayuSubMenu = std::make_unique(parent, st::popupMenuWithIcons); - } +namespace AyuUi +{ + AyuPopupMenu::AyuPopupMenu(HistoryInner* parent) + { + _ayuSubMenu = std::make_unique(parent, st::popupMenuWithIcons); + } - void AyuPopupMenu::addHistoryAction(HistoryItem *item) { - if (AyuDatabase::editedMessagesTableExists() && !((AyuDatabase::getEditedMessages(item)).empty())) { - _ayuSubMenu->addAction(tr::ayu_EditsHistoryMenuText(tr::now), [=] { - auto box = Box(item); - Ui::show(std::move(box)); - }, &st::menuIconInfo); - } - } + void AyuPopupMenu::addHistoryAction(HistoryItem* item) + { + if (AyuDatabase::editedMessagesTableExists() && !((AyuDatabase::getEditedMessages(item)).empty())) + { + _ayuSubMenu->addAction(tr::ayu_EditsHistoryMenuText(tr::now), [=] + { + auto box = Box(item); + show(std::move(box)); + }, &st::menuIconInfo); + } + } - void AyuPopupMenu::addHideMessageAction(HistoryItem *item) const { - const auto settings = &AyuSettings::getInstance(); - const auto history = item->history(); - _ayuSubMenu->addAction(QString("Hide"), [=]() { - const auto initKeepDeleted = settings->keepDeletedMessages; + void AyuPopupMenu::addHideMessageAction(HistoryItem* item) const + { + const auto settings = &AyuSettings::getInstance(); + const auto history = item->history(); + _ayuSubMenu->addAction(QString("Hide"), [=]() + { + const auto initKeepDeleted = settings->keepDeletedMessages; - settings->set_keepDeletedMessages(false); - history->destroyMessage(item); - settings->set_keepDeletedMessages(initKeepDeleted); - }, &st::menuIconClear); - } + settings->set_keepDeletedMessages(false); + history->destroyMessage(item); + settings->set_keepDeletedMessages(initKeepDeleted); + }, &st::menuIconClear); + } - void AyuPopupMenu::addReadUntilAction(HistoryItem *item) const { - const auto history = item->history(); - _ayuSubMenu->addAction(tr::ayu_ReadUntilMenuText(tr::now), [=]() { - AyuState::setAllowSendReadPacket(true); - history->session().data().histories().readInboxOnNewMessage(item); - }, &st::menuIconShowInChat); - } -} // namespace AyuUi \ No newline at end of file + void AyuPopupMenu::addReadUntilAction(HistoryItem* item) const + { + const auto history = item->history(); + _ayuSubMenu->addAction(tr::ayu_ReadUntilMenuText(tr::now), [=]() + { + AyuState::setAllowSendReadPacket(true); + history->session().data().histories().readInboxOnNewMessage(item); + }, &st::menuIconShowInChat); + } +} // namespace AyuUi diff --git a/Telegram/SourceFiles/ayu/ui/context_menu/context_menu.h b/Telegram/SourceFiles/ayu/ui/context_menu/context_menu.h index 47282e70c..3c3fda82a 100644 --- a/Telegram/SourceFiles/ayu/ui/context_menu/context_menu.h +++ b/Telegram/SourceFiles/ayu/ui/context_menu/context_menu.h @@ -7,93 +7,93 @@ #pragma once -#include "history/history_inner_widget.h" -#include "ui/widgets/popup_menu.h" -#include "ui/image/image.h" -#include "ui/effects/path_shift_gradient.h" -#include "ui/effects/message_sending_animation_controller.h" -#include "ui/effects/reaction_fly_animation.h" -#include "ui/text/text_options.h" -#include "ui/text/text_entity.h" -#include "ui/boxes/report_box.h" -#include "ui/layers/generic_box.h" -#include "ui/controls/delete_message_context_action.h" -#include "ui/controls/who_reacted_context_action.h" -#include "ui/painter.h" -#include "ui/ui_utility.h" -#include "ui/cached_round_corners.h" -#include "ui/inactive_press.h" -#include "window/window_adaptive.h" -#include "window/window_session_controller.h" -#include "window/window_controller.h" -#include "window/window_peer_menu.h" -#include "window/window_controller.h" -#include "window/notifications_manager.h" -#include "boxes/about_sponsored_box.h" -#include "boxes/delete_messages_box.h" -#include "boxes/report_messages_box.h" -#include "boxes/sticker_set_box.h" -#include "boxes/premium_preview_box.h" -#include "boxes/translate_box.h" -#include "chat_helpers/message_field.h" -#include "chat_helpers/emoji_interactions.h" -#include "history/history_widget.h" -#include "history/view/history_view_translate_tracker.h" +#include "mainwindow.h" +#include "base/call_delayed.h" +#include "base/unixtime.h" #include "base/platform/base_platform_info.h" #include "base/qt/qt_common_adapters.h" #include "base/qt/qt_key_modifiers.h" -#include "base/unixtime.h" -#include "base/call_delayed.h" -#include "mainwindow.h" +#include "boxes/about_sponsored_box.h" +#include "boxes/delete_messages_box.h" +#include "boxes/premium_preview_box.h" +#include "boxes/report_messages_box.h" +#include "boxes/sticker_set_box.h" +#include "boxes/translate_box.h" +#include "chat_helpers/emoji_interactions.h" +#include "chat_helpers/message_field.h" +#include "core/application.h" +#include "data/data_changes.h" +#include "data/data_channel.h" +#include "data/data_chat.h" +#include "data/data_document.h" +#include "data/data_file_click_handler.h" +#include "data/data_file_origin.h" +#include "data/data_forum_topic.h" +#include "data/data_histories.h" +#include "data/data_media_types.h" +#include "data/data_message_reactions.h" +#include "data/data_peer_values.h" +#include "data/data_photo.h" +#include "data/data_photo_media.h" +#include "data/data_poll.h" +#include "data/data_session.h" +#include "data/data_sponsored_messages.h" +#include "data/data_user.h" +#include "data/stickers/data_stickers.h" +#include "dialogs/ui/dialogs_video_userpic.h" +#include "history/history_inner_widget.h" +#include "history/history_widget.h" +#include "history/view/history_view_translate_tracker.h" +#include "lang/lang_keys.h" #include "layout/layout_selection.h" #include "main/main_session.h" #include "main/main_session_settings.h" #include "main/session/send_as_peers.h" #include "menu/menu_item_download_files.h" -#include "core/application.h" -#include "lang/lang_keys.h" -#include "data/data_session.h" -#include "data/data_media_types.h" -#include "data/data_message_reactions.h" -#include "data/data_document.h" -#include "data/data_channel.h" -#include "data/data_forum_topic.h" -#include "data/data_poll.h" -#include "data/data_photo.h" -#include "data/data_photo_media.h" -#include "data/data_peer_values.h" -#include "data/data_chat.h" -#include "data/data_user.h" -#include "data/data_file_click_handler.h" -#include "data/data_file_origin.h" -#include "data/data_histories.h" -#include "data/data_changes.h" -#include "data/stickers/data_stickers.h" -#include "data/data_sponsored_messages.h" -#include "dialogs/ui/dialogs_video_userpic.h" #include "settings/settings_premium.h" #include "styles/style_chat.h" -#include "styles/style_window.h" // st::windowMinWidth #include "styles/style_menu_icons.h" +#include "styles/style_window.h" // st::windowMinWidth +#include "ui/cached_round_corners.h" +#include "ui/inactive_press.h" +#include "ui/painter.h" +#include "ui/ui_utility.h" +#include "ui/boxes/report_box.h" +#include "ui/controls/delete_message_context_action.h" +#include "ui/controls/who_reacted_context_action.h" +#include "ui/effects/message_sending_animation_controller.h" +#include "ui/effects/path_shift_gradient.h" +#include "ui/effects/reaction_fly_animation.h" +#include "ui/image/image.h" +#include "ui/layers/generic_box.h" +#include "ui/text/text_entity.h" +#include "ui/text/text_options.h" +#include "ui/widgets/popup_menu.h" +#include "window/notifications_manager.h" +#include "window/window_adaptive.h" +#include "window/window_controller.h" +#include "window/window_controller.h" +#include "window/window_peer_menu.h" +#include "window/window_session_controller.h" #include "history/view/history_view_context_menu.h" -#include #include +#include -namespace AyuUi { - class AyuPopupMenu { +namespace AyuUi +{ + class AyuPopupMenu + { + public: + AyuPopupMenu(HistoryInner* parent); - public: - AyuPopupMenu(HistoryInner *parent); + void addHistoryAction(HistoryItem* item); - void addHistoryAction(HistoryItem *item); + void addHideMessageAction(HistoryItem* item) const; - void addHideMessageAction(HistoryItem *item) const; + void addReadUntilAction(HistoryItem* item) const; - void addReadUntilAction(HistoryItem *item) const; - - std::unique_ptr _ayuSubMenu; - }; - -} \ No newline at end of file + std::unique_ptr _ayuSubMenu; + }; +} diff --git a/Telegram/SourceFiles/ayu/ui/context_menu/message_history_box.cpp b/Telegram/SourceFiles/ayu/ui/context_menu/message_history_box.cpp index 2c0970e6b..ded4c94ce 100644 --- a/Telegram/SourceFiles/ayu/ui/context_menu/message_history_box.cpp +++ b/Telegram/SourceFiles/ayu/ui/context_menu/message_history_box.cpp @@ -5,65 +5,74 @@ // // Copyright @Radolyn, 2023 -#include -#include -#include -#include #include "message_history_box.h" -#include "settings/settings_common.h" +#include +#include +#include +#include #include "ayu/ayu_settings.h" #include "ayu/database/ayu_database.h" #include "history/history.h" +#include "settings/settings_common.h" using namespace Settings; -namespace AyuUi { - MessageHistoryBox::MessageHistoryBox(QWidget *, HistoryItem *item) - : _content(this), _scroll(base::make_unique_q(this, st::boxScroll)) { - setupControls(); - addEditedMessagesToLayout(item); - } +namespace AyuUi +{ + MessageHistoryBox::MessageHistoryBox(QWidget*, HistoryItem* item) + : _content(this), _scroll(base::make_unique_q(this, st::boxScroll)) + { + setupControls(); + addEditedMessagesToLayout(item); + } - void MessageHistoryBox::setupControls() { - _content.create(this); + void MessageHistoryBox::setupControls() + { + _content.create(this); - _content->resizeToWidth(st::boxWideWidth); - _content->moveToLeft(0, 0); + _content->resizeToWidth(st::boxWideWidth); + _content->moveToLeft(0, 0); - _content->heightValue( - ) | rpl::start_to_stream(_contentHeight, _content->lifetime()); + _content->heightValue( + ) | start_to_stream(_contentHeight, _content->lifetime()); - _scroll->setOwnedWidget( - object_ptr::fromRaw(_content)); - } + _scroll->setOwnedWidget( + object_ptr::fromRaw(_content)); + } - void MessageHistoryBox::resizeEvent(QResizeEvent *e) { - _scroll->resize(width(), height() - st::boxPhotoPadding.top() - st::boxPadding.bottom()); - _scroll->move(0, st::boxPadding.top()); + void MessageHistoryBox::resizeEvent(QResizeEvent* e) + { + _scroll->resize(width(), height() - st::boxPhotoPadding.top() - st::boxPadding.bottom()); + _scroll->move(0, st::boxPadding.top()); - if (_content) { - _content->resize(_scroll->width(), _content->height()); - } - } + if (_content) + { + _content->resize(_scroll->width(), _content->height()); + } + } - void MessageHistoryBox::prepare() { - setTitle(tr::ayu_EditsHistoryTitle()); + void MessageHistoryBox::prepare() + { + setTitle(tr::ayu_EditsHistoryTitle()); -// setDimensionsToContent(st::boxWideWidth, _content); - setDimensions(st::boxWideWidth, 900); - Ui::SetupShadowsToScrollContent(this, _scroll, _contentHeight.events()); - } + // setDimensionsToContent(st::boxWideWidth, _content); + setDimensions(st::boxWideWidth, 900); + SetupShadowsToScrollContent(this, _scroll, _contentHeight.events()); + } - void MessageHistoryBox::addEditedMessagesToLayout(HistoryItem *item) { - auto messages = AyuDatabase::getEditedMessages(item); - if (messages.empty()) { - return; - } + void MessageHistoryBox::addEditedMessagesToLayout(HistoryItem* item) + { + auto messages = AyuDatabase::getEditedMessages(item); + if (messages.empty()) + { + return; + } - for (const auto &message: messages) { - AddSkip(_content); - AddDividerText(_content, rpl::single(QString::fromStdString(message.text))); - AddSkip(_content); - } - } -} \ No newline at end of file + for (const auto& message : messages) + { + AddSkip(_content); + AddDividerText(_content, rpl::single(QString::fromStdString(message.text))); + AddSkip(_content); + } + } +} diff --git a/Telegram/SourceFiles/ayu/ui/context_menu/message_history_box.h b/Telegram/SourceFiles/ayu/ui/context_menu/message_history_box.h index 73cc9e60c..0bebb9082 100644 --- a/Telegram/SourceFiles/ayu/ui/context_menu/message_history_box.h +++ b/Telegram/SourceFiles/ayu/ui/context_menu/message_history_box.h @@ -6,28 +6,30 @@ // Copyright @Radolyn, 2023 #include -#include "ui/wrap/vertical_layout.h" -#include "ui/widgets/scroll_area.h" #include "history/history_item.h" +#include "ui/widgets/scroll_area.h" +#include "ui/wrap/vertical_layout.h" -namespace AyuUi { - class MessageHistoryBox : public Ui::BoxContent { - public: - MessageHistoryBox(QWidget *, HistoryItem *item); +namespace AyuUi +{ + class MessageHistoryBox : public Ui::BoxContent + { + public: + MessageHistoryBox(QWidget*, HistoryItem* item); - protected: - void prepare() override; + protected: + void prepare() override; - void resizeEvent(QResizeEvent *e) override; + void resizeEvent(QResizeEvent* e) override; - private: - void setupControls(); + private: + void setupControls(); - void addEditedMessagesToLayout(HistoryItem *item); + void addEditedMessagesToLayout(HistoryItem* item); - object_ptr _content; - const base::unique_qptr _scroll; + object_ptr _content; + const base::unique_qptr _scroll; - rpl::event_stream _contentHeight; - }; -} \ No newline at end of file + rpl::event_stream _contentHeight; + }; +} diff --git a/Telegram/SourceFiles/ayu/ui/settings/settings_ayu.cpp b/Telegram/SourceFiles/ayu/ui/settings/settings_ayu.cpp index 339e2ad44..445039b71 100644 --- a/Telegram/SourceFiles/ayu/ui/settings/settings_ayu.cpp +++ b/Telegram/SourceFiles/ayu/ui/settings/settings_ayu.cpp @@ -5,429 +5,475 @@ // // Copyright @Radolyn, 2023 -#include "ayu/sync/ayu_sync_controller.h" -#include "ayu/ui/boxes/edit_edited_mark.h" -#include "ayu/ui/boxes/edit_deleted_mark.h" -#include "ayu/ayu_settings.h" #include "settings_ayu.h" +#include "ayu/ayu_settings.h" +#include "ayu/sync/ayu_sync_controller.h" +#include "ayu/ui/boxes/edit_deleted_mark.h" +#include "ayu/ui/boxes/edit_edited_mark.h" +#include "apiwrap.h" #include "lang_auto.h" #include "mainwindow.h" +#include "api/api_blocked_peers.h" +#include "boxes/connection_box.h" +#include "core/application.h" +#include "data/data_session.h" +#include "lang/lang_instance.h" +#include "main/main_session.h" +#include "platform/platform_specific.h" #include "settings/settings_common.h" -#include "ui/wrap/vertical_layout.h" +#include "storage/localstorage.h" +#include "styles/style_settings.h" +#include "ui/boxes/single_choice_box.h" #include "ui/widgets/buttons.h" #include "ui/widgets/checkbox.h" -#include "boxes/connection_box.h" -#include "platform/platform_specific.h" -#include "window/window_session_controller.h" -#include "lang/lang_instance.h" -#include "core/application.h" -#include "storage/localstorage.h" -#include "data/data_session.h" -#include "main/main_session.h" -#include "styles/style_settings.h" -#include "apiwrap.h" -#include "api/api_blocked_peers.h" #include "ui/widgets/continuous_sliders.h" -#include "ui/boxes/single_choice_box.h" +#include "ui/wrap/vertical_layout.h" +#include "window/window_session_controller.h" -namespace Settings { +namespace Settings +{ + rpl::producer Ayu::title() + { + return tr::ayu_AyuPreferences(); + } - rpl::producer Ayu::title() { - return tr::ayu_AyuPreferences(); - } + Ayu::Ayu( + QWidget* parent, + not_null controller) + : Section(parent) + { + setupContent(controller); + } - Ayu::Ayu( - QWidget *parent, - not_null controller) - : Section(parent) { - setupContent(controller); - } + void Ayu::SetupGhostEssentials(not_null container) + { + auto settings = &AyuSettings::getInstance(); - void Ayu::SetupGhostEssentials(not_null container) { - auto settings = &AyuSettings::getInstance(); + AddSubsectionTitle(container, tr::ayu_GhostEssentialsHeader()); - AddSubsectionTitle(container, tr::ayu_GhostEssentialsHeader()); + AddButton( + container, + tr::ayu_SendReadPackets(), + st::settingsButtonNoIcon + )->toggleOn( + rpl::single(settings->sendReadPackets) + )->toggledValue( + ) | rpl::filter([=](bool enabled) + { + return (enabled != settings->sendReadPackets); + }) | start_with_next([=](bool enabled) + { + settings->set_sendReadPackets(enabled); + AyuSettings::save(); + }, container->lifetime()); - AddButton( - container, - tr::ayu_SendReadPackets(), - st::settingsButtonNoIcon - )->toggleOn( - rpl::single(settings->sendReadPackets) - )->toggledValue( - ) | rpl::filter([=](bool enabled) { - return (enabled != settings->sendReadPackets); - }) | rpl::start_with_next([=](bool enabled) { - settings->set_sendReadPackets(enabled); - AyuSettings::save(); - }, container->lifetime()); + AddButton( + container, + tr::ayu_SendOnlinePackets(), + st::settingsButtonNoIcon + )->toggleOn( + rpl::single(settings->sendOnlinePackets) + )->toggledValue( + ) | rpl::filter([=](bool enabled) + { + return (enabled != settings->sendOnlinePackets); + }) | start_with_next([=](bool enabled) + { + settings->set_sendOnlinePackets(enabled); + AyuSettings::save(); + }, container->lifetime()); - AddButton( - container, - tr::ayu_SendOnlinePackets(), - st::settingsButtonNoIcon - )->toggleOn( - rpl::single(settings->sendOnlinePackets) - )->toggledValue( - ) | rpl::filter([=](bool enabled) { - return (enabled != settings->sendOnlinePackets); - }) | rpl::start_with_next([=](bool enabled) { - settings->set_sendOnlinePackets(enabled); - AyuSettings::save(); - }, container->lifetime()); + AddButton( + container, + tr::ayu_SendUploadProgress(), + st::settingsButtonNoIcon + )->toggleOn( + rpl::single(settings->sendUploadProgress) + )->toggledValue( + ) | rpl::filter([=](bool enabled) + { + return (enabled != settings->sendUploadProgress); + }) | start_with_next([=](bool enabled) + { + settings->set_sendUploadProgress(enabled); + AyuSettings::save(); + }, container->lifetime()); - AddButton( - container, - tr::ayu_SendUploadProgress(), - st::settingsButtonNoIcon - )->toggleOn( - rpl::single(settings->sendUploadProgress) - )->toggledValue( - ) | rpl::filter([=](bool enabled) { - return (enabled != settings->sendUploadProgress); - }) | rpl::start_with_next([=](bool enabled) { - settings->set_sendUploadProgress(enabled); - AyuSettings::save(); - }, container->lifetime()); + AddButton( + container, + tr::ayu_SendOfflinePacketAfterOnline(), + st::settingsButtonNoIcon + )->toggleOn( + rpl::single(settings->sendOfflinePacketAfterOnline) + )->toggledValue( + ) | rpl::filter([=](bool enabled) + { + return (enabled != settings->sendOfflinePacketAfterOnline); + }) | start_with_next([=](bool enabled) + { + settings->set_sendOfflinePacketAfterOnline(enabled); + AyuSettings::save(); + }, container->lifetime()); - AddButton( - container, - tr::ayu_SendOfflinePacketAfterOnline(), - st::settingsButtonNoIcon - )->toggleOn( - rpl::single(settings->sendOfflinePacketAfterOnline) - )->toggledValue( - ) | rpl::filter([=](bool enabled) { - return (enabled != settings->sendOfflinePacketAfterOnline); - }) | rpl::start_with_next([=](bool enabled) { - settings->set_sendOfflinePacketAfterOnline(enabled); - AyuSettings::save(); - }, container->lifetime()); + AddButton( + container, + tr::ayu_MarkReadAfterSend(), + st::settingsButtonNoIcon + )->toggleOn( + rpl::single(settings->markReadAfterSend) + )->toggledValue( + ) | rpl::filter([=](bool enabled) + { + return (enabled != settings->markReadAfterSend); + }) | start_with_next([=](bool enabled) + { + settings->set_markReadAfterSend(enabled); + AyuSettings::save(); + }, container->lifetime()); - AddButton( - container, - tr::ayu_MarkReadAfterSend(), - st::settingsButtonNoIcon - )->toggleOn( - rpl::single(settings->markReadAfterSend) - )->toggledValue( - ) | rpl::filter([=](bool enabled) { - return (enabled != settings->markReadAfterSend); - }) | rpl::start_with_next([=](bool enabled) { - settings->set_markReadAfterSend(enabled); - AyuSettings::save(); - }, container->lifetime()); + AddButton( + container, + tr::ayu_UseScheduledMessages(), + st::settingsButtonNoIcon + )->toggleOn( + rpl::single(settings->useScheduledMessages) + )->toggledValue( + ) | rpl::filter([=](bool enabled) + { + return (enabled != settings->useScheduledMessages); + }) | start_with_next([=](bool enabled) + { + settings->set_useScheduledMessages(enabled); + AyuSettings::save(); + }, container->lifetime()); + } - AddButton( - container, - tr::ayu_UseScheduledMessages(), - st::settingsButtonNoIcon - )->toggleOn( - rpl::single(settings->useScheduledMessages) - )->toggledValue( - ) | rpl::filter([=](bool enabled) { - return (enabled != settings->useScheduledMessages); - }) | rpl::start_with_next([=](bool enabled) { - settings->set_useScheduledMessages(enabled); - AyuSettings::save(); - }, container->lifetime()); - } + void Ayu::SetupSpyEssentials(not_null container) + { + auto settings = &AyuSettings::getInstance(); - void Ayu::SetupSpyEssentials(not_null container) { - auto settings = &AyuSettings::getInstance(); + AddSubsectionTitle(container, tr::ayu_SpyEssentialsHeader()); - AddSubsectionTitle(container, tr::ayu_SpyEssentialsHeader()); + AddButton( + container, + tr::ayu_KeepDeletedMessages(), + st::settingsButtonNoIcon + )->toggleOn( + rpl::single(settings->keepDeletedMessages) + )->toggledValue( + ) | rpl::filter([=](bool enabled) + { + return (enabled != settings->keepDeletedMessages); + }) | start_with_next([=](bool enabled) + { + settings->set_keepDeletedMessages(enabled); + AyuSettings::save(); + }, container->lifetime()); - AddButton( - container, - tr::ayu_KeepDeletedMessages(), - st::settingsButtonNoIcon - )->toggleOn( - rpl::single(settings->keepDeletedMessages) - )->toggledValue( - ) | rpl::filter([=](bool enabled) { - return (enabled != settings->keepDeletedMessages); - }) | rpl::start_with_next([=](bool enabled) { - settings->set_keepDeletedMessages(enabled); - AyuSettings::save(); - }, container->lifetime()); + AddButton( + container, + tr::ayu_KeepMessagesHistory(), + st::settingsButtonNoIcon + )->toggleOn( + rpl::single(settings->keepMessagesHistory) + )->toggledValue( + ) | rpl::filter([=](bool enabled) + { + return (enabled != settings->keepMessagesHistory); + }) | start_with_next([=](bool enabled) + { + settings->set_keepMessagesHistory(enabled); + AyuSettings::save(); + }, container->lifetime()); + } - AddButton( - container, - tr::ayu_KeepMessagesHistory(), - st::settingsButtonNoIcon - )->toggleOn( - rpl::single(settings->keepMessagesHistory) - )->toggledValue( - ) | rpl::filter([=](bool enabled) { - return (enabled != settings->keepMessagesHistory); - }) | rpl::start_with_next([=](bool enabled) { - settings->set_keepMessagesHistory(enabled); - AyuSettings::save(); - }, container->lifetime()); - } + void Ayu::SetupQoLToggles(not_null container) + { + auto settings = &AyuSettings::getInstance(); - void Ayu::SetupQoLToggles(not_null container) { - auto settings = &AyuSettings::getInstance(); + AddSubsectionTitle(container, tr::ayu_QoLTogglesHeader()); - AddSubsectionTitle(container, tr::ayu_QoLTogglesHeader()); + AddButton( + container, + tr::ayu_EnableAds(), + st::settingsButtonNoIcon + )->toggleOn( + rpl::single(settings->enableAds) + )->toggledValue( + ) | rpl::filter([=](bool enabled) + { + return (enabled != settings->enableAds); + }) | start_with_next([=](bool enabled) + { + settings->set_enableAds(enabled); + AyuSettings::save(); + }, container->lifetime()); + } - AddButton( - container, - tr::ayu_EnableAds(), - st::settingsButtonNoIcon - )->toggleOn( - rpl::single(settings->enableAds) - )->toggledValue( - ) | rpl::filter([=](bool enabled) { - return (enabled != settings->enableAds); - }) | rpl::start_with_next([=](bool enabled) { - settings->set_enableAds(enabled); - AyuSettings::save(); - }, container->lifetime()); - } + void Ayu::SetupCustomization(not_null container, + not_null controller) + { + auto settings = &AyuSettings::getInstance(); - void Ayu::SetupCustomization(not_null container, - not_null controller) { - auto settings = &AyuSettings::getInstance(); + AddSubsectionTitle(container, tr::ayu_CustomizationHeader()); - AddSubsectionTitle(container, tr::ayu_CustomizationHeader()); + auto btn = AddButtonWithLabel( + container, + tr::ayu_DeletedMarkText(), + AyuSettings::get_deletedMarkReactive(), + st::settingsButtonNoIcon + ); + btn->addClickHandler([=]() + { + auto box = Box(); + Ui::show(std::move(box)); + }); - auto btn = AddButtonWithLabel( - container, - tr::ayu_DeletedMarkText(), - AyuSettings::get_deletedMarkReactive(), - st::settingsButtonNoIcon - ); - btn->addClickHandler([=]() { - auto box = Box(); - Ui::show(std::move(box)); - }); + auto btn2 = AddButtonWithLabel( + container, + tr::ayu_EditedMarkText(), + AyuSettings::get_editedMarkReactive(), + st::settingsButtonNoIcon + ); + btn2->addClickHandler([=]() + { + auto box = Box(); + Ui::show(std::move(box)); + }); - auto btn2 = AddButtonWithLabel( - container, - tr::ayu_EditedMarkText(), - AyuSettings::get_editedMarkReactive(), - st::settingsButtonNoIcon - ); - btn2->addClickHandler([=]() { - auto box = Box(); - Ui::show(std::move(box)); - }); + SetupRecentStickersLimitSlider(container); - SetupRecentStickersLimitSlider(container); + SetupShowPeerId(container, controller); - SetupShowPeerId(container, controller); + AddButton( + container, + tr::ayu_ShowGhostToggleInDrawer(), + st::settingsButtonNoIcon + )->toggleOn( + rpl::single(settings->showGhostToggleInDrawer) + )->toggledValue( + ) | rpl::filter([=](bool enabled) + { + return (enabled != settings->showGhostToggleInDrawer); + }) | start_with_next([=](bool enabled) + { + settings->set_showGhostToggleInDrawer(enabled); + AyuSettings::save(); + }, container->lifetime()); - AddButton( - container, - tr::ayu_ShowGhostToggleInDrawer(), - st::settingsButtonNoIcon - )->toggleOn( - rpl::single(settings->showGhostToggleInDrawer) - )->toggledValue( - ) | rpl::filter([=](bool enabled) { - return (enabled != settings->showGhostToggleInDrawer); - }) | rpl::start_with_next([=](bool enabled) { - settings->set_showGhostToggleInDrawer(enabled); - AyuSettings::save(); - }, container->lifetime()); + AddButton( + container, + tr::ayu_SettingsShowMessageSeconds(), + st::settingsButtonNoIcon + )->toggleOn( + rpl::single(settings->showMessageSeconds) + )->toggledValue( + ) | rpl::filter([=](bool enabled) + { + return (enabled != settings->showMessageSeconds); + }) | start_with_next([=](bool enabled) + { + settings->set_showMessageSeconds(enabled); + AyuSettings::save(); + }, container->lifetime()); - AddButton( - container, - tr::ayu_SettingsShowMessageSeconds(), - st::settingsButtonNoIcon - )->toggleOn( - rpl::single(settings->showMessageSeconds) - )->toggledValue( - ) | rpl::filter([=](bool enabled) { - return (enabled != settings->showMessageSeconds); - }) | rpl::start_with_next([=](bool enabled) { - settings->set_showMessageSeconds(enabled); - AyuSettings::save(); - }, container->lifetime()); + AddDividerText(container, tr::ayu_SettingsCustomizationHint()); + } - AddDividerText(container, tr::ayu_SettingsCustomizationHint()); - } + void Ayu::SetupShowPeerId(not_null container, + not_null controller) + { + auto settings = &AyuSettings::getInstance(); - void Ayu::SetupShowPeerId(not_null container, - not_null controller) { - auto settings = &AyuSettings::getInstance(); + const auto options = std::vector{ + QString(tr::ayu_SettingsShowID_Hide(tr::now)), + QString("Telegram API"), + QString("Bot API") + }; - const auto options = std::vector{ - QString(tr::ayu_SettingsShowID_Hide(tr::now)), - QString("Telegram API"), - QString("Bot API") - }; + auto currentVal = AyuSettings::get_showPeerIdReactive() | rpl::map([=](int val) + { + return options[val]; + }); - auto currentVal = AyuSettings::get_showPeerIdReactive() | rpl::map([=](int val) { - return options[val]; - }); + const auto button = AddButtonWithLabel( + container, + tr::ayu_SettingsShowID(), + currentVal, + st::settingsButtonNoIcon); + button->addClickHandler([=] + { + controller->show(Box([=](not_null box) + { + const auto save = [=](int index) + { + settings->set_showPeerId(index); + AyuSettings::save(); + }; + SingleChoiceBox(box, { + .title = tr::ayu_SettingsShowID(), + .options = options, + .initialSelection = settings->showPeerId, + .callback = save, + }); + })); + }); + } - const auto button = AddButtonWithLabel( - container, - tr::ayu_SettingsShowID(), - currentVal, - st::settingsButtonNoIcon); - button->addClickHandler([=] { - controller->show(Box([=](not_null box) { - const auto save = [=](int index) { - settings->set_showPeerId(index); - AyuSettings::save(); - }; - SingleChoiceBox(box, { - .title = tr::ayu_SettingsShowID(), - .options = options, - .initialSelection = settings->showPeerId, - .callback = save, - }); - })); - }); - } + void Ayu::SetupRecentStickersLimitSlider(not_null container) + { + auto settings = &AyuSettings::getInstance(); - void Ayu::SetupRecentStickersLimitSlider(not_null container) { - auto settings = &AyuSettings::getInstance(); + container->add( + CreateButton( + container, + tr::ayu_SettingsRecentStickersCount(), + st::settingsButtonNoIcon) + ); - container->add( - CreateButton( - container, - tr::ayu_SettingsRecentStickersCount(), - st::settingsButtonNoIcon) - ); + auto recentStickersLimitSlider = MakeSliderWithLabel( + container, + st::settingsScale, + st::settingsScaleLabel, + st::normalFont->spacew * 2, + st::settingsScaleLabel.style.font->width("300%")); + container->add( + std::move(recentStickersLimitSlider.widget), + st::settingsScalePadding); + const auto slider = recentStickersLimitSlider.slider; + const auto label = recentStickersLimitSlider.label; - auto recentStickersLimitSlider = MakeSliderWithLabel( - container, - st::settingsScale, - st::settingsScaleLabel, - st::normalFont->spacew * 2, - st::settingsScaleLabel.style.font->width("300%")); - container->add( - std::move(recentStickersLimitSlider.widget), - st::settingsScalePadding); - const auto slider = recentStickersLimitSlider.slider; - const auto label = recentStickersLimitSlider.label; + const auto updateLabel = [=](int amount) + { + label->setText(QString::number(amount)); + }; + updateLabel(settings->recentStickersCount); - const auto updateLabel = [=](int amount) { - label->setText(QString::number(amount)); - }; - updateLabel(settings->recentStickersCount); + slider->setPseudoDiscrete( + 100 + 1, // thx tg + [=](int amount) { return amount; }, + settings->recentStickersCount, + [=](int amount) { updateLabel(amount); }, + [=](int amount) + { + updateLabel(amount); - slider->setPseudoDiscrete( - 100 + 1, // thx tg - [=](int amount) { return amount; }, - settings->recentStickersCount, - [=](int amount) { updateLabel(amount); }, - [=](int amount) { - updateLabel(amount); + settings->set_recentStickersCount(amount); + AyuSettings::save(); + }); + } - settings->set_recentStickersCount(amount); - AyuSettings::save(); - }); - } + void Ayu::SetupAyuSync(not_null container) + { + AddSubsectionTitle(container, rpl::single(QString("AyuSync"))); - void Ayu::SetupAyuSync(not_null container) { - AddSubsectionTitle(container, rpl::single(QString("AyuSync"))); + auto text = AyuSync::isAgentDownloaded() ? QString("Open preferences") : QString("Download agent"); - auto text = AyuSync::isAgentDownloaded() ? - QString("Open preferences") : - QString("Download agent"); + AddButton( + container, + rpl::single(text), + st::settingsButtonNoIcon + )->addClickHandler([=] + { + auto controller = &AyuSync::getControllerInstance(); + controller->initializeAgent(); + }); + } - AddButton( - container, - rpl::single(text), - st::settingsButtonNoIcon - )->addClickHandler([=] { - auto controller = &AyuSync::getControllerInstance(); - controller->initializeAgent(); - }); - } + void Ayu::SetupBetaFunctions(not_null container) + { + auto settings = &AyuSettings::getInstance(); - void Ayu::SetupBetaFunctions(not_null container) { - auto settings = &AyuSettings::getInstance(); + AddSubsectionTitle(container, rpl::single(QString("Beta functions"))); - AddSubsectionTitle(container, rpl::single(QString("Beta functions"))); + AddButton( + container, + rpl::single(QString("Send sticker confirmation")), + st::settingsButtonNoIcon + )->toggleOn( + rpl::single(settings->stickerConfirmation) + )->toggledValue( + ) | rpl::filter([=](bool enabled) + { + return (enabled != settings->stickerConfirmation); + }) | start_with_next([=](bool enabled) + { + settings->set_stickerConfirmation(enabled); + AyuSettings::save(); + }, container->lifetime()); - AddButton( - container, - rpl::single(QString("Send sticker confirmation")), - st::settingsButtonNoIcon - )->toggleOn( - rpl::single(settings->stickerConfirmation) - )->toggledValue( - ) | rpl::filter([=](bool enabled) { - return (enabled != settings->stickerConfirmation); - }) | rpl::start_with_next([=](bool enabled) { - settings->set_stickerConfirmation(enabled); - AyuSettings::save(); - }, container->lifetime()); + AddButton( + container, + rpl::single(QString("Send GIF confirmation")), + st::settingsButtonNoIcon + )->toggleOn( + rpl::single(settings->GIFConfirmation) + )->toggledValue( + ) | rpl::filter([=](bool enabled) + { + return (enabled != settings->GIFConfirmation); + }) | start_with_next([=](bool enabled) + { + settings->set_GIFConfirmation(enabled); + AyuSettings::save(); + }, container->lifetime()); - AddButton( - container, - rpl::single(QString("Send GIF confirmation")), - st::settingsButtonNoIcon - )->toggleOn( - rpl::single(settings->GIFConfirmation) - )->toggledValue( - ) | rpl::filter([=](bool enabled) { - return (enabled != settings->GIFConfirmation); - }) | rpl::start_with_next([=](bool enabled) { - settings->set_GIFConfirmation(enabled); - AyuSettings::save(); - }, container->lifetime()); + AddButton( + container, + rpl::single(QString("Send voice confirmation")), + st::settingsButtonNoIcon + )->toggleOn( + rpl::single(settings->voiceConfirmation) + )->toggledValue( + ) | rpl::filter([=](bool enabled) + { + return (enabled != settings->voiceConfirmation); + }) | start_with_next([=](bool enabled) + { + settings->set_voiceConfirmation(enabled); + AyuSettings::save(); + }, container->lifetime()); + } - AddButton( - container, - rpl::single(QString("Send voice confirmation")), - st::settingsButtonNoIcon - )->toggleOn( - rpl::single(settings->voiceConfirmation) - )->toggledValue( - ) | rpl::filter([=](bool enabled) { - return (enabled != settings->voiceConfirmation); - }) | rpl::start_with_next([=](bool enabled) { - settings->set_voiceConfirmation(enabled); - AyuSettings::save(); - }, container->lifetime()); - } + void Ayu::SetupAyuGramSettings(not_null container, + not_null controller) + { + AddSkip(container); + SetupGhostEssentials(container); - void Ayu::SetupAyuGramSettings(not_null container, - not_null controller) { - AddSkip(container); - SetupGhostEssentials(container); + AddDivider(container); - AddDivider(container); + AddSkip(container); + SetupSpyEssentials(container); - AddSkip(container); - SetupSpyEssentials(container); + AddDivider(container); - AddDivider(container); + AddSkip(container); + SetupQoLToggles(container); - AddSkip(container); - SetupQoLToggles(container); + AddDivider(container); - AddDivider(container); + AddSkip(container); + SetupCustomization(container, controller); - AddSkip(container); - SetupCustomization(container, controller); + AddSkip(container); + SetupAyuSync(container); - AddSkip(container); - SetupAyuSync(container); + AddDivider(container); - AddDivider(container); + AddSkip(container); + SetupBetaFunctions(container); - AddSkip(container); - SetupBetaFunctions(container); + AddDividerText(container, tr::ayu_SettingsWatermark()); + } - AddDividerText(container, tr::ayu_SettingsWatermark()); - } + void Ayu::setupContent(not_null controller) + { + const auto content = Ui::CreateChild(this); - void Ayu::setupContent(not_null controller) { - const auto content = Ui::CreateChild(this); + SetupAyuGramSettings(content, controller); - SetupAyuGramSettings(content, controller); - - Ui::ResizeFitChild(this, content); - } + ResizeFitChild(this, content); + } } // namespace Settings - diff --git a/Telegram/SourceFiles/ayu/ui/settings/settings_ayu.h b/Telegram/SourceFiles/ayu/ui/settings/settings_ayu.h index 1ad2a0700..817fc9fe9 100644 --- a/Telegram/SourceFiles/ayu/ui/settings/settings_ayu.h +++ b/Telegram/SourceFiles/ayu/ui/settings/settings_ayu.h @@ -11,39 +11,42 @@ class BoxContent; -namespace Window { - class Controller; +namespace Window +{ + class Controller; - class SessionController; + class SessionController; } // namespace Window -namespace Settings { - class Ayu : public Section { - public: - Ayu(QWidget *parent, not_null controller); +namespace Settings +{ + class Ayu : public Section + { + public: + Ayu(QWidget* parent, not_null controller); - [[nodiscard]] rpl::producer title() override; + [[nodiscard]] rpl::producer title() override; - private: - void SetupGhostEssentials(not_null container); + private: + void SetupGhostEssentials(not_null container); - void SetupSpyEssentials(not_null container); + void SetupSpyEssentials(not_null container); - void SetupQoLToggles(not_null container); + void SetupQoLToggles(not_null container); - void SetupCustomization(not_null container, not_null controller); + void SetupCustomization(not_null container, + not_null controller); - void SetupShowPeerId(not_null container, not_null controller); + void SetupShowPeerId(not_null container, not_null controller); - void SetupRecentStickersLimitSlider(not_null container); + void SetupRecentStickersLimitSlider(not_null container); - void SetupAyuSync(not_null container); + void SetupAyuSync(not_null container); - void SetupBetaFunctions(not_null container); + void SetupBetaFunctions(not_null container); - void SetupAyuGramSettings(not_null container, not_null null); - - void setupContent(not_null controller); - }; + void SetupAyuGramSettings(not_null container, not_null null); + void setupContent(not_null controller); + }; } // namespace Settings diff --git a/Telegram/SourceFiles/ayu/ui/utils/ayu_profile_values.cpp b/Telegram/SourceFiles/ayu/ui/utils/ayu_profile_values.cpp index 567dd459f..8eb2f60e2 100644 --- a/Telegram/SourceFiles/ayu/ui/utils/ayu_profile_values.cpp +++ b/Telegram/SourceFiles/ayu/ui/utils/ayu_profile_values.cpp @@ -5,47 +5,55 @@ // // Copyright @Radolyn, 2023 -#include "ui/text/text_utilities.h" -#include "ayu/ayu_settings.h" #include "ayu_profile_values.h" +#include "ayu/ayu_settings.h" #include "data/data_peer.h" +#include "ui/text/text_utilities.h" constexpr auto kMaxChannelId = -1000000000000; -QString IDString(not_null peer) { - auto resultId = QString::number(peerIsUser(peer->id) - ? peerToUser(peer->id).bare - : peerIsChat(peer->id) - ? peerToChat(peer->id).bare - : peerIsChannel(peer->id) - ? peerToChannel(peer->id).bare - : peer->id.value); +QString IDString(not_null peer) +{ + auto resultId = QString::number(peerIsUser(peer->id) + ? peerToUser(peer->id).bare + : peerIsChat(peer->id) + ? peerToChat(peer->id).bare + : peerIsChannel(peer->id) + ? peerToChannel(peer->id).bare + : peer->id.value); - auto const settings = &AyuSettings::getInstance(); - if (settings->showPeerId == 2) { - if (peer->isChannel()) { - resultId = QString::number(peerToChannel(peer->id).bare - kMaxChannelId).prepend("-"); - } else if (peer->isChat()) { - resultId = resultId.prepend("-"); - } - } + const auto settings = &AyuSettings::getInstance(); + if (settings->showPeerId == 2) + { + if (peer->isChannel()) + { + resultId = QString::number(peerToChannel(peer->id).bare - kMaxChannelId).prepend("-"); + } + else if (peer->isChat()) + { + resultId = resultId.prepend("-"); + } + } - return resultId; + return resultId; } -QString IDString(MsgId topic_root_id) { - auto resultId = QString::number(topic_root_id.bare); +QString IDString(MsgId topic_root_id) +{ + auto resultId = QString::number(topic_root_id.bare); - return resultId; + return resultId; } -rpl::producer IDValue(not_null peer) { - return rpl::single(IDString(peer)) | Ui::Text::ToWithEntities(); +rpl::producer IDValue(not_null peer) +{ + return rpl::single(IDString(peer)) | Ui::Text::ToWithEntities(); } -rpl::producer IDValue(MsgId topic_root_id) { - return rpl::single(IDString(topic_root_id)) | Ui::Text::ToWithEntities(); -} \ No newline at end of file +rpl::producer IDValue(MsgId topic_root_id) +{ + return rpl::single(IDString(topic_root_id)) | Ui::Text::ToWithEntities(); +} diff --git a/Telegram/SourceFiles/ayu/ui/utils/ayu_profile_values.h b/Telegram/SourceFiles/ayu/ui/utils/ayu_profile_values.h index d80ef7b08..bdf91d415 100644 --- a/Telegram/SourceFiles/ayu/ui/utils/ayu_profile_values.h +++ b/Telegram/SourceFiles/ayu/ui/utils/ayu_profile_values.h @@ -8,8 +8,8 @@ #pragma once -QString IDString(not_null peer); +QString IDString(not_null peer); QString IDString(MsgId topic_root_id); -rpl::producer IDValue(not_null peer); -rpl::producer IDValue(MsgId topic_root_id); \ No newline at end of file +rpl::producer IDValue(not_null peer); +rpl::producer IDValue(MsgId topic_root_id); diff --git a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp index 4762a024d..8c788e07d 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp @@ -481,29 +481,32 @@ object_ptr DetailsFiller::setupInfo() { }); } - if (settings->showPeerId != 0) { - - auto idDrawableText = IDValue( - user - ) | rpl::map([](TextWithEntities &&text) { - return Ui::Text::Code(text.text); - }); - auto idInfo = addInfoOneLine( - rpl::single(QString("ID")), - std::move(idDrawableText), - tr::ayu_ContextCopyID(tr::now) - ); + if (settings->showPeerId != 0) + { + auto idDrawableText = IDValue( + user + ) | rpl::map([](TextWithEntities&& text) + { + return Ui::Text::Code(text.text); + }); + auto idInfo = addInfoOneLine( + rpl::single(QString("ID")), + std::move(idDrawableText), + tr::ayu_ContextCopyID(tr::now) + ); - idInfo.text->setClickHandlerFilter([=](auto &&...) { - const auto idText = IDString(user); - if (!idText.isEmpty()) { - QGuiApplication::clipboard()->setText(idText); - const auto msg = tr::ayu_IDCopiedToast(tr::now); - controller->showToast(msg); - } - return false; - }); - } + idInfo.text->setClickHandlerFilter([=](auto&&...) + { + const auto idText = IDString(user); + if (!idText.isEmpty()) + { + QGuiApplication::clipboard()->setText(idText); + const auto msg = tr::ayu_IDCopiedToast(tr::now); + controller->showToast(msg); + } + return false; + }); + } AddMainButton( result, @@ -566,45 +569,53 @@ object_ptr DetailsFiller::setupInfo() { addTranslateToMenu(about.text, AboutValue(_peer)); } - if (settings->showPeerId != 0 && !_topic) { - auto idDrawableText = IDValue( - _peer - ) | rpl::map([](TextWithEntities &&text) { - return Ui::Text::Code(text.text); - }); - auto idInfo = addInfoOneLine( - rpl::single(QString("ID")), - std::move(idDrawableText), - tr::ayu_ContextCopyID(tr::now) - ); + if (settings->showPeerId != 0 && !_topic) + { + auto idDrawableText = IDValue( + _peer + ) | rpl::map([](TextWithEntities&& text) + { + return Ui::Text::Code(text.text); + }); + auto idInfo = addInfoOneLine( + rpl::single(QString("ID")), + std::move(idDrawableText), + tr::ayu_ContextCopyID(tr::now) + ); - idInfo.text->setClickHandlerFilter([=, peer = _peer](auto &&...) { - const auto idText = IDString(peer); - if (!idText.isEmpty()) { - QGuiApplication::clipboard()->setText(idText); - const auto msg = tr::ayu_IDCopiedToast(tr::now); - controller->showToast(msg); - } - return false; - }); - } + idInfo.text->setClickHandlerFilter([=, peer = _peer](auto&&...) + { + const auto idText = IDString(peer); + if (!idText.isEmpty()) + { + QGuiApplication::clipboard()->setText(idText); + const auto msg = tr::ayu_IDCopiedToast(tr::now); + controller->showToast(msg); + } + return false; + }); + } - if (settings->showPeerId != 0 && _topic) { + if (settings->showPeerId != 0 && _topic) + { const auto topicRootId = _topic->rootId(); auto idDrawableText = IDValue( _peer->forumTopicFor(topicRootId)->topicRootId() - ) | rpl::map([](TextWithEntities &&text) { - return Ui::Text::Code(text.text); + ) | rpl::map([](TextWithEntities&& text) + { + return Ui::Text::Code(text.text); }); auto idInfo = addInfoOneLine( - rpl::single(QString("ID")), - std::move(idDrawableText), - tr::ayu_ContextCopyID(tr::now) + rpl::single(QString("ID")), + std::move(idDrawableText), + tr::ayu_ContextCopyID(tr::now) ); - idInfo.text->setClickHandlerFilter([=, peer = _peer](auto &&...) { + idInfo.text->setClickHandlerFilter([=, peer = _peer](auto&&...) + { const auto idText = IDString(peer); - if (!idText.isEmpty()) { + if (!idText.isEmpty()) + { QGuiApplication::clipboard()->setText(idText); const auto msg = tr::ayu_IDCopiedToast(tr::now); controller->showToast(msg);