diff --git a/Telegram/SourceFiles/boxes/send_credits_box.cpp b/Telegram/SourceFiles/boxes/send_credits_box.cpp index 6e75f5c5c..ed48b04ff 100644 --- a/Telegram/SourceFiles/boxes/send_credits_box.cpp +++ b/Telegram/SourceFiles/boxes/send_credits_box.cpp @@ -79,10 +79,14 @@ struct PaidMediaData { } } + const auto sender = item->originalSender(); + const auto broadcast = (sender && sender->isBroadcast()) + ? sender + : message->peer.get(); return { .invoice = invoice, .item = item, - .peer = message->peer, + .peer = broadcast, .photos = photos, .videos = videos, }; @@ -270,21 +274,11 @@ void SendCreditsBox( loadingAnimation->showOn(state->confirmButtonBusy.value()); } { - const auto emojiMargin = QMargins( - 0, - -st::moderateBoxExpandInnerSkip, - 0, - 0); - const auto buttonEmoji = Ui::Text::SingleCustomEmoji( - session->data().customEmojiManager().registerInternalEmoji( - st::settingsPremiumIconStar, - emojiMargin, - true)); auto buttonText = tr::lng_credits_box_out_confirm( lt_count, rpl::single(form->invoice.amount) | tr::to_count(), lt_emoji, - rpl::single(buttonEmoji), + rpl::single(CreditsEmoji(session)), Ui::Text::RichLangValue); const auto buttonLabel = Ui::CreateChild( button, @@ -359,4 +353,12 @@ void SendCreditsBox( } } +TextWithEntities CreditsEmoji(not_null session) { + return Ui::Text::SingleCustomEmoji( + session->data().customEmojiManager().registerInternalEmoji( + st::settingsPremiumIconStar, + QMargins{ 0, -st::moderateBoxExpandInnerSkip, 0, 0 }, + true)); +} + } // namespace Ui diff --git a/Telegram/SourceFiles/boxes/send_credits_box.h b/Telegram/SourceFiles/boxes/send_credits_box.h index 25ceb1d56..71675c720 100644 --- a/Telegram/SourceFiles/boxes/send_credits_box.h +++ b/Telegram/SourceFiles/boxes/send_credits_box.h @@ -9,6 +9,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL class HistoryItem; +namespace Main { +class Session; +} // namespace Main + namespace Payments { struct CreditsFormData; } // namespace Payments @@ -22,4 +26,7 @@ void SendCreditsBox( std::shared_ptr data, Fn sent); +[[nodiscard]] TextWithEntities CreditsEmoji( + not_null session); + } // namespace Ui diff --git a/Telegram/SourceFiles/boxes/send_files_box.cpp b/Telegram/SourceFiles/boxes/send_files_box.cpp index ac27ddb0f..7cf1536c3 100644 --- a/Telegram/SourceFiles/boxes/send_files_box.cpp +++ b/Telegram/SourceFiles/boxes/send_files_box.cpp @@ -25,10 +25,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/view/controls/history_view_characters_limit.h" #include "history/view/history_view_schedule_box.h" #include "core/mime_type.h" +#include "core/ui_integration.h" #include "base/event_filter.h" #include "base/call_delayed.h" #include "boxes/premium_limits_box.h" #include "boxes/premium_preview_box.h" +#include "boxes/send_credits_box.h" #include "ui/effects/scroll_content_shadow.h" #include "ui/widgets/checkbox.h" #include "ui/widgets/scroll_area.h" @@ -749,13 +751,26 @@ void SendFilesBox::refreshPriceTag() { p.drawRoundedRect(raw->rect(), radius, radius); }, raw->lifetime()); + const auto session = &_show->session(); auto price = _price.value() | rpl::map([=](uint64 amount) { - return QChar(0x2B50) + Lang::FormatCountDecimal(amount); + auto result = Ui::Text::Colorized(Ui::CreditsEmoji(session)); + result.append(Lang::FormatCountDecimal(amount)); + return result; }); + auto text = tr::lng_paid_price( + lt_price, + std::move(price), + Ui::Text::WithEntities); const auto label = Ui::CreateChild( raw, - tr::lng_paid_price(lt_price, std::move(price)), + QString(), st::paidTagLabel); + std::move(text) | rpl::start_with_next([=](TextWithEntities &&text) { + label->setMarkedText(text, Core::MarkedTextContext{ + .session = session, + .customEmojiRepaint = [=] { label->update(); }, + }); + }, label->lifetime()); label->show(); label->sizeValue() | rpl::start_with_next([=](QSize size) { const auto inner = QRect(QPoint(), size); @@ -1633,11 +1648,16 @@ void SendFilesBox::send( auto caption = (_caption && !_caption->isHidden()) ? _caption->getTextWithAppliedMarkdown() : TextWithTags(); - options.invertCaption = _invertCaption; - options.price = hasPrice() ? _price.current() : 0; if (!validateLength(caption.text)) { return; } + options.invertCaption = _invertCaption; + options.price = hasPrice() ? _price.current() : 0; + if (options.price > 0) { + for (auto &file : _list.files) { + file.spoiler = false; + } + } _confirmedCallback( std::move(_list), _sendWay.current(), diff --git a/Telegram/SourceFiles/chat_helpers/chat_helpers.style b/Telegram/SourceFiles/chat_helpers/chat_helpers.style index b268377f9..0b1290dc8 100644 --- a/Telegram/SourceFiles/chat_helpers/chat_helpers.style +++ b/Telegram/SourceFiles/chat_helpers/chat_helpers.style @@ -1417,6 +1417,9 @@ paidAmountAbout: FlatLabel(defaultFlatLabel) { } paidTagLabel: FlatLabel(defaultFlatLabel) { textFg: radialFg; + palette: TextPalette(defaultTextPalette) { + linkFg: creditsBg1; + } style: semiboldTextStyle; } paidTagPadding: margins(16px, 6px, 16px, 6px); diff --git a/Telegram/SourceFiles/history/view/media/history_view_media_common.cpp b/Telegram/SourceFiles/history/view/media/history_view_media_common.cpp index e5c01ba70..dd32fa00f 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_media_common.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_media_common.cpp @@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "api/api_views.h" #include "apiwrap.h" #include "ui/text/format_values.h" +#include "ui/text/text_utilities.h" #include "ui/painter.h" #include "core/click_handler_types.h" #include "data/data_document.h" @@ -25,6 +26,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/view/media/history_view_theme_document.h" #include "history/history_item.h" #include "history/history.h" +#include "lang/lang_keys.h" #include "main/main_session.h" #include "mainwindow.h" #include "media/streaming/media_streaming_utility.h" @@ -34,6 +36,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "styles/style_chat.h" namespace HistoryView { +namespace { + +constexpr auto kMediaUnlockedTooltipDuration = 5 * crl::time(1000); + +} // namespace void PaintInterpolatedIcon( QPainter &p, @@ -191,10 +198,36 @@ QSize CountPhotoMediaSize( media.scaled(media.width(), newWidth, Qt::KeepAspectRatio)); } +void ShowPaidMediaUnlockedToast( + not_null controller, + not_null item) { + const auto media = item->media(); + const auto invoice = media ? media->invoice() : nullptr; + if (!invoice || !invoice->isPaidMedia) { + return; + } + const auto sender = item->originalSender(); + const auto broadcast = (sender && sender->isBroadcast()) + ? sender + : item->history()->peer.get(); + auto text = tr::lng_credits_media_done_title( + tr::now, + Ui::Text::Bold + ).append('\n').append(tr::lng_credits_media_done_text( + tr::now, + lt_count, + invoice->amount, + lt_chat, + Ui::Text::Bold(broadcast->name()), + Ui::Text::RichLangValue)); + controller->showToast(std::move(text), kMediaUnlockedTooltipDuration); +} + ClickHandlerPtr MakePaidMediaLink(not_null item) { return std::make_shared([=](ClickContext context) { const auto my = context.other.value(); const auto controller = my.sessionWindow.get(); + const auto weak = my.sessionWindow; const auto itemId = item->fullId(); const auto session = &item->history()->session(); using Result = Payments::CheckoutResult; @@ -203,6 +236,9 @@ ClickHandlerPtr MakePaidMediaLink(not_null item) { return; } else if (const auto item = session->data().message(itemId)) { session->api().views().pollExtendedMedia(item, true); + if (const auto strong = weak.get()) { + ShowPaidMediaUnlockedToast(strong, item); + } } }); Payments::CheckoutProcess::Start( diff --git a/Telegram/SourceFiles/history/view/media/history_view_photo.cpp b/Telegram/SourceFiles/history/view/media/history_view_photo.cpp index e3f6c91c5..6d634073a 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_photo.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_photo.cpp @@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "history/view/media/history_view_photo.h" +#include "boxes/send_credits_box.h" #include "history/history_item_components.h" #include "history/history_item.h" #include "history/history.h" @@ -24,6 +25,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/image/image.h" #include "ui/effects/spoiler_mess.h" #include "ui/chat/chat_style.h" +#include "ui/text/text_utilities.h" #include "ui/grouped_layout.h" #include "ui/cached_round_corners.h" #include "ui/painter.h" @@ -38,6 +40,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_auto_download.h" #include "data/data_web_page.h" #include "core/application.h" +#include "core/ui_integration.h" #include "styles/style_chat.h" #include "styles/style_chat_helpers.h" @@ -65,6 +68,7 @@ struct Photo::PriceTag { QImage cache; QColor darken; QColor fg; + QColor star; ClickHandlerPtr link; }; @@ -438,9 +442,11 @@ void Photo::drawPriceTag( const auto st = context.st; const auto darken = st->msgDateImgBg()->c; const auto fg = st->msgDateImgFg()->c; + const auto star = st->creditsBg1()->c; if (_priceTag->cache.isNull() || _priceTag->darken != darken - || _priceTag->fg != fg) { + || _priceTag->fg != fg + || _priceTag->star != star) { auto bg = generateBackground(); if (bg.isNull()) { bg = QImage(2, 2, QImage::Format_ARGB32_Premultiplied); @@ -448,12 +454,21 @@ void Photo::drawPriceTag( } auto text = Ui::Text::String(); - text.setText( + const auto session = &history()->session(); + auto price = Ui::Text::Colorized(Ui::CreditsEmoji(session)); + price.append(Lang::FormatCountDecimal(_priceTag->price)); + text.setMarkedText( st::semiboldTextStyle, tr::lng_paid_price( tr::now, lt_price, - QChar(0x2B50) + Lang::FormatCountDecimal(_priceTag->price))); + price, + Ui::Text::WithEntities), + kMarkupTextOptions, + Core::MarkedTextContext{ + .session = session, + .customEmojiRepaint = [] {}, + }); const auto width = text.maxWidth(); const auto inner = QRect(0, 0, width, text.minHeight()); const auto outer = inner.marginsAdded(st::paidTagPadding); @@ -476,6 +491,7 @@ void Photo::drawPriceTag( bg); p.fillRect(QRect(QPoint(), size), darken); p.setPen(fg); + p.setTextPalette(st->priceTagTextPalette()); text.draw(p, -outer.x(), -outer.y(), width); p.end(); diff --git a/Telegram/SourceFiles/ui/chat/chat.style b/Telegram/SourceFiles/ui/chat/chat.style index e4ff33434..a817f5dfe 100644 --- a/Telegram/SourceFiles/ui/chat/chat.style +++ b/Telegram/SourceFiles/ui/chat/chat.style @@ -106,6 +106,9 @@ outTextPaletteSelected: TextPalette(outTextPalette) { monoFg: msgOutMonoFgSelected; spoilerFg: msgOutDateFgSelected; } +priceTagTextPalette: TextPalette(defaultTextPalette) { + linkFg: creditsBg1; +} fwdTextUserpicPadding: margins(0px, 1px, 3px, 0px); fwdTextStyle: TextStyle(semiboldTextStyle) { linkUnderline: kLinkUnderlineNever; diff --git a/Telegram/SourceFiles/ui/chat/chat_style.cpp b/Telegram/SourceFiles/ui/chat/chat_style.cpp index 56f236481..0c50f77b8 100644 --- a/Telegram/SourceFiles/ui/chat/chat_style.cpp +++ b/Telegram/SourceFiles/ui/chat/chat_style.cpp @@ -171,6 +171,7 @@ ChatStyle::ChatStyle(rpl::producer colorIndices) { make(_historyPsaForwardPalette, st::historyPsaForwardPalette); make(_imgReplyTextPalette, st::imgReplyTextPalette); make(_serviceTextPalette, st::serviceTextPalette); + make(_priceTagTextPalette, st::priceTagTextPalette); make(_historyRepliesInvertedIcon, st::historyRepliesInvertedIcon); make(_historyViewsInvertedIcon, st::historyViewsInvertedIcon); make(_historyViewsSendingIcon, st::historyViewsSendingIcon); diff --git a/Telegram/SourceFiles/ui/chat/chat_style.h b/Telegram/SourceFiles/ui/chat/chat_style.h index f7499a2d0..a00fe941a 100644 --- a/Telegram/SourceFiles/ui/chat/chat_style.h +++ b/Telegram/SourceFiles/ui/chat/chat_style.h @@ -349,6 +349,9 @@ public: [[nodiscard]] const style::TextPalette &serviceTextPalette() const { return _serviceTextPalette; } + [[nodiscard]] const style::TextPalette &priceTagTextPalette() const { + return _priceTagTextPalette; + } [[nodiscard]] const style::icon &historyRepliesInvertedIcon() const { return _historyRepliesInvertedIcon; } @@ -516,6 +519,7 @@ private: style::TextPalette _historyPsaForwardPalette; style::TextPalette _imgReplyTextPalette; style::TextPalette _serviceTextPalette; + style::TextPalette _priceTagTextPalette; style::icon _historyRepliesInvertedIcon = { Qt::Uninitialized }; style::icon _historyViewsInvertedIcon = { Qt::Uninitialized }; style::icon _historyViewsSendingIcon = { Qt::Uninitialized };