Add td_api::checkPremiumGiftCode.
This commit is contained in:
parent
ca1ae47242
commit
4bd27a1516
@ -695,6 +695,16 @@ premiumGiftCodePaymentOption currency:string amount:int53 user_count:int32 month
|
||||
//@description Contains a list of options for creating Telegram Premium gift codes @options The list of options
|
||||
premiumGiftCodePaymentOptions options:vector<premiumGiftCodePaymentOption> = PremiumGiftCodePaymentOptions;
|
||||
|
||||
//@description Contains information about a Telegram Premium gift code
|
||||
//@creator_id Identifier of a chat or a user that created the gift code
|
||||
//@creation_date Point in time (Unix timestamp) when the code was created
|
||||
//@is_from_giveaway True, if the gift code was created for a giveaway
|
||||
//@giveaway_message_id Identifier of the corresponding giveaway message; can be 0 or an identifier of a deleted message
|
||||
//@month_count Number of month the Telegram Premium subscription will be active after code activation
|
||||
//@user_id Identifier of a user, which can activate the code; 0 if none
|
||||
//@use_date Point in time (Unix timestamp) when the code was activated; 0 if none
|
||||
premiumGiftCodeInfo creator_id:MessageSender creation_date:int32 is_from_giveaway:Bool giveaway_message_id:int53 month_count:int32 user_id:int53 use_date:int32 = PremiumGiftCodeInfo;
|
||||
|
||||
|
||||
//@description Describes a custom emoji to be shown instead of the Telegram Premium badge
|
||||
//@custom_emoji_id Identifier of the custom emoji in stickerFormatTgs format
|
||||
@ -9030,6 +9040,9 @@ getPremiumState = PremiumState;
|
||||
//@boosted_chat_id Identifier of the channel chat, which will be automatically boosted by receivers of the gift codes and which is administered by the user; 0 if none
|
||||
getPremiumGiftCodePaymentOptions boosted_chat_id:int53 = PremiumGiftCodePaymentOptions;
|
||||
|
||||
//@description Return information about a premium gift code @code The code to check
|
||||
checkPremiumGiftCode code:string = PremiumGiftCodeInfo;
|
||||
|
||||
//@description Checks whether Telegram Premium purchase is possible. Must be called before in-store Premium purchase @purpose Transaction purpose
|
||||
canPurchasePremium purpose:StorePaymentPurpose = Ok;
|
||||
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include "td/telegram/DocumentsManager.h"
|
||||
#include "td/telegram/Global.h"
|
||||
#include "td/telegram/MessageEntity.h"
|
||||
#include "td/telegram/MessageSender.h"
|
||||
#include "td/telegram/MessagesManager.h"
|
||||
#include "td/telegram/misc.h"
|
||||
#include "td/telegram/PremiumGiftOption.h"
|
||||
@ -274,6 +275,61 @@ class GetPremiumGiftCodeOptionsQuery final : public Td::ResultHandler {
|
||||
promise_.set_value(td_api::make_object<td_api::premiumGiftCodePaymentOptions>(std::move(options)));
|
||||
}
|
||||
|
||||
void on_error(Status status) final {
|
||||
td_->messages_manager_->on_get_dialog_error(boosted_dialog_id_, status, "GetPremiumGiftCodeOptionsQuery");
|
||||
promise_.set_error(std::move(status));
|
||||
}
|
||||
};
|
||||
|
||||
class CheckGiftCodeQuery final : public Td::ResultHandler {
|
||||
Promise<td_api::object_ptr<td_api::premiumGiftCodeInfo>> promise_;
|
||||
|
||||
public:
|
||||
explicit CheckGiftCodeQuery(Promise<td_api::object_ptr<td_api::premiumGiftCodeInfo>> &&promise)
|
||||
: promise_(std::move(promise)) {
|
||||
}
|
||||
|
||||
void send(const string &code) {
|
||||
send_query(G()->net_query_creator().create(telegram_api::payments_checkGiftCode(code)));
|
||||
}
|
||||
|
||||
void on_result(BufferSlice packet) final {
|
||||
auto result_ptr = fetch_result<telegram_api::payments_checkGiftCode>(packet);
|
||||
if (result_ptr.is_error()) {
|
||||
return on_error(result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
auto result = result_ptr.move_as_ok();
|
||||
LOG(INFO) << "Receive result for CheckGiftCodeQuery: " << to_string(result);
|
||||
td_->contacts_manager_->on_get_users(std::move(result->users_), "CheckGiftCodeQuery");
|
||||
td_->contacts_manager_->on_get_chats(std::move(result->chats_), "CheckGiftCodeQuery");
|
||||
|
||||
DialogId creator_dialog_id(result->from_id_);
|
||||
if (!creator_dialog_id.is_valid() ||
|
||||
!td_->messages_manager_->have_dialog_info_force(creator_dialog_id, "CheckGiftCodeQuery") ||
|
||||
result->date_ <= 0 || result->months_ <= 0 || result->used_date_ < 0) {
|
||||
LOG(ERROR) << "Receive " << to_string(result);
|
||||
return on_error(Status::Error(500, "Receive invalid response"));
|
||||
}
|
||||
if (creator_dialog_id.get_type() != DialogType::User) {
|
||||
td_->messages_manager_->force_create_dialog(creator_dialog_id, "CheckGiftCodeQuery", true);
|
||||
}
|
||||
UserId user_id(result->to_id_);
|
||||
if (!user_id.is_valid() && user_id != UserId()) {
|
||||
LOG(ERROR) << "Receive " << to_string(result);
|
||||
user_id = UserId();
|
||||
}
|
||||
MessageId message_id(ServerMessageId(result->giveaway_msg_id_));
|
||||
if (!message_id.is_valid() && message_id != MessageId()) {
|
||||
LOG(ERROR) << "Receive " << to_string(result);
|
||||
message_id = MessageId();
|
||||
}
|
||||
promise_.set_value(td_api::make_object<td_api::premiumGiftCodeInfo>(
|
||||
get_message_sender_object(td_, creator_dialog_id, "premiumGiftCodeInfo"), result->date_, result->via_giveaway_,
|
||||
message_id.get(), result->months_, td_->contacts_manager_->get_user_id_object(user_id, "premiumGiftCodeInfo"),
|
||||
result->used_date_));
|
||||
}
|
||||
|
||||
void on_error(Status status) final {
|
||||
promise_.set_error(std::move(status));
|
||||
}
|
||||
@ -710,6 +766,11 @@ void get_premium_gift_code_options(Td *td, DialogId boosted_dialog_id,
|
||||
td->create_handler<GetPremiumGiftCodeOptionsQuery>(std::move(promise))->send(boosted_dialog_id);
|
||||
}
|
||||
|
||||
void check_premium_gift_code(Td *td, const string &code,
|
||||
Promise<td_api::object_ptr<td_api::premiumGiftCodeInfo>> &&promise) {
|
||||
td->create_handler<CheckGiftCodeQuery>(std::move(promise))->send(code);
|
||||
}
|
||||
|
||||
void can_purchase_premium(Td *td, td_api::object_ptr<td_api::StorePaymentPurpose> &&purpose, Promise<Unit> &&promise) {
|
||||
td->create_handler<CanPurchasePremiumQuery>(std::move(promise))->send(std::move(purpose));
|
||||
}
|
||||
|
@ -34,6 +34,9 @@ void get_premium_state(Td *td, Promise<td_api::object_ptr<td_api::premiumState>>
|
||||
void get_premium_gift_code_options(Td *td, DialogId boosted_dialog_id,
|
||||
Promise<td_api::object_ptr<td_api::premiumGiftCodePaymentOptions>> &&promise);
|
||||
|
||||
void check_premium_gift_code(Td *td, const string &code,
|
||||
Promise<td_api::object_ptr<td_api::premiumGiftCodeInfo>> &&promise);
|
||||
|
||||
void can_purchase_premium(Td *td, td_api::object_ptr<td_api::StorePaymentPurpose> &&purpose, Promise<Unit> &&promise);
|
||||
|
||||
void assign_app_store_transaction(Td *td, const string &receipt,
|
||||
|
@ -8795,6 +8795,13 @@ void Td::on_request(uint64 id, const td_api::getPremiumGiftCodePaymentOptions &r
|
||||
get_premium_gift_code_options(this, DialogId(request.boosted_chat_id_), std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, td_api::checkPremiumGiftCode &request) {
|
||||
CHECK_IS_USER();
|
||||
CLEAN_INPUT_STRING(request.code_);
|
||||
CREATE_REQUEST_PROMISE();
|
||||
check_premium_gift_code(this, request.code_, std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, td_api::canPurchasePremium &request) {
|
||||
CHECK_IS_USER();
|
||||
CREATE_OK_REQUEST_PROMISE();
|
||||
|
@ -1599,6 +1599,8 @@ class Td final : public Actor {
|
||||
|
||||
void on_request(uint64 id, const td_api::getPremiumGiftCodePaymentOptions &request);
|
||||
|
||||
void on_request(uint64 id, td_api::checkPremiumGiftCode &request);
|
||||
|
||||
void on_request(uint64 id, td_api::canPurchasePremium &request);
|
||||
|
||||
void on_request(uint64 id, td_api::assignAppStoreTransaction &request);
|
||||
|
@ -3096,6 +3096,8 @@ class CliClient final : public Actor {
|
||||
ChatId boosted_chat_id;
|
||||
get_args(args, boosted_chat_id);
|
||||
send_request(td_api::make_object<td_api::getPremiumGiftCodePaymentOptions>(boosted_chat_id));
|
||||
} else if (op == "cpgc") {
|
||||
send_request(td_api::make_object<td_api::checkPremiumGiftCode>(args));
|
||||
} else if (op == "cppr" || op == "cpprb") {
|
||||
UserId user_id;
|
||||
string currency;
|
||||
|
Loading…
Reference in New Issue
Block a user