2022-05-24 00:21:03 +02:00
|
|
|
//
|
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2022
|
|
|
|
//
|
|
|
|
// 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/Premium.h"
|
|
|
|
|
2022-06-06 17:50:50 +02:00
|
|
|
#include "td/telegram/AnimationsManager.h"
|
2022-05-24 14:42:46 +02:00
|
|
|
#include "td/telegram/Application.h"
|
2022-05-24 00:36:55 +02:00
|
|
|
#include "td/telegram/ConfigShared.h"
|
2022-06-08 14:50:11 +02:00
|
|
|
#include "td/telegram/ContactsManager.h"
|
2022-06-02 15:19:16 +02:00
|
|
|
#include "td/telegram/DialogId.h"
|
|
|
|
#include "td/telegram/Document.h"
|
2022-06-01 14:14:09 +02:00
|
|
|
#include "td/telegram/DocumentsManager.h"
|
2022-05-24 00:36:55 +02:00
|
|
|
#include "td/telegram/Global.h"
|
2022-07-01 13:33:59 +02:00
|
|
|
#include "td/telegram/JsonValue.h"
|
2022-06-01 14:14:09 +02:00
|
|
|
#include "td/telegram/MessageEntity.h"
|
|
|
|
#include "td/telegram/Td.h"
|
2022-06-02 15:19:16 +02:00
|
|
|
#include "td/telegram/telegram_api.h"
|
2022-06-24 16:27:03 +02:00
|
|
|
#include "td/telegram/UpdatesManager.h"
|
2022-05-24 00:36:55 +02:00
|
|
|
|
2022-05-24 01:55:03 +02:00
|
|
|
#include "td/utils/algorithm.h"
|
2022-06-01 14:14:09 +02:00
|
|
|
#include "td/utils/buffer.h"
|
2022-07-01 13:33:59 +02:00
|
|
|
#include "td/utils/JsonBuilder.h"
|
2022-06-02 15:19:16 +02:00
|
|
|
#include "td/utils/logging.h"
|
|
|
|
#include "td/utils/misc.h"
|
2022-05-24 00:36:55 +02:00
|
|
|
#include "td/utils/SliceBuilder.h"
|
2022-06-02 15:19:16 +02:00
|
|
|
#include "td/utils/Status.h"
|
2022-05-24 00:36:55 +02:00
|
|
|
|
2022-05-24 00:21:03 +02:00
|
|
|
namespace td {
|
|
|
|
|
2022-06-01 14:14:09 +02:00
|
|
|
static td_api::object_ptr<td_api::PremiumFeature> get_premium_feature_object(Slice premium_feature) {
|
|
|
|
if (premium_feature == "double_limits") {
|
|
|
|
return td_api::make_object<td_api::premiumFeatureIncreasedLimits>();
|
|
|
|
}
|
|
|
|
if (premium_feature == "more_upload") {
|
|
|
|
return td_api::make_object<td_api::premiumFeatureIncreasedUploadFileSize>();
|
|
|
|
}
|
|
|
|
if (premium_feature == "faster_download") {
|
|
|
|
return td_api::make_object<td_api::premiumFeatureImprovedDownloadSpeed>();
|
|
|
|
}
|
|
|
|
if (premium_feature == "voice_to_text") {
|
|
|
|
return td_api::make_object<td_api::premiumFeatureVoiceRecognition>();
|
|
|
|
}
|
|
|
|
if (premium_feature == "no_ads") {
|
|
|
|
return td_api::make_object<td_api::premiumFeatureDisabledAds>();
|
|
|
|
}
|
|
|
|
if (premium_feature == "unique_reactions") {
|
|
|
|
return td_api::make_object<td_api::premiumFeatureUniqueReactions>();
|
|
|
|
}
|
|
|
|
if (premium_feature == "premium_stickers") {
|
|
|
|
return td_api::make_object<td_api::premiumFeatureUniqueStickers>();
|
|
|
|
}
|
|
|
|
if (premium_feature == "advanced_chat_management") {
|
|
|
|
return td_api::make_object<td_api::premiumFeatureAdvancedChatManagement>();
|
|
|
|
}
|
|
|
|
if (premium_feature == "profile_badge") {
|
|
|
|
return td_api::make_object<td_api::premiumFeatureProfileBadge>();
|
|
|
|
}
|
|
|
|
if (premium_feature == "animated_userpics") {
|
|
|
|
return td_api::make_object<td_api::premiumFeatureAnimatedProfilePhoto>();
|
|
|
|
}
|
2022-06-01 16:19:05 +02:00
|
|
|
if (premium_feature == "app_icons") {
|
|
|
|
return td_api::make_object<td_api::premiumFeatureAppIcons>();
|
|
|
|
}
|
2022-06-01 14:14:09 +02:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2022-07-01 18:27:59 +02:00
|
|
|
static Result<tl_object_ptr<telegram_api::InputStorePaymentPurpose>> get_input_store_payment_purpose(
|
|
|
|
Td *td, const td_api::object_ptr<td_api::StorePaymentPurpose> &purpose) {
|
|
|
|
if (purpose == nullptr) {
|
|
|
|
return Status::Error(400, "Purchase purpose must be non-empty");
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (purpose->get_id()) {
|
|
|
|
case td_api::storePaymentPurposePremiumSubscription::ID: {
|
|
|
|
auto p = static_cast<const td_api::storePaymentPurposePremiumSubscription *>(purpose.get());
|
|
|
|
int32 flags = 0;
|
|
|
|
if (p->is_restore_) {
|
|
|
|
flags |= telegram_api::inputStorePaymentPremiumSubscription::RESTORE_MASK;
|
|
|
|
}
|
|
|
|
return make_tl_object<telegram_api::inputStorePaymentPremiumSubscription>(flags, false /*ignored*/);
|
|
|
|
}
|
|
|
|
case td_api::storePaymentPurposeGiftedPremium::ID: {
|
|
|
|
auto p = static_cast<const td_api::storePaymentPurposeGiftedPremium *>(purpose.get());
|
|
|
|
UserId user_id(p->user_id_);
|
|
|
|
TRY_RESULT(input_user, td->contacts_manager_->get_input_user(user_id));
|
|
|
|
return make_tl_object<telegram_api::inputStorePaymentGiftPremium>(std::move(input_user), p->currency_,
|
|
|
|
p->amount_);
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-01 14:14:09 +02:00
|
|
|
class GetPremiumPromoQuery final : public Td::ResultHandler {
|
|
|
|
Promise<td_api::object_ptr<td_api::premiumState>> promise_;
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit GetPremiumPromoQuery(Promise<td_api::object_ptr<td_api::premiumState>> &&promise)
|
|
|
|
: promise_(std::move(promise)) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void send() {
|
|
|
|
send_query(G()->net_query_creator().create(telegram_api::help_getPremiumPromo()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void on_result(BufferSlice packet) final {
|
|
|
|
auto result_ptr = fetch_result<telegram_api::help_getPremiumPromo>(packet);
|
|
|
|
if (result_ptr.is_error()) {
|
|
|
|
return on_error(result_ptr.move_as_error());
|
|
|
|
}
|
|
|
|
|
|
|
|
auto promo = result_ptr.move_as_ok();
|
|
|
|
LOG(INFO) << "Receive result for GetPremiumPromoQuery: " << to_string(promo);
|
|
|
|
|
2022-06-08 14:50:11 +02:00
|
|
|
td_->contacts_manager_->on_get_users(std::move(promo->users_), "GetPremiumPromoQuery");
|
|
|
|
|
2022-06-01 14:14:09 +02:00
|
|
|
auto state = get_message_text(td_->contacts_manager_.get(), std::move(promo->status_text_),
|
|
|
|
std::move(promo->status_entities_), true, true, 0, false, "GetPremiumPromoQuery");
|
|
|
|
|
|
|
|
if (promo->video_sections_.size() != promo->videos_.size()) {
|
|
|
|
return on_error(Status::Error(500, "Receive wrong number of videos"));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (promo->monthly_amount_ < 0 || promo->monthly_amount_ > 9999'9999'9999) {
|
|
|
|
return on_error(Status::Error(500, "Receive invalid monthly amount"));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (promo->currency_.size() != 3) {
|
|
|
|
return on_error(Status::Error(500, "Receive invalid currency"));
|
|
|
|
}
|
|
|
|
|
2022-06-06 17:50:50 +02:00
|
|
|
vector<td_api::object_ptr<td_api::premiumFeaturePromotionAnimation>> animations;
|
2022-06-01 14:14:09 +02:00
|
|
|
for (size_t i = 0; i < promo->video_sections_.size(); i++) {
|
|
|
|
auto feature = get_premium_feature_object(promo->video_sections_[i]);
|
|
|
|
if (feature == nullptr) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto video = std::move(promo->videos_[i]);
|
|
|
|
if (video->get_id() != telegram_api::document::ID) {
|
|
|
|
LOG(ERROR) << "Receive " << to_string(video) << " for " << promo->video_sections_[i];
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto parsed_document = td_->documents_manager_->on_get_document(move_tl_object_as<telegram_api::document>(video),
|
2022-06-06 17:50:50 +02:00
|
|
|
DialogId(), nullptr, Document::Type::Animation);
|
2022-06-01 14:14:09 +02:00
|
|
|
|
2022-06-06 17:50:50 +02:00
|
|
|
if (parsed_document.type != Document::Type::Animation) {
|
2022-06-01 14:14:09 +02:00
|
|
|
LOG(ERROR) << "Receive " << parsed_document.type << " for " << promo->video_sections_[i];
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2022-06-06 17:50:50 +02:00
|
|
|
auto animation_object = td_->animations_manager_->get_animation_object(parsed_document.file_id);
|
|
|
|
animations.push_back(td_api::make_object<td_api::premiumFeaturePromotionAnimation>(std::move(feature),
|
|
|
|
std::move(animation_object)));
|
2022-06-01 14:14:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
promise_.set_value(td_api::make_object<td_api::premiumState>(get_formatted_text_object(state, true, 0),
|
|
|
|
std::move(promo->currency_), promo->monthly_amount_,
|
2022-06-06 17:50:50 +02:00
|
|
|
std::move(animations)));
|
2022-06-01 14:14:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void on_error(Status status) final {
|
|
|
|
promise_.set_error(std::move(status));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-06-24 16:07:10 +02:00
|
|
|
class CanPurchasePremiumQuery final : public Td::ResultHandler {
|
|
|
|
Promise<Unit> promise_;
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit CanPurchasePremiumQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void send() {
|
2022-07-01 13:33:59 +02:00
|
|
|
send_query(G()->net_query_creator().create(telegram_api::payments_canPurchasePremium(
|
|
|
|
make_tl_object<telegram_api::inputStorePaymentPremiumSubscription>(0, false /*ignored*/))));
|
2022-06-24 16:07:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void on_result(BufferSlice packet) final {
|
|
|
|
auto result_ptr = fetch_result<telegram_api::payments_canPurchasePremium>(packet);
|
|
|
|
if (result_ptr.is_error()) {
|
|
|
|
return on_error(result_ptr.move_as_error());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool result = result_ptr.ok();
|
|
|
|
if (result) {
|
|
|
|
return promise_.set_value(Unit());
|
|
|
|
}
|
|
|
|
on_error(Status::Error(400, "Premium can't be purchased"));
|
|
|
|
}
|
|
|
|
|
|
|
|
void on_error(Status status) final {
|
|
|
|
promise_.set_error(std::move(status));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-06-24 17:14:00 +02:00
|
|
|
class AssignAppStoreTransactionQuery final : public Td::ResultHandler {
|
|
|
|
Promise<Unit> promise_;
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit AssignAppStoreTransactionQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
|
|
|
|
}
|
|
|
|
|
2022-07-01 18:27:59 +02:00
|
|
|
void send(const string &receipt, td_api::object_ptr<td_api::StorePaymentPurpose> &&purpose) {
|
|
|
|
auto r_input_purpose = get_input_store_payment_purpose(td_, purpose);
|
|
|
|
if (r_input_purpose.is_error()) {
|
|
|
|
return on_error(r_input_purpose.move_as_error());
|
2022-06-24 17:14:00 +02:00
|
|
|
}
|
2022-07-01 18:27:59 +02:00
|
|
|
|
|
|
|
send_query(G()->net_query_creator().create(
|
|
|
|
telegram_api::payments_assignAppStoreTransaction(BufferSlice(receipt), r_input_purpose.move_as_ok())));
|
2022-06-24 17:14:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void on_result(BufferSlice packet) final {
|
|
|
|
auto result_ptr = fetch_result<telegram_api::payments_assignAppStoreTransaction>(packet);
|
|
|
|
if (result_ptr.is_error()) {
|
|
|
|
return on_error(result_ptr.move_as_error());
|
|
|
|
}
|
|
|
|
|
|
|
|
auto ptr = result_ptr.move_as_ok();
|
|
|
|
LOG(INFO) << "Receive result for AssignAppStoreTransactionQuery: " << to_string(ptr);
|
|
|
|
td_->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_));
|
|
|
|
}
|
|
|
|
|
|
|
|
void on_error(Status status) final {
|
|
|
|
promise_.set_error(std::move(status));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-06-24 16:27:03 +02:00
|
|
|
class AssignPlayMarketTransactionQuery final : public Td::ResultHandler {
|
|
|
|
Promise<Unit> promise_;
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit AssignPlayMarketTransactionQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
|
|
|
|
}
|
|
|
|
|
2022-07-01 18:27:59 +02:00
|
|
|
void send(const string &purchase_token, td_api::object_ptr<td_api::StorePaymentPurpose> &&purpose) {
|
|
|
|
auto r_input_purpose = get_input_store_payment_purpose(td_, purpose);
|
|
|
|
if (r_input_purpose.is_error()) {
|
|
|
|
return on_error(r_input_purpose.move_as_error());
|
|
|
|
}
|
2022-07-01 13:33:59 +02:00
|
|
|
auto receipt = make_tl_object<telegram_api::dataJSON>(string());
|
|
|
|
receipt->data_ =
|
|
|
|
json_encode<string>(json_object([&purchase_token](auto &o) { o("purchase_token", purchase_token); }));
|
2022-07-01 18:27:59 +02:00
|
|
|
send_query(G()->net_query_creator().create(
|
|
|
|
telegram_api::payments_assignPlayMarketTransaction(std::move(receipt), r_input_purpose.move_as_ok())));
|
2022-06-24 16:27:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void on_result(BufferSlice packet) final {
|
|
|
|
auto result_ptr = fetch_result<telegram_api::payments_assignPlayMarketTransaction>(packet);
|
|
|
|
if (result_ptr.is_error()) {
|
|
|
|
return on_error(result_ptr.move_as_error());
|
|
|
|
}
|
|
|
|
|
|
|
|
auto ptr = result_ptr.move_as_ok();
|
|
|
|
LOG(INFO) << "Receive result for AssignPlayMarketTransactionQuery: " << to_string(ptr);
|
|
|
|
td_->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_));
|
|
|
|
}
|
|
|
|
|
|
|
|
void on_error(Status status) final {
|
|
|
|
promise_.set_error(std::move(status));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-05-24 00:21:03 +02:00
|
|
|
const vector<Slice> &get_premium_limit_keys() {
|
2022-05-24 01:59:11 +02:00
|
|
|
static const vector<Slice> limit_keys{"channels",
|
|
|
|
"saved_gifs",
|
|
|
|
"stickers_faved",
|
|
|
|
"dialog_filters",
|
|
|
|
"dialog_filters_chats",
|
|
|
|
"dialogs_pinned",
|
|
|
|
"dialogs_folder_pinned",
|
|
|
|
"channels_public",
|
2022-05-30 01:20:12 +02:00
|
|
|
"caption_length",
|
|
|
|
"about_length"};
|
2022-05-24 00:21:03 +02:00
|
|
|
return limit_keys;
|
|
|
|
}
|
|
|
|
|
2022-05-24 01:55:03 +02:00
|
|
|
static Slice get_limit_type_key(const td_api::PremiumLimitType *limit_type) {
|
|
|
|
CHECK(limit_type != nullptr);
|
|
|
|
switch (limit_type->get_id()) {
|
|
|
|
case td_api::premiumLimitTypeSupergroupCount::ID:
|
|
|
|
return Slice("channels");
|
|
|
|
case td_api::premiumLimitTypeSavedAnimationCount::ID:
|
|
|
|
return Slice("saved_gifs");
|
|
|
|
case td_api::premiumLimitTypeFavoriteStickerCount::ID:
|
|
|
|
return Slice("stickers_faved");
|
|
|
|
case td_api::premiumLimitTypeChatFilterCount::ID:
|
|
|
|
return Slice("dialog_filters");
|
|
|
|
case td_api::premiumLimitTypeChatFilterChosenChatCount::ID:
|
|
|
|
return Slice("dialog_filters_chats");
|
|
|
|
case td_api::premiumLimitTypePinnedChatCount::ID:
|
|
|
|
return Slice("dialogs_pinned");
|
|
|
|
case td_api::premiumLimitTypePinnedArchivedChatCount::ID:
|
|
|
|
return Slice("dialogs_folder_pinned");
|
|
|
|
case td_api::premiumLimitTypeCreatedPublicChatCount::ID:
|
|
|
|
return Slice("channels_public");
|
|
|
|
case td_api::premiumLimitTypeCaptionLength::ID:
|
|
|
|
return Slice("caption_length");
|
2022-05-30 01:20:12 +02:00
|
|
|
case td_api::premiumLimitTypeBioLength::ID:
|
|
|
|
return Slice("about_length");
|
2022-05-24 01:55:03 +02:00
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
return Slice();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-24 01:19:30 +02:00
|
|
|
static string get_premium_source(const td_api::PremiumLimitType *limit_type) {
|
|
|
|
if (limit_type == nullptr) {
|
|
|
|
return string();
|
|
|
|
}
|
|
|
|
|
2022-05-24 01:55:03 +02:00
|
|
|
return PSTRING() << "double_limits__" << get_limit_type_key(limit_type);
|
2022-05-24 01:19:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static string get_premium_source(const td_api::PremiumFeature *feature) {
|
|
|
|
if (feature == nullptr) {
|
|
|
|
return string();
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (feature->get_id()) {
|
|
|
|
case td_api::premiumFeatureIncreasedLimits::ID:
|
|
|
|
return "double_limits";
|
2022-05-24 19:17:51 +02:00
|
|
|
case td_api::premiumFeatureIncreasedUploadFileSize::ID:
|
2022-05-24 01:19:30 +02:00
|
|
|
return "more_upload";
|
|
|
|
case td_api::premiumFeatureImprovedDownloadSpeed::ID:
|
|
|
|
return "faster_download";
|
|
|
|
case td_api::premiumFeatureVoiceRecognition::ID:
|
|
|
|
return "voice_to_text";
|
|
|
|
case td_api::premiumFeatureDisabledAds::ID:
|
|
|
|
return "no_ads";
|
|
|
|
case td_api::premiumFeatureUniqueReactions::ID:
|
|
|
|
return "unique_reactions";
|
|
|
|
case td_api::premiumFeatureUniqueStickers::ID:
|
|
|
|
return "premium_stickers";
|
|
|
|
case td_api::premiumFeatureAdvancedChatManagement::ID:
|
|
|
|
return "advanced_chat_management";
|
|
|
|
case td_api::premiumFeatureProfileBadge::ID:
|
|
|
|
return "profile_badge";
|
|
|
|
case td_api::premiumFeatureAnimatedProfilePhoto::ID:
|
|
|
|
return "animated_userpics";
|
2022-06-01 16:19:05 +02:00
|
|
|
case td_api::premiumFeatureAppIcons::ID:
|
|
|
|
return "app_icons";
|
2022-05-24 01:19:30 +02:00
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
return string();
|
|
|
|
}
|
|
|
|
|
|
|
|
static string get_premium_source(const td_api::object_ptr<td_api::PremiumSource> &source) {
|
|
|
|
if (source == nullptr) {
|
|
|
|
return string();
|
|
|
|
}
|
|
|
|
switch (source->get_id()) {
|
|
|
|
case td_api::premiumSourceLimitExceeded::ID: {
|
|
|
|
auto *limit_type = static_cast<const td_api::premiumSourceLimitExceeded *>(source.get())->limit_type_.get();
|
|
|
|
return get_premium_source(limit_type);
|
|
|
|
}
|
|
|
|
case td_api::premiumSourceFeature::ID: {
|
|
|
|
auto *feature = static_cast<const td_api::premiumSourceFeature *>(source.get())->feature_.get();
|
|
|
|
return get_premium_source(feature);
|
|
|
|
}
|
|
|
|
case td_api::premiumSourceLink::ID: {
|
|
|
|
auto &referrer = static_cast<const td_api::premiumSourceLink *>(source.get())->referrer_;
|
|
|
|
if (referrer.empty()) {
|
|
|
|
return "deeplink";
|
|
|
|
}
|
|
|
|
return PSTRING() << "deeplink_" << referrer;
|
|
|
|
}
|
|
|
|
case td_api::premiumSourceSettings::ID:
|
|
|
|
return "settings";
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
return string();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-24 01:55:03 +02:00
|
|
|
static td_api::object_ptr<td_api::premiumLimit> get_premium_limit_object(Slice key) {
|
2022-05-24 01:59:11 +02:00
|
|
|
int32 default_limit =
|
|
|
|
static_cast<int32>(G()->shared_config().get_option_integer(PSLICE() << key << "_limit_default"));
|
|
|
|
int32 premium_limit =
|
|
|
|
static_cast<int32>(G()->shared_config().get_option_integer(PSLICE() << key << "_limit_premium"));
|
2022-05-24 01:55:03 +02:00
|
|
|
if (default_limit <= 0 || premium_limit <= default_limit) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
auto type = [&]() -> td_api::object_ptr<td_api::PremiumLimitType> {
|
2022-05-24 01:59:11 +02:00
|
|
|
if (key == "channels") {
|
2022-05-24 01:55:03 +02:00
|
|
|
return td_api::make_object<td_api::premiumLimitTypeSupergroupCount>();
|
|
|
|
}
|
2022-05-24 01:59:11 +02:00
|
|
|
if (key == "saved_gifs") {
|
2022-05-24 01:55:03 +02:00
|
|
|
return td_api::make_object<td_api::premiumLimitTypeSavedAnimationCount>();
|
|
|
|
}
|
2022-05-24 01:59:11 +02:00
|
|
|
if (key == "stickers_faved") {
|
2022-05-24 01:55:03 +02:00
|
|
|
return td_api::make_object<td_api::premiumLimitTypeFavoriteStickerCount>();
|
|
|
|
}
|
2022-05-24 01:59:11 +02:00
|
|
|
if (key == "dialog_filters") {
|
2022-05-24 01:55:03 +02:00
|
|
|
return td_api::make_object<td_api::premiumLimitTypeChatFilterCount>();
|
|
|
|
}
|
2022-05-24 01:59:11 +02:00
|
|
|
if (key == "dialog_filters_chats") {
|
2022-05-24 01:55:03 +02:00
|
|
|
return td_api::make_object<td_api::premiumLimitTypeChatFilterChosenChatCount>();
|
|
|
|
}
|
2022-05-24 01:59:11 +02:00
|
|
|
if (key == "dialogs_pinned") {
|
2022-05-24 01:55:03 +02:00
|
|
|
return td_api::make_object<td_api::premiumLimitTypePinnedChatCount>();
|
|
|
|
}
|
2022-05-24 01:59:11 +02:00
|
|
|
if (key == "dialogs_folder_pinned") {
|
2022-05-24 01:55:03 +02:00
|
|
|
return td_api::make_object<td_api::premiumLimitTypePinnedArchivedChatCount>();
|
|
|
|
}
|
2022-05-24 01:59:11 +02:00
|
|
|
if (key == "channels_public") {
|
2022-05-24 01:55:03 +02:00
|
|
|
return td_api::make_object<td_api::premiumLimitTypeCreatedPublicChatCount>();
|
|
|
|
}
|
2022-05-24 01:59:11 +02:00
|
|
|
if (key == "caption_length") {
|
2022-05-24 01:55:03 +02:00
|
|
|
return td_api::make_object<td_api::premiumLimitTypeCaptionLength>();
|
|
|
|
}
|
2022-05-30 01:20:12 +02:00
|
|
|
if (key == "about_length") {
|
|
|
|
return td_api::make_object<td_api::premiumLimitTypeBioLength>();
|
|
|
|
}
|
2022-05-24 01:55:03 +02:00
|
|
|
UNREACHABLE();
|
|
|
|
return nullptr;
|
|
|
|
}();
|
|
|
|
return td_api::make_object<td_api::premiumLimit>(std::move(type), default_limit, premium_limit);
|
|
|
|
}
|
|
|
|
|
|
|
|
void get_premium_limit(const td_api::object_ptr<td_api::PremiumLimitType> &limit_type,
|
|
|
|
Promise<td_api::object_ptr<td_api::premiumLimit>> &&promise) {
|
|
|
|
if (limit_type == nullptr) {
|
|
|
|
return promise.set_error(Status::Error(400, "Limit type must be non-empty"));
|
|
|
|
}
|
|
|
|
|
2022-05-24 01:59:11 +02:00
|
|
|
promise.set_value(get_premium_limit_object(get_limit_type_key(limit_type.get())));
|
2022-05-24 01:55:03 +02:00
|
|
|
}
|
|
|
|
|
2022-05-24 14:42:46 +02:00
|
|
|
void get_premium_features(Td *td, const td_api::object_ptr<td_api::PremiumSource> &source,
|
2022-05-24 01:19:30 +02:00
|
|
|
Promise<td_api::object_ptr<td_api::premiumFeatures>> &&promise) {
|
2022-05-24 00:36:55 +02:00
|
|
|
auto premium_features =
|
|
|
|
full_split(G()->shared_config().get_option_string(
|
|
|
|
"premium_features",
|
|
|
|
"double_limits,more_upload,faster_download,voice_to_text,no_ads,unique_reactions,premium_stickers,"
|
2022-06-01 16:19:05 +02:00
|
|
|
"advanced_chat_management,profile_badge,animated_userpics,app_icons"),
|
2022-05-24 00:36:55 +02:00
|
|
|
',');
|
|
|
|
vector<td_api::object_ptr<td_api::PremiumFeature>> features;
|
|
|
|
for (const auto &premium_feature : premium_features) {
|
2022-06-01 14:14:09 +02:00
|
|
|
auto feature = get_premium_feature_object(premium_feature);
|
2022-05-24 00:36:55 +02:00
|
|
|
if (feature != nullptr) {
|
|
|
|
features.push_back(std::move(feature));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-24 01:55:03 +02:00
|
|
|
auto limits = transform(get_premium_limit_keys(), get_premium_limit_object);
|
|
|
|
td::remove_if(limits, [](auto &limit) { return limit == nullptr; });
|
2022-05-24 01:19:30 +02:00
|
|
|
|
|
|
|
auto source_str = get_premium_source(source);
|
2022-05-24 14:42:46 +02:00
|
|
|
if (!source_str.empty()) {
|
|
|
|
vector<tl_object_ptr<telegram_api::jsonObjectValue>> data;
|
|
|
|
vector<tl_object_ptr<telegram_api::JSONValue>> promo_order;
|
|
|
|
for (const auto &premium_feature : premium_features) {
|
|
|
|
promo_order.push_back(make_tl_object<telegram_api::jsonString>(premium_feature));
|
|
|
|
}
|
|
|
|
data.push_back(make_tl_object<telegram_api::jsonObjectValue>(
|
|
|
|
"premium_promo_order", make_tl_object<telegram_api::jsonArray>(std::move(promo_order))));
|
|
|
|
data.push_back(
|
|
|
|
make_tl_object<telegram_api::jsonObjectValue>("source", make_tl_object<telegram_api::jsonString>(source_str)));
|
|
|
|
save_app_log(td, "premium.promo_screen_show", DialogId(), make_tl_object<telegram_api::jsonObject>(std::move(data)),
|
|
|
|
Promise<Unit>());
|
|
|
|
}
|
2022-05-24 01:19:30 +02:00
|
|
|
|
2022-05-24 15:30:01 +02:00
|
|
|
td_api::object_ptr<td_api::InternalLinkType> payment_link;
|
|
|
|
auto premium_bot_username = G()->shared_config().get_option_string("premium_bot_username");
|
|
|
|
if (!premium_bot_username.empty()) {
|
2022-07-01 15:21:29 +02:00
|
|
|
payment_link = td_api::make_object<td_api::internalLinkTypeBotStart>(premium_bot_username, source_str, true);
|
2022-05-24 15:30:01 +02:00
|
|
|
} else {
|
|
|
|
auto premium_invoice_slug = G()->shared_config().get_option_string("premium_invoice_slug");
|
|
|
|
if (!premium_invoice_slug.empty()) {
|
|
|
|
payment_link = td_api::make_object<td_api::internalLinkTypeInvoice>(premium_invoice_slug);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
promise.set_value(
|
|
|
|
td_api::make_object<td_api::premiumFeatures>(std::move(features), std::move(limits), std::move(payment_link)));
|
2022-05-24 00:36:55 +02:00
|
|
|
}
|
|
|
|
|
2022-05-24 19:45:03 +02:00
|
|
|
void view_premium_feature(Td *td, const td_api::object_ptr<td_api::PremiumFeature> &feature, Promise<Unit> &&promise) {
|
|
|
|
auto source = get_premium_source(feature.get());
|
|
|
|
if (source.empty()) {
|
|
|
|
return promise.set_error(Status::Error(400, "Feature must be non-empty"));
|
|
|
|
}
|
|
|
|
|
|
|
|
vector<tl_object_ptr<telegram_api::jsonObjectValue>> data;
|
|
|
|
data.push_back(
|
|
|
|
make_tl_object<telegram_api::jsonObjectValue>("item", make_tl_object<telegram_api::jsonString>(source)));
|
|
|
|
save_app_log(td, "premium.promo_screen_tap", DialogId(), make_tl_object<telegram_api::jsonObject>(std::move(data)),
|
|
|
|
std::move(promise));
|
|
|
|
}
|
|
|
|
|
2022-05-25 14:34:36 +02:00
|
|
|
void click_premium_subscription_button(Td *td, Promise<Unit> &&promise) {
|
|
|
|
vector<tl_object_ptr<telegram_api::jsonObjectValue>> data;
|
|
|
|
save_app_log(td, "premium.promo_screen_accept", DialogId(), make_tl_object<telegram_api::jsonObject>(std::move(data)),
|
|
|
|
std::move(promise));
|
|
|
|
}
|
|
|
|
|
2022-06-01 14:14:09 +02:00
|
|
|
void get_premium_state(Td *td, Promise<td_api::object_ptr<td_api::premiumState>> &&promise) {
|
|
|
|
td->create_handler<GetPremiumPromoQuery>(std::move(promise))->send();
|
|
|
|
}
|
|
|
|
|
2022-06-24 16:07:10 +02:00
|
|
|
void can_purchase_premium(Td *td, Promise<Unit> &&promise) {
|
|
|
|
td->create_handler<CanPurchasePremiumQuery>(std::move(promise))->send();
|
|
|
|
}
|
|
|
|
|
2022-07-01 18:27:59 +02:00
|
|
|
void assign_app_store_transaction(Td *td, const string &receipt,
|
|
|
|
td_api::object_ptr<td_api::StorePaymentPurpose> &&purpose, Promise<Unit> &&promise) {
|
|
|
|
td->create_handler<AssignAppStoreTransactionQuery>(std::move(promise))->send(receipt, std::move(purpose));
|
2022-06-24 17:14:00 +02:00
|
|
|
}
|
|
|
|
|
2022-07-01 18:27:59 +02:00
|
|
|
void assign_play_market_transaction(Td *td, const string &purchase_token,
|
|
|
|
td_api::object_ptr<td_api::StorePaymentPurpose> &&purpose,
|
|
|
|
Promise<Unit> &&promise) {
|
|
|
|
td->create_handler<AssignPlayMarketTransactionQuery>(std::move(promise))->send(purchase_token, std::move(purpose));
|
2022-06-24 16:27:03 +02:00
|
|
|
}
|
|
|
|
|
2022-05-24 00:21:03 +02:00
|
|
|
} // namespace td
|