From 092474fdb91fe9035387f3f29d4edd84f3d045e8 Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 2 Jun 2022 21:09:54 +0400 Subject: [PATCH] Support recurring payment phrases. --- Telegram/Resources/langs/lang.strings | 3 ++ .../export/data/export_data_types.cpp | 2 + .../export/data/export_data_types.h | 2 + .../export/output/export_output_html.cpp | 12 ++++- .../export/output/export_output_json.cpp | 6 +++ .../SourceFiles/history/history_service.cpp | 46 ++++++++++++------- .../SourceFiles/history/history_service.h | 2 + 7 files changed, 55 insertions(+), 18 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 9cce5c029..2681f3ad1 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -1426,6 +1426,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_action_game_you_scored_no_game#other" = "You scored {count}"; "lng_action_payment_done" = "You have just successfully transferred {amount} to {user}"; "lng_action_payment_done_for" = "You have just successfully transferred {amount} to {user} for {invoice}"; +"lng_action_payment_init_recurring_for" = "You have just successfully transferred {amount} to {user} for {invoice} and allowed future recurring payments"; +"lng_action_payment_init_recurring" = "You have just successfully transferred {amount} to {user} and allowed future recurring payments"; +"lng_action_payment_used_recurring" = "You were charged {amount} via recurring payment"; "lng_action_took_screenshot" = "{from} took a screenshot!"; "lng_action_you_took_screenshot" = "You took a screenshot!"; "lng_action_bot_allowed_from_domain" = "You allowed this bot to message you when you logged in on {domain}."; diff --git a/Telegram/SourceFiles/export/data/export_data_types.cpp b/Telegram/SourceFiles/export/data/export_data_types.cpp index db81318cc..f8901709b 100644 --- a/Telegram/SourceFiles/export/data/export_data_types.cpp +++ b/Telegram/SourceFiles/export/data/export_data_types.cpp @@ -1023,6 +1023,8 @@ ServiceAction ParseServiceAction( auto content = ActionPaymentSent(); content.currency = ParseString(data.vcurrency()); content.amount = data.vtotal_amount().v; + content.recurringInit = data.is_recurring_init(); + content.recurringUsed = data.is_recurring_used(); result.content = content; }, [&](const MTPDmessageActionPhoneCall &data) { auto content = ActionPhoneCall(); diff --git a/Telegram/SourceFiles/export/data/export_data_types.h b/Telegram/SourceFiles/export/data/export_data_types.h index f0a128613..bf92fc8d3 100644 --- a/Telegram/SourceFiles/export/data/export_data_types.h +++ b/Telegram/SourceFiles/export/data/export_data_types.h @@ -401,6 +401,8 @@ struct ActionGameScore { struct ActionPaymentSent { Utf8String currency; uint64 amount = 0; + bool recurringInit = false; + bool recurringUsed = false; }; struct ActionPhoneCall { diff --git a/Telegram/SourceFiles/export/output/export_output_html.cpp b/Telegram/SourceFiles/export/output/export_output_html.cpp index c53bb3f32..d9334146b 100644 --- a/Telegram/SourceFiles/export/output/export_output_html.cpp +++ b/Telegram/SourceFiles/export/output/export_output_html.cpp @@ -1001,10 +1001,18 @@ auto HtmlWriter::Wrap::pushMessage( + " in " + wrapReplyToLink("this game"); }, [&](const ActionPaymentSent &data) { - return "You have successfully transferred " - + FormatMoneyAmount(data.amount, data.currency) + const auto amount = FormatMoneyAmount(data.amount, data.currency); + if (data.recurringUsed) { + return "You were charged " + amount + " via recurring payment"; + } + auto result = "You have successfully transferred " + + amount + " for " + wrapReplyToLink("this invoice"); + if (data.recurringInit) { + result += " and allowed future recurring payments"; + } + return result; }, [&](const ActionPhoneCall &data) { return QByteArray(); }, [&](const ActionScreenshotTaken &data) { diff --git a/Telegram/SourceFiles/export/output/export_output_json.cpp b/Telegram/SourceFiles/export/output/export_output_json.cpp index 133a91156..fac36dd88 100644 --- a/Telegram/SourceFiles/export/output/export_output_json.cpp +++ b/Telegram/SourceFiles/export/output/export_output_json.cpp @@ -430,7 +430,13 @@ QByteArray SerializeMessage( pushAction("send_payment"); push("amount", data.amount); push("currency", data.currency); + const auto amount = FormatMoneyAmount(data.amount, data.currency); pushReplyToMsgId("invoice_message_id"); + if (data.recurringUsed) { + push("recurring", "used"); + } else if (data.recurringInit) { + push("recurring", "init"); + } }, [&](const ActionPhoneCall &data) { pushActor(); pushAction("phone_call"); diff --git a/Telegram/SourceFiles/history/history_service.cpp b/Telegram/SourceFiles/history/history_service.cpp index 47db60456..10da7bcbe 100644 --- a/Telegram/SourceFiles/history/history_service.cpp +++ b/Telegram/SourceFiles/history/history_service.cpp @@ -1048,23 +1048,35 @@ HistoryService::PreparedText HistoryService::preparePaymentSentText() { }(); if (invoiceTitle.text.isEmpty()) { - result.text = tr::lng_action_payment_done( - tr::now, - lt_amount, - { .text = payment->amount }, - lt_user, - { .text = history()->peer->name }, - Ui::Text::WithEntities); + if (payment->recurringUsed) { + result.text = tr::lng_action_payment_used_recurring( + tr::now, + lt_amount, + { .text = payment->amount }, + Ui::Text::WithEntities); + } else { + result.text = (payment->recurringInit + ? tr::lng_action_payment_init_recurring + : tr::lng_action_payment_done)( + tr::now, + lt_amount, + { .text = payment->amount }, + lt_user, + { .text = history()->peer->name }, + Ui::Text::WithEntities); + } } else { - result.text = tr::lng_action_payment_done_for( - tr::now, - lt_amount, - { .text = payment->amount }, - lt_user, - { .text = history()->peer->name }, - lt_invoice, - invoiceTitle, - Ui::Text::WithEntities); + result.text = (payment->recurringInit + ? tr::lng_action_payment_init_recurring_for + : tr::lng_action_payment_done_for)( + tr::now, + lt_amount, + { .text = payment->amount }, + lt_user, + { .text = history()->peer->name }, + lt_invoice, + invoiceTitle, + Ui::Text::WithEntities); if (payment->msg) { result.links.push_back(payment->lnk); } @@ -1363,6 +1375,8 @@ void HistoryService::createFromMtp(const MTPDmessageService &message) { const auto id = fullId(); const auto owner = &history()->owner(); payment->slug = data.vinvoice_slug().value_or_empty(); + payment->recurringInit = data.is_recurring_init(); + payment->recurringUsed = data.is_recurring_used(); payment->amount = Ui::FillAmountAndCurrency(amount, currency); payment->invoiceLink = std::make_shared([=]( ClickContext context) { diff --git a/Telegram/SourceFiles/history/history_service.h b/Telegram/SourceFiles/history/history_service.h index 380d8696f..dd9805da7 100644 --- a/Telegram/SourceFiles/history/history_service.h +++ b/Telegram/SourceFiles/history/history_service.h @@ -37,6 +37,8 @@ struct HistoryServicePayment QString slug; QString amount; ClickHandlerPtr invoiceLink; + bool recurringInit = false; + bool recurringUsed = false; }; struct HistoryServiceSelfDestruct