Simplify paid message button labeling.

This commit is contained in:
John Preston 2025-02-28 14:35:24 +04:00
parent 97b021efaf
commit 8ea7bd4913
7 changed files with 48 additions and 41 deletions

View file

@ -1230,16 +1230,9 @@ object_ptr<Ui::RpWidget> CreatePollBox::setupContent() {
const auto submit = addButton( const auto submit = addButton(
tr::lng_polls_create_button(), tr::lng_polls_create_button(),
[=] { isNormal ? send({}) : schedule(); }); [=] { isNormal ? send({}) : schedule(); });
submit->setText(_starsRequired.value() | rpl::map([=](int stars) { submit->setText(PaidSendButtonText(_starsRequired.value(), isNormal
using namespace Ui; ? tr::lng_polls_create_button()
if (!stars) { : tr::lng_schedule_button()));
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);
}));
const auto sendMenuDetails = [=] { const auto sendMenuDetails = [=] {
collectError(); collectError();
return (*error) ? SendMenu::Details() : _sendMenuDetails(); return (*error) ? SendMenu::Details() : _sendMenuDetails();

View file

@ -740,12 +740,8 @@ void SendFilesBox::refreshButtons() {
? _captionToPeer->starsPerMessageChecked() ? _captionToPeer->starsPerMessageChecked()
: 0; : 0;
if (perMessage > 0) { if (perMessage > 0) {
_send->setText(_messagesCount.value( _send->setText(PaidSendButtonText(_messagesCount.value(
) | rpl::map([=](int count) { ) | rpl::map(rpl::mappers::_1 * perMessage)));
const auto stars = count * perMessage;
return Ui::Text::IconEmoji(&st::boxStarIconEmoji).append(
Lang::FormatCountToShort(stars).string);
}));
} }
if (_sendType == Api::SendType::Normal) { if (_sendType == Api::SendType::Normal) {
SendMenu::SetupMenuAndShortcuts( SendMenu::SetupMenuAndShortcuts(

View file

@ -620,13 +620,9 @@ void ShareBox::createButtons() {
showMenu(send); showMenu(send);
} }
}, send->lifetime()); }, send->lifetime());
send->setText(_starsToSend.value() | rpl::map([=](int stars) { send->setText(PaidSendButtonText(
using namespace Ui; _starsToSend.value(),
return stars tr::lng_share_confirm()));
? Text::IconEmoji(&st::boxStarIconEmoji).append(
Lang::FormatCountToShort(stars).string)
: tr::lng_share_confirm(tr::now, Text::WithEntities);
}));
} else if (_descriptor.copyCallback) { } else if (_descriptor.copyCallback) {
addButton(_copyLinkText.value(), [=] { copyLink(); }); addButton(_copyLinkText.value(), [=] { copyLink(); });
} }

View file

@ -1280,3 +1280,26 @@ void SelectTextInFieldWithMargins(
textCursor.setPosition(selection.to, QTextCursor::KeepAnchor); textCursor.setPosition(selection.to, QTextCursor::KeepAnchor);
field->setTextCursor(textCursor); field->setTextCursor(textCursor);
} }
TextWithEntities PaidSendButtonText(tr::now_t, int stars) {
return Ui::Text::IconEmoji(&st::boxStarIconEmoji).append(
Lang::FormatCountToShort(stars).string);
}
rpl::producer<TextWithEntities> PaidSendButtonText(
rpl::producer<int> stars,
rpl::producer<QString> 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);
});
}

View file

@ -19,6 +19,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include <QtGui/QClipboard> #include <QtGui/QClipboard>
namespace tr {
struct now_t;
} // namespace tr
namespace Main { namespace Main {
class Session; class Session;
class SessionShow; class SessionShow;
@ -169,3 +173,8 @@ private:
void SelectTextInFieldWithMargins( void SelectTextInFieldWithMargins(
not_null<Ui::InputField*> field, not_null<Ui::InputField*> field,
const TextSelection &selection); const TextSelection &selection);
[[nodiscard]] TextWithEntities PaidSendButtonText(tr::now_t, int stars);
[[nodiscard]] rpl::producer<TextWithEntities> PaidSendButtonText(
rpl::producer<int> stars,
rpl::producer<QString> fallback = nullptr);

View file

@ -12,8 +12,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/text/text_utilities.h" #include "ui/text/text_utilities.h"
#include "ui/painter.h" #include "ui/painter.h"
#include "ui/ui_utility.h" #include "ui/ui_utility.h"
#include "styles/style_boxes.h"
#include "styles/style_chat_helpers.h" #include "styles/style_chat_helpers.h"
#include "styles/style_credits.h" // starIconEmoji
namespace Ui { namespace Ui {
namespace { namespace {
@ -54,7 +54,7 @@ void SendButton::setState(State state) {
|| _state.starsToSend != state.starsToSend) { || _state.starsToSend != state.starsToSend) {
_starsToSendText.setMarkedText( _starsToSendText.setMarkedText(
_st.stars.style, _st.stars.style,
Text::IconEmoji(&st::starIconEmoji).append( Text::IconEmoji(&st::boxStarIconEmoji).append(
Lang::FormatCountToShort(state.starsToSend).string), Lang::FormatCountToShort(state.starsToSend).string),
kMarkupTextOptions); kMarkupTextOptions);
} }

View file

@ -2174,14 +2174,9 @@ object_ptr<Ui::BoxContent> PrepareChooseRecipientBox(
onstack({}); onstack({});
} }
}); });
send->setText(state->starsToSend.value( send->setText(PaidSendButtonText(
) | rpl::map([=](int stars) { state->starsToSend.value(),
using namespace Ui; tr::lng_send_button()));
return stars
? Text::IconEmoji(&st::boxStarIconEmoji).append(
Lang::FormatCountToShort(stars).string)
: tr::lng_send_button(tr::now, Text::WithEntities);
}));
} }
box->addButton(tr::lng_cancel(), [=] { box->addButton(tr::lng_cancel(), [=] {
box->closeBox(); box->closeBox();
@ -2729,14 +2724,9 @@ QPointer<Ui::BoxContent> ShowForwardMessagesBox(
showMenu(send); showMenu(send);
} }
}, send->lifetime()); }, send->lifetime());
send->setText(state->starsToSend.value( send->setText(PaidSendButtonText(
) | rpl::map([=](int stars) { state->starsToSend.value(),
using namespace Ui; tr::lng_send_button()));
return stars
? Text::IconEmoji(&st::boxStarIconEmoji).append(
Lang::FormatCountToShort(stars).string)
: tr::lng_send_button(tr::now, Text::WithEntities);
}));
} }
state->box->addButton(tr::lng_cancel(), [=] { state->box->addButton(tr::lng_cancel(), [=] {
state->box->closeBox(); state->box->closeBox();