mirror of
https://github.com/tdlight-team/tdlight-telegram-bot-api.git
synced 2024-12-18 00:27:49 +01:00
Implement optimize_memory correctly
This commit is contained in:
parent
4a27b53890
commit
01c4a80ceb
@ -2556,6 +2556,44 @@ class Client::TdOnCheckChatCallback : public TdQueryCallback {
|
||||
OnSuccess on_success_;
|
||||
};
|
||||
|
||||
template <class OnSuccess>
|
||||
class Client::TdOnDisableInternetConnectionCallback : public TdQueryCallback {
|
||||
public:
|
||||
TdOnDisableInternetConnectionCallback(const Client *client, PromisedQueryPtr query, OnSuccess on_success)
|
||||
: client_(client)
|
||||
, query_(std::move(query))
|
||||
, on_success_(std::move(on_success)) {
|
||||
}
|
||||
|
||||
void on_result(object_ptr<td_api::Object> result) override {
|
||||
on_success_(std::move(query_));
|
||||
}
|
||||
|
||||
private:
|
||||
const Client *client_;
|
||||
PromisedQueryPtr query_;
|
||||
OnSuccess on_success_;
|
||||
};
|
||||
|
||||
template <class OnSuccess>
|
||||
class Client::TdOnOptimizeMemoryCallback : public TdQueryCallback {
|
||||
public:
|
||||
TdOnOptimizeMemoryCallback(const Client *client, PromisedQueryPtr query, OnSuccess on_success)
|
||||
: client_(client)
|
||||
, query_(std::move(query))
|
||||
, on_success_(std::move(on_success)) {
|
||||
}
|
||||
|
||||
void on_result(object_ptr<td_api::Object> result) override {
|
||||
on_success_(std::move(query_));
|
||||
}
|
||||
|
||||
private:
|
||||
const Client *client_;
|
||||
PromisedQueryPtr query_;
|
||||
OnSuccess on_success_;
|
||||
};
|
||||
|
||||
template <class OnSuccess>
|
||||
class Client::TdOnSearchStickerSetCallback : public TdQueryCallback {
|
||||
public:
|
||||
@ -6904,10 +6942,30 @@ td::Status Client::process_get_chat_member_count_query(PromisedQueryPtr &query)
|
||||
}
|
||||
|
||||
td::Status Client::process_optimize_memory_query(PromisedQueryPtr &query) {
|
||||
send_request(make_object<td_api::optimizeMemory>(), std::make_unique<TdOnOkQueryCallback>(std::move(query)));
|
||||
disable_internet_connection(std::move(query), [this](PromisedQueryPtr query) {
|
||||
optimize_memory(std::move(query), [this](PromisedQueryPtr query) {
|
||||
enable_internet_connection(std::move(query));
|
||||
});
|
||||
});
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
template <class OnSuccess>
|
||||
void Client::disable_internet_connection(PromisedQueryPtr query, OnSuccess on_success) {
|
||||
send_request(make_object<td_api::setNetworkType>(make_object<td_api::networkTypeNone>()),
|
||||
std::make_unique<TdOnDisableInternetConnectionCallback<OnSuccess>>(this, std::move(query), std::move(on_success)));
|
||||
}
|
||||
|
||||
void Client::enable_internet_connection(PromisedQueryPtr query) {
|
||||
send_request(make_object<td_api::setNetworkType>(make_object<td_api::networkTypeOther>()), std::make_unique<TdOnOkQueryCallback>(std::move(query)));
|
||||
}
|
||||
|
||||
template <class OnSuccess>
|
||||
void Client::optimize_memory(PromisedQueryPtr query, OnSuccess on_success) {
|
||||
send_request(make_object<td_api::optimizeMemory>(),
|
||||
std::make_unique<TdOnOptimizeMemoryCallback<OnSuccess>>(this, std::move(query), std::move(on_success)));
|
||||
}
|
||||
|
||||
td::Status Client::process_leave_chat_query(PromisedQueryPtr &query) {
|
||||
auto chat_id = query->arg("chat_id");
|
||||
|
||||
|
@ -212,6 +212,12 @@ class Client : public WebhookActor::Callback {
|
||||
template <class OnSuccess>
|
||||
class TdOnCheckChatCallback;
|
||||
template <class OnSuccess>
|
||||
class TdOnEnableInternetConnectionCallback;
|
||||
template <class OnSuccess>
|
||||
class TdOnOptimizeMemoryCallback;
|
||||
template <class OnSuccess>
|
||||
class TdOnDisableInternetConnectionCallback;
|
||||
template <class OnSuccess>
|
||||
class TdOnCheckMessageCallback;
|
||||
template <class OnSuccess>
|
||||
class TdOnCheckRemoteFileIdCallback;
|
||||
@ -239,6 +245,14 @@ class Client : public WebhookActor::Callback {
|
||||
template <class OnSuccess>
|
||||
void check_chat(Slice chat_id_str, AccessRights access_rights, PromisedQueryPtr query, OnSuccess on_success);
|
||||
|
||||
template <class OnSuccess>
|
||||
void disable_internet_connection(PromisedQueryPtr query, OnSuccess on_success);
|
||||
|
||||
template <class OnSuccess>
|
||||
void optimize_memory(PromisedQueryPtr query, OnSuccess on_success);
|
||||
|
||||
void enable_internet_connection(PromisedQueryPtr query);
|
||||
|
||||
template <class OnSuccess>
|
||||
void check_remote_file_id(td::string file_id, PromisedQueryPtr query, OnSuccess on_success);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user