Move get_invite_text and save_app_log to Application.cpp.

This commit is contained in:
levlam 2022-05-24 14:56:02 +03:00
parent d06a7ddf1c
commit 80f3c88bdb
4 changed files with 114 additions and 60 deletions

View File

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

View File

@ -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<string> promise_;
public:
explicit GetInviteTextQuery(Promise<string> &&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<telegram_api::help_getInviteText>(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<Unit> promise_;
public:
explicit SaveAppLogQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
}
void send(const string &type, DialogId dialog_id, tl_object_ptr<telegram_api::JSONValue> &&data) {
CHECK(data != nullptr);
vector<telegram_api::object_ptr<telegram_api::inputAppEvent>> input_app_events;
input_app_events.push_back(
make_tl_object<telegram_api::inputAppEvent>(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<telegram_api::help_saveAppLog>(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<string> &&promise) {
td->create_handler<GetInviteTextQuery>(std::move(promise))->send();
}
void save_app_log(Td *td, const string &type, DialogId dialog_id, tl_object_ptr<telegram_api::JSONValue> &&data,
Promise<Unit> &&promise) {
td->create_handler<SaveAppLogQuery>(std::move(promise))->send(type, dialog_id, std::move(data));
}
} // namespace td

25
td/telegram/Application.h Normal file
View File

@ -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<string> &&promise);
void save_app_log(Td *td, const string &type, DialogId dialog_id, tl_object_ptr<telegram_api::JSONValue> &&data,
Promise<Unit> &&promise);
} // namespace td

View File

@ -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<string> promise_;
public:
explicit GetInviteTextQuery(Promise<string> &&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<telegram_api::help_getInviteText>(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<Unit> promise_;
public:
explicit SaveAppLogQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
}
void send(const string &type, int64 peer_id, tl_object_ptr<telegram_api::JSONValue> &&data) {
CHECK(data != nullptr);
vector<telegram_api::object_ptr<telegram_api::inputAppEvent>> input_app_events;
input_app_events.push_back(
make_tl_object<telegram_api::inputAppEvent>(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<telegram_api::help_saveAppLog>(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<Unit> promise_;
@ -7852,7 +7796,7 @@ void Td::on_request(uint64 id, const td_api::getApplicationDownloadLink &request
promise.set_value(make_tl_object<td_api::httpUrl>(result.move_as_ok()));
}
});
create_handler<GetInviteTextQuery>(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<SaveAppLogQuery>(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) {