From 4729e51e1412932d6e811970c013bdefe8e55b39 Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 18 Feb 2025 21:06:05 +0400 Subject: [PATCH] Improve phrases for paid messages. --- Telegram/Resources/langs/lang.strings | 9 +++-- Telegram/SourceFiles/apiwrap.cpp | 14 +++++-- Telegram/SourceFiles/apiwrap.h | 2 +- .../data/data_chat_participant_status.cpp | 39 ++++++++++++++++--- 4 files changed, 51 insertions(+), 13 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index ea11eb467..0720de5c8 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -4826,10 +4826,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_payment_confirm_title" = "Confirm payment"; "lng_payment_confirm_text#one" = "{name} charges **{count}** Star per message."; "lng_payment_confirm_text#other" = "{name} charges **{count}** Stars per message."; -"lng_payment_confirm_sure#one" = "Would you like to pay **{count}** Star to send one message?"; -"lng_payment_confirm_sure#other" = "Would you like to pay **{count}** Stars to send one message?"; +"lng_payment_confirm_amount#one" = "**{count}** Star"; +"lng_payment_confirm_amount#other" = "**{count}** Stars"; +"lng_payment_confirm_sure#one" = "Would you like to pay {amount} to send **{count}** message?"; +"lng_payment_confirm_sure#other" = "Would you like to pay {amount} to send **{count}** messages?"; "lng_payment_confirm_dont_ask" = "Don't ask me again"; -"lng_payment_confirm_button" = "Pay for 1 Message"; +"lng_payment_confirm_button#one" = "Pay for {count} Message"; +"lng_payment_confirm_button#other" = "Pay for {count} Messages"; "lng_payment_bar_text" = "{name} must pay {cost} for each message to you."; "lng_payment_bar_button" = "Remove Fee"; "lng_payment_refund_title" = "Remove Fee"; diff --git a/Telegram/SourceFiles/apiwrap.cpp b/Telegram/SourceFiles/apiwrap.cpp index 778d55228..f10f68988 100644 --- a/Telegram/SourceFiles/apiwrap.cpp +++ b/Telegram/SourceFiles/apiwrap.cpp @@ -3298,7 +3298,7 @@ void ApiWrap::finishForwarding(const SendAction &action) { void ApiWrap::forwardMessages( Data::ResolvedForwardDraft &&draft, - const SendAction &action, + SendAction action, FnMut &&successCallback) { Expects(!draft.items.empty()); @@ -3373,9 +3373,17 @@ void ApiWrap::forwardMessages( const auto requestType = Data::Histories::RequestType::Send; const auto idsCopy = localIds; const auto scheduled = action.options.scheduled; + auto paidStars = std::min( + action.options.starsApproved, + int(ids.size() * peer->starsPerMessageChecked())); + auto oneFlags = sendFlags; + if (paidStars) { + action.options.starsApproved -= paidStars; + oneFlags |= SendFlag::f_allow_paid_stars; + } histories.sendRequest(history, requestType, [=](Fn finish) { history->sendRequestId = request(MTPmessages_ForwardMessages( - MTP_flags(sendFlags), + MTP_flags(oneFlags), forwardFrom->input, MTP_vector(ids), MTP_vector(randomIds), @@ -3385,7 +3393,7 @@ void ApiWrap::forwardMessages( (sendAs ? sendAs->input : MTP_inputPeerEmpty()), Data::ShortcutIdToMTP(_session, action.options.shortcutId), MTPint(), // video_timestamp - MTPlong() // allow_paid_stars + MTP_long(paidStars) )).done([=](const MTPUpdates &result) { if (!scheduled) { this->updates().checkForSentToScheduled(result); diff --git a/Telegram/SourceFiles/apiwrap.h b/Telegram/SourceFiles/apiwrap.h index c9e97d0ed..0817560b7 100644 --- a/Telegram/SourceFiles/apiwrap.h +++ b/Telegram/SourceFiles/apiwrap.h @@ -306,7 +306,7 @@ public: void finishForwarding(const SendAction &action); void forwardMessages( Data::ResolvedForwardDraft &&draft, - const SendAction &action, + SendAction action, FnMut &&successCallback = nullptr); void shareContact( const QString &phone, diff --git a/Telegram/SourceFiles/data/data_chat_participant_status.cpp b/Telegram/SourceFiles/data/data_chat_participant_status.cpp index feb4349c5..14ae85c26 100644 --- a/Telegram/SourceFiles/data/data_chat_participant_status.cpp +++ b/Telegram/SourceFiles/data/data_chat_participant_status.cpp @@ -17,6 +17,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_user.h" #include "lang/lang_keys.h" #include "main/main_session.h" +#include "settings/settings_credits_graphics.h" #include "storage/storage_account.h" #include "ui/boxes/confirm_box.h" #include "ui/chat/attach/attach_prepare.h" @@ -443,12 +444,30 @@ void ShowSendPaidConfirm( not_null peer, Data::SendError error, Fn confirmed) { + const auto check = [=] { + const auto required = error.paidStars; + if (!required) { + return; + } + const auto done = [=](Settings::SmallBalanceResult result) { + if (result == Settings::SmallBalanceResult::Success + || result == Settings::SmallBalanceResult::Already) { + confirmed(); + } + }; + Settings::MaybeRequestBalanceIncrease( + show, + required, + Settings::SmallBalanceForMessage{ .recipientId = peer->id }, + done); + }; + const auto session = &peer->session(); if (session->local().isPeerTrustedPayForMessage(peer->id)) { - confirmed(); + check(); return; } - //const auto messages = error.paidMessages; + const auto messages = error.paidMessages; const auto stars = error.paidStars; show->showBox(Box([=](not_null box) { const auto trust = std::make_shared>(); @@ -456,24 +475,32 @@ void ShowSendPaidConfirm( if ((*trust)->checked()) { session->local().markPeerTrustedPayForMessage(peer->id); } - confirmed(); + check(); close(); }; Ui::ConfirmBox(box, { .text = tr::lng_payment_confirm_text( tr::now, lt_count, - stars, + stars / messages, lt_name, Ui::Text::Bold(peer->shortName()), Ui::Text::RichLangValue).append(' ').append( tr::lng_payment_confirm_sure( tr::now, lt_count, - stars, + messages, + lt_amount, + tr::lng_payment_confirm_amount( + tr::now, + lt_count, + stars, + Ui::Text::RichLangValue), Ui::Text::RichLangValue)), .confirmed = proceed, - .confirmText = tr::lng_payment_confirm_button(), + .confirmText = tr::lng_payment_confirm_button( + lt_count, + rpl::single(messages * 1.)), .title = tr::lng_payment_confirm_title(), }); const auto skip = st::defaultCheckbox.margin.top();