1 /* 2 This file is part of Telegram Desktop, 3 the official desktop application for the Telegram messaging service. 4 5 For license and copyright information please follow this link: 6 https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL 7 */ 8 #pragma once 9 10 #include "mtproto/sender.h" 11 12 namespace Main { 13 14 class Account; 15 16 class AppConfig final { 17 public: 18 explicit AppConfig(not_null<Account*> account); 19 20 template <typename Type> get(const QString & key,Type fallback)21 [[nodiscard]] Type get(const QString &key, Type fallback) const { 22 if constexpr (std::is_same_v<Type, double>) { 23 return getDouble(key, fallback); 24 } else if constexpr (std::is_same_v<Type, QString>) { 25 return getString(key, fallback); 26 } else if constexpr (std::is_same_v<Type, std::vector<QString>>) { 27 return getStringArray(key, std::move(fallback)); 28 } else if constexpr (std::is_same_v<Type, std::vector<std::map<QString, QString>>>) { 29 return getStringMapArray(key, std::move(fallback)); 30 } else if constexpr (std::is_same_v<Type, bool>) { 31 return getBool(key, fallback); 32 } 33 } 34 35 [[nodiscard]] rpl::producer<> refreshed() const; 36 [[nodiscard]] rpl::producer<> value() const; 37 38 [[nodiscard]] bool suggestionCurrent(const QString &key) const; 39 [[nodiscard]] rpl::producer<> suggestionRequested( 40 const QString &key) const; 41 void dismissSuggestion(const QString &key); 42 43 void refresh(); 44 45 private: 46 void refreshDelayed(); 47 48 template <typename Extractor> 49 [[nodiscard]] auto getValue( 50 const QString &key, 51 Extractor &&extractor) const; 52 53 [[nodiscard]] bool getBool( 54 const QString &key, 55 bool fallback) const; 56 [[nodiscard]] double getDouble( 57 const QString &key, 58 double fallback) const; 59 [[nodiscard]] QString getString( 60 const QString &key, 61 const QString &fallback) const; 62 [[nodiscard]] std::vector<QString> getStringArray( 63 const QString &key, 64 std::vector<QString> &&fallback) const; 65 [[nodiscard]] std::vector<std::map<QString, QString>> getStringMapArray( 66 const QString &key, 67 std::vector<std::map<QString, QString>> &&fallback) const; 68 69 const not_null<Account*> _account; 70 std::optional<MTP::Sender> _api; 71 mtpRequestId _requestId = 0; 72 base::flat_map<QString, MTPJSONValue> _data; 73 rpl::event_stream<> _refreshed; 74 base::flat_set<QString> _dismissedSuggestions; 75 rpl::lifetime _lifetime; 76 77 }; 78 79 } // namespace Main 80