mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +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(
|
[[nodiscard]] Invoice ComputeInvoiceData(
|
||||||
not_null<HistoryItem*> item,
|
not_null<HistoryItem*> item,
|
||||||
const MTPDmessageMediaInvoice &data) {
|
const MTPDmessageMediaInvoice &data) {
|
||||||
auto result = Invoice();
|
return {
|
||||||
result.isTest = data.is_test();
|
.receiptMsgId = data.vreceipt_msg_id().value_or_empty(),
|
||||||
result.amount = data.vtotal_amount().v;
|
.amount = data.vtotal_amount().v,
|
||||||
result.currency = qs(data.vcurrency());
|
.currency = qs(data.vcurrency()),
|
||||||
result.description = qs(data.vdescription());
|
.title = TextUtilities::SingleLine(qs(data.vtitle())),
|
||||||
result.title = TextUtilities::SingleLine(qs(data.vtitle()));
|
.description = qs(data.vdescription()),
|
||||||
result.receiptMsgId = data.vreceipt_msg_id().value_or_empty();
|
.photo = (data.vphoto()
|
||||||
if (const auto photo = data.vphoto()) {
|
? item->history()->owner().photoFromWeb(
|
||||||
result.photo = item->history()->owner().photoFromWeb(
|
*data.vphoto(),
|
||||||
*photo,
|
ImageLocation())
|
||||||
ImageLocation());
|
: nullptr),
|
||||||
}
|
.isMultipleAllowed = item->history()->isChannel(), // #TODO payments
|
||||||
return result;
|
.isTest = data.is_test(),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] QString WithCaptionDialogsText(
|
[[nodiscard]] QString WithCaptionDialogsText(
|
||||||
|
@ -188,6 +189,10 @@ PollData *Media::poll() const {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Media::setInvoiceReceiptId(MsgId id) {
|
||||||
|
Unexpected("Media::setInvoiceReceiptId.");
|
||||||
|
}
|
||||||
|
|
||||||
bool Media::uploading() const {
|
bool Media::uploading() const {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1190,6 +1195,11 @@ const Invoice *MediaInvoice::invoice() const {
|
||||||
return &_invoice;
|
return &_invoice;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MediaInvoice::setInvoiceReceiptId(MsgId id) {
|
||||||
|
_invoice.receiptMsgId = id;
|
||||||
|
parent()->checkBuyButton();
|
||||||
|
}
|
||||||
|
|
||||||
bool MediaInvoice::hasReplyPreview() const {
|
bool MediaInvoice::hasReplyPreview() const {
|
||||||
if (const auto photo = _invoice.photo) {
|
if (const auto photo = _invoice.photo) {
|
||||||
return !photo->isNull();
|
return !photo->isNull();
|
||||||
|
|
|
@ -62,6 +62,7 @@ struct Invoice {
|
||||||
QString title;
|
QString title;
|
||||||
QString description;
|
QString description;
|
||||||
PhotoData *photo = nullptr;
|
PhotoData *photo = nullptr;
|
||||||
|
bool isMultipleAllowed = false;
|
||||||
bool isTest = false;
|
bool isTest = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -84,6 +85,8 @@ public:
|
||||||
virtual Data::CloudImage *location() const;
|
virtual Data::CloudImage *location() const;
|
||||||
virtual PollData *poll() const;
|
virtual PollData *poll() const;
|
||||||
|
|
||||||
|
virtual void setInvoiceReceiptId(MsgId id);
|
||||||
|
|
||||||
virtual bool uploading() const;
|
virtual bool uploading() const;
|
||||||
virtual Storage::SharedMediaTypesMask sharedMediaTypes() const;
|
virtual Storage::SharedMediaTypesMask sharedMediaTypes() const;
|
||||||
virtual bool canBeGrouped() const;
|
virtual bool canBeGrouped() const;
|
||||||
|
@ -381,6 +384,7 @@ public:
|
||||||
std::unique_ptr<Media> clone(not_null<HistoryItem*> parent) override;
|
std::unique_ptr<Media> clone(not_null<HistoryItem*> parent) override;
|
||||||
|
|
||||||
const Invoice *invoice() const override;
|
const Invoice *invoice() const override;
|
||||||
|
void setInvoiceReceiptId(MsgId id) override;
|
||||||
|
|
||||||
bool hasReplyPreview() const override;
|
bool hasReplyPreview() const override;
|
||||||
Image *replyPreview() const override;
|
Image *replyPreview() const override;
|
||||||
|
|
|
@ -76,6 +76,8 @@ public:
|
||||||
virtual MsgId dependencyMsgId() const {
|
virtual MsgId dependencyMsgId() const {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
virtual void checkBuyButton() {
|
||||||
|
}
|
||||||
[[nodiscard]] virtual bool notificationReady() const {
|
[[nodiscard]] virtual bool notificationReady() const {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1215,6 +1215,10 @@ void HistoryMessage::returnSavedMedia() {
|
||||||
|
|
||||||
void HistoryMessage::setMedia(const MTPMessageMedia &media) {
|
void HistoryMessage::setMedia(const MTPMessageMedia &media) {
|
||||||
_media = CreateMedia(this, media);
|
_media = CreateMedia(this, media);
|
||||||
|
checkBuyButton();
|
||||||
|
}
|
||||||
|
|
||||||
|
void HistoryMessage::checkBuyButton() {
|
||||||
if (const auto invoice = _media ? _media->invoice() : nullptr) {
|
if (const auto invoice = _media ? _media->invoice() : nullptr) {
|
||||||
if (invoice->receiptMsgId) {
|
if (invoice->receiptMsgId) {
|
||||||
replaceBuyWithReceiptInMarkup();
|
replaceBuyWithReceiptInMarkup();
|
||||||
|
@ -1341,11 +1345,18 @@ std::unique_ptr<Data::Media> HistoryMessage::CreateMedia(
|
||||||
}
|
}
|
||||||
|
|
||||||
void HistoryMessage::replaceBuyWithReceiptInMarkup() {
|
void HistoryMessage::replaceBuyWithReceiptInMarkup() {
|
||||||
if (auto markup = inlineReplyMarkup()) {
|
if (const auto markup = inlineReplyMarkup()) {
|
||||||
for (auto &row : markup->rows) {
|
for (auto &row : markup->rows) {
|
||||||
for (auto &button : row) {
|
for (auto &button : row) {
|
||||||
if (button.type == HistoryMessageMarkupButton::Type::Buy) {
|
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 refreshSentMedia(const MTPMessageMedia *media);
|
||||||
void returnSavedMedia() override;
|
void returnSavedMedia() override;
|
||||||
void setMedia(const MTPMessageMedia &media);
|
void setMedia(const MTPMessageMedia &media);
|
||||||
|
void checkBuyButton() override;
|
||||||
[[nodiscard]] static std::unique_ptr<Data::Media> CreateMedia(
|
[[nodiscard]] static std::unique_ptr<Data::Media> CreateMedia(
|
||||||
not_null<HistoryMessage*> item,
|
not_null<HistoryMessage*> item,
|
||||||
const MTPMessageMedia &media);
|
const MTPMessageMedia &media);
|
||||||
|
|
|
@ -765,6 +765,10 @@ HistoryService::PreparedText HistoryService::preparePaymentSentText() {
|
||||||
if (payment->msg) {
|
if (payment->msg) {
|
||||||
if (const auto media = payment->msg->media()) {
|
if (const auto media = payment->msg->media()) {
|
||||||
if (const auto invoice = media->invoice()) {
|
if (const auto invoice = media->invoice()) {
|
||||||
|
if (!invoice->isMultipleAllowed
|
||||||
|
&& !invoice->receiptMsgId) {
|
||||||
|
media->setInvoiceReceiptId(id);
|
||||||
|
}
|
||||||
return textcmdLink(1, invoice->title);
|
return textcmdLink(1, invoice->title);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue