From acec58e7efcbe7c46d0d126ac675161e2eb32bf0 Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 21 Feb 2023 12:08:55 +0300 Subject: [PATCH] Add addApplicationChangelog. --- td/generate/scheme/td_api.tl | 8 ++++++-- td/telegram/Application.cpp | 30 ++++++++++++++++++++++++++++++ td/telegram/Application.h | 2 ++ td/telegram/Td.cpp | 7 +++++++ td/telegram/Td.h | 2 ++ td/telegram/cli.cpp | 2 ++ 6 files changed, 49 insertions(+), 2 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 5517acb86..9ab1e63b0 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -8111,8 +8111,6 @@ getPhoneNumberInfo phone_number_prefix:string = PhoneNumberInfo; //@phone_number_prefix The phone number prefix getPhoneNumberInfoSync language_code:string phone_number_prefix:string = PhoneNumberInfo; -//@description Returns the link for downloading official Telegram application to be used when the current user invites friends to Telegram -getApplicationDownloadLink = HttpUrl; //@description Returns information about a tg:// deep link. Use "tg://need_update_for_some_feature" or "tg:some_unsupported_feature" for testing. Returns a 404 error for unknown links. Can be called before authorization @link The link getDeepLinkInfo link:string = DeepLinkInfo; @@ -8121,9 +8119,15 @@ getDeepLinkInfo link:string = DeepLinkInfo; //@description Returns application config, provided by the server. Can be called before authorization getApplicationConfig = JsonValue; +//@description Adds server-provided application changelog as messages to the chat 777000 (Telegram); for official applications only @previous_application_version The previous application version +addApplicationChangelog previous_application_version:string = Ok; + //@description Saves application log event on the server. Can be called before authorization @type Event type @chat_id Optional chat identifier, associated with the event @data The log event data saveApplicationLogEvent type:string chat_id:int53 data:JsonValue = Ok; +//@description Returns the link for downloading official Telegram application to be used when the current user invites friends to Telegram +getApplicationDownloadLink = HttpUrl; + //@description Adds a proxy server for network requests. Can be called before authorization //@server Proxy server IP address diff --git a/td/telegram/Application.cpp b/td/telegram/Application.cpp index a09d8864e..073b72607 100644 --- a/td/telegram/Application.cpp +++ b/td/telegram/Application.cpp @@ -11,6 +11,7 @@ #include "td/telegram/logevent/LogEventHelper.h" #include "td/telegram/Td.h" #include "td/telegram/TdDb.h" +#include "td/telegram/UpdatesManager.h" #include "td/db/binlog/BinlogEvent.h" #include "td/db/binlog/BinlogHelper.h" @@ -77,6 +78,31 @@ class SaveAppLogQuery final : public Td::ResultHandler { } }; +class GetAppChangelogQuery final : public Td::ResultHandler { + Promise promise_; + + public: + explicit GetAppChangelogQuery(Promise &&promise) : promise_(std::move(promise)) { + } + + void send(const string &prev_app_version) { + send_query(G()->net_query_creator().create(telegram_api::help_getAppChangelog(prev_app_version))); + } + + 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()); + } + + td_->updates_manager_->on_get_updates(result_ptr.move_as_ok(), std::move(promise_)); + } + + 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(); } @@ -132,4 +158,8 @@ void on_save_app_log_binlog_event(Td *td, BinlogEvent &&event) { save_app_log_impl(td, std::move(log_event.input_app_event_out_), event.id_, Promise()); } +void add_app_changelog(Td *td, const string &previous_application_version, Promise &&promise) { + td->create_handler(std::move(promise))->send(previous_application_version); +} + } // namespace td diff --git a/td/telegram/Application.h b/td/telegram/Application.h index b3c5c515a..fa3608243 100644 --- a/td/telegram/Application.h +++ b/td/telegram/Application.h @@ -25,4 +25,6 @@ void save_app_log(Td *td, const string &type, DialogId dialog_id, tl_object_ptr< void on_save_app_log_binlog_event(Td *td, BinlogEvent &&event); +void add_app_changelog(Td *td, const string &previous_application_version, Promise &&promise); + } // namespace td diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 06e01e027..4e57ed4cc 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -8320,6 +8320,13 @@ void Td::on_request(uint64 id, const td_api::getApplicationConfig &request) { send_closure(G()->config_manager(), &ConfigManager::get_app_config, std::move(promise)); } +void Td::on_request(uint64 id, td_api::addApplicationChangelog &request) { + CHECK_IS_USER(); + CLEAN_INPUT_STRING(request.previous_application_version_); + CREATE_OK_REQUEST_PROMISE(); + add_app_changelog(this, request.previous_application_version_, std::move(promise)); +} + void Td::on_request(uint64 id, td_api::saveApplicationLogEvent &request) { CHECK_IS_USER(); CLEAN_INPUT_STRING(request.type_); diff --git a/td/telegram/Td.h b/td/telegram/Td.h index 0c78275f1..787070f35 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -1462,6 +1462,8 @@ class Td final : public Actor { void on_request(uint64 id, const td_api::getApplicationConfig &request); + void on_request(uint64 id, td_api::addApplicationChangelog &request); + void on_request(uint64 id, td_api::saveApplicationLogEvent &request); void on_request(uint64 id, td_api::addProxy &request); diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index a741781fa..3b9fc3761 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -3647,6 +3647,8 @@ class CliClient final : public Actor { execute(td_api::make_object(as_theme_parameters())); } else if (op == "gac") { send_request(td_api::make_object()); + } else if (op == "aac") { + send_request(td_api::make_object(args)); } else if (op == "sale") { string type; ChatId chat_id;