From c73fa3ed72955457f67c480846e124bdc11fb5bf Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 30 Aug 2022 16:48:26 +0300 Subject: [PATCH] Add td_api::premiumStatus. --- td/generate/scheme/td_api.tl | 11 +++++++---- td/telegram/ContactsManager.cpp | 13 +++++++------ td/telegram/EmojiStatus.h | 11 ++++++++--- td/telegram/Td.cpp | 4 ++-- td/telegram/Td.h | 2 +- td/telegram/cli.cpp | 6 ++++-- 6 files changed, 29 insertions(+), 18 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 88c76f6b8..f6dd5aa46 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -475,6 +475,9 @@ chatAdministratorRights can_manage_chat:Bool can_change_info:Bool can_post_messa //@payment_link An internal link to be opened for buying Telegram Premium to the user if store payment isn't possible; may be null if direct payment isn't available premiumPaymentOption currency:string amount:int53 discount_percentage:int32 month_count:int32 store_product_id:string payment_link:InternalLinkType = PremiumPaymentOption; +//@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 +premiumStatus custom_emoji_id:int64 = PremiumStatus; + //@description Represents a user //@id User identifier @@ -484,7 +487,7 @@ premiumPaymentOption currency:string amount:int53 discount_percentage:int32 mont //@phone_number Phone number of the user //@status Current online status of the user //@profile_photo Profile photo of the user; may be null -//@premium_badge_custom_emoji_id Identifier of the custom emoji to be shown instead of the Telegram Premium badge; 0 if none. For Telegram Premium users only +//@premium_status Premium status to be shown instead of the default Telegram Premium badge; may be null. For Telegram Premium users only //@is_contact The user is a contact of the current user //@is_mutual_contact The user is a contact of the current user and the current user is a contact of the user //@is_verified True, if the user is verified @@ -497,7 +500,7 @@ premiumPaymentOption currency:string amount:int53 discount_percentage:int32 mont //@type Type of the user //@language_code IETF language tag of the user's language; only available to bots //@added_to_attachment_menu True, if the user added the current bot to attachment menu; only available to bots -user id:int53 first_name:string last_name:string username:string phone_number:string status:UserStatus profile_photo:profilePhoto premium_badge_custom_emoji_id:int64 is_contact:Bool is_mutual_contact:Bool is_verified:Bool is_premium:Bool is_support:Bool restriction_reason:string is_scam:Bool is_fake:Bool have_access:Bool type:UserType language_code:string added_to_attachment_menu:Bool = User; +user id:int53 first_name:string last_name:string username:string phone_number:string status:UserStatus profile_photo:profilePhoto premium_status:premiumStatus is_contact:Bool is_mutual_contact:Bool is_verified:Bool is_premium:Bool is_support:Bool restriction_reason:string is_scam:Bool is_fake:Bool have_access:Bool type:UserType language_code:string added_to_attachment_menu:Bool = User; //@description Contains information about a bot @@ -6075,8 +6078,8 @@ setBio bio:string = Ok; //@description Changes the username of the current user @username The new value of the username. Use an empty string to remove the username setUsername username:string = Ok; -//@description Changes the premium badge of the current user; for Telegram Premium users only @custom_emoji_id Identifier of the custom emoji to use as premium badge; pass 0 to switch to default badge. The custom emoji must have stickerFormatTgs -setPremiumBadge custom_emoji_id:int64 = Ok; +//@description Changes the premium status of the current user; for Telegram Premium users only @premium_status New premium status; pass null to switch to the default badge +setPremiumStatus premium_status:premiumStatus = Ok; //@description Changes the location of the current user. Needs to be called if GetOption("is_location_visible") is true and location changes for more than 1 kilometer @location The new location of the user setLocation location:location = Ok; diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index 5b9a5fb1f..3b7db0941 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -16745,8 +16745,8 @@ td_api::object_ptr ContactsManager::get_user_status_object(U td_api::object_ptr ContactsManager::get_update_unknown_user_object(UserId user_id) { return td_api::make_object(td_api::make_object( - user_id.get(), "", "", "", "", td_api::make_object(), nullptr, 0, false, false, false, - false, false, "", false, false, false, td_api::make_object(), "", false)); + user_id.get(), "", "", "", "", td_api::make_object(), nullptr, nullptr, false, false, + false, false, false, "", false, false, false, td_api::make_object(), "", false)); } int64 ContactsManager::get_user_id_object(UserId user_id, const char *source) const { @@ -16777,12 +16777,13 @@ tl_object_ptr ContactsManager::get_user_object(UserId user_id, con type = make_tl_object(); } - int64 premium_badge = u->is_premium ? u->emoji_status.get_premium_badge_object() : 0; + auto premium_status = u->is_premium ? u->emoji_status.get_premium_status_object() : nullptr; return make_tl_object( user_id.get(), u->first_name, u->last_name, u->username, u->phone_number, get_user_status_object(user_id, u), - get_profile_photo_object(td_->file_manager_.get(), u->photo), premium_badge, u->is_contact, u->is_mutual_contact, - u->is_verified, u->is_premium, u->is_support, get_restriction_reason_description(u->restriction_reasons), - u->is_scam, u->is_fake, u->is_received, std::move(type), u->language_code, u->attach_menu_enabled); + get_profile_photo_object(td_->file_manager_.get(), u->photo), std::move(premium_status), u->is_contact, + u->is_mutual_contact, u->is_verified, u->is_premium, u->is_support, + get_restriction_reason_description(u->restriction_reasons), u->is_scam, u->is_fake, u->is_received, + std::move(type), u->language_code, u->attach_menu_enabled); } vector ContactsManager::get_user_ids_object(const vector &user_ids, const char *source) const { diff --git a/td/telegram/EmojiStatus.h b/td/telegram/EmojiStatus.h index e29588ca0..f91257273 100644 --- a/td/telegram/EmojiStatus.h +++ b/td/telegram/EmojiStatus.h @@ -6,6 +6,7 @@ // #pragma once +#include "td/telegram/td_api.h" #include "td/telegram/telegram_api.h" #include "td/utils/common.h" @@ -24,7 +25,8 @@ class EmojiStatus { public: EmojiStatus() = default; - explicit EmojiStatus(int64 custom_emoji_id) : custom_emoji_id_(custom_emoji_id) { + explicit EmojiStatus(const td_api::object_ptr &premium_status) + : custom_emoji_id_(premium_status != nullptr ? premium_status->custom_emoji_id_ : 0) { } explicit EmojiStatus(tl_object_ptr &&emoji_status) { @@ -40,8 +42,11 @@ class EmojiStatus { return make_tl_object(custom_emoji_id_); } - int64 get_premium_badge_object() const { - return custom_emoji_id_; + td_api::object_ptr get_premium_status_object() const { + if (is_empty()) { + return nullptr; + } + return td_api::make_object(custom_emoji_id_); } bool is_empty() const { diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index ea4162e57..14d18a7eb 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -6727,10 +6727,10 @@ void Td::on_request(uint64 id, td_api::setUsername &request) { contacts_manager_->set_username(request.username_, std::move(promise)); } -void Td::on_request(uint64 id, const td_api::setPremiumBadge &request) { +void Td::on_request(uint64 id, const td_api::setPremiumStatus &request) { CHECK_IS_USER(); CREATE_OK_REQUEST_PROMISE(); - contacts_manager_->set_emoji_status(EmojiStatus(request.custom_emoji_id_), std::move(promise)); + contacts_manager_->set_emoji_status(EmojiStatus(request.premium_status_), std::move(promise)); } void Td::on_request(uint64 id, td_api::setCommands &request) { diff --git a/td/telegram/Td.h b/td/telegram/Td.h index bdda812a9..8efb02d9f 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -1012,7 +1012,7 @@ class Td final : public Actor { void on_request(uint64 id, td_api::setUsername &request); - void on_request(uint64 id, const td_api::setPremiumBadge &request); + void on_request(uint64 id, const td_api::setPremiumStatus &request); void on_request(uint64 id, td_api::setCommands &request); diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index ca4790c73..8970c8ca0 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -4473,8 +4473,10 @@ class CliClient final : public Actor { send_request(td_api::make_object("\n" + args + "\n" + args + "\n")); } else if (op == "sun") { send_request(td_api::make_object(args)); - } else if (op == "spb") { - send_request(td_api::make_object(to_integer(args))); + } else if (op == "sps") { + auto premium_status = + args.empty() ? nullptr : td_api::make_object(to_integer(args)); + send_request(td_api::make_object(std::move(premium_status))); } else if (op == "ccun") { ChatId chat_id; string username;