Add td_api::premiumGiveawayParameters.

This commit is contained in:
levlam 2023-10-12 17:05:03 +03:00
parent c2d5ca2d3f
commit 3dea942078
9 changed files with 292 additions and 112 deletions

View File

@ -368,6 +368,7 @@ set(TDLIB_SOURCE
td/telegram/ForumTopicManager.cpp
td/telegram/Game.cpp
td/telegram/GameManager.cpp
td/telegram/GiveawayParameters.cpp
td/telegram/Global.cpp
td/telegram/GlobalPrivacySettings.cpp
td/telegram/GroupCallManager.cpp
@ -647,6 +648,7 @@ set(TDLIB_SOURCE
td/telegram/Game.h
td/telegram/GameManager.h
td/telegram/GitCommitHash.h
td/telegram/GiveawayParameters.h
td/telegram/Global.h
td/telegram/GlobalPrivacySettings.h
td/telegram/GroupCallId.h
@ -853,6 +855,7 @@ set(TDLIB_SOURCE
td/telegram/ForumTopicIcon.hpp
td/telegram/ForumTopicInfo.hpp
td/telegram/Game.hpp
td/telegram/GiveawayParameters.hpp
td/telegram/InputInvoice.hpp
td/telegram/InputMessageText.hpp
td/telegram/MediaArea.hpp

View File

@ -2293,6 +2293,13 @@ messageExtendedMediaVideo video:video caption:formattedText = MessageExtendedMed
messageExtendedMediaUnsupported caption:formattedText = MessageExtendedMedia;
//@description Describes parameters of a Telegram Premium giveaway
//@boosted_chat_id Identifier of the channel chat, which will be automatically boosted by the winners of the giveaway for duration of the Premium subscription
//@additional_chat_ids Identifiers of other channel chats that must be subscribed by the users to be eligible for the giveaway
//@date Point in time (Unix timestamp) when the giveaway will be performed; must be from 1 minute to 365 days in the future
//@only_new_subscribers Pass true if only new subscribers of the chats will be eligible for the giveaway
premiumGiveawayParameters boosted_chat_id:int53 additional_chat_ids:vector<int53> date:int32 only_new_subscribers:Bool = PremiumGiveawayParameters;
//@description File with the date it was uploaded @file The file @date Point in time (Unix timestamp) when the file was uploaded
datedFile file:file date:int32 = DatedFile;
@ -2798,12 +2805,10 @@ messageGiftedPremium gifter_user_id:int53 currency:string amount:int53 cryptocur
messagePremiumGiftCode creator_id:MessageSender is_from_giveaway:Bool month_count:int32 code:string = MessageContent;
//@description A Telegram Premium giveaway is scheduled by channel chats
//@chat_ids Identifiers of chats that started the giveaway
//@only_new_subscribers True, if only new subscribers of the chats will be eligible for the giveaway
//@quantity Number of users which will receive Telegram Premium subscription gift codes
//@parameters Giveaway parameters
//@user_count Number of users which will receive Telegram Premium subscription gift codes
//@month_count Number of month the Telegram Premium subscription will be active after code activation
//@date Point in time (Unix timestamp) when the giveaway starts
messagePremiumGiveaway chat_ids:vector<int53> only_new_subscribers:Bool quantity:int32 month_count:int32 date:int32 = MessageContent;
messagePremiumGiveaway parameters:premiumGiveawayParameters user_count:int32 month_count:int32 = MessageContent;
//@description A contact has registered with Telegram
messageContactRegistered = MessageContent;
@ -3445,10 +3450,10 @@ chatActiveStories chat_id:int53 list:StoryList order:int53 max_read_story_id:int
//@description Describes a prepaid Telegram Premium giveaway
//@id Unique identifier of the prepaid giveaway
//@quantity Number of users which will receive Telegram Premium subscription gift codes
//@user_count Number of users which will receive Telegram Premium subscription gift codes
//@month_count Number of month the Telegram Premium subscription will be active after code activation
//@payment_date Point in time (Unix timestamp) when the giveaway was paid
prepaidPremiumGiveaway id:int64 quantity:int32 month_count:int32 payment_date:int32 = PrepaidPremiumGiveaway;
prepaidPremiumGiveaway id:int64 user_count:int32 month_count:int32 payment_date:int32 = PrepaidPremiumGiveaway;
//@description Describes current boost status of a chat
//@boost_url An HTTP URL, which can be used to boost the chat
@ -4474,13 +4479,10 @@ storePaymentPurposeGiftedPremium user_id:int53 currency:string amount:int53 = St
storePaymentPurposePremiumGiftCodes boosted_chat_id:int53 currency:string amount:int53 user_ids:vector<int53> = StorePaymentPurpose;
//@description The user creating a Telegram Premium giveaway for subscribers of a channel chat
//@boosted_chat_id Identifier of the channel chat, which will be automatically boosted by the users for duration of the Premium subscription and which is administered by the user
//@additional_chat_ids Identifiers of other channel chats that must be subscribed by the users to be eligible for the giveaway
//@date Point in time (Unix timestamp) when the giveaway will be performed; must be from 1 minute to 365 days in the future
//@only_new_subscribers Pass true if only new subscribers of the chats will be eligible for the giveaway
//@parameters Giveaway parameters
//@currency ISO 4217 currency code of the payment currency
//@amount Paid amount, in the smallest units of the currency
storePaymentPurposePremiumGiveaway boosted_chat_id:int53 additional_chat_ids:vector<int53> date:int32 only_new_subscribers:Bool currency:string amount:int53 = StorePaymentPurpose;
storePaymentPurposePremiumGiveaway parameters:premiumGiveawayParameters currency:string amount:int53 = StorePaymentPurpose;
//@class TelegramPaymentPurpose @description Describes a purpose of a payment toward Telegram
@ -4494,15 +4496,12 @@ storePaymentPurposePremiumGiveaway boosted_chat_id:int53 additional_chat_ids:vec
telegramPaymentPurposePremiumGiftCodes boosted_chat_id:int53 currency:string amount:int53 user_ids:vector<int53> month_count:int32 = TelegramPaymentPurpose;
//@description The user creating a Telegram Premium giveaway for subscribers of a channel chat
//@boosted_chat_id Identifier of the channel chat, which will be automatically boosted by the users for duration of the Premium subscription and which is administered by the user
//@additional_chat_ids Identifiers of other channel chats that must be subscribed by the users to be eligible for the giveaway
//@date Point in time (Unix timestamp) when the giveaway will be performed; must be from 1 minute to 365 days in the future
//@only_new_subscribers Pass true, if only new subscribers of the chats will be eligible for the giveaway
//@parameters Giveaway parameters
//@currency ISO 4217 currency code of the payment currency
//@amount Paid amount, in the smallest units of the currency
//@user_count Number of users which will be able to activate the gift codes
//@month_count Number of month the Telegram Premium subscription will be active for the users
telegramPaymentPurposePremiumGiveaway boosted_chat_id:int53 additional_chat_ids:vector<int53> date:int32 only_new_subscribers:Bool currency:string amount:int53 user_count:int32 month_count:int32 = TelegramPaymentPurpose;
telegramPaymentPurposePremiumGiveaway parameters:premiumGiveawayParameters currency:string amount:int53 user_count:int32 month_count:int32 = TelegramPaymentPurpose;
//@class DeviceToken @description Represents a data needed to subscribe for push notifications through registerDevice method.

View File

@ -0,0 +1,123 @@
//
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#include "td/telegram/GiveawayParameters.h"
#include "td/telegram/ContactsManager.h"
#include "td/telegram/Dependencies.h"
#include "td/telegram/DialogId.h"
#include "td/telegram/MessagesManager.h"
#include "td/telegram/Td.h"
#include "td/utils/Random.h"
namespace td {
Result<ChannelId> GiveawayParameters::get_boosted_channel_id(Td *td, DialogId dialog_id) {
if (!td->messages_manager_->have_dialog_force(dialog_id, "get_boosted_channel_id")) {
return Status::Error(400, "Chat to boost not found");
}
if (dialog_id.get_type() != DialogType::Channel) {
return Status::Error(400, "Can't boost the chat");
}
auto channel_id = dialog_id.get_channel_id();
if (!td->contacts_manager_->is_broadcast_channel(channel_id)) {
return Status::Error(400, "Can't boost the group");
}
if (!td->contacts_manager_->get_channel_status(channel_id).can_post_messages()) {
return Status::Error(400, "Not enough rights in the chat");
}
return channel_id;
}
Result<GiveawayParameters> GiveawayParameters::get_giveaway_parameters(
Td *td, const td_api::premiumGiveawayParameters *parameters) {
if (parameters == nullptr) {
return Status::Error(400, "Giveaway parameters must be non-empty");
}
TRY_RESULT(boosted_channel_id, get_boosted_channel_id(td, DialogId(parameters->boosted_chat_id_)));
vector<ChannelId> additional_channel_ids;
for (auto additional_chat_id : parameters->additional_chat_ids_) {
TRY_RESULT(channel_id, get_boosted_channel_id(td, DialogId(additional_chat_id)));
additional_channel_ids.push_back(channel_id);
}
if (parameters->date_ < G()->unix_time()) {
return Status::Error(400, "Giveaway date is in the past");
}
return GiveawayParameters(boosted_channel_id, std::move(additional_channel_ids), parameters->only_new_subscribers_,
parameters->date_);
}
void GiveawayParameters::add_dependencies(Dependencies &dependencies) const {
dependencies.add_dialog_and_dependencies(DialogId(boosted_channel_id_));
for (auto channel_id : additional_channel_ids_) {
dependencies.add_dialog_and_dependencies(DialogId(channel_id));
}
}
telegram_api::object_ptr<telegram_api::inputStorePaymentPremiumGiveaway>
GiveawayParameters::get_input_store_payment_premium_giveaway(Td *td, const string &currency, int64 amount) const {
int64 random_id;
do {
random_id = Random::secure_int64();
} while (random_id == 0);
auto boost_input_peer = td->messages_manager_->get_input_peer(DialogId(boosted_channel_id_), AccessRights::Write);
CHECK(boost_input_peer != nullptr);
vector<telegram_api::object_ptr<telegram_api::InputPeer>> additional_input_peers;
for (auto additional_channel_id : additional_channel_ids_) {
auto input_peer = td->messages_manager_->get_input_peer(DialogId(additional_channel_id), AccessRights::Write);
CHECK(input_peer != nullptr);
additional_input_peers.push_back(std::move(input_peer));
}
int32 flags = 0;
if (only_new_subscribers_) {
flags |= telegram_api::inputStorePaymentPremiumGiveaway::ONLY_NEW_SUBSCRIBERS_MASK;
}
if (!additional_input_peers.empty()) {
flags |= telegram_api::inputStorePaymentPremiumGiveaway::ADDITIONAL_PEERS_MASK;
}
return telegram_api::make_object<telegram_api::inputStorePaymentPremiumGiveaway>(
flags, false /*ignored*/, std::move(boost_input_peer), std::move(additional_input_peers), vector<string>(),
random_id, date_, currency, amount);
}
td_api::object_ptr<td_api::premiumGiveawayParameters> GiveawayParameters::get_premium_giveaway_parameters_object(
Td *td) const {
CHECK(is_valid());
vector<int64> chat_ids;
for (auto channel_id : additional_channel_ids_) {
DialogId dialog_id(channel_id);
td->messages_manager_->force_create_dialog(dialog_id, "premiumGiveawayParameters", true);
chat_ids.push_back(td->messages_manager_->get_chat_id_object(dialog_id, "premiumGiveawayParameters"));
}
DialogId dialog_id(boosted_channel_id_);
td->messages_manager_->force_create_dialog(dialog_id, "premiumGiveawayParameters", true);
return td_api::make_object<td_api::premiumGiveawayParameters>(
td->messages_manager_->get_chat_id_object(dialog_id, "premiumGiveawayParameters"), std::move(chat_ids), date_,
only_new_subscribers_);
}
bool operator==(const GiveawayParameters &lhs, const GiveawayParameters &rhs) {
return lhs.boosted_channel_id_ == rhs.boosted_channel_id_ &&
lhs.additional_channel_ids_ == rhs.additional_channel_ids_ &&
lhs.only_new_subscribers_ == rhs.only_new_subscribers_ && lhs.date_ == rhs.date_;
}
bool operator!=(const GiveawayParameters &lhs, const GiveawayParameters &rhs) {
return !(lhs == rhs);
}
StringBuilder &operator<<(StringBuilder &string_builder, const GiveawayParameters &giveaway_parameters) {
return string_builder << "Giveaway[" << giveaway_parameters.boosted_channel_id_ << " + "
<< giveaway_parameters.additional_channel_ids_
<< (giveaway_parameters.only_new_subscribers_ ? " only for new subscribes" : "") << " at "
<< giveaway_parameters.date_ << ']';
}
} // namespace td

View File

@ -0,0 +1,79 @@
//
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#pragma once
#include "td/telegram/ChannelId.h"
#include "td/telegram/DialogId.h"
#include "td/telegram/td_api.h"
#include "td/telegram/telegram_api.h"
#include "td/utils/common.h"
#include "td/utils/Status.h"
#include "td/utils/StringBuilder.h"
namespace td {
class Dependencies;
class Td;
class GiveawayParameters {
ChannelId boosted_channel_id_;
vector<ChannelId> additional_channel_ids_;
bool only_new_subscribers_ = false;
int32 date_ = 0;
static Result<ChannelId> get_boosted_channel_id(Td *td, DialogId dialog_id);
friend bool operator==(const GiveawayParameters &lhs, const GiveawayParameters &rhs);
friend bool operator!=(const GiveawayParameters &lhs, const GiveawayParameters &rhs);
friend StringBuilder &operator<<(StringBuilder &string_builder, const GiveawayParameters &giveaway_parameters);
public:
GiveawayParameters() = default;
GiveawayParameters(ChannelId boosted_channel_id, vector<ChannelId> &&additional_channel_ids,
bool only_new_subscribers, int32 date)
: boosted_channel_id_(boosted_channel_id)
, additional_channel_ids_(std::move(additional_channel_ids))
, only_new_subscribers_(only_new_subscribers)
, date_(date) {
}
static Result<GiveawayParameters> get_giveaway_parameters(Td *td,
const td_api::premiumGiveawayParameters *parameters);
bool is_valid() const {
for (auto channel_id : additional_channel_ids_) {
if (!channel_id.is_valid()) {
return false;
}
}
return boosted_channel_id_.is_valid() && date_ > 0;
}
void add_dependencies(Dependencies &dependencies) const;
telegram_api::object_ptr<telegram_api::inputStorePaymentPremiumGiveaway> get_input_store_payment_premium_giveaway(
Td *td, const string &currency, int64 amount) const;
td_api::object_ptr<td_api::premiumGiveawayParameters> get_premium_giveaway_parameters_object(Td *td) const;
template <class StorerT>
void store(StorerT &storer) const;
template <class ParserT>
void parse(ParserT &parser);
};
bool operator==(const GiveawayParameters &lhs, const GiveawayParameters &rhs);
bool operator!=(const GiveawayParameters &lhs, const GiveawayParameters &rhs);
StringBuilder &operator<<(StringBuilder &string_builder, const GiveawayParameters &giveaway_parameters);
} // namespace td

View File

@ -0,0 +1,43 @@
//
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#pragma once
#include "td/telegram/GiveawayParameters.h"
#include "td/utils/tl_helpers.h"
namespace td {
template <class StorerT>
void GiveawayParameters::store(StorerT &storer) const {
bool has_additional_channel_ids = !additional_channel_ids_.empty();
BEGIN_STORE_FLAGS();
STORE_FLAG(only_new_subscribers_);
STORE_FLAG(has_additional_channel_ids);
END_STORE_FLAGS();
td::store(boosted_channel_id_, storer);
if (has_additional_channel_ids) {
td::store(additional_channel_ids_, storer);
}
td::store(date_, storer);
}
template <class ParserT>
void GiveawayParameters::parse(ParserT &parser) {
bool has_additional_channel_ids;
BEGIN_PARSE_FLAGS();
PARSE_FLAG(only_new_subscribers_);
PARSE_FLAG(has_additional_channel_ids);
END_PARSE_FLAGS();
td::parse(boosted_channel_id_, parser);
if (has_additional_channel_ids) {
td::parse(additional_channel_ids_, parser);
}
td::parse(date_, parser);
}
} // namespace td

View File

@ -38,6 +38,8 @@
#include "td/telegram/ForumTopicManager.h"
#include "td/telegram/Game.h"
#include "td/telegram/Game.hpp"
#include "td/telegram/GiveawayParameters.h"
#include "td/telegram/GiveawayParameters.hpp"
#include "td/telegram/Global.h"
#include "td/telegram/GroupCallManager.h"
#include "td/telegram/HashtagHints.h"
@ -956,20 +958,13 @@ class MessageGiftCode final : public MessageContent {
class MessageGiveaway final : public MessageContent {
public:
vector<ChannelId> channel_ids;
bool only_new_subscribers = false;
GiveawayParameters giveaway_parameters;
int32 quantity = 0;
int32 months = 0;
int32 until_date = 0;
MessageGiveaway() = default;
MessageGiveaway(vector<ChannelId> channel_ids, bool only_new_subscribers, int32 quantity, int32 months,
int32 until_date)
: channel_ids(std::move(channel_ids))
, only_new_subscribers(only_new_subscribers)
, quantity(quantity)
, months(months)
, until_date(until_date) {
MessageGiveaway(GiveawayParameters giveaway_parameters, int32 quantity, int32 months)
: giveaway_parameters(std::move(giveaway_parameters)), quantity(quantity), months(months) {
}
MessageContentType get_type() const final {
@ -1396,12 +1391,10 @@ static void store(const MessageContent *content, StorerT &storer) {
case MessageContentType::Giveaway: {
const auto *m = static_cast<const MessageGiveaway *>(content);
BEGIN_STORE_FLAGS();
STORE_FLAG(m->only_new_subscribers);
END_STORE_FLAGS();
store(m->channel_ids, storer);
store(m->giveaway_parameters, storer);
store(m->quantity, storer);
store(m->months, storer);
store(m->until_date, storer);
break;
}
default:
@ -1968,16 +1961,12 @@ static void parse(unique_ptr<MessageContent> &content, ParserT &parser) {
case MessageContentType::Giveaway: {
auto m = make_unique<MessageGiveaway>();
BEGIN_PARSE_FLAGS();
PARSE_FLAG(m->only_new_subscribers);
END_PARSE_FLAGS();
parse(m->channel_ids, parser);
parse(m->giveaway_parameters, parser);
parse(m->quantity, parser);
parse(m->months, parser);
parse(m->until_date, parser);
for (auto channel_id : m->channel_ids) {
if (!channel_id.is_valid()) {
is_bad = true;
}
if (!m->giveaway_parameters.is_valid()) {
is_bad = true;
}
content = std::move(m);
break;
@ -4333,8 +4322,8 @@ void merge_message_contents(Td *td, const MessageContent *old_content, MessageCo
case MessageContentType::Giveaway: {
const auto *old_ = static_cast<const MessageGiveaway *>(old_content);
const auto *new_ = static_cast<const MessageGiveaway *>(new_content);
if (old_->channel_ids != new_->channel_ids || old_->only_new_subscribers != new_->only_new_subscribers ||
old_->quantity != new_->quantity || old_->months != new_->months || old_->until_date != new_->until_date) {
if (old_->giveaway_parameters != new_->giveaway_parameters || old_->quantity != new_->quantity ||
old_->months != new_->months) {
need_update = true;
}
break;
@ -5245,8 +5234,11 @@ unique_ptr<MessageContent> get_message_content(Td *td, FormattedText message,
LOG(ERROR) << "Receive " << to_string(media);
break;
}
return td::make_unique<MessageGiveaway>(std::move(channel_ids), media->only_new_subscribers_, media->quantity_,
media->months_, media->until_date_);
auto boosted_channel_id = channel_ids[0];
channel_ids.erase(channel_ids.begin());
return td::make_unique<MessageGiveaway>(GiveawayParameters{boosted_channel_id, std::move(channel_ids),
media->only_new_subscribers_, media->until_date_},
media->quantity_, media->months_);
}
case telegram_api::messageMediaUnsupported::ID:
return make_unique<MessageUnsupported>();
@ -6276,14 +6268,8 @@ tl_object_ptr<td_api::MessageContent> get_message_content_object(const MessageCo
}
case MessageContentType::Giveaway: {
const auto *m = static_cast<const MessageGiveaway *>(content);
vector<int64> chat_ids;
for (auto channel_id : m->channel_ids) {
DialogId boosted_dialog_id(channel_id);
td->messages_manager_->force_create_dialog(boosted_dialog_id, "messageGiveaway", true);
chat_ids.push_back(td->messages_manager_->get_chat_id_object(boosted_dialog_id, "messageGiveaway"));
}
return td_api::make_object<td_api::messagePremiumGiveaway>(std::move(chat_ids), m->only_new_subscribers,
m->quantity, m->months, m->until_date);
return td_api::make_object<td_api::messagePremiumGiveaway>(
m->giveaway_parameters.get_premium_giveaway_parameters_object(td), m->quantity, m->months);
}
default:
UNREACHABLE();
@ -7027,9 +7013,7 @@ void add_message_content_dependencies(Dependencies &dependencies, const MessageC
}
case MessageContentType::Giveaway: {
const auto *content = static_cast<const MessageGiveaway *>(message_content);
for (auto channel_id : content->channel_ids) {
dependencies.add_dialog_and_dependencies(DialogId(channel_id));
}
content->giveaway_parameters.add_dependencies(dependencies);
break;
}
default:

View File

@ -9,6 +9,7 @@
#include "td/telegram/AccessRights.h"
#include "td/telegram/ContactsManager.h"
#include "td/telegram/DialogId.h"
#include "td/telegram/GiveawayParameters.h"
#include "td/telegram/Global.h"
#include "td/telegram/InputInvoice.h"
#include "td/telegram/MessageEntity.h"
@ -107,39 +108,11 @@ Result<InputInvoiceInfo> get_input_invoice_info(Td *td, td_api::object_ptr<td_ap
if (p->amount_ <= 0 || !check_currency_amount(p->amount_)) {
return Status::Error(400, "Invalid amount of the currency specified");
}
DialogId boosted_dialog_id(p->boosted_chat_id_);
TRY_RESULT(boost_input_peer, get_boost_input_peer(td, boosted_dialog_id));
if (boost_input_peer == nullptr) {
return Status::Error(400, "Boosted chat can't be empty");
}
vector<telegram_api::object_ptr<telegram_api::InputPeer>> additional_input_peers;
for (auto additional_chat_id : p->additional_chat_ids_) {
TRY_RESULT(input_peer, get_boost_input_peer(td, DialogId(additional_chat_id)));
if (input_peer == nullptr) {
return Status::Error(400, "Additional chat can't be empty");
}
additional_input_peers.push_back(std::move(input_peer));
}
int64 random_id;
do {
random_id = Random::secure_int64();
} while (random_id == 0);
int32 flags = 0;
if (p->only_new_subscribers_) {
flags |= telegram_api::inputStorePaymentPremiumGiveaway::ONLY_NEW_SUBSCRIBERS_MASK;
}
if (!additional_input_peers.empty()) {
flags |= telegram_api::inputStorePaymentPremiumGiveaway::ADDITIONAL_PEERS_MASK;
}
TRY_RESULT(parameters, GiveawayParameters::get_giveaway_parameters(td, p->parameters_.get()));
auto option = telegram_api::make_object<telegram_api::premiumGiftCodeOption>(
0, p->user_count_, p->month_count_, string(), 0, p->currency_, p->amount_);
auto purpose = telegram_api::make_object<telegram_api::inputStorePaymentPremiumGiveaway>(
flags, false /*ignored*/, std::move(boost_input_peer), std::move(additional_input_peers),
vector<string>(), random_id, p->date_, p->currency_, p->amount_);
result.input_invoice_ = telegram_api::make_object<telegram_api::inputInvoicePremiumGiftCode>(
std::move(purpose), std::move(option));
parameters.get_input_store_payment_premium_giveaway(td, p->currency_, p->amount_), std::move(option));
break;
}
default:

View File

@ -12,6 +12,7 @@
#include "td/telegram/DialogId.h"
#include "td/telegram/Document.h"
#include "td/telegram/DocumentsManager.h"
#include "td/telegram/GiveawayParameters.h"
#include "td/telegram/Global.h"
#include "td/telegram/MessageEntity.h"
#include "td/telegram/MessageSender.h"
@ -30,7 +31,6 @@
#include "td/utils/JsonBuilder.h"
#include "td/utils/logging.h"
#include "td/utils/misc.h"
#include "td/utils/Random.h"
#include "td/utils/SliceBuilder.h"
#include "td/utils/Status.h"
@ -164,34 +164,8 @@ static Result<tl_object_ptr<telegram_api::InputStorePaymentPurpose>> get_input_s
if (p->amount_ <= 0 || !check_currency_amount(p->amount_)) {
return Status::Error(400, "Invalid amount of the currency specified");
}
DialogId boosted_dialog_id(p->boosted_chat_id_);
TRY_RESULT(boost_input_peer, get_boost_input_peer(td, boosted_dialog_id));
if (boost_input_peer == nullptr) {
return Status::Error(400, "Boosted chat can't be empty");
}
vector<telegram_api::object_ptr<telegram_api::InputPeer>> additional_input_peers;
for (auto additional_chat_id : p->additional_chat_ids_) {
TRY_RESULT(input_peer, get_boost_input_peer(td, DialogId(additional_chat_id)));
if (input_peer == nullptr) {
return Status::Error(400, "Additional chat can't be empty");
}
additional_input_peers.push_back(std::move(input_peer));
}
int64 random_id;
do {
random_id = Random::secure_int64();
} while (random_id == 0);
int32 flags = 0;
if (p->only_new_subscribers_) {
flags |= telegram_api::inputStorePaymentPremiumGiveaway::ONLY_NEW_SUBSCRIBERS_MASK;
}
if (!additional_input_peers.empty()) {
flags |= telegram_api::inputStorePaymentPremiumGiveaway::ADDITIONAL_PEERS_MASK;
}
return telegram_api::make_object<telegram_api::inputStorePaymentPremiumGiveaway>(
flags, false /*ignored*/, std::move(boost_input_peer), std::move(additional_input_peers), vector<string>(),
random_id, p->date_, p->currency_, p->amount_);
TRY_RESULT(parameters, GiveawayParameters::get_giveaway_parameters(td, p->parameters_.get()));
return parameters.get_input_store_payment_premium_giveaway(td, p->currency_, p->amount_);
}
default:
UNREACHABLE();

View File

@ -3121,7 +3121,9 @@ class CliClient final : public Actor {
} else if (op == "cpprg") {
send_request(td_api::make_object<td_api::canPurchasePremium>(
td_api::make_object<td_api::storePaymentPurposePremiumGiveaway>(
boosted_chat_id, Auto(), static_cast<int32>(user_id) /*date*/, rand_bool(), currency, amount)));
td_api::make_object<td_api::premiumGiveawayParameters>(
boosted_chat_id, Auto(), static_cast<int32>(user_id) /*date*/, rand_bool()),
currency, amount)));
} else {
send_request(td_api::make_object<td_api::canPurchasePremium>(
td_api::make_object<td_api::storePaymentPurposePremiumGiftCodes>(boosted_chat_id, currency, amount,