From abc59be31954ae2799de71821c1c4b593d8e9d71 Mon Sep 17 00:00:00 2001 From: levlam Date: Sun, 12 May 2019 04:10:18 +0300 Subject: [PATCH] Add td_api::resetBackgrounds. GitOrigin-RevId: 9ed830d56b31f0c26ba83245f0c53fb2f20fe8da --- td/generate/scheme/td_api.tl | 3 ++ td/generate/scheme/td_api.tlo | Bin 154316 -> 154376 bytes td/telegram/BackgroundManager.cpp | 50 +++++++++++++++++++++++++++++- td/telegram/BackgroundManager.h | 4 +++ td/telegram/Td.cpp | 17 +++++++++- td/telegram/Td.h | 4 ++- td/telegram/cli.cpp | 2 ++ 7 files changed, 77 insertions(+), 3 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 613f05e4..00d311a6 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -3631,6 +3631,9 @@ setBackground background:InputBackground type:BackgroundType = Background; //@description Removes background from the list of installed backgrounds @background_id The background indentifier removeBackground background_id:int64 = Ok; +//@description Resets list of installed backgrounds to its default value +resetBackgrounds = Ok; + //@description Returns information about the current localization target. This is an offline request if only_local is true. Can be called before authorization @only_local If true, returns only locally available information without sending network requests getLocalizationTargetInfo only_local:Bool = LocalizationTargetInfo; diff --git a/td/generate/scheme/td_api.tlo b/td/generate/scheme/td_api.tlo index 81bb5af94a55126fddb303a3bbe913eb7d9758e6..2bf81389b5a5d65ce248bb041af9f94f2e824eab 100644 GIT binary patch delta 51 zcmX@Jm9t|TXTugofo+UI+Xc5V?#>adIBm)!P?TDnTH=(LoSj~jUz(RvJU#F_qx$kQ HN=z024OtVr delta 24 gcmeC!#(8EdXTugofo+U|+Xc5V?#@}xq0D3f0DI;L(EtDd diff --git a/td/telegram/BackgroundManager.cpp b/td/telegram/BackgroundManager.cpp index f280b75f..4df60389 100644 --- a/td/telegram/BackgroundManager.cpp +++ b/td/telegram/BackgroundManager.cpp @@ -182,7 +182,7 @@ class SaveBackgroundQuery : public Td::ResultHandler { } bool result = result_ptr.move_as_ok(); - LOG(INFO) << "Receive result for fave background: " << result; + LOG(INFO) << "Receive result for save background: " << result; promise_.set_value(Unit()); } @@ -194,6 +194,36 @@ class SaveBackgroundQuery : public Td::ResultHandler { } }; +class ResetBackgroundsQuery : public Td::ResultHandler { + Promise promise_; + + public: + explicit ResetBackgroundsQuery(Promise &&promise) : promise_(std::move(promise)) { + } + + void send() { + send_query(G()->net_query_creator().create(create_storer(telegram_api::account_resetWallPapers()))); + } + + void on_result(uint64 id, BufferSlice packet) override { + auto result_ptr = fetch_result(packet); + if (result_ptr.is_error()) { + return on_error(id, result_ptr.move_as_error()); + } + + bool result = result_ptr.move_as_ok(); + LOG(INFO) << "Receive result for reset backgrounds: " << result; + promise_.set_value(Unit()); + } + + void on_error(uint64 id, Status status) override { + if (!G()->close_flag()) { + LOG(ERROR) << "Receive error for reset backgrounds: " << status; + } + promise_.set_error(std::move(status)); + } +}; + class BackgroundManager::UploadBackgroundFileCallback : public FileManager::UploadCallback { public: void on_upload_ok(FileId file_id, tl_object_ptr input_file) override { @@ -689,6 +719,24 @@ void BackgroundManager::on_removed_background(BackgroundId background_id, Result promise.set_value(Unit()); } +void BackgroundManager::reset_backgrounds(Promise &&promise) { + auto query_promise = + PromiseCreator::lambda([actor_id = actor_id(this), promise = std::move(promise)](Result &&result) mutable { + send_closure(actor_id, &BackgroundManager::on_reset_background, std::move(result), std::move(promise)); + }); + + td_->create_handler(std::move(query_promise))->send(); +} + +void BackgroundManager::on_reset_background(Result &&result, Promise &&promise) { + if (result.is_error()) { + return promise.set_error(result.move_as_error()); + } + installed_background_ids_.clear(); + set_background_id(BackgroundId(), BackgroundType()); + promise.set_value(Unit()); +} + BackgroundManager::Background *BackgroundManager::add_background(BackgroundId background_id) { CHECK(background_id.is_valid()); auto *result = &backgrounds_[background_id]; diff --git a/td/telegram/BackgroundManager.h b/td/telegram/BackgroundManager.h index fb2bd509..3be93d67 100644 --- a/td/telegram/BackgroundManager.h +++ b/td/telegram/BackgroundManager.h @@ -45,6 +45,8 @@ class BackgroundManager : public Actor { void remove_background(BackgroundId background_id, Promise &&promise); + void reset_backgrounds(Promise &&promise); + td_api::object_ptr get_background_object(BackgroundId background_id) const; td_api::object_ptr get_backgrounds_object() const; @@ -114,6 +116,8 @@ class BackgroundManager : public Actor { void on_removed_background(BackgroundId background_id, Result &&result, Promise &&promise); + void on_reset_background(Result &&result, Promise &&promise); + void upload_background_file(FileId file_id, const BackgroundType &type, Promise &&promise); void on_upload_background_file(FileId file_id, tl_object_ptr input_file); diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index d7af1eb4..3d1f369d 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -2956,6 +2956,16 @@ class RemoveBackgroundRequest : public RequestOnceActor { } }; +class ResetBackgroundsRequest : public RequestOnceActor { + void do_run(Promise &&promise) override { + td->background_manager_->reset_backgrounds(std::move(promise)); + } + + public: + ResetBackgroundsRequest(ActorShared td, uint64 request_id) : RequestOnceActor(std::move(td), request_id) { + } +}; + class GetRecentlyVisitedTMeUrlsRequest : public RequestActor> { string referrer_; @@ -7025,11 +7035,16 @@ void Td::on_request(uint64 id, td_api::setBackground &request) { CREATE_REQUEST(SetBackgroundRequest, std::move(request.background_), std::move(request.type_)); } -void Td::on_request(uint64 id, td_api::removeBackground &request) { +void Td::on_request(uint64 id, const td_api::removeBackground &request) { CHECK_IS_USER(); CREATE_REQUEST(RemoveBackgroundRequest, request.background_id_); } +void Td::on_request(uint64 id, const td_api::resetBackgrounds &request) { + CHECK_IS_USER(); + CREATE_NO_ARGS_REQUEST(ResetBackgroundsRequest); +} + void Td::on_request(uint64 id, td_api::getRecentlyVisitedTMeUrls &request) { CHECK_IS_USER(); CLEAN_INPUT_STRING(request.referrer_); diff --git a/td/telegram/Td.h b/td/telegram/Td.h index 474a3917..66caf9c9 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -930,7 +930,9 @@ class Td final : public NetQueryCallback { void on_request(uint64 id, td_api::setBackground &request); - void on_request(uint64 id, td_api::removeBackground &request); + void on_request(uint64 id, const td_api::removeBackground &request); + + void on_request(uint64 id, const td_api::resetBackgrounds &request); void on_request(uint64 id, td_api::getRecentlyVisitedTMeUrls &request); diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 0d1f7172..c87ef861 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -2003,6 +2003,8 @@ class CliClient final : public Actor { td_api::make_object(true, 0xabcdef, 49))); } else if (op == "rbg") { send_request(td_api::make_object(to_integer(args))); + } else if (op == "rbgs") { + send_request(td_api::make_object()); } else if (op == "gccode") { send_request(td_api::make_object()); } else if (op == "git") {