From 24121fbbce7d09b211bf3480b6ad42f77e571487 Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 30 Jun 2025 18:26:53 +0400 Subject: [PATCH] Improve conditions / phrases. --- Telegram/Resources/langs/lang.strings | 1 + .../SourceFiles/boxes/delete_messages_box.cpp | 11 ++-- .../controls/history_view_suggest_options.cpp | 55 +++++++++++++++++-- Telegram/SourceFiles/main/main_app_config.cpp | 16 ++++++ Telegram/SourceFiles/main/main_app_config.h | 4 ++ 5 files changed, 76 insertions(+), 11 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 9a8e6e2bf7..d0f7b1b36e 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -4452,6 +4452,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_suggest_options_date_publish" = "Publish"; "lng_suggest_options_date_now" = "Publish Now"; "lng_suggest_options_date_about" = "Select the date and time you want the message to be published."; +"lng_suggest_options_you_get" = "You will receive {amount} ({percent}) for publishing this post."; "lng_suggest_options_offer" = "Offer {amount}"; "lng_suggest_options_offer_free" = "Offer for Free"; "lng_suggest_options_update" = "Update Terms"; diff --git a/Telegram/SourceFiles/boxes/delete_messages_box.cpp b/Telegram/SourceFiles/boxes/delete_messages_box.cpp index 885ce1d2b6..5c4b266cd4 100644 --- a/Telegram/SourceFiles/boxes/delete_messages_box.cpp +++ b/Telegram/SourceFiles/boxes/delete_messages_box.cpp @@ -21,6 +21,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/history.h" #include "history/history_item.h" #include "lang/lang_keys.h" +#include "main/main_app_config.h" #include "main/main_session.h" #include "menu/menu_ttl_validator.h" #include "ui/boxes/confirm_box.h" @@ -33,12 +34,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "styles/style_layers.h" #include "styles/style_boxes.h" -namespace { - -constexpr auto kPaidShowLive = 86400; - -} // namespace - DeleteMessagesBox::DeleteMessagesBox( QWidget*, not_null item, @@ -507,7 +502,9 @@ PaidPostType DeleteMessagesBox::paidPostType() const { const auto type = item->paidType(); if (type != PaidPostType::None) { const auto date = item->date(); - if (now < date || now - date <= kPaidShowLive) { + const auto config = &item->history()->session().appConfig(); + const auto limit = config->suggestedPostAgeMin(); + if (now < date || now - date <= limit) { if (type == PaidPostType::Ton) { return type; } else if (type == PaidPostType::Stars) { diff --git a/Telegram/SourceFiles/history/view/controls/history_view_suggest_options.cpp b/Telegram/SourceFiles/history/view/controls/history_view_suggest_options.cpp index fe813538f9..d27ca8cf9a 100644 --- a/Telegram/SourceFiles/history/view/controls/history_view_suggest_options.cpp +++ b/Telegram/SourceFiles/history/view/controls/history_view_suggest_options.cpp @@ -109,6 +109,38 @@ void ChooseSuggestPriceBox( } }; + const auto appConfig = &args.peer->session().appConfig(); + const auto starsMul = appConfig->suggestedPostCommissionStars(); + const auto tonMul = appConfig->suggestedPostCommissionTon(); + + const auto starsPrice = [=] { + return rpl::single( + CreditsAmount() + ) | rpl::then(state->price.value( + ) | rpl::filter([=](CreditsAmount amount) { + return amount.stars(); + })); + }; + const auto tonPrice = [=] { + return rpl::single( + CreditsAmount(0, 0, CreditsType::Ton) + ) | rpl::then(state->price.value( + ) | rpl::filter([=](CreditsAmount amount) { + return amount.ton(); + })); + }; + const auto formatPrice = [=](int mul) { + return [=](CreditsAmount amount) { + const auto value = (amount.value() * mul / 1000.); + const auto whole = int(std::floor(value)); + //const auto nano = int(base::SafeRound( + // (value - whole) * Ui::kNanosInOne)); + const auto nano = 0; + return Lang::FormatCreditsAmountWithCurrency( + CreditsAmount(whole, nano, amount.type())); + }; + }; + const auto peer = args.peer; const auto admin = peer->amMonoforumAdmin(); const auto broadcast = peer->monoforumBroadcast(); @@ -118,7 +150,7 @@ void ChooseSuggestPriceBox( session->credits().load(); session->credits().tonLoad(); } - const auto starsMin = 0; + const auto starsMin = session->appConfig().suggestedPostStarsMin(); const auto starsMax = session->appConfig().suggestedPostStarsMax(); const auto nanoTonMin = session->appConfig().suggestedPostNanoTonMin(); const auto nanoTonMax = session->appConfig().suggestedPostNanoTonMax(); @@ -299,11 +331,20 @@ void ChooseSuggestPriceBox( starsFieldWrap->resize(width, starsField->height()); }, starsFieldWrap->lifetime()); + const auto starsCommission = QString::number(starsMul / 10.) + '%'; + const auto tonCommission = QString::number(tonMul / 10.) + '%'; + Ui::AddSkip(starsInner); Ui::AddSkip(starsInner); Ui::AddDividerText( starsInner, - tr::lng_suggest_options_stars_price_about()); + (admin + ? tr::lng_suggest_options_you_get( + lt_amount, + starsPrice() | rpl::map(formatPrice(starsMul)), + lt_percent, + rpl::single(starsCommission)) + : tr::lng_suggest_options_stars_price_about())); const auto tonWrap = container->add( object_ptr>( @@ -352,7 +393,13 @@ void ChooseSuggestPriceBox( Ui::AddSkip(tonInner); Ui::AddDividerText( tonInner, - tr::lng_suggest_options_ton_price_about()); + (admin + ? tr::lng_suggest_options_you_get( + lt_amount, + tonPrice() | rpl::map(formatPrice(tonMul)), + lt_percent, + rpl::single(tonCommission)) + : tr::lng_suggest_options_ton_price_about())); tonWrap->toggleOn(state->ton.value(), anim::type::instant); starsWrap->toggleOn( @@ -374,7 +421,7 @@ void ChooseSuggestPriceBox( nanos = now.value_or(0); } else { const auto now = starsField->getLastText().toLongLong(); - if (now < starsMin || now > starsMax) { + if (now && (now < starsMin || now > starsMax)) { starsField->showError(); return {}; } diff --git a/Telegram/SourceFiles/main/main_app_config.cpp b/Telegram/SourceFiles/main/main_app_config.cpp index 8b11c58683..b65c104555 100644 --- a/Telegram/SourceFiles/main/main_app_config.cpp +++ b/Telegram/SourceFiles/main/main_app_config.cpp @@ -170,6 +170,18 @@ int AppConfig::todoListItemTextLimit() const { return get(u"todo_item_length_max"_q, 64); } +int AppConfig::suggestedPostCommissionStars() const { + return get(u"stars_suggested_post_commission_permille"_q, 850); +} + +int AppConfig::suggestedPostCommissionTon() const { + return get(u"ton_suggested_post_commission_permille"_q, 850); +} + +int AppConfig::suggestedPostStarsMin() const { + return get(u"stars_suggested_post_amount_min"_q, 5); +} + int AppConfig::suggestedPostStarsMax() const { return get(u"stars_suggested_post_amount_max"_q, 100'000); } @@ -192,6 +204,10 @@ int AppConfig::suggestedPostDelayMax() const { return get(u"appConfig.stars_suggested_post_future_max"_q, 2678400); } +TimeId AppConfig::suggestedPostAgeMin() const { + return get(u"stars_suggested_post_age_min"_q, 86400); +} + void AppConfig::refresh(bool force) { if (_requestId || !_api) { if (force) { diff --git a/Telegram/SourceFiles/main/main_app_config.h b/Telegram/SourceFiles/main/main_app_config.h index 537c9cfaee..a2ea65f426 100644 --- a/Telegram/SourceFiles/main/main_app_config.h +++ b/Telegram/SourceFiles/main/main_app_config.h @@ -92,11 +92,15 @@ public: [[nodiscard]] int todoListTitleLimit() const; [[nodiscard]] int todoListItemTextLimit() const; + [[nodiscard]] int suggestedPostCommissionStars() const; + [[nodiscard]] int suggestedPostCommissionTon() const; + [[nodiscard]] int suggestedPostStarsMin() const; [[nodiscard]] int suggestedPostStarsMax() const; [[nodiscard]] int64 suggestedPostNanoTonMin() const; [[nodiscard]] int64 suggestedPostNanoTonMax() const; [[nodiscard]] int suggestedPostDelayMin() const; [[nodiscard]] int suggestedPostDelayMax() const; + [[nodiscard]] TimeId suggestedPostAgeMin() const; void refresh(bool force = false);