// // Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2020 // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #include "td/telegram/CountryInfoManager.h" #include "td/telegram/Global.h" #include "td/telegram/Td.h" #include "td/telegram/telegram_api.h" #include "td/utils/buffer.h" #include "td/utils/Status.h" namespace td { class GetNearestDcQuery : public Td::ResultHandler { Promise promise_; public: explicit GetNearestDcQuery(Promise &&promise) : promise_(std::move(promise)) { } void send() { send_query(G()->net_query_creator().create_unauth(telegram_api::help_getNearestDc())); } 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()); } auto result = result_ptr.move_as_ok(); promise_.set_value(std::move(result->country_)); } void on_error(uint64 id, Status status) override { if (!G()->is_expected_error(status) && status.message() != "BOT_METHOD_INVALID") { LOG(ERROR) << "GetNearestDc returned " << status; } promise_.set_error(std::move(status)); } }; CountryInfoManager::CountryInfoManager(Td *td, ActorShared<> parent) : td_(td), parent_(std::move(parent)) { } void CountryInfoManager::tear_down() { parent_.reset(); } void CountryInfoManager::get_current_country_code(Promise &&promise) { td_->create_handler(std::move(promise))->send(); } } // namespace td