2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-23 10:47:11 +00:00
tdesktop/Telegram/SourceFiles/main/main_app_config.h

170 lines
5.4 KiB
C
Raw Normal View History

2019-08-01 15:50:24 +01:00
/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#pragma once
2019-11-27 12:45:23 +03:00
#include "mtproto/sender.h"
#include "base/algorithm.h"
2019-11-27 12:45:23 +03:00
namespace Ui {
struct ColorIndicesCompressed;
} // namespace Ui
2019-08-01 15:50:24 +01:00
namespace Main {
2019-11-27 12:45:23 +03:00
class Account;
2019-08-01 15:50:24 +01:00
class AppConfig final {
public:
2019-11-27 12:45:23 +03:00
explicit AppConfig(not_null<Account*> account);
~AppConfig();
2019-08-01 15:50:24 +01:00
void start();
2019-08-01 15:50:24 +01:00
template <typename Type>
2019-11-27 12:45:23 +03:00
[[nodiscard]] Type get(const QString &key, Type fallback) const {
2019-08-01 15:50:24 +01:00
if constexpr (std::is_same_v<Type, double>) {
return getDouble(key, fallback);
} else if constexpr (std::is_same_v<Type, int>) {
return int(base::SafeRound(getDouble(key, double(fallback))));
} else if constexpr (std::is_same_v<Type, int64>) {
return int64(base::SafeRound(getDouble(key, double(fallback))));
2019-11-27 12:45:23 +03:00
} else if constexpr (std::is_same_v<Type, QString>) {
return getString(key, fallback);
} else if constexpr (std::is_same_v<Type, std::vector<QString>>) {
return getStringArray(key, std::move(fallback));
2024-07-12 12:23:47 +02:00
} else if constexpr (
std::is_same_v<Type, base::flat_map<QString, QString>>) {
return getStringMap(key, std::move(fallback));
} else if constexpr (std::is_same_v<Type, std::vector<int>>) {
return getIntArray(key, std::move(fallback));
2020-03-18 14:07:11 +04:00
} else if constexpr (std::is_same_v<Type, bool>) {
return getBool(key, fallback);
2019-08-01 15:50:24 +01:00
}
}
2019-11-27 12:45:23 +03:00
[[nodiscard]] rpl::producer<> refreshed() const;
2020-07-03 20:53:24 +04:00
[[nodiscard]] rpl::producer<> value() const;
2024-03-29 15:30:50 +04:00
[[nodiscard]] bool newRequirePremiumFree() const;
2024-08-14 15:17:59 +02:00
[[nodiscard]] auto ignoredRestrictionReasons() const
-> const std::vector<QString> & {
return _ignoreRestrictionReasons;
}
[[nodiscard]] auto ignoredRestrictionReasonsChanges() const {
return _ignoreRestrictionChanges.events();
}
2024-09-30 14:45:55 +04:00
[[nodiscard]] int quoteLengthMax() const;
2024-10-14 18:31:35 +04:00
[[nodiscard]] int stargiftConvertPeriodMax() const;
2024-09-30 14:45:55 +04:00
2024-11-29 17:24:22 +04:00
[[nodiscard]] const std::vector<QString> &startRefPrefixes();
[[nodiscard]] bool starrefSetupAllowed() const;
[[nodiscard]] bool starrefJoinAllowed() const;
[[nodiscard]] int starrefCommissionMin() const;
[[nodiscard]] int starrefCommissionMax() const;
2024-11-29 17:24:22 +04:00
[[nodiscard]] int starsWithdrawMax() const;
[[nodiscard]] float64 starsWithdrawRate() const;
[[nodiscard]] float64 currencyWithdrawRate() const;
[[nodiscard]] bool paidMessagesAvailable() const;
[[nodiscard]] int paidMessageStarsMax() const;
[[nodiscard]] int paidMessageCommission() const;
[[nodiscard]] int paidMessageChannelStarsDefault() const;
2025-03-05 14:57:17 +04:00
[[nodiscard]] int pinnedGiftsLimit() const;
2025-07-17 17:31:38 +04:00
[[nodiscard]] int giftCollectionsLimit() const;
[[nodiscard]] int giftCollectionGiftsLimit() const;
2025-03-05 14:57:17 +04:00
[[nodiscard]] bool callsDisabledForSession() const;
2025-04-07 13:30:58 +04:00
[[nodiscard]] int confcallSizeLimit() const;
2025-04-04 11:18:10 +04:00
[[nodiscard]] bool confcallPrioritizeVP8() const;
2025-07-29 17:15:48 +04:00
[[nodiscard]] int giftResaleStarsMin() const;
[[nodiscard]] int giftResaleStarsMax() const;
[[nodiscard]] int giftResaleStarsThousandths() const;
[[nodiscard]] int64 giftResaleNanoTonMin() const;
[[nodiscard]] int64 giftResaleNanoTonMax() const;
[[nodiscard]] int giftResaleNanoTonThousandths() const;
2025-04-22 12:04:26 +04:00
2025-05-27 18:31:47 +04:00
[[nodiscard]] int pollOptionsLimit() const;
2025-06-10 18:16:48 +04:00
[[nodiscard]] int todoListItemsLimit() const;
[[nodiscard]] int todoListTitleLimit() const;
[[nodiscard]] int todoListItemTextLimit() const;
2025-05-27 18:31:47 +04:00
2025-06-30 18:26:53 +04:00
[[nodiscard]] int suggestedPostCommissionStars() const;
[[nodiscard]] int suggestedPostCommissionTon() const;
[[nodiscard]] int suggestedPostStarsMin() const;
2025-06-13 14:39:30 +04:00
[[nodiscard]] int suggestedPostStarsMax() const;
[[nodiscard]] int64 suggestedPostNanoTonMin() const;
[[nodiscard]] int64 suggestedPostNanoTonMax() const;
[[nodiscard]] int suggestedPostDelayMin() const;
[[nodiscard]] int suggestedPostDelayMax() const;
2025-06-30 18:26:53 +04:00
[[nodiscard]] TimeId suggestedPostAgeMin() const;
2025-06-13 14:39:30 +04:00
[[nodiscard]] bool ageVerifyNeeded() const;
[[nodiscard]] QString ageVerifyCountry() const;
[[nodiscard]] int ageVerifyMinAge() const;
[[nodiscard]] QString ageVerifyBotUsername() const;
2025-07-28 22:29:39 +04:00
[[nodiscard]] int storiesAlbumsLimit() const;
[[nodiscard]] int storiesAlbumLimit() const;
2024-08-14 15:17:59 +02:00
void refresh(bool force = false);
private:
2019-08-01 15:50:24 +01:00
void refreshDelayed();
2019-11-27 12:45:23 +03:00
template <typename Extractor>
[[nodiscard]] auto getValue(
const QString &key,
Extractor &&extractor) const;
2020-03-18 14:07:11 +04:00
[[nodiscard]] bool getBool(
const QString &key,
bool fallback) const;
2019-11-27 12:45:23 +03:00
[[nodiscard]] double getDouble(
const QString &key,
double fallback) const;
[[nodiscard]] QString getString(
const QString &key,
const QString &fallback) const;
[[nodiscard]] std::vector<QString> getStringArray(
const QString &key,
std::vector<QString> &&fallback) const;
2024-07-12 12:23:47 +02:00
[[nodiscard]] base::flat_map<QString, QString> getStringMap(
2020-07-09 21:38:26 +04:00
const QString &key,
2024-07-12 12:23:47 +02:00
base::flat_map<QString, QString> &&fallback) const;
[[nodiscard]] std::vector<int> getIntArray(
const QString &key,
std::vector<int> &&fallback) const;
2019-08-01 15:50:24 +01:00
2024-08-14 15:17:59 +02:00
void updateIgnoredRestrictionReasons(std::vector<QString> was);
2019-11-27 12:45:23 +03:00
const not_null<Account*> _account;
std::optional<MTP::Sender> _api;
2019-08-01 15:50:24 +01:00
mtpRequestId _requestId = 0;
2023-03-01 11:55:33 +04:00
int32 _hash = 0;
2024-08-14 15:17:59 +02:00
bool _pendingRefresh = false;
2019-08-01 15:50:24 +01:00
base::flat_map<QString, MTPJSONValue> _data;
2019-11-27 12:45:23 +03:00
rpl::event_stream<> _refreshed;
2024-08-14 15:17:59 +02:00
std::vector<QString> _ignoreRestrictionReasons;
rpl::event_stream<std::vector<QString>> _ignoreRestrictionChanges;
2024-11-29 17:24:22 +04:00
std::vector<QString> _startRefPrefixes;
2025-03-10 17:52:13 +04:00
crl::time _lastFrozenRefresh = 0;
rpl::lifetime _frozenTrackLifetime;
2019-11-27 12:45:23 +03:00
rpl::lifetime _lifetime;
2019-08-01 15:50:24 +01:00
};
} // namespace Main