Add td_api::resetBackgrounds.

GitOrigin-RevId: 9ed830d56b31f0c26ba83245f0c53fb2f20fe8da
This commit is contained in:
levlam 2019-05-12 04:10:18 +03:00
parent 3bf9bae32f
commit abc59be319
7 changed files with 77 additions and 3 deletions

View File

@ -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;

Binary file not shown.

View File

@ -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<Unit> promise_;
public:
explicit ResetBackgroundsQuery(Promise<Unit> &&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<telegram_api::account_resetWallPapers>(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<telegram_api::InputFile> 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<Unit> &&promise) {
auto query_promise =
PromiseCreator::lambda([actor_id = actor_id(this), promise = std::move(promise)](Result<Unit> &&result) mutable {
send_closure(actor_id, &BackgroundManager::on_reset_background, std::move(result), std::move(promise));
});
td_->create_handler<ResetBackgroundsQuery>(std::move(query_promise))->send();
}
void BackgroundManager::on_reset_background(Result<Unit> &&result, Promise<Unit> &&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];

View File

@ -45,6 +45,8 @@ class BackgroundManager : public Actor {
void remove_background(BackgroundId background_id, Promise<Unit> &&promise);
void reset_backgrounds(Promise<Unit> &&promise);
td_api::object_ptr<td_api::background> get_background_object(BackgroundId background_id) const;
td_api::object_ptr<td_api::backgrounds> get_backgrounds_object() const;
@ -114,6 +116,8 @@ class BackgroundManager : public Actor {
void on_removed_background(BackgroundId background_id, Result<Unit> &&result, Promise<Unit> &&promise);
void on_reset_background(Result<Unit> &&result, Promise<Unit> &&promise);
void upload_background_file(FileId file_id, const BackgroundType &type, Promise<Unit> &&promise);
void on_upload_background_file(FileId file_id, tl_object_ptr<telegram_api::InputFile> input_file);

View File

@ -2956,6 +2956,16 @@ class RemoveBackgroundRequest : public RequestOnceActor {
}
};
class ResetBackgroundsRequest : public RequestOnceActor {
void do_run(Promise<Unit> &&promise) override {
td->background_manager_->reset_backgrounds(std::move(promise));
}
public:
ResetBackgroundsRequest(ActorShared<Td> td, uint64 request_id) : RequestOnceActor(std::move(td), request_id) {
}
};
class GetRecentlyVisitedTMeUrlsRequest : public RequestActor<tl_object_ptr<td_api::tMeUrls>> {
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_);

View File

@ -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);

View File

@ -2003,6 +2003,8 @@ class CliClient final : public Actor {
td_api::make_object<td_api::backgroundTypePattern>(true, 0xabcdef, 49)));
} else if (op == "rbg") {
send_request(td_api::make_object<td_api::removeBackground>(to_integer<int64>(args)));
} else if (op == "rbgs") {
send_request(td_api::make_object<td_api::resetBackgrounds>());
} else if (op == "gccode") {
send_request(td_api::make_object<td_api::getCountryCode>());
} else if (op == "git") {