Locally update owned star count after bying a paid media.
This commit is contained in:
parent
e2076d593b
commit
a4171a8cc7
@ -17466,7 +17466,7 @@ void MessagesManager::get_message_properties(DialogId dialog_id, MessageId messa
|
||||
auto can_be_saved = can_save_message(dialog_id, m);
|
||||
auto can_be_edited = can_edit_message(dialog_id, m, false, is_bot);
|
||||
auto can_be_forwarded = can_be_saved && can_forward_message(dialog_id, m);
|
||||
auto can_be_paid = get_invoice_message_id({dialog_id, m->message_id}).is_ok();
|
||||
auto can_be_paid = get_invoice_message_info({dialog_id, m->message_id}).is_ok();
|
||||
auto can_be_pinned = can_pin_message(dialog_id, m).is_ok();
|
||||
auto can_be_replied =
|
||||
message_id.is_valid() && !(message_id == MessageId(ServerMessageId(1)) && dialog_type == DialogType::Channel) &&
|
||||
@ -38600,8 +38600,8 @@ void MessagesManager::stop_poll(MessageFullId message_full_id, td_api::object_pt
|
||||
stop_message_content_poll(td_, m->content.get(), message_full_id, std::move(new_reply_markup), std::move(promise));
|
||||
}
|
||||
|
||||
Result<ServerMessageId> MessagesManager::get_invoice_message_id(MessageFullId message_full_id) {
|
||||
auto m = get_message_force(message_full_id, "get_invoice_message_id");
|
||||
Result<MessagesManager::InvoiceMessageInfo> MessagesManager::get_invoice_message_info(MessageFullId message_full_id) {
|
||||
auto m = get_message_force(message_full_id, "get_invoice_message_info");
|
||||
if (m == nullptr) {
|
||||
return Status::Error(400, "Message not found");
|
||||
}
|
||||
@ -38628,7 +38628,11 @@ Result<ServerMessageId> MessagesManager::get_invoice_message_id(MessageFullId me
|
||||
}
|
||||
}
|
||||
|
||||
return m->message_id.get_server_message_id();
|
||||
InvoiceMessageInfo result;
|
||||
result.server_message_id_ = m->message_id.get_server_message_id();
|
||||
result.star_count_ =
|
||||
content_type != MessageContentType::PaidMedia ? 0 : get_message_content_star_count(m->content.get());
|
||||
return std::move(result);
|
||||
}
|
||||
|
||||
Result<ServerMessageId> MessagesManager::get_payment_successful_message_id(MessageFullId message_full_id) {
|
||||
|
@ -966,7 +966,11 @@ class MessagesManager final : public Actor {
|
||||
|
||||
Result<string> get_login_button_url(MessageFullId message_full_id, int64 button_id);
|
||||
|
||||
Result<ServerMessageId> get_invoice_message_id(MessageFullId message_full_id);
|
||||
struct InvoiceMessageInfo {
|
||||
ServerMessageId server_message_id_;
|
||||
int64 star_count_ = 0;
|
||||
};
|
||||
Result<InvoiceMessageInfo> get_invoice_message_info(MessageFullId message_full_id);
|
||||
|
||||
Result<ServerMessageId> get_payment_successful_message_id(MessageFullId message_full_id);
|
||||
|
||||
|
@ -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()));
|
||||
|
@ -666,6 +666,10 @@ void StarManager::on_update_owned_star_count(int64 star_count) {
|
||||
send_closure(G()->td(), &Td::send_update, get_update_owned_star_count_object());
|
||||
}
|
||||
|
||||
void StarManager::add_owned_star_count(int64 star_count) {
|
||||
on_update_owned_star_count(star_count + owned_star_count_);
|
||||
}
|
||||
|
||||
Status StarManager::can_manage_stars(DialogId dialog_id, bool allow_self) const {
|
||||
switch (dialog_id.get_type()) {
|
||||
case DialogType::User: {
|
||||
|
@ -29,6 +29,8 @@ class StarManager final : public Actor {
|
||||
|
||||
void on_update_owned_star_count(int64 star_count);
|
||||
|
||||
void add_owned_star_count(int64 star_count);
|
||||
|
||||
void get_star_payment_options(Promise<td_api::object_ptr<td_api::starPaymentOptions>> &&promise);
|
||||
|
||||
void get_star_gift_payment_options(UserId user_id, Promise<td_api::object_ptr<td_api::starPaymentOptions>> &&promise);
|
||||
|
Loading…
Reference in New Issue
Block a user