Add td_api::clearRecentPremiumStatuses.

This commit is contained in:
levlam 2022-08-31 16:41:13 +03:00
parent c627f5987d
commit 93d870bfc6
6 changed files with 51 additions and 3 deletions

View File

@ -5581,6 +5581,9 @@ getDefaultPremiumStatuses = PremiumStatuses;
//@description Returns recent premium statuses
getRecentPremiumStatuses = PremiumStatuses;
//@description Clears recent premium statuses
clearRecentPremiumStatuses = Ok;
//@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

View File

@ -18,7 +18,7 @@
namespace td {
struct EmojiStatuses {
int64 hash_ = -1;
int64 hash_ = 0;
vector<EmojiStatus> emoji_statuses_;
td_api::object_ptr<td_api::premiumStatuses> get_premium_statuses_object() const {
@ -73,6 +73,8 @@ static EmojiStatuses load_emoji_statuses(const string &key) {
auto log_event_string = G()->td_db()->get_binlog_pmc()->get(key);
if (!log_event_string.empty()) {
log_event_parse(result, log_event_string).ensure();
} else {
result.hash_ = -1;
}
return result;
}
@ -90,7 +92,7 @@ class GetDefaultEmojiStatusesQuery final : public Td::ResultHandler {
}
void send(int64 hash) {
send_query(G()->net_query_creator().create(telegram_api::account_getDefaultEmojiStatuses(hash)));
send_query(G()->net_query_creator().create(telegram_api::account_getDefaultEmojiStatuses(hash), {{"me"}}));
}
void on_result(BufferSlice packet) final {
@ -132,7 +134,7 @@ class GetRecentEmojiStatusesQuery final : public Td::ResultHandler {
}
void send(int64 hash) {
send_query(G()->net_query_creator().create(telegram_api::account_getRecentEmojiStatuses(hash)));
send_query(G()->net_query_creator().create(telegram_api::account_getRecentEmojiStatuses(hash), {{"me"}}));
}
void on_result(BufferSlice packet) final {
@ -165,6 +167,32 @@ class GetRecentEmojiStatusesQuery final : public Td::ResultHandler {
}
};
class ClearRecentEmojiStatusesQuery final : public Td::ResultHandler {
Promise<Unit> promise_;
public:
explicit ClearRecentEmojiStatusesQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
}
void send() {
send_query(G()->net_query_creator().create(telegram_api::account_clearRecentEmojiStatuses(), {{"me"}}));
}
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::account_clearRecentEmojiStatuses>(packet);
if (result_ptr.is_error()) {
return on_error(result_ptr.move_as_error());
}
save_emoji_statuses(get_recent_emoji_statuses_database_key(), EmojiStatuses());
promise_.set_value(Unit());
}
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) {
}
@ -214,4 +242,9 @@ void get_recent_emoji_statuses(Td *td, Promise<td_api::object_ptr<td_api::premiu
td->create_handler<GetRecentEmojiStatusesQuery>(std::move(promise))->send(statuses.hash_);
}
void clear_recent_emoji_statuses(Td *td, Promise<Unit> &&promise) {
save_emoji_statuses(get_recent_emoji_statuses_database_key(), EmojiStatuses());
td->create_handler<ClearRecentEmojiStatusesQuery>(std::move(promise))->send();
}
} // namespace td

View File

@ -65,4 +65,6 @@ void get_default_emoji_statuses(Td *td, Promise<td_api::object_ptr<td_api::premi
void get_recent_emoji_statuses(Td *td, Promise<td_api::object_ptr<td_api::premiumStatuses>> &&promise);
void clear_recent_emoji_statuses(Td *td, Promise<Unit> &&promise);
} // namespace td

View File

@ -6745,6 +6745,12 @@ void Td::on_request(uint64 id, const td_api::getRecentPremiumStatuses &request)
get_recent_emoji_statuses(this, std::move(promise));
}
void Td::on_request(uint64 id, const td_api::clearRecentPremiumStatuses &request) {
CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE();
clear_recent_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

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

View File

@ -4481,6 +4481,8 @@ class CliClient final : public Actor {
send_request(td_api::make_object<td_api::getDefaultPremiumStatuses>());
} else if (op == "grps") {
send_request(td_api::make_object<td_api::getRecentPremiumStatuses>());
} else if (op == "crps") {
send_request(td_api::make_object<td_api::clearRecentPremiumStatuses>());
} else if (op == "ccun") {
ChatId chat_id;
string username;