diff --git a/Telegram/SourceFiles/data/data_media_types.cpp b/Telegram/SourceFiles/data/data_media_types.cpp index bccad1a5e..5fa3c9273 100644 --- a/Telegram/SourceFiles/data/data_media_types.cpp +++ b/Telegram/SourceFiles/data/data_media_types.cpp @@ -80,19 +80,20 @@ constexpr auto kFastRevokeRestriction = 24 * 60 * TimeId(60); [[nodiscard]] Invoice ComputeInvoiceData( not_null item, const MTPDmessageMediaInvoice &data) { - auto result = Invoice(); - result.isTest = data.is_test(); - result.amount = data.vtotal_amount().v; - result.currency = qs(data.vcurrency()); - result.description = qs(data.vdescription()); - result.title = TextUtilities::SingleLine(qs(data.vtitle())); - result.receiptMsgId = data.vreceipt_msg_id().value_or_empty(); - if (const auto photo = data.vphoto()) { - result.photo = item->history()->owner().photoFromWeb( - *photo, - ImageLocation()); - } - return result; + return { + .receiptMsgId = data.vreceipt_msg_id().value_or_empty(), + .amount = data.vtotal_amount().v, + .currency = qs(data.vcurrency()), + .title = TextUtilities::SingleLine(qs(data.vtitle())), + .description = qs(data.vdescription()), + .photo = (data.vphoto() + ? item->history()->owner().photoFromWeb( + *data.vphoto(), + ImageLocation()) + : nullptr), + .isMultipleAllowed = item->history()->isChannel(), // #TODO payments + .isTest = data.is_test(), + }; } [[nodiscard]] QString WithCaptionDialogsText( @@ -188,6 +189,10 @@ PollData *Media::poll() const { return nullptr; } +void Media::setInvoiceReceiptId(MsgId id) { + Unexpected("Media::setInvoiceReceiptId."); +} + bool Media::uploading() const { return false; } @@ -1190,6 +1195,11 @@ const Invoice *MediaInvoice::invoice() const { return &_invoice; } +void MediaInvoice::setInvoiceReceiptId(MsgId id) { + _invoice.receiptMsgId = id; + parent()->checkBuyButton(); +} + bool MediaInvoice::hasReplyPreview() const { if (const auto photo = _invoice.photo) { return !photo->isNull(); diff --git a/Telegram/SourceFiles/data/data_media_types.h b/Telegram/SourceFiles/data/data_media_types.h index b99cdd065..edf719f9e 100644 --- a/Telegram/SourceFiles/data/data_media_types.h +++ b/Telegram/SourceFiles/data/data_media_types.h @@ -62,6 +62,7 @@ struct Invoice { QString title; QString description; PhotoData *photo = nullptr; + bool isMultipleAllowed = false; bool isTest = false; }; @@ -84,6 +85,8 @@ public: virtual Data::CloudImage *location() const; virtual PollData *poll() const; + virtual void setInvoiceReceiptId(MsgId id); + virtual bool uploading() const; virtual Storage::SharedMediaTypesMask sharedMediaTypes() const; virtual bool canBeGrouped() const; @@ -381,6 +384,7 @@ public: std::unique_ptr clone(not_null parent) override; const Invoice *invoice() const override; + void setInvoiceReceiptId(MsgId id) override; bool hasReplyPreview() const override; Image *replyPreview() const override; diff --git a/Telegram/SourceFiles/history/history_item.h b/Telegram/SourceFiles/history/history_item.h index 960bb0f1d..b9517f2ae 100644 --- a/Telegram/SourceFiles/history/history_item.h +++ b/Telegram/SourceFiles/history/history_item.h @@ -76,6 +76,8 @@ public: virtual MsgId dependencyMsgId() const { return 0; } + virtual void checkBuyButton() { + } [[nodiscard]] virtual bool notificationReady() const { return true; } diff --git a/Telegram/SourceFiles/history/history_message.cpp b/Telegram/SourceFiles/history/history_message.cpp index c79bc2ae6..3165d328b 100644 --- a/Telegram/SourceFiles/history/history_message.cpp +++ b/Telegram/SourceFiles/history/history_message.cpp @@ -1215,6 +1215,10 @@ void HistoryMessage::returnSavedMedia() { void HistoryMessage::setMedia(const MTPMessageMedia &media) { _media = CreateMedia(this, media); + checkBuyButton(); +} + +void HistoryMessage::checkBuyButton() { if (const auto invoice = _media ? _media->invoice() : nullptr) { if (invoice->receiptMsgId) { replaceBuyWithReceiptInMarkup(); @@ -1341,11 +1345,18 @@ std::unique_ptr HistoryMessage::CreateMedia( } void HistoryMessage::replaceBuyWithReceiptInMarkup() { - if (auto markup = inlineReplyMarkup()) { + if (const auto markup = inlineReplyMarkup()) { for (auto &row : markup->rows) { for (auto &button : row) { if (button.type == HistoryMessageMarkupButton::Type::Buy) { - button.text = tr::lng_payments_receipt_button(tr::now); + const auto receipt = tr::lng_payments_receipt_button(tr::now); + if (button.text != receipt) { + button.text = receipt; + if (markup->inlineKeyboard) { + markup->inlineKeyboard = nullptr; + history()->owner().requestItemResize(this); + } + } } } } diff --git a/Telegram/SourceFiles/history/history_message.h b/Telegram/SourceFiles/history/history_message.h index 36e3ac653..7959087c3 100644 --- a/Telegram/SourceFiles/history/history_message.h +++ b/Telegram/SourceFiles/history/history_message.h @@ -118,6 +118,7 @@ public: void refreshSentMedia(const MTPMessageMedia *media); void returnSavedMedia() override; void setMedia(const MTPMessageMedia &media); + void checkBuyButton() override; [[nodiscard]] static std::unique_ptr CreateMedia( not_null item, const MTPMessageMedia &media); diff --git a/Telegram/SourceFiles/history/history_service.cpp b/Telegram/SourceFiles/history/history_service.cpp index 132b3e3c8..03912ae23 100644 --- a/Telegram/SourceFiles/history/history_service.cpp +++ b/Telegram/SourceFiles/history/history_service.cpp @@ -765,6 +765,10 @@ HistoryService::PreparedText HistoryService::preparePaymentSentText() { if (payment->msg) { if (const auto media = payment->msg->media()) { if (const auto invoice = media->invoice()) { + if (!invoice->isMultipleAllowed + && !invoice->receiptMsgId) { + media->setInvoiceReceiptId(id); + } return textcmdLink(1, invoice->title); } }