diff --git a/Telegram/SourceFiles/history/history.cpp b/Telegram/SourceFiles/history/history.cpp index 754791e80..35643637e 100644 --- a/Telegram/SourceFiles/history/history.cpp +++ b/Telegram/SourceFiles/history/history.cpp @@ -17,6 +17,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/history_item_helpers.h" #include "history/history_translation.h" #include "history/history_unread_things.h" +#include "core/ui_integration.h" #include "dialogs/ui/dialogs_layout.h" #include "data/business/data_shortcut_messages.h" #include "data/components/scheduled_messages.h" @@ -1128,14 +1129,23 @@ void History::applyServiceChanges( } if (paid) { // Toast on a current active window. + const auto context = [=](not_null toast) { + return Core::MarkedTextContext{ + .session = &session(), + .customEmojiRepaint = [=] { toast->update(); }, + }; + }; Ui::Toast::Show({ .text = tr::lng_payments_success( tr::now, lt_amount, - Ui::Text::Bold(payment->amount), + Ui::Text::Wrapped( + payment->amount, + EntityType::Bold), lt_title, Ui::Text::Bold(paid->title), Ui::Text::WithEntities), + .textContext = context, }); } } diff --git a/Telegram/SourceFiles/history/history_item.cpp b/Telegram/SourceFiles/history/history_item.cpp index 9cee2262e..4a8a413cc 100644 --- a/Telegram/SourceFiles/history/history_item.cpp +++ b/Telegram/SourceFiles/history/history_item.cpp @@ -39,6 +39,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/click_handler_types.h" #include "base/unixtime.h" #include "base/timer_rpl.h" +#include "boxes/send_credits_box.h" #include "api/api_text_entities.h" #include "api/api_updates.h" #include "data/components/scheduled_messages.h" @@ -137,6 +138,17 @@ template return fields; } +[[nodiscard]] TextWithEntities AmountAndStarCurrency( + not_null session, + int64 amount, + const QString ¤cy) { + if (currency == Ui::kCreditsCurrency) { + return Ui::CreditsEmojiSmall(session).append( + Lang::FormatCountDecimal(std::abs(amount))); + } + return { Ui::FillAmountAndCurrency(amount, currency) }; +} + } // namespace void HistoryItem::HistoryItem::Destroyer::operator()(HistoryItem *value) { @@ -3957,7 +3969,10 @@ void HistoryItem::createServiceFromMtp(const MTPDmessageService &message) { payment->recurringInit = data.is_recurring_init(); payment->recurringUsed = data.is_recurring_used(); payment->isCreditsCurrency = (currency == Ui::kCreditsCurrency); - payment->amount = Ui::FillAmountAndCurrency(amount, currency); + payment->amount = AmountAndStarCurrency( + &_history->session(), + amount, + currency); payment->invoiceLink = std::make_shared([=]( ClickContext context) { using namespace Payments; @@ -4692,7 +4707,7 @@ void HistoryItem::setServiceMessageByAction(const MTPmessageAction &action) { lt_user, Ui::Text::Link(peer->name(), 1), // Link 1. lt_cost, - { Ui::FillAmountAndCurrency(amount, currency) }, + AmountAndStarCurrency(&peer->session(), amount, currency), Ui::Text::WithEntities); return result; }; @@ -4905,9 +4920,10 @@ void HistoryItem::setServiceMessageByAction(const MTPmessageAction &action) { lt_user, Ui::Text::Link(peer->name(), 1), // Link 1. lt_cost, - { Ui::FillAmountAndCurrency( + AmountAndStarCurrency( + &_history->session(), action.vamount().value_or_empty(), - qs(action.vcurrency().value_or_empty())) }, + qs(action.vcurrency().value_or_empty())), Ui::Text::WithEntities); } @@ -4957,7 +4973,6 @@ void HistoryItem::setServiceMessageByAction(const MTPmessageAction &action) { Ui::Text::WithEntities); return result; }; - auto preparePaymentRefunded = [&](const MTPDmessageActionPaymentRefunded &action) { auto result = PreparedServiceText(); const auto refund = Get(); @@ -4972,7 +4987,7 @@ void HistoryItem::setServiceMessageByAction(const MTPmessageAction &action) { lt_peer, Ui::Text::Link(refund->peer->name(), 1), // Link 1. lt_amount, - { Ui::FillAmountAndCurrency(amount, currency) }, + AmountAndStarCurrency(&_history->session(), amount, currency), Ui::Text::WithEntities); return result; }; @@ -4993,7 +5008,10 @@ void HistoryItem::setServiceMessageByAction(const MTPmessageAction &action) { lt_user, Ui::Text::Link(peer->name(), 1), // Link 1. lt_cost, - { Ui::FillAmountAndCurrency(amount, currency) }, + AmountAndStarCurrency( + &_history->session(), + amount, + currency), Ui::Text::WithEntities); return result; }; @@ -5412,7 +5430,7 @@ PreparedServiceText HistoryItem::preparePaymentSentText() { result.text = tr::lng_action_payment_used_recurring( tr::now, lt_amount, - { .text = payment->amount }, + payment->amount, Ui::Text::WithEntities); } else { result.text = (payment->recurringInit @@ -5420,7 +5438,7 @@ PreparedServiceText HistoryItem::preparePaymentSentText() { : tr::lng_action_payment_done)( tr::now, lt_amount, - { .text = payment->amount }, + payment->amount, lt_user, { .text = _history->peer->name() }, Ui::Text::WithEntities); @@ -5431,7 +5449,7 @@ PreparedServiceText HistoryItem::preparePaymentSentText() { : tr::lng_action_payment_done_for)( tr::now, lt_amount, - { .text = payment->amount }, + payment->amount, lt_user, { .text = _history->peer->name() }, lt_invoice, diff --git a/Telegram/SourceFiles/history/history_item_components.h b/Telegram/SourceFiles/history/history_item_components.h index 7e9fb6396..1a5e14014 100644 --- a/Telegram/SourceFiles/history/history_item_components.h +++ b/Telegram/SourceFiles/history/history_item_components.h @@ -649,7 +649,7 @@ struct HistoryServicePayment : public RuntimeComponent , public HistoryServiceDependentData { QString slug; - QString amount; + TextWithEntities amount; ClickHandlerPtr invoiceLink; bool recurringInit = false; bool recurringUsed = false; diff --git a/Telegram/SourceFiles/ui/text/format_values.cpp b/Telegram/SourceFiles/ui/text/format_values.cpp index d95062313..7ebd961f3 100644 --- a/Telegram/SourceFiles/ui/text/format_values.cpp +++ b/Telegram/SourceFiles/ui/text/format_values.cpp @@ -146,11 +146,11 @@ QString FillAmountAndCurrency( // std::abs doesn't work on that one :/ Expects(amount != std::numeric_limits::min()); - const auto rule = LookupCurrencyRule(currency); if (currency == kCreditsCurrency) { return QChar(0x2B50) + Lang::FormatCountDecimal(std::abs(amount)); } + const auto rule = LookupCurrencyRule(currency); const auto prefix = (amount < 0) ? QString::fromUtf8("\xe2\x88\x92") : QString();