Add td_api::setPremiumBadge.
This commit is contained in:
parent
ff039e2195
commit
02b42d7ee6
|
@ -6053,6 +6053,9 @@ 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 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;
|
||||
|
||||
|
|
|
@ -670,6 +670,42 @@ class UpdateUsernameQuery final : public Td::ResultHandler {
|
|||
}
|
||||
};
|
||||
|
||||
class UpdateEmojiStatusQuery final : public Td::ResultHandler {
|
||||
Promise<Unit> promise_;
|
||||
|
||||
public:
|
||||
explicit UpdateEmojiStatusQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
|
||||
}
|
||||
|
||||
void send(int64 custom_emoji_id) {
|
||||
auto emoji_status = [custom_emoji_id]() -> telegram_api::object_ptr<telegram_api::EmojiStatus> {
|
||||
if (custom_emoji_id == 0) {
|
||||
return make_tl_object<telegram_api::emojiStatusEmpty>();
|
||||
}
|
||||
return make_tl_object<telegram_api::emojiStatus>(custom_emoji_id);
|
||||
}();
|
||||
send_query(G()->net_query_creator().create(telegram_api::account_updateEmojiStatus(std::move(emoji_status))));
|
||||
}
|
||||
|
||||
void on_result(BufferSlice packet) final {
|
||||
auto result_ptr = fetch_result<telegram_api::account_updateEmojiStatus>(packet);
|
||||
if (result_ptr.is_error()) {
|
||||
return on_error(result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
LOG(DEBUG) << "Receive result for UpdateEmojiStatusQuery: " << result_ptr.ok();
|
||||
if (result_ptr.ok()) {
|
||||
promise_.set_value(Unit());
|
||||
} else {
|
||||
promise_.set_error(Status::Error(400, "Failed to change Premium badge"));
|
||||
}
|
||||
}
|
||||
|
||||
void on_error(Status status) final {
|
||||
promise_.set_error(std::move(status));
|
||||
}
|
||||
};
|
||||
|
||||
class CheckChannelUsernameQuery final : public Td::ResultHandler {
|
||||
Promise<bool> promise_;
|
||||
ChannelId channel_id_;
|
||||
|
@ -6565,6 +6601,32 @@ void ContactsManager::set_username(const string &username, Promise<Unit> &&promi
|
|||
td_->create_handler<UpdateUsernameQuery>(std::move(promise))->send(username);
|
||||
}
|
||||
|
||||
void ContactsManager::set_emoji_status(int64 custom_emoji_id, Promise<Unit> &&promise) {
|
||||
if (!td_->option_manager_->get_option_boolean("is_premium")) {
|
||||
return promise.set_error(Status::Error(400, "The method is available only for Telegram Premium users"));
|
||||
}
|
||||
auto query_promise = PromiseCreator::lambda(
|
||||
[actor_id = actor_id(this), custom_emoji_id, promise = std::move(promise)](Result<Unit> result) mutable {
|
||||
if (result.is_ok()) {
|
||||
send_closure(actor_id, &ContactsManager::on_set_emoji_status, custom_emoji_id, std::move(promise));
|
||||
} else {
|
||||
promise.set_error(result.move_as_error());
|
||||
}
|
||||
});
|
||||
td_->create_handler<UpdateEmojiStatusQuery>(std::move(query_promise))->send(custom_emoji_id);
|
||||
}
|
||||
|
||||
void ContactsManager::on_set_emoji_status(int64 custom_emoji_id, Promise<Unit> &&promise) {
|
||||
auto user_id = get_my_id();
|
||||
User *u = get_user(user_id);
|
||||
if (u != nullptr && u->emoji_status != custom_emoji_id) {
|
||||
u->emoji_status = custom_emoji_id;
|
||||
u->is_changed = true;
|
||||
update_user(u, user_id);
|
||||
}
|
||||
promise.set_value(Unit());
|
||||
}
|
||||
|
||||
void ContactsManager::set_chat_description(ChatId chat_id, const string &description, Promise<Unit> &&promise) {
|
||||
auto new_description = strip_empty_characters(description, MAX_DESCRIPTION_LENGTH);
|
||||
auto c = get_chat(chat_id);
|
||||
|
|
|
@ -343,6 +343,8 @@ class ContactsManager final : public Actor {
|
|||
|
||||
void set_username(const string &username, Promise<Unit> &&promise);
|
||||
|
||||
void set_emoji_status(int64 suctom_emoji_id, Promise<Unit> &&promise);
|
||||
|
||||
void set_chat_description(ChatId chat_id, const string &description, Promise<Unit> &&promise);
|
||||
|
||||
void set_channel_username(ChannelId channel_id, const string &username, Promise<Unit> &&promise);
|
||||
|
@ -1248,6 +1250,8 @@ class ContactsManager final : public Actor {
|
|||
|
||||
static bool is_valid_username(const string &username);
|
||||
|
||||
void on_set_emoji_status(int64 custom_emoji_id, Promise<Unit> &&promise);
|
||||
|
||||
void on_update_user_name(User *u, UserId user_id, string &&first_name, string &&last_name, string &&username);
|
||||
void on_update_user_phone_number(User *u, UserId user_id, string &&phone_number);
|
||||
void on_update_user_photo(User *u, UserId user_id, tl_object_ptr<telegram_api::UserProfilePhoto> &&photo,
|
||||
|
|
|
@ -6723,6 +6723,12 @@ 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) {
|
||||
CHECK_IS_USER();
|
||||
CREATE_OK_REQUEST_PROMISE();
|
||||
contacts_manager_->set_emoji_status(request.custom_emoji_id_, std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, td_api::setCommands &request) {
|
||||
CHECK_IS_BOT();
|
||||
CREATE_OK_REQUEST_PROMISE();
|
||||
|
|
|
@ -1010,6 +1010,8 @@ 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, td_api::setCommands &request);
|
||||
|
||||
void on_request(uint64 id, td_api::deleteCommands &request);
|
||||
|
|
|
@ -4456,6 +4456,8 @@ class CliClient final : public Actor {
|
|||
send_request(td_api::make_object<td_api::setBio>("\n" + args + "\n" + args + "\n"));
|
||||
} else if (op == "sun") {
|
||||
send_request(td_api::make_object<td_api::setUsername>(args));
|
||||
} else if (op == "spb") {
|
||||
send_request(td_api::make_object<td_api::setPremiumBadge>(to_integer<int64>(args)));
|
||||
} else if (op == "ccun") {
|
||||
ChatId chat_id;
|
||||
string username;
|
||||
|
|
Loading…
Reference in New Issue
Block a user