From 3fea28f8b0a83d0c0df07f757d6b9055de6ce12e Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 30 Jun 2025 22:23:55 +0400 Subject: [PATCH] Warn admins about commission and stars. --- Telegram/Resources/langs/lang.strings | 12 +-- Telegram/SourceFiles/api/api_suggest_post.cpp | 32 ++++++-- .../controls/history_view_suggest_options.cpp | 73 ++++++++++++------- .../controls/history_view_suggest_options.h | 7 ++ 4 files changed, 87 insertions(+), 37 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index d0f7b1b36e..4b278eeb3d 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -4451,8 +4451,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_suggest_options_date_any" = "Anytime"; "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_date_about" = "Select the date and time you want the message to be published. The post will remain available for at least 24 hours from this date."; "lng_suggest_options_you_get" = "You will receive {amount} ({percent}) for publishing this post."; +"lng_suggest_options_stars_warning" = "Transactions in **Stars** may be reversed by the payment provider within **21** days. Only accept Stars from people you trust."; "lng_suggest_options_offer" = "Offer {amount}"; "lng_suggest_options_offer_free" = "Offer for Free"; "lng_suggest_options_update" = "Update Terms"; @@ -4494,14 +4495,15 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_suggest_decline_text" = "Do you want to decline publishing this post from {from}?"; "lng_suggest_decline_text_to" = "Do you want to decline publishing this post to {channel}?"; "lng_suggest_decline_reason" = "Add a reason (optional)"; -"lng_suggest_accept_title" = "Accept"; +"lng_suggest_accept_title" = "Accept Terms"; "lng_suggest_accept_text" = "Do you want to publish this post from {from}?"; "lng_suggest_accept_text_to" = "Do you want to publish this post to {channel}?"; -"lng_suggest_accept_receive" = "{channel} will receive {amount} for publishing {date}."; -"lng_suggest_accept_receive_now" = "{channel} will receive {amount} for publishing right now."; +"lng_suggest_accept_receive" = "{channel} will receive {amount} ({percent}) for publishing {date}."; +"lng_suggest_accept_receive_now" = "{channel} will receive {amount} ({percent}) for publishing right now."; +"lng_suggest_accept_receive_if" = "It must remain visible for at least **24** hours after publication."; "lng_suggest_accept_pay" = "You will pay {amount} for publishing {date}."; "lng_suggest_accept_pay_now" = "You will pay {amount} for publishing right now."; -"lng_suggest_accept_send" = "Send"; +"lng_suggest_accept_send" = "Publish"; "lng_suggest_ton_amount#one" = "{count} TON"; "lng_suggest_ton_amount#other" = "{count} TON"; "lng_suggest_warn_title_stars" = "Stars will be lost"; diff --git a/Telegram/SourceFiles/api/api_suggest_post.cpp b/Telegram/SourceFiles/api/api_suggest_post.cpp index 1aa8921826..b366f4722e 100644 --- a/Telegram/SourceFiles/api/api_suggest_post.cpp +++ b/Telegram/SourceFiles/api/api_suggest_post.cpp @@ -137,9 +137,15 @@ void ConfirmApproval( } } const auto peer = item->history()->peer; + const auto session = &peer->session(); const auto broadcast = peer->monoforumBroadcast(); const auto channelName = (broadcast ? broadcast : peer)->name(); - const auto amount = Lang::FormatCreditsAmountWithCurrency(price); + const auto amount = admin + ? HistoryView::FormatPriceAfterCommission(session, price) + : Lang::FormatCreditsAmountWithCurrency(price); + const auto commission = HistoryView::FormatAfterCommissionPercent( + session, + price); const auto date = langDateTime(base::unixtime::parse(scheduleDate)); show->show(Box([=](not_null box) { const auto callback = std::make_shared>(); @@ -163,16 +169,20 @@ void ConfirmApproval( Ui::Text::Bold(channelName), lt_amount, Ui::Text::Bold(amount), + lt_percent, + TextWithEntities{ commission }, lt_date, Ui::Text::Bold(date), - Ui::Text::WithEntities) + Ui::Text::RichLangValue) : tr::lng_suggest_accept_receive_now( tr::now, lt_channel, Ui::Text::Bold(channelName), lt_amount, Ui::Text::Bold(amount), - Ui::Text::WithEntities)) + lt_percent, + TextWithEntities{ commission }, + Ui::Text::RichLangValue)) : (scheduleDate ? tr::lng_suggest_accept_pay( tr::now, @@ -180,12 +190,24 @@ void ConfirmApproval( Ui::Text::Bold(amount), lt_date, Ui::Text::Bold(date), - Ui::Text::WithEntities) + Ui::Text::RichLangValue) : tr::lng_suggest_accept_pay_now( tr::now, lt_amount, Ui::Text::Bold(amount), - Ui::Text::WithEntities))); + Ui::Text::RichLangValue))); + if (admin) { + text.append(' ').append( + tr::lng_suggest_accept_receive_if( + tr::now, + Ui::Text::RichLangValue)); + if (price.stars()) { + text.append("\n\n").append( + tr::lng_suggest_options_stars_warning( + tr::now, + Ui::Text::RichLangValue)); + } + } } Ui::ConfirmBox(box, { .text = text, 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 d27ca8cf9a..151beb72da 100644 --- a/Telegram/SourceFiles/history/view/controls/history_view_suggest_options.cpp +++ b/Telegram/SourceFiles/history/view/controls/history_view_suggest_options.cpp @@ -109,10 +109,6 @@ 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() @@ -129,17 +125,6 @@ void ChooseSuggestPriceBox( 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(); @@ -331,20 +316,26 @@ 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, - (admin - ? tr::lng_suggest_options_you_get( + const auto formatPrice = [peer = args.peer](CreditsAmount amount) { + return FormatPriceAfterCommission(&peer->session(), amount); + }; + const auto formatCommission = [peer = args.peer](CreditsAmount amount) { + return FormatAfterCommissionPercent(&peer->session(), amount); + }; + Ui::AddDividerText(starsInner, admin + ? rpl::combine( + tr::lng_suggest_options_you_get( lt_amount, - starsPrice() | rpl::map(formatPrice(starsMul)), + starsPrice() | rpl::map(formatPrice), lt_percent, - rpl::single(starsCommission)) - : tr::lng_suggest_options_stars_price_about())); + starsPrice() | rpl::map(formatCommission)), + tr::lng_suggest_options_stars_warning(Ui::Text::RichLangValue) + ) | rpl::map([=](const QString &t1, const TextWithEntities &t2) { + return TextWithEntities{ t1 }.append("\n\n").append(t2); + }) + : tr::lng_suggest_options_stars_price_about(Ui::Text::WithEntities)); const auto tonWrap = container->add( object_ptr>( @@ -396,9 +387,9 @@ void ChooseSuggestPriceBox( (admin ? tr::lng_suggest_options_you_get( lt_amount, - tonPrice() | rpl::map(formatPrice(tonMul)), + tonPrice() | rpl::map(formatPrice), lt_percent, - rpl::single(tonCommission)) + tonPrice() | rpl::map(formatCommission)) : tr::lng_suggest_options_ton_price_about())); tonWrap->toggleOn(state->ton.value(), anim::type::instant); @@ -642,6 +633,33 @@ bool CanAddOfferToMessage(not_null item) { history->owner().history(broadcast)).has_value(); } +QString FormatPriceAfterCommission( + not_null session, + CreditsAmount price) { + const auto appConfig = &session->appConfig(); + const auto mul = price.stars() + ? appConfig->suggestedPostCommissionStars() + : appConfig->suggestedPostCommissionTon(); + + const auto value = (price.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, price.type())); +} + +QString FormatAfterCommissionPercent( + not_null session, + CreditsAmount price) { + const auto appConfig = &session->appConfig(); + const auto mul = price.stars() + ? appConfig->suggestedPostCommissionStars() + : appConfig->suggestedPostCommissionTon(); + return QString::number(mul / 10.) + '%'; +} + void InsufficientTonBox( not_null box, not_null peer, @@ -755,6 +773,7 @@ void SuggestOptions::edit() { .peer = _peer, .done = apply, .value = _values, + .mode = _mode, })); } diff --git a/Telegram/SourceFiles/history/view/controls/history_view_suggest_options.h b/Telegram/SourceFiles/history/view/controls/history_view_suggest_options.h index 46f8cde0dd..325ada40f3 100644 --- a/Telegram/SourceFiles/history/view/controls/history_view_suggest_options.h +++ b/Telegram/SourceFiles/history/view/controls/history_view_suggest_options.h @@ -58,6 +58,13 @@ void ChooseSuggestPriceBox( [[nodiscard]] bool CanAddOfferToMessage(not_null item); +[[nodiscard]] QString FormatPriceAfterCommission( + not_null session, + CreditsAmount price); +[[nodiscard]] QString FormatAfterCommissionPercent( + not_null session, + CreditsAmount price); + void InsufficientTonBox( not_null box, not_null peer,