Parse link entities into Data::Invoice.

This commit is contained in:
John Preston 2022-06-21 19:16:00 +04:00
parent 9d7060c24a
commit ff55918da0
6 changed files with 16 additions and 13 deletions

View File

@ -31,6 +31,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/image/image.h" #include "ui/image/image.h"
#include "ui/text/format_song_document_name.h" #include "ui/text/format_song_document_name.h"
#include "ui/text/format_values.h" #include "ui/text/format_values.h"
#include "ui/text/text_entity.h"
#include "ui/text/text_options.h" #include "ui/text/text_options.h"
#include "ui/text/text_utilities.h" #include "ui/text/text_utilities.h"
#include "ui/toast/toast.h" #include "ui/toast/toast.h"
@ -246,12 +247,15 @@ TextForMimeData WithCaptionClipboardText(
Invoice ComputeInvoiceData( Invoice ComputeInvoiceData(
not_null<HistoryItem*> item, not_null<HistoryItem*> item,
const MTPDmessageMediaInvoice &data) { const MTPDmessageMediaInvoice &data) {
auto description = qs(data.vdescription());
return { return {
.receiptMsgId = data.vreceipt_msg_id().value_or_empty(), .receiptMsgId = data.vreceipt_msg_id().value_or_empty(),
.amount = data.vtotal_amount().v, .amount = data.vtotal_amount().v,
.currency = qs(data.vcurrency()), .currency = qs(data.vcurrency()),
.title = TextUtilities::SingleLine(qs(data.vtitle())), .title = TextUtilities::SingleLine(qs(data.vtitle())),
.description = qs(data.vdescription()), .description = TextUtilities::ParseEntities(
description,
TextParseLinks | TextParseMultiline),
.photo = (data.vphoto() .photo = (data.vphoto()
? item->history()->owner().photoFromWeb( ? item->history()->owner().photoFromWeb(
*data.vphoto(), *data.vphoto(),

View File

@ -63,7 +63,7 @@ struct Invoice {
uint64 amount = 0; uint64 amount = 0;
QString currency; QString currency;
QString title; QString title;
QString description; TextWithEntities description;
PhotoData *photo = nullptr; PhotoData *photo = nullptr;
bool isTest = false; bool isTest = false;
}; };

View File

@ -68,13 +68,10 @@ void Invoice::fillFromData(not_null<Data::Invoice*> invoice) {
_receiptMsgId = invoice->receiptMsgId; _receiptMsgId = invoice->receiptMsgId;
// init strings // init strings
if (!invoice->description.isEmpty()) { if (!invoice->description.empty()) {
auto marked = TextWithEntities { invoice->description };
auto parseFlags = TextParseLinks | TextParseMultiline;
TextUtilities::ParseEntities(marked, parseFlags);
_description.setMarkedText( _description.setMarkedText(
st::webPageDescriptionStyle, st::webPageDescriptionStyle,
marked, invoice->description,
Ui::WebpageTextDescriptionOptions()); Ui::WebpageTextDescriptionOptions());
} }
if (!invoice->title.isEmpty()) { if (!invoice->title.isEmpty()) {

View File

@ -26,6 +26,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "smartglocal/smartglocal_token.h" #include "smartglocal/smartglocal_token.h"
#include "storage/storage_account.h" #include "storage/storage_account.h"
#include "ui/image/image.h" #include "ui/image/image.h"
#include "ui/text/text_entity.h"
#include "apiwrap.h" #include "apiwrap.h"
#include "core/core_cloud_password.h" #include "core/core_cloud_password.h"
#include "window/themes/window_theme.h" #include "window/themes/window_theme.h"
@ -400,7 +401,9 @@ void Form::processDetails(const MTPDpayments_paymentForm &data) {
.passwordMissing = data.is_password_missing(), .passwordMissing = data.is_password_missing(),
}; };
_invoice.cover.title = qs(data.vtitle()); _invoice.cover.title = qs(data.vtitle());
_invoice.cover.description = qs(data.vdescription()); _invoice.cover.description = TextUtilities::ParseEntities(
qs(data.vdescription()),
TextParseLinks | TextParseMultiline)
if (_invoice.cover.thumbnail.isNull() && !_thumbnailLoadProcess) { if (_invoice.cover.thumbnail.isNull() && !_thumbnailLoadProcess) {
if (const auto photo = data.vphoto()) { if (const auto photo = data.vphoto()) {
loadThumbnail( loadThumbnail(

View File

@ -16,7 +16,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/wrap/fade_wrap.h" #include "ui/wrap/fade_wrap.h"
#include "ui/text/format_values.h" #include "ui/text/format_values.h"
#include "ui/text/text_utilities.h" #include "ui/text/text_utilities.h"
#include "ui/text/text_entity.h"
#include "countries/countries_instance.h" #include "countries/countries_instance.h"
#include "lang/lang_keys.h" #include "lang/lang_keys.h"
#include "base/unixtime.h" #include "base/unixtime.h"
@ -218,9 +217,7 @@ void FormSummary::setupCover(not_null<VerticalLayout*> layout) {
st::paymentsTitle); st::paymentsTitle);
state->description = CreateChild<FlatLabel>( state->description = CreateChild<FlatLabel>(
cover, cover,
rpl::single(TextUtilities::ParseEntities( rpl::single(_invoice.cover.description),
_invoice.cover.description,
TextParseLinks)),
st::paymentsDescription); st::paymentsDescription);
state->seller = CreateChild<FlatLabel>( state->seller = CreateChild<FlatLabel>(
cover, cover,

View File

@ -7,6 +7,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/ */
#pragma once #pragma once
#include "ui/text/text_entity.h"
namespace Payments::Ui { namespace Payments::Ui {
struct LabeledPrice { struct LabeledPrice {
@ -16,7 +18,7 @@ struct LabeledPrice {
struct Cover { struct Cover {
QString title; QString title;
QString description; TextWithEntities description;
QString seller; QString seller;
QImage thumbnail; QImage thumbnail;
}; };