Moved out minimal levels of boosts for channel settings to single place.

This commit is contained in:
23rd 2024-03-07 02:27:15 +03:00 committed by John Preston
parent eab249fc13
commit 09285bc9cd
7 changed files with 129 additions and 49 deletions

View file

@ -31,8 +31,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "history/history_item.h"
#include "history/history_item_helpers.h"
#include "history/view/history_view_message.h"
#include "main/main_account.h"
#include "main/main_app_config.h"
#include "main/main_session.h"
#include "apiwrap.h"
#include "data/data_session.h"
@ -42,6 +40,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_document_resolver.h"
#include "data/data_file_origin.h"
#include "data/data_peer_values.h"
#include "data/data_premium_limits.h"
#include "settings/settings_premium.h"
#include "storage/file_upload.h"
#include "storage/localimageloader.h"
@ -699,16 +698,10 @@ void BackgroundPreviewBox::checkLevelForChannel() {
if (!weak) {
return std::optional<Ui::AskBoostReason>();
}
const auto appConfig = &_forPeer->session().account().appConfig();
const auto defaultRequired = appConfig->get<int>(
"channel_wallpaper_level_min",
9);
const auto customRequired = appConfig->get<int>(
"channel_custom_wallpaper_level_min",
10);
const auto limits = Data::LevelLimits(&_forPeer->session());
const auto required = _paperEmojiId.isEmpty()
? customRequired
: defaultRequired;
? limits.channelCustomWallpaperLevelMin()
: limits.channelWallpaperLevelMin();
if (level >= required) {
applyForPeer(false);
return std::optional<Ui::AskBoostReason>();

View file

@ -23,6 +23,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_emoji_statuses.h"
#include "data/data_file_origin.h"
#include "data/data_peer.h"
#include "data/data_premium_limits.h"
#include "data/data_session.h"
#include "data/data_web_page.h"
#include "history/view/history_view_element.h"
@ -34,8 +35,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "lang/lang_keys.h"
#include "lottie/lottie_icon.h"
#include "lottie/lottie_single_player.h"
#include "main/main_account.h"
#include "main/main_app_config.h"
#include "main/main_session.h"
#include "settings/settings_common.h"
#include "settings/settings_premium.h"
@ -541,16 +540,13 @@ void Apply(
: peerColors->requiredChannelLevelFor(
peer->id,
values.colorIndex);
const auto limits = Data::LevelLimits(&peer->session());
const auto iconRequired = values.backgroundEmojiId
? session->account().appConfig().get<int>(
"channel_bg_icon_level_min",
5)
? limits.channelBgIconLevelMin()
: 0;
const auto statusRequired = (values.statusChanged
&& values.statusId)
? session->account().appConfig().get<int>(
"channel_emoji_status_level_min",
8)
? limits.channelEmojiStatusLevelMin()
: 0;
const auto required = std::max({
colorRequired,

View file

@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "apiwrap.h"
#include "base/event_filter.h"
#include "base/unixtime.h"
#include "data/data_premium_limits.h"
#include "boxes/peer_list_box.h"
#include "data/data_channel.h"
#include "data/data_cloud_themes.h"
@ -447,22 +448,23 @@ Ui::BoostFeatures LookupBoostFeatures(not_null<ChannelData*> channel) {
if (themes.empty()) {
channel->owner().cloudThemes().refreshChatThemes();
}
const auto levelLimits = Data::LevelLimits(&channel->session());
return Ui::BoostFeatures{
.nameColorsByLevel = std::move(nameColorsByLevel),
.linkStylesByLevel = std::move(linkStylesByLevel),
.linkLogoLevel = get(u"channel_bg_icon_level_min"_q, 4, !group),
.transcribeLevel = get(u"group_transcribe_level_min"_q, 6, group),
.emojiPackLevel = get(u"group_emoji_stickers_level_min"_q, 4, group),
.emojiStatusLevel = get(group
? u"group_emoji_status_level_min"_q
: u"channel_emoji_status_level_min"_q, 8),
.wallpaperLevel = get(group
? u"group_wallpaper_level_min"_q
: u"channel_wallpaper_level_min"_q, 9),
.linkLogoLevel = group ? 0 : levelLimits.channelBgIconLevelMin(),
.transcribeLevel = group ? levelLimits.groupTranscribeLevelMin() : 0,
.emojiPackLevel = group ? levelLimits.groupEmojiStickersLevelMin() : 0,
.emojiStatusLevel = group
? levelLimits.groupEmojiStatusLevelMin()
: levelLimits.channelEmojiStatusLevelMin(),
.wallpaperLevel = group
? levelLimits.groupWallpaperLevelMin()
: levelLimits.channelWallpaperLevelMin(),
.wallpapersCount = themes.empty() ? 8 : int(themes.size()),
.customWallpaperLevel = get(group
? u"channel_custom_wallpaper_level_min"_q
: u"group_custom_wallpaper_level_min"_q, 10),
.customWallpaperLevel = group
? levelLimits.groupCustomWallpaperLevelMin()
: levelLimits.channelCustomWallpaperLevelMin(),
};
}

View file

@ -12,6 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_channel.h"
#include "data/data_file_origin.h"
#include "data/data_document_media.h"
#include "data/data_premium_limits.h"
#include "data/stickers/data_stickers.h"
#include "core/application.h"
#include "lang/lang_keys.h"
@ -40,8 +41,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/painter.h"
#include "ui/unread_badge_paint.h"
#include "media/clip/media_clip_reader.h"
#include "main/main_account.h"
#include "main/main_app_config.h"
#include "main/main_session.h"
#include "styles/style_layers.h"
#include "styles/style_boxes.h"
@ -2050,10 +2049,8 @@ void StickersBox::Inner::checkGroupLevel(Fn<void()> done) {
return std::optional<Ui::AskBoostReason>();
}
_checkingGroupLevel = false;
const auto appConfig = &peer->session().account().appConfig();
const auto required = appConfig->get<int>(
"group_emoji_stickers_level_min",
4);
const auto required = Data::LevelLimits(
&peer->session()).groupEmojiStickersLevelMin();
if (level >= required) {
save();
return std::optional<Ui::AskBoostReason>();

View file

@ -217,4 +217,80 @@ bool PremiumLimits::isPremium() const {
return _session->premium();
}
LevelLimits::LevelLimits(not_null<Main::Session*> session)
: _session(session) {
}
int LevelLimits::channelColorLevelMin() const {
return _session->account().appConfig().get<int>(
u"channel_color_level_min"_q,
5);
}
int LevelLimits::channelBgIconLevelMin() const {
return _session->account().appConfig().get<int>(
u"channel_bg_icon_level_min"_q,
4);
}
int LevelLimits::channelProfileBgIconLevelMin() const {
return _session->account().appConfig().get<int>(
u"channel_profile_bg_icon_level_min"_q,
7);
}
int LevelLimits::channelEmojiStatusLevelMin() const {
return _session->account().appConfig().get<int>(
u"channel_emoji_status_level_min"_q,
8);
}
int LevelLimits::channelWallpaperLevelMin() const {
return _session->account().appConfig().get<int>(
u"channel_wallpaper_level_min"_q,
9);
}
int LevelLimits::channelCustomWallpaperLevelMin() const {
return _session->account().appConfig().get<int>(
u"channel_custom_wallpaper_level_min"_q,
10);
}
int LevelLimits::groupTranscribeLevelMin() const {
return _session->account().appConfig().get<int>(
u"group_transcribe_level_min"_q,
6);
}
int LevelLimits::groupEmojiStickersLevelMin() const {
return _session->account().appConfig().get<int>(
u"group_emoji_stickers_level_min"_q,
4);
}
int LevelLimits::groupProfileBgIconLevelMin() const {
return _session->account().appConfig().get<int>(
u"group_profile_bg_icon_level_min"_q,
5);
}
int LevelLimits::groupEmojiStatusLevelMin() const {
return _session->account().appConfig().get<int>(
u"group_emoji_status_level_min"_q,
8);
}
int LevelLimits::groupWallpaperLevelMin() const {
return _session->account().appConfig().get<int>(
u"group_wallpaper_level_min"_q,
9);
}
int LevelLimits::groupCustomWallpaperLevelMin() const {
return _session->account().appConfig().get<int>(
u"group_custom_wallpaper_level_min"_q,
10);
}
} // namespace Data

View file

@ -91,4 +91,26 @@ private:
};
class LevelLimits final {
public:
LevelLimits(not_null<Main::Session*> session);
[[nodiscard]] int channelColorLevelMin() const;
[[nodiscard]] int channelBgIconLevelMin() const;
[[nodiscard]] int channelProfileBgIconLevelMin() const;
[[nodiscard]] int channelEmojiStatusLevelMin() const;
[[nodiscard]] int channelWallpaperLevelMin() const;
[[nodiscard]] int channelCustomWallpaperLevelMin() const;
[[nodiscard]] int groupTranscribeLevelMin() const;
[[nodiscard]] int groupEmojiStickersLevelMin() const;
[[nodiscard]] int groupProfileBgIconLevelMin() const;
[[nodiscard]] int groupEmojiStatusLevelMin() const;
[[nodiscard]] int groupWallpaperLevelMin() const;
[[nodiscard]] int groupCustomWallpaperLevelMin() const;
private:
const not_null<Main::Session*> _session;
};
} // namespace Data

View file

@ -239,10 +239,8 @@ Session::Session(not_null<Main::Session*> session)
_session->local().cacheBigFilePath(),
_session->local().cacheBigFileSettings()))
, _groupFreeTranscribeLevel(session->account().appConfig().value(
) | rpl::map([=] {
return session->account().appConfig().get<int>(
u"group_transcribe_level_min"_q,
6);
) | rpl::map([limits = Data::LevelLimits(session)] {
return limits.groupTranscribeLevelMin();
}))
, _chatsList(
session,
@ -2185,8 +2183,7 @@ rpl::producer<int> Session::maxPinnedChatsLimitValue(
// because it slices the list to that limit. We don't want to slice
// premium-ly added chats from the pinned list because of sync issues.
return _session->account().appConfig().value(
) | rpl::map([=] {
const auto limits = Data::PremiumLimits(_session);
) | rpl::map([folder, limits = Data::PremiumLimits(_session)] {
return folder
? limits.dialogsFolderPinnedPremium()
: limits.dialogsPinnedPremium();
@ -2200,8 +2197,7 @@ rpl::producer<int> Session::maxPinnedChatsLimitValue(
// because it slices the list to that limit. We don't want to slice
// premium-ly added chats from the pinned list because of sync issues.
return _session->account().appConfig().value(
) | rpl::map([=] {
const auto limits = Data::PremiumLimits(_session);
) | rpl::map([limits = Data::PremiumLimits(_session)] {
return limits.dialogFiltersChatsPremium();
});
}
@ -2209,8 +2205,7 @@ rpl::producer<int> Session::maxPinnedChatsLimitValue(
rpl::producer<int> Session::maxPinnedChatsLimitValue(
not_null<Data::Forum*> forum) const {
return _session->account().appConfig().value(
) | rpl::map([=] {
const auto limits = Data::PremiumLimits(_session);
) | rpl::map([limits = Data::PremiumLimits(_session)] {
return limits.topicsPinnedCurrent();
});
}
@ -2222,8 +2217,7 @@ rpl::producer<int> Session::maxPinnedChatsLimitValue(
// because it slices the list to that limit. We don't want to slice
// premium-ly added chats from the pinned list because of sync issues.
return _session->account().appConfig().value(
) | rpl::map([=] {
const auto limits = Data::PremiumLimits(_session);
) | rpl::map([limits = Data::PremiumLimits(_session)] {
return limits.savedSublistsPinnedPremium();
});
}