aboutsummaryrefslogtreecommitdiffhomepage
path: root/td/telegram/Payments.cpp
diff options
context:
space:
mode:
authorlevlam <levlam@telegram.org>2024-08-07 14:30:45 +0300
committerlevlam <levlam@telegram.org>2024-08-07 14:30:45 +0300
commita4171a8cc77e54687496beb4f094286ead0ebe47 (patch)
tree27a36e35c7d26723fe46abd8cc1d7c09d7c1bceb /td/telegram/Payments.cpp
parente2076d593b521dac472427171edfdf694a9aab3a (diff)
Locally update owned star count after bying a paid media.
Diffstat (limited to 'td/telegram/Payments.cpp')
-rw-r--r--td/telegram/Payments.cpp15
1 files changed, 11 insertions, 4 deletions
diff --git a/td/telegram/Payments.cpp b/td/telegram/Payments.cpp
index ed73bccab..915a3aa96 100644
--- a/td/telegram/Payments.cpp
+++ b/td/telegram/Payments.cpp
@@ -46,6 +46,7 @@ namespace {
struct InputInvoiceInfo {
DialogId dialog_id_;
telegram_api::object_ptr<telegram_api::InputInvoice> input_invoice_;
+ int64 star_count_ = 0;
};
Result<InputInvoiceInfo> get_input_invoice_info(Td *td, td_api::object_ptr<td_api::InputInvoice> &&input_invoice) {
@@ -59,7 +60,7 @@ Result<InputInvoiceInfo> get_input_invoice_info(Td *td, td_api::object_ptr<td_ap
auto invoice = td_api::move_object_as<td_api::inputInvoiceMessage>(input_invoice);
DialogId dialog_id(invoice->chat_id_);
MessageId message_id(invoice->message_id_);
- TRY_RESULT(server_message_id, td->messages_manager_->get_invoice_message_id({dialog_id, message_id}));
+ TRY_RESULT(invoice_message_info, td->messages_manager_->get_invoice_message_info({dialog_id, message_id}));
auto input_peer = td->dialog_manager_->get_input_peer(dialog_id, AccessRights::Read);
if (input_peer == nullptr) {
@@ -67,8 +68,9 @@ Result<InputInvoiceInfo> get_input_invoice_info(Td *td, td_api::object_ptr<td_ap
}
result.dialog_id_ = dialog_id;
- result.input_invoice_ =
- make_tl_object<telegram_api::inputInvoiceMessage>(std::move(input_peer), server_message_id.get());
+ result.input_invoice_ = telegram_api::make_object<telegram_api::inputInvoiceMessage>(
+ std::move(input_peer), invoice_message_info.server_message_id_.get());
+ result.star_count_ = invoice_message_info.star_count_;
break;
}
case td_api::inputInvoiceName::ID: {
@@ -673,6 +675,7 @@ class SendPaymentFormQuery final : public Td::ResultHandler {
class SendStarPaymentFormQuery final : public Td::ResultHandler {
Promise<td_api::object_ptr<td_api::paymentResult>> promise_;
DialogId dialog_id_;
+ int64 star_count_;
public:
explicit SendStarPaymentFormQuery(Promise<td_api::object_ptr<td_api::paymentResult>> &&promise)
@@ -681,13 +684,14 @@ class SendStarPaymentFormQuery final : public Td::ResultHandler {
void send(InputInvoiceInfo &&input_invoice_info, int64 payment_form_id) {
dialog_id_ = input_invoice_info.dialog_id_;
+ star_count_ = input_invoice_info.star_count_;
send_query(G()->net_query_creator().create(
telegram_api::payments_sendStarsForm(0, payment_form_id, std::move(input_invoice_info.input_invoice_))));
}
void on_result(BufferSlice packet) final {
- auto result_ptr = fetch_result<telegram_api::payments_sendPaymentForm>(packet);
+ auto result_ptr = fetch_result<telegram_api::payments_sendStarsForm>(packet);
if (result_ptr.is_error()) {
return on_error(result_ptr.move_as_error());
}
@@ -698,6 +702,9 @@ class SendStarPaymentFormQuery final : public Td::ResultHandler {
switch (payment_result->get_id()) {
case telegram_api::payments_paymentResult::ID: {
auto result = telegram_api::move_object_as<telegram_api::payments_paymentResult>(payment_result);
+ if (star_count_ != 0) {
+ td_->star_manager_->add_owned_star_count(-star_count_);
+ }
td_->updates_manager_->on_get_updates(
std::move(result->updates_), PromiseCreator::lambda([promise = std::move(promise_)](Unit) mutable {
promise.set_value(td_api::make_object<td_api::paymentResult>(true, string()));