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"
|
2022-08-02 12:40:55 +03:00
|
|
|
#include "base/algorithm.h"
|
2019-11-27 12:45:23 +03:00
|
|
|
|
2023-10-26 23:40:53 +04: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);
|
2023-10-26 23:40:53 +04:00
|
|
|
~AppConfig();
|
2019-08-01 15:50:24 +01:00
|
|
|
|
2022-01-13 19:39:44 +03: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);
|
2022-08-02 12:40:55 +03:00
|
|
|
} else if constexpr (std::is_same_v<Type, int>) {
|
|
|
|
return int(base::SafeRound(getDouble(key, double(fallback))));
|
2025-06-27 18:57:01 +04:00
|
|
|
} 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);
|
2019-12-09 16:57:33 +03:00
|
|
|
} 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));
|
2023-10-26 23:40:53 +04:00
|
|
|
} 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();
|
2024-11-29 17:35:46 +04:00
|
|
|
[[nodiscard]] bool starrefSetupAllowed() const;
|
|
|
|
[[nodiscard]] bool starrefJoinAllowed() const;
|
2024-11-30 13:10:03 +04:00
|
|
|
[[nodiscard]] int starrefCommissionMin() const;
|
|
|
|
[[nodiscard]] int starrefCommissionMax() const;
|
2024-11-29 17:24:22 +04:00
|
|
|
|
2025-06-29 22:34:18 +03:00
|
|
|
[[nodiscard]] int starsWithdrawMax() const;
|
2025-03-01 09:22:07 +04:00
|
|
|
[[nodiscard]] float64 starsWithdrawRate() const;
|
2025-06-29 15:44:32 +03:00
|
|
|
[[nodiscard]] float64 currencyWithdrawRate() const;
|
2025-03-01 09:22:07 +04:00
|
|
|
[[nodiscard]] bool paidMessagesAvailable() const;
|
|
|
|
[[nodiscard]] int paidMessageStarsMax() const;
|
|
|
|
[[nodiscard]] int paidMessageCommission() const;
|
2025-06-04 18:42:17 +04:00
|
|
|
[[nodiscard]] int paidMessageChannelStarsDefault() const;
|
2025-03-01 09:22:07 +04:00
|
|
|
|
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
|
|
|
|
2025-04-16 14:27:08 +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;
|
2025-06-27 18:57:01 +04:00
|
|
|
[[nodiscard]] int64 suggestedPostNanoTonMin() const;
|
|
|
|
[[nodiscard]] int64 suggestedPostNanoTonMax() const;
|
2025-06-20 13:13:17 +04:00
|
|
|
[[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
|
|
|
|
2025-07-21 16:47:41 +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);
|
2019-12-09 16:57:33 +03:00
|
|
|
|
|
|
|
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;
|
2019-12-09 16:57:33 +03:00
|
|
|
[[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;
|
2023-10-26 23:40:53 +04:00
|
|
|
[[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;
|
2023-10-26 23:40:53 +04:00
|
|
|
|
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
|