From 80f3c88bdb0202dd57378d32adece3104d393922 Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 24 May 2022 14:56:02 +0300 Subject: [PATCH] Move get_invite_text and save_app_log to Application.cpp. --- CMakeLists.txt | 2 + td/telegram/Application.cpp | 83 +++++++++++++++++++++++++++++++++++++ td/telegram/Application.h | 25 +++++++++++ td/telegram/Td.cpp | 64 ++-------------------------- 4 files changed, 114 insertions(+), 60 deletions(-) create mode 100644 td/telegram/Application.cpp create mode 100644 td/telegram/Application.h diff --git a/CMakeLists.txt b/CMakeLists.txt index ae58a43fa..73c2d2aeb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -278,6 +278,7 @@ set(TDLIB_SOURCE td/telegram/Account.cpp td/telegram/AnimationsManager.cpp + td/telegram/Application.cpp td/telegram/AttachMenuManager.cpp td/telegram/AudiosManager.cpp td/telegram/AuthManager.cpp @@ -472,6 +473,7 @@ set(TDLIB_SOURCE td/telegram/Account.h td/telegram/AffectedHistory.h td/telegram/AnimationsManager.h + td/telegram/Application.h td/telegram/AttachMenuManager.h td/telegram/AudiosManager.h td/telegram/AuthManager.h diff --git a/td/telegram/Application.cpp b/td/telegram/Application.cpp new file mode 100644 index 000000000..7c33fa646 --- /dev/null +++ b/td/telegram/Application.cpp @@ -0,0 +1,83 @@ +// +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2022 +// +// 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/Application.h" + +#include "td/telegram/Global.h" +#include "td/telegram/Td.h" + +#include "td/utils/buffer.h" +#include "td/utils/logging.h" + +namespace td { + +class GetInviteTextQuery final : public Td::ResultHandler { + Promise promise_; + + public: + explicit GetInviteTextQuery(Promise &&promise) : promise_(std::move(promise)) { + } + + void send() { + send_query(G()->net_query_creator().create(telegram_api::help_getInviteText())); + } + + void on_result(BufferSlice packet) final { + auto result_ptr = fetch_result(packet); + if (result_ptr.is_error()) { + return on_error(result_ptr.move_as_error()); + } + + auto result = result_ptr.move_as_ok(); + promise_.set_value(std::move(result->message_)); + } + + void on_error(Status status) final { + promise_.set_error(std::move(status)); + } +}; + +class SaveAppLogQuery final : public Td::ResultHandler { + Promise promise_; + + public: + explicit SaveAppLogQuery(Promise &&promise) : promise_(std::move(promise)) { + } + + void send(const string &type, DialogId dialog_id, tl_object_ptr &&data) { + CHECK(data != nullptr); + vector> input_app_events; + input_app_events.push_back( + make_tl_object(G()->server_time_cached(), type, dialog_id.get(), std::move(data))); + send_query(G()->net_query_creator().create_unauth(telegram_api::help_saveAppLog(std::move(input_app_events)))); + } + + void on_result(BufferSlice packet) final { + auto result_ptr = fetch_result(packet); + if (result_ptr.is_error()) { + return on_error(result_ptr.move_as_error()); + } + + bool result = result_ptr.move_as_ok(); + LOG_IF(ERROR, !result) << "Receive false from help.saveAppLog"; + promise_.set_value(Unit()); + } + + void on_error(Status status) final { + promise_.set_error(std::move(status)); + } +}; + +void get_invite_text(Td *td, Promise &&promise) { + td->create_handler(std::move(promise))->send(); +} + +void save_app_log(Td *td, const string &type, DialogId dialog_id, tl_object_ptr &&data, + Promise &&promise) { + td->create_handler(std::move(promise))->send(type, dialog_id, std::move(data)); +} + +} // namespace td diff --git a/td/telegram/Application.h b/td/telegram/Application.h new file mode 100644 index 000000000..b0d18cbd2 --- /dev/null +++ b/td/telegram/Application.h @@ -0,0 +1,25 @@ +// +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2022 +// +// 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) +// +#pragma once + +#include "td/telegram/DialogId.h" +#include "td/telegram/telegram_api.h" + +#include "td/actor/PromiseFuture.h" + +#include "td/utils/common.h" + +namespace td { + +class Td; + +void get_invite_text(Td *td, Promise &&promise); + +void save_app_log(Td *td, const string &type, DialogId dialog_id, tl_object_ptr &&data, + Promise &&promise); + +} // namespace td diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index c5336f71a..a171eded6 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -8,6 +8,7 @@ #include "td/telegram/Account.h" #include "td/telegram/AnimationsManager.h" +#include "td/telegram/Application.h" #include "td/telegram/AttachMenuManager.h" #include "td/telegram/AudiosManager.h" #include "td/telegram/AuthManager.h" @@ -416,63 +417,6 @@ class UpdateStatusQuery final : public Td::ResultHandler { } }; -class GetInviteTextQuery final : public Td::ResultHandler { - Promise promise_; - - public: - explicit GetInviteTextQuery(Promise &&promise) : promise_(std::move(promise)) { - } - - void send() { - send_query(G()->net_query_creator().create(telegram_api::help_getInviteText())); - } - - void on_result(BufferSlice packet) final { - auto result_ptr = fetch_result(packet); - if (result_ptr.is_error()) { - return on_error(result_ptr.move_as_error()); - } - - auto result = result_ptr.move_as_ok(); - promise_.set_value(std::move(result->message_)); - } - - void on_error(Status status) final { - promise_.set_error(std::move(status)); - } -}; - -class SaveAppLogQuery final : public Td::ResultHandler { - Promise promise_; - - public: - explicit SaveAppLogQuery(Promise &&promise) : promise_(std::move(promise)) { - } - - void send(const string &type, int64 peer_id, tl_object_ptr &&data) { - CHECK(data != nullptr); - vector> input_app_events; - input_app_events.push_back( - make_tl_object(G()->server_time_cached(), type, peer_id, std::move(data))); - send_query(G()->net_query_creator().create_unauth(telegram_api::help_saveAppLog(std::move(input_app_events)))); - } - - void on_result(BufferSlice packet) final { - auto result_ptr = fetch_result(packet); - if (result_ptr.is_error()) { - return on_error(result_ptr.move_as_error()); - } - - bool result = result_ptr.move_as_ok(); - LOG_IF(ERROR, !result) << "Receive false from help.saveAppLog"; - promise_.set_value(Unit()); - } - - void on_error(Status status) final { - promise_.set_error(std::move(status)); - } -}; - class TestNetworkQuery final : public Td::ResultHandler { Promise promise_; @@ -7852,7 +7796,7 @@ void Td::on_request(uint64 id, const td_api::getApplicationDownloadLink &request promise.set_value(make_tl_object(result.move_as_ok())); } }); - create_handler(std::move(query_promise))->send(); + get_invite_text(this, std::move(query_promise)); } void Td::on_request(uint64 id, td_api::getDeepLinkInfo &request) { @@ -7870,9 +7814,9 @@ void Td::on_request(uint64 id, const td_api::getApplicationConfig &request) { void Td::on_request(uint64 id, td_api::saveApplicationLogEvent &request) { CHECK_IS_USER(); CLEAN_INPUT_STRING(request.type_); - auto result = convert_json_value(std::move(request.data_)); CREATE_OK_REQUEST_PROMISE(); - create_handler(std::move(promise))->send(request.type_, request.chat_id_, std::move(result)); + save_app_log(this, request.type_, DialogId(request.chat_id_), convert_json_value(std::move(request.data_)), + std::move(promise)); } void Td::on_request(uint64 id, td_api::addProxy &request) {