diff --git a/Telegram/SourceFiles/boxes/create_poll_box.cpp b/Telegram/SourceFiles/boxes/create_poll_box.cpp index 517b1f5e3..fab9731cc 100644 --- a/Telegram/SourceFiles/boxes/create_poll_box.cpp +++ b/Telegram/SourceFiles/boxes/create_poll_box.cpp @@ -1230,16 +1230,9 @@ object_ptr CreatePollBox::setupContent() { const auto submit = addButton( tr::lng_polls_create_button(), [=] { isNormal ? send({}) : schedule(); }); - submit->setText(_starsRequired.value() | rpl::map([=](int stars) { - using namespace Ui; - if (!stars) { - return (isNormal - ? tr::lng_polls_create_button - : tr::lng_schedule_button)(tr::now, Text::WithEntities); - } - return Text::IconEmoji(&st::boxStarIconEmoji).append( - Lang::FormatCountToShort(stars).string); - })); + submit->setText(PaidSendButtonText(_starsRequired.value(), isNormal + ? tr::lng_polls_create_button() + : tr::lng_schedule_button())); const auto sendMenuDetails = [=] { collectError(); return (*error) ? SendMenu::Details() : _sendMenuDetails(); diff --git a/Telegram/SourceFiles/boxes/send_files_box.cpp b/Telegram/SourceFiles/boxes/send_files_box.cpp index b86be64c8..a269f83bd 100644 --- a/Telegram/SourceFiles/boxes/send_files_box.cpp +++ b/Telegram/SourceFiles/boxes/send_files_box.cpp @@ -740,12 +740,8 @@ void SendFilesBox::refreshButtons() { ? _captionToPeer->starsPerMessageChecked() : 0; if (perMessage > 0) { - _send->setText(_messagesCount.value( - ) | rpl::map([=](int count) { - const auto stars = count * perMessage; - return Ui::Text::IconEmoji(&st::boxStarIconEmoji).append( - Lang::FormatCountToShort(stars).string); - })); + _send->setText(PaidSendButtonText(_messagesCount.value( + ) | rpl::map(rpl::mappers::_1 * perMessage))); } if (_sendType == Api::SendType::Normal) { SendMenu::SetupMenuAndShortcuts( diff --git a/Telegram/SourceFiles/boxes/share_box.cpp b/Telegram/SourceFiles/boxes/share_box.cpp index 5912dd312..c262435b7 100644 --- a/Telegram/SourceFiles/boxes/share_box.cpp +++ b/Telegram/SourceFiles/boxes/share_box.cpp @@ -620,13 +620,9 @@ void ShareBox::createButtons() { showMenu(send); } }, send->lifetime()); - send->setText(_starsToSend.value() | rpl::map([=](int stars) { - using namespace Ui; - return stars - ? Text::IconEmoji(&st::boxStarIconEmoji).append( - Lang::FormatCountToShort(stars).string) - : tr::lng_share_confirm(tr::now, Text::WithEntities); - })); + send->setText(PaidSendButtonText( + _starsToSend.value(), + tr::lng_share_confirm())); } else if (_descriptor.copyCallback) { addButton(_copyLinkText.value(), [=] { copyLink(); }); } diff --git a/Telegram/SourceFiles/chat_helpers/message_field.cpp b/Telegram/SourceFiles/chat_helpers/message_field.cpp index 0177e3bfe..617051762 100644 --- a/Telegram/SourceFiles/chat_helpers/message_field.cpp +++ b/Telegram/SourceFiles/chat_helpers/message_field.cpp @@ -1280,3 +1280,26 @@ void SelectTextInFieldWithMargins( textCursor.setPosition(selection.to, QTextCursor::KeepAnchor); field->setTextCursor(textCursor); } + +TextWithEntities PaidSendButtonText(tr::now_t, int stars) { + return Ui::Text::IconEmoji(&st::boxStarIconEmoji).append( + Lang::FormatCountToShort(stars).string); +} + +rpl::producer PaidSendButtonText( + rpl::producer stars, + rpl::producer fallback) { + if (fallback) { + return rpl::combine( + std::move(fallback), + std::move(stars) + ) | rpl::map([=](QString zero, int count) { + return count + ? PaidSendButtonText(tr::now, count) + : TextWithEntities{ zero }; + }); + } + return std::move(stars) | rpl::map([=](int count) { + return PaidSendButtonText(tr::now, count); + }); +} diff --git a/Telegram/SourceFiles/chat_helpers/message_field.h b/Telegram/SourceFiles/chat_helpers/message_field.h index 15e5f04b6..7d97d9332 100644 --- a/Telegram/SourceFiles/chat_helpers/message_field.h +++ b/Telegram/SourceFiles/chat_helpers/message_field.h @@ -19,6 +19,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include +namespace tr { +struct now_t; +} // namespace tr + namespace Main { class Session; class SessionShow; @@ -169,3 +173,8 @@ private: void SelectTextInFieldWithMargins( not_null field, const TextSelection &selection); + +[[nodiscard]] TextWithEntities PaidSendButtonText(tr::now_t, int stars); +[[nodiscard]] rpl::producer PaidSendButtonText( + rpl::producer stars, + rpl::producer fallback = nullptr); diff --git a/Telegram/SourceFiles/ui/controls/send_button.cpp b/Telegram/SourceFiles/ui/controls/send_button.cpp index 5aaa78303..8c692403b 100644 --- a/Telegram/SourceFiles/ui/controls/send_button.cpp +++ b/Telegram/SourceFiles/ui/controls/send_button.cpp @@ -12,8 +12,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/text/text_utilities.h" #include "ui/painter.h" #include "ui/ui_utility.h" +#include "styles/style_boxes.h" #include "styles/style_chat_helpers.h" -#include "styles/style_credits.h" // starIconEmoji namespace Ui { namespace { @@ -54,7 +54,7 @@ void SendButton::setState(State state) { || _state.starsToSend != state.starsToSend) { _starsToSendText.setMarkedText( _st.stars.style, - Text::IconEmoji(&st::starIconEmoji).append( + Text::IconEmoji(&st::boxStarIconEmoji).append( Lang::FormatCountToShort(state.starsToSend).string), kMarkupTextOptions); } diff --git a/Telegram/SourceFiles/window/window_peer_menu.cpp b/Telegram/SourceFiles/window/window_peer_menu.cpp index fd2c666f1..634c3c6f9 100644 --- a/Telegram/SourceFiles/window/window_peer_menu.cpp +++ b/Telegram/SourceFiles/window/window_peer_menu.cpp @@ -2174,14 +2174,9 @@ object_ptr PrepareChooseRecipientBox( onstack({}); } }); - send->setText(state->starsToSend.value( - ) | rpl::map([=](int stars) { - using namespace Ui; - return stars - ? Text::IconEmoji(&st::boxStarIconEmoji).append( - Lang::FormatCountToShort(stars).string) - : tr::lng_send_button(tr::now, Text::WithEntities); - })); + send->setText(PaidSendButtonText( + state->starsToSend.value(), + tr::lng_send_button())); } box->addButton(tr::lng_cancel(), [=] { box->closeBox(); @@ -2729,14 +2724,9 @@ QPointer ShowForwardMessagesBox( showMenu(send); } }, send->lifetime()); - send->setText(state->starsToSend.value( - ) | rpl::map([=](int stars) { - using namespace Ui; - return stars - ? Text::IconEmoji(&st::boxStarIconEmoji).append( - Lang::FormatCountToShort(stars).string) - : tr::lng_send_button(tr::now, Text::WithEntities); - })); + send->setText(PaidSendButtonText( + state->starsToSend.value(), + tr::lng_send_button())); } state->box->addButton(tr::lng_cancel(), [=] { state->box->closeBox();