mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-19 07:37:11 +02:00
Update button on paid invoices to 'Receipt'.
This commit is contained in:
parent
889e0dc035
commit
e6ba6050e7
6 changed files with 47 additions and 15 deletions
|
@ -80,19 +80,20 @@ constexpr auto kFastRevokeRestriction = 24 * 60 * TimeId(60);
|
|||
[[nodiscard]] Invoice ComputeInvoiceData(
|
||||
not_null<HistoryItem*> 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();
|
||||
|
|
|
@ -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<Media> clone(not_null<HistoryItem*> parent) override;
|
||||
|
||||
const Invoice *invoice() const override;
|
||||
void setInvoiceReceiptId(MsgId id) override;
|
||||
|
||||
bool hasReplyPreview() const override;
|
||||
Image *replyPreview() const override;
|
||||
|
|
|
@ -76,6 +76,8 @@ public:
|
|||
virtual MsgId dependencyMsgId() const {
|
||||
return 0;
|
||||
}
|
||||
virtual void checkBuyButton() {
|
||||
}
|
||||
[[nodiscard]] virtual bool notificationReady() const {
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -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<Data::Media> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<Data::Media> CreateMedia(
|
||||
not_null<HistoryMessage*> item,
|
||||
const MTPMessageMedia &media);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue