Add getRecentPremiumStatuses.
This commit is contained in:
parent
947a92e94c
commit
c627f5987d
@ -5578,6 +5578,9 @@ toggleBotIsAddedToAttachmentMenu bot_user_id:int53 is_added:Bool = Ok;
|
||||
//@description Returns default premium statuses
|
||||
getDefaultPremiumStatuses = PremiumStatuses;
|
||||
|
||||
//@description Returns recent premium statuses
|
||||
getRecentPremiumStatuses = 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
|
||||
|
@ -18,7 +18,7 @@
|
||||
namespace td {
|
||||
|
||||
struct EmojiStatuses {
|
||||
int64 hash_ = 0;
|
||||
int64 hash_ = -1;
|
||||
vector<EmojiStatus> emoji_statuses_;
|
||||
|
||||
td_api::object_ptr<td_api::premiumStatuses> get_premium_statuses_object() const {
|
||||
@ -63,6 +63,11 @@ static const string &get_default_emoji_statuses_database_key() {
|
||||
return key;
|
||||
}
|
||||
|
||||
static const string &get_recent_emoji_statuses_database_key() {
|
||||
static string key = "rec_emoji_statuses";
|
||||
return key;
|
||||
}
|
||||
|
||||
static EmojiStatuses load_emoji_statuses(const string &key) {
|
||||
EmojiStatuses result;
|
||||
auto log_event_string = G()->td_db()->get_binlog_pmc()->get(key);
|
||||
@ -118,6 +123,48 @@ class GetDefaultEmojiStatusesQuery final : public Td::ResultHandler {
|
||||
}
|
||||
};
|
||||
|
||||
class GetRecentEmojiStatusesQuery final : public Td::ResultHandler {
|
||||
Promise<td_api::object_ptr<td_api::premiumStatuses>> promise_;
|
||||
|
||||
public:
|
||||
explicit GetRecentEmojiStatusesQuery(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_getRecentEmojiStatuses(hash)));
|
||||
}
|
||||
|
||||
void on_result(BufferSlice packet) final {
|
||||
auto result_ptr = fetch_result<telegram_api::account_getRecentEmojiStatuses>(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 GetRecentEmojiStatusesQuery: " << to_string(emoji_statuses_ptr);
|
||||
|
||||
if (emoji_statuses_ptr->get_id() == telegram_api::account_emojiStatusesNotModified::ID) {
|
||||
if (promise_) {
|
||||
promise_.set_error(Status::Error(500, "Receive wrong server response"));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
CHECK(emoji_statuses_ptr->get_id() == telegram_api::account_emojiStatuses::ID);
|
||||
EmojiStatuses emoji_statuses(move_tl_object_as<telegram_api::account_emojiStatuses>(emoji_statuses_ptr));
|
||||
save_emoji_statuses(get_recent_emoji_statuses_database_key(), emoji_statuses);
|
||||
|
||||
if (promise_) {
|
||||
promise_.set_value(emoji_statuses.get_premium_statuses_object());
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
}
|
||||
@ -151,11 +198,20 @@ StringBuilder &operator<<(StringBuilder &string_builder, const EmojiStatus &emoj
|
||||
|
||||
void get_default_emoji_statuses(Td *td, Promise<td_api::object_ptr<td_api::premiumStatuses>> &&promise) {
|
||||
auto statuses = load_emoji_statuses(get_default_emoji_statuses_database_key());
|
||||
if (statuses.hash_ != 0 && promise) {
|
||||
if (statuses.hash_ != -1 && promise) {
|
||||
promise.set_value(statuses.get_premium_statuses_object());
|
||||
promise = Promise<td_api::object_ptr<td_api::premiumStatuses>>();
|
||||
}
|
||||
td->create_handler<GetDefaultEmojiStatusesQuery>(std::move(promise))->send(statuses.hash_);
|
||||
}
|
||||
|
||||
void get_recent_emoji_statuses(Td *td, Promise<td_api::object_ptr<td_api::premiumStatuses>> &&promise) {
|
||||
auto statuses = load_emoji_statuses(get_recent_emoji_statuses_database_key());
|
||||
if (statuses.hash_ != -1 && promise) {
|
||||
promise.set_value(statuses.get_premium_statuses_object());
|
||||
promise = Promise<td_api::object_ptr<td_api::premiumStatuses>>();
|
||||
}
|
||||
td->create_handler<GetRecentEmojiStatusesQuery>(std::move(promise))->send(statuses.hash_);
|
||||
}
|
||||
|
||||
} // namespace td
|
||||
|
@ -63,4 +63,6 @@ StringBuilder &operator<<(StringBuilder &string_builder, const EmojiStatus &emoj
|
||||
|
||||
void get_default_emoji_statuses(Td *td, Promise<td_api::object_ptr<td_api::premiumStatuses>> &&promise);
|
||||
|
||||
void get_recent_emoji_statuses(Td *td, Promise<td_api::object_ptr<td_api::premiumStatuses>> &&promise);
|
||||
|
||||
} // namespace td
|
||||
|
@ -6739,6 +6739,12 @@ void Td::on_request(uint64 id, const td_api::getDefaultPremiumStatuses &request)
|
||||
get_default_emoji_statuses(this, std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, const td_api::getRecentPremiumStatuses &request) {
|
||||
CHECK_IS_USER();
|
||||
CREATE_REQUEST_PROMISE();
|
||||
get_recent_emoji_statuses(this, std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, td_api::setCommands &request) {
|
||||
CHECK_IS_BOT();
|
||||
CREATE_OK_REQUEST_PROMISE();
|
||||
|
@ -1016,6 +1016,8 @@ class Td final : public Actor {
|
||||
|
||||
void on_request(uint64 id, const td_api::getDefaultPremiumStatuses &request);
|
||||
|
||||
void on_request(uint64 id, const td_api::getRecentPremiumStatuses &request);
|
||||
|
||||
void on_request(uint64 id, td_api::setCommands &request);
|
||||
|
||||
void on_request(uint64 id, td_api::deleteCommands &request);
|
||||
|
@ -4479,6 +4479,8 @@ class CliClient final : public Actor {
|
||||
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 == "grps") {
|
||||
send_request(td_api::make_object<td_api::getRecentPremiumStatuses>());
|
||||
} else if (op == "ccun") {
|
||||
ChatId chat_id;
|
||||
string username;
|
||||
|
Loading…
Reference in New Issue
Block a user