diff --git a/.clang-format b/.clang-format deleted file mode 100644 index 8685938b4a..0000000000 --- a/.clang-format +++ /dev/null @@ -1,57 +0,0 @@ ---- -Language: Cpp -BasedOnStyle: LLVM -AccessModifierOffset: -4 -AlignConsecutiveAssignments: false -AlignConsecutiveDeclarations: false -AlignOperands: false -AlignTrailingComments: false -AllowShortCaseLabelsOnASingleLine: true -AllowShortIfStatementsOnASingleLine: true -AllowShortLoopsOnASingleLine: true -AlwaysBreakTemplateDeclarations: Yes -BinPackArguments: false -BinPackParameters: false -BraceWrapping: - AfterCaseLabel: false - AfterClass: true - AfterControlStatement: false - AfterEnum: true - AfterFunction: false - AfterNamespace: false - AfterStruct: true - AfterUnion: true - AfterExternBlock: true - BeforeCatch: false - BeforeElse: false - BeforeLambdaBody: true - BeforeWhile: false - SplitEmptyFunction: true - SplitEmptyRecord: true - SplitEmptyNamespace: true -BreakBeforeBraces: Custom -ColumnLimit: 120 -IncludeCategories: - - Regex: '^<.*' - Priority: 1 - - Regex: '^".*' - Priority: 2 - - Regex: '.*' - Priority: 3 -IncludeIsMainRegex: '([-_](test|unittest))?$' -IndentCaseLabels: true -IndentWidth: 4 -InsertNewlineAtEOF: true -MacroBlockBegin: '' -MacroBlockEnd: '' -MaxEmptyLinesToKeep: 2 -SpaceAfterCStyleCast: true -SpaceAfterTemplateKeyword: false -SpaceInEmptyParentheses: false -SpacesInAngles: false -SpacesInConditionalStatement: false -SpacesInCStyleCastParentheses: false -SpacesInParentheses: false -TabWidth: 4 -UseTab: Always -... diff --git a/Telegram/CMakeLists.txt b/Telegram/CMakeLists.txt index 75b4611f0b..b68022b0a3 100644 --- a/Telegram/CMakeLists.txt +++ b/Telegram/CMakeLists.txt @@ -232,8 +232,6 @@ set(ayugram_files ayu/features/filters/filters_cache_controller.h ayu/features/filters/filters_utils.cpp ayu/features/filters/filters_utils.h - ayu/features/filters/shadow_ban_utils.cpp - ayu/features/filters/shadow_ban_utils.h ayu/data/messages_storage.cpp ayu/data/messages_storage.h ayu/data/entities.h diff --git a/Telegram/SourceFiles/api/api_peer_search.cpp b/Telegram/SourceFiles/api/api_peer_search.cpp index 810fc45af3..0a206552a5 100644 --- a/Telegram/SourceFiles/api/api_peer_search.cpp +++ b/Telegram/SourceFiles/api/api_peer_search.cpp @@ -98,7 +98,7 @@ void PeerSearch::requestSponsored() { const MTPcontacts_SponsoredPeers &result, mtpRequestId requestId) { const auto &settings = AyuSettings::getInstance(); - if (settings.disableAds) { + if (settings.disableAds()) { finishSponsored(requestId, PeerSearchResult{}); return; } diff --git a/Telegram/SourceFiles/api/api_polls.cpp b/Telegram/SourceFiles/api/api_polls.cpp index f4f9369991..6df273ff22 100644 --- a/Telegram/SourceFiles/api/api_polls.cpp +++ b/Telegram/SourceFiles/api/api_polls.cpp @@ -175,8 +175,8 @@ void Polls::sendVotes( hideSending(); _session->updates().applyUpdates(result); - const auto &settings = AyuSettings::getInstance(); - if (!settings.sendReadMessages && settings.markReadAfterAction && item) + const auto &ghost = AyuSettings::ghost(_session); + if (!ghost.sendReadMessages() && ghost.markReadAfterAction() && item) { readHistory(item); } diff --git a/Telegram/SourceFiles/api/api_send_progress.cpp b/Telegram/SourceFiles/api/api_send_progress.cpp index 3ef238f556..c79ee258ed 100644 --- a/Telegram/SourceFiles/api/api_send_progress.cpp +++ b/Telegram/SourceFiles/api/api_send_progress.cpp @@ -118,8 +118,8 @@ void SendProgressManager::send(const Key &key, int progress) { } // AyuGram sendUploadProgress - const auto &settings = AyuSettings::getInstance(); - if (!settings.sendUploadProgress) + const auto &ghost = AyuSettings::ghost(_session); + if (!ghost.sendUploadProgress()) { DEBUG_LOG(("[AyuGram] Don't send upload progress")); return; diff --git a/Telegram/SourceFiles/api/api_unread_things.cpp b/Telegram/SourceFiles/api/api_unread_things.cpp index 82e7f903f3..d111022db7 100644 --- a/Telegram/SourceFiles/api/api_unread_things.cpp +++ b/Telegram/SourceFiles/api/api_unread_things.cpp @@ -47,10 +47,10 @@ bool UnreadThings::trackReactions(Data::Thread *thread) const { return false; } const auto &settings = AyuSettings::getInstance(); - if (peer->isChannel() && !peer->isMegagroup() && !settings.showChannelReactions) { + if (peer->isChannel() && !peer->isMegagroup() && !settings.showChannelReactions()) { return false; } - if (peer->isMegagroup() && !settings.showGroupReactions) { + if (peer->isMegagroup() && !settings.showGroupReactions()) { return false; } return peer->isUser() || peer->isChat() || peer->isMegagroup(); diff --git a/Telegram/SourceFiles/api/api_updates.cpp b/Telegram/SourceFiles/api/api_updates.cpp index 08ae9ceb57..db90cbd9a0 100644 --- a/Telegram/SourceFiles/api/api_updates.cpp +++ b/Telegram/SourceFiles/api/api_updates.cpp @@ -910,10 +910,10 @@ void Updates::updateOnline(crl::time lastNonIdleTime, bool gotOtherOffline) { }); // AyuGram sendOnlinePackets - const auto &settings = AyuSettings::getInstance(); + const auto &ghost = AyuSettings::ghost(_session); const auto& config = _session->serverConfig(); bool isOnlineOrig = Core::App().hasActiveWindow(&session()); - bool isOnline = settings.sendOnlinePackets && isOnlineOrig; + bool isOnline = ghost.sendOnlinePackets() && isOnlineOrig; int updateIn = config.onlineUpdatePeriod; Assert(updateIn >= 0); diff --git a/Telegram/SourceFiles/api/api_views.cpp b/Telegram/SourceFiles/api/api_views.cpp index 1a4afb88f9..54e1b7e850 100644 --- a/Telegram/SourceFiles/api/api_views.cpp +++ b/Telegram/SourceFiles/api/api_views.cpp @@ -87,7 +87,7 @@ void ViewsManager::pollExtendedMedia( } void ViewsManager::viewsIncrement() { - const auto &settings = AyuSettings::getInstance(); + const auto &ghost = AyuSettings::ghost(_session); for (auto i = _toIncrement.begin(); i != _toIncrement.cend();) { if (_incrementRequests.contains(i->first)) { @@ -103,7 +103,7 @@ void ViewsManager::viewsIncrement() { const auto requestId = _api.request(MTPmessages_GetMessagesViews( i->first->input(), MTP_vector(ids), - MTP_bool(settings.sendReadMessages) + MTP_bool(ghost.sendReadMessages()) )).done([=]( const MTPmessages_MessageViews &result, mtpRequestId requestId) { diff --git a/Telegram/SourceFiles/apiwrap.cpp b/Telegram/SourceFiles/apiwrap.cpp index 9081f3a806..78206acd3b 100644 --- a/Telegram/SourceFiles/apiwrap.cpp +++ b/Telegram/SourceFiles/apiwrap.cpp @@ -460,7 +460,7 @@ void ApiWrap::toggleHistoryArchived( history->setFolder(_session->data().folder(archiveId)); } else { const auto &settings = AyuSettings::getInstance(); - if (settings.hideAllChatsFolder) { + if (settings.hideAllChatsFolder()) { if (const auto window = Core::App().activeWindow()) { if (const auto controller = window->sessionController()) { const auto filters = &_session->data().chatsFilters(); @@ -1347,7 +1347,7 @@ void ApiWrap::migrateFail(not_null peer, const QString &error) { void ApiWrap::markContentsRead( const base::flat_set> &items) { - const auto &settings = AyuSettings::getInstance(); + const auto &ghost = AyuSettings::ghost(&session()); auto markedIds = QVector(); auto channelMarkedIds = base::flat_map< @@ -1361,7 +1361,7 @@ void ApiWrap::markContentsRead( continue; } - if (!settings.sendReadMessages && !passthrough) { + if (!ghost.sendReadMessages() && !passthrough) { continue; } @@ -1393,8 +1393,8 @@ void ApiWrap::markContentsRead(not_null item) { return; } - const auto &settings = AyuSettings::getInstance(); - if (!settings.sendReadMessages && !passthrough) { + const auto &ghost = AyuSettings::ghost(&session()); + if (!ghost.sendReadMessages() && !passthrough) { return; } @@ -1828,7 +1828,7 @@ void ApiWrap::joinChannel(not_null channel) { chatParticipants().loadSimilarPeers(channel); const auto &settings = AyuSettings::getInstance(); - if (!settings.collapseSimilarChannels) { + if (!settings.collapseSimilarChannels()) { channel->setFlags(channel->flags() | Flag::SimilarExpanded); } } @@ -3623,8 +3623,8 @@ void ApiWrap::forwardMessages( shared->callback(); } - const auto &settings = AyuSettings::getInstance(); - if (!settings.sendReadMessages && settings.markReadAfterAction && history->lastMessage()) + const auto &ghost = AyuSettings::ghost(&session()); + if (!ghost.sendReadMessages() && ghost.markReadAfterAction() && history->lastMessage()) { readHistory(history->lastMessage()); } @@ -3948,7 +3948,8 @@ void ApiWrap::sendUploadedPhoto( Api::RemoteFileInfo info, Api::SendOptions options) { if (const auto item = _session->data().message(localId)) { - if (AyuSettings::isUseScheduledMessages() && !options.scheduled) { + const auto &ghost = AyuSettings::ghost(_session); + if (ghost.isUseScheduledMessages() && !options.scheduled) { auto current = base::unixtime::now(); options.scheduled = current + 12; } @@ -3971,7 +3972,8 @@ void ApiWrap::sendUploadedDocument( return; } - if (AyuSettings::isUseScheduledMessages() && !options.scheduled) { + const auto &ghost = AyuSettings::ghost(_session); + if (ghost.isUseScheduledMessages() && !options.scheduled) { auto current = base::unixtime::now(); options.scheduled = current + 12; } @@ -4299,7 +4301,8 @@ void ApiWrap::sendBotStart( message.textWithTags.text += '@' + bot->username(); } - if (AyuSettings::isUseScheduledMessages()) { + const auto &ghost = AyuSettings::ghost(_session); + if (ghost.isUseScheduledMessages()) { auto current = base::unixtime::now(); message.action.options.scheduled = current + 12; } @@ -4550,7 +4553,8 @@ void ApiWrap::sendMediaWithRandomId( Api::SendOptions options, uint64 randomId, Fn done) { - if (AyuSettings::isUseScheduledMessages() && !options.scheduled) { + const auto &ghost = AyuSettings::ghost(_session); + if (ghost.isUseScheduledMessages() && !options.scheduled) { auto current = base::unixtime::now(); options.scheduled = current + 12; } @@ -4797,7 +4801,8 @@ void ApiWrap::sendAlbumIfReady(not_null album) { return; } - if (AyuSettings::isUseScheduledMessages() && !album->options.scheduled) { + const auto &ghost = AyuSettings::ghost(_session); + if (ghost.isUseScheduledMessages() && !album->options.scheduled) { auto current = base::unixtime::now(); album->options.scheduled = current + 12; } diff --git a/Telegram/SourceFiles/ayu/ayu_infra.cpp b/Telegram/SourceFiles/ayu/ayu_infra.cpp index 6c00d1301c..3e7154a477 100644 --- a/Telegram/SourceFiles/ayu/ayu_infra.cpp +++ b/Telegram/SourceFiles/ayu/ayu_infra.cpp @@ -12,8 +12,11 @@ #include "ayu/ayu_worker.h" #include "ayu/data/ayu_database.h" #include "features/translator/ayu_translator.h" -#include "features/filters/shadow_ban_utils.h" #include "lang/lang_instance.h" +#include "main/main_account.h" +#include "main/main_domain.h" +#include "main/main_session.h" +#include "ui/layers/generic_box.h" #include "utils/rc_manager.h" namespace AyuInfra { @@ -32,9 +35,9 @@ void initLang() { void initUiSettings() { const auto &settings = AyuSettings::getInstance(); - AyuUiSettings::setMonoFont(settings.monoFont); - AyuUiSettings::setWideMultiplier(settings.wideMultiplier); - AyuUiSettings::setMaterialSwitches(settings.materialSwitches); + AyuUiSettings::setMonoFont(settings.monoFont()); + AyuUiSettings::setWideMultiplier(settings.wideMultiplier()); + AyuUiSettings::setMaterialSwitches(settings.materialSwitches()); } void initDatabase() { diff --git a/Telegram/SourceFiles/ayu/ayu_settings.cpp b/Telegram/SourceFiles/ayu/ayu_settings.cpp index 206daa18d7..2aae650452 100644 --- a/Telegram/SourceFiles/ayu/ayu_settings.cpp +++ b/Telegram/SourceFiles/ayu/ayu_settings.cpp @@ -6,172 +6,228 @@ // Copyright @Radolyn, 2025 #include "ayu_settings.h" -#include "ayu/ui/ayu_logo.h" - +#include "ayu_worker.h" #include "lang_auto.h" +#include "ayu/ui/ayu_logo.h" #include "core/application.h" - -#include "rpl/lifetime.h" -#include "rpl/producer.h" -#include "rpl/variable.h" +#include "features/filters/filters_cache_controller.h" +#include "features/translator/ayu_translator.h" +#include "main/main_session.h" +#include "rpl/combine.h" +#include "window/window_controller.h" #include -#include "ayu_worker.h" -#include "features/translator/ayu_translator.h" -#include "window/window_controller.h" - using json = nlohmann::json; -namespace AyuSettings { - -std::optional settings = std::nullopt; - -rpl::variable sendReadMessagesReactive; -rpl::variable sendReadStoriesReactive; -rpl::variable sendOnlinePacketsReactive; -rpl::variable sendUploadProgressReactive; -rpl::variable sendOfflinePacketAfterOnlineReactive; - -rpl::variable ghostModeEnabled; - -rpl::variable deletedMarkReactive; -rpl::variable editedMarkReactive; - -rpl::variable showPeerIdReactive; - -rpl::variable translationProviderReactive; - -rpl::event_stream<> filtersUpdateReactive; // triggered on adding / editing filter - -rpl::event_stream<> historyUpdateReactive; - -rpl::lifetime lifetime = rpl::lifetime(); - -bool ghostModeEnabled_util(const AyuGramSettings &settingsUtil) { - return - !settingsUtil.sendReadMessages - && !settingsUtil.sendReadStories - && !settingsUtil.sendOnlinePackets - && !settingsUtil.sendUploadProgress - && settingsUtil.sendOfflinePacketAfterOnline; -} - -void initialize() { - if (settings.has_value()) { - return; - } - - settings = AyuGramSettings(); - - sendReadMessagesReactive.value() | rpl::filter( - [=](bool val) - { - return (val != settings->sendReadMessages); - }) | on_next( - [=](bool val) - { - ghostModeEnabled = - ghostModeEnabled_util(settings.value()); - }, - lifetime); - // .. - sendReadStoriesReactive.value() | rpl::filter( - [=](bool val) - { - return (val != settings->sendReadStories); - }) | on_next( - [=](bool val) - { - ghostModeEnabled = - ghostModeEnabled_util(settings.value()); - }, - lifetime); - // .. - sendOnlinePacketsReactive.value() | rpl::filter( - [=](bool val) - { - return (val != settings->sendOnlinePackets); - }) | on_next( - [=](bool val) - { - ghostModeEnabled = - ghostModeEnabled_util(settings - .value()); - }, - lifetime); - // .. - sendUploadProgressReactive.value() | rpl::filter( - [=](bool val) - { - return (val != settings->sendUploadProgress); - }) | on_next( - [=](bool val) - { - ghostModeEnabled = - ghostModeEnabled_util(settings - .value()); - }, - lifetime); - // .. - sendOfflinePacketAfterOnlineReactive.value() | rpl::filter( - [=](bool val) - { - return (val - != settings->sendOfflinePacketAfterOnline); - }) | on_next( - [=](bool val) - { - ghostModeEnabled = - ghostModeEnabled_util( - settings.value()); - }, - lifetime); -} - -void postinitialize() { - sendReadMessagesReactive = settings->sendReadMessages; - sendReadStoriesReactive = settings->sendReadStories; - sendUploadProgressReactive = settings->sendUploadProgress; - sendOfflinePacketAfterOnlineReactive = settings->sendOfflinePacketAfterOnline; - sendOnlinePacketsReactive = settings->sendOnlinePackets; - - deletedMarkReactive = settings->deletedMark; - editedMarkReactive = settings->editedMark; - showPeerIdReactive = settings->showPeerId; - translationProviderReactive = settings->translationProvider; - - ghostModeEnabled = ghostModeEnabled_util(settings.value()); - - if (settings->appIcon == QString("macos")) { - settings->appIcon = AyuAssets::DEFAULT_ICON; - } -} - -AyuGramSettings &getInstance() { - initialize(); - return settings.value(); -} +namespace { std::string getSettingsPath() { return (cWorkingDir() + u"tdata/ayu_settings.json"_q).toStdString(); } -void load() { +rpl::lifetime lifetime; // idk reactivity dies when placed in `GhostModeAccountSettings` as field + +} // namespace + +GhostModeAccountSettings::GhostModeAccountSettings() { + rpl::combine( + _sendReadMessages.value(), + _sendReadMessagesLocked.value(), + _sendReadStories.value(), + _sendReadStoriesLocked.value(), + _sendOnlinePackets.value(), + _sendOnlinePacketsLocked.value(), + _sendUploadProgress.value(), + _sendUploadProgressLocked.value(), + _sendOfflinePacketAfterOnline.value(), + _sendOfflinePacketAfterOnlineLocked.value() + ) | rpl::on_next([=]( + bool readMsg, bool readMsgLocked, + bool readStories, bool readStoriesLocked, + bool online, bool onlineLocked, + bool upload, bool uploadLocked, + bool offline, bool offlineLocked) { + _ghostModeActive = (readMsgLocked || !readMsg) + && (readStoriesLocked || !readStories) + && (onlineLocked || !online) + && (uploadLocked || !upload) + && (offlineLocked || offline); + }, lifetime); +} + +void GhostModeAccountSettings::setSendReadMessages(bool val) { + if (_sendReadMessages.current() == val) return; + _sendReadMessages = val; + AyuSettings::save(); +} + +void GhostModeAccountSettings::setSendReadStories(bool val) { + if (_sendReadStories.current() == val) return; + _sendReadStories = val; + AyuSettings::save(); +} + +void GhostModeAccountSettings::setSendOnlinePackets(bool val) { + if (_sendOnlinePackets.current() == val) return; + _sendOnlinePackets = val; + AyuSettings::save(); +} + +void GhostModeAccountSettings::setSendUploadProgress(bool val) { + if (_sendUploadProgress.current() == val) return; + _sendUploadProgress = val; + AyuSettings::save(); +} + +void GhostModeAccountSettings::setSendOfflinePacketAfterOnline(bool val) { + if (_sendOfflinePacketAfterOnline.current() == val) return; + _sendOfflinePacketAfterOnline = val; + AyuSettings::save(); +} + +void GhostModeAccountSettings::setMarkReadAfterAction(bool val) { + if (_markReadAfterAction.current() == val) return; + _markReadAfterAction = val; + AyuSettings::save(); +} + +void GhostModeAccountSettings::setUseScheduledMessages(bool val) { + if (_useScheduledMessages.current() == val) return; + _useScheduledMessages = val; + AyuSettings::save(); +} + +void GhostModeAccountSettings::setSendWithoutSound(bool val) { + if (_sendWithoutSound.current() == val) return; + _sendWithoutSound = val; + AyuSettings::save(); +} + +void GhostModeAccountSettings::setGhostModeEnabled(bool val) { + if (!_sendReadMessagesLocked.current()) _sendReadMessages = !val; + if (!_sendReadStoriesLocked.current()) _sendReadStories = !val; + if (!_sendOnlinePacketsLocked.current()) _sendOnlinePackets = !val; + if (!_sendUploadProgressLocked.current()) _sendUploadProgress = !val; + if (!_sendOfflinePacketAfterOnlineLocked.current()) _sendOfflinePacketAfterOnline = val; + AyuSettings::save(); + + if (val) { + if (const auto window = Core::App().activeWindow()) { + if (const auto session = window->maybeSession()) { + AyuWorker::markAsOnline(session); + } + } + } +} + +void GhostModeAccountSettings::setSendReadMessagesLocked(bool val) { + if (_sendReadMessagesLocked.current() == val) return; + _sendReadMessagesLocked = val; + AyuSettings::save(); +} + +void GhostModeAccountSettings::setSendReadStoriesLocked(bool val) { + if (_sendReadStoriesLocked.current() == val) return; + _sendReadStoriesLocked = val; + AyuSettings::save(); +} + +void GhostModeAccountSettings::setSendOnlinePacketsLocked(bool val) { + if (_sendOnlinePacketsLocked.current() == val) return; + _sendOnlinePacketsLocked = val; + AyuSettings::save(); +} + +void GhostModeAccountSettings::setSendUploadProgressLocked(bool val) { + if (_sendUploadProgressLocked.current() == val) return; + _sendUploadProgressLocked = val; + AyuSettings::save(); +} + +void GhostModeAccountSettings::setSendOfflinePacketAfterOnlineLocked(bool val) { + if (_sendOfflinePacketAfterOnlineLocked.current() == val) return; + _sendOfflinePacketAfterOnlineLocked = val; + AyuSettings::save(); +} + +void to_json(nlohmann::json &j, const GhostModeAccountSettings &s) { + j = nlohmann::json{ + {"sendReadMessages", s._sendReadMessages.current()}, + {"sendReadStories", s._sendReadStories.current()}, + {"sendOnlinePackets", s._sendOnlinePackets.current()}, + {"sendUploadProgress", s._sendUploadProgress.current()}, + {"sendOfflinePacketAfterOnline", s._sendOfflinePacketAfterOnline.current()}, + {"markReadAfterAction", s._markReadAfterAction.current()}, + {"useScheduledMessages", s._useScheduledMessages.current()}, + {"sendWithoutSound", s._sendWithoutSound.current()}, + {"sendReadMessagesLocked", s._sendReadMessagesLocked.current()}, + {"sendReadStoriesLocked", s._sendReadStoriesLocked.current()}, + {"sendOnlinePacketsLocked", s._sendOnlinePacketsLocked.current()}, + {"sendUploadProgressLocked", s._sendUploadProgressLocked.current()}, + {"sendOfflinePacketAfterOnlineLocked", s._sendOfflinePacketAfterOnlineLocked.current()} + }; +} + +void from_json(const nlohmann::json &j, GhostModeAccountSettings &s) { + s._sendReadMessages = j.value("sendReadMessages", true); + s._sendReadStories = j.value("sendReadStories", true); + s._sendOnlinePackets = j.value("sendOnlinePackets", true); + s._sendUploadProgress = j.value("sendUploadProgress", true); + s._sendOfflinePacketAfterOnline = j.value("sendOfflinePacketAfterOnline", false); + s._markReadAfterAction = j.value("markReadAfterAction", true); + s._useScheduledMessages = j.value("useScheduledMessages", false); + s._sendWithoutSound = j.value("sendWithoutSound", false); + s._sendReadMessagesLocked = j.value("sendReadMessagesLocked", false); + s._sendReadStoriesLocked = j.value("sendReadStoriesLocked", false); + s._sendOnlinePacketsLocked = j.value("sendOnlinePacketsLocked", false); + s._sendUploadProgressLocked = j.value("sendUploadProgressLocked", false); + s._sendOfflinePacketAfterOnlineLocked = j.value("sendOfflinePacketAfterOnlineLocked", false); +} + +AyuSettings::AyuSettings() +: _appIcon(AyuAssets::DEFAULT_ICON) +, _editedMark(Core::IsAppLaunched() ? tr::lng_edited(tr::now) : QString("edited")) { +} + +AyuSettings &AyuSettings::getInstance() { + static AyuSettings instance; + return instance; +} + +void AyuSettings::load() { std::ifstream file(getSettingsPath()); if (!file.good()) { return; } - initialize(); + auto &settings = getInstance(); try { json p; file >> p; file.close(); + if (!p.contains("ghostModeSettings")) { + p["ghostModeSettings"] = nlohmann::json::object({ + {"0", { + {"sendReadMessages", p.value("sendReadMessages", true)}, + {"sendReadStories", p.value("sendReadStories", true)}, + {"sendOnlinePackets", p.value("sendOnlinePackets", true)}, + {"sendUploadProgress", p.value("sendUploadProgress", true)}, + {"sendOfflinePacketAfterOnline", p.value("sendOfflinePacketAfterOnline", false)}, + {"markReadAfterAction", p.value("markReadAfterAction", true)}, + {"useScheduledMessages", p.value("useScheduledMessages", false)}, + {"sendWithoutSound", p.value("sendWithoutSound", false)} + }} + }); + p["useGlobalGhostMode"] = true; + + LOG(("AyuGramSettings: migrated ghost mode settings to per-account format")); + } + try { - settings = p.get(); + from_json(p, settings); } catch (...) { LOG(("AyuGramSettings: failed to parse settings file")); } @@ -180,564 +236,733 @@ void load() { } if (cGhost()) { - settings->sendReadMessages = false; - settings->sendReadStories = false; - settings->sendOnlinePackets = false; - settings->sendUploadProgress = false; - settings->sendOfflinePacketAfterOnline = true; + auto &ghost = AyuSettings::ghost(); + ghost._sendReadMessages = false; + ghost._sendReadStories = false; + ghost._sendOnlinePackets = false; + ghost._sendUploadProgress = false; + ghost._sendOfflinePacketAfterOnline = true; } - postinitialize(); + settings.validate(); } -void save() { - initialize(); - - json p = settings.value(); +void AyuSettings::save() { + auto &settings = getInstance(); + json p = settings; std::ofstream file; file.open(getSettingsPath()); file << p.dump(4); file.close(); - - postinitialize(); } -void reset() { - lifetime.destroy(); - lifetime = rpl::lifetime(); - settings = std::nullopt; - initialize(); - postinitialize(); +void AyuSettings::reset() { + getInstance() = AyuSettings(); save(); } -AyuGramSettings::AyuGramSettings() { - // ~ Ghost essentials - sendReadMessages = true; - sendReadStories = true; - sendOnlinePackets = true; - sendUploadProgress = true; - sendOfflinePacketAfterOnline = false; - - markReadAfterAction = true; - useScheduledMessages = false; - sendWithoutSound = false; - - // ~ Message edits & deletion history - saveDeletedMessages = true; - saveMessagesHistory = true; - - saveForBots = false; - - // ~ Message filters - filtersEnabled = false; - filtersEnabledInChats = false; - hideFromBlocked = false; - - // ~ QoL toggles - disableAds = true; - disableStories = false; - disableCustomBackgrounds = true; - showOnlyAddedEmojisAndStickers = false; - collapseSimilarChannels = true; - hideSimilarChannels = false; - - wideMultiplier = 1.0; - - spoofWebviewAsAndroid = false; - increaseWebviewHeight = false; - increaseWebviewWidth = false; - - materialSwitches = true; - removeMessageTail = false; - - disableNotificationsDelay = false; - localPremium = false; - showChannelReactions = true; - showGroupReactions = true; - - // ~ Customization - appIcon = AyuAssets::DEFAULT_ICON; - simpleQuotesAndReplies = false; - hideFastShare = false; - replaceBottomInfoWithIcons = true; - deletedMark = "🧹"; - editedMark = Core::IsAppLaunched() ? tr::lng_edited(tr::now) : QString("edited"); - recentStickersCount = 100; - - // context menu items - // 0 - hide - // 1 - show normally - // 2 - show with SHIFT or CTRL pressed - showReactionsPanelInContextMenu = 1; - showViewsPanelInContextMenu = 1; - showHideMessageInContextMenu = 0; - showUserMessagesInContextMenu = 2; - showMessageDetailsInContextMenu = 2; - showRepeatMessageInContextMenu = 0; - showAddFilterInContextMenu = 1; - - showAttachButtonInMessageField = true; - showCommandsButtonInMessageField = true; - showEmojiButtonInMessageField = true; - showMicrophoneButtonInMessageField = true; - showAutoDeleteButtonInMessageField = true; - - showAttachPopup = true; - showEmojiPopup = true; - - // ~ Drawer Elements - showMyProfileInDrawer = true; - showBotsInDrawer = true; - showNewGroupInDrawer = true; - showNewChannelInDrawer = true; - showContactsInDrawer = true; - showCallsInDrawer = true; - showSavedMessagesInDrawer = true; - showLReadToggleInDrawer = false; - showSReadToggleInDrawer = true; - showNightModeToggleInDrawer = true; - showGhostToggleInDrawer = true; - showStreamerToggleInDrawer = false; - - showGhostToggleInTray = true; - showStreamerToggleInTray = false; - - monoFont = ""; - - hideNotificationCounters = false; - hideNotificationBadge = false; - hideAllChatsFolder = false; - - /* - * channelBottomButton = 0 means "Hide" - * channelBottomButton = 1 means "Mute"/"Unmute" - * channelBottomButton = 2 means "Discuss" + fallback to "Mute"/"Unmute" - */ - channelBottomButton = 2; - quickAdminShortcuts = true; - - /* - * 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; - showMessageShot = true; - - filterZalgo = true; - - // ~ Confirmations - stickerConfirmation = false; - gifConfirmation = false; - voiceConfirmation = false; - - translationProvider = "telegram"; // telegram, google, yandex - - adaptiveCoverColor = true; - - crashReporting = true; +GhostModeAccountSettings &AyuSettings::ghost(not_null session) { + return ghost(session->userId().bare); } -void set_sendReadMessages(bool val) { - settings->sendReadMessages = val; - sendReadMessagesReactive = val; +GhostModeAccountSettings &AyuSettings::ghost(uint64 userId) { + auto &settings = getInstance(); + auto overriddenId = settings.getOverriddenGhostUserId(userId); + + auto it = settings._ghostAccounts.find(overriddenId); + if (it == settings._ghostAccounts.end()) { + auto account = std::make_unique(); + it = settings._ghostAccounts.emplace(overriddenId, std::move(account)).first; + } + + return *it->second; } -void set_sendReadStories(bool val) { - settings->sendReadStories = val; - sendReadStoriesReactive = val; -} - -void set_sendOnlinePackets(bool val) { - settings->sendOnlinePackets = val; - sendOnlinePacketsReactive = val; -} - -void set_sendUploadProgress(bool val) { - settings->sendUploadProgress = val; - sendUploadProgressReactive = val; -} - -void set_sendOfflinePacketAfterOnline(bool val) { - settings->sendOfflinePacketAfterOnline = val; - sendOfflinePacketAfterOnlineReactive = val; -} - -void set_ghostModeEnabled(bool val) { - set_sendReadMessages(!val); - set_sendReadStories(!val); - set_sendOnlinePackets(!val); - set_sendUploadProgress(!val); - set_sendOfflinePacketAfterOnline(val); - +GhostModeAccountSettings &AyuSettings::ghost() { if (const auto window = Core::App().activeWindow()) { if (const auto session = window->maybeSession()) { - AyuWorker::markAsOnline(session); // mark as online to get offline instantly + return ghost(session); } } + return ghost(0); +} + +void AyuSettings::setUseGlobalGhostMode(bool val) { + if (_useGlobalGhostMode.current() == val) return; + _useGlobalGhostMode = val; + save(); +} + +void AyuSettings::addShadowBan(int64 id) { + if (_shadowBanIds.insert(id).second) { + FiltersCacheController::rebuildCache(); + FiltersCacheController::fireUpdate(); + save(); + } } -void set_markReadAfterAction(bool val) { - settings->markReadAfterAction = val; +void AyuSettings::removeShadowBan(int64 id) { + if (_shadowBanIds.erase(id) > 0) { + FiltersCacheController::rebuildCache(); + FiltersCacheController::fireUpdate(); + save(); + } } -void set_useScheduledMessages(bool val) { - settings->useScheduledMessages = val; -} +void AyuSettings::validate() { + AyuSettings defaults; + auto modified = false; + + auto validateRange = [&](auto &var, auto min, auto max, const auto &defaultVar) { + if (var.current() < min || var.current() > max) { + var = defaultVar.current(); + modified = true; + } + }; + + auto validateEnum = [&](auto &var, const auto &defaultVar) { + auto intVal = static_cast(var.current()); + if (intVal < 0 || intVal > 2) { + var = defaultVar.current(); + modified = true; + } + }; + + validateEnum(_showPeerId, defaults._showPeerId); + validateEnum(_channelBottomButton, defaults._channelBottomButton); + validateEnum(_showReactionsPanelInContextMenu, defaults._showReactionsPanelInContextMenu); + validateEnum(_showViewsPanelInContextMenu, defaults._showViewsPanelInContextMenu); + validateEnum(_showHideMessageInContextMenu, defaults._showHideMessageInContextMenu); + validateEnum(_showUserMessagesInContextMenu, defaults._showUserMessagesInContextMenu); + validateEnum(_showMessageDetailsInContextMenu, defaults._showMessageDetailsInContextMenu); + validateEnum(_showRepeatMessageInContextMenu, defaults._showRepeatMessageInContextMenu); + validateEnum(_showAddFilterInContextMenu, defaults._showAddFilterInContextMenu); + + const auto &provider = _translationProvider.current(); + if (provider != "telegram" && provider != "google" && provider != "yandex") { + _translationProvider = defaults._translationProvider.current(); + modified = true; + } + + validateRange(_wideMultiplier, 0.5, 3.0, defaults._wideMultiplier); + validateRange(_recentStickersCount, 1, 200, defaults._recentStickersCount); -void set_sendWithoutSound(bool val) { - settings->sendWithoutSound = val; + if (modified) { + save(); + } } -void set_saveDeletedMessages(bool val) { - settings->saveDeletedMessages = val; +void AyuSettings::setSaveDeletedMessages(bool val) { + if (_saveDeletedMessages.current() == val) return; + _saveDeletedMessages = val; + save(); } -void set_saveMessagesHistory(bool val) { - settings->saveMessagesHistory = val; +void AyuSettings::setSaveMessagesHistory(bool val) { + if (_saveMessagesHistory.current() == val) return; + _saveMessagesHistory = val; + save(); } -void set_saveForBots(bool val) { - settings->saveForBots = val; +void AyuSettings::setSaveForBots(bool val) { + if (_saveForBots.current() == val) return; + _saveForBots = val; + save(); } -void set_filtersEnabled(bool val) { - settings->filtersEnabled = val; +void AyuSettings::setFiltersEnabled(bool val) { + if (_filtersEnabled.current() == val) return; + _filtersEnabled = val; + save(); } -void set_filtersEnabledInChats(bool val) { - settings->filtersEnabledInChats = val; +void AyuSettings::setFiltersEnabledInChats(bool val) { + if (_filtersEnabledInChats.current() == val) return; + _filtersEnabledInChats = val; + save(); } -void set_hideFromBlocked(bool val) { - settings->hideFromBlocked = val; +void AyuSettings::setHideFromBlocked(bool val) { + if (_hideFromBlocked.current() == val) return; + _hideFromBlocked = val; + save(); } -void set_disableAds(bool val) { - settings->disableAds = val; +void AyuSettings::setDisableAds(bool val) { + if (_disableAds.current() == val) return; + _disableAds = val; + save(); } -void set_disableStories(bool val) { - settings->disableStories = val; +void AyuSettings::setDisableStories(bool val) { + if (_disableStories.current() == val) return; + _disableStories = val; + save(); } -void set_disableCustomBackgrounds(bool val) { - settings->disableCustomBackgrounds = val; +void AyuSettings::setDisableCustomBackgrounds(bool val) { + if (_disableCustomBackgrounds.current() == val) return; + _disableCustomBackgrounds = val; + save(); } -void set_showOnlyAddedEmojisAndStickers(bool val) { - settings->showOnlyAddedEmojisAndStickers = val; +void AyuSettings::setShowOnlyAddedEmojisAndStickers(bool val) { + if (_showOnlyAddedEmojisAndStickers.current() == val) return; + _showOnlyAddedEmojisAndStickers = val; + save(); } -void set_collapseSimilarChannels(bool val) { - settings->collapseSimilarChannels = val; +void AyuSettings::setCollapseSimilarChannels(bool val) { + if (_collapseSimilarChannels.current() == val) return; + _collapseSimilarChannels = val; + save(); } -void set_hideSimilarChannels(bool val) { - settings->hideSimilarChannels = val; +void AyuSettings::setHideSimilarChannels(bool val) { + if (_hideSimilarChannels.current() == val) return; + _hideSimilarChannels = val; + save(); } -void set_wideMultiplier(double val) { - settings->wideMultiplier = val; +void AyuSettings::setWideMultiplier(double val) { + if (_wideMultiplier.current() == val) return; + _wideMultiplier = val; + save(); } -void set_spoofWebviewAsAndroid(bool val) { - settings->spoofWebviewAsAndroid = val; +void AyuSettings::setSpoofWebviewAsAndroid(bool val) { + if (_spoofWebviewAsAndroid.current() == val) return; + _spoofWebviewAsAndroid = val; + save(); } -void set_increaseWebviewHeight(bool val) { - settings->increaseWebviewHeight = val; +void AyuSettings::setIncreaseWebviewHeight(bool val) { + if (_increaseWebviewHeight.current() == val) return; + _increaseWebviewHeight = val; + save(); } -void set_increaseWebviewWidth(bool val) { - settings->increaseWebviewWidth = val; +void AyuSettings::setIncreaseWebviewWidth(bool val) { + if (_increaseWebviewWidth.current() == val) return; + _increaseWebviewWidth = val; + save(); } -void set_materialSwitches(bool val) { - settings->materialSwitches = val; +void AyuSettings::setMaterialSwitches(bool val) { + if (_materialSwitches.current() == val) return; + _materialSwitches = val; + save(); } -void set_removeMessageTail(bool val) { - settings->removeMessageTail = val; +void AyuSettings::setRemoveMessageTail(bool val) { + if (_removeMessageTail.current() == val) return; + _removeMessageTail = val; + save(); } -void set_disableNotificationsDelay(bool val) { - settings->disableNotificationsDelay = val; +void AyuSettings::setDisableNotificationsDelay(bool val) { + if (_disableNotificationsDelay.current() == val) return; + _disableNotificationsDelay = val; + save(); } -void set_localPremium(bool val) { - settings->localPremium = val; +void AyuSettings::setLocalPremium(bool val) { + if (_localPremium.current() == val) return; + _localPremium = val; + save(); } -void set_hideChannelReactions(bool val) { - settings->showChannelReactions = val; +void AyuSettings::setShowChannelReactions(bool val) { + if (_showChannelReactions.current() == val) return; + _showChannelReactions = val; + save(); } -void set_hideGroupReactions(bool val) { - settings->showGroupReactions = val; +void AyuSettings::setShowGroupReactions(bool val) { + if (_showGroupReactions.current() == val) return; + _showGroupReactions = val; + save(); } -void set_appIcon(const QString &val) { - settings->appIcon = val; +void AyuSettings::setAppIcon(const QString &val) { + if (_appIcon.current() == val) return; + _appIcon = val; + save(); } -void set_simpleQuotesAndReplies(bool val) { - settings->simpleQuotesAndReplies = val; +void AyuSettings::setSimpleQuotesAndReplies(bool val) { + if (_simpleQuotesAndReplies.current() == val) return; + _simpleQuotesAndReplies = val; + save(); } -void set_hideFastShare(bool val) { - settings->hideFastShare = val; +void AyuSettings::setHideFastShare(bool val) { + if (_hideFastShare.current() == val) return; + _hideFastShare = val; + save(); } -void set_replaceBottomInfoWithIcons(bool val) { - settings->replaceBottomInfoWithIcons = val; +void AyuSettings::setReplaceBottomInfoWithIcons(bool val) { + if (_replaceBottomInfoWithIcons.current() == val) return; + _replaceBottomInfoWithIcons = val; + save(); } -void set_deletedMark(const QString &val) { - settings->deletedMark = val; - deletedMarkReactive = settings->deletedMark; +void AyuSettings::setDeletedMark(const QString &val) { + if (_deletedMark.current() == val) return; + _deletedMark = val; + save(); } -void set_editedMark(const QString &val) { - settings->editedMark = val; - editedMarkReactive = settings->editedMark; +void AyuSettings::setEditedMark(const QString &val) { + if (_editedMark.current() == val) return; + _editedMark = val; + save(); } -void set_recentStickersCount(int val) { - settings->recentStickersCount = val; +void AyuSettings::setRecentStickersCount(int val) { + if (_recentStickersCount.current() == val) return; + _recentStickersCount = val; + save(); } -void set_showReactionsPanelInContextMenu(int val) { - settings->showReactionsPanelInContextMenu = val; +void AyuSettings::setShowReactionsPanelInContextMenu(ContextMenuVisibility val) { + if (_showReactionsPanelInContextMenu.current() == val) return; + _showReactionsPanelInContextMenu = val; + save(); } -void set_showViewsPanelInContextMenu(int val) { - settings->showViewsPanelInContextMenu = val; +void AyuSettings::setShowViewsPanelInContextMenu(ContextMenuVisibility val) { + if (_showViewsPanelInContextMenu.current() == val) return; + _showViewsPanelInContextMenu = val; + save(); } -void set_showHideMessageInContextMenu(int val) { - settings->showHideMessageInContextMenu = val; +void AyuSettings::setShowHideMessageInContextMenu(ContextMenuVisibility val) { + if (_showHideMessageInContextMenu.current() == val) return; + _showHideMessageInContextMenu = val; + save(); } -void set_showUserMessagesInContextMenu(int val) { - settings->showUserMessagesInContextMenu = val; +void AyuSettings::setShowUserMessagesInContextMenu(ContextMenuVisibility val) { + if (_showUserMessagesInContextMenu.current() == val) return; + _showUserMessagesInContextMenu = val; + save(); } -void set_showMessageDetailsInContextMenu(int val) { - settings->showMessageDetailsInContextMenu = val; +void AyuSettings::setShowMessageDetailsInContextMenu(ContextMenuVisibility val) { + if (_showMessageDetailsInContextMenu.current() == val) return; + _showMessageDetailsInContextMenu = val; + save(); } -void set_showRepeatMessageInContextMenu(int val) { - settings->showRepeatMessageInContextMenu = val; +void AyuSettings::setShowRepeatMessageInContextMenu(ContextMenuVisibility val) { + if (_showRepeatMessageInContextMenu.current() == val) return; + _showRepeatMessageInContextMenu = val; + save(); } -void set_showAddFilterInContextMenu(int val) { - settings->showAddFilterInContextMenu = val; +void AyuSettings::setShowAddFilterInContextMenu(ContextMenuVisibility val) { + if (_showAddFilterInContextMenu.current() == val) return; + _showAddFilterInContextMenu = val; + save(); } -void set_showAttachButtonInMessageField(bool val) { - settings->showAttachButtonInMessageField = val; - triggerHistoryUpdate(); +void AyuSettings::setShowAttachButtonInMessageField(bool val) { + if (_showAttachButtonInMessageField.current() == val) return; + _showAttachButtonInMessageField = val; + save(); } -void set_showCommandsButtonInMessageField(bool val) { - settings->showCommandsButtonInMessageField = val; - triggerHistoryUpdate(); +void AyuSettings::setShowCommandsButtonInMessageField(bool val) { + if (_showCommandsButtonInMessageField.current() == val) return; + _showCommandsButtonInMessageField = val; + save(); } -void set_showEmojiButtonInMessageField(bool val) { - settings->showEmojiButtonInMessageField = val; - triggerHistoryUpdate(); +void AyuSettings::setShowEmojiButtonInMessageField(bool val) { + if (_showEmojiButtonInMessageField.current() == val) return; + _showEmojiButtonInMessageField = val; + save(); } -void set_showMicrophoneButtonInMessageField(bool val) { - settings->showMicrophoneButtonInMessageField = val; - triggerHistoryUpdate(); +void AyuSettings::setShowMicrophoneButtonInMessageField(bool val) { + if (_showMicrophoneButtonInMessageField.current() == val) return; + _showMicrophoneButtonInMessageField = val; + save(); } -void set_showAutoDeleteButtonInMessageField(bool val) { - settings->showAutoDeleteButtonInMessageField = val; - triggerHistoryUpdate(); +void AyuSettings::setShowAutoDeleteButtonInMessageField(bool val) { + if (_showAutoDeleteButtonInMessageField.current() == val) return; + _showAutoDeleteButtonInMessageField = val; + save(); } -void set_showAttachPopup(bool val) { - settings->showAttachPopup = val; - triggerHistoryUpdate(); +void AyuSettings::setShowAttachPopup(bool val) { + if (_showAttachPopup.current() == val) return; + _showAttachPopup = val; + save(); } -void set_showEmojiPopup(bool val) { - settings->showEmojiPopup = val; - triggerHistoryUpdate(); +void AyuSettings::setShowEmojiPopup(bool val) { + if (_showEmojiPopup.current() == val) return; + _showEmojiPopup = val; + save(); } -void set_showMyProfileInDrawer(bool val) { - settings->showMyProfileInDrawer = val; +void AyuSettings::setShowMyProfileInDrawer(bool val) { + if (_showMyProfileInDrawer.current() == val) return; + _showMyProfileInDrawer = val; + save(); } -void set_showBotsInDrawer(bool val) { - settings->showBotsInDrawer = val; +void AyuSettings::setShowBotsInDrawer(bool val) { + if (_showBotsInDrawer.current() == val) return; + _showBotsInDrawer = val; + save(); } -void set_showNewGroupInDrawer(bool val) { - settings->showNewGroupInDrawer = val; +void AyuSettings::setShowNewGroupInDrawer(bool val) { + if (_showNewGroupInDrawer.current() == val) return; + _showNewGroupInDrawer = val; + save(); } -void set_showNewChannelInDrawer(bool val) { - settings->showNewChannelInDrawer = val; +void AyuSettings::setShowNewChannelInDrawer(bool val) { + if (_showNewChannelInDrawer.current() == val) return; + _showNewChannelInDrawer = val; + save(); } -void set_showContactsInDrawer(bool val) { - settings->showContactsInDrawer = val; +void AyuSettings::setShowContactsInDrawer(bool val) { + if (_showContactsInDrawer.current() == val) return; + _showContactsInDrawer = val; + save(); } -void set_showCallsInDrawer(bool val) { - settings->showCallsInDrawer = val; +void AyuSettings::setShowCallsInDrawer(bool val) { + if (_showCallsInDrawer.current() == val) return; + _showCallsInDrawer = val; + save(); } -void set_showSavedMessagesInDrawer(bool val) { - settings->showSavedMessagesInDrawer = val; +void AyuSettings::setShowSavedMessagesInDrawer(bool val) { + if (_showSavedMessagesInDrawer.current() == val) return; + _showSavedMessagesInDrawer = val; + save(); } -void set_showLReadToggleInDrawer(bool val) { - settings->showLReadToggleInDrawer = val; +void AyuSettings::setShowLReadToggleInDrawer(bool val) { + if (_showLReadToggleInDrawer.current() == val) return; + _showLReadToggleInDrawer = val; + save(); } -void set_showSReadToggleInDrawer(bool val) { - settings->showSReadToggleInDrawer = val; +void AyuSettings::setShowSReadToggleInDrawer(bool val) { + if (_showSReadToggleInDrawer.current() == val) return; + _showSReadToggleInDrawer = val; + save(); } -void set_showNightModeToggleInDrawer(bool val) { - settings->showNightModeToggleInDrawer = val; +void AyuSettings::setShowNightModeToggleInDrawer(bool val) { + if (_showNightModeToggleInDrawer.current() == val) return; + _showNightModeToggleInDrawer = val; + save(); } -void set_showGhostToggleInDrawer(bool val) { - settings->showGhostToggleInDrawer = val; +void AyuSettings::setShowGhostToggleInDrawer(bool val) { + if (_showGhostToggleInDrawer.current() == val) return; + _showGhostToggleInDrawer = val; + save(); } -void set_showStreamerToggleInDrawer(bool val) { - settings->showStreamerToggleInDrawer = val; +void AyuSettings::setShowStreamerToggleInDrawer(bool val) { + if (_showStreamerToggleInDrawer.current() == val) return; + _showStreamerToggleInDrawer = val; + save(); } -void set_showGhostToggleInTray(bool val) { - settings->showGhostToggleInTray = val; +void AyuSettings::setShowGhostToggleInTray(bool val) { + if (_showGhostToggleInTray.current() == val) return; + _showGhostToggleInTray = val; + save(); } -void set_showStreamerToggleInTray(bool val) { - settings->showStreamerToggleInTray = val; +void AyuSettings::setShowStreamerToggleInTray(bool val) { + if (_showStreamerToggleInTray.current() == val) return; + _showStreamerToggleInTray = val; + save(); } -void set_monoFont(const QString &val) { - settings->monoFont = val; +void AyuSettings::setMonoFont(const QString &val) { + if (_monoFont.current() == val) return; + _monoFont = val; + save(); } -void set_showPeerId(int val) { - settings->showPeerId = val; - showPeerIdReactive = val; +void AyuSettings::setHideNotificationCounters(bool val) { + if (_hideNotificationCounters.current() == val) return; + _hideNotificationCounters = val; + save(); } -void set_hideNotificationCounters(bool val) { - settings->hideNotificationCounters = val; +void AyuSettings::setHideNotificationBadge(bool val) { + if (_hideNotificationBadge.current() == val) return; + _hideNotificationBadge = val; + save(); } -void set_hideNotificationBadge(bool val) { - settings->hideNotificationBadge = val; +void AyuSettings::setHideAllChatsFolder(bool val) { + if (_hideAllChatsFolder.current() == val) return; + _hideAllChatsFolder = val; + save(); } -void set_hideAllChatsFolder(bool val) { - settings->hideAllChatsFolder = val; +void AyuSettings::setChannelBottomButton(ChannelBottomButton val) { + if (_channelBottomButton.current() == val) return; + _channelBottomButton = val; + save(); } -void set_channelBottomButton(int val) { - settings->channelBottomButton = val; +void AyuSettings::setQuickAdminShortcuts(bool val) { + if (_quickAdminShortcuts.current() == val) return; + _quickAdminShortcuts = val; + save(); } -void set_quickAdminShortcuts(bool val) { - settings->quickAdminShortcuts = val; +void AyuSettings::setShowPeerId(PeerIdDisplay val) { + if (_showPeerId.current() == val) return; + _showPeerId = val; + save(); } -void set_showMessageSeconds(bool val) { - settings->showMessageSeconds = val; +void AyuSettings::setShowMessageSeconds(bool val) { + if (_showMessageSeconds.current() == val) return; + _showMessageSeconds = val; + save(); } -void set_showMessageShot(bool val) { - settings->showMessageShot = val; +void AyuSettings::setShowMessageShot(bool val) { + if (_showMessageShot.current() == val) return; + _showMessageShot = val; + save(); } -void set_filterZalgo(bool val) { - settings->filterZalgo = val; +void AyuSettings::setFilterZalgo(bool val) { + if (_filterZalgo.current() == val) return; + _filterZalgo = val; + save(); } -void set_stickerConfirmation(bool val) { - settings->stickerConfirmation = val; +void AyuSettings::setStickerConfirmation(bool val) { + if (_stickerConfirmation.current() == val) return; + _stickerConfirmation = val; + save(); } -void set_gifConfirmation(bool val) { - settings->gifConfirmation = val; +void AyuSettings::setGifConfirmation(bool val) { + if (_gifConfirmation.current() == val) return; + _gifConfirmation = val; + save(); } -void set_voiceConfirmation(bool val) { - settings->voiceConfirmation = val; +void AyuSettings::setVoiceConfirmation(bool val) { + if (_voiceConfirmation.current() == val) return; + _voiceConfirmation = val; + save(); } -void set_translationProvider(const QString &val) { - settings->translationProvider = val; - translationProviderReactive = val; +void AyuSettings::setTranslationProvider(const QString &val) { + if (_translationProvider.current() == val) return; + _translationProvider = val; Ayu::Translator::TranslateManager::currentInstance()->resetCache(); + save(); } -void set_adaptiveCoverColor(bool val) { - settings->adaptiveCoverColor = val; +void AyuSettings::setAdaptiveCoverColor(bool val) { + if (_adaptiveCoverColor.current() == val) return; + _adaptiveCoverColor = val; + save(); } -void set_crashReporting(bool val) { - settings->crashReporting = val; +void AyuSettings::setCrashReporting(bool val) { + if (_crashReporting.current() == val) return; + _crashReporting = val; + save(); } -bool isUseScheduledMessages() { - return isGhostModeActive() && settings->useScheduledMessages; +void to_json(nlohmann::json &j, const AyuSettings &s) { + std::map ghostAccounts; + for (const auto &[key, value] : s._ghostAccounts) { + ghostAccounts[std::to_string(key)] = std::move(*value); + } + + j = nlohmann::json{ + {"ghostModeSettings", ghostAccounts}, + {"useGlobalGhostMode", s._useGlobalGhostMode.current()}, + {"saveDeletedMessages", s._saveDeletedMessages.current()}, + {"saveMessagesHistory", s._saveMessagesHistory.current()}, + {"saveForBots", s._saveForBots.current()}, + {"shadowBanIds", s._shadowBanIds}, + {"filtersEnabled", s._filtersEnabled.current()}, + {"filtersEnabledInChats", s._filtersEnabledInChats.current()}, + {"hideFromBlocked", s._hideFromBlocked.current()}, + {"disableAds", s._disableAds.current()}, + {"disableStories", s._disableStories.current()}, + {"disableCustomBackgrounds", s._disableCustomBackgrounds.current()}, + {"showOnlyAddedEmojisAndStickers", s._showOnlyAddedEmojisAndStickers.current()}, + {"collapseSimilarChannels", s._collapseSimilarChannels.current()}, + {"hideSimilarChannels", s._hideSimilarChannels.current()}, + {"wideMultiplier", s._wideMultiplier.current()}, + {"spoofWebviewAsAndroid", s._spoofWebviewAsAndroid.current()}, + {"increaseWebviewHeight", s._increaseWebviewHeight.current()}, + {"increaseWebviewWidth", s._increaseWebviewWidth.current()}, + {"materialSwitches", s._materialSwitches.current()}, + {"removeMessageTail", s._removeMessageTail.current()}, + {"disableNotificationsDelay", s._disableNotificationsDelay.current()}, + {"localPremium", s._localPremium.current()}, + {"showChannelReactions", s._showChannelReactions.current()}, + {"showGroupReactions", s._showGroupReactions.current()}, + {"appIcon", s._appIcon.current()}, + {"simpleQuotesAndReplies", s._simpleQuotesAndReplies.current()}, + {"hideFastShare", s._hideFastShare.current()}, + {"replaceBottomInfoWithIcons", s._replaceBottomInfoWithIcons.current()}, + {"deletedMark", s._deletedMark.current()}, + {"editedMark", s._editedMark.current()}, + {"recentStickersCount", s._recentStickersCount.current()}, + {"showReactionsPanelInContextMenu", s._showReactionsPanelInContextMenu.current()}, + {"showViewsPanelInContextMenu", s._showViewsPanelInContextMenu.current()}, + {"showHideMessageInContextMenu", s._showHideMessageInContextMenu.current()}, + {"showUserMessagesInContextMenu", s._showUserMessagesInContextMenu.current()}, + {"showMessageDetailsInContextMenu", s._showMessageDetailsInContextMenu.current()}, + {"showRepeatMessageInContextMenu", s._showRepeatMessageInContextMenu.current()}, + {"showAddFilterInContextMenu", s._showAddFilterInContextMenu.current()}, + {"showAttachButtonInMessageField", s._showAttachButtonInMessageField.current()}, + {"showCommandsButtonInMessageField", s._showCommandsButtonInMessageField.current()}, + {"showEmojiButtonInMessageField", s._showEmojiButtonInMessageField.current()}, + {"showMicrophoneButtonInMessageField", s._showMicrophoneButtonInMessageField.current()}, + {"showAutoDeleteButtonInMessageField", s._showAutoDeleteButtonInMessageField.current()}, + {"showAttachPopup", s._showAttachPopup.current()}, + {"showEmojiPopup", s._showEmojiPopup.current()}, + {"showMyProfileInDrawer", s._showMyProfileInDrawer.current()}, + {"showBotsInDrawer", s._showBotsInDrawer.current()}, + {"showNewGroupInDrawer", s._showNewGroupInDrawer.current()}, + {"showNewChannelInDrawer", s._showNewChannelInDrawer.current()}, + {"showContactsInDrawer", s._showContactsInDrawer.current()}, + {"showCallsInDrawer", s._showCallsInDrawer.current()}, + {"showSavedMessagesInDrawer", s._showSavedMessagesInDrawer.current()}, + {"showLReadToggleInDrawer", s._showLReadToggleInDrawer.current()}, + {"showSReadToggleInDrawer", s._showSReadToggleInDrawer.current()}, + {"showNightModeToggleInDrawer", s._showNightModeToggleInDrawer.current()}, + {"showGhostToggleInDrawer", s._showGhostToggleInDrawer.current()}, + {"showStreamerToggleInDrawer", s._showStreamerToggleInDrawer.current()}, + {"showGhostToggleInTray", s._showGhostToggleInTray.current()}, + {"showStreamerToggleInTray", s._showStreamerToggleInTray.current()}, + {"monoFont", s._monoFont.current()}, + {"hideNotificationCounters", s._hideNotificationCounters.current()}, + {"hideNotificationBadge", s._hideNotificationBadge.current()}, + {"hideAllChatsFolder", s._hideAllChatsFolder.current()}, + {"channelBottomButton", s._channelBottomButton.current()}, + {"quickAdminShortcuts", s._quickAdminShortcuts.current()}, + {"showPeerId", s._showPeerId.current()}, + {"showMessageSeconds", s._showMessageSeconds.current()}, + {"showMessageShot", s._showMessageShot.current()}, + {"filterZalgo", s._filterZalgo.current()}, + {"stickerConfirmation", s._stickerConfirmation.current()}, + {"gifConfirmation", s._gifConfirmation.current()}, + {"voiceConfirmation", s._voiceConfirmation.current()}, + {"translationProvider", s._translationProvider.current()}, + {"adaptiveCoverColor", s._adaptiveCoverColor.current()}, + {"crashReporting", s._crashReporting.current()} + }; } -bool isGhostModeActive() { - return ghostModeEnabled.current(); -} +void from_json(const nlohmann::json &j, AyuSettings &s) { + AyuSettings defaults; -rpl::producer get_deletedMarkReactive() { - return deletedMarkReactive.value(); -} - -rpl::producer get_editedMarkReactive() { - return editedMarkReactive.value(); -} - -rpl::producer get_showPeerIdReactive() { - return showPeerIdReactive.value(); -} - -rpl::producer get_translationProviderReactive() { - return translationProviderReactive.value(); -} - -rpl::producer get_ghostModeEnabledReactive() { - return ghostModeEnabled.value(); -} - -void fire_filtersUpdate() { - filtersUpdateReactive.fire({}); -} - -rpl::producer<> get_filtersUpdate() { - return filtersUpdateReactive.events(); -} - -void triggerHistoryUpdate() { - historyUpdateReactive.fire({}); -} - -rpl::producer<> get_historyUpdateReactive() { - return historyUpdateReactive.events(); -} + if (j.contains("ghostModeSettings") && j["ghostModeSettings"].is_object()) { + s._ghostAccounts.clear(); + for (auto &[key, value] : j["ghostModeSettings"].items()) { + auto account = std::make_unique(); + value.get_to(*account); + s._ghostAccounts[std::stoull(key)] = std::move(account); + } + } + s._useGlobalGhostMode = j.value("useGlobalGhostMode", defaults._useGlobalGhostMode.current()); + s._saveDeletedMessages = j.value("saveDeletedMessages", defaults._saveDeletedMessages.current()); + s._saveMessagesHistory = j.value("saveMessagesHistory", defaults._saveMessagesHistory.current()); + s._saveForBots = j.value("saveForBots", defaults._saveForBots.current()); + s._shadowBanIds = j.value("shadowBanIds", defaults._shadowBanIds); + s._filtersEnabled = j.value("filtersEnabled", defaults._filtersEnabled.current()); + s._filtersEnabledInChats = j.value("filtersEnabledInChats", defaults._filtersEnabledInChats.current()); + s._hideFromBlocked = j.value("hideFromBlocked", defaults._hideFromBlocked.current()); + s._disableAds = j.value("disableAds", defaults._disableAds.current()); + s._disableStories = j.value("disableStories", defaults._disableStories.current()); + s._disableCustomBackgrounds = j.value("disableCustomBackgrounds", defaults._disableCustomBackgrounds.current()); + s._showOnlyAddedEmojisAndStickers = j.value("showOnlyAddedEmojisAndStickers", defaults._showOnlyAddedEmojisAndStickers.current()); + s._collapseSimilarChannels = j.value("collapseSimilarChannels", defaults._collapseSimilarChannels.current()); + s._hideSimilarChannels = j.value("hideSimilarChannels", defaults._hideSimilarChannels.current()); + s._wideMultiplier = j.value("wideMultiplier", defaults._wideMultiplier.current()); + s._spoofWebviewAsAndroid = j.value("spoofWebviewAsAndroid", defaults._spoofWebviewAsAndroid.current()); + s._increaseWebviewHeight = j.value("increaseWebviewHeight", defaults._increaseWebviewHeight.current()); + s._increaseWebviewWidth = j.value("increaseWebviewWidth", defaults._increaseWebviewWidth.current()); + s._materialSwitches = j.value("materialSwitches", defaults._materialSwitches.current()); + s._removeMessageTail = j.value("removeMessageTail", defaults._removeMessageTail.current()); + s._disableNotificationsDelay = j.value("disableNotificationsDelay", defaults._disableNotificationsDelay.current()); + s._localPremium = j.value("localPremium", defaults._localPremium.current()); + s._showChannelReactions = j.value("showChannelReactions", defaults._showChannelReactions.current()); + s._showGroupReactions = j.value("showGroupReactions", defaults._showGroupReactions.current()); + s._appIcon = j.value("appIcon", defaults._appIcon.current()); + s._simpleQuotesAndReplies = j.value("simpleQuotesAndReplies", defaults._simpleQuotesAndReplies.current()); + s._hideFastShare = j.value("hideFastShare", defaults._hideFastShare.current()); + s._replaceBottomInfoWithIcons = j.value("replaceBottomInfoWithIcons", defaults._replaceBottomInfoWithIcons.current()); + s._deletedMark = j.value("deletedMark", defaults._deletedMark.current()); + s._editedMark = j.value("editedMark", defaults._editedMark.current()); + s._recentStickersCount = j.value("recentStickersCount", defaults._recentStickersCount.current()); + s._showReactionsPanelInContextMenu = j.value("showReactionsPanelInContextMenu", defaults._showReactionsPanelInContextMenu.current()); + s._showViewsPanelInContextMenu = j.value("showViewsPanelInContextMenu", defaults._showViewsPanelInContextMenu.current()); + s._showHideMessageInContextMenu = j.value("showHideMessageInContextMenu", defaults._showHideMessageInContextMenu.current()); + s._showUserMessagesInContextMenu = j.value("showUserMessagesInContextMenu", defaults._showUserMessagesInContextMenu.current()); + s._showMessageDetailsInContextMenu = j.value("showMessageDetailsInContextMenu", defaults._showMessageDetailsInContextMenu.current()); + s._showRepeatMessageInContextMenu = j.value("showRepeatMessageInContextMenu", defaults._showRepeatMessageInContextMenu.current()); + s._showAddFilterInContextMenu = j.value("showAddFilterInContextMenu", defaults._showAddFilterInContextMenu.current()); + s._showAttachButtonInMessageField = j.value("showAttachButtonInMessageField", defaults._showAttachButtonInMessageField.current()); + s._showCommandsButtonInMessageField = j.value("showCommandsButtonInMessageField", defaults._showCommandsButtonInMessageField.current()); + s._showEmojiButtonInMessageField = j.value("showEmojiButtonInMessageField", defaults._showEmojiButtonInMessageField.current()); + s._showMicrophoneButtonInMessageField = j.value("showMicrophoneButtonInMessageField", defaults._showMicrophoneButtonInMessageField.current()); + s._showAutoDeleteButtonInMessageField = j.value("showAutoDeleteButtonInMessageField", defaults._showAutoDeleteButtonInMessageField.current()); + s._showAttachPopup = j.value("showAttachPopup", defaults._showAttachPopup.current()); + s._showEmojiPopup = j.value("showEmojiPopup", defaults._showEmojiPopup.current()); + s._showMyProfileInDrawer = j.value("showMyProfileInDrawer", defaults._showMyProfileInDrawer.current()); + s._showBotsInDrawer = j.value("showBotsInDrawer", defaults._showBotsInDrawer.current()); + s._showNewGroupInDrawer = j.value("showNewGroupInDrawer", defaults._showNewGroupInDrawer.current()); + s._showNewChannelInDrawer = j.value("showNewChannelInDrawer", defaults._showNewChannelInDrawer.current()); + s._showContactsInDrawer = j.value("showContactsInDrawer", defaults._showContactsInDrawer.current()); + s._showCallsInDrawer = j.value("showCallsInDrawer", defaults._showCallsInDrawer.current()); + s._showSavedMessagesInDrawer = j.value("showSavedMessagesInDrawer", defaults._showSavedMessagesInDrawer.current()); + s._showLReadToggleInDrawer = j.value("showLReadToggleInDrawer", defaults._showLReadToggleInDrawer.current()); + s._showSReadToggleInDrawer = j.value("showSReadToggleInDrawer", defaults._showSReadToggleInDrawer.current()); + s._showNightModeToggleInDrawer = j.value("showNightModeToggleInDrawer", defaults._showNightModeToggleInDrawer.current()); + s._showGhostToggleInDrawer = j.value("showGhostToggleInDrawer", defaults._showGhostToggleInDrawer.current()); + s._showStreamerToggleInDrawer = j.value("showStreamerToggleInDrawer", defaults._showStreamerToggleInDrawer.current()); + s._showGhostToggleInTray = j.value("showGhostToggleInTray", defaults._showGhostToggleInTray.current()); + s._showStreamerToggleInTray = j.value("showStreamerToggleInTray", defaults._showStreamerToggleInTray.current()); + s._monoFont = j.value("monoFont", defaults._monoFont.current()); + s._hideNotificationCounters = j.value("hideNotificationCounters", defaults._hideNotificationCounters.current()); + s._hideNotificationBadge = j.value("hideNotificationBadge", defaults._hideNotificationBadge.current()); + s._hideAllChatsFolder = j.value("hideAllChatsFolder", defaults._hideAllChatsFolder.current()); + s._channelBottomButton = j.value("channelBottomButton", defaults._channelBottomButton.current()); + s._quickAdminShortcuts = j.value("quickAdminShortcuts", defaults._quickAdminShortcuts.current()); + s._showPeerId = j.value("showPeerId", defaults._showPeerId.current()); + s._showMessageSeconds = j.value("showMessageSeconds", defaults._showMessageSeconds.current()); + s._showMessageShot = j.value("showMessageShot", defaults._showMessageShot.current()); + s._filterZalgo = j.value("filterZalgo", defaults._filterZalgo.current()); + s._stickerConfirmation = j.value("stickerConfirmation", defaults._stickerConfirmation.current()); + s._gifConfirmation = j.value("gifConfirmation", defaults._gifConfirmation.current()); + s._voiceConfirmation = j.value("voiceConfirmation", defaults._voiceConfirmation.current()); + s._translationProvider = j.value("translationProvider", defaults._translationProvider.current()); + s._adaptiveCoverColor = j.value("adaptiveCoverColor", defaults._adaptiveCoverColor.current()); + s._crashReporting = j.value("crashReporting", defaults._crashReporting.current()); } diff --git a/Telegram/SourceFiles/ayu/ayu_settings.h b/Telegram/SourceFiles/ayu/ayu_settings.h index 75734fec69..6983dbfda0 100644 --- a/Telegram/SourceFiles/ayu/ayu_settings.h +++ b/Telegram/SourceFiles/ayu/ayu_settings.h @@ -6,454 +6,470 @@ // Copyright @Radolyn, 2025 #pragma once -#include #include "ayu/libs/json.hpp" #include "ayu/libs/json_ext.hpp" - -// json.hpp in some build environments may not provide helper macros. -// To ensure successful compilation, define them here when missing. -#ifndef NLOHMANN_JSON_TO -#define NLOHMANN_JSON_TO(v1) nlohmann_json_j[#v1] = nlohmann_json_t.v1; -#endif -#ifndef NLOHMANN_JSON_FROM -#define NLOHMANN_JSON_FROM(v1) nlohmann_json_j.at(#v1).get_to(nlohmann_json_t.v1); -#endif -#ifndef NLOHMANN_JSON_FROM_WITH_DEFAULT -#define NLOHMANN_JSON_FROM_WITH_DEFAULT(v1) \ - nlohmann_json_t.v1 = nlohmann_json_j.value(#v1, nlohmann_json_default_obj.v1); -#endif -#ifndef NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT -#define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Type, ...) \ - inline void to_json(nlohmann::json& nlohmann_json_j, \ - const Type& nlohmann_json_t) { \ - NLOHMANN_JSON_EXPAND( \ - NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) \ - } \ - inline void from_json(const nlohmann::json& nlohmann_json_j, \ - Type& nlohmann_json_t) { \ - const Type nlohmann_json_default_obj{}; \ - NLOHMANN_JSON_EXPAND( \ - NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM_WITH_DEFAULT, __VA_ARGS__)) \ - } -#endif +#include "rpl/lifetime.h" #include "rpl/producer.h" +#include "rpl/variable.h" -namespace AyuSettings { +#include +#include -class AyuGramSettings -{ -public: - AyuGramSettings(); - bool sendReadMessages; - bool sendReadStories; - bool sendOnlinePackets; - bool sendUploadProgress; - bool sendOfflinePacketAfterOnline; +namespace Main { +class Session; +} - bool markReadAfterAction; - bool useScheduledMessages; - bool sendWithoutSound; - - bool saveDeletedMessages; - bool saveMessagesHistory; - - bool saveForBots; - - std::unordered_set shadowBanIds; - bool filtersEnabled; - bool filtersEnabledInChats; - bool hideFromBlocked; - - bool disableAds; - bool disableStories; - bool disableCustomBackgrounds; - bool showOnlyAddedEmojisAndStickers; - bool collapseSimilarChannels; - bool hideSimilarChannels; - - double wideMultiplier; - - bool spoofWebviewAsAndroid; - bool increaseWebviewHeight; - bool increaseWebviewWidth; - - bool materialSwitches; - bool removeMessageTail; - - bool disableNotificationsDelay; - bool localPremium; - bool showChannelReactions; - bool showGroupReactions; - - QString appIcon; - bool simpleQuotesAndReplies; - bool hideFastShare; - bool replaceBottomInfoWithIcons; - QString deletedMark; - QString editedMark; - int recentStickersCount; - - int showReactionsPanelInContextMenu; - int showViewsPanelInContextMenu; - int showHideMessageInContextMenu; - int showUserMessagesInContextMenu; - int showMessageDetailsInContextMenu; - int showRepeatMessageInContextMenu; - int showAddFilterInContextMenu; - - bool showAttachButtonInMessageField; - bool showCommandsButtonInMessageField; - bool showEmojiButtonInMessageField; - bool showMicrophoneButtonInMessageField; - bool showAutoDeleteButtonInMessageField; - - bool showAttachPopup; - bool showEmojiPopup; - - bool showMyProfileInDrawer; - bool showBotsInDrawer; - bool showNewGroupInDrawer; - bool showNewChannelInDrawer; - bool showContactsInDrawer; - bool showCallsInDrawer; - bool showSavedMessagesInDrawer; - bool showLReadToggleInDrawer; - bool showSReadToggleInDrawer; - bool showNightModeToggleInDrawer; - bool showGhostToggleInDrawer; - bool showStreamerToggleInDrawer; - - bool showGhostToggleInTray; - bool showStreamerToggleInTray; - - QString monoFont; - - bool hideNotificationCounters; - bool hideNotificationBadge; - bool hideAllChatsFolder; - - int channelBottomButton; - bool quickAdminShortcuts; - - int showPeerId; - bool showMessageSeconds; - bool showMessageShot; - - bool filterZalgo; - - bool stickerConfirmation; - bool gifConfirmation; - bool voiceConfirmation; - - QString translationProvider; - - bool adaptiveCoverColor; - - bool crashReporting; +enum class PeerIdDisplay { + Hidden = 0, + TelegramApi = 1, + BotApi = 2, }; -void set_sendReadMessages(bool val); -void set_sendReadStories(bool val); -void set_sendOnlinePackets(bool val); -void set_sendUploadProgress(bool val); -void set_sendOfflinePacketAfterOnline(bool val); +enum class ChannelBottomButton { + Hidden = 0, + MuteUnmute = 1, + DiscussWithFallback = 2, +}; -void set_ghostModeEnabled(bool val); +enum class ContextMenuVisibility { + Hidden = 0, + Visible = 1, + VisibleWithModifier = 2, +}; -void set_markReadAfterAction(bool val); -void set_useScheduledMessages(bool val); -void set_sendWithoutSound(bool val); +NLOHMANN_JSON_SERIALIZE_ENUM(PeerIdDisplay, { + {PeerIdDisplay::Hidden, 0}, + {PeerIdDisplay::TelegramApi, 1}, + {PeerIdDisplay::BotApi, 2}, +}) -void set_saveDeletedMessages(bool val); -void set_saveMessagesHistory(bool val); +NLOHMANN_JSON_SERIALIZE_ENUM(ChannelBottomButton, { + {ChannelBottomButton::Hidden, 0}, + {ChannelBottomButton::MuteUnmute, 1}, + {ChannelBottomButton::DiscussWithFallback, 2}, +}) -void set_saveForBots(bool val); +NLOHMANN_JSON_SERIALIZE_ENUM(ContextMenuVisibility, { + {ContextMenuVisibility::Hidden, 0}, + {ContextMenuVisibility::Visible, 1}, + {ContextMenuVisibility::VisibleWithModifier, 2}, +}) -void set_filtersEnabled(bool val); -void set_filtersEnabledInChats(bool val); -void set_hideFromBlocked(bool val); +class GhostModeAccountSettings { +public: + GhostModeAccountSettings(); -void set_disableAds(bool val); -void set_disableStories(bool val); -void set_disableCustomBackgrounds(bool val); -void set_showOnlyAddedEmojisAndStickers(bool val); -void set_collapseSimilarChannels(bool val); -void set_hideSimilarChannels(bool val); + [[nodiscard]] bool sendReadMessages() const { return _sendReadMessages.current(); } + [[nodiscard]] bool sendReadStories() const { return _sendReadStories.current(); } + [[nodiscard]] bool sendOnlinePackets() const { return _sendOnlinePackets.current(); } + [[nodiscard]] bool sendUploadProgress() const { return _sendUploadProgress.current(); } + [[nodiscard]] bool sendOfflinePacketAfterOnline() const { return _sendOfflinePacketAfterOnline.current(); } + [[nodiscard]] bool markReadAfterAction() const { return _markReadAfterAction.current(); } + [[nodiscard]] bool useScheduledMessages() const { return _useScheduledMessages.current(); } + [[nodiscard]] bool sendWithoutSound() const { return _sendWithoutSound.current(); } + [[nodiscard]] bool isGhostModeActive() const { return _ghostModeActive.current(); } + [[nodiscard]] bool isUseScheduledMessages() const { return isGhostModeActive() && useScheduledMessages(); } -void set_wideMultiplier(double val); + [[nodiscard]] bool sendReadMessagesLocked() const { return _sendReadMessagesLocked.current(); } + [[nodiscard]] bool sendReadStoriesLocked() const { return _sendReadStoriesLocked.current(); } + [[nodiscard]] bool sendOnlinePacketsLocked() const { return _sendOnlinePacketsLocked.current(); } + [[nodiscard]] bool sendUploadProgressLocked() const { return _sendUploadProgressLocked.current(); } + [[nodiscard]] bool sendOfflinePacketAfterOnlineLocked() const { return _sendOfflinePacketAfterOnlineLocked.current(); } -void set_spoofWebviewAsAndroid(bool val); -void set_increaseWebviewHeight(bool val); -void set_increaseWebviewWidth(bool val); + void setSendReadMessages(bool val); + void setSendReadStories(bool val); + void setSendOnlinePackets(bool val); + void setSendUploadProgress(bool val); + void setSendOfflinePacketAfterOnline(bool val); + void setMarkReadAfterAction(bool val); + void setUseScheduledMessages(bool val); + void setSendWithoutSound(bool val); + void setGhostModeEnabled(bool val); -void set_materialSwitches(bool val); -void set_removeMessageTail(bool val); + void setSendReadMessagesLocked(bool val); + void setSendReadStoriesLocked(bool val); + void setSendOnlinePacketsLocked(bool val); + void setSendUploadProgressLocked(bool val); + void setSendOfflinePacketAfterOnlineLocked(bool val); -void set_disableNotificationsDelay(bool val); -void set_localPremium(bool val); -void set_hideChannelReactions(bool val); -void set_hideGroupReactions(bool val); + [[nodiscard]] rpl::producer sendReadMessagesChanges() const { return _sendReadMessages.value(); } + [[nodiscard]] rpl::producer sendReadStoriesChanges() const { return _sendReadStories.value(); } + [[nodiscard]] rpl::producer sendOnlinePacketsChanges() const { return _sendOnlinePackets.value(); } + [[nodiscard]] rpl::producer sendUploadProgressChanges() const { return _sendUploadProgress.value(); } + [[nodiscard]] rpl::producer sendOfflinePacketAfterOnlineChanges() const { return _sendOfflinePacketAfterOnline.value(); } + [[nodiscard]] rpl::producer markReadAfterActionChanges() const { return _markReadAfterAction.value(); } + [[nodiscard]] rpl::producer useScheduledMessagesChanges() const { return _useScheduledMessages.value(); } + [[nodiscard]] rpl::producer sendWithoutSoundChanges() const { return _sendWithoutSound.value(); } + [[nodiscard]] rpl::producer ghostModeActiveChanges() const { return _ghostModeActive.value(); } -void set_appIcon(const QString &val); -void set_simpleQuotesAndReplies(bool val); -void set_hideFastShare(bool val); -void set_replaceBottomInfoWithIcons(bool val); -void set_deletedMark(const QString &val); -void set_editedMark(const QString &val); -void set_recentStickersCount(int val); + [[nodiscard]] rpl::producer sendReadMessagesLockedChanges() const { return _sendReadMessagesLocked.value(); } + [[nodiscard]] rpl::producer sendReadStoriesLockedChanges() const { return _sendReadStoriesLocked.value(); } + [[nodiscard]] rpl::producer sendOnlinePacketsLockedChanges() const { return _sendOnlinePacketsLocked.value(); } + [[nodiscard]] rpl::producer sendUploadProgressLockedChanges() const { return _sendUploadProgressLocked.value(); } + [[nodiscard]] rpl::producer sendOfflinePacketAfterOnlineLockedChanges() const { return _sendOfflinePacketAfterOnlineLocked.value(); } -void set_showReactionsPanelInContextMenu(int val); -void set_showViewsPanelInContextMenu(int val); -void set_showHideMessageInContextMenu(int val); -void set_showUserMessagesInContextMenu(int val); -void set_showMessageDetailsInContextMenu(int val); -void set_showRepeatMessageInContextMenu(int val); -void set_showAddFilterInContextMenu(int val); + friend void to_json(nlohmann::json &j, const GhostModeAccountSettings &s); + friend void from_json(const nlohmann::json &j, GhostModeAccountSettings &s); -void set_showAttachButtonInMessageField(bool val); -void set_showCommandsButtonInMessageField(bool val); -void set_showEmojiButtonInMessageField(bool val); -void set_showMicrophoneButtonInMessageField(bool val); -void set_showAutoDeleteButtonInMessageField(bool val); +private: + friend class AyuSettings; -void set_showAttachPopup(bool val); -void set_showEmojiPopup(bool val); + rpl::variable _sendReadMessages = true; + rpl::variable _sendReadStories = true; + rpl::variable _sendOnlinePackets = true; + rpl::variable _sendUploadProgress = true; + rpl::variable _sendOfflinePacketAfterOnline = false; + rpl::variable _markReadAfterAction = true; + rpl::variable _useScheduledMessages = false; + rpl::variable _sendWithoutSound = false; + rpl::variable _ghostModeActive = false; -void set_showMyProfileInDrawer(bool val); -void set_showBotsInDrawer(bool val); -void set_showNewGroupInDrawer(bool val); -void set_showNewChannelInDrawer(bool val); -void set_showContactsInDrawer(bool val); -void set_showCallsInDrawer(bool val); -void set_showSavedMessagesInDrawer(bool val); -void set_showLReadToggleInDrawer(bool val); -void set_showSReadToggleInDrawer(bool val); -void set_showNightModeToggleInDrawer(bool val); -void set_showGhostToggleInDrawer(bool val); -void set_showStreamerToggleInDrawer(bool val); + rpl::variable _sendReadMessagesLocked = false; + rpl::variable _sendReadStoriesLocked = false; + rpl::variable _sendOnlinePacketsLocked = false; + rpl::variable _sendUploadProgressLocked = false; + rpl::variable _sendOfflinePacketAfterOnlineLocked = false; +}; -void set_showGhostToggleInTray(bool val); -void set_showStreamerToggleInTray(bool val); +void to_json(nlohmann::json &j, const GhostModeAccountSettings &s); +void from_json(const nlohmann::json &j, GhostModeAccountSettings &s); -void set_monoFont(const QString &val); +class AyuSettings { +public: + AyuSettings(const AyuSettings &) = delete; + AyuSettings &operator=(const AyuSettings &) = delete; + AyuSettings(AyuSettings &&) noexcept = default; + AyuSettings &operator=(AyuSettings &&) noexcept = default; -void set_hideNotificationCounters(bool val); -void set_hideNotificationBadge(bool val); -void set_hideAllChatsFolder(bool val); + [[nodiscard]] static AyuSettings &getInstance(); -void set_channelBottomButton(int val); -void set_quickAdminShortcuts(bool val); + static void load(); + static void save(); + static void reset(); -void set_showPeerId(int val); -void set_showMessageSeconds(bool val); -void set_showMessageShot(bool val); + [[nodiscard]] static GhostModeAccountSettings &ghost(not_null session); + [[nodiscard]] static GhostModeAccountSettings &ghost(uint64 userId); + [[nodiscard]] static GhostModeAccountSettings &ghost(); + [[nodiscard]] bool useGlobalGhostMode() const { return _useGlobalGhostMode.current(); } + void setUseGlobalGhostMode(bool val); -void set_filterZalgo(bool val); + void addShadowBan(int64 id); + void removeShadowBan(int64 id); + [[nodiscard]] bool isShadowBanned(const int64 id) const { return _shadowBanIds.contains(id); } + [[nodiscard]] const std::unordered_set &shadowBanIds() const { return _shadowBanIds; } -void set_stickerConfirmation(bool val); -void set_gifConfirmation(bool val); -void set_voiceConfirmation(bool val); + void validate(); -void set_translationProvider(const QString &val); + [[nodiscard]] bool saveDeletedMessages() const { return _saveDeletedMessages.current(); } + [[nodiscard]] bool saveMessagesHistory() const { return _saveMessagesHistory.current(); } + [[nodiscard]] bool saveForBots() const { return _saveForBots.current(); } + [[nodiscard]] bool filtersEnabled() const { return _filtersEnabled.current(); } + [[nodiscard]] bool filtersEnabledInChats() const { return _filtersEnabledInChats.current(); } + [[nodiscard]] bool hideFromBlocked() const { return _hideFromBlocked.current(); } + [[nodiscard]] bool disableAds() const { return _disableAds.current(); } + [[nodiscard]] bool disableStories() const { return _disableStories.current(); } + [[nodiscard]] bool disableCustomBackgrounds() const { return _disableCustomBackgrounds.current(); } + [[nodiscard]] bool showOnlyAddedEmojisAndStickers() const { return _showOnlyAddedEmojisAndStickers.current(); } + [[nodiscard]] bool collapseSimilarChannels() const { return _collapseSimilarChannels.current(); } + [[nodiscard]] bool hideSimilarChannels() const { return _hideSimilarChannels.current(); } + [[nodiscard]] double wideMultiplier() const { return _wideMultiplier.current(); } + [[nodiscard]] bool spoofWebviewAsAndroid() const { return _spoofWebviewAsAndroid.current(); } + [[nodiscard]] bool increaseWebviewHeight() const { return _increaseWebviewHeight.current(); } + [[nodiscard]] bool increaseWebviewWidth() const { return _increaseWebviewWidth.current(); } + [[nodiscard]] bool materialSwitches() const { return _materialSwitches.current(); } + [[nodiscard]] bool removeMessageTail() const { return _removeMessageTail.current(); } + [[nodiscard]] bool disableNotificationsDelay() const { return _disableNotificationsDelay.current(); } + [[nodiscard]] bool localPremium() const { return _localPremium.current(); } + [[nodiscard]] bool showChannelReactions() const { return _showChannelReactions.current(); } + [[nodiscard]] bool showGroupReactions() const { return _showGroupReactions.current(); } + [[nodiscard]] const QString &appIcon() const { return _appIcon.current(); } + [[nodiscard]] bool simpleQuotesAndReplies() const { return _simpleQuotesAndReplies.current(); } + [[nodiscard]] bool hideFastShare() const { return _hideFastShare.current(); } + [[nodiscard]] bool replaceBottomInfoWithIcons() const { return _replaceBottomInfoWithIcons.current(); } + [[nodiscard]] const QString &deletedMark() const { return _deletedMark.current(); } + [[nodiscard]] const QString &editedMark() const { return _editedMark.current(); } + [[nodiscard]] int recentStickersCount() const { return _recentStickersCount.current(); } + [[nodiscard]] ContextMenuVisibility showReactionsPanelInContextMenu() const { return _showReactionsPanelInContextMenu.current(); } + [[nodiscard]] ContextMenuVisibility showViewsPanelInContextMenu() const { return _showViewsPanelInContextMenu.current(); } + [[nodiscard]] ContextMenuVisibility showHideMessageInContextMenu() const { return _showHideMessageInContextMenu.current(); } + [[nodiscard]] ContextMenuVisibility showUserMessagesInContextMenu() const { return _showUserMessagesInContextMenu.current(); } + [[nodiscard]] ContextMenuVisibility showMessageDetailsInContextMenu() const { return _showMessageDetailsInContextMenu.current(); } + [[nodiscard]] ContextMenuVisibility showRepeatMessageInContextMenu() const { return _showRepeatMessageInContextMenu.current(); } + [[nodiscard]] ContextMenuVisibility showAddFilterInContextMenu() const { return _showAddFilterInContextMenu.current(); } + [[nodiscard]] bool showAttachButtonInMessageField() const { return _showAttachButtonInMessageField.current(); } + [[nodiscard]] bool showCommandsButtonInMessageField() const { return _showCommandsButtonInMessageField.current(); } + [[nodiscard]] bool showEmojiButtonInMessageField() const { return _showEmojiButtonInMessageField.current(); } + [[nodiscard]] bool showMicrophoneButtonInMessageField() const { return _showMicrophoneButtonInMessageField.current(); } + [[nodiscard]] bool showAutoDeleteButtonInMessageField() const { return _showAutoDeleteButtonInMessageField.current(); } + [[nodiscard]] bool showAttachPopup() const { return _showAttachPopup.current(); } + [[nodiscard]] bool showEmojiPopup() const { return _showEmojiPopup.current(); } + [[nodiscard]] bool showMyProfileInDrawer() const { return _showMyProfileInDrawer.current(); } + [[nodiscard]] bool showBotsInDrawer() const { return _showBotsInDrawer.current(); } + [[nodiscard]] bool showNewGroupInDrawer() const { return _showNewGroupInDrawer.current(); } + [[nodiscard]] bool showNewChannelInDrawer() const { return _showNewChannelInDrawer.current(); } + [[nodiscard]] bool showContactsInDrawer() const { return _showContactsInDrawer.current(); } + [[nodiscard]] bool showCallsInDrawer() const { return _showCallsInDrawer.current(); } + [[nodiscard]] bool showSavedMessagesInDrawer() const { return _showSavedMessagesInDrawer.current(); } + [[nodiscard]] bool showLReadToggleInDrawer() const { return _showLReadToggleInDrawer.current(); } + [[nodiscard]] bool showSReadToggleInDrawer() const { return _showSReadToggleInDrawer.current(); } + [[nodiscard]] bool showNightModeToggleInDrawer() const { return _showNightModeToggleInDrawer.current(); } + [[nodiscard]] bool showGhostToggleInDrawer() const { return _showGhostToggleInDrawer.current(); } + [[nodiscard]] bool showStreamerToggleInDrawer() const { return _showStreamerToggleInDrawer.current(); } + [[nodiscard]] bool showGhostToggleInTray() const { return _showGhostToggleInTray.current(); } + [[nodiscard]] bool showStreamerToggleInTray() const { return _showStreamerToggleInTray.current(); } + [[nodiscard]] const QString &monoFont() const { return _monoFont.current(); } + [[nodiscard]] bool hideNotificationCounters() const { return _hideNotificationCounters.current(); } + [[nodiscard]] bool hideNotificationBadge() const { return _hideNotificationBadge.current(); } + [[nodiscard]] bool hideAllChatsFolder() const { return _hideAllChatsFolder.current(); } + [[nodiscard]] ChannelBottomButton channelBottomButton() const { return _channelBottomButton.current(); } + [[nodiscard]] bool quickAdminShortcuts() const { return _quickAdminShortcuts.current(); } + [[nodiscard]] PeerIdDisplay showPeerId() const { return _showPeerId.current(); } + [[nodiscard]] bool showMessageSeconds() const { return _showMessageSeconds.current(); } + [[nodiscard]] bool showMessageShot() const { return _showMessageShot.current(); } + [[nodiscard]] bool filterZalgo() const { return _filterZalgo.current(); } + [[nodiscard]] bool stickerConfirmation() const { return _stickerConfirmation.current(); } + [[nodiscard]] bool gifConfirmation() const { return _gifConfirmation.current(); } + [[nodiscard]] bool voiceConfirmation() const { return _voiceConfirmation.current(); } + [[nodiscard]] const QString &translationProvider() const { return _translationProvider.current(); } + [[nodiscard]] bool adaptiveCoverColor() const { return _adaptiveCoverColor.current(); } + [[nodiscard]] bool crashReporting() const { return _crashReporting.current(); } -void set_adaptiveCoverColor(bool val); + void setSaveDeletedMessages(bool val); + void setSaveMessagesHistory(bool val); + void setSaveForBots(bool val); + void setFiltersEnabled(bool val); + void setFiltersEnabledInChats(bool val); + void setHideFromBlocked(bool val); + void setDisableAds(bool val); + void setDisableStories(bool val); + void setDisableCustomBackgrounds(bool val); + void setShowOnlyAddedEmojisAndStickers(bool val); + void setCollapseSimilarChannels(bool val); + void setHideSimilarChannels(bool val); + void setWideMultiplier(double val); + void setSpoofWebviewAsAndroid(bool val); + void setIncreaseWebviewHeight(bool val); + void setIncreaseWebviewWidth(bool val); + void setMaterialSwitches(bool val); + void setRemoveMessageTail(bool val); + void setDisableNotificationsDelay(bool val); + void setLocalPremium(bool val); + void setShowChannelReactions(bool val); + void setShowGroupReactions(bool val); + void setAppIcon(const QString &val); + void setSimpleQuotesAndReplies(bool val); + void setHideFastShare(bool val); + void setReplaceBottomInfoWithIcons(bool val); + void setDeletedMark(const QString &val); + void setEditedMark(const QString &val); + void setRecentStickersCount(int val); + void setShowReactionsPanelInContextMenu(ContextMenuVisibility val); + void setShowViewsPanelInContextMenu(ContextMenuVisibility val); + void setShowHideMessageInContextMenu(ContextMenuVisibility val); + void setShowUserMessagesInContextMenu(ContextMenuVisibility val); + void setShowMessageDetailsInContextMenu(ContextMenuVisibility val); + void setShowRepeatMessageInContextMenu(ContextMenuVisibility val); + void setShowAddFilterInContextMenu(ContextMenuVisibility val); + void setShowAttachButtonInMessageField(bool val); + void setShowCommandsButtonInMessageField(bool val); + void setShowEmojiButtonInMessageField(bool val); + void setShowMicrophoneButtonInMessageField(bool val); + void setShowAutoDeleteButtonInMessageField(bool val); + void setShowAttachPopup(bool val); + void setShowEmojiPopup(bool val); + void setShowMyProfileInDrawer(bool val); + void setShowBotsInDrawer(bool val); + void setShowNewGroupInDrawer(bool val); + void setShowNewChannelInDrawer(bool val); + void setShowContactsInDrawer(bool val); + void setShowCallsInDrawer(bool val); + void setShowSavedMessagesInDrawer(bool val); + void setShowLReadToggleInDrawer(bool val); + void setShowSReadToggleInDrawer(bool val); + void setShowNightModeToggleInDrawer(bool val); + void setShowGhostToggleInDrawer(bool val); + void setShowStreamerToggleInDrawer(bool val); + void setShowGhostToggleInTray(bool val); + void setShowStreamerToggleInTray(bool val); + void setMonoFont(const QString &val); + void setHideNotificationCounters(bool val); + void setHideNotificationBadge(bool val); + void setHideAllChatsFolder(bool val); + void setChannelBottomButton(ChannelBottomButton val); + void setQuickAdminShortcuts(bool val); + void setShowPeerId(PeerIdDisplay val); + void setShowMessageSeconds(bool val); + void setShowMessageShot(bool val); + void setFilterZalgo(bool val); + void setStickerConfirmation(bool val); + void setGifConfirmation(bool val); + void setVoiceConfirmation(bool val); + void setTranslationProvider(const QString &val); + void setAdaptiveCoverColor(bool val); + void setCrashReporting(bool val); -void set_crashReporting(bool val); + [[nodiscard]] rpl::producer useGlobalGhostModeChanges() const { return _useGlobalGhostMode.value(); } + [[nodiscard]] rpl::producer saveDeletedMessagesChanges() const { return _saveDeletedMessages.value(); } + [[nodiscard]] rpl::producer saveMessagesHistoryChanges() const { return _saveMessagesHistory.value(); } + [[nodiscard]] rpl::producer saveForBotsChanges() const { return _saveForBots.value(); } + [[nodiscard]] rpl::producer filtersEnabledChanges() const { return _filtersEnabled.value(); } + [[nodiscard]] rpl::producer filtersEnabledInChatsChanges() const { return _filtersEnabledInChats.value(); } + [[nodiscard]] rpl::producer hideFromBlockedChanges() const { return _hideFromBlocked.value(); } + [[nodiscard]] rpl::producer disableAdsChanges() const { return _disableAds.value(); } + [[nodiscard]] rpl::producer disableStoriesChanges() const { return _disableStories.value(); } + [[nodiscard]] rpl::producer disableCustomBackgroundsChanges() const { return _disableCustomBackgrounds.value(); } + [[nodiscard]] rpl::producer showOnlyAddedEmojisAndStickersChanges() const { return _showOnlyAddedEmojisAndStickers.value(); } + [[nodiscard]] rpl::producer collapseSimilarChannelsChanges() const { return _collapseSimilarChannels.value(); } + [[nodiscard]] rpl::producer hideSimilarChannelsChanges() const { return _hideSimilarChannels.value(); } + [[nodiscard]] rpl::producer wideMultiplierChanges() const { return _wideMultiplier.value(); } + [[nodiscard]] rpl::producer spoofWebviewAsAndroidChanges() const { return _spoofWebviewAsAndroid.value(); } + [[nodiscard]] rpl::producer increaseWebviewHeightChanges() const { return _increaseWebviewHeight.value(); } + [[nodiscard]] rpl::producer increaseWebviewWidthChanges() const { return _increaseWebviewWidth.value(); } + [[nodiscard]] rpl::producer materialSwitchesChanges() const { return _materialSwitches.value(); } + [[nodiscard]] rpl::producer removeMessageTailChanges() const { return _removeMessageTail.value(); } + [[nodiscard]] rpl::producer disableNotificationsDelayChanges() const { return _disableNotificationsDelay.value(); } + [[nodiscard]] rpl::producer localPremiumChanges() const { return _localPremium.value(); } + [[nodiscard]] rpl::producer showChannelReactionsChanges() const { return _showChannelReactions.value(); } + [[nodiscard]] rpl::producer showGroupReactionsChanges() const { return _showGroupReactions.value(); } + [[nodiscard]] rpl::producer appIconChanges() const { return _appIcon.value(); } + [[nodiscard]] rpl::producer simpleQuotesAndRepliesChanges() const { return _simpleQuotesAndReplies.value(); } + [[nodiscard]] rpl::producer hideFastShareChanges() const { return _hideFastShare.value(); } + [[nodiscard]] rpl::producer replaceBottomInfoWithIconsChanges() const { return _replaceBottomInfoWithIcons.value(); } + [[nodiscard]] rpl::producer deletedMarkChanges() const { return _deletedMark.value(); } + [[nodiscard]] rpl::producer editedMarkChanges() const { return _editedMark.value(); } + [[nodiscard]] rpl::producer recentStickersCountChanges() const { return _recentStickersCount.value(); } + [[nodiscard]] rpl::producer showReactionsPanelInContextMenuChanges() const { return _showReactionsPanelInContextMenu.value(); } + [[nodiscard]] rpl::producer showViewsPanelInContextMenuChanges() const { return _showViewsPanelInContextMenu.value(); } + [[nodiscard]] rpl::producer showHideMessageInContextMenuChanges() const { return _showHideMessageInContextMenu.value(); } + [[nodiscard]] rpl::producer showUserMessagesInContextMenuChanges() const { return _showUserMessagesInContextMenu.value(); } + [[nodiscard]] rpl::producer showMessageDetailsInContextMenuChanges() const { return _showMessageDetailsInContextMenu.value(); } + [[nodiscard]] rpl::producer showRepeatMessageInContextMenuChanges() const { return _showRepeatMessageInContextMenu.value(); } + [[nodiscard]] rpl::producer showAddFilterInContextMenuChanges() const { return _showAddFilterInContextMenu.value(); } + [[nodiscard]] rpl::producer showAttachButtonInMessageFieldChanges() const { return _showAttachButtonInMessageField.value(); } + [[nodiscard]] rpl::producer showCommandsButtonInMessageFieldChanges() const { return _showCommandsButtonInMessageField.value(); } + [[nodiscard]] rpl::producer showEmojiButtonInMessageFieldChanges() const { return _showEmojiButtonInMessageField.value(); } + [[nodiscard]] rpl::producer showMicrophoneButtonInMessageFieldChanges() const { return _showMicrophoneButtonInMessageField.value(); } + [[nodiscard]] rpl::producer showAutoDeleteButtonInMessageFieldChanges() const { return _showAutoDeleteButtonInMessageField.value(); } + [[nodiscard]] rpl::producer showAttachPopupChanges() const { return _showAttachPopup.value(); } + [[nodiscard]] rpl::producer showEmojiPopupChanges() const { return _showEmojiPopup.value(); } + [[nodiscard]] rpl::producer showMyProfileInDrawerChanges() const { return _showMyProfileInDrawer.value(); } + [[nodiscard]] rpl::producer showBotsInDrawerChanges() const { return _showBotsInDrawer.value(); } + [[nodiscard]] rpl::producer showNewGroupInDrawerChanges() const { return _showNewGroupInDrawer.value(); } + [[nodiscard]] rpl::producer showNewChannelInDrawerChanges() const { return _showNewChannelInDrawer.value(); } + [[nodiscard]] rpl::producer showContactsInDrawerChanges() const { return _showContactsInDrawer.value(); } + [[nodiscard]] rpl::producer showCallsInDrawerChanges() const { return _showCallsInDrawer.value(); } + [[nodiscard]] rpl::producer showSavedMessagesInDrawerChanges() const { return _showSavedMessagesInDrawer.value(); } + [[nodiscard]] rpl::producer showLReadToggleInDrawerChanges() const { return _showLReadToggleInDrawer.value(); } + [[nodiscard]] rpl::producer showSReadToggleInDrawerChanges() const { return _showSReadToggleInDrawer.value(); } + [[nodiscard]] rpl::producer showNightModeToggleInDrawerChanges() const { return _showNightModeToggleInDrawer.value(); } + [[nodiscard]] rpl::producer showGhostToggleInDrawerChanges() const { return _showGhostToggleInDrawer.value(); } + [[nodiscard]] rpl::producer showStreamerToggleInDrawerChanges() const { return _showStreamerToggleInDrawer.value(); } + [[nodiscard]] rpl::producer showGhostToggleInTrayChanges() const { return _showGhostToggleInTray.value(); } + [[nodiscard]] rpl::producer showStreamerToggleInTrayChanges() const { return _showStreamerToggleInTray.value(); } + [[nodiscard]] rpl::producer monoFontChanges() const { return _monoFont.value(); } + [[nodiscard]] rpl::producer hideNotificationCountersChanges() const { return _hideNotificationCounters.value(); } + [[nodiscard]] rpl::producer hideNotificationBadgeChanges() const { return _hideNotificationBadge.value(); } + [[nodiscard]] rpl::producer hideAllChatsFolderChanges() const { return _hideAllChatsFolder.value(); } + [[nodiscard]] rpl::producer channelBottomButtonChanges() const { return _channelBottomButton.value(); } + [[nodiscard]] rpl::producer quickAdminShortcutsChanges() const { return _quickAdminShortcuts.value(); } + [[nodiscard]] rpl::producer showPeerIdChanges() const { return _showPeerId.value(); } + [[nodiscard]] rpl::producer showMessageSecondsChanges() const { return _showMessageSeconds.value(); } + [[nodiscard]] rpl::producer showMessageShotChanges() const { return _showMessageShot.value(); } + [[nodiscard]] rpl::producer filterZalgoChanges() const { return _filterZalgo.value(); } + [[nodiscard]] rpl::producer stickerConfirmationChanges() const { return _stickerConfirmation.value(); } + [[nodiscard]] rpl::producer gifConfirmationChanges() const { return _gifConfirmation.value(); } + [[nodiscard]] rpl::producer voiceConfirmationChanges() const { return _voiceConfirmation.value(); } + [[nodiscard]] rpl::producer translationProviderChanges() const { return _translationProvider.value(); } + [[nodiscard]] rpl::producer adaptiveCoverColorChanges() const { return _adaptiveCoverColor.value(); } + [[nodiscard]] rpl::producer crashReportingChanges() const { return _crashReporting.value(); } -inline void to_json(nlohmann::json &nlohmann_json_j, const AyuGramSettings &nlohmann_json_t) { - NLOHMANN_JSON_TO(sendReadMessages) - NLOHMANN_JSON_TO(sendReadStories) - NLOHMANN_JSON_TO(sendOnlinePackets) - NLOHMANN_JSON_TO(sendUploadProgress) - NLOHMANN_JSON_TO(sendOfflinePacketAfterOnline) - NLOHMANN_JSON_TO(markReadAfterAction) - NLOHMANN_JSON_TO(useScheduledMessages) - NLOHMANN_JSON_TO(sendWithoutSound) - NLOHMANN_JSON_TO(saveDeletedMessages) - NLOHMANN_JSON_TO(saveMessagesHistory) - NLOHMANN_JSON_TO(saveForBots) - NLOHMANN_JSON_TO(shadowBanIds) - NLOHMANN_JSON_TO(filtersEnabled) - NLOHMANN_JSON_TO(filtersEnabledInChats) - NLOHMANN_JSON_TO(hideFromBlocked) - NLOHMANN_JSON_TO(disableAds) - NLOHMANN_JSON_TO(disableStories) - NLOHMANN_JSON_TO(disableCustomBackgrounds) - NLOHMANN_JSON_TO(showOnlyAddedEmojisAndStickers) - NLOHMANN_JSON_TO(collapseSimilarChannels) - NLOHMANN_JSON_TO(hideSimilarChannels) - NLOHMANN_JSON_TO(wideMultiplier) - NLOHMANN_JSON_TO(spoofWebviewAsAndroid) - NLOHMANN_JSON_TO(increaseWebviewHeight) - NLOHMANN_JSON_TO(increaseWebviewWidth) - NLOHMANN_JSON_TO(materialSwitches) - NLOHMANN_JSON_TO(removeMessageTail) - NLOHMANN_JSON_TO(disableNotificationsDelay) - NLOHMANN_JSON_TO(localPremium) - NLOHMANN_JSON_TO(appIcon) - NLOHMANN_JSON_TO(simpleQuotesAndReplies) - NLOHMANN_JSON_TO(hideFastShare) - NLOHMANN_JSON_TO(replaceBottomInfoWithIcons) - NLOHMANN_JSON_TO(deletedMark) - NLOHMANN_JSON_TO(editedMark) - NLOHMANN_JSON_TO(recentStickersCount) - NLOHMANN_JSON_TO(showReactionsPanelInContextMenu) - NLOHMANN_JSON_TO(showViewsPanelInContextMenu) - NLOHMANN_JSON_TO(showHideMessageInContextMenu) - NLOHMANN_JSON_TO(showUserMessagesInContextMenu) - NLOHMANN_JSON_TO(showMessageDetailsInContextMenu) - NLOHMANN_JSON_TO(showRepeatMessageInContextMenu) - NLOHMANN_JSON_TO(showAddFilterInContextMenu) - NLOHMANN_JSON_TO(showAttachButtonInMessageField) - NLOHMANN_JSON_TO(showCommandsButtonInMessageField) - NLOHMANN_JSON_TO(showEmojiButtonInMessageField) - NLOHMANN_JSON_TO(showMicrophoneButtonInMessageField) - NLOHMANN_JSON_TO(showAutoDeleteButtonInMessageField) - NLOHMANN_JSON_TO(showAttachPopup) - NLOHMANN_JSON_TO(showEmojiPopup) - NLOHMANN_JSON_TO(showMyProfileInDrawer) - NLOHMANN_JSON_TO(showBotsInDrawer) - NLOHMANN_JSON_TO(showNewGroupInDrawer) - NLOHMANN_JSON_TO(showNewChannelInDrawer) - NLOHMANN_JSON_TO(showContactsInDrawer) - NLOHMANN_JSON_TO(showCallsInDrawer) - NLOHMANN_JSON_TO(showSavedMessagesInDrawer) - NLOHMANN_JSON_TO(showLReadToggleInDrawer) - NLOHMANN_JSON_TO(showSReadToggleInDrawer) - NLOHMANN_JSON_TO(showNightModeToggleInDrawer) - NLOHMANN_JSON_TO(showGhostToggleInDrawer) - NLOHMANN_JSON_TO(showStreamerToggleInDrawer) - NLOHMANN_JSON_TO(showGhostToggleInTray) - NLOHMANN_JSON_TO(showStreamerToggleInTray) - NLOHMANN_JSON_TO(monoFont) - NLOHMANN_JSON_TO(showChannelReactions) - NLOHMANN_JSON_TO(showGroupReactions) - NLOHMANN_JSON_TO(hideNotificationCounters) - NLOHMANN_JSON_TO(hideNotificationBadge) - NLOHMANN_JSON_TO(hideAllChatsFolder) - NLOHMANN_JSON_TO(channelBottomButton) - NLOHMANN_JSON_TO(quickAdminShortcuts) - NLOHMANN_JSON_TO(showPeerId) - NLOHMANN_JSON_TO(showMessageSeconds) - NLOHMANN_JSON_TO(showMessageShot) - NLOHMANN_JSON_TO(filterZalgo) - NLOHMANN_JSON_TO(stickerConfirmation) - NLOHMANN_JSON_TO(gifConfirmation) - NLOHMANN_JSON_TO(voiceConfirmation) - NLOHMANN_JSON_TO(translationProvider) - NLOHMANN_JSON_TO(adaptiveCoverColor) - NLOHMANN_JSON_TO(crashReporting) -} + friend void to_json(nlohmann::json &j, const AyuSettings &s); + friend void from_json(const nlohmann::json &j, AyuSettings &s); -inline void from_json(const nlohmann::json &nlohmann_json_j, AyuGramSettings &nlohmann_json_t) { - const AyuGramSettings nlohmann_json_default_obj{}; - NLOHMANN_JSON_FROM_WITH_DEFAULT(sendReadMessages) - NLOHMANN_JSON_FROM_WITH_DEFAULT(sendReadStories) - NLOHMANN_JSON_FROM_WITH_DEFAULT(sendOnlinePackets) - NLOHMANN_JSON_FROM_WITH_DEFAULT(sendUploadProgress) - NLOHMANN_JSON_FROM_WITH_DEFAULT(sendOfflinePacketAfterOnline) - NLOHMANN_JSON_FROM_WITH_DEFAULT(markReadAfterAction) - NLOHMANN_JSON_FROM_WITH_DEFAULT(useScheduledMessages) - NLOHMANN_JSON_FROM_WITH_DEFAULT(sendWithoutSound) - NLOHMANN_JSON_FROM_WITH_DEFAULT(saveDeletedMessages) - NLOHMANN_JSON_FROM_WITH_DEFAULT(saveMessagesHistory) - NLOHMANN_JSON_FROM_WITH_DEFAULT(saveForBots) - NLOHMANN_JSON_FROM_WITH_DEFAULT(filtersEnabled) - NLOHMANN_JSON_FROM_WITH_DEFAULT(filtersEnabledInChats) - NLOHMANN_JSON_FROM_WITH_DEFAULT(shadowBanIds) - NLOHMANN_JSON_FROM_WITH_DEFAULT(hideFromBlocked) - NLOHMANN_JSON_FROM_WITH_DEFAULT(disableAds) - NLOHMANN_JSON_FROM_WITH_DEFAULT(disableStories) - NLOHMANN_JSON_FROM_WITH_DEFAULT(disableCustomBackgrounds) - NLOHMANN_JSON_FROM_WITH_DEFAULT(showOnlyAddedEmojisAndStickers) - NLOHMANN_JSON_FROM_WITH_DEFAULT(collapseSimilarChannels) - NLOHMANN_JSON_FROM_WITH_DEFAULT(hideSimilarChannels) - NLOHMANN_JSON_FROM_WITH_DEFAULT(wideMultiplier) - NLOHMANN_JSON_FROM_WITH_DEFAULT(spoofWebviewAsAndroid) - NLOHMANN_JSON_FROM_WITH_DEFAULT(increaseWebviewHeight) - NLOHMANN_JSON_FROM_WITH_DEFAULT(increaseWebviewWidth) - NLOHMANN_JSON_FROM_WITH_DEFAULT(materialSwitches) - NLOHMANN_JSON_FROM_WITH_DEFAULT(removeMessageTail) - NLOHMANN_JSON_FROM_WITH_DEFAULT(disableNotificationsDelay) - NLOHMANN_JSON_FROM_WITH_DEFAULT(localPremium) - NLOHMANN_JSON_FROM_WITH_DEFAULT(appIcon) - NLOHMANN_JSON_FROM_WITH_DEFAULT(simpleQuotesAndReplies) - NLOHMANN_JSON_FROM_WITH_DEFAULT(hideFastShare) - NLOHMANN_JSON_FROM_WITH_DEFAULT(replaceBottomInfoWithIcons) - NLOHMANN_JSON_FROM_WITH_DEFAULT(deletedMark) - NLOHMANN_JSON_FROM_WITH_DEFAULT(editedMark) - NLOHMANN_JSON_FROM_WITH_DEFAULT(recentStickersCount) - NLOHMANN_JSON_FROM_WITH_DEFAULT(showReactionsPanelInContextMenu) - NLOHMANN_JSON_FROM_WITH_DEFAULT(showViewsPanelInContextMenu) - NLOHMANN_JSON_FROM_WITH_DEFAULT(showHideMessageInContextMenu) - NLOHMANN_JSON_FROM_WITH_DEFAULT(showUserMessagesInContextMenu) - NLOHMANN_JSON_FROM_WITH_DEFAULT(showMessageDetailsInContextMenu) - NLOHMANN_JSON_FROM_WITH_DEFAULT(showRepeatMessageInContextMenu) - NLOHMANN_JSON_FROM_WITH_DEFAULT(showAddFilterInContextMenu) - NLOHMANN_JSON_FROM_WITH_DEFAULT(showAttachButtonInMessageField) - NLOHMANN_JSON_FROM_WITH_DEFAULT(showCommandsButtonInMessageField) - NLOHMANN_JSON_FROM_WITH_DEFAULT(showEmojiButtonInMessageField) - NLOHMANN_JSON_FROM_WITH_DEFAULT(showMicrophoneButtonInMessageField) - NLOHMANN_JSON_FROM_WITH_DEFAULT(showAutoDeleteButtonInMessageField) - NLOHMANN_JSON_FROM_WITH_DEFAULT(showAttachPopup) - NLOHMANN_JSON_FROM_WITH_DEFAULT(showEmojiPopup) - NLOHMANN_JSON_FROM_WITH_DEFAULT(showMyProfileInDrawer) - NLOHMANN_JSON_FROM_WITH_DEFAULT(showBotsInDrawer) - NLOHMANN_JSON_FROM_WITH_DEFAULT(showNewGroupInDrawer) - NLOHMANN_JSON_FROM_WITH_DEFAULT(showNewChannelInDrawer) - NLOHMANN_JSON_FROM_WITH_DEFAULT(showContactsInDrawer) - NLOHMANN_JSON_FROM_WITH_DEFAULT(showCallsInDrawer) - NLOHMANN_JSON_FROM_WITH_DEFAULT(showSavedMessagesInDrawer) - NLOHMANN_JSON_FROM_WITH_DEFAULT(showLReadToggleInDrawer) - NLOHMANN_JSON_FROM_WITH_DEFAULT(showSReadToggleInDrawer) - NLOHMANN_JSON_FROM_WITH_DEFAULT(showNightModeToggleInDrawer) - NLOHMANN_JSON_FROM_WITH_DEFAULT(showGhostToggleInDrawer) - NLOHMANN_JSON_FROM_WITH_DEFAULT(showStreamerToggleInDrawer) - NLOHMANN_JSON_FROM_WITH_DEFAULT(showGhostToggleInTray) - NLOHMANN_JSON_FROM_WITH_DEFAULT(showStreamerToggleInTray) - NLOHMANN_JSON_FROM_WITH_DEFAULT(monoFont) - NLOHMANN_JSON_FROM_WITH_DEFAULT(showChannelReactions) - NLOHMANN_JSON_FROM_WITH_DEFAULT(showGroupReactions) - NLOHMANN_JSON_FROM_WITH_DEFAULT(hideNotificationCounters) - NLOHMANN_JSON_FROM_WITH_DEFAULT(hideNotificationBadge) - NLOHMANN_JSON_FROM_WITH_DEFAULT(hideAllChatsFolder) - NLOHMANN_JSON_FROM_WITH_DEFAULT(channelBottomButton) - NLOHMANN_JSON_FROM_WITH_DEFAULT(quickAdminShortcuts) - NLOHMANN_JSON_FROM_WITH_DEFAULT(showPeerId) - NLOHMANN_JSON_FROM_WITH_DEFAULT(showMessageSeconds) - NLOHMANN_JSON_FROM_WITH_DEFAULT(showMessageShot) - NLOHMANN_JSON_FROM_WITH_DEFAULT(filterZalgo) - NLOHMANN_JSON_FROM_WITH_DEFAULT(stickerConfirmation) - NLOHMANN_JSON_FROM_WITH_DEFAULT(gifConfirmation) - NLOHMANN_JSON_FROM_WITH_DEFAULT(voiceConfirmation) - NLOHMANN_JSON_FROM_WITH_DEFAULT(translationProvider) - NLOHMANN_JSON_FROM_WITH_DEFAULT(adaptiveCoverColor) - NLOHMANN_JSON_FROM_WITH_DEFAULT(crashReporting) -} +private: + AyuSettings(); -AyuGramSettings &getInstance(); + [[nodiscard]] uint64 getOverriddenGhostUserId(uint64 userId) const { return _useGlobalGhostMode.current() ? 0 : userId; } -void load(); -void save(); -void reset(); + rpl::variable _saveDeletedMessages = true; + rpl::variable _saveMessagesHistory = true; + rpl::variable _saveForBots = false; + std::unordered_set _shadowBanIds; + rpl::variable _filtersEnabled = false; + rpl::variable _filtersEnabledInChats = false; + rpl::variable _hideFromBlocked = false; + rpl::variable _disableAds = true; + rpl::variable _disableStories = false; + rpl::variable _disableCustomBackgrounds = true; + rpl::variable _showOnlyAddedEmojisAndStickers = false; + rpl::variable _collapseSimilarChannels = true; + rpl::variable _hideSimilarChannels = false; + rpl::variable _wideMultiplier = 1.0; + rpl::variable _spoofWebviewAsAndroid = false; + rpl::variable _increaseWebviewHeight = false; + rpl::variable _increaseWebviewWidth = false; + rpl::variable _materialSwitches = true; + rpl::variable _removeMessageTail = false; + rpl::variable _disableNotificationsDelay = false; + rpl::variable _localPremium = false; + rpl::variable _showChannelReactions = true; + rpl::variable _showGroupReactions = true; + rpl::variable _appIcon; + rpl::variable _simpleQuotesAndReplies = false; + rpl::variable _hideFastShare = false; + rpl::variable _replaceBottomInfoWithIcons = true; + rpl::variable _deletedMark = QString::fromUtf8("🧹"); + rpl::variable _editedMark; + rpl::variable _recentStickersCount = 100; + rpl::variable _showReactionsPanelInContextMenu = ContextMenuVisibility::Visible; + rpl::variable _showViewsPanelInContextMenu = ContextMenuVisibility::Visible; + rpl::variable _showHideMessageInContextMenu = ContextMenuVisibility::Hidden; + rpl::variable _showUserMessagesInContextMenu = ContextMenuVisibility::VisibleWithModifier; + rpl::variable _showMessageDetailsInContextMenu = ContextMenuVisibility::VisibleWithModifier; + rpl::variable _showRepeatMessageInContextMenu = ContextMenuVisibility::Hidden; + rpl::variable _showAddFilterInContextMenu = ContextMenuVisibility::Visible; + rpl::variable _showAttachButtonInMessageField = true; + rpl::variable _showCommandsButtonInMessageField = true; + rpl::variable _showEmojiButtonInMessageField = true; + rpl::variable _showMicrophoneButtonInMessageField = true; + rpl::variable _showAutoDeleteButtonInMessageField = true; + rpl::variable _showAttachPopup = true; + rpl::variable _showEmojiPopup = true; + rpl::variable _showMyProfileInDrawer = true; + rpl::variable _showBotsInDrawer = true; + rpl::variable _showNewGroupInDrawer = true; + rpl::variable _showNewChannelInDrawer = true; + rpl::variable _showContactsInDrawer = true; + rpl::variable _showCallsInDrawer = true; + rpl::variable _showSavedMessagesInDrawer = true; + rpl::variable _showLReadToggleInDrawer = false; + rpl::variable _showSReadToggleInDrawer = true; + rpl::variable _showNightModeToggleInDrawer = true; + rpl::variable _showGhostToggleInDrawer = true; + rpl::variable _showStreamerToggleInDrawer = false; + rpl::variable _showGhostToggleInTray = true; + rpl::variable _showStreamerToggleInTray = false; + rpl::variable _monoFont; + rpl::variable _hideNotificationCounters = false; + rpl::variable _hideNotificationBadge = false; + rpl::variable _hideAllChatsFolder = false; + rpl::variable _channelBottomButton = ChannelBottomButton::DiscussWithFallback; + rpl::variable _quickAdminShortcuts = true; + rpl::variable _showPeerId = PeerIdDisplay::BotApi; + rpl::variable _showMessageSeconds = false; + rpl::variable _showMessageShot = true; + rpl::variable _filterZalgo = true; + rpl::variable _stickerConfirmation = false; + rpl::variable _gifConfirmation = false; + rpl::variable _voiceConfirmation = false; + rpl::variable _translationProvider = QString("telegram"); + rpl::variable _adaptiveCoverColor = true; + rpl::variable _crashReporting = true; -rpl::producer get_deletedMarkReactive(); -rpl::producer get_editedMarkReactive(); + rpl::variable _useGlobalGhostMode = true; + std::map> _ghostAccounts; +}; -rpl::producer get_showPeerIdReactive(); - -rpl::producer get_translationProviderReactive(); - -bool isGhostModeActive(); -bool isUseScheduledMessages(); - -rpl::producer get_ghostModeEnabledReactive(); - -void fire_filtersUpdate(); -rpl::producer<> get_filtersUpdate(); - -void triggerHistoryUpdate(); -rpl::producer<> get_historyUpdateReactive(); - -} +void to_json(nlohmann::json &j, const AyuSettings &s); +void from_json(const nlohmann::json &j, AyuSettings &s); diff --git a/Telegram/SourceFiles/ayu/ayu_worker.cpp b/Telegram/SourceFiles/ayu/ayu_worker.cpp index 1bc92c6cdb..f2b5c3916b 100644 --- a/Telegram/SourceFiles/ayu/ayu_worker.cpp +++ b/Telegram/SourceFiles/ayu/ayu_worker.cpp @@ -54,11 +54,6 @@ void runOnce() { lateInit(); } - const auto &settings = AyuSettings::getInstance(); - if (!settings.sendOfflinePacketAfterOnline) { - return; - } - const auto t = base::unixtime::now(); for (const auto &[index, account] : Core::App().domain().accounts()) { @@ -69,6 +64,11 @@ void runOnce() { state[id] = true; } + const auto &ghost = AyuSettings::ghost(session); + if (!ghost.sendOfflinePacketAfterOnline()) { + continue; + } + if (state[id] || session->user()->lastseen().isOnline(t)) { session->api().request(MTPaccount_UpdateStatus( MTP_bool(true) diff --git a/Telegram/SourceFiles/ayu/features/filters/filters_cache_controller.cpp b/Telegram/SourceFiles/ayu/features/filters/filters_cache_controller.cpp index 8563d9bd60..3b35a481cd 100644 --- a/Telegram/SourceFiles/ayu/features/filters/filters_cache_controller.cpp +++ b/Telegram/SourceFiles/ayu/features/filters/filters_cache_controller.cpp @@ -15,11 +15,22 @@ #include "data/data_session.h" #include "history/history.h" #include "history/history_item.h" +#include "rpl/event_stream.h" static std::mutex mutex; namespace FiltersCacheController { +rpl::event_stream<> filtersUpdateStream; + +void fireUpdate() { + filtersUpdateStream.fire({}); +} + +rpl::producer<> updates() { + return filtersUpdateStream.events(); +} + std::optional> sharedPatterns; std::optional>> patternsByDialogId; diff --git a/Telegram/SourceFiles/ayu/features/filters/filters_cache_controller.h b/Telegram/SourceFiles/ayu/features/filters/filters_cache_controller.h index 0fc4a7e9cc..37c9e67a83 100644 --- a/Telegram/SourceFiles/ayu/features/filters/filters_cache_controller.h +++ b/Telegram/SourceFiles/ayu/features/filters/filters_cache_controller.h @@ -8,6 +8,7 @@ #include "filters_controller.h" #include "ayu/data/entities.h" +#include "rpl/producer.h" namespace Data { struct Group; @@ -17,6 +18,9 @@ using namespace FiltersController; namespace FiltersCacheController { +void fireUpdate(); +[[nodiscard]] rpl::producer<> updates(); + void rebuildCache(); std::unordered_map> buildExclusions( diff --git a/Telegram/SourceFiles/ayu/features/filters/filters_controller.cpp b/Telegram/SourceFiles/ayu/features/filters/filters_controller.cpp index 970a38a252..1be0274ccb 100644 --- a/Telegram/SourceFiles/ayu/features/filters/filters_controller.cpp +++ b/Telegram/SourceFiles/ayu/features/filters/filters_controller.cpp @@ -26,7 +26,6 @@ #include "history/history_item_components.h" #include "filters_utils.h" -#include "shadow_ban_utils.h" #include "ayu/utils/telegram_helpers.h" namespace FiltersController { @@ -91,7 +90,7 @@ std::optional isFiltered(const QString &str, uint64 dialogId) { bool isEnabled(not_null peer) { const auto &settings = AyuSettings::getInstance(); - return settings.filtersEnabled && (settings.filtersEnabledInChats || peer->isBroadcast()); + return settings.filtersEnabled() && (settings.filtersEnabledInChats() || peer->isBroadcast()); } bool isBlocked(const not_null item) { @@ -115,16 +114,16 @@ bool isBlocked(const not_null item) { return false; }(); - return settings.filtersEnabled && + return settings.filtersEnabled() && ( - ((item->from()->isUser() || item->from()->isBroadcast()) && ShadowBanUtils::isShadowBanned(getDialogIdFromPeer(item->from()))) || - (settings.hideFromBlocked && blocked) + ((item->from()->isUser() || item->from()->isBroadcast()) && settings.isShadowBanned(getDialogIdFromPeer(item->from()))) || + (settings.hideFromBlocked() && blocked) ); } bool filtered(const not_null item) { const auto &settings = AyuSettings::getInstance(); - if (!settings.filtersEnabled) { + if (!settings.filtersEnabled()) { return false; } @@ -155,7 +154,7 @@ bool filtered(const not_null item) { void invalidate(not_null item) { const auto &settings = AyuSettings::getInstance(); - if (!settings.filtersEnabled) { + if (!settings.filtersEnabled()) { return; } diff --git a/Telegram/SourceFiles/ayu/features/filters/filters_utils.cpp b/Telegram/SourceFiles/ayu/features/filters/filters_utils.cpp index 4bd3ede3b9..900653ead9 100644 --- a/Telegram/SourceFiles/ayu/features/filters/filters_utils.cpp +++ b/Telegram/SourceFiles/ayu/features/filters/filters_utils.cpp @@ -641,6 +641,6 @@ void FilterUtils::applyChanges(const ApplyChanges &changes) { FiltersCacheController::rebuildCache(); crl::on_main([] { - AyuSettings::fire_filtersUpdate(); + FiltersCacheController::fireUpdate(); }); } diff --git a/Telegram/SourceFiles/ayu/features/filters/shadow_ban_utils.cpp b/Telegram/SourceFiles/ayu/features/filters/shadow_ban_utils.cpp deleted file mode 100644 index f3792d4ac3..0000000000 --- a/Telegram/SourceFiles/ayu/features/filters/shadow_ban_utils.cpp +++ /dev/null @@ -1,38 +0,0 @@ -// This is the source code of AyuGram for Desktop. -// -// We do not and cannot prevent the use of our code, -// but be respectful and credit the original author. -// -// Copyright @Radolyn, 2025 -#include "shadow_ban_utils.h" - -#include - -#include "filters_cache_controller.h" -#include "ayu/ayu_settings.h" -#include "ayu/data/entities.h" - -void ShadowBanUtils::addShadowBan(ID userId) { - auto &settings = AyuSettings::getInstance(); - if (settings.shadowBanIds.insert(userId).second) { - setShadowBanList(); - } -} - -void ShadowBanUtils::removeShadowBan(ID userId) { - auto &settings = AyuSettings::getInstance(); - if (settings.shadowBanIds.erase(userId) > 0) { - setShadowBanList(); - } -} - -bool ShadowBanUtils::isShadowBanned(ID userId) { - const auto &settings = AyuSettings::getInstance(); - return settings.shadowBanIds.contains(userId); -} - -void ShadowBanUtils::setShadowBanList() { - FiltersCacheController::rebuildCache(); - AyuSettings::fire_filtersUpdate(); - AyuSettings::save(); -} diff --git a/Telegram/SourceFiles/ayu/features/filters/shadow_ban_utils.h b/Telegram/SourceFiles/ayu/features/filters/shadow_ban_utils.h deleted file mode 100644 index de250f91e3..0000000000 --- a/Telegram/SourceFiles/ayu/features/filters/shadow_ban_utils.h +++ /dev/null @@ -1,21 +0,0 @@ -// This is the source code of AyuGram for Desktop. -// -// We do not and cannot prevent the use of our code, -// but be respectful and credit the original author. -// -// Copyright @Radolyn, 2025 -#pragma once - -#include - -class ShadowBanUtils { -public: - static void addShadowBan(long long userId); - static void removeShadowBan(long long userId); - static bool isShadowBanned(long long userId); - -private: - ShadowBanUtils() = delete; - - static void setShadowBanList(); -}; diff --git a/Telegram/SourceFiles/ayu/features/translator/ayu_translator.cpp b/Telegram/SourceFiles/ayu/features/translator/ayu_translator.cpp index 7bfc60fe4d..0b125ea792 100644 --- a/Telegram/SourceFiles/ayu/features/translator/ayu_translator.cpp +++ b/Telegram/SourceFiles/ayu/features/translator/ayu_translator.cpp @@ -228,9 +228,9 @@ mtpRequestId TranslateManager::performTranslation(Builder &req) { if (const auto it = _pending.find(id); it != _pending.end()) { const auto &settings = AyuSettings::getInstance(); - if (settings.translationProvider == "telegram") { + if (settings.translationProvider() == "telegram") { it->second.cancel = TelegramTranslator::instance().startTranslation(args); - } else if (settings.translationProvider == "yandex") { + } else if (settings.translationProvider() == "yandex") { it->second.cancel = YandexTranslator::instance().startTranslation(args); } else { it->second.cancel = GoogleTranslator::instance().startTranslation(args); diff --git a/Telegram/SourceFiles/ayu/ui/ayu_logo.cpp b/Telegram/SourceFiles/ayu/ui/ayu_logo.cpp index f289850b54..c40fb1afd8 100644 --- a/Telegram/SourceFiles/ayu/ui/ayu_logo.cpp +++ b/Telegram/SourceFiles/ayu/ui/ayu_logo.cpp @@ -31,7 +31,7 @@ void loadAppIco() { f.remove(); } f.close(); - QFile::copy(qsl(":/gui/art/ayu/%1/app_icon.ico").arg(settings.appIcon), tempIconPath); + QFile::copy(qsl(":/gui/art/ayu/%1/app_icon.ico").arg(settings.appIcon()), tempIconPath); } QImage CreateImage(const QString &name, const QSize resultImageSize, const int padding = 0) { @@ -88,10 +88,10 @@ QImage CreateImage(const QString &name, const QSize resultImageSize, const int p void loadIcons() { const auto &settings = AyuSettings::getInstance(); - if (LAST_LOADED_NAME != settings.appIcon) { - LAST_LOADED_NAME = settings.appIcon; - LAST_LOADED = CreateImage(settings.appIcon, Size(256)); - LAST_LOADED_PAD = CreateImage(settings.appIcon, Size(256), 12); + if (LAST_LOADED_NAME != settings.appIcon()) { + LAST_LOADED_NAME = settings.appIcon(); + LAST_LOADED = CreateImage(settings.appIcon(), Size(256)); + LAST_LOADED_PAD = CreateImage(settings.appIcon(), Size(256), 12); } } diff --git a/Telegram/SourceFiles/ayu/ui/ayu_styles.style b/Telegram/SourceFiles/ayu/ui/ayu_styles.style index ea972ea2ee..a1444c9d50 100644 --- a/Telegram/SourceFiles/ayu/ui/ayu_styles.style +++ b/Telegram/SourceFiles/ayu/ui/ayu_styles.style @@ -106,4 +106,13 @@ maxPluginDescriptionHeight: 400px; pluginVersionAuthorLabel: FlatLabel(boxLabel) { align: align(center); } -pluginChipSkip: 6px; \ No newline at end of file +pluginChipSkip: 6px; + +ghostPickerArrow: icon{{ "info/edit/expand_arrow_small", windowActiveTextFg }}; + +ghostPickerButton: LinkButton(defaultLinkButton) { + color: windowActiveTextFg; + overColor: windowActiveTextFg; + font: font(boxFontSize); + overFont: font(boxFontSize); +} \ No newline at end of file diff --git a/Telegram/SourceFiles/ayu/ui/boxes/message_shot_box.cpp b/Telegram/SourceFiles/ayu/ui/boxes/message_shot_box.cpp index c5852fd81d..06ea85ffd8 100644 --- a/Telegram/SourceFiles/ayu/ui/boxes/message_shot_box.cpp +++ b/Telegram/SourceFiles/ayu/ui/boxes/message_shot_box.cpp @@ -39,7 +39,7 @@ void MessageShotBox::setupContent() { _selectedPalette = std::make_shared(); const auto &settings = AyuSettings::getInstance(); - const auto savedShowColorfulReplies = !settings.simpleQuotesAndReplies; + const auto savedShowColorfulReplies = !settings.simpleQuotesAndReplies(); using namespace Settings; @@ -164,7 +164,7 @@ void MessageShotBox::setupContent() { ) | on_next( [=](bool enabled) { - AyuSettings::set_simpleQuotesAndReplies(!enabled); + AyuSettings::getInstance().setSimpleQuotesAndReplies(!enabled); _config.st = std::make_shared(_config.st.get()); updatePreview(); @@ -208,7 +208,7 @@ void MessageShotBox::setupContent() { AyuFeatures::MessageShot::resetDefaultSelected(); AyuFeatures::MessageShot::resetShotConfig(); - AyuSettings::set_simpleQuotesAndReplies(!savedShowColorfulReplies); + AyuSettings::getInstance().setSimpleQuotesAndReplies(!savedShowColorfulReplies); }, content->lifetime()); diff --git a/Telegram/SourceFiles/ayu/ui/components/icon_picker.cpp b/Telegram/SourceFiles/ayu/ui/components/icon_picker.cpp index 8a64e376ce..101f6f3ea8 100644 --- a/Telegram/SourceFiles/ayu/ui/components/icon_picker.cpp +++ b/Telegram/SourceFiles/ayu/ui/components/icon_picker.cpp @@ -145,8 +145,8 @@ void IconPicker::mousePressEvent(QMouseEvent *e) { break; } - if (settings.appIcon != iconName) { - wasSelected = settings.appIcon; + if (settings.appIcon() != iconName) { + wasSelected = settings.appIcon(); animation.start( [=] { @@ -158,7 +158,7 @@ void IconPicker::mousePressEvent(QMouseEvent *e) { anim::easeOutCubic ); - AyuSettings::set_appIcon(iconName); + AyuSettings::getInstance().setAppIcon(iconName); changed = true; break; } @@ -167,7 +167,6 @@ void IconPicker::mousePressEvent(QMouseEvent *e) { } if (changed) { - AyuSettings::save(); applyIcon(); repaint(); diff --git a/Telegram/SourceFiles/ayu/ui/components/saved_music.cpp b/Telegram/SourceFiles/ayu/ui/components/saved_music.cpp index bb72a826e5..13bad78768 100644 --- a/Telegram/SourceFiles/ayu/ui/components/saved_music.cpp +++ b/Telegram/SourceFiles/ayu/ui/components/saved_music.cpp @@ -274,7 +274,7 @@ void AyuMusicButton::makeCover() { } QColor bgColor; - if (cover.noCover || !settings.adaptiveCoverColor) { + if (cover.noCover || !settings.adaptiveCoverColor()) { bgColor = GetNoCoverBgColor(overrideBg); } else { if (const auto extractedColor = ExtractColorFromCover(cover.pixToBg)) { @@ -302,7 +302,7 @@ void AyuMusicButton::makeCover() { const auto &settings2 = AyuSettings::getInstance(); const auto &cover2 = *strong->_currentCover; - if (!cover2.noCover && settings2.adaptiveCoverColor && !cover2.pix.isNull()) { + if (!cover2.noCover && settings2.adaptiveCoverColor() && !cover2.pix.isNull()) { strong->_title->setTextColorOverride(Qt::white); strong->_performer->setTextColorOverride(performerColor); } else { @@ -333,7 +333,7 @@ void AyuMusicButton::paintEvent(QPaintEvent *e) { const auto &settings = AyuSettings::getInstance(); const auto cover = _currentCover.value(); - if (cover.noCover || !settings.adaptiveCoverColor) { + if (cover.noCover || !settings.adaptiveCoverColor()) { p.fillRect(e->rect(), cover.bg); paintRipple(p, QPoint()); } else { diff --git a/Telegram/SourceFiles/ayu/ui/context_menu/context_menu.cpp b/Telegram/SourceFiles/ayu/ui/context_menu/context_menu.cpp index 568b7f9e35..49434b1589 100644 --- a/Telegram/SourceFiles/ayu/ui/context_menu/context_menu.cpp +++ b/Telegram/SourceFiles/ayu/ui/context_menu/context_menu.cpp @@ -12,7 +12,6 @@ #include "ayu/ayu_settings.h" #include "ayu/ayu_state.h" #include "ayu/data/messages_storage.h" -#include "ayu/features/filters/shadow_ban_utils.h" #include "ayu/features/forward/ayu_forward.h" #include "ayu/ui/context_menu/menu_item_subtext.h" #include "ayu/utils/qt_key_modifiers_extended.h" @@ -186,8 +185,9 @@ Fn DeleteMyMessagesHandler(not_null controll } -bool needToShowItem(int state) { - return state == 1 || (state == 2 && base::IsExtendedContextMenuModifierPressed()); +bool needToShowItem(ContextMenuVisibility state) { + return state == ContextMenuVisibility::Visible + || (state == ContextMenuVisibility::VisibleWithModifier && base::IsExtendedContextMenuModifierPressed()); } void AddDeletedMessagesActions(PeerData *peerData, @@ -325,7 +325,7 @@ void AddOpenChannelAction(PeerData *peerData, void AddShadowBanAction(PeerData *peerData, const Window::PeerMenuCallback &addCallback) { const auto &settings = AyuSettings::getInstance(); - if (!peerData || !(peerData->isUser() || peerData->isBroadcast()) || !settings.filtersEnabled) { + if (!peerData || !(peerData->isUser() || peerData->isBroadcast()) || !settings.filtersEnabled()) { return; } @@ -336,13 +336,13 @@ void AddShadowBanAction(PeerData *peerData, } const auto realId = getDialogIdFromPeer(peerData); - const auto shadowBanned = ShadowBanUtils::isShadowBanned(realId); + const auto shadowBanned = AyuSettings::getInstance().isShadowBanned(realId); const auto toggleShadowBan = [=] { if (shadowBanned) { - ShadowBanUtils::removeShadowBan(realId); + AyuSettings::getInstance().removeShadowBan(realId); } else { - ShadowBanUtils::addShadowBan(realId); + AyuSettings::getInstance().addShadowBan(realId); } }; @@ -411,7 +411,7 @@ void AddHistoryAction(not_null menu, HistoryItem *item) { void AddHideMessageAction(not_null menu, HistoryItem *item) { const auto &settings = AyuSettings::getInstance(); - if (!needToShowItem(settings.showHideMessageInContextMenu)) { + if (!needToShowItem(settings.showHideMessageInContextMenu())) { return; } @@ -439,7 +439,7 @@ void AddHideMessageAction(not_null menu, HistoryItem *item) { void AddUserMessagesAction(not_null menu, HistoryItem *item) { const auto &settings = AyuSettings::getInstance(); - if (!needToShowItem(settings.showUserMessagesInContextMenu)) { + if (!needToShowItem(settings.showUserMessagesInContextMenu())) { return; } @@ -464,7 +464,7 @@ void AddUserMessagesAction(not_null menu, HistoryItem *item) { void AddMessageDetailsAction(not_null menu, HistoryItem *item) { const auto &settings = AyuSettings::getInstance(); - if (!needToShowItem(settings.showMessageDetailsInContextMenu)) { + if (!needToShowItem(settings.showMessageDetailsInContextMenu())) { return; } @@ -675,7 +675,7 @@ void AddMessageDetailsAction(not_null menu, HistoryItem *item) { void AddRepeatMessageAction(not_null menu, HistoryItem *item) { const auto &settings = AyuSettings::getInstance(); - if (!needToShowItem(settings.showRepeatMessageInContextMenu)) { + if (!needToShowItem(settings.showRepeatMessageInContextMenu())) { return; } @@ -747,8 +747,8 @@ void AddReadUntilAction(not_null menu, HistoryItem *item) { return; } - const auto &settings = AyuSettings::getInstance(); - if (settings.sendReadMessages) { + const auto &ghost = AyuSettings::ghost(&item->history()->session()); + if (ghost.sendReadMessages()) { return; } @@ -830,7 +830,7 @@ void AddCreateFilterAction(not_null menu, HistoryItem *item, const QString &selectedText) { const auto &settings = AyuSettings::getInstance(); - if (!needToShowItem(settings.showAddFilterInContextMenu) || !settings.filtersEnabled) { + if (!needToShowItem(settings.showAddFilterInContextMenu()) || !settings.filtersEnabled()) { return; } diff --git a/Telegram/SourceFiles/ayu/ui/context_menu/context_menu.h b/Telegram/SourceFiles/ayu/ui/context_menu/context_menu.h index 2da20de8e5..09f1ea5d9e 100644 --- a/Telegram/SourceFiles/ayu/ui/context_menu/context_menu.h +++ b/Telegram/SourceFiles/ayu/ui/context_menu/context_menu.h @@ -11,9 +11,11 @@ #include "window/window_peer_menu.h" #include "window/window_session_controller.h" +#include "ayu/ayu_settings.h" + namespace AyuUi { -bool needToShowItem(int state); +bool needToShowItem(ContextMenuVisibility state); void AddDeletedMessagesActions(PeerData *peerData, Data::Thread *thread, diff --git a/Telegram/SourceFiles/ayu/ui/settings/filters/edit_filter.cpp b/Telegram/SourceFiles/ayu/ui/settings/filters/edit_filter.cpp index 7038d7f1fd..621e5b6fe7 100644 --- a/Telegram/SourceFiles/ayu/ui/settings/filters/edit_filter.cpp +++ b/Telegram/SourceFiles/ayu/ui/settings/filters/edit_filter.cpp @@ -217,7 +217,7 @@ void RegexEditBuilder( if (onDone) { onDone(newFilter); } - AyuSettings::fire_filtersUpdate(); + FiltersCacheController::fireUpdate(); if (showToast) { const auto onClick = [=](const auto &...) mutable @@ -226,7 +226,7 @@ void RegexEditBuilder( AyuDatabase::updateRegexFilter(newFilter); FiltersCacheController::rebuildCache(); - AyuSettings::fire_filtersUpdate(); + FiltersCacheController::fireUpdate(); return true; }; diff --git a/Telegram/SourceFiles/ayu/ui/settings/filters/per_dialog_filter.cpp b/Telegram/SourceFiles/ayu/ui/settings/filters/per_dialog_filter.cpp index d131984b9c..1d0c90aec5 100644 --- a/Telegram/SourceFiles/ayu/ui/settings/filters/per_dialog_filter.cpp +++ b/Telegram/SourceFiles/ayu/ui/settings/filters/per_dialog_filter.cpp @@ -12,7 +12,6 @@ #include "settings_filters_list.h" #include "ayu/ayu_settings.h" #include "ayu/data/ayu_database.h" -#include "ayu/features/filters/shadow_ban_utils.h" #include "ayu/utils/telegram_helpers.h" #include "data/data_peer.h" #include "data/data_session.h" @@ -67,7 +66,7 @@ Main::Session &PerDialogFiltersListController::session() const { void PerDialogFiltersListController::prepareShadowBan() { const auto &settings = AyuSettings::getInstance(); - const auto &shadowBanned = settings.shadowBanIds; + const auto &shadowBanned = settings.shadowBanIds(); for (const auto id : shadowBanned) { auto peerId = PeerId(PeerIdHelper(abs(id))); @@ -146,10 +145,10 @@ void PerDialogFiltersListController::rowClicked(not_null peer) { tr::lng_theme_delete(tr::now), [=] { - if (ShadowBanUtils::isShadowBanned(did)) { - ShadowBanUtils::removeShadowBan(did); + if (AyuSettings::getInstance().isShadowBanned(did)) { + AyuSettings::getInstance().removeShadowBan(did); } else { - ShadowBanUtils::addShadowBan(did); + AyuSettings::getInstance().addShadowBan(did); } }, &st::menuIconDelete); diff --git a/Telegram/SourceFiles/ayu/ui/settings/filters/settings_filters_list.cpp b/Telegram/SourceFiles/ayu/ui/settings/filters/settings_filters_list.cpp index 4eacaf977c..f86deff802 100644 --- a/Telegram/SourceFiles/ayu/ui/settings/filters/settings_filters_list.cpp +++ b/Telegram/SourceFiles/ayu/ui/settings/filters/settings_filters_list.cpp @@ -11,6 +11,7 @@ #include "per_dialog_filter.h" #include "ayu/ayu_settings.h" #include "ayu/data/ayu_database.h" +#include "ayu/ui/settings/settings_ayu_utils.h" #include "ayu/features/filters/filters_cache_controller.h" #include "ayu/features/filters/filters_utils.h" #include "ayu/ui/components/icon_picker.h" @@ -118,7 +119,7 @@ void AyuFiltersList::addNewFilter(const RegexFilter &filter, bool exclusion) { state->enabled = !state->enabled; AyuDatabase::updateRegexFilter(*state); FiltersCacheController::rebuildCache(); - AyuSettings::fire_filtersUpdate(); + FiltersCacheController::fireUpdate(); }, state->enabled ? &st::menuIconBlock : &st::menuIconUnblock); @@ -131,7 +132,7 @@ void AyuFiltersList::addNewFilter(const RegexFilter &filter, bool exclusion) { AyuDatabase::deleteFilter(state->id); AyuDatabase::deleteExclusionsByFilterId(state->id); FiltersCacheController::rebuildCache(); - AyuSettings::fire_filtersUpdate(); + FiltersCacheController::fireUpdate(); }, &st::menuIconDelete); @@ -163,7 +164,7 @@ void AyuFiltersList::addNewFilter(const RegexFilter &filter, bool exclusion) { AyuDatabase::addRegexExclusion(newExclusion); FiltersCacheController::rebuildCache(); - AyuSettings::fire_filtersUpdate(); + FiltersCacheController::fireUpdate(); controller->dialogId = dialogId; controller->showExclude = true; @@ -183,7 +184,7 @@ void AyuFiltersList::addNewFilter(const RegexFilter &filter, bool exclusion) { AyuDatabase::deleteExclusion(dialogId.value(), state->id); FiltersCacheController::rebuildCache(); - AyuSettings::fire_filtersUpdate(); + FiltersCacheController::fireUpdate(); }, &st::menuIconDelete); @@ -246,9 +247,7 @@ void AyuFiltersList::initializeSharedFilters( if (!exclusions.empty()) { if (!filters.empty()) { - AddSkip(container); - AddDivider(container); - AddSkip(container); + AddSectionDivider(container); } excludedTitle = AddSubsectionTitle(container, tr::ayu_RegexFiltersExcluded()); @@ -278,7 +277,7 @@ void AyuFiltersList::initializeShadowBan(not_null container QMargins(0, -st::peerListBox.padding.top(), 0, -st::peerListBox.padding.bottom())); // delegate is not initialized at this moment - if (AyuSettings::getInstance().shadowBanIds.size() > 0) { + if (AyuSettings::getInstance().shadowBanIds().size() > 0) { AddSkip(container); filtersTitle = AddSubsectionTitle(container, tr::ayu_RegexFiltersHeader()); diff --git a/Telegram/SourceFiles/ayu/ui/settings/settings_appearance.cpp b/Telegram/SourceFiles/ayu/ui/settings/settings_appearance.cpp index 59028bb2d4..bd1a4fd218 100644 --- a/Telegram/SourceFiles/ayu/ui/settings/settings_appearance.cpp +++ b/Telegram/SourceFiles/ayu/ui/settings/settings_appearance.cpp @@ -10,6 +10,7 @@ #include "ayu/ayu_settings.h" #include "ayu/ui/boxes/font_selector.h" #include "ayu/ui/components/icon_picker.h" +#include "ayu/ui/settings/settings_ayu_utils.h" #include "inline_bots/bot_attach_web_view.h" #include "main/main_session.h" #include "settings/settings_common.h" @@ -59,28 +60,9 @@ void SetupAppIcon(not_null container) { st::settingsCheckboxPadding); #ifdef Q_OS_WIN - auto *settings = &AyuSettings::getInstance(); - AddDivider(container); AddSkip(container); - AddButtonWithIcon( - container, - tr::ayu_HideNotificationBadge(), - st::settingsButtonNoIcon - )->toggleOn( - rpl::single(settings->hideNotificationBadge) - )->toggledValue( - ) | rpl::filter( - [=](bool enabled) - { - return (enabled != settings->hideNotificationBadge); - }) | rpl::on_next( - [=](bool enabled) - { - AyuSettings::set_hideNotificationBadge(enabled); - AyuSettings::save(); - }, - container->lifetime()); + AddSettingToggle(container, tr::ayu_HideNotificationBadge(), &AyuSettings::hideNotificationBadge, &AyuSettings::setHideNotificationBadge); AddSkip(container); AddDividerText(container, tr::ayu_HideNotificationBadgeDescription()); AddSkip(container); @@ -92,68 +74,15 @@ void SetupAppearance(not_null container, not_nulltoggleOn( - rpl::single(settings->materialSwitches) - )->toggledValue( - ) | rpl::filter( - [=](bool enabled) - { - return (enabled != settings->materialSwitches); - }) | rpl::on_next( - [=](bool enabled) - { - AyuSettings::set_materialSwitches(enabled); - AyuSettings::save(); - }, - container->lifetime()); - - AddButtonWithIcon( - container, - tr::ayu_RemoveMessageTail(), - st::settingsButtonNoIcon - )->toggleOn( - rpl::single(settings->removeMessageTail) - )->toggledValue( - ) | rpl::filter( - [=](bool enabled) - { - return (enabled != settings->removeMessageTail); - }) | on_next( - [=](bool enabled) - { - AyuSettings::set_removeMessageTail(enabled); - AyuSettings::save(); - }, - container->lifetime()); - - AddButtonWithIcon( - container, - tr::ayu_DisableCustomBackgrounds(), - st::settingsButtonNoIcon - )->toggleOn( - rpl::single(settings->disableCustomBackgrounds) - )->toggledValue( - ) | rpl::filter( - [=](bool enabled) - { - return (enabled != settings->disableCustomBackgrounds); - }) | rpl::on_next( - [=](bool enabled) - { - AyuSettings::set_disableCustomBackgrounds(enabled); - AyuSettings::save(); - }, - container->lifetime()); + AddSettingToggle(container, tr::ayu_MaterialSwitches(), &AyuSettings::materialSwitches, &AyuSettings::setMaterialSwitches); + AddSettingToggle(container, tr::ayu_RemoveMessageTail(), &AyuSettings::removeMessageTail, &AyuSettings::setRemoveMessageTail); + AddSettingToggle(container, tr::ayu_DisableCustomBackgrounds(), &AyuSettings::disableCustomBackgrounds, &AyuSettings::setDisableCustomBackgrounds); const auto monoButton = AddButtonWithLabel( container, tr::ayu_MonospaceFont(), rpl::single( - settings->monoFont.isEmpty() ? tr::ayu_FontDefault(tr::now) : settings->monoFont + settings->monoFont().isEmpty() ? tr::ayu_FontDefault(tr::now) : settings->monoFont() ), st::settingsButtonNoIcon); const auto monoGuard = Ui::CreateChild(monoButton.get()); @@ -163,366 +92,60 @@ void SetupAppearance(not_null container, not_null container) { - auto *settings = &AyuSettings::getInstance(); - AddSubsectionTitle(container, tr::ayu_ChatFoldersHeader()); - AddButtonWithIcon( - container, - tr::ayu_HideNotificationCounters(), - st::settingsButtonNoIcon - )->toggleOn( - rpl::single(settings->hideNotificationCounters) - )->toggledValue( - ) | rpl::filter( - [=](bool enabled) - { - return (enabled != settings->hideNotificationCounters); - }) | rpl::on_next( - [=](bool enabled) - { - AyuSettings::set_hideNotificationCounters(enabled); - AyuSettings::save(); - }, - container->lifetime()); + AddSettingToggle(container, tr::ayu_HideNotificationCounters(), &AyuSettings::hideNotificationCounters, &AyuSettings::setHideNotificationCounters); + AddSettingToggle(container, tr::ayu_HideAllChats(), &AyuSettings::hideAllChatsFolder, &AyuSettings::setHideAllChatsFolder); - AddButtonWithIcon( - container, - tr::ayu_HideAllChats(), - st::settingsButtonNoIcon - )->toggleOn( - rpl::single(settings->hideAllChatsFolder) - )->toggledValue( - ) | rpl::filter( - [=](bool enabled) - { - return (enabled != settings->hideAllChatsFolder); - }) | rpl::on_next( - [=](bool enabled) - { - AyuSettings::set_hideAllChatsFolder(enabled); - AyuSettings::save(); - }, - container->lifetime()); - - AddSkip(container); - AddDivider(container); - AddSkip(container); + AddSectionDivider(container); } void SetupDrawerElements(not_null container, not_null controller) { - auto *settings = &AyuSettings::getInstance(); - AddSubsectionTitle(container, tr::ayu_DrawerElementsHeader()); - AddButtonWithIcon( - container, - tr::lng_menu_my_profile(), - st::settingsButton, - {&st::menuIconProfile} - )->toggleOn( - rpl::single(settings->showMyProfileInDrawer) - )->toggledValue( - ) | rpl::filter( - [=](bool enabled) - { - return (enabled != settings->showMyProfileInDrawer); - }) | rpl::on_next( - [=](bool enabled) - { - AyuSettings::set_showMyProfileInDrawer(enabled); - AyuSettings::save(); - }, - container->lifetime()); + AddSettingToggle(container, tr::lng_menu_my_profile(), &AyuSettings::showMyProfileInDrawer, &AyuSettings::setShowMyProfileInDrawer, st::menuIconProfile); if (HasDrawerBots(controller)) { - AddButtonWithIcon( - container, - tr::lng_filters_type_bots(), - st::settingsButton, - {&st::menuIconBot} - )->toggleOn( - rpl::single(settings->showBotsInDrawer) - )->toggledValue( - ) | rpl::filter( - [=](bool enabled) - { - return (enabled != settings->showBotsInDrawer); - }) | rpl::on_next( - [=](bool enabled) - { - AyuSettings::set_showBotsInDrawer(enabled); - AyuSettings::save(); - }, - container->lifetime()); + AddSettingToggle(container, tr::lng_filters_type_bots(), &AyuSettings::showBotsInDrawer, &AyuSettings::setShowBotsInDrawer, st::menuIconBot); } - AddButtonWithIcon( - container, - tr::lng_create_group_title(), - st::settingsButton, - {&st::menuIconGroups} - )->toggleOn( - rpl::single(settings->showNewGroupInDrawer) - )->toggledValue( - ) | rpl::filter( - [=](bool enabled) - { - return (enabled != settings->showNewGroupInDrawer); - }) | rpl::on_next( - [=](bool enabled) - { - AyuSettings::set_showNewGroupInDrawer(enabled); - AyuSettings::save(); - }, - container->lifetime()); - - AddButtonWithIcon( - container, - tr::lng_create_channel_title(), - st::settingsButton, - {&st::menuIconChannel} - )->toggleOn( - rpl::single(settings->showNewChannelInDrawer) - )->toggledValue( - ) | rpl::filter( - [=](bool enabled) - { - return (enabled != settings->showNewChannelInDrawer); - }) | rpl::on_next( - [=](bool enabled) - { - AyuSettings::set_showNewChannelInDrawer(enabled); - AyuSettings::save(); - }, - container->lifetime()); - - AddButtonWithIcon( - container, - tr::lng_menu_contacts(), - st::settingsButton, - {&st::menuIconUserShow} - )->toggleOn( - rpl::single(settings->showContactsInDrawer) - )->toggledValue( - ) | rpl::filter( - [=](bool enabled) - { - return (enabled != settings->showContactsInDrawer); - }) | rpl::on_next( - [=](bool enabled) - { - AyuSettings::set_showContactsInDrawer(enabled); - AyuSettings::save(); - }, - container->lifetime()); - - AddButtonWithIcon( - container, - tr::lng_menu_calls(), - st::settingsButton, - {&st::menuIconPhone} - )->toggleOn( - rpl::single(settings->showCallsInDrawer) - )->toggledValue( - ) | rpl::filter( - [=](bool enabled) - { - return (enabled != settings->showCallsInDrawer); - }) | rpl::on_next( - [=](bool enabled) - { - AyuSettings::set_showCallsInDrawer(enabled); - AyuSettings::save(); - }, - container->lifetime()); - - AddButtonWithIcon( - container, - tr::lng_saved_messages(), - st::settingsButton, - {&st::menuIconSavedMessages} - )->toggleOn( - rpl::single(settings->showSavedMessagesInDrawer) - )->toggledValue( - ) | rpl::filter( - [=](bool enabled) - { - return (enabled != settings->showSavedMessagesInDrawer); - }) | rpl::on_next( - [=](bool enabled) - { - AyuSettings::set_showSavedMessagesInDrawer(enabled); - AyuSettings::save(); - }, - container->lifetime()); - - AddButtonWithIcon( - container, - tr::ayu_LReadMessages(), - st::settingsButton, - {&st::ayuLReadMenuIcon} - )->toggleOn( - rpl::single(settings->showLReadToggleInDrawer) - )->toggledValue( - ) | rpl::filter( - [=](bool enabled) - { - return (enabled != settings->showLReadToggleInDrawer); - }) | rpl::on_next( - [=](bool enabled) - { - AyuSettings::set_showLReadToggleInDrawer(enabled); - AyuSettings::save(); - }, - container->lifetime()); - - AddButtonWithIcon( - container, - tr::ayu_SReadMessages(), - st::settingsButton, - {&st::ayuSReadMenuIcon} - )->toggleOn( - rpl::single(settings->showSReadToggleInDrawer) - )->toggledValue( - ) | rpl::filter( - [=](bool enabled) - { - return (enabled != settings->showSReadToggleInDrawer); - }) | rpl::on_next( - [=](bool enabled) - { - AyuSettings::set_showSReadToggleInDrawer(enabled); - AyuSettings::save(); - }, - container->lifetime()); - - AddButtonWithIcon( - container, - tr::lng_menu_night_mode(), - st::settingsButton, - {&st::menuIconNightMode} - )->toggleOn( - rpl::single(settings->showNightModeToggleInDrawer) - )->toggledValue( - ) | rpl::filter( - [=](bool enabled) - { - return (enabled != settings->showNightModeToggleInDrawer); - }) | rpl::on_next( - [=](bool enabled) - { - AyuSettings::set_showNightModeToggleInDrawer(enabled); - AyuSettings::save(); - }, - container->lifetime()); - - AddButtonWithIcon( - container, - tr::ayu_GhostModeToggle(), - st::settingsButton, - {&st::ayuGhostIcon} - )->toggleOn( - rpl::single(settings->showGhostToggleInDrawer) - )->toggledValue( - ) | rpl::filter( - [=](bool enabled) - { - return (enabled != settings->showGhostToggleInDrawer); - }) | rpl::on_next( - [=](bool enabled) - { - AyuSettings::set_showGhostToggleInDrawer(enabled); - AyuSettings::save(); - }, - container->lifetime()); + AddSettingToggle(container, tr::lng_create_group_title(), &AyuSettings::showNewGroupInDrawer, &AyuSettings::setShowNewGroupInDrawer, st::menuIconGroups); + AddSettingToggle(container, tr::lng_create_channel_title(), &AyuSettings::showNewChannelInDrawer, &AyuSettings::setShowNewChannelInDrawer, st::menuIconChannel); + AddSettingToggle(container, tr::lng_menu_contacts(), &AyuSettings::showContactsInDrawer, &AyuSettings::setShowContactsInDrawer, st::menuIconUserShow); + AddSettingToggle(container, tr::lng_menu_calls(), &AyuSettings::showCallsInDrawer, &AyuSettings::setShowCallsInDrawer, st::menuIconPhone); + AddSettingToggle(container, tr::lng_saved_messages(), &AyuSettings::showSavedMessagesInDrawer, &AyuSettings::setShowSavedMessagesInDrawer, st::menuIconSavedMessages); + AddSettingToggle(container, tr::ayu_LReadMessages(), &AyuSettings::showLReadToggleInDrawer, &AyuSettings::setShowLReadToggleInDrawer, st::ayuLReadMenuIcon); + AddSettingToggle(container, tr::ayu_SReadMessages(), &AyuSettings::showSReadToggleInDrawer, &AyuSettings::setShowSReadToggleInDrawer, st::ayuSReadMenuIcon); + AddSettingToggle(container, tr::lng_menu_night_mode(), &AyuSettings::showNightModeToggleInDrawer, &AyuSettings::setShowNightModeToggleInDrawer, st::menuIconNightMode); + AddSettingToggle(container, tr::ayu_GhostModeToggle(), &AyuSettings::showGhostToggleInDrawer, &AyuSettings::setShowGhostToggleInDrawer, st::ayuGhostIcon); #ifdef WIN32 - AddButtonWithIcon( - container, - tr::ayu_StreamerModeToggle(), - st::settingsButton, - {&st::ayuStreamerModeMenuIcon} - )->toggleOn( - rpl::single(settings->showStreamerToggleInDrawer) - )->toggledValue( - ) | rpl::filter( - [=](bool enabled) - { - return (enabled != settings->showStreamerToggleInDrawer); - }) | rpl::on_next( - [=](bool enabled) - { - AyuSettings::set_showStreamerToggleInDrawer(enabled); - AyuSettings::save(); - }, - container->lifetime()); + AddSettingToggle(container, tr::ayu_StreamerModeToggle(), &AyuSettings::showStreamerToggleInDrawer, &AyuSettings::setShowStreamerToggleInDrawer, st::ayuStreamerModeMenuIcon); #endif AddSkip(container); } void SetupTrayElements(not_null container) { - auto *settings = &AyuSettings::getInstance(); - AddSubsectionTitle(container, tr::ayu_TrayElementsHeader()); - AddButtonWithIcon( - container, - tr::ayu_EnableGhostModeTray(), - st::settingsButtonNoIcon - )->toggleOn( - rpl::single(settings->showGhostToggleInTray) - )->toggledValue( - ) | rpl::filter( - [=](bool enabled) - { - return (enabled != settings->showGhostToggleInTray); - }) | rpl::on_next( - [=](bool enabled) - { - AyuSettings::set_showGhostToggleInTray(enabled); - AyuSettings::save(); - }, - container->lifetime()); + AddSettingToggle(container, tr::ayu_EnableGhostModeTray(), &AyuSettings::showGhostToggleInTray, &AyuSettings::setShowGhostToggleInTray); #ifdef WIN32 - AddButtonWithIcon( - container, - tr::ayu_EnableStreamerModeTray(), - st::settingsButtonNoIcon - )->toggleOn( - rpl::single(settings->showStreamerToggleInTray) - )->toggledValue( - ) | rpl::filter( - [=](bool enabled) - { - return (enabled != settings->showStreamerToggleInTray); - }) | rpl::on_next( - [=](bool enabled) - { - AyuSettings::set_showStreamerToggleInTray(enabled); - AyuSettings::save(); - }, - container->lifetime()); + AddSettingToggle(container, tr::ayu_EnableStreamerModeTray(), &AyuSettings::showStreamerToggleInTray, &AyuSettings::setShowStreamerToggleInTray); #endif - AddSkip(container); - AddDivider(container); - AddSkip(container); + AddSectionDivider(container); } void AyuAppearance::setupContent(not_null controller) { diff --git a/Telegram/SourceFiles/ayu/ui/settings/settings_ayu.cpp b/Telegram/SourceFiles/ayu/ui/settings/settings_ayu.cpp index de88e72c47..ed67297403 100644 --- a/Telegram/SourceFiles/ayu/ui/settings/settings_ayu.cpp +++ b/Telegram/SourceFiles/ayu/ui/settings/settings_ayu.cpp @@ -10,17 +10,488 @@ #include "settings_ayu_utils.h" #include "ayu/ayu_settings.h" #include "boxes/peer_list_box.h" +#include "core/application.h" +#include "data/data_user.h" #include "filters/settings_filters_list.h" +#include "main/main_account.h" +#include "main/main_domain.h" +#include "main/main_session.h" #include "settings/settings_common.h" +#include "styles/style_ayu_styles.h" +#include "styles/style_chat.h" +#include "styles/style_chat_helpers.h" +#include "styles/style_info.h" +#include "styles/style_layers.h" #include "styles/style_settings.h" +#include "ui/painter.h" #include "ui/vertical_list.h" +#include "ui/text/text.h" +#include "ui/toast/toast.h" #include "ui/widgets/buttons.h" -#include "ui/widgets/checkbox.h" +#include "ui/widgets/popup_menu.h" +#include "ui/widgets/menu/menu_item_base.h" #include "ui/wrap/vertical_layout.h" #include "window/window_session_controller.h" namespace Settings { +struct GhostPickerState { + rpl::variable selectedUserId; + base::unique_qptr menu; + Ui::LinkButton *pickerButton = nullptr; + Fn refreshCheckboxes; +}; + +class AccountAction final : public Ui::Menu::ItemBase { +public: + AccountAction( + not_null parent, + const style::Menu &st, + UserData *user, + Fn callback) + : ItemBase(parent, st) + , _dummyAction(Ui::CreateChild(parent.get())) + , _user(user) + , _st(st) + , _height(st::defaultWhoRead.photoSkip * 2 + st::defaultWhoRead.photoSize) { + setAcceptBoth(true); + fitToMenuWidth(); + + _text.setText(_st.itemStyle, user->name()); + const auto goodWidth = st::defaultWhoRead.nameLeft + + _text.maxWidth() + + _st.itemPadding.right(); + setMinWidth(std::clamp(goodWidth, _st.widthMin, _st.widthMax)); + + setActionTriggered(std::move(callback)); + + paintRequest( + ) | rpl::on_next([=] { + paint(Painter(this)); + }, lifetime()); + + enableMouseSelecting(); + } + + not_null action() const override { return _dummyAction; } + bool isEnabled() const override { return true; } + +protected: + int contentHeight() const override { return _height; } + +private: + void paint(Painter &&p) { + const auto selected = isSelected(); + if (selected && _st.itemBgOver->c.alpha() < 255) { + p.fillRect(0, 0, width(), _height, _st.itemBg); + } + const auto bg = selected ? _st.itemBgOver : _st.itemBg; + p.fillRect(0, 0, width(), _height, bg); + if (isEnabled()) { + paintRipple(p, 0, 0); + } + + const auto photoSize = st::defaultWhoRead.photoSize; + const auto photoLeft = st::defaultWhoRead.photoLeft; + const auto photoTop = (_height - photoSize) / 2; + _user->paintUserpicLeft(p, _userpicView, photoLeft, photoTop, width(), photoSize); + + p.setPen(selected ? _st.itemFgOver : _st.itemFg); + _text.drawLeftElided( + p, + st::defaultWhoRead.nameLeft, + (_height - _st.itemStyle.font->height) / 2, + width() - st::defaultWhoRead.nameLeft - _st.itemPadding.right(), + width()); + } + + const not_null _dummyAction; + UserData *_user = nullptr; + mutable Ui::PeerUserpicView _userpicView; + const style::Menu &_st; + Ui::Text::String _text; + const int _height; +}; + +class GlobalAction final : public Ui::Menu::ItemBase { +public: + GlobalAction( + not_null parent, + const style::Menu &st, + const QString &text, + Fn callback) + : ItemBase(parent, st) + , _dummyAction(Ui::CreateChild(parent.get())) + , _st(st) + , _height(st::defaultWhoRead.photoSkip * 2 + st::defaultWhoRead.photoSize) { + setAcceptBoth(true); + fitToMenuWidth(); + + _text.setText(_st.itemStyle, text); + const auto goodWidth = st::defaultWhoRead.nameLeft + + _text.maxWidth() + + _st.itemPadding.right(); + setMinWidth(std::clamp(goodWidth, _st.widthMin, _st.widthMax)); + + setActionTriggered(std::move(callback)); + + paintRequest( + ) | rpl::on_next([=] { + paint(Painter(this)); + }, lifetime()); + + enableMouseSelecting(); + } + + not_null action() const override { return _dummyAction; } + bool isEnabled() const override { return true; } + +protected: + int contentHeight() const override { return _height; } + +private: + void paint(Painter &&p) { + const auto selected = isSelected(); + if (selected && _st.itemBgOver->c.alpha() < 255) { + p.fillRect(0, 0, width(), _height, _st.itemBg); + } + const auto bg = selected ? _st.itemBgOver : _st.itemBg; + p.fillRect(0, 0, width(), _height, bg); + if (isEnabled()) { + paintRipple(p, 0, 0); + } + + const auto photoSize = st::defaultWhoRead.photoSize; + const auto photoLeft = st::defaultWhoRead.photoLeft; + const auto photoTop = (_height - photoSize) / 2; + { + auto hq = PainterHighQualityEnabler(p); + auto rect = QRectF(photoLeft, photoTop, photoSize, photoSize); + auto gradient = QLinearGradient(rect.topLeft(), rect.bottomLeft()); + gradient.setStops({ + { 0., st::historyPeer5UserpicBg->c }, + { 1., st::historyPeer5UserpicBg2->c }, + }); + p.setPen(Qt::NoPen); + p.setBrush(gradient); + p.drawEllipse(rect); + } + { + const auto fontsize = (photoSize * 13) / 33; + auto font = st::historyPeerUserpicFont->f; + font.setPixelSize(fontsize); + p.setFont(font); + p.setBrush(Qt::NoBrush); + p.setPen(st::historyPeerUserpicFg); + p.drawText( + QRect(photoLeft, photoTop, photoSize, photoSize), + u"GS"_q, + QTextOption(style::al_center)); + } + + p.setPen(selected ? _st.itemFgOver : _st.itemFg); + _text.drawLeftElided( + p, + st::defaultWhoRead.nameLeft, + (_height - _st.itemStyle.font->height) / 2, + width() - st::defaultWhoRead.nameLeft - _st.itemPadding.right(), + width()); + } + + const not_null _dummyAction; + const style::Menu &_st; + Ui::Text::String _text; + const int _height; +}; + +QString GetAccountName(uint64 userId) { + for (const auto &account : Core::App().domain().orderedAccounts()) { + if (account->sessionExists() + && account->session().userId().bare == userId) { + return account->session().user()->name(); + } + } + return QString("Unknown"); +} + +QString PickerLabel(uint64 userId) { + return (userId == 0) + ? tr::ayu_GhostModeGlobalSettings(tr::now) + : GetAccountName(userId); +} + +void selectGhostProfile(GhostPickerState *state, uint64 userId) { + if (state->selectedUserId.current() == userId) { + return; + } + + auto wasGlobal = (state->selectedUserId.current() == 0); + auto nowGlobal = (userId == 0); + + AyuSettings::getInstance().setUseGlobalGhostMode(nowGlobal); + + state->selectedUserId = userId; + + state->pickerButton->setText(PickerLabel(userId)); + + state->refreshCheckboxes(); + + if (wasGlobal != nowGlobal) { + Ui::Toast::Show(nowGlobal + ? tr::ayu_GhostModeSwitchedToGlobalSettings(tr::now) + : tr::ayu_GhostModeSwitchedToIndividualSettings(tr::now)); + } +} + +void SetupGhostEssentials( + not_null container, + not_null controller) { + auto activeCount = 0; + for (const auto &account : Core::App().domain().orderedAccounts()) { + if (account->sessionExists()) { + ++activeCount; + } + } + + if (activeCount <= 1 && !AyuSettings::getInstance().useGlobalGhostMode()) { + auto userId = controller->session().userId().bare; + auto &src = AyuSettings::ghost(userId); + auto &dst = AyuSettings::ghost(0); + dst.setSendReadMessages(src.sendReadMessages()); + dst.setSendReadStories(src.sendReadStories()); + dst.setSendOnlinePackets(src.sendOnlinePackets()); + dst.setSendUploadProgress(src.sendUploadProgress()); + dst.setSendOfflinePacketAfterOnline(src.sendOfflinePacketAfterOnline()); + dst.setMarkReadAfterAction(src.markReadAfterAction()); + dst.setUseScheduledMessages(src.useScheduledMessages()); + dst.setSendWithoutSound(src.sendWithoutSound()); + dst.setSendReadMessagesLocked(src.sendReadMessagesLocked()); + dst.setSendReadStoriesLocked(src.sendReadStoriesLocked()); + dst.setSendOnlinePacketsLocked(src.sendOnlinePacketsLocked()); + dst.setSendUploadProgressLocked(src.sendUploadProgressLocked()); + dst.setSendOfflinePacketAfterOnlineLocked(src.sendOfflinePacketAfterOnlineLocked()); + AyuSettings::getInstance().setUseGlobalGhostMode(true); + } + + const auto isGlobal = AyuSettings::getInstance().useGlobalGhostMode(); + auto initialUserId = isGlobal + ? uint64(0) + : controller->session().userId().bare; + + const auto state = container->lifetime().make_state(); + state->selectedUserId = initialUserId; + + const auto title = AddSubsectionTitle(container, tr::ayu_GhostEssentialsHeader()); + + const auto pickerButton = Ui::CreateChild( + container.get(), + PickerLabel(initialUserId), + st::ghostPickerButton); + state->pickerButton = pickerButton; + + const auto arrow = Ui::CreateChild(container.get()); + { + const auto &icon = st::ghostPickerArrow; + arrow->resize(icon.size()); + arrow->paintRequest( + ) | rpl::on_next([=, &icon] { + auto p = QPainter(arrow); + icon.paint(p, 0, 0, arrow->width()); + }, arrow->lifetime()); + } + arrow->setCursor(style::cur_pointer); + + const auto showPicker = activeCount > 1; + pickerButton->setVisible(showPicker); + arrow->setVisible(showPicker); + + rpl::combine( + title->geometryValue(), + container->widthValue(), + pickerButton->naturalWidthValue() + ) | rpl::on_next([=](QRect r, int width, int natural) { + pickerButton->resizeToNaturalWidth(width / 2); + pickerButton->moveToRight( + st::defaultSubsectionTitlePadding.right() + arrow->width() + st::normalFont->spacew / 2, + r.y() + (r.height() - pickerButton->height()) / 2, + width); + arrow->moveToLeft( + pickerButton->x() + pickerButton->width() + st::normalFont->spacew / 2, + r.y() + (r.height() - arrow->height()) / 2); + }, pickerButton->lifetime()); + + std::vector checkboxes{ + NestedEntry{ + tr::ayu_DontReadMessages(tr::now), + [state] { return !AyuSettings::ghost(state->selectedUserId.current()).sendReadMessages(); }, + [state](bool v) { AyuSettings::ghost(state->selectedUserId.current()).setSendReadMessages(!v); }, + [state] { return AyuSettings::ghost(state->selectedUserId.current()).sendReadMessagesLocked(); }, + [state](bool v) { AyuSettings::ghost(state->selectedUserId.current()).setSendReadMessagesLocked(v); } + }, + NestedEntry{ + tr::ayu_DontReadStories(tr::now), + [state] { return !AyuSettings::ghost(state->selectedUserId.current()).sendReadStories(); }, + [state](bool v) { AyuSettings::ghost(state->selectedUserId.current()).setSendReadStories(!v); }, + [state] { return AyuSettings::ghost(state->selectedUserId.current()).sendReadStoriesLocked(); }, + [state](bool v) { AyuSettings::ghost(state->selectedUserId.current()).setSendReadStoriesLocked(v); } + }, + NestedEntry{ + tr::ayu_DontSendOnlinePackets(tr::now), + [state] { return !AyuSettings::ghost(state->selectedUserId.current()).sendOnlinePackets(); }, + [state](bool v) { AyuSettings::ghost(state->selectedUserId.current()).setSendOnlinePackets(!v); }, + [state] { return AyuSettings::ghost(state->selectedUserId.current()).sendOnlinePacketsLocked(); }, + [state](bool v) { AyuSettings::ghost(state->selectedUserId.current()).setSendOnlinePacketsLocked(v); } + }, + NestedEntry{ + tr::ayu_DontSendUploadProgress(tr::now), + [state] { return !AyuSettings::ghost(state->selectedUserId.current()).sendUploadProgress(); }, + [state](bool v) { AyuSettings::ghost(state->selectedUserId.current()).setSendUploadProgress(!v); }, + [state] { return AyuSettings::ghost(state->selectedUserId.current()).sendUploadProgressLocked(); }, + [state](bool v) { AyuSettings::ghost(state->selectedUserId.current()).setSendUploadProgressLocked(v); } + }, + NestedEntry{ + tr::ayu_SendOfflinePacketAfterOnline(tr::now), + [state] { return AyuSettings::ghost(state->selectedUserId.current()).sendOfflinePacketAfterOnline(); }, + [state](bool v) { AyuSettings::ghost(state->selectedUserId.current()).setSendOfflinePacketAfterOnline(v); }, + [state] { return AyuSettings::ghost(state->selectedUserId.current()).sendOfflinePacketAfterOnlineLocked(); }, + [state](bool v) { AyuSettings::ghost(state->selectedUserId.current()).setSendOfflinePacketAfterOnlineLocked(v); } + }, + }; + + state->refreshCheckboxes = AddCollapsibleToggle( + container, tr::ayu_GhostModeToggle(), std::move(checkboxes), true); + + AddButtonWithIcon( + container, + tr::ayu_MarkReadAfterAction(), + st::settingsButtonNoIcon + )->toggleOn( + state->selectedUserId.value() + | rpl::map([](uint64 id) { + return AyuSettings::ghost(id).markReadAfterActionChanges(); + }) | rpl::flatten_latest() + )->toggledValue( + ) | rpl::filter( + [=](bool enabled) + { + return enabled != AyuSettings::ghost(state->selectedUserId.current()).markReadAfterAction(); + }) | on_next( + [=](bool enabled) + { + auto &ghost = AyuSettings::ghost(state->selectedUserId.current()); + ghost.setMarkReadAfterAction(enabled); + if (enabled) { + ghost.setUseScheduledMessages(false); + } + }, + container->lifetime()); + AddSkip(container); + AddDividerText(container, tr::ayu_MarkReadAfterActionDescription()); + + AddSkip(container); + AddButtonWithIcon( + container, + tr::ayu_UseScheduledMessages(), + st::settingsButtonNoIcon + )->toggleOn( + state->selectedUserId.value() + | rpl::map([](uint64 id) { + return AyuSettings::ghost(id).useScheduledMessagesChanges(); + }) | rpl::flatten_latest() + )->toggledValue( + ) | rpl::filter( + [=](bool enabled) + { + return enabled != AyuSettings::ghost(state->selectedUserId.current()).useScheduledMessages(); + }) | on_next( + [=](bool enabled) + { + auto &ghost = AyuSettings::ghost(state->selectedUserId.current()); + ghost.setUseScheduledMessages(enabled); + if (enabled) { + ghost.setMarkReadAfterAction(false); + } + }, + container->lifetime()); + AddSkip(container); + AddDividerText(container, tr::ayu_UseScheduledMessagesDescription()); + + AddSkip(container); + AddButtonWithIcon( + container, + tr::ayu_SendWithoutSoundByDefault(), + st::settingsButtonNoIcon + )->toggleOn( + state->selectedUserId.value() + | rpl::map([](uint64 id) { + return AyuSettings::ghost(id).sendWithoutSoundChanges(); + }) | rpl::flatten_latest() + )->toggledValue( + ) | rpl::filter( + [=](bool enabled) + { + return enabled != AyuSettings::ghost(state->selectedUserId.current()).sendWithoutSound(); + }) | on_next( + [=](bool enabled) + { + AyuSettings::ghost(state->selectedUserId.current()).setSendWithoutSound(enabled); + }, + container->lifetime()); + AddSkip(container); + AddDividerText(container, tr::ayu_SendWithoutSoundByDefaultDescription()); + + auto showMenu = [=] { + state->menu = base::make_unique_q( + pickerButton, + st::defaultPopupMenu); + + state->menu->addAction( + base::make_unique_q( + state->menu->menu(), + st::defaultPopupMenu.menu, + tr::ayu_GhostModeGlobalSettings(tr::now), + [=] { selectGhostProfile(state, 0); })); + + for (const auto &account : Core::App().domain().orderedAccounts()) { + if (!account->sessionExists()) { + continue; + } + auto user = account->session().user(); + auto id = account->session().userId().bare; + state->menu->addAction( + base::make_unique_q( + state->menu->menu(), + st::defaultPopupMenu.menu, + user, + [=] { selectGhostProfile(state, id); })); + } + + state->menu->popup( + pickerButton->mapToGlobal( + QPoint(pickerButton->width(), pickerButton->height()))); + }; + pickerButton->setClickedCallback(showMenu); + arrow->setClickedCallback(showMenu); +} + +void SetupSpyEssentials(not_null container) { + AddSubsectionTitle(container, tr::ayu_SpyEssentialsHeader()); + + AddSettingToggle(container, tr::ayu_SaveDeletedMessages(), &AyuSettings::saveDeletedMessages, &AyuSettings::setSaveDeletedMessages); + AddSettingToggle(container, tr::ayu_SaveMessagesHistory(), &AyuSettings::saveMessagesHistory, &AyuSettings::setSaveMessagesHistory); + + AddSectionDivider(container); + + AddSettingToggle(container, tr::ayu_MessageSavingSaveForBots(), &AyuSettings::saveForBots, &AyuSettings::setSaveForBots); +} + +void SetupOther(not_null container) { + AddSubsectionTitle(container, tr::ayu_MessageSavingOtherHeader()); + + AddSettingToggle(container, tr::ayu_LocalPremium(), &AyuSettings::localPremium, &AyuSettings::setLocalPremium); + AddSettingToggle(container, tr::ayu_DisableAds(), &AyuSettings::disableAds, &AyuSettings::setDisableAds); +} + rpl::producer AyuGhost::title() { return rpl::single(QString("AyuGram")); } @@ -28,282 +499,22 @@ rpl::producer AyuGhost::title() { AyuGhost::AyuGhost( QWidget *parent, not_null controller) - : Section(parent) { + : Section(parent) + , _controller(controller) { setupContent(controller); } -void SetupGhostModeToggle(not_null container) { - auto *settings = &AyuSettings::getInstance(); - - AddSubsectionTitle(container, tr::ayu_GhostEssentialsHeader()); - - std::vector checkboxes{ - NestedEntry{ - tr::ayu_DontReadMessages(tr::now), !settings->sendReadMessages, [=](bool enabled) - { - AyuSettings::set_sendReadMessages(!enabled); - AyuSettings::save(); - } - }, - NestedEntry{ - tr::ayu_DontReadStories(tr::now), !settings->sendReadStories, [=](bool enabled) - { - AyuSettings::set_sendReadStories(!enabled); - AyuSettings::save(); - } - }, - NestedEntry{ - tr::ayu_DontSendOnlinePackets(tr::now), !settings->sendOnlinePackets, [=](bool enabled) - { - AyuSettings::set_sendOnlinePackets(!enabled); - AyuSettings::save(); - } - }, - NestedEntry{ - tr::ayu_DontSendUploadProgress(tr::now), !settings->sendUploadProgress, [=](bool enabled) - { - AyuSettings::set_sendUploadProgress(!enabled); - AyuSettings::save(); - } - }, - NestedEntry{ - tr::ayu_SendOfflinePacketAfterOnline(tr::now), settings->sendOfflinePacketAfterOnline, [=](bool enabled) - { - AyuSettings::set_sendOfflinePacketAfterOnline(enabled); - AyuSettings::save(); - } - }, - }; - - AddCollapsibleToggle(container, tr::ayu_GhostModeToggle(), checkboxes, true); -} - -void SetupGhostEssentials( - not_null container, - not_null settings, - not_null*> markReadAfterActionVal, - not_null*> useScheduledMessagesVal) { - SetupGhostModeToggle(container); - - - AddButtonWithIcon( - container, - tr::ayu_MarkReadAfterAction(), - st::settingsButtonNoIcon - )->toggleOn( - markReadAfterActionVal->value() - )->toggledValue( - ) | rpl::filter( - [=](bool enabled) - { - return (enabled != settings->markReadAfterAction); - }) | on_next( - [=](bool enabled) - { - AyuSettings::set_markReadAfterAction(enabled); - if (enabled) { - AyuSettings::set_useScheduledMessages(false); - useScheduledMessagesVal->force_assign(false); - } - - AyuSettings::save(); - }, - container->lifetime()); - AddSkip(container); - AddDividerText(container, tr::ayu_MarkReadAfterActionDescription()); -} - -void SetupScheduleMessages( - not_null container, - not_null settings, - not_null*> markReadAfterActionVal, - not_null*> useScheduledMessagesVal) { - AddSkip(container); - AddButtonWithIcon( - container, - tr::ayu_UseScheduledMessages(), - st::settingsButtonNoIcon - )->toggleOn( - useScheduledMessagesVal->value() - )->toggledValue( - ) | rpl::filter( - [=](bool enabled) - { - return (enabled != settings->useScheduledMessages); - }) | on_next( - [=](bool enabled) - { - AyuSettings::set_useScheduledMessages(enabled); - if (enabled) { - AyuSettings::set_markReadAfterAction(false); - markReadAfterActionVal->force_assign(false); - } - - AyuSettings::save(); - }, - container->lifetime()); - AddSkip(container); - AddDividerText(container, tr::ayu_UseScheduledMessagesDescription()); -} - -void SetupSendWithoutSound(not_null container) { - auto *settings = &AyuSettings::getInstance(); - - AddSkip(container); - AddButtonWithIcon( - container, - tr::ayu_SendWithoutSoundByDefault(), - st::settingsButtonNoIcon - )->toggleOn( - rpl::single(settings->sendWithoutSound) - )->toggledValue( - ) | rpl::filter( - [=](bool enabled) - { - return (enabled != settings->sendWithoutSound); - }) | on_next( - [=](bool enabled) - { - AyuSettings::set_sendWithoutSound(enabled); - AyuSettings::save(); - }, - container->lifetime()); - AddSkip(container); - AddDividerText(container, tr::ayu_SendWithoutSoundByDefaultDescription()); -} - -void SetupSpyEssentials(not_null container) { - auto *settings = &AyuSettings::getInstance(); - - AddSubsectionTitle(container, tr::ayu_SpyEssentialsHeader()); - - AddButtonWithIcon( - container, - tr::ayu_SaveDeletedMessages(), - st::settingsButtonNoIcon - )->toggleOn( - rpl::single(settings->saveDeletedMessages) - )->toggledValue( - ) | rpl::filter( - [=](bool enabled) - { - return (enabled != settings->saveDeletedMessages); - }) | on_next( - [=](bool enabled) - { - AyuSettings::set_saveDeletedMessages(enabled); - AyuSettings::save(); - }, - container->lifetime()); - - AddButtonWithIcon( - container, - tr::ayu_SaveMessagesHistory(), - st::settingsButtonNoIcon - )->toggleOn( - rpl::single(settings->saveMessagesHistory) - )->toggledValue( - ) | rpl::filter( - [=](bool enabled) - { - return (enabled != settings->saveMessagesHistory); - }) | on_next( - [=](bool enabled) - { - AyuSettings::set_saveMessagesHistory(enabled); - AyuSettings::save(); - }, - container->lifetime()); - - AddSkip(container); - AddDivider(container); - AddSkip(container); - - AddButtonWithIcon( - container, - tr::ayu_MessageSavingSaveForBots(), - st::settingsButtonNoIcon - )->toggleOn( - rpl::single(settings->saveForBots) - )->toggledValue( - ) | rpl::filter( - [=](bool enabled) - { - return (enabled != settings->saveForBots); - }) | on_next( - [=](bool enabled) - { - AyuSettings::set_saveForBots(enabled); - AyuSettings::save(); - }, - container->lifetime()); -} - -void SetupOther(not_null container) { - auto *settings = &AyuSettings::getInstance(); - - AddSubsectionTitle(container, tr::ayu_MessageSavingOtherHeader()); - - AddButtonWithIcon( - container, - tr::ayu_LocalPremium(), - st::settingsButtonNoIcon - )->toggleOn( - rpl::single(settings->localPremium) - )->toggledValue( - ) | rpl::filter( - [=](bool enabled) - { - return (enabled != settings->localPremium); - }) | on_next( - [=](bool enabled) - { - AyuSettings::set_localPremium(enabled); - AyuSettings::save(); - }, - container->lifetime()); - - AddButtonWithIcon( - container, - tr::ayu_DisableAds(), - st::settingsButtonNoIcon - )->toggleOn( - rpl::single(settings->disableAds) - )->toggledValue( - ) | rpl::filter( - [=](bool enabled) - { - return (enabled != settings->disableAds); - }) | on_next( - [=](bool enabled) - { - AyuSettings::set_disableAds(enabled); - AyuSettings::save(); - }, - container->lifetime()); -} - void AyuGhost::setupContent(not_null controller) { const auto content = Ui::CreateChild(this); - const auto settings = &AyuSettings::getInstance(); - const auto markReadAfterActionVal = content->lifetime().make_state>( - settings->markReadAfterAction); - const auto useScheduledMessagesVal = content->lifetime().make_state>( - settings->useScheduledMessages); - AddSkip(content); - SetupGhostEssentials(content, settings, markReadAfterActionVal, useScheduledMessagesVal); - SetupScheduleMessages(content, settings, markReadAfterActionVal, useScheduledMessagesVal); - SetupSendWithoutSound(content); + SetupGhostEssentials(content, controller); AddSkip(content); SetupSpyEssentials(content); - AddSkip(content); - AddDivider(content); - AddSkip(content); + AddSectionDivider(content); SetupOther(content); AddSkip(content); diff --git a/Telegram/SourceFiles/ayu/ui/settings/settings_ayu.h b/Telegram/SourceFiles/ayu/ui/settings/settings_ayu.h index 93cbd46404..de3034e713 100644 --- a/Telegram/SourceFiles/ayu/ui/settings/settings_ayu.h +++ b/Telegram/SourceFiles/ayu/ui/settings/settings_ayu.h @@ -24,6 +24,8 @@ public: private: void setupContent(not_null controller); + + not_null _controller; }; } // namespace Settings \ No newline at end of file diff --git a/Telegram/SourceFiles/ayu/ui/settings/settings_ayu_utils.cpp b/Telegram/SourceFiles/ayu/ui/settings/settings_ayu_utils.cpp index 0d5b154809..a592963483 100644 --- a/Telegram/SourceFiles/ayu/ui/settings/settings_ayu_utils.cpp +++ b/Telegram/SourceFiles/ayu/ui/settings/settings_ayu_utils.cpp @@ -12,6 +12,7 @@ #include "styles/style_layers.h" #include "styles/style_settings.h" #include "ui/painter.h" +#include "ui/vertical_list.h" #include "ui/boxes/single_choice_box.h" #include "ui/text/text_utilities.h" #include "ui/widgets/buttons.h" @@ -21,6 +22,8 @@ #include "ui/wrap/vertical_layout.h" #include "window/window_session_controller.h" +#include + class PainterHighQualityEnabler; namespace Settings { @@ -41,7 +44,9 @@ not_null AddInnerToggle(not_null container, std::vector> innerCheckViews, not_null*> wrap, rpl::producer buttonLabel, - bool toggledWhenAll) { + bool toggledWhenAll, + std::vector> lockChecks, + rpl::event_stream<> *lockChanges) { const auto button = container->add(object_ptr( container, nullptr, @@ -62,6 +67,7 @@ not_null AddInnerToggle(not_null container, Ui::Animations::Simple animation; rpl::event_stream<> anyChanges; std::vector> innerChecks; + std::vector> lockChecks; }; const auto state = button->lifetime().make_state( st.toggle, @@ -70,6 +76,7 @@ not_null AddInnerToggle(not_null container, toggleButton->update(); }); state->innerChecks = std::move(innerCheckViews); + state->lockChecks = std::move(lockChecks); const auto countChecked = [=] { return ranges::count_if( @@ -79,12 +86,41 @@ not_null AddInnerToggle(not_null container, return v->checked(); }); }; + const auto countUnlockedChecked = [=] + { + auto count = 0; + for (auto i = 0u; i < state->innerChecks.size(); ++i) { + if (i < state->lockChecks.size() && state->lockChecks[i] && state->lockChecks[i]()) { + continue; + } + if (state->innerChecks[i]->checked()) { + ++count; + } + } + return count; + }; + const auto countTotal = [=] + { + auto total = static_cast(state->innerChecks.size()); + for (auto i = 0u; i < state->lockChecks.size(); ++i) { + if (state->lockChecks[i] && state->lockChecks[i]()) { + --total; + } + } + return total; + }; for (const auto &innerCheck : state->innerChecks) { innerCheck->checkedChanges( ) | rpl::to_empty | start_to_stream( state->anyChanges, button->lifetime()); } + if (lockChanges) { + lockChanges->events( + ) | start_to_stream( + state->anyChanges, + button->lifetime()); + } const auto checkView = &state->checkView; { const auto separator = Ui::CreateChild(container.get()); @@ -138,10 +174,11 @@ not_null AddInnerToggle(not_null container, state->anyChanges.events_starting_with( rpl::empty_value() - ) | rpl::map(countChecked) | on_next([=](int count) + ) | rpl::map(countUnlockedChecked) | on_next([=](int count) { + const auto total = countTotal(); if (toggledWhenAll) { - checkView->setChecked(count == totalInnerChecks, + checkView->setChecked(total > 0 && count == total, anim::type::normal); } else { checkView->setChecked(count != 0, @@ -237,8 +274,11 @@ not_null AddInnerToggle(not_null container, ) | on_next([=] { const auto checked = !checkView->checked(); - for (const auto &innerCheck : state->innerChecks) { - innerCheck->setChecked(checked, anim::type::normal); + for (auto i = 0u; i < state->innerChecks.size(); ++i) { + if (i < state->lockChecks.size() && state->lockChecks[i] && state->lockChecks[i]()) { + continue; + } + state->innerChecks[i]->setChecked(checked, anim::type::normal); } }, toggleButton->lifetime()); @@ -246,70 +286,132 @@ not_null AddInnerToggle(not_null container, return button; } -void AddCollapsibleToggle(not_null container, +Fn AddCollapsibleToggle(not_null container, rpl::producer title, std::vector checkboxes, bool toggledWhenAll) { - const auto addCheckbox = [&]( - not_null verticalLayout, - const QString &label, - const bool isCheckedOrig) - { - const auto checkView = [&]() -> not_null - { - const auto checkbox = verticalLayout->add( - object_ptr( - verticalLayout, - label, - isCheckedOrig, - st::settingsCheckbox), - st::powerSavingButton.padding); - const auto button = Ui::CreateChild( - verticalLayout.get(), - st::defaultRippleAnimation); - button->stackUnder(checkbox); - combine( - verticalLayout->widthValue(), - checkbox->geometryValue() - ) | on_next([=](int w, const QRect &r) - { - button->setGeometry(0, r.y(), w, r.height()); - }, - button->lifetime()); - checkbox->setAttribute(Qt::WA_TransparentForMouseEvents); - const auto checkView = checkbox->checkView(); - button->setClickedCallback([=] - { - checkView->setChecked( - !checkView->checked(), - anim::type::normal); - }); - - return checkView; - }(); - checkView->checkedChanges( - ) | on_next([=](bool checked) - { - }, - verticalLayout->lifetime()); - - return checkView; + struct CheckboxEntry { + not_null checkView; + Ui::Checkbox *checkbox = nullptr; + Ui::RippleButton *button = nullptr; }; + struct CollapsibleState { + std::vector entries; + std::vector checkboxes; + rpl::event_stream<> lockChanges; + }; + const auto cState = container->lifetime().make_state(); + cState->checkboxes = std::move(checkboxes); + auto wrap = object_ptr>( container, object_ptr(container)); const auto verticalLayout = wrap->entity(); auto innerChecks = std::vector>(); - for (const auto &entry : checkboxes) { - const auto c = addCheckbox(verticalLayout, entry.checkboxLabel, entry.initial); - c->checkedValue( + auto lockChecks = std::vector>(); + + const auto hasAnyLock = ranges::any_of(cState->checkboxes, [](const NestedEntry &e) { + return e.lockGetter != nullptr; + }); + + for (auto i = 0u; i < cState->checkboxes.size(); ++i) { + const auto &entry = cState->checkboxes[i]; + const auto checkbox = verticalLayout->add( + object_ptr( + verticalLayout, + entry.checkboxLabel, + entry.getter(), + st::settingsCheckbox), + st::powerSavingButton.padding); + const auto button = Ui::CreateChild( + verticalLayout, + st::defaultRippleAnimation); + button->stackUnder(checkbox); + combine( + verticalLayout->widthValue(), + checkbox->geometryValue() + ) | on_next([=](int w, const QRect &r) + { + button->setGeometry(0, r.y(), w, r.height()); + }, + button->lifetime()); + checkbox->setAttribute(Qt::WA_TransparentForMouseEvents); + const auto checkView = checkbox->checkView(); + + const auto idx = i; + button->setClickedCallback([=] + { + const auto &e = cState->checkboxes[idx]; + if (e.lockGetter && e.lockSetter) { + if (button->clickModifiers() & Qt::ShiftModifier) { + const auto currentlyLocked = e.lockGetter(); + if (!currentlyLocked) { + // Count already locked entries, deny if would lock all. + auto lockedCount = 0; + for (const auto &ce : cState->checkboxes) { + if (ce.lockGetter && ce.lockGetter()) { + ++lockedCount; + } + } + if (lockedCount + 1 >= static_cast(cState->checkboxes.size())) { + return; + } + } + e.lockSetter(!currentlyLocked); + // Update opacity. + const auto &ce = cState->entries[idx]; + if (!currentlyLocked) { + auto *effect = new QGraphicsOpacityEffect(ce.checkbox); + effect->setOpacity(0.4); + ce.checkbox->setGraphicsEffect(effect); + } else { + ce.checkbox->setGraphicsEffect(nullptr); + } + cState->lockChanges.fire({}); + return; + } + // Normal click on locked entry: ignore. + if (e.lockGetter()) { + return; + } + } + checkView->setChecked( + !checkView->checked(), + anim::type::normal); + }); + + checkView->checkedChanges( + ) | on_next([=](bool checked) + { + }, + verticalLayout->lifetime()); + + checkView->checkedValue( ) | on_next([=](bool enabled) { - entry.callback(enabled); + cState->checkboxes[idx].setter(enabled); }, container->lifetime()); - innerChecks.push_back(c); + + cState->entries.push_back(CheckboxEntry{ checkView, checkbox, button }); + innerChecks.push_back(checkView); + + if (hasAnyLock) { + lockChecks.push_back(entry.lockGetter + ? entry.lockGetter + : Fn(nullptr)); + } + } + + // Apply initial lock visuals. + for (auto i = 0u; i < cState->entries.size(); ++i) { + const auto &entry = cState->checkboxes[i]; + if (entry.lockGetter && entry.lockGetter()) { + auto *effect = new QGraphicsOpacityEffect(cState->entries[i].checkbox); + effect->setOpacity(0.4); + cState->entries[i].checkbox->setGraphicsEffect(effect); + } } const auto raw = wrap.data(); @@ -320,7 +422,9 @@ void AddCollapsibleToggle(not_null container, innerChecks, raw, std::move(title), - toggledWhenAll); + toggledWhenAll, + std::move(lockChecks), + &cState->lockChanges); container->add(std::move(wrap)); container->widthValue( ) | on_next([=](int w) @@ -328,6 +432,24 @@ void AddCollapsibleToggle(not_null container, raw->resizeToWidth(w); }, raw->lifetime()); + + return [cState] { + for (auto i = 0u; i < cState->entries.size(); ++i) { + cState->entries[i].checkView->setChecked( + cState->checkboxes[i].getter(), anim::type::normal); + // Refresh lock visuals. + const auto &entry = cState->checkboxes[i]; + if (entry.lockGetter) { + if (entry.lockGetter()) { + auto *effect = new QGraphicsOpacityEffect(cState->entries[i].checkbox); + effect->setOpacity(0.4); + cState->entries[i].checkbox->setGraphicsEffect(effect); + } else { + cState->entries[i].checkbox->setGraphicsEffect(nullptr); + } + } + } + }; } void AddChooseButtonWithIconAndRightTextInner(not_null container, @@ -414,4 +536,93 @@ void AddChooseButtonWithIconAndRightText(not_null container setter); } +not_null AddToggleInner( + not_null container, + rpl::producer text, + Fn getter, + Fn setter, + const style::SettingsButton &st, + Settings::IconDescriptor &&descriptor) { + const auto button = AddButtonWithIcon( + container, + std::move(text), + st, + std::move(descriptor)); + button->toggleOn( + rpl::single(getter()) + )->toggledValue( + ) | rpl::filter( + [=](bool enabled) + { + return (enabled != getter()); + }) | rpl::on_next( + [=](bool enabled) + { + setter(enabled); + }, + container->lifetime()); + return button; +} + +not_null AddToggle( + not_null container, + rpl::producer text, + Fn getter, + Fn setter) { + return AddToggleInner( + container, + std::move(text), + std::move(getter), + std::move(setter), + st::settingsButtonNoIcon, + {}); +} + +not_null AddToggle( + not_null container, + rpl::producer text, + Fn getter, + Fn setter, + const style::icon &icon) { + return AddToggleInner( + container, + std::move(text), + std::move(getter), + std::move(setter), + st::settingsButton, + {&icon}); +} + +void AddSectionDivider(not_null container) { + AddSkip(container); + AddDivider(container); + AddSkip(container); +} + +not_null AddSettingToggle( + not_null container, + rpl::producer text, + BoolGetter getter, + BoolSetter setter) { + return AddToggle( + container, + std::move(text), + [getter] { return (AyuSettings::getInstance().*getter)(); }, + [setter](bool v) { (AyuSettings::getInstance().*setter)(v); }); +} + +not_null AddSettingToggle( + not_null container, + rpl::producer text, + BoolGetter getter, + BoolSetter setter, + const style::icon &icon) { + return AddToggle( + container, + std::move(text), + [getter] { return (AyuSettings::getInstance().*getter)(); }, + [setter](bool v) { (AyuSettings::getInstance().*setter)(v); }, + icon); +} + } // namespace Settings \ No newline at end of file diff --git a/Telegram/SourceFiles/ayu/ui/settings/settings_ayu_utils.h b/Telegram/SourceFiles/ayu/ui/settings/settings_ayu_utils.h index b009d719ae..b3fcaefe8e 100644 --- a/Telegram/SourceFiles/ayu/ui/settings/settings_ayu_utils.h +++ b/Telegram/SourceFiles/ayu/ui/settings/settings_ayu_utils.h @@ -6,6 +6,7 @@ // Copyright @Radolyn, 2025 #pragma once +#include "ayu/ayu_settings.h" #include "settings/settings_common.h" #include "ui/widgets/buttons.h" #include "ui/widgets/checkbox.h" @@ -17,11 +18,16 @@ class SessionController; namespace Settings { +using BoolGetter = bool (AyuSettings::*)() const; +using BoolSetter = void (AyuSettings::*)(bool); + struct NestedEntry { QString checkboxLabel; - bool initial; - std::function callback; + Fn getter; + Fn setter; + Fn lockGetter; // nullptr = no lock support + Fn lockSetter; }; QString asBeta(const QString &text); @@ -32,9 +38,11 @@ not_null AddInnerToggle(not_null container, std::vector> innerCheckViews, not_null*> wrap, rpl::producer buttonLabel, - bool toggledWhenAll); + bool toggledWhenAll, + std::vector> lockChecks = {}, + rpl::event_stream<> *lockChanges = nullptr); -void AddCollapsibleToggle(not_null container, +Fn AddCollapsibleToggle(not_null container, rpl::producer title, std::vector checkboxes, bool toggledWhenAll); @@ -66,4 +74,32 @@ void AddChooseButtonWithIconAndRightText(not_null container rpl::producer boxTitle, const Fn &setter); +not_null AddToggle( + not_null container, + rpl::producer text, + Fn getter, + Fn setter); + +not_null AddToggle( + not_null container, + rpl::producer text, + Fn getter, + Fn setter, + const style::icon &icon); + +void AddSectionDivider(not_null container); + +not_null AddSettingToggle( + not_null container, + rpl::producer text, + BoolGetter getter, + BoolSetter setter); + +not_null AddSettingToggle( + not_null container, + rpl::producer text, + BoolGetter getter, + BoolSetter setter, + const style::icon &icon); + } // namespace Settings \ No newline at end of file diff --git a/Telegram/SourceFiles/ayu/ui/settings/settings_chats.cpp b/Telegram/SourceFiles/ayu/ui/settings/settings_chats.cpp index 2e92a1ff19..476099da04 100644 --- a/Telegram/SourceFiles/ayu/ui/settings/settings_chats.cpp +++ b/Telegram/SourceFiles/ayu/ui/settings/settings_chats.cpp @@ -44,47 +44,24 @@ void SetupStickersAndEmojiSettings(not_null container) { AddSubsectionTitle(container, tr::lng_settings_stickers_emoji()/*rpl::single(QString("Stickers and Emoji"))*/); - AddButtonWithIcon( - container, - tr::ayu_ShowOnlyAddedEmojisAndStickers(), - st::settingsButtonNoIcon - )->toggleOn( - rpl::single(settings->showOnlyAddedEmojisAndStickers) - )->toggledValue( - ) | rpl::filter( - [=](bool enabled) - { - return (enabled != settings->showOnlyAddedEmojisAndStickers); - }) | rpl::on_next( - [=](bool enabled) - { - AyuSettings::set_showOnlyAddedEmojisAndStickers(enabled); - AyuSettings::save(); - }, - container->lifetime()); + AddSettingToggle(container, tr::ayu_ShowOnlyAddedEmojisAndStickers(), &AyuSettings::showOnlyAddedEmojisAndStickers, &AyuSettings::setShowOnlyAddedEmojisAndStickers); std::vector checkboxes = { NestedEntry{ - tr::ayu_HideReactionsInChannels(tr::now), !settings->showChannelReactions, [=](bool enabled) - { - AyuSettings::set_hideChannelReactions(!enabled); - AyuSettings::save(); - } + tr::ayu_HideReactionsInChannels(tr::now), + [] { return !AyuSettings::getInstance().showChannelReactions(); }, + [](bool v) { AyuSettings::getInstance().setShowChannelReactions(!v); } }, NestedEntry{ - tr::ayu_HideReactionsInGroups(tr::now), !settings->showGroupReactions, [=](bool enabled) - { - AyuSettings::set_hideGroupReactions(!enabled); - AyuSettings::save(); - } + tr::ayu_HideReactionsInGroups(tr::now), + [] { return !AyuSettings::getInstance().showGroupReactions(); }, + [](bool v) { AyuSettings::getInstance().setShowGroupReactions(!v); } } }; AddCollapsibleToggle(container, tr::ayu_HideReactions(), checkboxes, false); - AddSkip(container); - AddDivider(container); - AddSkip(container); + AddSectionDivider(container); } void SetupRecentStickersLimit(not_null container) { @@ -110,7 +87,7 @@ void SetupRecentStickersLimit(not_null container) { { label->setText(QString::number(amount)); }; - updateLabel(settings->recentStickersCount); + updateLabel(settings->recentStickersCount()); slider->setPseudoDiscrete( 200 + 1, @@ -118,7 +95,7 @@ void SetupRecentStickersLimit(not_null container) { { return amount; }, - settings->recentStickersCount, + settings->recentStickersCount(), [=](int amount) { updateLabel(amount); @@ -126,13 +103,10 @@ void SetupRecentStickersLimit(not_null container) { [=](int amount) { updateLabel(amount); - AyuSettings::set_recentStickersCount(amount); - AyuSettings::save(); + AyuSettings::getInstance().setRecentStickersCount(amount); }); - AddSkip(container); - AddDivider(container); - AddSkip(container); + AddSectionDivider(container); } void SetupGroupsAndChannels(not_null container, not_null controller) { @@ -151,53 +125,17 @@ void SetupGroupsAndChannels(not_null container, not_nullchannelBottomButton, + static_cast(settings->channelBottomButton()), options, tr::ayu_ChannelBottomButton(), tr::ayu_ChannelBottomButton(), [=](int index) { - AyuSettings::set_channelBottomButton(index); - AyuSettings::save(); + AyuSettings::getInstance().setChannelBottomButton(static_cast(index)); }); - AddButtonWithIcon( - container, - tr::ayu_QuickAdminShortcuts(), - st::settingsButtonNoIcon - )->toggleOn( - rpl::single(settings->quickAdminShortcuts) - )->toggledValue( - ) | rpl::filter( - [=](bool enabled) - { - return (enabled != settings->quickAdminShortcuts); - }) | rpl::on_next( - [=](bool enabled) - { - AyuSettings::set_quickAdminShortcuts(enabled); - AyuSettings::save(); - }, - container->lifetime()); - - AddButtonWithIcon( - container, - tr::ayu_SettingsShowMessageShot(), - st::settingsButtonNoIcon - )->toggleOn( - rpl::single(settings->showMessageShot) - )->toggledValue( - ) | rpl::filter( - [=](bool enabled) - { - return (enabled != settings->showMessageShot); - }) | on_next( - [=](bool enabled) - { - AyuSettings::set_showMessageShot(enabled); - AyuSettings::save(); - }, - container->lifetime()); + AddSettingToggle(container, tr::ayu_QuickAdminShortcuts(), &AyuSettings::quickAdminShortcuts, &AyuSettings::setQuickAdminShortcuts); + AddSettingToggle(container, tr::ayu_SettingsShowMessageShot(), &AyuSettings::showMessageShot, &AyuSettings::setShowMessageShot); AddSkip(container); AddDividerText(container, tr::ayu_SettingsShowMessageShotDescription()); @@ -212,19 +150,18 @@ void SetupMarks(not_null container) { AddButtonWithLabel( container, tr::ayu_DeletedMarkText(), - AyuSettings::get_deletedMarkReactive(), + AyuSettings::getInstance().deletedMarkChanges(), st::settingsButtonNoIcon )->addClickHandler( [=]() { auto box = Box( tr::ayu_DeletedMarkText(), - settings->deletedMark, + settings->deletedMark(), QString("🧹"), [=](const QString &value) { - AyuSettings::set_deletedMark(value); - AyuSettings::save(); + AyuSettings::getInstance().setDeletedMark(value); } ); Ui::show(std::move(box)); @@ -233,88 +170,31 @@ void SetupMarks(not_null container) { AddButtonWithLabel( container, tr::ayu_EditedMarkText(), - AyuSettings::get_editedMarkReactive(), + AyuSettings::getInstance().editedMarkChanges(), st::settingsButtonNoIcon )->addClickHandler( [=]() { auto box = Box( tr::ayu_EditedMarkText(), - settings->editedMark, + settings->editedMark(), tr::lng_edited(tr::now), [=](const QString &value) { - AyuSettings::set_editedMark(value); - AyuSettings::save(); + AyuSettings::getInstance().setEditedMark(value); } ); Ui::show(std::move(box)); }); - AddButtonWithIcon( - container, - tr::ayu_ReplaceMarksWithIcons(), - st::settingsButtonNoIcon - )->toggleOn( - rpl::single(settings->replaceBottomInfoWithIcons) - )->toggledValue( - ) | rpl::filter( - [=](bool enabled) - { - return (enabled != settings->replaceBottomInfoWithIcons); - }) | on_next( - [=](bool enabled) - { - AyuSettings::set_replaceBottomInfoWithIcons(enabled); - AyuSettings::save(); - }, - container->lifetime()); + AddSettingToggle(container, tr::ayu_ReplaceMarksWithIcons(), &AyuSettings::replaceBottomInfoWithIcons, &AyuSettings::setReplaceBottomInfoWithIcons); - AddSkip(container); - AddDivider(container); - AddSkip(container); + AddSectionDivider(container); - AddButtonWithIcon( - container, - tr::ayu_HideShareButton(), - st::settingsButtonNoIcon - )->toggleOn( - rpl::single(settings->hideFastShare) - )->toggledValue( - ) | rpl::filter( - [=](bool enabled) - { - return (enabled != settings->hideFastShare); - }) | on_next( - [=](bool enabled) - { - AyuSettings::set_hideFastShare(enabled); - AyuSettings::save(); - }, - container->lifetime()); + AddSettingToggle(container, tr::ayu_HideShareButton(), &AyuSettings::hideFastShare, &AyuSettings::setHideFastShare); + AddSettingToggle(container, tr::ayu_SimpleQuotesAndReplies(), &AyuSettings::simpleQuotesAndReplies, &AyuSettings::setSimpleQuotesAndReplies); - AddButtonWithIcon( - container, - tr::ayu_SimpleQuotesAndReplies(), - st::settingsButtonNoIcon - )->toggleOn( - rpl::single(settings->simpleQuotesAndReplies) - )->toggledValue( - ) | rpl::filter( - [=](bool enabled) - { - return (enabled != settings->simpleQuotesAndReplies); - }) | rpl::on_next( - [=](bool enabled) - { - AyuSettings::set_simpleQuotesAndReplies(enabled); - AyuSettings::save(); - }, - container->lifetime()); - - AddSkip(container); - AddDivider(container); - AddSkip(container); + AddSectionDivider(container); } void SetupWideMessagesMultiplier(not_null container, @@ -355,12 +235,12 @@ void SetupWideMessagesMultiplier(not_null container, return kMinSize + index * kStep; }; - updateLabel(settings->wideMultiplier); + updateLabel(settings->wideMultiplier()); slider->setPseudoDiscrete( kSizeAmount, [=](int index) { return index; }, - valueToIndex(settings->wideMultiplier), + valueToIndex(settings->wideMultiplier()), [=](int index) { updateLabel(indexToValue(index)); @@ -368,8 +248,7 @@ void SetupWideMessagesMultiplier(not_null container, [=](int index) { updateLabel(indexToValue(index)); - AyuSettings::set_wideMultiplier(indexToValue(index)); - AyuSettings::save(); + AyuSettings::getInstance().setWideMultiplier(indexToValue(index)); // fix slider crl::on_main([=] @@ -406,95 +285,88 @@ void SetupContextMenuElements(not_null container, AddChooseButtonWithIconAndRightText( container, controller, - settings->showReactionsPanelInContextMenu, + static_cast(settings->showReactionsPanelInContextMenu()), options, tr::ayu_SettingsContextMenuReactionsPanel(), tr::ayu_SettingsContextMenuTitle(), st::menuIconReactions, [=](int index) { - AyuSettings::set_showReactionsPanelInContextMenu(index); - AyuSettings::save(); + AyuSettings::getInstance().setShowReactionsPanelInContextMenu(static_cast(index)); }); AddChooseButtonWithIconAndRightText( container, controller, - settings->showViewsPanelInContextMenu, + static_cast(settings->showViewsPanelInContextMenu()), options, tr::ayu_SettingsContextMenuViewsPanel(), tr::ayu_SettingsContextMenuTitle(), st::menuIconShowInChat, [=](int index) { - AyuSettings::set_showViewsPanelInContextMenu(index); - AyuSettings::save(); + AyuSettings::getInstance().setShowViewsPanelInContextMenu(static_cast(index)); }); AddChooseButtonWithIconAndRightText( container, controller, - settings->showHideMessageInContextMenu, + static_cast(settings->showHideMessageInContextMenu()), options, tr::ayu_ContextHideMessage(), tr::ayu_SettingsContextMenuTitle(), st::menuIconClear, [=](int index) { - AyuSettings::set_showHideMessageInContextMenu(index); - AyuSettings::save(); + AyuSettings::getInstance().setShowHideMessageInContextMenu(static_cast(index)); }); AddChooseButtonWithIconAndRightText( container, controller, - settings->showUserMessagesInContextMenu, + static_cast(settings->showUserMessagesInContextMenu()), options, tr::ayu_UserMessagesMenuText(), tr::ayu_SettingsContextMenuTitle(), st::menuIconTTL, [=](int index) { - AyuSettings::set_showUserMessagesInContextMenu(index); - AyuSettings::save(); + AyuSettings::getInstance().setShowUserMessagesInContextMenu(static_cast(index)); }); AddChooseButtonWithIconAndRightText( container, controller, - settings->showMessageDetailsInContextMenu, + static_cast(settings->showMessageDetailsInContextMenu()), options, tr::ayu_MessageDetailsPC(), tr::ayu_SettingsContextMenuTitle(), st::menuIconInfo, [=](int index) { - AyuSettings::set_showMessageDetailsInContextMenu(index); - AyuSettings::save(); + AyuSettings::getInstance().setShowMessageDetailsInContextMenu(static_cast(index)); }); AddChooseButtonWithIconAndRightText( container, controller, - settings->showRepeatMessageInContextMenu, + static_cast(settings->showRepeatMessageInContextMenu()), options, tr::ayu_RepeatMessage(), tr::ayu_SettingsContextMenuTitle(), st::menuIconRestore, [=](int index) { - AyuSettings::set_showRepeatMessageInContextMenu(index); - AyuSettings::save(); + AyuSettings::getInstance().setShowRepeatMessageInContextMenu(static_cast(index)); }); - if (settings->filtersEnabled) { + if (settings->filtersEnabled()) { AddChooseButtonWithIconAndRightText( container, controller, - settings->showAddFilterInContextMenu, + static_cast(settings->showAddFilterInContextMenu()), options, tr::ayu_RegexFilterQuickAdd(), tr::ayu_SettingsContextMenuTitle(), st::menuIconAddToFolder, [=](int index) { - AyuSettings::set_showAddFilterInContextMenu(index); - AyuSettings::save(); + AyuSettings::getInstance().setShowAddFilterInContextMenu(static_cast(index)); }); } @@ -504,159 +376,22 @@ void SetupContextMenuElements(not_null container, } void SetupMessageFieldElements(not_null container) { - auto *settings = &AyuSettings::getInstance(); - AddSubsectionTitle(container, tr::ayu_MessageFieldElementsHeader()); - AddButtonWithIcon( - container, - tr::ayu_MessageFieldElementAttach(), - st::settingsButton, - {&st::messageFieldAttachIcon} - )->toggleOn( - rpl::single(settings->showAttachButtonInMessageField) - )->toggledValue( - ) | rpl::filter( - [=](bool enabled) - { - return (enabled != settings->showAttachButtonInMessageField); - }) | rpl::on_next( - [=](bool enabled) - { - AyuSettings::set_showAttachButtonInMessageField(enabled); - AyuSettings::save(); - }, - container->lifetime()); + AddSettingToggle(container, tr::ayu_MessageFieldElementAttach(), &AyuSettings::showAttachButtonInMessageField, &AyuSettings::setShowAttachButtonInMessageField, st::messageFieldAttachIcon); + AddSettingToggle(container, tr::ayu_MessageFieldElementCommands(), &AyuSettings::showCommandsButtonInMessageField, &AyuSettings::setShowCommandsButtonInMessageField, st::messageFieldCommandsIcon); + AddSettingToggle(container, tr::ayu_MessageFieldElementTTL(), &AyuSettings::showAutoDeleteButtonInMessageField, &AyuSettings::setShowAutoDeleteButtonInMessageField, st::messageFieldTTLIcon); + AddSettingToggle(container, tr::ayu_MessageFieldElementEmoji(), &AyuSettings::showEmojiButtonInMessageField, &AyuSettings::setShowEmojiButtonInMessageField, st::messageFieldEmojiIcon); + AddSettingToggle(container, tr::ayu_MessageFieldElementVoice(), &AyuSettings::showMicrophoneButtonInMessageField, &AyuSettings::setShowMicrophoneButtonInMessageField, st::messageFieldVoiceIcon); - AddButtonWithIcon( - container, - tr::ayu_MessageFieldElementCommands(), - st::settingsButton, - {&st::messageFieldCommandsIcon} - )->toggleOn( - rpl::single(settings->showCommandsButtonInMessageField) - )->toggledValue( - ) | rpl::filter( - [=](bool enabled) - { - return (enabled != settings->showCommandsButtonInMessageField); - }) | rpl::on_next( - [=](bool enabled) - { - AyuSettings::set_showCommandsButtonInMessageField(enabled); - AyuSettings::save(); - }, - container->lifetime()); - - AddButtonWithIcon( - container, - tr::ayu_MessageFieldElementTTL(), - st::settingsButton, - {&st::messageFieldTTLIcon} - )->toggleOn( - rpl::single(settings->showAutoDeleteButtonInMessageField) - )->toggledValue( - ) | rpl::filter( - [=](bool enabled) - { - return (enabled != settings->showAutoDeleteButtonInMessageField); - }) | rpl::on_next( - [=](bool enabled) - { - AyuSettings::set_showAutoDeleteButtonInMessageField(enabled); - AyuSettings::save(); - }, - container->lifetime()); - - AddButtonWithIcon( - container, - tr::ayu_MessageFieldElementEmoji(), - st::settingsButton, - {&st::messageFieldEmojiIcon} - )->toggleOn( - rpl::single(settings->showEmojiButtonInMessageField) - )->toggledValue( - ) | rpl::filter( - [=](bool enabled) - { - return (enabled != settings->showEmojiButtonInMessageField); - }) | rpl::on_next( - [=](bool enabled) - { - AyuSettings::set_showEmojiButtonInMessageField(enabled); - AyuSettings::save(); - }, - container->lifetime()); - - AddButtonWithIcon( - container, - tr::ayu_MessageFieldElementVoice(), - st::settingsButton, - {&st::messageFieldVoiceIcon} - )->toggleOn( - rpl::single(settings->showMicrophoneButtonInMessageField) - )->toggledValue( - ) | rpl::filter( - [=](bool enabled) - { - return (enabled != settings->showMicrophoneButtonInMessageField); - }) | rpl::on_next( - [=](bool enabled) - { - AyuSettings::set_showMicrophoneButtonInMessageField(enabled); - AyuSettings::save(); - }, - container->lifetime()); - - AddSkip(container); - AddDivider(container); - AddSkip(container); + AddSectionDivider(container); } void SetupMessageFieldPopups(not_null container) { - auto *settings = &AyuSettings::getInstance(); - AddSubsectionTitle(container, tr::ayu_MessageFieldPopupsHeader()); - AddButtonWithIcon( - container, - tr::ayu_MessageFieldElementAttach(), - st::settingsButton, - {&st::messageFieldAttachIcon} - )->toggleOn( - rpl::single(settings->showAttachPopup) - )->toggledValue( - ) | rpl::filter( - [=](bool enabled) - { - return (enabled != settings->showAttachPopup); - }) | rpl::on_next( - [=](bool enabled) - { - AyuSettings::set_showAttachPopup(enabled); - AyuSettings::save(); - }, - container->lifetime()); - - AddButtonWithIcon( - container, - tr::ayu_MessageFieldElementEmoji(), - st::settingsButton, - {&st::messageFieldEmojiIcon} - )->toggleOn( - rpl::single(settings->showEmojiPopup) - )->toggledValue( - ) | rpl::filter( - [=](bool enabled) - { - return (enabled != settings->showEmojiPopup); - }) | rpl::on_next( - [=](bool enabled) - { - AyuSettings::set_showEmojiPopup(enabled); - AyuSettings::save(); - }, - container->lifetime()); + AddSettingToggle(container, tr::ayu_MessageFieldElementAttach(), &AyuSettings::showAttachPopup, &AyuSettings::setShowAttachPopup, st::messageFieldAttachIcon); + AddSettingToggle(container, tr::ayu_MessageFieldElementEmoji(), &AyuSettings::showEmojiPopup, &AyuSettings::setShowEmojiPopup, st::messageFieldEmojiIcon); } void AyuChats::setupContent(not_null controller) { diff --git a/Telegram/SourceFiles/ayu/ui/settings/settings_filters.cpp b/Telegram/SourceFiles/ayu/ui/settings/settings_filters.cpp index b2e9aa5c1b..1eb7c65b6c 100644 --- a/Telegram/SourceFiles/ayu/ui/settings/settings_filters.cpp +++ b/Telegram/SourceFiles/ayu/ui/settings/settings_filters.cpp @@ -11,6 +11,7 @@ #include "ayu/data/ayu_database.h" #include "ayu/features/filters/filters_cache_controller.h" #include "ayu/ui/boxes/import_filters_box.h" +#include "ayu/ui/settings/settings_ayu_utils.h" #include "ayu/utils/telegram_helpers.h" #include "boxes/abstract_box.h" #include "boxes/peer_list_box.h" @@ -100,7 +101,7 @@ void AyuFilters::fillTopBarMenu(const Ui::Menu::MenuCallback &addAction) { AyuDatabase::deleteAllFilters(); AyuDatabase::deleteAllExclusions(); FiltersCacheController::rebuildCache(); - AyuSettings::fire_filtersUpdate(); + FiltersCacheController::fireUpdate(); close(); }; @@ -132,20 +133,19 @@ void SetupFiltersSettings(not_null container) { tr::ayu_RegexFiltersEnable(), st::settingsButtonNoIcon )->toggleOn( - rpl::single(settings->filtersEnabled) + rpl::single(settings->filtersEnabled()) )->toggledValue( ) | rpl::filter( [=](bool enabled) { - return (enabled != settings->filtersEnabled); + return (enabled != settings->filtersEnabled()); }) | on_next( [=](bool enabled) { - AyuSettings::set_filtersEnabled(enabled); - AyuSettings::save(); + AyuSettings::getInstance().setFiltersEnabled(enabled); FiltersCacheController::rebuildCache(); - AyuSettings::fire_filtersUpdate(); + FiltersCacheController::fireUpdate(); }, container->lifetime()); @@ -154,20 +154,19 @@ void SetupFiltersSettings(not_null container) { tr::ayu_RegexFiltersEnableSharedInChats(), st::settingsButtonNoIcon )->toggleOn( - rpl::single(settings->filtersEnabledInChats) + rpl::single(settings->filtersEnabledInChats()) )->toggledValue( ) | rpl::filter( [=](bool enabled) { - return (enabled != settings->filtersEnabledInChats); + return (enabled != settings->filtersEnabledInChats()); }) | on_next( [=](bool enabled) { - AyuSettings::set_filtersEnabledInChats(enabled); - AyuSettings::save(); + AyuSettings::getInstance().setFiltersEnabledInChats(enabled); FiltersCacheController::rebuildCache(); - AyuSettings::fire_filtersUpdate(); + FiltersCacheController::fireUpdate(); }, container->lifetime()); @@ -177,20 +176,19 @@ void SetupFiltersSettings(not_null container) { tr::ayu_FiltersHideFromBlocked(), st::settingsButtonNoIcon )->toggleOn( - rpl::single(settings->hideFromBlocked) + rpl::single(settings->hideFromBlocked()) )->toggledValue( ) | rpl::filter( [=](bool enabled) { - return (enabled != settings->hideFromBlocked); + return (enabled != settings->hideFromBlocked()); }) | on_next( [=](bool enabled) { - AyuSettings::set_hideFromBlocked(enabled); - AyuSettings::save(); + AyuSettings::getInstance().setHideFromBlocked(enabled); FiltersCacheController::rebuildCache(); - AyuSettings::fire_filtersUpdate(); + FiltersCacheController::fireUpdate(); }, container->lifetime()); AddSkip(container); @@ -251,28 +249,9 @@ void SetupPerDialog( } void SetupMessageFilters(not_null container) { - auto *settings = &AyuSettings::getInstance(); - AddSubsectionTitle(container, tr::ayu_RegexFilters()); - AddButtonWithIcon( - container, - tr::ayu_FiltersHideFromBlocked(), - st::settingsButtonNoIcon - )->toggleOn( - rpl::single(settings->hideFromBlocked) - )->toggledValue( - ) | rpl::filter( - [=](bool enabled) - { - return (enabled != settings->hideFromBlocked); - }) | on_next( - [=](bool enabled) - { - AyuSettings::set_hideFromBlocked(enabled); - AyuSettings::save(); - }, - container->lifetime()); + AddSettingToggle(container, tr::ayu_FiltersHideFromBlocked(), &AyuSettings::hideFromBlocked, &AyuSettings::setHideFromBlocked); } void AyuFilters::setupContent(not_null controller) { diff --git a/Telegram/SourceFiles/ayu/ui/settings/settings_general.cpp b/Telegram/SourceFiles/ayu/ui/settings/settings_general.cpp index 7f7428fe4c..826a6992d4 100644 --- a/Telegram/SourceFiles/ayu/ui/settings/settings_general.cpp +++ b/Telegram/SourceFiles/ayu/ui/settings/settings_general.cpp @@ -58,7 +58,7 @@ void SetupTranslator(not_null container, return 0; }; - auto currentVal = AyuSettings::get_translationProviderReactive() | rpl::map(getIndex) | rpl::map( + auto currentVal = AyuSettings::getInstance().translationProviderChanges() | rpl::map(getIndex) | rpl::map( [=](int val) { return options[val]; @@ -79,14 +79,13 @@ void SetupTranslator(not_null container, { const auto provider = (index == 0) ? "telegram" : (index == 1) ? "google" : "yandex"; - AyuSettings::set_translationProvider(provider); - AyuSettings::save(); + AyuSettings::getInstance().setTranslationProvider(provider); }; SingleChoiceBox(box, { .title = tr::ayu_TranslationProvider(), .options = options, - .initialSelection = getIndex(settings->translationProvider), + .initialSelection = getIndex(settings->translationProvider()), .callback = save, }); })); @@ -103,10 +102,10 @@ void SetupShowPeerId(not_null container, QString("Bot API") }; - auto currentVal = AyuSettings::get_showPeerIdReactive() | rpl::map( - [=](int val) + auto currentVal = AyuSettings::getInstance().showPeerIdChanges() | rpl::map( + [=](PeerIdDisplay val) { - return options[val]; + return options[static_cast(val)]; }); const auto button = AddButtonWithLabel( @@ -122,14 +121,13 @@ void SetupShowPeerId(not_null container, { const auto save = [=](int index) { - AyuSettings::set_showPeerId(index); - AyuSettings::save(); + AyuSettings::getInstance().setShowPeerId(static_cast(index)); }; SingleChoiceBox(box, { .title = tr::ayu_SettingsShowID(), .options = options, - .initialSelection = settings->showPeerId, + .initialSelection = static_cast(settings->showPeerId()), .callback = save, }); })); @@ -140,88 +138,47 @@ void SetupQoLToggles(not_null container, not_nulltoggleOn( - rpl::single(settings->disableStories) - )->toggledValue( - ) | rpl::filter( - [=](bool enabled) - { - return (enabled != settings->disableStories); - }) | rpl::on_next( - [=](bool enabled) - { - AyuSettings::set_disableStories(enabled); - AyuSettings::save(); - }, - container->lifetime()); + AddSettingToggle(container, tr::ayu_DisableStories(), &AyuSettings::disableStories, &AyuSettings::setDisableStories); std::vector checkboxes = { NestedEntry{ - tr::ayu_CollapseSimilarChannels(tr::now), settings->collapseSimilarChannels, [=](bool enabled) - { - AyuSettings::set_collapseSimilarChannels(enabled); - AyuSettings::save(); - } + tr::ayu_CollapseSimilarChannels(tr::now), + [] { return AyuSettings::getInstance().collapseSimilarChannels(); }, + [](bool v) { AyuSettings::getInstance().setCollapseSimilarChannels(v); } }, NestedEntry{ - tr::ayu_HideSimilarChannelsTab(tr::now), settings->hideSimilarChannels, [=](bool enabled) - { - AyuSettings::set_hideSimilarChannels(enabled); - AyuSettings::save(); - } + tr::ayu_HideSimilarChannelsTab(tr::now), + [] { return AyuSettings::getInstance().hideSimilarChannels(); }, + [](bool v) { AyuSettings::getInstance().setHideSimilarChannels(v); } } }; AddCollapsibleToggle(container, tr::ayu_DisableSimilarChannels(), checkboxes, true); - AddButtonWithIcon( - container, - tr::ayu_DisableNotificationsDelay(), - st::settingsButtonNoIcon - )->toggleOn( - rpl::single(settings->disableNotificationsDelay) - )->toggledValue( - ) | rpl::filter([=](bool enabled) - { - return (enabled != settings->disableNotificationsDelay); - }) | on_next([=](bool enabled) - { - AyuSettings::set_disableNotificationsDelay(enabled); - AyuSettings::save(); - }, - container->lifetime()); + AddSettingToggle(container, tr::ayu_DisableNotificationsDelay(), &AyuSettings::disableNotificationsDelay, &AyuSettings::setDisableNotificationsDelay); - AddSkip(container); - AddDivider(container); - AddSkip(container); + AddSectionDivider(container); AddButtonWithIcon( container, tr::ayu_FilterZalgo(), st::settingsButtonNoIcon )->toggleOn( - rpl::single(settings->filterZalgo) + rpl::single(settings->filterZalgo()) )->toggledValue( ) | rpl::filter( [=](bool enabled) { - return (enabled != settings->filterZalgo); + return (enabled != settings->filterZalgo()); }) | on_next( [=](bool enabled) { - AyuSettings::set_filterZalgo(enabled); - AyuSettings::save(); + AyuSettings::getInstance().setFilterZalgo(enabled); // restart because hooks for filter are in Peer::setName which can be updated only on restart // same for HistoryItem::setText @@ -237,134 +194,39 @@ void SetupQoLToggles(not_null container, not_nulllifetime()); - AddButtonWithIcon( - container, - tr::ayu_SettingsShowMessageSeconds(), - st::settingsButtonNoIcon - )->toggleOn( - rpl::single(settings->showMessageSeconds) - )->toggledValue( - ) | rpl::filter( - [=](bool enabled) - { - return (enabled != settings->showMessageSeconds); - }) | on_next( - [=](bool enabled) - { - AyuSettings::set_showMessageSeconds(enabled); - AyuSettings::save(); - }, - container->lifetime()); + AddSettingToggle(container, tr::ayu_SettingsShowMessageSeconds(), &AyuSettings::showMessageSeconds, &AyuSettings::setShowMessageSeconds); SetupShowPeerId(container, controller); - AddSkip(container); - AddDivider(container); - AddSkip(container); + AddSectionDivider(container); AddSubsectionTitle(container, rpl::single(QString("Webview"))); - AddButtonWithIcon( - container, - tr::ayu_SettingsSpoofWebviewAsAndroid(), - st::settingsButtonNoIcon - )->toggleOn( - rpl::single(settings->spoofWebviewAsAndroid) - )->toggledValue( - ) | rpl::filter( - [=](bool enabled) - { - return (enabled != settings->spoofWebviewAsAndroid); - }) | on_next( - [=](bool enabled) - { - AyuSettings::set_spoofWebviewAsAndroid(enabled); - AyuSettings::save(); - }, - container->lifetime()); + AddSettingToggle(container, tr::ayu_SettingsSpoofWebviewAsAndroid(), &AyuSettings::spoofWebviewAsAndroid, &AyuSettings::setSpoofWebviewAsAndroid); std::vector webviewCheckboxes = { NestedEntry{ - tr::ayu_SettingsIncreaseWebviewHeight(tr::now), settings->increaseWebviewHeight, [=](bool enabled) - { - AyuSettings::set_increaseWebviewHeight(enabled); - AyuSettings::save(); - } + tr::ayu_SettingsIncreaseWebviewHeight(tr::now), + [] { return AyuSettings::getInstance().increaseWebviewHeight(); }, + [](bool v) { AyuSettings::getInstance().setIncreaseWebviewHeight(v); } }, NestedEntry{ - tr::ayu_SettingsIncreaseWebviewWidth(tr::now), settings->increaseWebviewWidth, [=](bool enabled) - { - AyuSettings::set_increaseWebviewWidth(enabled); - AyuSettings::save(); - } + tr::ayu_SettingsIncreaseWebviewWidth(tr::now), + [] { return AyuSettings::getInstance().increaseWebviewWidth(); }, + [](bool v) { AyuSettings::getInstance().setIncreaseWebviewWidth(v); } } }; AddCollapsibleToggle(container, tr::ayu_SettingsBiggerWindow(), webviewCheckboxes, false); - AddSkip(container); - AddDivider(container); - AddSkip(container); + AddSectionDivider(container); // todo: move into a single checkbox with dropdown AddSubsectionTitle(container, tr::ayu_ConfirmationsTitle()); - AddButtonWithIcon( - container, - tr::ayu_StickerConfirmation(), - st::settingsButtonNoIcon - )->toggleOn( - rpl::single(settings->stickerConfirmation) - )->toggledValue( - ) | rpl::filter( - [=](bool enabled) - { - return (enabled != settings->stickerConfirmation); - }) | on_next( - [=](bool enabled) - { - AyuSettings::set_stickerConfirmation(enabled); - AyuSettings::save(); - }, - container->lifetime()); - - AddButtonWithIcon( - container, - tr::ayu_GIFConfirmation(), - st::settingsButtonNoIcon - )->toggleOn( - rpl::single(settings->gifConfirmation) - )->toggledValue( - ) | rpl::filter( - [=](bool enabled) - { - return (enabled != settings->gifConfirmation); - }) | on_next( - [=](bool enabled) - { - AyuSettings::set_gifConfirmation(enabled); - AyuSettings::save(); - }, - container->lifetime()); - - AddButtonWithIcon( - container, - tr::ayu_VoiceConfirmation(), - st::settingsButtonNoIcon - )->toggleOn( - rpl::single(settings->voiceConfirmation) - )->toggledValue( - ) | rpl::filter( - [=](bool enabled) - { - return (enabled != settings->voiceConfirmation); - }) | on_next( - [=](bool enabled) - { - AyuSettings::set_voiceConfirmation(enabled); - AyuSettings::save(); - }, - container->lifetime()); + AddSettingToggle(container, tr::ayu_StickerConfirmation(), &AyuSettings::stickerConfirmation, &AyuSettings::setStickerConfirmation); + AddSettingToggle(container, tr::ayu_GIFConfirmation(), &AyuSettings::gifConfirmation, &AyuSettings::setGifConfirmation); + AddSettingToggle(container, tr::ayu_VoiceConfirmation(), &AyuSettings::voiceConfirmation, &AyuSettings::setVoiceConfirmation); } void AyuGeneral::setupContent(not_null controller) { diff --git a/Telegram/SourceFiles/ayu/ui/settings/settings_main.cpp b/Telegram/SourceFiles/ayu/ui/settings/settings_main.cpp index 473c54621f..192749346a 100644 --- a/Telegram/SourceFiles/ayu/ui/settings/settings_main.cpp +++ b/Telegram/SourceFiles/ayu/ui/settings/settings_main.cpp @@ -208,9 +208,7 @@ void AyuMain::setupContent(not_null controller) { AddSubsectionTitle(content, tr::ayu_CategoriesHeader()); SetupCategories(content, controller, showOtherMethod()); - AddSkip(content); - AddDivider(content); - AddSkip(content); + AddSectionDivider(content); AddSubsectionTitle(content, tr::ayu_LinksHeader()); SetupLinks(content, controller); diff --git a/Telegram/SourceFiles/ayu/ui/settings/settings_other.cpp b/Telegram/SourceFiles/ayu/ui/settings/settings_other.cpp index e9d5c4c5de..d6e22356ab 100644 --- a/Telegram/SourceFiles/ayu/ui/settings/settings_other.cpp +++ b/Telegram/SourceFiles/ayu/ui/settings/settings_other.cpp @@ -13,6 +13,7 @@ #include "lang_auto.h" #include "ayu/ayu_settings.h" #include "ayu/ui/boxes/donate_qr_box.h" +#include "ayu/ui/settings/settings_ayu_utils.h" #include "boxes/abstract_box.h" #include "core/application.h" #include "lang/lang_text_entity.h" @@ -174,30 +175,10 @@ void SetupDonations(not_null container, not_null container) { - auto *settings = &AyuSettings::getInstance(); - AddSkip(container); AddSubsectionTitle(container, tr::ayu_CategoryOther()); - AddButtonWithIcon( - container, - tr::ayu_CrashReporting(), - st::settingsButton, - {&st::menuIconReport} - )->toggleOn( - rpl::single(settings->crashReporting) - )->toggledValue( - ) | rpl::filter( - [=](bool enabled) - { - return (enabled != settings->crashReporting); - }) | on_next( - [=](bool enabled) - { - AyuSettings::set_crashReporting(enabled); - AyuSettings::save(); - }, - container->lifetime()); + AddSettingToggle(container, tr::ayu_CrashReporting(), &AyuSettings::crashReporting, &AyuSettings::setCrashReporting, st::menuIconReport); AddSkip(container); AddDividerText(container, tr::ayu_CrashReportingDescription()); } diff --git a/Telegram/SourceFiles/ayu/ui/utils/ayu_profile_values.cpp b/Telegram/SourceFiles/ayu/ui/utils/ayu_profile_values.cpp index 61f3a27d2d..e1f366bd0c 100644 --- a/Telegram/SourceFiles/ayu/ui/utils/ayu_profile_values.cpp +++ b/Telegram/SourceFiles/ayu/ui/utils/ayu_profile_values.cpp @@ -17,7 +17,7 @@ QString IDString(const not_null peer) { auto resultId = QString::number(getBareID(peer)); const auto &settings = AyuSettings::getInstance(); - if (settings.showPeerId == 2) { + if (settings.showPeerId() == PeerIdDisplay::BotApi) { if (peer->isChannel()) { resultId = QString::number(peerToChannel(peer->id).bare - kMaxChannelId).prepend("-"); } else if (peer->isChat()) { diff --git a/Telegram/SourceFiles/ayu/utils/telegram_helpers.cpp b/Telegram/SourceFiles/ayu/utils/telegram_helpers.cpp index 15a558e480..241b6bed7a 100644 --- a/Telegram/SourceFiles/ayu/utils/telegram_helpers.cpp +++ b/Telegram/SourceFiles/ayu/utils/telegram_helpers.cpp @@ -409,7 +409,7 @@ QString formatMessageTime(const QTime &time) { const auto &settings = AyuSettings::getInstance(); const auto format = - settings.showMessageSeconds + settings.showMessageSeconds() ? (QLocale().timeFormat(QLocale::ShortFormat).contains("AP") ? "h:mm:ss AP" : "HH:mm:ss") @@ -617,12 +617,12 @@ int getScheduleTime(int64 sumSize) { bool isMessageSavable(const not_null item) { const auto &settings = AyuSettings::getInstance(); - if (!settings.saveDeletedMessages) { + if (!settings.saveDeletedMessages()) { return false; } if (const auto possiblyBot = item->history()->peer->asUser()) { - return !possiblyBot->isBot() || (settings.saveForBots && possiblyBot->isBot()); + return !possiblyBot->isBot() || (settings.saveForBots() && possiblyBot->isBot()); } return true; } diff --git a/Telegram/SourceFiles/boxes/send_files_box.cpp b/Telegram/SourceFiles/boxes/send_files_box.cpp index a6729d6062..e696a4018d 100644 --- a/Telegram/SourceFiles/boxes/send_files_box.cpp +++ b/Telegram/SourceFiles/boxes/send_files_box.cpp @@ -1947,7 +1947,8 @@ bool SendFilesBox::validateLength(const QString &text) const { void SendFilesBox::send( Api::SendOptions options, bool ctrlShiftEnter) { - if (AyuSettings::isUseScheduledMessages() && !options.scheduled) { + auto &ghost = AyuSettings::ghost(); + if (ghost.isUseScheduledMessages() && !options.scheduled) { const auto sumSize = ranges::accumulate( _list.files, 0, diff --git a/Telegram/SourceFiles/boxes/share_box.cpp b/Telegram/SourceFiles/boxes/share_box.cpp index c8b53a1c28..e6ea5a3699 100644 --- a/Telegram/SourceFiles/boxes/share_box.cpp +++ b/Telegram/SourceFiles/boxes/share_box.cpp @@ -1867,8 +1867,8 @@ ShareBox::SubmitCallback ShareBox::DefaultForwardCallback( } } - const auto &settings = AyuSettings::getInstance(); - if (!settings.sendReadMessages && settings.markReadAfterAction && history->lastMessage()) + const auto &ghost = AyuSettings::ghost(&history->owner().session()); + if (!ghost.sendReadMessages() && ghost.markReadAfterAction() && history->lastMessage()) { readHistory(history->lastMessage()); } diff --git a/Telegram/SourceFiles/boxes/sticker_set_box.cpp b/Telegram/SourceFiles/boxes/sticker_set_box.cpp index 8487093014..a90c960840 100644 --- a/Telegram/SourceFiles/boxes/sticker_set_box.cpp +++ b/Telegram/SourceFiles/boxes/sticker_set_box.cpp @@ -812,7 +812,7 @@ void StickerSetBox::updateButtons() { }, &st::menuIconProfile); - if (settings.showPeerId != 0) { + if (settings.showPeerId() != PeerIdDisplay::Hidden) { (*menu)->addAction( tr::ayu_ContextCopyID(tr::now), [weak, setId] @@ -1444,7 +1444,8 @@ void StickerSetBox::Inner::chosen( ? Ui::MessageSendingAnimationFrom() : messageSentAnimationInfo(index, sticker); - if (AyuSettings::isUseScheduledMessages() && !options.scheduled) { + auto &ghost = AyuSettings::ghost(_session); + if (ghost.isUseScheduledMessages() && !options.scheduled) { auto current = base::unixtime::now(); options.scheduled = current + 12; } @@ -1503,7 +1504,7 @@ void StickerSetBox::Inner::contextMenuEvent(QContextMenuEvent *e) { }, &st::menuIconCopy); const auto &settings = AyuSettings::getInstance(); - if (settings.showPeerId != 0) { + if (settings.showPeerId() != PeerIdDisplay::Hidden) { _menu->addAction(tr::ayu_ContextCopyID(tr::now), [=] { diff --git a/Telegram/SourceFiles/chat_helpers/emoji_list_widget.cpp b/Telegram/SourceFiles/chat_helpers/emoji_list_widget.cpp index b6c80cbd4a..2b82521fb7 100644 --- a/Telegram/SourceFiles/chat_helpers/emoji_list_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/emoji_list_widget.cpp @@ -2313,7 +2313,7 @@ void EmojiListWidget::refreshCustom() { const auto push = [&](uint64 setId, bool installed) { const auto megagroup = _megagroupSet && (setId == Data::Stickers::MegagroupSetId); - if (settings.showOnlyAddedEmojisAndStickers && !installed && !megagroup) { + if (settings.showOnlyAddedEmojisAndStickers() && !installed && !megagroup) { return; } const auto lookupId = megagroup diff --git a/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp b/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp index aa42ffc73a..13e3ff2cb4 100644 --- a/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp +++ b/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp @@ -412,7 +412,7 @@ FieldAutocomplete::StickerRows FieldAutocomplete::getStickerSuggestions() { auto result = ranges::views::all( list ) | ranges::views::filter([&](not_null sticker) { - return !settings.showOnlyAddedEmojisAndStickers + return !settings.showOnlyAddedEmojisAndStickers() || sticker->isStickerSetInstalled(); }) | ranges::views::transform([](not_null sticker) { return StickerSuggestion{ diff --git a/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp b/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp index 4d41fc38cc..b167c806ed 100644 --- a/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp @@ -502,8 +502,8 @@ void GifsListWidget::selectInlineResult( return; } - const auto &settings = AyuSettings::getInstance(); - if (AyuSettings::isUseScheduledMessages()) { + auto &ghost = AyuSettings::ghost(&session()); + if (ghost.isUseScheduledMessages() && !options.scheduled) { auto current = base::unixtime::now(); options.scheduled = current + 12; } @@ -553,7 +553,8 @@ void GifsListWidget::selectInlineResult( }); }); - if (settings.gifConfirmation) { + const auto &settings = AyuSettings::getInstance(); + if (settings.gifConfirmation()) { Ui::show(Ui::MakeConfirmBox({ .text = tr::ayu_ConfirmationGIF(), .confirmed = sendGIFCallback, diff --git a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp index 4e899a8bad..2758f8bb4f 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp @@ -853,7 +853,7 @@ void StickersListWidget::fillFilteredStickersRow() { void StickersListWidget::addSearchRow(not_null set) { const auto &settings = AyuSettings::getInstance(); - if (settings.showOnlyAddedEmojisAndStickers && !SetInMyList(set->flags)) { + if (settings.showOnlyAddedEmojisAndStickers() && !SetInMyList(set->flags)) { return; } const auto skipPremium = !session().premiumPossible(); @@ -2170,7 +2170,8 @@ void StickersListWidget::mouseReleaseEvent(QMouseEvent *e) { document ); auto options = Api::SendOptions(); - if (AyuSettings::isUseScheduledMessages()) { + auto &ghost = AyuSettings::ghost(&session()); + if (ghost.isUseScheduledMessages() && !options.scheduled) { auto current = base::unixtime::now(); options.scheduled = current + 12; } @@ -2185,7 +2186,7 @@ void StickersListWidget::mouseReleaseEvent(QMouseEvent *e) { }); }); - if (settings.stickerConfirmation && (_mode == Mode::Full || _mode == Mode::ChatIntro) && _requireConfirmation) { + if (settings.stickerConfirmation() && (_mode == Mode::Full || _mode == Mode::ChatIntro) && _requireConfirmation) { Ui::show(Ui::MakeConfirmBox({ .text = tr::ayu_ConfirmationSticker(), .confirmed = sendStickerCallback, @@ -2599,7 +2600,7 @@ auto StickersListWidget::collectRecentStickers() -> std::vector { const auto &settings = AyuSettings::getInstance(); auto add = [&](not_null document, bool custom) { - if (result.size() >= settings.recentStickersCount) { + if (result.size() >= settings.recentStickersCount()) { return; } const auto i = ranges::find(result, document, &Sticker::document); diff --git a/Telegram/SourceFiles/chat_helpers/tabbed_panel.cpp b/Telegram/SourceFiles/chat_helpers/tabbed_panel.cpp index 518cb24067..0f7d674834 100644 --- a/Telegram/SourceFiles/chat_helpers/tabbed_panel.cpp +++ b/Telegram/SourceFiles/chat_helpers/tabbed_panel.cpp @@ -485,7 +485,7 @@ void TabbedPanel::showStarted() { bool TabbedPanel::eventFilter(QObject *obj, QEvent *e) { const auto &settings = AyuSettings::getInstance(); - if (TabbedPanelShowOnClick.value() || !settings.showEmojiPopup) { + if (TabbedPanelShowOnClick.value() || !settings.showEmojiPopup()) { return false; } else if (e->type() == QEvent::Enter) { otherEnter(); diff --git a/Telegram/SourceFiles/chat_helpers/ttl_media_layer_widget.cpp b/Telegram/SourceFiles/chat_helpers/ttl_media_layer_widget.cpp index d31bcbf829..4c5d996d10 100644 --- a/Telegram/SourceFiles/chat_helpers/ttl_media_layer_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/ttl_media_layer_widget.cpp @@ -201,7 +201,7 @@ PreviewWrap::PreviewWrap( { const auto close = Ui::CreateChild( this, - item->out() || settings.saveDeletedMessages + item->out() || settings.saveDeletedMessages() ? tr::lng_close() : tr::lng_ttl_voice_close_in(), st::ttlMediaButton); @@ -235,8 +235,8 @@ PreviewWrap::PreviewWrap( ) | rpl::map(tr::rich), tr::rich) : (isRound - ? settings.saveDeletedMessages ? tr::ayu_ExpiringVideoMessageNote : tr::lng_ttl_round_tooltip_in - : settings.saveDeletedMessages ? tr::ayu_ExpiringVoiceMessageNote : tr::lng_ttl_voice_tooltip_in)(tr::rich); + ? settings.saveDeletedMessages() ? tr::ayu_ExpiringVideoMessageNote : tr::lng_ttl_round_tooltip_in + : settings.saveDeletedMessages() ? tr::ayu_ExpiringVoiceMessageNote : tr::lng_ttl_voice_tooltip_in)(tr::rich); const auto tooltip = Ui::CreateChild( this, object_ptr>( diff --git a/Telegram/SourceFiles/core/crash_report_window.cpp b/Telegram/SourceFiles/core/crash_report_window.cpp index 07672df5bc..e350495633 100644 --- a/Telegram/SourceFiles/core/crash_report_window.cpp +++ b/Telegram/SourceFiles/core/crash_report_window.cpp @@ -278,7 +278,7 @@ LastCrashedWindow::LastCrashedWindow( #ifndef TDESKTOP_DISABLE_AUTOUPDATE const auto &settings = AyuSettings::getInstance(); - if (!settings.crashReporting) { + if (!settings.crashReporting()) { #else if (true) { #endif diff --git a/Telegram/SourceFiles/core/local_url_handlers.cpp b/Telegram/SourceFiles/core/local_url_handlers.cpp index 8271ed6a58..7bc0daee4b 100644 --- a/Telegram/SourceFiles/core/local_url_handlers.cpp +++ b/Telegram/SourceFiles/core/local_url_handlers.cpp @@ -1839,7 +1839,7 @@ const std::vector &LocalUrlHandlers() { AyuUrlHandlers::HandleAyu }, { - u"^support$"_q, + u"^(support)|(donate)$"_q, AyuUrlHandlers::HandleSupport }, { diff --git a/Telegram/SourceFiles/data/components/promo_suggestions.cpp b/Telegram/SourceFiles/data/components/promo_suggestions.cpp index 1b16fcec83..d5a154e052 100644 --- a/Telegram/SourceFiles/data/components/promo_suggestions.cpp +++ b/Telegram/SourceFiles/data/components/promo_suggestions.cpp @@ -130,7 +130,7 @@ void PromoSuggestions::refreshTopPromotion() { } const auto &settings = AyuSettings::getInstance(); - if (settings.disableAds) { + if (settings.disableAds()) { setTopPromoted(nullptr, QString(), QString()); return; } diff --git a/Telegram/SourceFiles/data/components/sponsored_messages.cpp b/Telegram/SourceFiles/data/components/sponsored_messages.cpp index bfaf8834bd..dd271dc968 100644 --- a/Telegram/SourceFiles/data/components/sponsored_messages.cpp +++ b/Telegram/SourceFiles/data/components/sponsored_messages.cpp @@ -244,7 +244,7 @@ void SponsoredMessages::inject( bool SponsoredMessages::canHaveFor(not_null history) const { const auto &settings = AyuSettings::getInstance(); - if (settings.disableAds) { + if (settings.disableAds()) { return false; } @@ -258,7 +258,7 @@ bool SponsoredMessages::canHaveFor(not_null history) const { bool SponsoredMessages::canHaveFor(not_null item) const { const auto &settings = AyuSettings::getInstance(); - if (settings.disableAds) { + if (settings.disableAds()) { return false; } @@ -268,7 +268,7 @@ bool SponsoredMessages::canHaveFor(not_null item) const { bool SponsoredMessages::isTopBarFor(not_null history) const { const auto &settings = AyuSettings::getInstance(); - if (settings.disableAds) { + if (settings.disableAds()) { return false; } @@ -456,7 +456,7 @@ void SponsoredMessages::parseForVideo( SponsoredForVideo SponsoredMessages::prepareForVideo( not_null peer) { const auto &settings = AyuSettings::getInstance(); - if (settings.disableAds) { + if (settings.disableAds()) { return {}; } diff --git a/Telegram/SourceFiles/data/data_channel.cpp b/Telegram/SourceFiles/data/data_channel.cpp index cafac704ee..27e5b5cc56 100644 --- a/Telegram/SourceFiles/data/data_channel.cpp +++ b/Telegram/SourceFiles/data/data_channel.cpp @@ -140,7 +140,7 @@ void ChannelData::setName( const QString &newUsername) { auto filteredName = newName; const auto &settings = AyuSettings::getInstance(); - if (settings.filterZalgo) { + if (settings.filterZalgo()) { filteredName = filterZalgo(filteredName); } updateNameDelayed(filteredName.isEmpty() ? name() : filteredName, {}, newUsername); diff --git a/Telegram/SourceFiles/data/data_chat.cpp b/Telegram/SourceFiles/data/data_chat.cpp index c720ac88a8..ef60a655ce 100644 --- a/Telegram/SourceFiles/data/data_chat.cpp +++ b/Telegram/SourceFiles/data/data_chat.cpp @@ -119,7 +119,7 @@ bool ChatData::anyoneCanAddMembers() const { void ChatData::setName(const QString &newName) { auto filteredName = newName; const auto &settings = AyuSettings::getInstance(); - if (settings.filterZalgo) { + if (settings.filterZalgo()) { filteredName = filterZalgo(filteredName); } updateNameDelayed(filteredName.isEmpty() ? name() : filteredName, {}, {}); diff --git a/Telegram/SourceFiles/data/data_chat_filters.cpp b/Telegram/SourceFiles/data/data_chat_filters.cpp index 58de277bab..eae9126a14 100644 --- a/Telegram/SourceFiles/data/data_chat_filters.cpp +++ b/Telegram/SourceFiles/data/data_chat_filters.cpp @@ -494,7 +494,7 @@ void ChatFilters::received(const QVector &list) { auto changed = false; for (const auto &filter : list) { auto parsed = ChatFilter::FromTL(filter, _owner); - if (settings.hideAllChatsFolder && parsed.id() == 0 && list.size() > 1) { + if (settings.hideAllChatsFolder() && parsed.id() == 0 && list.size() > 1) { continue; } const auto b = begin(_list) + position; @@ -518,7 +518,7 @@ void ChatFilters::received(const QVector &list) { applyRemove(position); changed = true; } - if (!settings.hideAllChatsFolder && !ranges::contains(begin(_list), end(_list), 0, &ChatFilter::id)) { + if (!settings.hideAllChatsFolder() && !ranges::contains(begin(_list), end(_list), 0, &ChatFilter::id)) { _list.insert(begin(_list), ChatFilter()); } if (changed || !_loaded || _reloading) { @@ -535,7 +535,7 @@ void ChatFilters::apply(const MTPUpdate &update) { update.match([&](const MTPDupdateDialogFilter &data) { if (const auto filter = data.vfilter()) { auto parsed = ChatFilter::FromTL(*filter, _owner); - if (settings.hideAllChatsFolder && parsed.id() == 0) { + if (settings.hideAllChatsFolder() && parsed.id() == 0) { return; } set(parsed); @@ -918,7 +918,7 @@ FilterId ChatFilters::lookupId(int index) const { const auto &settings = AyuSettings::getInstance(); - if (_owner->session().user()->isPremium() || !_list.front().id() || settings.hideAllChatsFolder) { + if (_owner->session().user()->isPremium() || !_list.front().id() || settings.hideAllChatsFolder()) { return _list[index].id(); } const auto i = ranges::find(_list, FilterId(0), &ChatFilter::id); diff --git a/Telegram/SourceFiles/data/data_histories.cpp b/Telegram/SourceFiles/data/data_histories.cpp index ca1dfc88d6..590a66f2ff 100644 --- a/Telegram/SourceFiles/data/data_histories.cpp +++ b/Telegram/SourceFiles/data/data_histories.cpp @@ -675,8 +675,8 @@ void Histories::sendReadRequests() { DEBUG_LOG(("Reading: send requests with count %1.").arg(_states.size())); // AyuGram sendReadMessages - const auto &settings = AyuSettings::getInstance(); - if (!settings.sendReadMessages) { + const auto &ghost = AyuSettings::ghost(&_owner->session()); + if (!ghost.sendReadMessages()) { DEBUG_LOG(("[AyuGram] Don't read messages")); _states.clear(); return; diff --git a/Telegram/SourceFiles/data/data_message_reactions.cpp b/Telegram/SourceFiles/data/data_message_reactions.cpp index ea3907da05..ad5f6b0984 100644 --- a/Telegram/SourceFiles/data/data_message_reactions.cpp +++ b/Telegram/SourceFiles/data/data_message_reactions.cpp @@ -1521,8 +1521,8 @@ void Reactions::send(not_null item, bool addToRecent) { _sentRequests.remove(id); _owner->session().api().applyUpdates(result); - const auto &settings = AyuSettings::getInstance(); - if (!settings.sendReadMessages && settings.markReadAfterAction && item) { + const auto &ghost = AyuSettings::ghost(&_owner->session()); + if (!ghost.sendReadMessages() && ghost.markReadAfterAction() && item) { readHistory(item); } }).fail([=](const MTP::Error &error) { diff --git a/Telegram/SourceFiles/data/data_peer_values.cpp b/Telegram/SourceFiles/data/data_peer_values.cpp index 9c16999b49..5d2952526b 100644 --- a/Telegram/SourceFiles/data/data_peer_values.cpp +++ b/Telegram/SourceFiles/data/data_peer_values.cpp @@ -409,7 +409,7 @@ rpl::producer PeerPremiumValue(not_null peer) { rpl::producer AmPremiumValue(not_null session) { const auto &settings = AyuSettings::getInstance(); - if (settings.localPremium) { + if (settings.localPremium()) { return rpl::single(true); } @@ -499,14 +499,14 @@ QString OnlineTextFull(not_null user, TimeId now) { const auto nowFull = base::unixtime::parse(now); const auto locale = QLocale(); if (onlineFull.date() == nowFull.date()) { - const auto onlineTime = locale.toString(onlineFull.time(), settings.showMessageSeconds ? QLocale::LongFormat : QLocale::ShortFormat); + const auto onlineTime = locale.toString(onlineFull.time(), settings.showMessageSeconds() ? QLocale::LongFormat : QLocale::ShortFormat); return tr::lng_status_lastseen_today(tr::now, lt_time, onlineTime); } else if (onlineFull.date().addDays(1) == nowFull.date()) { - const auto onlineTime = locale.toString(onlineFull.time(), settings.showMessageSeconds ? QLocale::LongFormat : QLocale::ShortFormat); + const auto onlineTime = locale.toString(onlineFull.time(), settings.showMessageSeconds() ? QLocale::LongFormat : QLocale::ShortFormat); return tr::lng_status_lastseen_yesterday(tr::now, lt_time, onlineTime); } const auto date = locale.toString(onlineFull.date(), QLocale::ShortFormat); - const auto time = locale.toString(onlineFull.time(), settings.showMessageSeconds ? QLocale::LongFormat : QLocale::ShortFormat); + const auto time = locale.toString(onlineFull.time(), settings.showMessageSeconds() ? QLocale::LongFormat : QLocale::ShortFormat); return tr::lng_status_lastseen_date_time(tr::now, lt_date, date, lt_time, time); } diff --git a/Telegram/SourceFiles/data/data_replies_list.cpp b/Telegram/SourceFiles/data/data_replies_list.cpp index 1c1074d987..096d25e842 100644 --- a/Telegram/SourceFiles/data/data_replies_list.cpp +++ b/Telegram/SourceFiles/data/data_replies_list.cpp @@ -1007,8 +1007,8 @@ void RepliesList::sendReadTillRequest() { const auto api = &_history->session().api(); api->request(base::take(_readRequestId)).cancel(); - const auto &settings = AyuSettings::getInstance(); - if (!settings.sendReadMessages) { + const auto &ghost = AyuSettings::ghost(&_history->session()); + if (!ghost.sendReadMessages()) { return; } diff --git a/Telegram/SourceFiles/data/data_session.cpp b/Telegram/SourceFiles/data/data_session.cpp index f24077e7eb..3b0b9077df 100644 --- a/Telegram/SourceFiles/data/data_session.cpp +++ b/Telegram/SourceFiles/data/data_session.cpp @@ -326,7 +326,7 @@ Session::Session(not_null session) // AyuGram disableStories const auto &settings = AyuSettings::getInstance(); - if (!settings.disableStories) { + if (!settings.disableStories()) { _stories->loadMore(Data::StorySourcesList::NotHidden); } }); @@ -2681,7 +2681,7 @@ void Session::updateEditedMessage(const MTPMessage &data) { goto proceed; } edit = HistoryMessageEdition(_session, data.c_message()); - if (settings.saveMessagesHistory && !existing->isLocal() && !existing->author()->isSelf() && !edit.isEditHide) { + if (settings.saveMessagesHistory() && !existing->isLocal() && !existing->author()->isSelf() && !edit.isEditHide) { const auto msg = existing->originalText(); if (edit.textWithEntities == msg || msg.empty()) { @@ -2837,7 +2837,7 @@ void Session::checkTTLs() { _ttlCheckTimer.cancel(); const auto now = base::unixtime::now(); - if (settings.saveDeletedMessages) { + if (settings.saveDeletedMessages()) { auto toBeRemoved = ranges::views::take_while( _ttlMessages, [now](const auto &pair) { diff --git a/Telegram/SourceFiles/data/data_stories.cpp b/Telegram/SourceFiles/data/data_stories.cpp index 82245ce574..82da8db089 100644 --- a/Telegram/SourceFiles/data/data_stories.cpp +++ b/Telegram/SourceFiles/data/data_stories.cpp @@ -1238,8 +1238,8 @@ void Stories::markAsRead(FullStoryId id, bool viewed) { return; } - const auto &settings = AyuSettings::getInstance(); - if (!settings.sendReadStories) { + const auto &ghost = AyuSettings::ghost(&_owner->session()); + if (!ghost.sendReadStories()) { return; } @@ -1397,8 +1397,8 @@ void Stories::toggleHidden( void Stories::sendMarkAsReadRequest( not_null peer, StoryId tillId) { - const auto &settings = AyuSettings::getInstance(); - if (!settings.sendReadStories) { + const auto &ghost = AyuSettings::ghost(&_owner->session()); + if (!ghost.sendReadStories()) { return; } @@ -1432,8 +1432,8 @@ void Stories::checkQuitPreventFinished() { void Stories::sendMarkAsReadRequests() { _markReadTimer.cancel(); - const auto &settings = AyuSettings::getInstance(); - if (!settings.sendReadStories) { + const auto &ghost = AyuSettings::ghost(&_owner->session()); + if (!ghost.sendReadStories()) { return; } @@ -1456,8 +1456,8 @@ void Stories::sendIncrementViewsRequests() { return; } - const auto &settings = AyuSettings::getInstance(); - if (!settings.sendReadStories) { + const auto &ghost = AyuSettings::ghost(&_owner->session()); + if (!ghost.sendReadStories()) { return; } @@ -2311,8 +2311,8 @@ bool Stories::isQuitPrevent() { sendIncrementViewsRequests(); } - const auto &settings = AyuSettings::getInstance(); - if (!settings.sendReadStories || _markReadRequests.empty() && _incrementViewsRequests.empty()) { + const auto &ghost = AyuSettings::ghost(&_owner->session()); + if (!ghost.sendReadStories() || _markReadRequests.empty() && _incrementViewsRequests.empty()) { return false; } LOG(("Stories prevents quit, marking as read...")); diff --git a/Telegram/SourceFiles/data/data_user.cpp b/Telegram/SourceFiles/data/data_user.cpp index de99780d12..95fcfbb83e 100644 --- a/Telegram/SourceFiles/data/data_user.cpp +++ b/Telegram/SourceFiles/data/data_user.cpp @@ -350,7 +350,7 @@ void UserData::setName( auto filteredLastName = newLastName; const auto &settings = AyuSettings::getInstance(); - if (settings.filterZalgo) { + if (settings.filterZalgo()) { filteredFirstName = filterZalgo(filteredFirstName); filteredLastName = filterZalgo(filteredLastName); } @@ -607,7 +607,7 @@ bool UserData::isFake() const { bool UserData::isPremium() const { if (id) { const auto &settings = AyuSettings::getInstance(); - if (settings.localPremium) { + if (settings.localPremium()) { if (getSession(id.value)) { return true; } diff --git a/Telegram/SourceFiles/dialogs/dialogs_row.cpp b/Telegram/SourceFiles/dialogs/dialogs_row.cpp index 20b052a560..430b21470c 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_row.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_row.cpp @@ -573,7 +573,7 @@ void Row::paintUserpic( const auto cornerBadgeShown = !_cornerBadgeUserpic ? _cornerBadgeShown : !_cornerBadgeUserpic->layersManager.isDisplayedNone(); - const auto storiesPeer = settings.disableStories ? nullptr : peer + const auto storiesPeer = settings.disableStories() ? nullptr : peer ? ((peer->isUser() || peer->isChannel()) ? peer : nullptr) : nullptr; const auto storiesFolder = peer ? nullptr : _id.folder(); diff --git a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp index ab9f5866af..08c34fd108 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp @@ -975,7 +975,7 @@ void Widget::chosenRow(const ChosenRow &row) { && (row.message.fullId.msg == ShowAtUnreadMsgId) && history->peer->hasActiveStories() && !history->peer->isSelf() - && !AyuSettings::getInstance().disableStories) { + && !AyuSettings::getInstance().disableStories()) { controller()->openPeerStories(history->peer->id); return; } else if (history @@ -1408,7 +1408,7 @@ void Widget::setupMainMenuToggle() { : &st::dialogsMenuToggleUnreadMuted; const auto &settings = AyuSettings::getInstance(); - if (settings.hideNotificationCounters) { + if (settings.hideNotificationCounters()) { icon = nullptr; } @@ -1419,7 +1419,7 @@ void Widget::setupMainMenuToggle() { void Widget::setupStories() { // AyuGram disableStories const auto &settings = AyuSettings::getInstance(); - if (settings.disableStories) { + if (settings.disableStories()) { return; } @@ -2399,7 +2399,7 @@ void Widget::updateStoriesVisibility() { } const auto &settings = AyuSettings::getInstance(); - if (settings.disableStories) { + if (settings.disableStories()) { _stories->setVisible(false); return; } diff --git a/Telegram/SourceFiles/history/history.cpp b/Telegram/SourceFiles/history/history.cpp index f5447113c5..480c1a626d 100644 --- a/Telegram/SourceFiles/history/history.cpp +++ b/Telegram/SourceFiles/history/history.cpp @@ -2456,8 +2456,8 @@ Dialogs::UnreadState History::computeUnreadState() const { result.mentions = unreadMentions().has() ? 1 : 0; const auto peer = this->peer.get(); const auto &settings = AyuSettings::getInstance(); - const auto hideReactions = (peer->isChannel() && !peer->isMegagroup() && !settings.showChannelReactions) - || (peer->isMegagroup() && !settings.showGroupReactions); + const auto hideReactions = (peer->isChannel() && !peer->isMegagroup() && !settings.showChannelReactions()) + || (peer->isMegagroup() && !settings.showGroupReactions()); result.reactions = hideReactions ? 0 : (unreadReactions().has() ? 1 : 0); result.messagesMuted = muted ? result.messages : 0; result.chatsMuted = muted ? result.chats : 0; diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index dbe414a4e9..dc629d993f 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -1242,8 +1242,8 @@ void HistoryInner::paintEvent(QPaintEvent *e) { if (markingAsViewed && item->hasUnwatchedEffect()) { const auto peer = item->history()->peer; const auto &settings = AyuSettings::getInstance(); - const auto hide = (!settings.showChannelReactions && peer->isChannel() && !peer->isMegagroup()) || - (!settings.showGroupReactions && peer->isMegagroup()); + const auto hide = (!settings.showChannelReactions() && peer->isChannel() && !peer->isMegagroup()) || + (!settings.showGroupReactions() && peer->isMegagroup()); if (!hide) { startEffects.emplace(view); } else { diff --git a/Telegram/SourceFiles/history/history_item.cpp b/Telegram/SourceFiles/history/history_item.cpp index e0ef32fdd6..21cc387e2a 100644 --- a/Telegram/SourceFiles/history/history_item.cpp +++ b/Telegram/SourceFiles/history/history_item.cpp @@ -2437,7 +2437,7 @@ void HistoryItem::clearMediaAsExpired() { } const auto &settings = AyuSettings::getInstance(); - if (settings.saveDeletedMessages) { + if (settings.saveDeletedMessages()) { return; } @@ -3503,7 +3503,7 @@ void HistoryItem::setDeleted() { if (isService()) { const auto &settings = AyuSettings::getInstance(); - setAyuHint(settings.deletedMark); + setAyuHint(settings.deletedMark()); } else { history()->owner().requestItemViewRefresh(this); history()->owner().requestItemResize(this); @@ -3952,7 +3952,7 @@ FullReplyTo HistoryItem::replyTo() const { void HistoryItem::setText(const TextWithEntities &textWithEntities) { auto text = textWithEntities; const auto &settings = AyuSettings::getInstance(); - if (settings.filterZalgo) { + if (settings.filterZalgo()) { text.text = filterZalgo(text.text); } diff --git a/Telegram/SourceFiles/history/history_item_components.cpp b/Telegram/SourceFiles/history/history_item_components.cpp index 413dd57e4c..03750dca69 100644 --- a/Telegram/SourceFiles/history/history_item_components.cpp +++ b/Telegram/SourceFiles/history/history_item_components.cpp @@ -533,7 +533,7 @@ void HistoryMessageReply::updateData( : resolvedStory ? resolvedStory->peer().get() : nullptr; - const auto blocked = settings.hideFromBlocked + const auto blocked = settings.hideFromBlocked() && author && author->isUser() && author->asUser()->isBlocked(); diff --git a/Telegram/SourceFiles/history/history_item_helpers.cpp b/Telegram/SourceFiles/history/history_item_helpers.cpp index 79683e18a3..90393f5c3d 100644 --- a/Telegram/SourceFiles/history/history_item_helpers.cpp +++ b/Telegram/SourceFiles/history/history_item_helpers.cpp @@ -611,8 +611,8 @@ QString NewMessagePostAuthor(const Api::SendAction &action) { bool ShouldSendSilent( not_null peer, const Api::SendOptions &options) { - const auto &settings = AyuSettings::getInstance(); - if (settings.sendWithoutSound) { + const auto &ghost = AyuSettings::ghost(&peer->session()); + if (ghost.sendWithoutSound()) { return !options.silent; } @@ -1186,8 +1186,8 @@ void CheckReactionNotificationSchedule( } const auto peer = item->history()->peer; const auto &settings = AyuSettings::getInstance(); - if ((peer->isChannel() && !peer->isMegagroup() && !settings.showChannelReactions) - || (peer->isMegagroup() && !settings.showGroupReactions)) { + if ((peer->isChannel() && !peer->isMegagroup() && !settings.showChannelReactions()) + || (peer->isMegagroup() && !settings.showGroupReactions())) { item->markEffectWatched(); return; } diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 063f930adf..cc9502a7f0 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -192,6 +192,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL // AyuGram includes #include "ayu/ayu_settings.h" +#include "ayu/features/filters/filters_cache_controller.h" #include "ayu/utils/telegram_helpers.h" #include "ayu/features/message_shot/message_shot.h" #include "ayu/features/forward/ayu_forward.h" @@ -526,7 +527,7 @@ HistoryWidget::HistoryWidget( _silent->setVisible(!hide); } if (_ttlInfo) { - _ttlInfo->setVisible(!hide && settings.showAutoDeleteButtonInMessageField); + _ttlInfo->setVisible(!hide && settings.showAutoDeleteButtonInMessageField()); } if (_giftToUser) { _giftToUser->setVisible(!hide); @@ -676,7 +677,7 @@ HistoryWidget::HistoryWidget( session().changes().peerUpdates( Data::PeerUpdate::Flag::IsBlocked ) | rpl::to_empty, - AyuSettings::get_filtersUpdate() + FiltersCacheController::updates() ) | rpl::on_next( [=] { @@ -808,8 +809,15 @@ HistoryWidget::HistoryWidget( } }, lifetime()); - AyuSettings::get_historyUpdateReactive() | rpl::on_next([=] - { + rpl::merge( + AyuSettings::getInstance().showAttachButtonInMessageFieldChanges() | rpl::to_empty, + AyuSettings::getInstance().showCommandsButtonInMessageFieldChanges() | rpl::to_empty, + AyuSettings::getInstance().showEmojiButtonInMessageFieldChanges() | rpl::to_empty, + AyuSettings::getInstance().showMicrophoneButtonInMessageFieldChanges() | rpl::to_empty, + AyuSettings::getInstance().showAutoDeleteButtonInMessageFieldChanges() | rpl::to_empty, + AyuSettings::getInstance().showAttachPopupChanges() | rpl::to_empty, + AyuSettings::getInstance().showEmojiPopupChanges() | rpl::to_empty + ) | rpl::on_next([=] { refreshAttachBotsMenu(); updateHistoryGeometry(); updateControlsVisibility(); @@ -1099,7 +1107,8 @@ HistoryWidget::HistoryWidget( if (action.replaceMediaOf) { } else if (action.options.scheduled) { cancelReplyOrSuggest(lastKeyboardUsed); - if (!AyuSettings::isUseScheduledMessages()) { + const auto &ghost = AyuSettings::ghost(&controller->session()); + if (!ghost.isUseScheduledMessages()) { crl::on_main(this, [=, history = action.history] { controller->showSection( @@ -2078,8 +2087,8 @@ void HistoryWidget::fileChosen(ChatHelpers::FileChosen &&data) { Data::InsertCustomEmoji(_field.data(), data.document); } } else if (_history) { - const auto &settings = AyuSettings::getInstance(); - if (!settings.sendReadMessages && settings.markReadAfterAction) { + const auto &ghost = AyuSettings::ghost(&controller()->session()); + if (!ghost.sendReadMessages() && ghost.markReadAfterAction()) { if (const auto lastMessage = history()->lastMessage()) { readHistory(lastMessage); } @@ -2990,7 +2999,7 @@ void HistoryWidget::setHistory(History *history) { const auto &settings = AyuSettings::getInstance(); const auto was = _attachBotsMenu && _history && _history->peer->isUser(); - const auto now = _attachBotsMenu && history && history->peer->isUser() && settings.showAttachPopup; + const auto now = _attachBotsMenu && history && history->peer->isUser() && settings.showAttachPopup(); if (was && !now) { _attachToggle->removeEventFilter(_attachBotsMenu.get()); _attachBotsMenu->hideFast(); @@ -3090,7 +3099,7 @@ void HistoryWidget::refreshAttachBotsMenu() { } _attachBotsMenu->setOrigin( Ui::PanelAnimation::Origin::BottomLeft); - if (settings.showAttachPopup) { + if (settings.showAttachPopup()) { _attachToggle->installEventFilter(_attachBotsMenu.get()); } _attachBotsMenu->heightValue( @@ -3645,27 +3654,27 @@ void HistoryWidget::updateControlsVisibility() { _botCommandStart->hide(); } else if (_kbReplyTo) { _kbScroll->hide(); - SWITCH_BUTTON(_tabbedSelectorToggle, settings.showEmojiButtonInMessageField); + SWITCH_BUTTON(_tabbedSelectorToggle, settings.showEmojiButtonInMessageField()); _botKeyboardHide->hide(); _botKeyboardShow->hide(); _botCommandStart->hide(); } else { _kbScroll->hide(); - SWITCH_BUTTON(_tabbedSelectorToggle, settings.showEmojiButtonInMessageField); + SWITCH_BUTTON(_tabbedSelectorToggle, settings.showEmojiButtonInMessageField()); _botKeyboardHide->hide(); if (_keyboard->hasMarkup()) { _botKeyboardShow->show(); _botCommandStart->hide(); } else { _botKeyboardShow->hide(); - _botCommandStart->setVisible(_cmdStartShown && settings.showCommandsButtonInMessageField); + _botCommandStart->setVisible(_cmdStartShown && settings.showCommandsButtonInMessageField()); } } if (_replaceMedia) { _replaceMedia->show(); _attachToggle->hide(); } else { - SWITCH_BUTTON(_attachToggle, settings.showAttachButtonInMessageField); + SWITCH_BUTTON(_attachToggle, settings.showAttachButtonInMessageField()); } if (_botMenu.button) { _botMenu.button->show(); @@ -3709,7 +3718,7 @@ void HistoryWidget::updateControlsVisibility() { } if (_ttlInfo) { const auto was = _ttlInfo->isVisible(); - const auto now = (!_editMsgId) && (!hideExtraButtons) && settings.showAutoDeleteButtonInMessageField; + const auto now = (!_editMsgId) && (!hideExtraButtons) && settings.showAutoDeleteButtonInMessageField(); if (was != now) { _ttlInfo->setVisible(now); rightButtonsChanged = true; @@ -4878,14 +4887,14 @@ void HistoryWidget::sendVoice(const VoiceToSend &data) { } void HistoryWidget::send(Api::SendOptions options) { - const auto &settings = AyuSettings::getInstance(); - if (AyuSettings::isUseScheduledMessages() && !options.scheduled) { + const auto &ghost = AyuSettings::ghost(&controller()->session()); + if (ghost.isUseScheduledMessages() && !options.scheduled) { auto current = base::unixtime::now(); options.scheduled = current + 12; } auto lastMessage = _history->lastMessage(); - if (!settings.sendReadMessages && settings.markReadAfterAction && lastMessage) { + if (!ghost.sendReadMessages() && ghost.markReadAfterAction() && lastMessage) { readHistory(lastMessage); } @@ -5090,7 +5099,7 @@ void HistoryWidget::goToDiscussionGroup() { bool HistoryWidget::hasDiscussionGroup() const { const auto &settings = AyuSettings::getInstance(); - if (settings.channelBottomButton != 2) { + if (settings.channelBottomButton() != ChannelBottomButton::DiscussWithFallback) { return false; } @@ -5705,7 +5714,7 @@ bool HistoryWidget::isChoosingTheme() const { bool HistoryWidget::isMuteUnmute() const { const auto &settings = AyuSettings::getInstance(); - if (settings.channelBottomButton == 0) { + if (settings.channelBottomButton() == ChannelBottomButton::Hidden) { return false; } @@ -5722,7 +5731,7 @@ bool HistoryWidget::isSearching() const { bool HistoryWidget::showRecordButton() const { const auto &settings = AyuSettings::getInstance(); - if (!settings.showMicrophoneButtonInMessageField) { + if (!settings.showMicrophoneButtonInMessageField()) { return false; } @@ -6001,7 +6010,7 @@ void HistoryWidget::toggleKeyboard(bool manual) { _botKeyboardHide->hide(); _botKeyboardShow->hide(); if (fieldEnabled) { - SWITCH_BUTTON(_botCommandStart, settings.showCommandsButtonInMessageField); + SWITCH_BUTTON(_botCommandStart, settings.showCommandsButtonInMessageField()); } _kbScroll->hide(); _kbShown = false; @@ -6051,7 +6060,7 @@ void HistoryWidget::toggleKeyboard(bool manual) { updateFieldPlaceholder(); SWITCH_BUTTON(_tabbedSelectorToggle, _botKeyboardHide->isHidden() && canWriteMessage() - && !_showAnimation && settings.showEmojiButtonInMessageField); + && !_showAnimation && settings.showEmojiButtonInMessageField()); updateField(); } @@ -6214,7 +6223,7 @@ void HistoryWidget::moveFieldControls() { if (_replaceMedia) { _replaceMedia->moveToLeft(left, buttonsBottom); } - if (settings.showAttachButtonInMessageField) { + if (settings.showAttachButtonInMessageField()) { _attachToggle->moveToLeft(left, buttonsBottom); left += _attachToggle->width(); } @@ -6235,14 +6244,14 @@ void HistoryWidget::moveFieldControls() { _voiceRecordBar->moveToLeft(0, bottom - _voiceRecordBar->height()); _tabbedSelectorToggle->moveToRight(right, buttonsBottom); _botKeyboardHide->moveToRight(right, buttonsBottom); - right += settings.showEmojiButtonInMessageField || !_botKeyboardHide->isHidden() ? _botKeyboardHide->width() : 0; + right += settings.showEmojiButtonInMessageField() || !_botKeyboardHide->isHidden() ? _botKeyboardHide->width() : 0; _botKeyboardShow->moveToRight(right, buttonsBottom); _botCommandStart->moveToRight(right, buttonsBottom); if (_silent) { _silent->moveToRight(right, buttonsBottom); } const auto kbShowShown = _history && !_kbShown && _keyboard->hasMarkup(); - if (kbShowShown || (_cmdStartShown && settings.showCommandsButtonInMessageField) || _silent) { + if (kbShowShown || (_cmdStartShown && settings.showCommandsButtonInMessageField()) || _silent) { right += _botCommandStart->width(); } if (_toggleSuggestPost) { @@ -6297,10 +6306,10 @@ void HistoryWidget::updateFieldSize() { const auto kbShowShown = _history && !_kbShown && _keyboard->hasMarkup(); auto fieldWidth = width() - - (settings.showAttachButtonInMessageField ? _attachToggle->width() : 0) + - (settings.showAttachButtonInMessageField() ? _attachToggle->width() : 0) - st::historySendRight - _send->width() - - (settings.showEmojiButtonInMessageField ? _tabbedSelectorToggle->width() : 0); + - (settings.showEmojiButtonInMessageField() ? _tabbedSelectorToggle->width() : 0); if (_botMenu.button) { fieldWidth -= st::historyBotMenuSkip + _botMenu.button->width(); } @@ -6310,7 +6319,7 @@ void HistoryWidget::updateFieldSize() { if (kbShowShown) { fieldWidth -= _botKeyboardShow->width(); } - if (_cmdStartShown && settings.showCommandsButtonInMessageField) { + if (_cmdStartShown && settings.showCommandsButtonInMessageField()) { fieldWidth -= _botCommandStart->width(); } if (_silent && !_silent->isHidden()) { @@ -6325,7 +6334,7 @@ void HistoryWidget::updateFieldSize() { if (_scheduled && !_scheduled->isHidden()) { fieldWidth -= _scheduled->width(); } - if (_ttlInfo && _ttlInfo->isVisible() && settings.showAutoDeleteButtonInMessageField) { + if (_ttlInfo && _ttlInfo->isVisible() && settings.showAutoDeleteButtonInMessageField()) { fieldWidth -= _ttlInfo->width(); } @@ -7535,7 +7544,7 @@ void HistoryWidget::updateBotKeyboard(History *h, bool force) { showKeyboardHideButton(); } else { _kbScroll->hide(); - SWITCH_BUTTON(_tabbedSelectorToggle, settings.showEmojiButtonInMessageField); + SWITCH_BUTTON(_tabbedSelectorToggle, settings.showEmojiButtonInMessageField()); _botKeyboardHide->hide(); } _botKeyboardShow->hide(); @@ -7559,7 +7568,7 @@ void HistoryWidget::updateBotKeyboard(History *h, bool force) { } else { if (!_showAnimation) { _kbScroll->hide(); - SWITCH_BUTTON(_tabbedSelectorToggle, settings.showEmojiButtonInMessageField); + SWITCH_BUTTON(_tabbedSelectorToggle, settings.showEmojiButtonInMessageField()); _botKeyboardHide->hide(); _botKeyboardShow->show(); _botCommandStart->hide(); @@ -7582,7 +7591,7 @@ void HistoryWidget::updateBotKeyboard(History *h, bool force) { _tabbedSelectorToggle->show(); _botKeyboardHide->hide(); _botKeyboardShow->hide(); - _botCommandStart->setVisible(!_editMsgId && settings.showCommandsButtonInMessageField); + _botCommandStart->setVisible(!_editMsgId && settings.showCommandsButtonInMessageField()); } _field->setMaxHeight(computeMaxFieldHeight()); _kbShown = false; diff --git a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp index 749f7a3adf..23329e5ab5 100644 --- a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp +++ b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp @@ -2190,8 +2190,15 @@ void ComposeControls::init() { updateAttachBotsMenu(); }, _wrap->lifetime()); - AyuSettings::get_historyUpdateReactive() | rpl::on_next([=] - { + rpl::merge( + AyuSettings::getInstance().showAttachButtonInMessageFieldChanges() | rpl::to_empty, + AyuSettings::getInstance().showCommandsButtonInMessageFieldChanges() | rpl::to_empty, + AyuSettings::getInstance().showEmojiButtonInMessageFieldChanges() | rpl::to_empty, + AyuSettings::getInstance().showMicrophoneButtonInMessageFieldChanges() | rpl::to_empty, + AyuSettings::getInstance().showAutoDeleteButtonInMessageFieldChanges() | rpl::to_empty, + AyuSettings::getInstance().showAttachPopupChanges() | rpl::to_empty, + AyuSettings::getInstance().showEmojiPopupChanges() | rpl::to_empty + ) | rpl::on_next([=] { updateSendButtonType(); updateControlsVisibility(); updateControlsGeometry(_wrap->size()); @@ -2208,7 +2215,7 @@ void ComposeControls::orderControls() { bool ComposeControls::showRecordButton() const { const auto &settings = AyuSettings::getInstance(); - if (!settings.showMicrophoneButtonInMessageField) { + if (!settings.showMicrophoneButtonInMessageField()) { return false; } @@ -3365,18 +3372,18 @@ void ComposeControls::updateControlsGeometry(QSize size) { - (commentsShown ? (_commentsShown->width() + _st.commentsSkip) : 0) - - ((_attachToggle && settings.showAttachButtonInMessageField || _sendAs) ? _st.padding.left() : _st.fieldLeft) - - (_attachToggle && settings.showAttachButtonInMessageField ? _attachToggle->width() : 0) + - ((_attachToggle && settings.showAttachButtonInMessageField() || _sendAs) ? _st.padding.left() : _st.fieldLeft) + - (_attachToggle && settings.showAttachButtonInMessageField() ? _attachToggle->width() : 0) - (_sendAs ? _sendAs->width() : 0) - _st.padding.right() - _send->width() - (_editStars ? _editStars->width() : 0) - - (settings.showEmojiButtonInMessageField ? _tabbedSelectorToggle->width() : 0) + - (settings.showEmojiButtonInMessageField() ? _tabbedSelectorToggle->width() : 0) - (_likeShown ? _like->width() : 0) - - (_botCommandShown && settings.showCommandsButtonInMessageField ? _botCommandStart->width() : 0) + - (_botCommandShown && settings.showCommandsButtonInMessageField() ? _botCommandStart->width() : 0) - (_silent ? _silent->width() : 0) - (_scheduled ? _scheduled->width() : 0) - - (_ttlInfo && settings.showAutoDeleteButtonInMessageField ? _ttlInfo->width() : 0) + - (_ttlInfo && settings.showAutoDeleteButtonInMessageField() ? _ttlInfo->width() : 0) - (_starsReaction ? (_st.starsSkip + _starsReaction->width()) : 0); @@ -3401,7 +3408,7 @@ void ComposeControls::updateControlsGeometry(QSize size) { if (_replaceMedia) { _replaceMedia->moveToLeft(left, buttonsTop); } - if (_attachToggle && settings.showAttachButtonInMessageField) { + if (_attachToggle && settings.showAttachButtonInMessageField()) { _attachToggle->moveToLeft(left, buttonsTop); left += _attachToggle->width(); } @@ -3430,7 +3437,7 @@ void ComposeControls::updateControlsGeometry(QSize size) { _editStars->moveToRight(right, buttonsTop); right += _editStars->width(); } - if (settings.showEmojiButtonInMessageField) { + if (settings.showEmojiButtonInMessageField()) { _tabbedSelectorToggle->moveToRight(right, buttonsTop); right += _tabbedSelectorToggle->width(); } @@ -3447,7 +3454,7 @@ void ComposeControls::updateControlsGeometry(QSize size) { } if (_botCommandStart) { _botCommandStart->moveToRight(right, buttonsTop); - if (_botCommandShown && settings.showCommandsButtonInMessageField) { + if (_botCommandShown && settings.showCommandsButtonInMessageField()) { right += _botCommandStart->width(); } } @@ -3459,7 +3466,7 @@ void ComposeControls::updateControlsGeometry(QSize size) { _scheduled->moveToRight(right, buttonsTop); right += _scheduled->width(); } - if (_ttlInfo && settings.showAutoDeleteButtonInMessageField) { + if (_ttlInfo && settings.showAutoDeleteButtonInMessageField()) { _ttlInfo->move(size.width() - right - _ttlInfo->width(), buttonsTop); } @@ -3473,7 +3480,7 @@ void ComposeControls::updateControlsVisibility() { const auto &settings = AyuSettings::getInstance(); if (_botCommandStart) { - SWITCH_BUTTON(_botCommandStart, _botCommandShown && settings.showCommandsButtonInMessageField); + SWITCH_BUTTON(_botCommandStart, _botCommandShown && settings.showCommandsButtonInMessageField()); } if (_like) { _like->setVisible(_likeShown); @@ -3482,7 +3489,7 @@ void ComposeControls::updateControlsVisibility() { _editStars->show(); } if (_ttlInfo) { - SWITCH_BUTTON(_ttlInfo, settings.showAutoDeleteButtonInMessageField); + SWITCH_BUTTON(_ttlInfo, settings.showAutoDeleteButtonInMessageField()); } if (_sendAs) { _sendAs->show(); @@ -3491,7 +3498,7 @@ void ComposeControls::updateControlsVisibility() { _replaceMedia->show(); } if (_attachToggle) { - SWITCH_BUTTON(_attachToggle, settings.showAttachButtonInMessageField && !_replaceMedia); + SWITCH_BUTTON(_attachToggle, settings.showAttachButtonInMessageField() && !_replaceMedia); } if (_scheduled) { _scheduled->setVisible(!isEditingMessage()); @@ -3502,7 +3509,7 @@ void ComposeControls::updateControlsVisibility() { if (_starsReaction) { _starsReaction->show(); } - SWITCH_BUTTON(_tabbedSelectorToggle, settings.showEmojiButtonInMessageField); + SWITCH_BUTTON(_tabbedSelectorToggle, settings.showEmojiButtonInMessageField()); } bool ComposeControls::updateLikeShown() { diff --git a/Telegram/SourceFiles/history/view/controls/history_view_voice_record_bar.cpp b/Telegram/SourceFiles/history/view/controls/history_view_voice_record_bar.cpp index a20e6eadfb..a78772ad8f 100644 --- a/Telegram/SourceFiles/history/view/controls/history_view_voice_record_bar.cpp +++ b/Telegram/SourceFiles/history/view/controls/history_view_voice_record_bar.cpp @@ -2188,8 +2188,8 @@ void VoiceRecordBar::stopRecording(StopType type, bool ttlBeforeHide) { : 0), }; - const auto &settings = AyuSettings::getInstance(); - if (AyuSettings::isUseScheduledMessages()) { + auto &ghost = AyuSettings::ghost(&_show->session()); + if (ghost.isUseScheduledMessages()) { auto current = base::unixtime::now(); options.scheduled = current + 12 + 5; } @@ -2206,7 +2206,8 @@ void VoiceRecordBar::stopRecording(StopType type, bool ttlBeforeHide) { close(); }); - if (settings.voiceConfirmation) { + const auto &settings = AyuSettings::getInstance(); + if (settings.voiceConfirmation()) { _show->showBox(Ui::MakeConfirmBox( { .text = tr::ayu_ConfirmationVoice(), @@ -2281,7 +2282,8 @@ void VoiceRecordBar::requestToSendWithOptions(Api::SendOptions options) { } const auto &settings = AyuSettings::getInstance(); - if (AyuSettings::isUseScheduledMessages()) { + const auto &ghost = AyuSettings::ghost(); + if (ghost.isUseScheduledMessages()) { auto current = base::unixtime::now(); options.scheduled = current + 12 + 5; } @@ -2299,7 +2301,7 @@ void VoiceRecordBar::requestToSendWithOptions(Api::SendOptions options) { close(); }); - if (settings.voiceConfirmation) { + if (settings.voiceConfirmation()) { _show->showBox(Ui::MakeConfirmBox( { .text = tr::ayu_ConfirmationVoice(), diff --git a/Telegram/SourceFiles/history/view/history_view_bottom_info.cpp b/Telegram/SourceFiles/history/view/history_view_bottom_info.cpp index 22313f3749..94c8a01467 100644 --- a/Telegram/SourceFiles/history/view/history_view_bottom_info.cpp +++ b/Telegram/SourceFiles/history/view/history_view_bottom_info.cpp @@ -456,12 +456,12 @@ void BottomInfo::layout() { void BottomInfo::layoutDateText() { const auto &settings = AyuSettings::getInstance(); - if (!settings.replaceBottomInfoWithIcons) { + if (!settings.replaceBottomInfoWithIcons()) { const auto deleted = (_data.flags & Data::Flag::AyuDeleted) - ? (settings.deletedMark + ' ') + ? (settings.deletedMark() + ' ') : QString(); const auto edited = (_data.flags & Data::Flag::Edited) - ? (settings.editedMark + ' ') + ? (settings.editedMark() + ' ') : (_data.flags & Data::Flag::EstimateDate) ? (tr::lng_approximate(tr::now) + ' ') : _data.scheduleRepeatPeriod diff --git a/Telegram/SourceFiles/history/view/history_view_chat_section.cpp b/Telegram/SourceFiles/history/view/history_view_chat_section.cpp index cb7e4b8d54..cf9c137ab7 100644 --- a/Telegram/SourceFiles/history/view/history_view_chat_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_chat_section.cpp @@ -1431,14 +1431,14 @@ void ChatWidget::sendVoice(const ComposeControls::VoiceToSend &data) { } void ChatWidget::send(Api::SendOptions options) { - const auto &settings = AyuSettings::getInstance(); - if (AyuSettings::isUseScheduledMessages() && !options.scheduled) { + const auto &ghost = AyuSettings::ghost(&controller()->session()); + if (ghost.isUseScheduledMessages() && !options.scheduled) { auto current = base::unixtime::now(); options.scheduled = current + 12; } auto lastMessage = _history->lastMessage(); - if (!settings.sendReadMessages && settings.markReadAfterAction && lastMessage) { + if (!ghost.sendReadMessages() && ghost.markReadAfterAction() && lastMessage) { readHistory(lastMessage); } diff --git a/Telegram/SourceFiles/history/view/history_view_context_menu.cpp b/Telegram/SourceFiles/history/view/history_view_context_menu.cpp index 485df86b7e..f3e17d6f26 100644 --- a/Telegram/SourceFiles/history/view/history_view_context_menu.cpp +++ b/Telegram/SourceFiles/history/view/history_view_context_menu.cpp @@ -1634,7 +1634,7 @@ void AddWhoReactedAction( not_null item, not_null controller) { const auto &settings = AyuSettings::getInstance(); - if (!AyuUi::needToShowItem(settings.showViewsPanelInContextMenu)) { + if (!AyuUi::needToShowItem(settings.showViewsPanelInContextMenu())) { return; } diff --git a/Telegram/SourceFiles/history/view/history_view_message.cpp b/Telegram/SourceFiles/history/view/history_view_message.cpp index 4cb98e5872..13fb9df7c4 100644 --- a/Telegram/SourceFiles/history/view/history_view_message.cpp +++ b/Telegram/SourceFiles/history/view/history_view_message.cpp @@ -3852,7 +3852,7 @@ std::optional Message::rightActionSize() const { bool Message::displayFastShare() const { const auto &settings = AyuSettings::getInstance(); - if (settings.hideFastShare) { + if (settings.hideFastShare()) { return false; } diff --git a/Telegram/SourceFiles/history/view/history_view_reply.cpp b/Telegram/SourceFiles/history/view/history_view_reply.cpp index bffd8f9c57..2ac4e7c5d3 100644 --- a/Telegram/SourceFiles/history/view/history_view_reply.cpp +++ b/Telegram/SourceFiles/history/view/history_view_reply.cpp @@ -805,7 +805,7 @@ void Reply::paint( Ui::Text::ValidateQuotePaintCache(*cache, quoteSt); Ui::Text::FillQuotePaint(p, rect, *cache, quoteSt); const auto &settings = AyuSettings::getInstance(); - if (!settings.simpleQuotesAndReplies && backgroundEmojiData) { + if (!settings.simpleQuotesAndReplies() && backgroundEmojiData) { ValidateBackgroundEmoji( backgroundEmojiId, colorCollectible, diff --git a/Telegram/SourceFiles/history/view/history_view_send_action.cpp b/Telegram/SourceFiles/history/view/history_view_send_action.cpp index 622dfe2870..75d53f6172 100644 --- a/Telegram/SourceFiles/history/view/history_view_send_action.cpp +++ b/Telegram/SourceFiles/history/view/history_view_send_action.cpp @@ -22,7 +22,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL // AyuGram includes #include "ayu/ayu_settings.h" -#include "ayu/features/filters/shadow_ban_utils.h" namespace HistoryView { namespace { @@ -68,12 +67,12 @@ bool SendActionPainter::updateNeedsAnimating( } const auto &settings = AyuSettings::getInstance(); - if (settings.hideFromBlocked) { + if (settings.hideFromBlocked()) { if (user->isBlocked()) { return false; } } - if (ShadowBanUtils::isShadowBanned(user->id.value & PeerId::kChatTypeMask)) { + if (AyuSettings::getInstance().isShadowBanned(user->id.value & PeerId::kChatTypeMask)) { return false; } diff --git a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp index 1c963a981b..6d33e9479f 100644 --- a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp @@ -818,7 +818,7 @@ void TopBarWidget::infoClicked() { void TopBarWidget::backClicked() { if (_activeChat.key.folder()) { const auto &settings = AyuSettings::getInstance(); - if (settings.hideAllChatsFolder) { + if (settings.hideAllChatsFolder()) { const auto filters = &_controller->session().data().chatsFilters(); const auto lookupId = filters->lookupId(_controller->session().premium() ? 0 : 1); _controller->setActiveChatsFilter(lookupId); @@ -1199,7 +1199,7 @@ void TopBarWidget::updateControlsVisibility() { _clear->show(); _delete->setVisible(_canDelete); - _messageShot->setVisible(settings.showMessageShot); + _messageShot->setVisible(settings.showMessageShot()); _forward->setVisible(_canForward); _sendNow->setVisible(_canSendNow); @@ -1291,7 +1291,7 @@ void TopBarWidget::updateControlsVisibility() { const auto showRecentActions = [&] { const auto &settings = AyuSettings::getInstance(); - if (!settings.quickAdminShortcuts) { + if (!settings.quickAdminShortcuts()) { return false; } if (_activeChat.section == Section::ChatsList) { @@ -1309,7 +1309,7 @@ void TopBarWidget::updateControlsVisibility() { const auto showAdmins = [&] { const auto &settings = AyuSettings::getInstance(); - if (!settings.quickAdminShortcuts) { + if (!settings.quickAdminShortcuts()) { return false; } if (_activeChat.section == Section::ChatsList) { @@ -1399,7 +1399,7 @@ bool TopBarWidget::showSelectedState() const { const auto &settings = AyuSettings::getInstance(); return (_selectedCount > 0) - && (_canDelete || _canForward || _canSendNow || settings.showMessageShot); + && (_canDelete || _canForward || _canSendNow || settings.showMessageShot()); } void TopBarWidget::showSelected(SelectedState state) { @@ -1408,7 +1408,7 @@ void TopBarWidget::showSelected(SelectedState state) { auto canDelete = (state.count > 0 && state.count == state.canDeleteCount); auto canForward = (state.count > 0 && state.count == state.canForwardCount); auto canSendNow = (state.count > 0 && state.count == state.canSendNowCount); - auto count = (!canDelete && !canForward && !canSendNow && !settings.showMessageShot) ? 0 : state.count; + auto count = (!canDelete && !canForward && !canSendNow && !settings.showMessageShot()) ? 0 : state.count; if (_selectedCount == count && _canDelete == canDelete && _canForward == canForward diff --git a/Telegram/SourceFiles/history/view/history_view_translate_bar.cpp b/Telegram/SourceFiles/history/view/history_view_translate_bar.cpp index aaa33e63a3..3ebe9dacb2 100644 --- a/Telegram/SourceFiles/history/view/history_view_translate_bar.cpp +++ b/Telegram/SourceFiles/history/view/history_view_translate_bar.cpp @@ -491,7 +491,7 @@ void TranslateBar::showMenu(base::unique_qptr menu) { &st::menuIconCancel); const auto &settings = AyuSettings::getInstance(); - if (settings.translationProvider == "telegram") { + if (settings.translationProvider() == "telegram") { _menu->addSeparator(); const auto cocoon = ChatHelpers::GenerateLocalTgsSticker( &_history->session(), diff --git a/Telegram/SourceFiles/history/view/media/history_view_document.cpp b/Telegram/SourceFiles/history/view/media/history_view_document.cpp index 2193e2810c..bcf954f21e 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_document.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_document.cpp @@ -327,7 +327,7 @@ Document::Document( _parent->data()->removeFromSharedMediaIndex(); setDocumentLinks(_data, realParent, [=] { const auto &settings = AyuSettings::getInstance(); - if (!settings.saveDeletedMessages) { + if (!settings.saveDeletedMessages()) { _openl = nullptr; } diff --git a/Telegram/SourceFiles/history/view/media/history_view_web_page.cpp b/Telegram/SourceFiles/history/view/media/history_view_web_page.cpp index d73dc65149..bcc6359687 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_web_page.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_web_page.cpp @@ -978,7 +978,7 @@ void WebPage::draw(Painter &p, const PaintContext &context) const { Ui::Text::ValidateQuotePaintCache(*cache, _st); Ui::Text::FillQuotePaint(p, outer, *cache, _st); const auto &settings = AyuSettings::getInstance(); - if (!settings.simpleQuotesAndReplies && backgroundEmojiData) { + if (!settings.simpleQuotesAndReplies() && backgroundEmojiData) { ValidateBackgroundEmoji( backgroundEmojiId, colorCollectible, diff --git a/Telegram/SourceFiles/history/view/reactions/history_view_reactions.cpp b/Telegram/SourceFiles/history/view/reactions/history_view_reactions.cpp index 92b86f9bdc..72e4a1cb68 100644 --- a/Telegram/SourceFiles/history/view/reactions/history_view_reactions.cpp +++ b/Telegram/SourceFiles/history/view/reactions/history_view_reactions.cpp @@ -845,12 +845,12 @@ InlineListData InlineListDataFromMessage(not_null view) { using Flag = InlineListData::Flag; const auto item = view->data(); const auto &settings = AyuSettings::getInstance(); - if (!settings.showChannelReactions + if (!settings.showChannelReactions() && item->history()->peer->isChannel() && !item->history()->peer->isMegagroup()) { return InlineListData(); } - if (!settings.showGroupReactions + if (!settings.showGroupReactions() && item->history()->peer->isMegagroup()) { return InlineListData(); } diff --git a/Telegram/SourceFiles/history/view/reactions/history_view_reactions_selector.cpp b/Telegram/SourceFiles/history/view/reactions/history_view_reactions_selector.cpp index 3b97f627be..e86bf8b1ad 100644 --- a/Telegram/SourceFiles/history/view/reactions/history_view_reactions_selector.cpp +++ b/Telegram/SourceFiles/history/view/reactions/history_view_reactions_selector.cpp @@ -1388,13 +1388,13 @@ AttachSelectorResult AttachSelectorToMenu( TextWithEntities about, IconFactory iconFactory) { const auto &settings = AyuSettings::getInstance(); - if (!AyuUi::needToShowItem(settings.showReactionsPanelInContextMenu)) { + if (!AyuUi::needToShowItem(settings.showReactionsPanelInContextMenu())) { return AttachSelectorResult::Skipped; } const auto peer = item->history()->peer; - if ((peer->isChannel() && !peer->isMegagroup() && !settings.showChannelReactions) - || (peer->isMegagroup() && !settings.showGroupReactions)) { + if ((peer->isChannel() && !peer->isMegagroup() && !settings.showChannelReactions()) + || (peer->isMegagroup() && !settings.showGroupReactions())) { return AttachSelectorResult::Skipped; } @@ -1446,7 +1446,7 @@ auto AttachSelectorToMenu( Fn paused) -> base::expected, AttachSelectorResult> { const auto &settings = AyuSettings::getInstance(); - if (!AyuUi::needToShowItem(settings.showReactionsPanelInContextMenu)) { + if (!AyuUi::needToShowItem(settings.showReactionsPanelInContextMenu())) { return base::make_unexpected(AttachSelectorResult::Skipped); } diff --git a/Telegram/SourceFiles/info/info_top_bar.cpp b/Telegram/SourceFiles/info/info_top_bar.cpp index 49e51af56e..3ab5278cb0 100644 --- a/Telegram/SourceFiles/info/info_top_bar.cpp +++ b/Telegram/SourceFiles/info/info_top_bar.cpp @@ -506,7 +506,7 @@ void TopBar::updateControlsVisibility(anim::type animated) { void TopBar::setStories(rpl::producer content) { // AyuGram disableStories const auto &settings = AyuSettings::getInstance(); - if (settings.disableStories) { + if (settings.disableStories()) { return; } diff --git a/Telegram/SourceFiles/info/info_wrap_widget.cpp b/Telegram/SourceFiles/info/info_wrap_widget.cpp index ef80b6dbbe..1e7cb8ee42 100644 --- a/Telegram/SourceFiles/info/info_wrap_widget.cpp +++ b/Telegram/SourceFiles/info/info_wrap_widget.cpp @@ -56,7 +56,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL // AyuGram includes #include "ayu/ayu_settings.h" -#include "ayu/features/filters/shadow_ban_utils.h" +#include "ayu/features/filters/filters_cache_controller.h" #include "ayu/ui/settings/filters/edit_filter.h" #include "ayu/ui/settings/filters/settings_filters_list.h" #include "ayu/utils/telegram_helpers.h" @@ -454,7 +454,7 @@ void WrapWidget::setupTopBarMenuToggle() { const auto peer = thread->peer(); const auto realId = getDialogIdFromPeer(peer); - ShadowBanUtils::addShadowBan(realId); + AyuSettings::getInstance().addShadowBan(realId); return true; }, tr::ayu_FiltersMenuSelectChat(), @@ -750,7 +750,7 @@ void WrapWidget::finishShowContent() { updateContentGeometry(); }, _content->lifetime()); - AyuSettings::get_filtersUpdate() | rpl::on_next([=] + FiltersCacheController::updates() | rpl::on_next([=] { auto contentMemento = _content->createMemento(); if (!contentMemento) { diff --git a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp index edab065f92..a3b7ddb5c7 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp @@ -1789,7 +1789,7 @@ object_ptr DetailsFiller::setupInfo() { ).text->setLinksTrusted(); } - if (settings.showPeerId != 0) { + if (settings.showPeerId() != PeerIdDisplay::Hidden) { const auto dataCenter = getPeerDC(_peer); const auto idLabel = dataCenter.isEmpty() ? QString("ID") : dataCenter; @@ -1922,7 +1922,7 @@ object_ptr DetailsFiller::setupInfo() { addTranslateToMenu(about.text, AboutWithAdvancedValue(_peer)); } - if (settings.showPeerId != 0 && !_topic) { + if (settings.showPeerId() != PeerIdDisplay::Hidden && !_topic) { const auto dataCenter = getPeerDC(_peer); const auto idLabel = dataCenter.isEmpty() ? QString("ID") : dataCenter; @@ -1950,7 +1950,7 @@ object_ptr DetailsFiller::setupInfo() { AddRegistrationOrCreationButton(controller, _peer, idInfo, fitLabelToButton); } - if (settings.showPeerId != 0 && _topic) { + if (settings.showPeerId() != PeerIdDisplay::Hidden && _topic) { auto idDrawableText = IDValue( _peer->forumTopicFor(topicRootId)->topicRootId() ) | rpl::map([](TextWithEntities &&text) diff --git a/Telegram/SourceFiles/info/profile/info_profile_inner_widget.cpp b/Telegram/SourceFiles/info/profile/info_profile_inner_widget.cpp index 1f0c98c949..0e36f47865 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_inner_widget.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_inner_widget.cpp @@ -296,7 +296,7 @@ object_ptr InnerWidget::setupSharedMedia( const auto addSimilarPeersButton = [&]( not_null peer, const style::icon &icon) { - if (settings.hideSimilarChannels) { + if (settings.hideSimilarChannels()) { return; } diff --git a/Telegram/SourceFiles/info/saved/info_saved_music_common.cpp b/Telegram/SourceFiles/info/saved/info_saved_music_common.cpp index 9b78b4d14b..341f221fe6 100644 --- a/Telegram/SourceFiles/info/saved/info_saved_music_common.cpp +++ b/Telegram/SourceFiles/info/saved/info_saved_music_common.cpp @@ -110,13 +110,12 @@ void SetupSavedMusic( contextMenu->setAttribute(Qt::WA_DeleteOnClose); contextMenu->addAction( - settings.adaptiveCoverColor + settings.adaptiveCoverColor() ? tr::ayu_DisableColorfulCover(tr::now) : tr::ayu_EnableColorfulCover(tr::now), [=] { - AyuSettings::set_adaptiveCoverColor(!settings.adaptiveCoverColor); - AyuSettings::save(); + AyuSettings::getInstance().setAdaptiveCoverColor(!AyuSettings::getInstance().adaptiveCoverColor()); const auto mediaRefreshed = item ? item->media() : nullptr; const auto documentRefreshed = mediaRefreshed diff --git a/Telegram/SourceFiles/inline_bots/bot_attach_web_view.cpp b/Telegram/SourceFiles/inline_bots/bot_attach_web_view.cpp index a1fb2ef227..1e192c1477 100644 --- a/Telegram/SourceFiles/inline_bots/bot_attach_web_view.cpp +++ b/Telegram/SourceFiles/inline_bots/bot_attach_web_view.cpp @@ -773,7 +773,7 @@ void BotAction::handleKeyPress(not_null e) { QString WebviewPlatform() { const auto &settings = AyuSettings::getInstance(); - return settings.spoofWebviewAsAndroid ? "android" : "tdesktop"; + return settings.spoofWebviewAsAndroid() ? "android" : "tdesktop"; } } // namespace diff --git a/Telegram/SourceFiles/main/main_session.cpp b/Telegram/SourceFiles/main/main_session.cpp index eaeb329bab..dab2511cb7 100644 --- a/Telegram/SourceFiles/main/main_session.cpp +++ b/Telegram/SourceFiles/main/main_session.cpp @@ -361,7 +361,7 @@ rpl::producer<> Session::downloaderTaskFinished() const { bool Session::premium() const { const auto &settings = AyuSettings::getInstance(); - if (settings.localPremium) { + if (settings.localPremium()) { return true; } @@ -370,7 +370,7 @@ bool Session::premium() const { bool Session::premiumPossible() const { const auto &settings = AyuSettings::getInstance(); - if (settings.localPremium) { + if (settings.localPremium()) { return true; } @@ -393,7 +393,7 @@ rpl::producer Session::premiumPossibleValue() const { }); const auto &settings = AyuSettings::getInstance(); - if (settings.localPremium) { + if (settings.localPremium()) { premium = rpl::single(true); } diff --git a/Telegram/SourceFiles/media/stories/media_stories_repost_view.cpp b/Telegram/SourceFiles/media/stories/media_stories_repost_view.cpp index d442ed29dc..cd3990869c 100644 --- a/Telegram/SourceFiles/media/stories/media_stories_repost_view.cpp +++ b/Telegram/SourceFiles/media/stories/media_stories_repost_view.cpp @@ -101,7 +101,7 @@ void RepostView::draw(Painter &p, int x, int y, int availableWidth) { Ui::Text::FillQuotePaint(p, rect, *cache, quoteSt); const auto &settings = AyuSettings::getInstance(); - if (!settings.simpleQuotesAndReplies && backgroundEmoji) { + if (!settings.simpleQuotesAndReplies() && backgroundEmoji) { using namespace HistoryView; if (backgroundEmoji->firstFrameMask.isNull() && !backgroundEmoji->emoji) { diff --git a/Telegram/SourceFiles/menu/menu_send.cpp b/Telegram/SourceFiles/menu/menu_send.cpp index b572d932af..4aee09d8d7 100644 --- a/Telegram/SourceFiles/menu/menu_send.cpp +++ b/Telegram/SourceFiles/menu/menu_send.cpp @@ -743,11 +743,14 @@ FillMenuResult FillSendMenu( : st::defaultComposeIcons; if (sending && type != Type::Reminder) { - const auto &settings = AyuSettings::getInstance(); + const auto &ghost = maybeShow + ? AyuSettings::ghost(&maybeShow->session()) + : AyuSettings::ghost(); + const auto sendWithoutSound = ghost.sendWithoutSound(); menu->addAction( - settings.sendWithoutSound ? tr::ayu_SendWithSound(tr::now) : tr::lng_send_silent_message(tr::now), + sendWithoutSound ? tr::ayu_SendWithSound(tr::now) : tr::lng_send_silent_message(tr::now), [=] { action({ Api::SendOptions{ .silent = true } }, details); }, - settings.sendWithoutSound ? &icons.menuUnmute : &icons.menuMute); + sendWithoutSound ? &icons.menuUnmute : &icons.menuMute); } if (sending && type != Type::SilentOnly) { menu->addAction( diff --git a/Telegram/SourceFiles/platform/mac/specific_mac_p.mm b/Telegram/SourceFiles/platform/mac/specific_mac_p.mm index fbf6121bb4..fdd0c1530a 100644 --- a/Telegram/SourceFiles/platform/mac/specific_mac_p.mm +++ b/Telegram/SourceFiles/platform/mac/specific_mac_p.mm @@ -306,11 +306,11 @@ namespace Platform { void SetApplicationIcon(const QIcon &icon) { const auto &settings = AyuSettings::getInstance(); - if (settings.appIcon.isEmpty()) { + if (settings.appIcon().isEmpty()) { return; } - const auto name = QString("AppIcon-") + settings.appIcon[0].toUpper() + settings.appIcon.mid(1); + const auto name = QString("AppIcon-") + settings.appIcon()[0].toUpper() + settings.appIcon().mid(1); @autoreleasepool { if (name == QString("AppIcon-Default")) { NSApplication.sharedApplication.applicationIconImage = nil; diff --git a/Telegram/SourceFiles/platform/win/main_window_win.cpp b/Telegram/SourceFiles/platform/win/main_window_win.cpp index 28e5e7e291..72a062e923 100644 --- a/Telegram/SourceFiles/platform/win/main_window_win.cpp +++ b/Telegram/SourceFiles/platform/win/main_window_win.cpp @@ -604,8 +604,8 @@ void MainWindow::unreadCounterChangedHook() { void MainWindow::updateTaskbarAndIconCounters() { const auto &settings = AyuSettings::getInstance(); - const auto counter = settings.hideNotificationBadge ? 0 : Core::App().unreadBadge(); - const auto muted = settings.hideNotificationBadge ? 0 : Core::App().unreadBadgeMuted(); + const auto counter = settings.hideNotificationBadge() ? 0 : Core::App().unreadBadge(); + const auto muted = settings.hideNotificationBadge() ? 0 : Core::App().unreadBadgeMuted(); const auto controller = sessionController(); const auto session = controller ? &controller->session() : nullptr; diff --git a/Telegram/SourceFiles/platform/win/tray_win.cpp b/Telegram/SourceFiles/platform/win/tray_win.cpp index ae7c3bf667..dd1a7286ab 100644 --- a/Telegram/SourceFiles/platform/win/tray_win.cpp +++ b/Telegram/SourceFiles/platform/win/tray_win.cpp @@ -142,7 +142,7 @@ bool DarkTasbarValueValid/* = false*/; } const auto &settings = AyuSettings::getInstance(); - if (settings.hideNotificationBadge) { + if (settings.hideNotificationBadge()) { args.count = 0; } diff --git a/Telegram/SourceFiles/settings/settings_premium.cpp b/Telegram/SourceFiles/settings/settings_premium.cpp index 01acbcfb46..ae4454477f 100644 --- a/Telegram/SourceFiles/settings/settings_premium.cpp +++ b/Telegram/SourceFiles/settings/settings_premium.cpp @@ -1206,7 +1206,7 @@ base::weak_qptr Premium::createPinnedToTop( } const auto &settings = AyuSettings::getInstance(); - if (settings.localPremium) { + if (settings.localPremium()) { return tr::ayu_LocalPremiumNotice(tr::rich); } diff --git a/Telegram/SourceFiles/tray.cpp b/Telegram/SourceFiles/tray.cpp index 312877f11e..d45ade89d8 100644 --- a/Telegram/SourceFiles/tray.cpp +++ b/Telegram/SourceFiles/tray.cpp @@ -18,6 +18,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL // AyuGram includes #include "ayu/ayu_settings.h" #include "ayu/features/streamer_mode/streamer_mode.h" +#include "window/window_controller.h" #include "lang_auto.h" @@ -103,30 +104,31 @@ void Tray::rebuildMenu() { const auto &settings = AyuSettings::getInstance(); - if (settings.showGhostToggleInTray) { - auto turnGhostModeText = _textUpdates.events( - ) | rpl::map( - [=] - { - bool ghostModeEnabled = AyuSettings::isGhostModeActive(); + if (settings.showGhostToggleInTray()) { + auto ghostActiveChanges = AyuSettings::getInstance().useGlobalGhostModeChanges() + | rpl::map([](bool) { + return AyuSettings::ghost().ghostModeActiveChanges(); + }) + | rpl::flatten_latest(); - return ghostModeEnabled - ? tr::ayu_DisableGhostModeTray(tr::now) - : tr::ayu_EnableGhostModeTray(tr::now); - }); + auto turnGhostModeText = rpl::combine( + _textUpdates.events_starting_with({}), + std::move(ghostActiveChanges) + ) | rpl::map([=](auto, bool active) { + return active + ? tr::ayu_DisableGhostModeTray(tr::now) + : tr::ayu_EnableGhostModeTray(tr::now); + }); _tray.addAction( std::move(turnGhostModeText), [=] { - bool ghostMode = AyuSettings::isGhostModeActive(); - - AyuSettings::set_ghostModeEnabled(!ghostMode); - - AyuSettings::save(); + auto &ghost = AyuSettings::ghost(); + ghost.setGhostModeEnabled(!ghost.isGhostModeActive()); }); } - if (settings.showStreamerToggleInTray) { + if (settings.showStreamerToggleInTray()) { auto turnStreamerModeText = _textUpdates.events( ) | rpl::map( [=] diff --git a/Telegram/SourceFiles/ui/chat/attach/attach_bot_webview.cpp b/Telegram/SourceFiles/ui/chat/attach/attach_bot_webview.cpp index c2a6bffc8f..ccabc116d4 100644 --- a/Telegram/SourceFiles/ui/chat/attach/attach_bot_webview.cpp +++ b/Telegram/SourceFiles/ui/chat/attach/attach_bot_webview.cpp @@ -388,10 +388,10 @@ Panel::Panel(Args &&args) const auto &settings = AyuSettings::getInstance(); auto size = QSize(st::botWebViewPanelSize); - if (settings.increaseWebviewHeight) { + if (settings.increaseWebviewHeight()) { size.setHeight(st::botWebViewPanelHeightIncreased); } - if (settings.increaseWebviewWidth) { + if (settings.increaseWebviewWidth()) { size.setWidth(st::botWebViewPanelWidthIncreased); } diff --git a/Telegram/SourceFiles/ui/chat/chat_style.cpp b/Telegram/SourceFiles/ui/chat/chat_style.cpp index 8f0473c9a9..fb9a188800 100644 --- a/Telegram/SourceFiles/ui/chat/chat_style.cpp +++ b/Telegram/SourceFiles/ui/chat/chat_style.cpp @@ -49,7 +49,7 @@ void EnsureBlockquoteCache( cache->icon = colors.name; const auto &settings = AyuSettings::getInstance(); - if (settings.simpleQuotesAndReplies) { + if (settings.simpleQuotesAndReplies()) { cache->bg = QColor(0, 0, 0, 0); } } diff --git a/Telegram/SourceFiles/ui/chat/message_bubble.cpp b/Telegram/SourceFiles/ui/chat/message_bubble.cpp index 4da923429d..b8ccf0fce5 100644 --- a/Telegram/SourceFiles/ui/chat/message_bubble.cpp +++ b/Telegram/SourceFiles/ui/chat/message_bubble.cpp @@ -47,7 +47,7 @@ void PaintBubbleGeneric( } const auto &settings = AyuSettings::getInstance(); - if (settings.removeMessageTail) { + if (settings.removeMessageTail()) { if (bottomWithTailLeft == Corner::Tail) { bottomWithTailLeft = Corner::Large; } diff --git a/Telegram/SourceFiles/ui/widgets/chat_filters_tabs_strip.cpp b/Telegram/SourceFiles/ui/widgets/chat_filters_tabs_strip.cpp index f0945dc907..8df8f22e13 100644 --- a/Telegram/SourceFiles/ui/widgets/chat_filters_tabs_strip.cpp +++ b/Telegram/SourceFiles/ui/widgets/chat_filters_tabs_strip.cpp @@ -250,7 +250,7 @@ not_null AddChatFiltersTabsStrip( const auto isMuted = includeMuted && (count == muted); const auto &settings = AyuSettings::getInstance(); - if (settings.hideNotificationCounters) { + if (settings.hideNotificationCounters()) { count = 0; } diff --git a/Telegram/SourceFiles/window/notifications_manager.cpp b/Telegram/SourceFiles/window/notifications_manager.cpp index 57086a0f51..6387942132 100644 --- a/Telegram/SourceFiles/window/notifications_manager.cpp +++ b/Telegram/SourceFiles/window/notifications_manager.cpp @@ -385,7 +385,7 @@ System::Timing System::countTiming( } const auto &settings = AyuSettings::getInstance(); - if (settings.disableNotificationsDelay) { + if (settings.disableNotificationsDelay()) { delay = minimalDelay; } diff --git a/Telegram/SourceFiles/window/section_widget.cpp b/Telegram/SourceFiles/window/section_widget.cpp index 08b611bf6a..3e4dd43aa0 100644 --- a/Telegram/SourceFiles/window/section_widget.cpp +++ b/Telegram/SourceFiles/window/section_widget.cpp @@ -545,7 +545,7 @@ auto ChatThemeValueFromPeer( -> rpl::producer> { const auto &settings = AyuSettings::getInstance(); // this check ensures that background is not a pattern wallpaper in a private chat - if (settings.disableCustomBackgrounds && resolved.paper && resolved.paper->media) { + if (settings.disableCustomBackgrounds() && resolved.paper && resolved.paper->media) { resolved.paper = std::nullopt; } diff --git a/Telegram/SourceFiles/window/window_filters_menu.cpp b/Telegram/SourceFiles/window/window_filters_menu.cpp index 3c75a3c319..61dd2d115d 100644 --- a/Telegram/SourceFiles/window/window_filters_menu.cpp +++ b/Telegram/SourceFiles/window/window_filters_menu.cpp @@ -142,7 +142,7 @@ void FiltersMenu::setupMainMenuIcon() { : &st::windowFiltersMainMenuUnreadMuted; const auto &settings = AyuSettings::getInstance(); - if (settings.hideNotificationCounters) { + if (settings.hideNotificationCounters()) { icon = nullptr; } @@ -195,7 +195,7 @@ void FiltersMenu::refresh() { const auto maxLimit = (reorderAll ? 1 : 0) + Data::PremiumLimits(&_session->session()).dialogFiltersCurrent(); const auto premiumFrom = (reorderAll ? 0 : 1) + maxLimit; - if (!reorderAll && !settings.hideAllChatsFolder) { + if (!reorderAll && !settings.hideAllChatsFolder()) { _reorder->addPinnedInterval(0, 1); } _reorder->addPinnedInterval( @@ -230,7 +230,7 @@ void FiltersMenu::refresh() { // Also check for session content existance, because it may be null // and there will be an exception in `Window::SessionController::showPeerHistory` // because `SessionController::content()` == nullptr - if (settings.hideAllChatsFolder && _session->widget()->sessionContent()) { + if (settings.hideAllChatsFolder() && _session->widget()->sessionContent()) { const auto lookupId = filters->lookupId(0); _session->setActiveChatsFilter(lookupId); } @@ -315,7 +315,7 @@ base::unique_qptr FiltersMenu::prepareButton( - (includeMuted ? 0 : muted); const auto &settings = AyuSettings::getInstance(); - if (settings.hideNotificationCounters) { + if (settings.hideNotificationCounters()) { count = 0; muted = 0; } @@ -473,7 +473,7 @@ void FiltersMenu::applyReorder( const auto filters = &_session->session().data().chatsFilters(); const auto &list = filters->list(); - if (!settings.hideAllChatsFolder && !premium()) { + if (!settings.hideAllChatsFolder() && !premium()) { if (list[0].id() != FilterId()) { filters->moveAllToFront(); } diff --git a/Telegram/SourceFiles/window/window_main_menu.cpp b/Telegram/SourceFiles/window/window_main_menu.cpp index 5596c6ece4..7c30d2dd73 100644 --- a/Telegram/SourceFiles/window/window_main_menu.cpp +++ b/Telegram/SourceFiles/window/window_main_menu.cpp @@ -651,7 +651,7 @@ void MainMenu::setupMenu() { std::move(descriptor)); }; if (!_controller->session().supportMode()) { - if (settings.showMyProfileInDrawer) + if (settings.showMyProfileInDrawer()) _menu->add( CreateButtonWithIcon( _menu, @@ -663,15 +663,15 @@ void MainMenu::setupMenu() { Info::Stories::Make(controller->session().user())); }); - if (settings.showBotsInDrawer) + if (settings.showBotsInDrawer()) SetupMenuBots(_menu, controller); - if (settings.showMyProfileInDrawer || settings.showBotsInDrawer) + if (settings.showMyProfileInDrawer() || settings.showBotsInDrawer()) _menu->add( object_ptr(_menu), { 0, st::mainMenuSkip, 0, st::mainMenuSkip }); - if (settings.showNewGroupInDrawer) + if (settings.showNewGroupInDrawer()) AddMyChannelsBox(addAction( tr::lng_create_group_title(), { &st::menuIconGroups } @@ -681,7 +681,7 @@ void MainMenu::setupMenu() { } }); - if (settings.showNewChannelInDrawer) + if (settings.showNewChannelInDrawer()) AddMyChannelsBox(addAction( tr::lng_create_channel_title(), { &st::menuIconChannel } @@ -691,21 +691,21 @@ void MainMenu::setupMenu() { } }); - if (settings.showContactsInDrawer) + if (settings.showContactsInDrawer()) addAction( tr::lng_menu_contacts(), { &st::menuIconUserShow } )->setClickedCallback([=] { controller->show(PrepareContactsBox(controller)); }); - if (settings.showCallsInDrawer) + if (settings.showCallsInDrawer()) addAction( tr::lng_menu_calls(), { &st::menuIconPhone } )->setClickedCallback([=] { ::Calls::ShowCallsBox(controller); }); - if (settings.showSavedMessagesInDrawer) + if (settings.showSavedMessagesInDrawer()) addAction( tr::lng_saved_messages(), { &st::menuIconSavedMessages } @@ -713,34 +713,37 @@ void MainMenu::setupMenu() { controller->showPeerHistory(controller->session().user()); }); - if (settings.showLReadToggleInDrawer) { + if (settings.showLReadToggleInDrawer()) { addAction( tr::ayu_LReadMessages(), {&st::ayuLReadMenuIcon} - )->setClickedCallback([=] + )->setClickedCallback([=]() mutable { - const auto prev = settings.sendReadMessages; - AyuSettings::set_sendReadMessages(false); + auto &ghost = AyuSettings::ghost(&controller->session()); + const auto prev = ghost.sendReadMessages(); + ghost.setSendReadMessages(false); const auto chats = controller->session().data().chatsList(); MarkAsReadChatList(chats); - AyuSettings::set_sendReadMessages(prev); + ghost.setSendReadMessages(prev); }); } - if (settings.showSReadToggleInDrawer) { - auto callback = [=](Fn &&close) { - auto prev = settings.sendReadMessages; - AyuSettings::set_sendReadMessages(true); + if (settings.showSReadToggleInDrawer()) { + auto callback = [=](Fn &&close) mutable { + auto &ghost = AyuSettings::ghost(&controller->session()); + const auto prev = ghost.sendReadMessages(); + ghost.setSendReadMessages(true); auto chats = controller->session().data().chatsList(); MarkAsReadChatList(chats); // slight delay for forums to send packets - dispatchToMainThread([=] + dispatchToMainThread([=]() mutable { - AyuSettings::set_sendReadMessages(prev); + auto &ghost = AyuSettings::ghost(&controller->session()); + ghost.setSendReadMessages(prev); }, 200); close(); }; @@ -789,7 +792,7 @@ void MainMenu::setupMenu() { controller->showSettings(); }); - if (settings.showNightModeToggleInDrawer) { + if (settings.showNightModeToggleInDrawer()) { _nightThemeToggle = addAction( tr::lng_menu_night_mode(), @@ -831,23 +834,29 @@ void MainMenu::setupMenu() { } - if (settings.showGhostToggleInDrawer) { + if (settings.showGhostToggleInDrawer()) { + auto ghostActiveChanges = AyuSettings::getInstance().useGlobalGhostModeChanges() + | rpl::map([controller = _controller](bool) { + return AyuSettings::ghost(&controller->session()).ghostModeActiveChanges(); + }) + | rpl::flatten_latest(); + const auto ghostModeToggle = addAction( tr::ayu_GhostModeToggle(), {&st::ayuGhostIcon} - )->toggleOn(AyuSettings::get_ghostModeEnabledReactive()); + )->toggleOn(std::move(ghostActiveChanges)); ghostModeToggle->toggledChanges( ) | rpl::on_next( - [=](bool ghostMode) + [controller = _controller](bool ghostMode) { - AyuSettings::set_ghostModeEnabled(ghostMode); - AyuSettings::save(); + auto &ghost = AyuSettings::ghost(&controller->session()); + ghost.setGhostModeEnabled(ghostMode); }, ghostModeToggle->lifetime()); } - if (settings.showStreamerToggleInDrawer) { + if (settings.showStreamerToggleInDrawer()) { const auto streamerModeToggle = addAction( tr::ayu_StreamerModeToggle(), {&st::ayuStreamerModeMenuIcon} diff --git a/Telegram/SourceFiles/window/window_session_controller.cpp b/Telegram/SourceFiles/window/window_session_controller.cpp index d39083e81c..c0da157ec0 100644 --- a/Telegram/SourceFiles/window/window_session_controller.cpp +++ b/Telegram/SourceFiles/window/window_session_controller.cpp @@ -1923,7 +1923,7 @@ void SessionController::activateFirstChatsFilter() { _filtersActivated = true; const auto &settings = AyuSettings::getInstance(); - if (!settings.hideAllChatsFolder) { + if (!settings.hideAllChatsFolder()) { setActiveChatsFilter(session().data().chatsFilters().defaultId()); } }