Add td_api::getDefaultPremiumStatuses.

This commit is contained in:
levlam 2022-08-30 18:03:57 +03:00
parent cefcf9e018
commit 31ec06a134
7 changed files with 75 additions and 0 deletions

View File

@ -478,6 +478,9 @@ premiumPaymentOption currency:string amount:int53 discount_percentage:int32 mont
//@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 Contains a list of premium statuses @premium_statuses The list of premium statuses
premiumStatuses premium_statuses:vector<premiumStatus> = PremiumStatuses;
//@description Represents a user
//@id User identifier
@ -5572,6 +5575,10 @@ getAttachmentMenuBot bot_user_id:int53 = AttachmentMenuBot;
toggleBotIsAddedToAttachmentMenu bot_user_id:int53 is_added:Bool = Ok;
//@description Returns default premium statuses
getDefaultPremiumStatuses = PremiumStatuses;
//@description Downloads a file from the cloud. Download progress and completion of the download will be notified through updateFile updates
//@file_id Identifier of the file to download
//@priority Priority of the download (1-32). The higher the priority, the earlier the file will be downloaded. If the priorities of two files are equal, then the last one for which downloadFile/addFileToDownloads was called will be downloaded first

View File

@ -6,8 +6,55 @@
//
#include "td/telegram/EmojiStatus.h"
#include "td/telegram/Global.h"
#include "td/telegram/Td.h"
#include "td/utils/buffer.h"
#include "td/utils/Status.h"
namespace td {
class GetDefaultEmojiStatusesQuery final : public Td::ResultHandler {
Promise<td_api::object_ptr<td_api::premiumStatuses>> promise_;
public:
explicit GetDefaultEmojiStatusesQuery(Promise<td_api::object_ptr<td_api::premiumStatuses>> &&promise)
: promise_(std::move(promise)) {
}
void send(int64 hash) {
send_query(G()->net_query_creator().create(telegram_api::account_getDefaultEmojiStatuses(hash)));
}
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::account_getDefaultEmojiStatuses>(packet);
if (result_ptr.is_error()) {
return on_error(result_ptr.move_as_error());
}
auto emoji_statuses_ptr = result_ptr.move_as_ok();
LOG(INFO) << "Receive result for GetDefaultEmojiStatusesQuery: " << to_string(emoji_statuses_ptr);
auto result = td_api::make_object<td_api::premiumStatuses>();
if (emoji_statuses_ptr->get_id() == telegram_api::account_emojiStatuses::ID) {
auto emoji_statuses = move_tl_object_as<telegram_api::account_emojiStatuses>(emoji_statuses_ptr);
for (auto &status : emoji_statuses->statuses_) {
EmojiStatus emoji_status(std::move(status));
if (emoji_status.is_empty()) {
LOG(ERROR) << "Receive empty default emoji status";
continue;
}
result->premium_statuses_.push_back(emoji_status.get_premium_status_object());
}
}
promise_.set_value(std::move(result));
}
void on_error(Status status) final {
promise_.set_error(std::move(status));
}
};
EmojiStatus::EmojiStatus(const td_api::object_ptr<td_api::premiumStatus> &premium_status)
: custom_emoji_id_(premium_status != nullptr ? premium_status->custom_emoji_id_ : 0) {
}
@ -39,4 +86,8 @@ StringBuilder &operator<<(StringBuilder &string_builder, const EmojiStatus &emoj
return string_builder << "CustomEmoji " << emoji_status.custom_emoji_id_;
}
void get_default_emoji_statuses(Td *td, Promise<td_api::object_ptr<td_api::premiumStatuses>> &&promise) {
td->create_handler<GetDefaultEmojiStatusesQuery>(std::move(promise))->send(0);
}
} // namespace td

View File

@ -10,11 +10,14 @@
#include "td/telegram/telegram_api.h"
#include "td/utils/common.h"
#include "td/utils/Promise.h"
#include "td/utils/StringBuilder.h"
#include "td/utils/tl_helpers.h"
namespace td {
class Td;
class EmojiStatus {
int64 custom_emoji_id_ = 0;
@ -58,4 +61,6 @@ inline bool operator!=(const EmojiStatus &lhs, const EmojiStatus &rhs) {
StringBuilder &operator<<(StringBuilder &string_builder, const EmojiStatus &emoji_status);
void get_default_emoji_statuses(Td *td, Promise<td_api::object_ptr<td_api::premiumStatuses>> &&promise);
} // namespace td

View File

@ -6733,6 +6733,12 @@ void Td::on_request(uint64 id, const td_api::setPremiumStatus &request) {
contacts_manager_->set_emoji_status(EmojiStatus(request.premium_status_), std::move(promise));
}
void Td::on_request(uint64 id, const td_api::getDefaultPremiumStatuses &request) {
CHECK_IS_USER();
CREATE_REQUEST_PROMISE();
get_default_emoji_statuses(this, std::move(promise));
}
void Td::on_request(uint64 id, td_api::setCommands &request) {
CHECK_IS_BOT();
CREATE_OK_REQUEST_PROMISE();

View File

@ -1014,6 +1014,8 @@ class Td final : public Actor {
void on_request(uint64 id, const td_api::setPremiumStatus &request);
void on_request(uint64 id, const td_api::getDefaultPremiumStatuses &request);
void on_request(uint64 id, td_api::setCommands &request);
void on_request(uint64 id, td_api::deleteCommands &request);

View File

@ -20,6 +20,7 @@
#include "td/telegram/DialogInviteLink.h"
#include "td/telegram/DialogParticipant.h"
#include "td/telegram/DownloadManager.h"
#include "td/telegram/EmojiStatus.h"
#include "td/telegram/FolderId.h"
#include "td/telegram/Global.h"
#include "td/telegram/GroupCallManager.h"
@ -1700,6 +1701,7 @@ void UpdatesManager::try_reload_data() {
td_->animations_manager_->get_saved_animations(Auto());
td_->contacts_manager_->reload_created_public_dialogs(PublicDialogType::HasUsername, Auto());
td_->contacts_manager_->reload_created_public_dialogs(PublicDialogType::IsLocationBased, Auto());
get_default_emoji_statuses(td_, Auto());
td_->notification_settings_manager_->reload_saved_ringtones(Auto());
td_->notification_settings_manager_->send_get_scope_notification_settings_query(NotificationSettingsScope::Private,
Auto());

View File

@ -4477,6 +4477,8 @@ class CliClient final : public Actor {
auto premium_status =
args.empty() ? nullptr : td_api::make_object<td_api::premiumStatus>(to_integer<int64>(args));
send_request(td_api::make_object<td_api::setPremiumStatus>(std::move(premium_status)));
} else if (op == "gdps") {
send_request(td_api::make_object<td_api::getDefaultPremiumStatuses>());
} else if (op == "ccun") {
ChatId chat_id;
string username;