From 561119367a89bd420def695f4191c21d4951c01a Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 13 Dec 2021 00:35:46 +0300 Subject: [PATCH 01/19] Update .clang-format. --- .clang-format | 42 +++++++++++++++++++++++------ telegram-bot-api/ClientParameters.h | 2 +- 2 files changed, 35 insertions(+), 9 deletions(-) diff --git a/.clang-format b/.clang-format index 6ce3c0d..4e23f1d 100644 --- a/.clang-format +++ b/.clang-format @@ -3,17 +3,20 @@ Language: Cpp # BasedOnStyle: Google AccessModifierOffset: -1 AlignAfterOpenBracket: Align -AlignConsecutiveMacros: false -AlignConsecutiveAssignments: false -AlignConsecutiveDeclarations: false +AlignArrayOfStructures: None +AlignConsecutiveMacros: None +AlignConsecutiveAssignments: None +AlignConsecutiveBitFields: None +AlignConsecutiveDeclarations: None AlignEscapedNewlines: Left -AlignOperands: true +AlignOperands: Align AlignTrailingComments: true AllowAllArgumentsOnNextLine: true AllowAllConstructorInitializersOnNextLine: true AllowAllParametersOfDeclarationOnNextLine: true AllowShortBlocksOnASingleLine: Never AllowShortCaseLabelsOnASingleLine: false +AllowShortEnumsOnASingleLine: true AllowShortFunctionsOnASingleLine: None # All AllowShortIfStatementsOnASingleLine: Never # WithoutElse AllowShortLambdasOnASingleLine: Inline # All @@ -24,10 +27,11 @@ AlwaysBreakBeforeMultilineStrings: true AlwaysBreakTemplateDeclarations: Yes BinPackArguments: true BinPackParameters: true +BitFieldColonSpacing: Both BraceWrapping: AfterCaseLabel: false AfterClass: false - AfterControlStatement: false + AfterControlStatement: Never AfterEnum: false AfterFunction: false AfterNamespace: false @@ -37,12 +41,15 @@ BraceWrapping: AfterExternBlock: false BeforeCatch: false BeforeElse: false + BeforeLambdaBody: false + BeforeWhile: false IndentBraces: false SplitEmptyFunction: true SplitEmptyRecord: true SplitEmptyNamespace: true BreakBeforeBinaryOperators: None BreakBeforeBraces: Attach +BreakBeforeConceptDeclarations: true BreakBeforeInheritanceComma: true # false BreakInheritanceList: BeforeComma # BeforeColon BreakBeforeTernaryOperators: true @@ -60,21 +67,30 @@ Cpp11BracedListStyle: true DeriveLineEnding: true DerivePointerAlignment: true DisableFormat: false +EmptyLineAfterAccessModifier: Never +EmptyLineBeforeAccessModifier: LogicalBlock ExperimentalAutoDetectBinPacking: false FixNamespaceComments: true ForEachMacros: - Q_FOREACH_THIS_LIST_MUST_BE_NON_EMPTY IncludeBlocks: Preserve -#IndentCaseBlocks: false +IncludeCategories: + - Regex: '.*' + Priority: 0 +IndentAccessModifiers: false +IndentCaseBlocks: false IndentCaseLabels: true +IndentExternBlock: AfterExternBlock IndentGotoLabels: true IndentPPDirectives: None +IndentRequires: false IndentWidth: 2 IndentWrappedFunctionNames: false # InsertTrailingCommas: None # JavaScriptQuotes: Leave # JavaScriptWrapImports: true KeepEmptyLinesAtTheStartOfBlocks: false +LambdaBodyIndentation: Signature MacroBlockBegin: '' MacroBlockEnd: '' MaxEmptyLinesToKeep: 1 @@ -91,15 +107,22 @@ PenaltyBreakFirstLessLess: 120 PenaltyBreakString: 1000 PenaltyBreakTemplateDeclaration: 10 PenaltyExcessCharacter: 1000000 +PenaltyIndentedWhitespace: 0 PenaltyReturnTypeOnItsOwnLine: 200 PointerAlignment: Right +PPIndentWidth: -1 +ReferenceAlignment: Pointer ReflowComments: false # true -SortIncludes: false # disabled, because we need case insensitive sort +ShortNamespaceLines: 0 # 1 +SortIncludes: CaseInsensitive # CaseSensitive +# SortJavaStaticImport: Before SortUsingDeclarations: false # true SpaceAfterCStyleCast: false SpaceAfterLogicalNot: false SpaceAfterTemplateKeyword: true +SpaceAroundPointerQualifiers: Default SpaceBeforeAssignmentOperators: true +SpaceBeforeCaseColon: false SpaceBeforeCpp11BracedList: false SpaceBeforeCtorInitializerColon: true SpaceBeforeInheritanceColon: true @@ -109,10 +132,13 @@ SpaceBeforeSquareBrackets: false SpaceInEmptyBlock: false SpaceInEmptyParentheses: false SpacesBeforeTrailingComments: 2 -SpacesInAngles: false +SpacesInAngles: Never SpacesInConditionalStatement: false SpacesInContainerLiterals: true SpacesInCStyleCastParentheses: false +SpacesInLineCommentPrefix: + Minimum: 1 + Maximum: 1 # -1 SpacesInParentheses: false SpacesInSquareBrackets: false Standard: Auto diff --git a/telegram-bot-api/ClientParameters.h b/telegram-bot-api/ClientParameters.h index b08bde7..79607f7 100644 --- a/telegram-bot-api/ClientParameters.h +++ b/telegram-bot-api/ClientParameters.h @@ -23,7 +23,7 @@ namespace td { class NetQueryStats; -} +} // namespace td namespace telegram_bot_api { From 75229c6209907ed82f9cc199eef1001bb619c1ea Mon Sep 17 00:00:00 2001 From: Mammad <67197540+Mammad900@users.noreply.github.com> Date: Tue, 14 Dec 2021 07:58:27 +0330 Subject: [PATCH 02/19] Update build.html --- build.html | 177 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 172 insertions(+), 5 deletions(-) diff --git a/build.html b/build.html index ab82511..b2c7b6d 100644 --- a/build.html +++ b/build.html @@ -3,11 +3,178 @@ Telegram Bot API server build instructions - + From 34b8e7d15e37ee39085b13f5fe92a557a9266ed1 Mon Sep 17 00:00:00 2001 From: Mammad <67197540+Mammad900@users.noreply.github.com> Date: Tue, 14 Dec 2021 08:01:35 +0330 Subject: [PATCH 03/19] Do not center text in build.html --- build.html | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/build.html b/build.html index b2c7b6d..b9ce4bd 100644 --- a/build.html +++ b/build.html @@ -180,7 +180,7 @@
-
+

Choose an operating system, on which you want to use the Telegram Bot API server:

@@ -212,7 +212,7 @@

-
+
@@ -258,11 +258,11 @@

-
+

Hidden text

-
+

Hidden text

Empty commands
From 8408c187d6147914c671ede4c5d620886adb344c Mon Sep 17 00:00:00 2001 From: Mammad <67197540+Mammad900@users.noreply.github.com> Date: Tue, 14 Dec 2021 08:06:23 +0330 Subject: [PATCH 04/19] Add copy button to build.html --- build.html | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/build.html b/build.html index b9ce4bd..7e8eb73 100644 --- a/build.html +++ b/build.html @@ -265,6 +265,9 @@

Hidden text

Empty commands +
@@ -652,6 +655,26 @@ function onOptionsChanged() { } commands.push((use_powershell ? 'dir ' : 'ls -l ') + install_dir + '/bin/telegram-bot-api*'); document.getElementById('buildCommands').innerHTML = '
  • ' + commands.join('
  • ') + '
'; + document.getElementById('copyBuildCommandsButton').style.display = commands.includes('exit') ? 'none' : 'block'; +} + +function copyBuildInstructions() { + var text = document.getElementById('buildCommands').innerText; + + function resetButtonState (state) { + document.getElementById('copyBuildCommandsButton').classList.remove(state); + document.getElementById('copyBuildCommandsText').innerText = "Copy"; + } + + navigator.clipboard.writeText(text).then(result => { + document.getElementById('copyBuildCommandsButton').classList.add('success'); + document.getElementById('copyBuildCommandsText').innerText = "Copied!"; + setTimeout(() => resetButtonState('success'), 5000); + }, error => { + document.getElementById('copyBuildCommandsButton').classList.add('fail'); + document.getElementById('copyBuildCommandsText').innerText = "Couldn't copy :("; + setTimeout(() => resetButtonState('fail'), 5000); + }) } From a3ba6536900e4fddb305790bd6481d59ca2284cf Mon Sep 17 00:00:00 2001 From: snxx-lppxx Date: Sat, 18 Dec 2021 05:26:08 +0500 Subject: [PATCH 05/19] README.md: updated the code field --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 28f40f6..e04c743 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ If you do that, you'll only need to choose the target operating system to receiv In general, you need to install all `Telegram Bot API server` [dependencies](#dependencies) and compile the source code using CMake: -``` +```sh git clone --recursive https://github.com/tdlib/telegram-bot-api.git cd telegram-bot-api mkdir build From 6abdb73512110c2adfaa7145eb01e102e75b89f6 Mon Sep 17 00:00:00 2001 From: levlam Date: Sat, 18 Dec 2021 23:26:05 +0300 Subject: [PATCH 06/19] Remove legacy message LRU deletion. --- telegram-bot-api/Client.cpp | 60 ++----------------------------------- telegram-bot-api/Client.h | 13 -------- 2 files changed, 2 insertions(+), 71 deletions(-) diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp index dbf9f4f..7d2ba45 100644 --- a/telegram-bot-api/Client.cpp +++ b/telegram-bot-api/Client.cpp @@ -184,9 +184,6 @@ Client::Client(td::ActorShared<> parent, const td::string &bot_token, bool is_te , tqueue_id_(tqueue_id) , parameters_(std::move(parameters)) , stat_actor_(std::move(stat_actor)) { - messages_lru_root_.lru_next = &messages_lru_root_; - messages_lru_root_.lru_prev = &messages_lru_root_; - static auto is_inited = init_methods(); CHECK(is_inited); } @@ -3505,7 +3502,6 @@ ServerBotInfo Client::get_bot_info() const { void Client::start_up() { start_time_ = td::Time::now(); next_bot_updates_warning_time_ = start_time_ + 600; - schedule_next_delete_messages_lru(); webhook_set_time_ = start_time_; next_allowed_set_webhook_time_ = start_time_; next_set_webhook_logging_time_ = start_time_; @@ -9462,58 +9458,12 @@ void Client::delete_message(int64 chat_id, int64 message_id, bool only_from_cach } auto message_info = it->second.get(); - CHECK(message_info->lru_next != nullptr); - message_info->lru_next->lru_prev = message_info->lru_prev; - message_info->lru_prev->lru_next = message_info->lru_next; set_message_reply_to_message_id(message_info, 0); messages_.erase(it); } -void Client::schedule_next_delete_messages_lru() { - CHECK(!next_delete_messages_lru_timeout_.has_timeout()); - next_delete_messages_lru_timeout_.set_callback(Client::delete_messages_lru); - next_delete_messages_lru_timeout_.set_callback_data(static_cast(this)); - next_delete_messages_lru_timeout_.set_timeout_in(td::Random::fast(MESSAGES_CACHE_TIME, 2 * MESSAGES_CACHE_TIME)); -} - -void Client::delete_messages_lru(void *client_void) { - CHECK(client_void != nullptr); - auto client = static_cast(client_void); - - auto now = td::Time::now(); - int32 deleted_message_count = 0; - while (client->messages_lru_root_.lru_next->access_time < now - MESSAGES_CACHE_TIME) { - auto message = client->messages_lru_root_.lru_next; - if (client->yet_unsent_reply_message_ids_.count({message->chat_id, message->id})) { - LOG(DEBUG) << "Force usage of message " << message->id << " in " << message->chat_id; - client->update_message_lru(message); - } else { - client->delete_message(message->chat_id, message->id, true); - deleted_message_count++; - } - } - - if (deleted_message_count != 0) { - LOG(DEBUG) << "Delete " << deleted_message_count << " messages from cache"; - } - client->schedule_next_delete_messages_lru(); -} - -void Client::update_message_lru(const MessageInfo *message_info) const { - message_info->access_time = td::Time::now(); - if (message_info->lru_next != nullptr) { - message_info->lru_next->lru_prev = message_info->lru_prev; - message_info->lru_prev->lru_next = message_info->lru_next; - } - auto prev = messages_lru_root_.lru_prev; - message_info->lru_prev = prev; - prev->lru_next = message_info; - message_info->lru_next = &messages_lru_root_; - messages_lru_root_.lru_prev = message_info; -} - Client::FullMessageId Client::add_message(object_ptr &&message, bool force_update_content) { CHECK(message != nullptr); CHECK(message->sending_state_ == nullptr); @@ -9530,8 +9480,6 @@ Client::FullMessageId Client::add_message(object_ptr &&message, message_info = std::move(it->second); } - update_message_lru(message_info.get()); - message_info->id = message_id; message_info->chat_id = chat_id; message_info->date = message->date_; @@ -9673,9 +9621,7 @@ const Client::MessageInfo *Client::get_message(int64 chat_id, int64 message_id) } LOG(DEBUG) << "Found message " << message_id << " from chat " << chat_id; - auto result = it->second.get(); - update_message_lru(result); - return result; + return it->second.get(); } Client::MessageInfo *Client::get_message_editable(int64 chat_id, int64 message_id) { @@ -9686,9 +9632,7 @@ Client::MessageInfo *Client::get_message_editable(int64 chat_id, int64 message_i } LOG(DEBUG) << "Found message " << message_id << " from chat " << chat_id; - auto result = it->second.get(); - update_message_lru(result); - return result; + return it->second.get(); } td::string Client::get_chat_member_status(const object_ptr &status) { diff --git a/telegram-bot-api/Client.h b/telegram-bot-api/Client.h index 7468ab0..6cd452f 100644 --- a/telegram-bot-api/Client.h +++ b/telegram-bot-api/Client.h @@ -15,7 +15,6 @@ #include "td/actor/actor.h" #include "td/actor/PromiseFuture.h" #include "td/actor/SignalSlot.h" -#include "td/actor/Timeout.h" #include "td/utils/common.h" #include "td/utils/Container.h" @@ -65,8 +64,6 @@ class Client : public WebhookActor::Callback { static constexpr int32 MAX_CONCURRENTLY_SENT_CHAT_MESSAGES = 1000; // some unreasonably big value - static constexpr int32 MESSAGES_CACHE_TIME = 3600; - static constexpr std::size_t MIN_PENDING_UPDATES_WARNING = 200; static constexpr int64 GREAT_MINDS_SET_ID = 1842540969984001; @@ -657,10 +654,6 @@ class Client : public WebhookActor::Callback { td::string get_chat_description(int64 chat_id) const; struct MessageInfo { - mutable double access_time = 1e20; - mutable const MessageInfo *lru_next = nullptr; - mutable const MessageInfo *lru_prev = nullptr; - int64 id = 0; int64 sender_user_id = 0; int64 sender_chat_id = 0; @@ -722,9 +715,6 @@ class Client : public WebhookActor::Callback { void remove_replies_to_message(int64 chat_id, int64 reply_to_message_id, bool only_from_cache); void delete_message(int64 chat_id, int64 message_id, bool only_from_cache); - static void delete_messages_lru(void *client_void); - void schedule_next_delete_messages_lru(); - void update_message_lru(const MessageInfo *message_info) const; void add_new_message(object_ptr &&message, bool is_edited); void process_new_message_queue(int64 chat_id); @@ -871,7 +861,6 @@ class Client : public WebhookActor::Callback { static std::unordered_map methods_; - MessageInfo messages_lru_root_; std::unordered_map, FullMessageIdHash> messages_; // message cache std::unordered_map users_; // user info cache std::unordered_map groups_; // group info cache @@ -883,8 +872,6 @@ class Client : public WebhookActor::Callback { std::unordered_map, FullMessageIdHash> yet_unsent_reply_message_ids_; // message -> replies to it - td::Timeout next_delete_messages_lru_timeout_; - std::unordered_map> file_download_listeners_; std::unordered_set download_started_file_ids_; From 14f11a9d0d3cce29d854e863ef92fc752a6a2763 Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 23 Dec 2021 15:04:56 +0300 Subject: [PATCH 07/19] Expect different Homebrew install paths on Apple silicon/Intel. --- build.html | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/build.html b/build.html index 7e8eb73..dd5030c 100644 --- a/build.html +++ b/build.html @@ -244,6 +244,13 @@

+
+ Choose host architecture:
+ + +

+
+
Choose for which bitness you want to build the Telegram Bot API server:
@@ -363,6 +370,8 @@ function onOptionsChanged() { var use_powershell = false; var use_cmd = false; var use_csh = false; + var homebrew_install_dir = ''; + var os_mac_host_name = ''; if (os_windows) { document.getElementById('buildShellDiv').style.display = 'block'; use_powershell = document.getElementById('buildShellRadioPowerShell').checked; @@ -375,6 +384,18 @@ function onOptionsChanged() { } else { document.getElementById('buildShellBsdDiv').style.display = 'none'; } + if (os_mac) { + document.getElementById('buildMacOsHostDiv').style.display = 'block'; + if (document.getElementById('buildMacOsHostRadioAppleSilicon').checked) { + homebrew_install_dir = '/opt/homebrew'; + os_mac_host_name = 'Apple silicon'; + } else { + homebrew_install_dir = '/usr/local'; + os_mac_host_name = 'Intel'; + } + } else { + document.getElementById('buildMacOsHostDiv').style.display = 'none'; + } var use_msvc = os_windows; var use_vcpkg = os_windows; @@ -482,7 +503,7 @@ function onOptionsChanged() { var cmake = 'cmake'; if (os_mac) { commands.push('xcode-select --install'); - commands.push('/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"'); + commands.push('/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"'); commands.push('brew install gperf cmake openssl'); } else if (os_linux && linux_distro !== 'Other') { switch (linux_distro) { @@ -605,7 +626,7 @@ function onOptionsChanged() { cmake_init_options = getBacicCmakeInitOptions(); if (os_mac) { - cmake_init_options.push('-DOPENSSL_ROOT_DIR=/usr/local/opt/openssl/'); + cmake_init_options.push('-DOPENSSL_ROOT_DIR=' + homebrew_install_dir + '/opt/openssl/'); } cmake_init_options.push('-DCMAKE_INSTALL_PREFIX:PATH=' + install_dir); if (use_vcpkg) { From 8e637b482a2de9b8e298a81a7625b224979ccfc1 Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 30 Dec 2021 14:34:39 +0300 Subject: [PATCH 08/19] Update TDLib to 1.8.0. --- td | 2 +- telegram-bot-api/Client.cpp | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/td b/td index 6821219..feffe41 160000 --- a/td +++ b/td @@ -1 +1 @@ -Subproject commit 68212198a0e44086bd8a63d23365c3f56e391f0f +Subproject commit feffe4153d0d1da2abc1bd419bb1ed6a83896eb7 diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp index 7d2ba45..0a0f81b 100644 --- a/telegram-bot-api/Client.cpp +++ b/telegram-bot-api/Client.cpp @@ -563,8 +563,8 @@ class Client::JsonChatInviteLink : public Jsonable { object("name", chat_invite_link_->name_); } object("creator", JsonUser(chat_invite_link_->creator_user_id_, client_)); - if (chat_invite_link_->expire_date_ != 0) { - object("expire_date", chat_invite_link_->expire_date_); + if (chat_invite_link_->expiration_date_ != 0) { + object("expire_date", chat_invite_link_->expiration_date_); } if (chat_invite_link_->member_limit_ != 0) { object("member_limit", chat_invite_link_->member_limit_); @@ -4343,7 +4343,7 @@ void Client::on_update(object_ptr result) { chat_info->title = std::move(chat->title_); chat_info->photo = std::move(chat->photo_); chat_info->permissions = std::move(chat->permissions_); - chat_info->message_auto_delete_time = chat->message_ttl_setting_; + chat_info->message_auto_delete_time = chat->message_ttl_; chat_info->has_protected_content = chat->has_protected_content_; break; } @@ -4368,11 +4368,11 @@ void Client::on_update(object_ptr result) { chat_info->permissions = std::move(update->permissions_); break; } - case td_api::updateChatMessageTtlSetting::ID: { - auto update = move_object_as(result); + case td_api::updateChatMessageTtl::ID: { + auto update = move_object_as(result); auto chat_info = add_chat(update->chat_id_); CHECK(chat_info->type != ChatInfo::Type::Unknown); - chat_info->message_auto_delete_time = update->message_ttl_setting_; + chat_info->message_auto_delete_time = update->message_ttl_; break; } case td_api::updateChatHasProtectedContent::ID: { @@ -5250,7 +5250,7 @@ td::Result> Client::get_input_me } td_api::object_ptr Client::get_message_send_options(bool disable_notification) { - return make_object(disable_notification, false, nullptr); + return make_object(disable_notification, false, false, nullptr); } td::Result>> Client::get_inline_query_results( From 6ec2104b810cebc3bdde02d7b45e00ea253df06d Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 30 Dec 2021 14:41:30 +0300 Subject: [PATCH 09/19] Add the ability to send messages with protected content. --- telegram-bot-api/Client.cpp | 32 +++++++++++++++++++------------- telegram-bot-api/Client.h | 3 ++- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp index 0a0f81b..5c79ff9 100644 --- a/telegram-bot-api/Client.cpp +++ b/telegram-bot-api/Client.cpp @@ -5249,8 +5249,9 @@ td::Result> Client::get_input_me return nullptr; } -td_api::object_ptr Client::get_message_send_options(bool disable_notification) { - return make_object(disable_notification, false, false, nullptr); +td_api::object_ptr Client::get_message_send_options(bool disable_notification, + bool protect_content) { + return make_object(disable_notification, false, protect_content, nullptr); } td::Result>> Client::get_inline_query_results( @@ -6846,6 +6847,7 @@ td::Status Client::process_send_media_group_query(PromisedQueryPtr &query) { auto reply_to_message_id = get_message_id(query.get(), "reply_to_message_id"); auto allow_sending_without_reply = to_bool(query->arg("allow_sending_without_reply")); auto disable_notification = to_bool(query->arg("disable_notification")); + auto protect_content = to_bool(query->arg("protect_content")); // TRY_RESULT(reply_markup, get_reply_markup(query.get())); auto reply_markup = nullptr; TRY_RESULT(input_message_contents, get_input_message_contents(query.get(), "media")); @@ -6853,9 +6855,10 @@ td::Status Client::process_send_media_group_query(PromisedQueryPtr &query) { resolve_reply_markup_bot_usernames( std::move(reply_markup), std::move(query), [this, chat_id = chat_id.str(), reply_to_message_id, allow_sending_without_reply, disable_notification, - input_message_contents = std::move(input_message_contents)](object_ptr reply_markup, - PromisedQueryPtr query) mutable { - auto on_success = [this, disable_notification, input_message_contents = std::move(input_message_contents), + protect_content, input_message_contents = std::move(input_message_contents)]( + object_ptr reply_markup, PromisedQueryPtr query) mutable { + auto on_success = [this, disable_notification, protect_content, + input_message_contents = std::move(input_message_contents), reply_markup = std::move(reply_markup)](int64 chat_id, int64 reply_to_message_id, PromisedQueryPtr query) mutable { auto it = yet_unsent_message_count_.find(chat_id); @@ -6863,10 +6866,11 @@ td::Status Client::process_send_media_group_query(PromisedQueryPtr &query) { return query->set_retry_after_error(60); } - send_request(make_object(chat_id, 0, reply_to_message_id, - get_message_send_options(disable_notification), - std::move(input_message_contents)), - std::make_unique(this, std::move(query))); + send_request( + make_object(chat_id, 0, reply_to_message_id, + get_message_send_options(disable_notification, protect_content), + std::move(input_message_contents)), + std::make_unique(this, std::move(query))); }; check_message(chat_id, reply_to_message_id, reply_to_message_id <= 0 || allow_sending_without_reply, AccessRights::Write, "replied message", std::move(query), std::move(on_success)); @@ -8184,6 +8188,7 @@ void Client::do_send_message(object_ptr input_messa auto reply_to_message_id = get_message_id(query.get(), "reply_to_message_id"); auto allow_sending_without_reply = to_bool(query->arg("allow_sending_without_reply")); auto disable_notification = to_bool(query->arg("disable_notification")); + auto protect_content = to_bool(query->arg("protect_content")); auto r_reply_markup = get_reply_markup(query.get()); if (r_reply_markup.is_error()) { return fail_query_with_error(std::move(query), 400, r_reply_markup.error().message()); @@ -8193,9 +8198,10 @@ void Client::do_send_message(object_ptr input_messa resolve_reply_markup_bot_usernames( std::move(reply_markup), std::move(query), [this, chat_id = chat_id.str(), reply_to_message_id, allow_sending_without_reply, disable_notification, - input_message_content = std::move(input_message_content)](object_ptr reply_markup, - PromisedQueryPtr query) mutable { - auto on_success = [this, disable_notification, input_message_content = std::move(input_message_content), + protect_content, input_message_content = std::move(input_message_content)]( + object_ptr reply_markup, PromisedQueryPtr query) mutable { + auto on_success = [this, disable_notification, protect_content, + input_message_content = std::move(input_message_content), reply_markup = std::move(reply_markup)](int64 chat_id, int64 reply_to_message_id, PromisedQueryPtr query) mutable { auto it = yet_unsent_message_count_.find(chat_id); @@ -8204,7 +8210,7 @@ void Client::do_send_message(object_ptr input_messa } send_request(make_object(chat_id, 0, reply_to_message_id, - get_message_send_options(disable_notification), + get_message_send_options(disable_notification, protect_content), std::move(reply_markup), std::move(input_message_content)), std::make_unique(this, std::move(query))); }; diff --git a/telegram-bot-api/Client.h b/telegram-bot-api/Client.h index 6cd452f..fee9aad 100644 --- a/telegram-bot-api/Client.h +++ b/telegram-bot-api/Client.h @@ -412,7 +412,8 @@ class Client : public WebhookActor::Callback { td::Result>> get_input_message_contents( const Query *query, td::JsonValue &&value) const; - static object_ptr get_message_send_options(bool disable_notification); + static object_ptr get_message_send_options(bool disable_notification, + bool protect_content); static td::Result> get_poll_options(const Query *query); From 6b137be127be166f81f5225f1bee5c06934953f1 Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 30 Dec 2021 14:44:21 +0300 Subject: [PATCH 10/19] Add support for spoiler entities. --- telegram-bot-api/Client.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp index 5c79ff9..71a7a2e 100644 --- a/telegram-bot-api/Client.cpp +++ b/telegram-bot-api/Client.cpp @@ -417,6 +417,9 @@ class Client::JsonEntity : public Jsonable { case td_api::textEntityTypeStrikethrough::ID: object("type", "strikethrough"); break; + case td_api::textEntityTypeSpoiler::ID: + object("type", "spoiler"); + break; case td_api::textEntityTypeCode::ID: object("type", "code"); break; @@ -5934,6 +5937,9 @@ td::Result> Client::get_text_entity_t if (type == "strikethrough") { return make_object(); } + if (type == "spoiler") { + return make_object(); + } if (type == "code") { return make_object(); } From 01ff608cfacdac59f981854e5caabef8fb1e8f49 Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 30 Dec 2021 17:18:30 +0300 Subject: [PATCH 11/19] Improve log message. --- telegram-bot-api/Client.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp index 71a7a2e..ff846d1 100644 --- a/telegram-bot-api/Client.cpp +++ b/telegram-bot-api/Client.cpp @@ -2900,10 +2900,11 @@ class Client::TdOnResolveBotUsernameCallback : public TdQueryCallback { template class Client::TdOnCheckMessageCallback : public TdQueryCallback { public: - TdOnCheckMessageCallback(Client *client, int64 chat_id, bool allow_empty, Slice message_type, PromisedQueryPtr query, - OnSuccess on_success) + TdOnCheckMessageCallback(Client *client, int64 chat_id, int64 message_id, bool allow_empty, Slice message_type, + PromisedQueryPtr query, OnSuccess on_success) : client_(client) , chat_id_(chat_id) + , message_id_(message_id) , allow_empty_(allow_empty) , message_type_(message_type) , query_(std::move(query)) @@ -2914,7 +2915,7 @@ class Client::TdOnCheckMessageCallback : public TdQueryCallback { if (result->get_id() == td_api::error::ID) { auto error = move_object_as(result); if (error->code_ == 429) { - LOG(WARNING) << "Failed to get " << message_type_; + LOG(WARNING) << "Failed to get message " << message_id_ << " in " << chat_id_ << ": " << message_type_; } if (allow_empty_) { return on_success_(chat_id_, 0, std::move(query_)); @@ -2925,12 +2926,14 @@ class Client::TdOnCheckMessageCallback : public TdQueryCallback { CHECK(result->get_id() == td_api::message::ID); auto full_message_id = client_->add_message(move_object_as(result)); CHECK(full_message_id.chat_id == chat_id_); + CHECK(full_message_id.message_id == message_id_); on_success_(full_message_id.chat_id, full_message_id.message_id, std::move(query_)); } private: Client *client_; int64 chat_id_; + int64 message_id_; bool allow_empty_; Slice message_type_; PromisedQueryPtr query_; @@ -3926,9 +3929,10 @@ void Client::check_message(Slice chat_id_str, int64 message_id, bool allow_empty return on_success(chat_id, 0, std::move(query)); } - send_request(make_object(chat_id, message_id), - std::make_unique>( - this, chat_id, allow_empty, message_type, std::move(query), std::move(on_success))); + send_request( + make_object(chat_id, message_id), + std::make_unique>( + this, chat_id, message_id, allow_empty, message_type, std::move(query), std::move(on_success))); }); } From d95441a48da9691436d6d21ddef933205793faaa Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 30 Dec 2021 21:01:14 +0300 Subject: [PATCH 12/19] Allow all updateUser updates before authorization. --- telegram-bot-api/Client.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp index ff846d1..f48e5b6 100644 --- a/telegram-bot-api/Client.cpp +++ b/telegram-bot-api/Client.cpp @@ -4231,7 +4231,7 @@ bool Client::allow_update_before_authorization(const td_api::Object *update) con return name == "my_id" || name == "unix_time"; } if (update_id == td_api::updateUser::ID) { - return static_cast(update)->user_->id_ == my_id_; + return true; } return false; } From b75e6b43cde0c1269baeb52f25ae6d0b59d9fdfb Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 30 Dec 2021 21:09:17 +0300 Subject: [PATCH 13/19] Update version to 5.6. --- CMakeLists.txt | 2 +- telegram-bot-api/telegram-bot-api.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8c5a221..1fc00b4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,7 @@ if (POLICY CMP0065) cmake_policy(SET CMP0065 NEW) endif() -project(TelegramBotApi VERSION 5.5.1 LANGUAGES CXX) +project(TelegramBotApi VERSION 5.6 LANGUAGES CXX) if (POLICY CMP0069) option(TELEGRAM_BOT_API_ENABLE_LTO "Use \"ON\" to enable Link Time Optimization.") diff --git a/telegram-bot-api/telegram-bot-api.cpp b/telegram-bot-api/telegram-bot-api.cpp index f850db3..00a4546 100644 --- a/telegram-bot-api/telegram-bot-api.cpp +++ b/telegram-bot-api/telegram-bot-api.cpp @@ -200,7 +200,7 @@ int main(int argc, char *argv[]) { auto start_time = td::Time::now(); auto shared_data = std::make_shared(); auto parameters = std::make_unique(); - parameters->version_ = "5.5.1"; + parameters->version_ = "5.6"; parameters->shared_data_ = shared_data; parameters->start_time_ = start_time; auto net_query_stats = td::create_net_query_stats(); From 9be6413e5ccbad08611c9a59622ba48aae2297c5 Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 31 Dec 2021 08:20:44 +0300 Subject: [PATCH 14/19] Improve logging. --- telegram-bot-api/Client.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp index f48e5b6..9f945b4 100644 --- a/telegram-bot-api/Client.cpp +++ b/telegram-bot-api/Client.cpp @@ -2629,7 +2629,7 @@ class Client::TdOnDeleteFailedToSendMessageCallback : public TdQueryCallback { void on_result(object_ptr result) override { if (result->get_id() == td_api::error::ID) { auto error = move_object_as(result); - if (error->code_ != 401) { + if (error->code_ != 401 && !client_->need_close_ && !client_->closing_ && !client_->logging_out_) { LOG(ERROR) << "Can't delete failed to send message " << message_id_ << " because of " << td::oneline(to_string(error)) << " in " << client_->get_chat_description(chat_id_) << ". Old chat description: " << old_chat_description_; @@ -4178,6 +4178,7 @@ void Client::on_update_authorization_state() { case td_api::authorizationStateReady::ID: { auto user_info = get_user_info(my_id_); if (my_id_ <= 0 || user_info == nullptr) { + LOG(INFO) << "Send getMe request for " << my_id_; return send_request(make_object(), std::make_unique(this)); } From d8a00b2c8ba0b85e8734115aa4162a4b730dee6c Mon Sep 17 00:00:00 2001 From: levlam Date: Sat, 1 Jan 2022 12:44:12 +0300 Subject: [PATCH 15/19] Update TDLib. --- td | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/td b/td index feffe41..14637ca 160000 --- a/td +++ b/td @@ -1 +1 @@ -Subproject commit feffe4153d0d1da2abc1bd419bb1ed6a83896eb7 +Subproject commit 14637caa64c2c992c1cde7c92cadb43a83d4435e From 93ccd2a145926612dc45c5e095560e43fbd94d2a Mon Sep 17 00:00:00 2001 From: levlam Date: Sat, 1 Jan 2022 12:45:09 +0300 Subject: [PATCH 16/19] Update version to 5.6.1. --- CMakeLists.txt | 2 +- telegram-bot-api/telegram-bot-api.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1fc00b4..694a31e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,7 @@ if (POLICY CMP0065) cmake_policy(SET CMP0065 NEW) endif() -project(TelegramBotApi VERSION 5.6 LANGUAGES CXX) +project(TelegramBotApi VERSION 5.6.1 LANGUAGES CXX) if (POLICY CMP0069) option(TELEGRAM_BOT_API_ENABLE_LTO "Use \"ON\" to enable Link Time Optimization.") diff --git a/telegram-bot-api/telegram-bot-api.cpp b/telegram-bot-api/telegram-bot-api.cpp index 00a4546..cf423ee 100644 --- a/telegram-bot-api/telegram-bot-api.cpp +++ b/telegram-bot-api/telegram-bot-api.cpp @@ -200,7 +200,7 @@ int main(int argc, char *argv[]) { auto start_time = td::Time::now(); auto shared_data = std::make_shared(); auto parameters = std::make_unique(); - parameters->version_ = "5.6"; + parameters->version_ = "5.6.1"; parameters->shared_data_ = shared_data; parameters->start_time_ = start_time; auto net_query_stats = td::create_net_query_stats(); From 208fd70d58a80df64986497c1e4c82957b6669b3 Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 25 Jan 2022 18:18:44 +0300 Subject: [PATCH 17/19] Minor improvements. --- build.html | 2 +- telegram-bot-api/Client.cpp | 329 +++++++++++++------------- telegram-bot-api/Client.h | 23 +- telegram-bot-api/ClientManager.cpp | 3 +- telegram-bot-api/ClientManager.h | 6 +- telegram-bot-api/ClientParameters.h | 4 +- telegram-bot-api/HttpConnection.h | 14 +- telegram-bot-api/HttpServer.h | 14 +- telegram-bot-api/HttpStatConnection.h | 14 +- telegram-bot-api/Query.h | 12 +- telegram-bot-api/Stats.h | 4 +- telegram-bot-api/WebhookActor.cpp | 6 +- telegram-bot-api/WebhookActor.h | 20 +- telegram-bot-api/telegram-bot-api.cpp | 20 +- 14 files changed, 236 insertions(+), 235 deletions(-) diff --git a/build.html b/build.html index dd5030c..409fb28 100644 --- a/build.html +++ b/build.html @@ -678,7 +678,7 @@ function onOptionsChanged() { document.getElementById('buildCommands').innerHTML = '
  • ' + commands.join('
  • ') + '
'; document.getElementById('copyBuildCommandsButton').style.display = commands.includes('exit') ? 'none' : 'block'; } - + function copyBuildInstructions() { var text = document.getElementById('buildCommands').innerText; diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp index 9f945b4..aec0787 100644 --- a/telegram-bot-api/Client.cpp +++ b/telegram-bot-api/Client.cpp @@ -8,11 +8,11 @@ #include "telegram-bot-api/ClientParameters.h" +#include "td/db/TQueue.h" + #include "td/actor/PromiseFuture.h" #include "td/actor/SleepActor.h" -#include "td/db/TQueue.h" - #include "td/utils/algorithm.h" #include "td/utils/base64.h" #include "td/utils/filesystem.h" @@ -23,7 +23,6 @@ #include "td/utils/PathView.h" #include "td/utils/port/path.h" #include "td/utils/port/Stat.h" -#include "td/utils/Random.h" #include "td/utils/Slice.h" #include "td/utils/SliceBuilder.h" #include "td/utils/Span.h" @@ -276,7 +275,7 @@ bool Client::init_methods() { return true; } -class Client::JsonFile : public Jsonable { +class Client::JsonFile final : public Jsonable { public: JsonFile(const td_api::file *file, const Client *client) : file_(file), client_(client) { } @@ -290,7 +289,7 @@ class Client::JsonFile : public Jsonable { const Client *client_; }; -class Client::JsonDatedFile : public Jsonable { +class Client::JsonDatedFile final : public Jsonable { public: JsonDatedFile(const td_api::datedFile *file, const Client *client) : file_(file), client_(client) { } @@ -305,7 +304,7 @@ class Client::JsonDatedFile : public Jsonable { const Client *client_; }; -class Client::JsonDatedFiles : public Jsonable { +class Client::JsonDatedFiles final : public Jsonable { public: JsonDatedFiles(const td::vector> &files, const Client *client) : files_(files), client_(client) { @@ -322,7 +321,7 @@ class Client::JsonDatedFiles : public Jsonable { const Client *client_; }; -class Client::JsonUser : public Jsonable { +class Client::JsonUser final : public Jsonable { public: JsonUser(int64 user_id, const Client *client, bool full_bot_info = false) : user_id_(user_id), client_(client), full_bot_info_(full_bot_info) { @@ -356,7 +355,7 @@ class Client::JsonUser : public Jsonable { bool full_bot_info_; }; -class Client::JsonUsers : public Jsonable { +class Client::JsonUsers final : public Jsonable { public: JsonUsers(const td::vector &user_ids, const Client *client) : user_ids_(user_ids), client_(client) { } @@ -372,7 +371,7 @@ class Client::JsonUsers : public Jsonable { const Client *client_; }; -class Client::JsonEntity : public Jsonable { +class Client::JsonEntity final : public Jsonable { public: JsonEntity(const td_api::textEntity *entity, const Client *client) : entity_(entity), client_(client) { } @@ -454,7 +453,7 @@ class Client::JsonEntity : public Jsonable { const Client *client_; }; -class Client::JsonVectorEntities : public Jsonable { +class Client::JsonVectorEntities final : public Jsonable { public: JsonVectorEntities(const td::vector> &entities, const Client *client) : entities_(entities), client_(client) { @@ -475,7 +474,7 @@ class Client::JsonVectorEntities : public Jsonable { const Client *client_; }; -class Client::JsonLocation : public Jsonable { +class Client::JsonLocation final : public Jsonable { public: explicit JsonLocation(const td_api::location *location, double expires_in = 0.0, int32 live_period = 0, int32 heading = 0, int32 proximity_alert_radius = 0) @@ -511,7 +510,7 @@ class Client::JsonLocation : public Jsonable { int32 proximity_alert_radius_; }; -class Client::JsonChatPermissions : public Jsonable { +class Client::JsonChatPermissions final : public Jsonable { public: explicit JsonChatPermissions(const td_api::chatPermissions *chat_permissions) : chat_permissions_(chat_permissions) { } @@ -524,7 +523,7 @@ class Client::JsonChatPermissions : public Jsonable { const td_api::chatPermissions *chat_permissions_; }; -class Client::JsonChatPhotoInfo : public Jsonable { +class Client::JsonChatPhotoInfo final : public Jsonable { public: explicit JsonChatPhotoInfo(const td_api::chatPhotoInfo *chat_photo) : chat_photo_(chat_photo) { } @@ -540,7 +539,7 @@ class Client::JsonChatPhotoInfo : public Jsonable { const td_api::chatPhotoInfo *chat_photo_; }; -class Client::JsonChatLocation : public Jsonable { +class Client::JsonChatLocation final : public Jsonable { public: explicit JsonChatLocation(const td_api::chatLocation *chat_location) : chat_location_(chat_location) { } @@ -554,7 +553,7 @@ class Client::JsonChatLocation : public Jsonable { const td_api::chatLocation *chat_location_; }; -class Client::JsonChatInviteLink : public Jsonable { +class Client::JsonChatInviteLink final : public Jsonable { public: JsonChatInviteLink(const td_api::chatInviteLink *chat_invite_link, const Client *client) : chat_invite_link_(chat_invite_link), client_(client) { @@ -585,7 +584,7 @@ class Client::JsonChatInviteLink : public Jsonable { const Client *client_; }; -class Client::JsonMessage : public Jsonable { +class Client::JsonMessage final : public Jsonable { public: JsonMessage(const MessageInfo *message, bool need_reply, const td::string &source, const Client *client) : message_(message), need_reply_(need_reply), source_(source), client_(client) { @@ -610,7 +609,7 @@ class Client::JsonMessage : public Jsonable { } }; -class Client::JsonChat : public Jsonable { +class Client::JsonChat final : public Jsonable { public: JsonChat(int64 chat_id, bool is_full, const Client *client, int64 pinned_message_id = -1) : chat_id_(chat_id), is_full_(is_full), client_(client), pinned_message_id_(pinned_message_id) { @@ -746,7 +745,7 @@ class Client::JsonChat : public Jsonable { int64 pinned_message_id_; }; -class Client::JsonMessageSender : public Jsonable { +class Client::JsonMessageSender final : public Jsonable { public: JsonMessageSender(const td_api::MessageSender *sender_id, const Client *client) : sender_id_(sender_id), client_(client) { @@ -774,7 +773,7 @@ class Client::JsonMessageSender : public Jsonable { const Client *client_; }; -class Client::JsonMessages : public Jsonable { +class Client::JsonMessages final : public Jsonable { public: explicit JsonMessages(const td::vector &messages) : messages_(messages) { } @@ -789,7 +788,7 @@ class Client::JsonMessages : public Jsonable { const td::vector &messages_; }; -class Client::JsonAnimation : public Jsonable { +class Client::JsonAnimation final : public Jsonable { public: JsonAnimation(const td_api::animation *animation, bool as_document, const Client *client) : animation_(animation), as_document_(as_document), client_(client) { @@ -817,7 +816,7 @@ class Client::JsonAnimation : public Jsonable { const Client *client_; }; -class Client::JsonAudio : public Jsonable { +class Client::JsonAudio final : public Jsonable { public: JsonAudio(const td_api::audio *audio, const Client *client) : audio_(audio), client_(client) { } @@ -845,7 +844,7 @@ class Client::JsonAudio : public Jsonable { const Client *client_; }; -class Client::JsonDocument : public Jsonable { +class Client::JsonDocument final : public Jsonable { public: JsonDocument(const td_api::document *document, const Client *client) : document_(document), client_(client) { } @@ -866,7 +865,7 @@ class Client::JsonDocument : public Jsonable { const Client *client_; }; -class Client::JsonPhotoSize : public Jsonable { +class Client::JsonPhotoSize final : public Jsonable { public: JsonPhotoSize(const td_api::photoSize *photo_size, const Client *client) : photo_size_(photo_size), client_(client) { } @@ -882,7 +881,7 @@ class Client::JsonPhotoSize : public Jsonable { const Client *client_; }; -class Client::JsonThumbnail : public Jsonable { +class Client::JsonThumbnail final : public Jsonable { public: JsonThumbnail(const td_api::thumbnail *thumbnail, const Client *client) : thumbnail_(thumbnail), client_(client) { } @@ -898,7 +897,7 @@ class Client::JsonThumbnail : public Jsonable { const Client *client_; }; -class Client::JsonPhoto : public Jsonable { +class Client::JsonPhoto final : public Jsonable { public: JsonPhoto(const td_api::photo *photo, const Client *client) : photo_(photo), client_(client) { } @@ -916,7 +915,7 @@ class Client::JsonPhoto : public Jsonable { const Client *client_; }; -class Client::JsonChatPhoto : public Jsonable { +class Client::JsonChatPhoto final : public Jsonable { public: JsonChatPhoto(const td_api::chatPhoto *photo, const Client *client) : photo_(photo), client_(client) { } @@ -934,7 +933,7 @@ class Client::JsonChatPhoto : public Jsonable { const Client *client_; }; -class Client::JsonMaskPosition : public Jsonable { +class Client::JsonMaskPosition final : public Jsonable { public: explicit JsonMaskPosition(const td_api::maskPosition *mask_position) : mask_position_(mask_position) { } @@ -950,7 +949,7 @@ class Client::JsonMaskPosition : public Jsonable { const td_api::maskPosition *mask_position_; }; -class Client::JsonSticker : public Jsonable { +class Client::JsonSticker final : public Jsonable { public: JsonSticker(const td_api::sticker *sticker, const Client *client) : sticker_(sticker), client_(client) { } @@ -978,7 +977,7 @@ class Client::JsonSticker : public Jsonable { const Client *client_; }; -class Client::JsonStickers : public Jsonable { +class Client::JsonStickers final : public Jsonable { public: JsonStickers(const td::vector> &stickers, const Client *client) : stickers_(stickers), client_(client) { @@ -995,7 +994,7 @@ class Client::JsonStickers : public Jsonable { const Client *client_; }; -class Client::JsonVideo : public Jsonable { +class Client::JsonVideo final : public Jsonable { public: JsonVideo(const td_api::video *video, const Client *client) : video_(video), client_(client) { } @@ -1019,7 +1018,7 @@ class Client::JsonVideo : public Jsonable { const Client *client_; }; -class Client::JsonVideoNote : public Jsonable { +class Client::JsonVideoNote final : public Jsonable { public: JsonVideoNote(const td_api::videoNote *video_note, const Client *client) : video_note_(video_note), client_(client) { } @@ -1036,7 +1035,7 @@ class Client::JsonVideoNote : public Jsonable { const Client *client_; }; -class Client::JsonVoiceNote : public Jsonable { +class Client::JsonVoiceNote final : public Jsonable { public: JsonVoiceNote(const td_api::voiceNote *voice_note, const Client *client) : voice_note_(voice_note), client_(client) { } @@ -1054,7 +1053,7 @@ class Client::JsonVoiceNote : public Jsonable { const Client *client_; }; -class Client::JsonVenue : public Jsonable { +class Client::JsonVenue final : public Jsonable { public: explicit JsonVenue(const td_api::venue *venue) : venue_(venue) { } @@ -1085,7 +1084,7 @@ class Client::JsonVenue : public Jsonable { const td_api::venue *venue_; }; -class Client::JsonContact : public Jsonable { +class Client::JsonContact final : public Jsonable { public: explicit JsonContact(const td_api::contact *contact) : contact_(contact) { } @@ -1108,7 +1107,7 @@ class Client::JsonContact : public Jsonable { const td_api::contact *contact_; }; -class Client::JsonDice : public Jsonable { +class Client::JsonDice final : public Jsonable { public: JsonDice(const td::string &emoji, int32 value) : emoji_(emoji), value_(value) { } @@ -1123,7 +1122,7 @@ class Client::JsonDice : public Jsonable { int32 value_; }; -class Client::JsonGame : public Jsonable { +class Client::JsonGame final : public Jsonable { public: JsonGame(const td_api::game *game, const Client *client) : game_(game), client_(client) { } @@ -1149,7 +1148,7 @@ class Client::JsonGame : public Jsonable { const Client *client_; }; -class Client::JsonInvoice : public Jsonable { +class Client::JsonInvoice final : public Jsonable { public: explicit JsonInvoice(const td_api::messageInvoice *invoice) : invoice_(invoice) { } @@ -1170,7 +1169,7 @@ class Client::JsonInvoice : public Jsonable { const td_api::messageInvoice *invoice_; }; -class Client::JsonPollOption : public Jsonable { +class Client::JsonPollOption final : public Jsonable { public: explicit JsonPollOption(const td_api::pollOption *option) : option_(option) { } @@ -1185,7 +1184,7 @@ class Client::JsonPollOption : public Jsonable { const td_api::pollOption *option_; }; -class Client::JsonPoll : public Jsonable { +class Client::JsonPoll final : public Jsonable { public: JsonPoll(const td_api::poll *poll, const Client *client) : poll_(poll), client_(client) { } @@ -1232,7 +1231,7 @@ class Client::JsonPoll : public Jsonable { const Client *client_; }; -class Client::JsonPollAnswer : public Jsonable { +class Client::JsonPollAnswer final : public Jsonable { public: JsonPollAnswer(const td_api::updatePollAnswer *poll_answer, const Client *client) : poll_answer_(poll_answer), client_(client) { @@ -1249,7 +1248,7 @@ class Client::JsonPollAnswer : public Jsonable { const Client *client_; }; -class Client::JsonAddress : public Jsonable { +class Client::JsonAddress final : public Jsonable { public: explicit JsonAddress(const td_api::address *address) : address_(address) { } @@ -1267,7 +1266,7 @@ class Client::JsonAddress : public Jsonable { const td_api::address *address_; }; -class Client::JsonOrderInfo : public Jsonable { +class Client::JsonOrderInfo final : public Jsonable { public: explicit JsonOrderInfo(const td_api::orderInfo *order_info) : order_info_(order_info) { } @@ -1291,7 +1290,7 @@ class Client::JsonOrderInfo : public Jsonable { const td_api::orderInfo *order_info_; }; -class Client::JsonSuccessfulPaymentBot : public Jsonable { +class Client::JsonSuccessfulPaymentBot final : public Jsonable { public: explicit JsonSuccessfulPaymentBot(const td_api::messagePaymentSuccessfulBot *successful_payment) : successful_payment_(successful_payment) { @@ -1321,7 +1320,7 @@ class Client::JsonSuccessfulPaymentBot : public Jsonable { const td_api::messagePaymentSuccessfulBot *successful_payment_; }; -class Client::JsonEncryptedPassportElement : public Jsonable { +class Client::JsonEncryptedPassportElement final : public Jsonable { public: JsonEncryptedPassportElement(const td_api::encryptedPassportElement *element, const Client *client) : element_(element), client_(client) { @@ -1388,7 +1387,7 @@ class Client::JsonEncryptedPassportElement : public Jsonable { const Client *client_; }; -class Client::JsonEncryptedCredentials : public Jsonable { +class Client::JsonEncryptedCredentials final : public Jsonable { public: explicit JsonEncryptedCredentials(const td_api::encryptedCredentials *credentials) : credentials_(credentials) { } @@ -1403,7 +1402,7 @@ class Client::JsonEncryptedCredentials : public Jsonable { const td_api::encryptedCredentials *credentials_; }; -class Client::JsonPassportData : public Jsonable { +class Client::JsonPassportData final : public Jsonable { public: JsonPassportData(const td_api::messagePassportDataReceived *passport_data, const Client *client) : passport_data_(passport_data), client_(client) { @@ -1421,7 +1420,7 @@ class Client::JsonPassportData : public Jsonable { const Client *client_; }; -class Client::JsonProximityAlertTriggered : public Jsonable { +class Client::JsonProximityAlertTriggered final : public Jsonable { public: JsonProximityAlertTriggered(const td_api::messageProximityAlertTriggered *proximity_alert_triggered, const Client *client) @@ -1439,7 +1438,7 @@ class Client::JsonProximityAlertTriggered : public Jsonable { const Client *client_; }; -class Client::JsonVideoChatScheduled : public Jsonable { +class Client::JsonVideoChatScheduled final : public Jsonable { public: explicit JsonVideoChatScheduled(const td_api::messageVideoChatScheduled *video_chat_scheduled) : video_chat_scheduled_(video_chat_scheduled) { @@ -1453,14 +1452,14 @@ class Client::JsonVideoChatScheduled : public Jsonable { const td_api::messageVideoChatScheduled *video_chat_scheduled_; }; -class Client::JsonVideoChatStarted : public Jsonable { +class Client::JsonVideoChatStarted final : public Jsonable { public: void store(JsonValueScope *scope) const { auto object = scope->enter_object(); } }; -class Client::JsonVideoChatEnded : public Jsonable { +class Client::JsonVideoChatEnded final : public Jsonable { public: explicit JsonVideoChatEnded(const td_api::messageVideoChatEnded *video_chat_ended) : video_chat_ended_(video_chat_ended) { @@ -1474,7 +1473,7 @@ class Client::JsonVideoChatEnded : public Jsonable { const td_api::messageVideoChatEnded *video_chat_ended_; }; -class Client::JsonInviteVideoChatParticipants : public Jsonable { +class Client::JsonInviteVideoChatParticipants final : public Jsonable { public: JsonInviteVideoChatParticipants(const td_api::messageInviteVideoChatParticipants *invite_video_chat_participants, const Client *client) @@ -1490,7 +1489,7 @@ class Client::JsonInviteVideoChatParticipants : public Jsonable { const Client *client_; }; -class Client::JsonChatSetTtl : public Jsonable { +class Client::JsonChatSetTtl final : public Jsonable { public: explicit JsonChatSetTtl(const td_api::messageChatSetTtl *chat_set_ttl) : chat_set_ttl_(chat_set_ttl) { } @@ -1503,14 +1502,14 @@ class Client::JsonChatSetTtl : public Jsonable { const td_api::messageChatSetTtl *chat_set_ttl_; }; -class Client::JsonCallbackGame : public Jsonable { +class Client::JsonCallbackGame final : public Jsonable { public: void store(JsonValueScope *scope) const { auto object = scope->enter_object(); } }; -class Client::JsonInlineKeyboardButton : public Jsonable { +class Client::JsonInlineKeyboardButton final : public Jsonable { public: explicit JsonInlineKeyboardButton(const td_api::inlineKeyboardButton *button) : button_(button) { } @@ -1568,7 +1567,7 @@ class Client::JsonInlineKeyboardButton : public Jsonable { const td_api::inlineKeyboardButton *button_; }; -class Client::JsonInlineKeyboard : public Jsonable { +class Client::JsonInlineKeyboard final : public Jsonable { public: explicit JsonInlineKeyboard(const td_api::replyMarkupInlineKeyboard *inline_keyboard) : inline_keyboard_(inline_keyboard) { @@ -1584,7 +1583,7 @@ class Client::JsonInlineKeyboard : public Jsonable { const td_api::replyMarkupInlineKeyboard *inline_keyboard_; }; -class Client::JsonReplyMarkup : public Jsonable { +class Client::JsonReplyMarkup final : public Jsonable { public: explicit JsonReplyMarkup(const td_api::ReplyMarkup *reply_markup) : reply_markup_(reply_markup) { } @@ -1936,7 +1935,7 @@ void Client::JsonMessage::store(JsonValueScope *scope) const { } } -class Client::JsonDeletedMessage : public Jsonable { +class Client::JsonDeletedMessage final : public Jsonable { public: JsonDeletedMessage(int64 chat_id, int64 message_id, const Client *client) : chat_id_(chat_id), message_id_(message_id), client_(client) { @@ -1954,7 +1953,7 @@ class Client::JsonDeletedMessage : public Jsonable { const Client *client_; }; -class Client::JsonMessageId : public Jsonable { +class Client::JsonMessageId final : public Jsonable { public: explicit JsonMessageId(int64 message_id) : message_id_(message_id) { } @@ -1967,7 +1966,7 @@ class Client::JsonMessageId : public Jsonable { int64 message_id_; }; -class Client::JsonInlineQuery : public Jsonable { +class Client::JsonInlineQuery final : public Jsonable { public: JsonInlineQuery(int64 inline_query_id, int64 sender_user_id, const td_api::location *user_location, const td_api::ChatType *chat_type, const td::string &query, const td::string &offset, @@ -2033,7 +2032,7 @@ class Client::JsonInlineQuery : public Jsonable { const Client *client_; }; -class Client::JsonChosenInlineResult : public Jsonable { +class Client::JsonChosenInlineResult final : public Jsonable { public: JsonChosenInlineResult(int64 sender_user_id, const td_api::location *user_location, const td::string &query, const td::string &result_id, const td::string &inline_message_id, const Client *client) @@ -2067,7 +2066,7 @@ class Client::JsonChosenInlineResult : public Jsonable { const Client *client_; }; -class Client::JsonCallbackQuery : public Jsonable { +class Client::JsonCallbackQuery final : public Jsonable { public: JsonCallbackQuery(int64 callback_query_id, int64 sender_user_id, int64 chat_id, int64 message_id, const MessageInfo *message_info, int64 chat_instance, td_api::CallbackQueryPayload *payload, @@ -2106,7 +2105,7 @@ class Client::JsonCallbackQuery : public Jsonable { const Client *client_; }; -class Client::JsonInlineCallbackQuery : public Jsonable { +class Client::JsonInlineCallbackQuery final : public Jsonable { public: JsonInlineCallbackQuery(int64 callback_query_id, int64 sender_user_id, const td::string &inline_message_id, int64 chat_instance, td_api::CallbackQueryPayload *payload, const Client *client) @@ -2136,7 +2135,7 @@ class Client::JsonInlineCallbackQuery : public Jsonable { const Client *client_; }; -class Client::JsonShippingQuery : public Jsonable { +class Client::JsonShippingQuery final : public Jsonable { public: JsonShippingQuery(const td_api::updateNewShippingQuery *query, const Client *client) : query_(query), client_(client) { @@ -2160,7 +2159,7 @@ class Client::JsonShippingQuery : public Jsonable { const Client *client_; }; -class Client::JsonPreCheckoutQuery : public Jsonable { +class Client::JsonPreCheckoutQuery final : public Jsonable { public: JsonPreCheckoutQuery(const td_api::updateNewPreCheckoutQuery *query, const Client *client) : query_(query), client_(client) { @@ -2191,7 +2190,7 @@ class Client::JsonPreCheckoutQuery : public Jsonable { const Client *client_; }; -class Client::JsonCustomJson : public Jsonable { +class Client::JsonCustomJson final : public Jsonable { public: explicit JsonCustomJson(const td::string &json) : json_(json) { } @@ -2204,7 +2203,7 @@ class Client::JsonCustomJson : public Jsonable { const td::string &json_; }; -class Client::JsonBotCommand : public Jsonable { +class Client::JsonBotCommand final : public Jsonable { public: explicit JsonBotCommand(const td_api::botCommand *command) : command_(command) { } @@ -2218,7 +2217,7 @@ class Client::JsonBotCommand : public Jsonable { const td_api::botCommand *command_; }; -class Client::JsonChatPhotos : public Jsonable { +class Client::JsonChatPhotos final : public Jsonable { public: JsonChatPhotos(const td_api::chatPhotos *photos, const Client *client) : photos_(photos), client_(client) { } @@ -2234,7 +2233,7 @@ class Client::JsonChatPhotos : public Jsonable { const Client *client_; }; -class Client::JsonChatMember : public Jsonable { +class Client::JsonChatMember final : public Jsonable { public: JsonChatMember(const td_api::chatMember *member, Client::ChatType chat_type, const Client *client) : member_(member), chat_type_(chat_type), client_(client) { @@ -2316,7 +2315,7 @@ class Client::JsonChatMember : public Jsonable { const Client *client_; }; -class Client::JsonChatMembers : public Jsonable { +class Client::JsonChatMembers final : public Jsonable { public: JsonChatMembers(const td::vector> &members, Client::ChatType chat_type, bool administrators_only, const Client *client) @@ -2353,7 +2352,7 @@ class Client::JsonChatMembers : public Jsonable { const Client *client_; }; -class Client::JsonChatMemberUpdated : public Jsonable { +class Client::JsonChatMemberUpdated final : public Jsonable { public: JsonChatMemberUpdated(const td_api::updateChatMember *update, const Client *client) : update_(update), client_(client) { @@ -2376,7 +2375,7 @@ class Client::JsonChatMemberUpdated : public Jsonable { const Client *client_; }; -class Client::JsonChatJoinRequest : public Jsonable { +class Client::JsonChatJoinRequest final : public Jsonable { public: JsonChatJoinRequest(const td_api::updateNewChatJoinRequest *update, const Client *client) : update_(update), client_(client) { @@ -2399,7 +2398,7 @@ class Client::JsonChatJoinRequest : public Jsonable { const Client *client_; }; -class Client::JsonGameHighScore : public Jsonable { +class Client::JsonGameHighScore final : public Jsonable { public: JsonGameHighScore(const td_api::gameHighScore *score, const Client *client) : score_(score), client_(client) { } @@ -2416,7 +2415,7 @@ class Client::JsonGameHighScore : public Jsonable { const Client *client_; }; -class Client::JsonUpdateTypes : public Jsonable { +class Client::JsonUpdateTypes final : public Jsonable { public: explicit JsonUpdateTypes(td::uint32 update_types) : update_types_(update_types) { } @@ -2436,7 +2435,7 @@ class Client::JsonUpdateTypes : public Jsonable { td::uint32 update_types_; }; -class Client::JsonWebhookInfo : public Jsonable { +class Client::JsonWebhookInfo final : public Jsonable { public: explicit JsonWebhookInfo(const Client *client) : client_(client) { } @@ -2474,7 +2473,7 @@ class Client::JsonWebhookInfo : public Jsonable { const Client *client_; }; -class Client::JsonStickerSet : public Jsonable { +class Client::JsonStickerSet final : public Jsonable { public: JsonStickerSet(const td_api::stickerSet *sticker_set, const Client *client) : sticker_set_(sticker_set), client_(client) { @@ -2500,9 +2499,9 @@ class Client::JsonStickerSet : public Jsonable { const Client *client_; }; -class Client::TdOnOkCallback : public TdQueryCallback { +class Client::TdOnOkCallback final : public TdQueryCallback { public: - void on_result(object_ptr result) override { + void on_result(object_ptr result) final { if (result->get_id() == td_api::error::ID) { auto error = move_object_as(result); if (error->code_ != 401 && error->code_ != 406 && error->code_ != 500) { @@ -2512,12 +2511,12 @@ class Client::TdOnOkCallback : public TdQueryCallback { } }; -class Client::TdOnAuthorizationCallback : public TdQueryCallback { +class Client::TdOnAuthorizationCallback final : public TdQueryCallback { public: explicit TdOnAuthorizationCallback(Client *client) : client_(client) { } - void on_result(object_ptr result) override { + void on_result(object_ptr result) final { bool was_ready = client_->authorization_state_->get_id() != td_api::authorizationStateWaitPhoneNumber::ID; if (result->get_id() == td_api::error::ID) { auto error = move_object_as(result); @@ -2537,12 +2536,12 @@ class Client::TdOnAuthorizationCallback : public TdQueryCallback { Client *client_; }; -class Client::TdOnInitCallback : public TdQueryCallback { +class Client::TdOnInitCallback final : public TdQueryCallback { public: explicit TdOnInitCallback(Client *client) : client_(client) { } - void on_result(object_ptr result) override { + void on_result(object_ptr result) final { if (result->get_id() == td_api::error::ID) { LOG(WARNING) << "Failed to initialize due to " << td::oneline(to_string(result)); client_->close(); @@ -2553,13 +2552,13 @@ class Client::TdOnInitCallback : public TdQueryCallback { Client *client_; }; -class Client::TdOnGetUserProfilePhotosCallback : public TdQueryCallback { +class Client::TdOnGetUserProfilePhotosCallback final : public TdQueryCallback { public: TdOnGetUserProfilePhotosCallback(const Client *client, PromisedQueryPtr query) : client_(client), query_(std::move(query)) { } - void on_result(object_ptr result) override { + void on_result(object_ptr result) final { if (result->get_id() == td_api::error::ID) { return fail_query_with_error(std::move(query_), move_object_as(result)); } @@ -2574,12 +2573,12 @@ class Client::TdOnGetUserProfilePhotosCallback : public TdQueryCallback { PromisedQueryPtr query_; }; -class Client::TdOnSendMessageCallback : public TdQueryCallback { +class Client::TdOnSendMessageCallback final : public TdQueryCallback { public: TdOnSendMessageCallback(Client *client, PromisedQueryPtr query) : client_(client), query_(std::move(query)) { } - void on_result(object_ptr result) override { + void on_result(object_ptr result) final { if (result->get_id() == td_api::error::ID) { return fail_query_with_error(std::move(query_), move_object_as(result)); } @@ -2594,12 +2593,12 @@ class Client::TdOnSendMessageCallback : public TdQueryCallback { PromisedQueryPtr query_; }; -class Client::TdOnSendMessageAlbumCallback : public TdQueryCallback { +class Client::TdOnSendMessageAlbumCallback final : public TdQueryCallback { public: TdOnSendMessageAlbumCallback(Client *client, PromisedQueryPtr query) : client_(client), query_(std::move(query)) { } - void on_result(object_ptr result) override { + void on_result(object_ptr result) final { if (result->get_id() == td_api::error::ID) { return fail_query_with_error(std::move(query_), move_object_as(result)); } @@ -2617,7 +2616,7 @@ class Client::TdOnSendMessageAlbumCallback : public TdQueryCallback { PromisedQueryPtr query_; }; -class Client::TdOnDeleteFailedToSendMessageCallback : public TdQueryCallback { +class Client::TdOnDeleteFailedToSendMessageCallback final : public TdQueryCallback { public: TdOnDeleteFailedToSendMessageCallback(Client *client, int64 chat_id, int64 message_id) : client_(client) @@ -2626,7 +2625,7 @@ class Client::TdOnDeleteFailedToSendMessageCallback : public TdQueryCallback { , old_chat_description_(client->get_chat_description(chat_id)) { } - void on_result(object_ptr result) override { + void on_result(object_ptr result) final { if (result->get_id() == td_api::error::ID) { auto error = move_object_as(result); if (error->code_ != 401 && !client_->need_close_ && !client_->closing_ && !client_->logging_out_) { @@ -2651,12 +2650,12 @@ class Client::TdOnDeleteFailedToSendMessageCallback : public TdQueryCallback { td::string old_chat_description_; }; -class Client::TdOnEditMessageCallback : public TdQueryCallback { +class Client::TdOnEditMessageCallback final : public TdQueryCallback { public: TdOnEditMessageCallback(const Client *client, PromisedQueryPtr query) : client_(client), query_(std::move(query)) { } - void on_result(object_ptr result) override { + void on_result(object_ptr result) final { if (result->get_id() == td_api::error::ID) { return fail_query_with_error(std::move(query_), move_object_as(result)); } @@ -2679,12 +2678,12 @@ class Client::TdOnEditMessageCallback : public TdQueryCallback { PromisedQueryPtr query_; }; -class Client::TdOnEditInlineMessageCallback : public TdQueryCallback { +class Client::TdOnEditInlineMessageCallback final : public TdQueryCallback { public: explicit TdOnEditInlineMessageCallback(PromisedQueryPtr query) : query_(std::move(query)) { } - void on_result(object_ptr result) override { + void on_result(object_ptr result) final { if (result->get_id() == td_api::error::ID) { return fail_query_with_error(std::move(query_), move_object_as(result)); } @@ -2697,13 +2696,13 @@ class Client::TdOnEditInlineMessageCallback : public TdQueryCallback { PromisedQueryPtr query_; }; -class Client::TdOnStopPollCallback : public TdQueryCallback { +class Client::TdOnStopPollCallback final : public TdQueryCallback { public: TdOnStopPollCallback(const Client *client, int64 chat_id, int64 message_id, PromisedQueryPtr query) : client_(client), chat_id_(chat_id), message_id_(message_id), query_(std::move(query)) { } - void on_result(object_ptr result) override { + void on_result(object_ptr result) final { if (result->get_id() == td_api::error::ID) { return fail_query_with_error(std::move(query_), move_object_as(result)); } @@ -2728,13 +2727,13 @@ class Client::TdOnStopPollCallback : public TdQueryCallback { PromisedQueryPtr query_; }; -class Client::TdOnOkQueryCallback : public TdQueryCallback { +class Client::TdOnOkQueryCallback final : public TdQueryCallback { public: explicit TdOnOkQueryCallback(PromisedQueryPtr query) : query_(std::move(query)) { CHECK(query_ != nullptr); } - void on_result(object_ptr result) override { + void on_result(object_ptr result) final { if (result->get_id() == td_api::error::ID) { return fail_query_with_error(std::move(query_), move_object_as(result)); } @@ -2748,13 +2747,13 @@ class Client::TdOnOkQueryCallback : public TdQueryCallback { }; template -class Client::TdOnCheckUserCallback : public TdQueryCallback { +class Client::TdOnCheckUserCallback final : public TdQueryCallback { public: TdOnCheckUserCallback(const Client *client, PromisedQueryPtr query, OnSuccess on_success) : client_(client), query_(std::move(query)), on_success_(std::move(on_success)) { } - void on_result(object_ptr result) override { + void on_result(object_ptr result) final { if (result->get_id() == td_api::error::ID) { return fail_query_with_error(std::move(query_), move_object_as(result), "user not found"); } @@ -2774,13 +2773,13 @@ class Client::TdOnCheckUserCallback : public TdQueryCallback { }; template -class Client::TdOnCheckUserNoFailCallback : public TdQueryCallback { +class Client::TdOnCheckUserNoFailCallback final : public TdQueryCallback { public: TdOnCheckUserNoFailCallback(PromisedQueryPtr query, OnSuccess on_success) : query_(std::move(query)), on_success_(std::move(on_success)) { } - void on_result(object_ptr result) override { + void on_result(object_ptr result) final { on_success_(std::move(query_)); } @@ -2790,7 +2789,7 @@ class Client::TdOnCheckUserNoFailCallback : public TdQueryCallback { }; template -class Client::TdOnCheckChatCallback : public TdQueryCallback { +class Client::TdOnCheckChatCallback final : public TdQueryCallback { public: TdOnCheckChatCallback(const Client *client, bool only_supergroup, AccessRights access_rights, PromisedQueryPtr query, OnSuccess on_success) @@ -2801,7 +2800,7 @@ class Client::TdOnCheckChatCallback : public TdQueryCallback { , on_success_(std::move(on_success)) { } - void on_result(object_ptr result) override { + void on_result(object_ptr result) final { if (result->get_id() == td_api::error::ID) { return fail_query_with_error(std::move(query_), move_object_as(result), "chat not found"); } @@ -2827,13 +2826,13 @@ class Client::TdOnCheckChatCallback : public TdQueryCallback { }; template -class Client::TdOnCheckChatNoFailCallback : public TdQueryCallback { +class Client::TdOnCheckChatNoFailCallback final : public TdQueryCallback { public: TdOnCheckChatNoFailCallback(int64 chat_id, PromisedQueryPtr query, OnSuccess on_success) : chat_id_(chat_id), query_(std::move(query)), on_success_(std::move(on_success)) { } - void on_result(object_ptr result) override { + void on_result(object_ptr result) final { on_success_(chat_id_, std::move(query_)); } @@ -2844,13 +2843,13 @@ class Client::TdOnCheckChatNoFailCallback : public TdQueryCallback { }; template -class Client::TdOnSearchStickerSetCallback : public TdQueryCallback { +class Client::TdOnSearchStickerSetCallback final : public TdQueryCallback { public: TdOnSearchStickerSetCallback(PromisedQueryPtr query, OnSuccess on_success) : query_(std::move(query)), on_success_(std::move(on_success)) { } - void on_result(object_ptr result) override { + void on_result(object_ptr result) final { if (result->get_id() == td_api::error::ID) { return fail_query_with_error(std::move(query_), move_object_as(result), "sticker set not found"); } @@ -2865,13 +2864,13 @@ class Client::TdOnSearchStickerSetCallback : public TdQueryCallback { OnSuccess on_success_; }; -class Client::TdOnResolveBotUsernameCallback : public TdQueryCallback { +class Client::TdOnResolveBotUsernameCallback final : public TdQueryCallback { public: TdOnResolveBotUsernameCallback(Client *client, td::string username) : client_(client), username_(std::move(username)) { } - void on_result(object_ptr result) override { + void on_result(object_ptr result) final { if (result->get_id() == td_api::error::ID) { return client_->on_resolve_bot_username(username_, 0); } @@ -2898,7 +2897,7 @@ class Client::TdOnResolveBotUsernameCallback : public TdQueryCallback { }; template -class Client::TdOnCheckMessageCallback : public TdQueryCallback { +class Client::TdOnCheckMessageCallback final : public TdQueryCallback { public: TdOnCheckMessageCallback(Client *client, int64 chat_id, int64 message_id, bool allow_empty, Slice message_type, PromisedQueryPtr query, OnSuccess on_success) @@ -2911,7 +2910,7 @@ class Client::TdOnCheckMessageCallback : public TdQueryCallback { , on_success_(std::move(on_success)) { } - void on_result(object_ptr result) override { + void on_result(object_ptr result) final { if (result->get_id() == td_api::error::ID) { auto error = move_object_as(result); if (error->code_ == 429) { @@ -2941,13 +2940,13 @@ class Client::TdOnCheckMessageCallback : public TdQueryCallback { }; template -class Client::TdOnCheckRemoteFileIdCallback : public TdQueryCallback { +class Client::TdOnCheckRemoteFileIdCallback final : public TdQueryCallback { public: TdOnCheckRemoteFileIdCallback(PromisedQueryPtr query, OnSuccess on_success) : query_(std::move(query)), on_success_(std::move(on_success)) { } - void on_result(object_ptr result) override { + void on_result(object_ptr result) final { if (result->get_id() == td_api::error::ID) { return fail_query_with_error(std::move(query_), move_object_as(result), "invalid file_id"); } @@ -2962,13 +2961,13 @@ class Client::TdOnCheckRemoteFileIdCallback : public TdQueryCallback { }; template -class Client::TdOnGetChatMemberCallback : public TdQueryCallback { +class Client::TdOnGetChatMemberCallback final : public TdQueryCallback { public: TdOnGetChatMemberCallback(PromisedQueryPtr query, OnSuccess on_success) : query_(std::move(query)), on_success_(std::move(on_success)) { } - void on_result(object_ptr result) override { + void on_result(object_ptr result) final { if (result->get_id() == td_api::error::ID) { return fail_query_with_error(std::move(query_), move_object_as(result), "user not found"); } @@ -2982,12 +2981,12 @@ class Client::TdOnGetChatMemberCallback : public TdQueryCallback { OnSuccess on_success_; }; -class Client::TdOnDownloadFileCallback : public TdQueryCallback { +class Client::TdOnDownloadFileCallback final : public TdQueryCallback { public: TdOnDownloadFileCallback(Client *client, int32 file_id) : client_(client), file_id_(file_id) { } - void on_result(object_ptr result) override { + void on_result(object_ptr result) final { if (result->get_id() == td_api::error::ID) { auto error = move_object_as(result); return client_->on_file_download(file_id_, Status::Error(error->code_, error->message_)); @@ -3004,9 +3003,9 @@ class Client::TdOnDownloadFileCallback : public TdQueryCallback { int32 file_id_; }; -class Client::TdOnCancelDownloadFileCallback : public TdQueryCallback { +class Client::TdOnCancelDownloadFileCallback final : public TdQueryCallback { public: - void on_result(object_ptr result) override { + void on_result(object_ptr result) final { if (result->get_id() == td_api::error::ID) { LOG(ERROR) << "Failed to cancel download file"; return; @@ -3015,12 +3014,12 @@ class Client::TdOnCancelDownloadFileCallback : public TdQueryCallback { } }; -class Client::TdOnGetReplyMessageCallback : public TdQueryCallback { +class Client::TdOnGetReplyMessageCallback final : public TdQueryCallback { public: TdOnGetReplyMessageCallback(Client *client, int64 chat_id) : client_(client), chat_id_(chat_id) { } - void on_result(object_ptr result) override { + void on_result(object_ptr result) final { if (result->get_id() == td_api::error::ID) { return client_->on_get_reply_message(chat_id_, nullptr); } @@ -3034,12 +3033,12 @@ class Client::TdOnGetReplyMessageCallback : public TdQueryCallback { int64 chat_id_; }; -class Client::TdOnGetEditedMessageCallback : public TdQueryCallback { +class Client::TdOnGetEditedMessageCallback final : public TdQueryCallback { public: explicit TdOnGetEditedMessageCallback(Client *client) : client_(client) { } - void on_result(object_ptr result) override { + void on_result(object_ptr result) final { if (result->get_id() == td_api::error::ID) { auto error = move_object_as(result); if (error->code_ == 429) { @@ -3056,13 +3055,13 @@ class Client::TdOnGetEditedMessageCallback : public TdQueryCallback { Client *client_; }; -class Client::TdOnGetCallbackQueryMessageCallback : public TdQueryCallback { +class Client::TdOnGetCallbackQueryMessageCallback final : public TdQueryCallback { public: TdOnGetCallbackQueryMessageCallback(Client *client, int64 user_id, int state) : client_(client), user_id_(user_id), state_(state) { } - void on_result(object_ptr result) override { + void on_result(object_ptr result) final { if (result->get_id() == td_api::error::ID) { auto error = move_object_as(result); if (error->code_ == 429) { @@ -3081,7 +3080,7 @@ class Client::TdOnGetCallbackQueryMessageCallback : public TdQueryCallback { int state_; }; -class Client::TdOnGetStickerSetCallback : public TdQueryCallback { +class Client::TdOnGetStickerSetCallback final : public TdQueryCallback { public: TdOnGetStickerSetCallback(Client *client, int64 set_id, int64 new_callback_query_user_id, int64 new_message_chat_id) : client_(client) @@ -3090,7 +3089,7 @@ class Client::TdOnGetStickerSetCallback : public TdQueryCallback { , new_message_chat_id_(new_message_chat_id) { } - void on_result(object_ptr result) override { + void on_result(object_ptr result) final { if (result->get_id() == td_api::error::ID) { auto error = move_object_as(result); if (error->message_ != "STICKERSET_INVALID" && error->code_ != 401 && error->code_ != 500) { @@ -3113,13 +3112,13 @@ class Client::TdOnGetStickerSetCallback : public TdQueryCallback { int64 new_message_chat_id_; }; -class Client::TdOnGetChatStickerSetCallback : public TdQueryCallback { +class Client::TdOnGetChatStickerSetCallback final : public TdQueryCallback { public: TdOnGetChatStickerSetCallback(Client *client, int64 chat_id, int64 pinned_message_id, PromisedQueryPtr query) : client_(client), chat_id_(chat_id), pinned_message_id_(pinned_message_id), query_(std::move(query)) { } - void on_result(object_ptr result) override { + void on_result(object_ptr result) final { if (result->get_id() == td_api::error::ID) { auto chat_info = client_->get_chat(chat_id_); CHECK(chat_info != nullptr); @@ -3141,13 +3140,13 @@ class Client::TdOnGetChatStickerSetCallback : public TdQueryCallback { PromisedQueryPtr query_; }; -class Client::TdOnGetChatPinnedMessageCallback : public TdQueryCallback { +class Client::TdOnGetChatPinnedMessageCallback final : public TdQueryCallback { public: TdOnGetChatPinnedMessageCallback(Client *client, int64 chat_id, PromisedQueryPtr query) : client_(client), chat_id_(chat_id), query_(std::move(query)) { } - void on_result(object_ptr result) override { + void on_result(object_ptr result) final { int64 pinned_message_id = 0; if (result->get_id() == td_api::error::ID) { auto error = move_object_as(result); @@ -3187,13 +3186,13 @@ class Client::TdOnGetChatPinnedMessageCallback : public TdQueryCallback { PromisedQueryPtr query_; }; -class Client::TdOnGetChatPinnedMessageToUnpinCallback : public TdQueryCallback { +class Client::TdOnGetChatPinnedMessageToUnpinCallback final : public TdQueryCallback { public: TdOnGetChatPinnedMessageToUnpinCallback(Client *client, int64 chat_id, PromisedQueryPtr query) : client_(client), chat_id_(chat_id), query_(std::move(query)) { } - void on_result(object_ptr result) override { + void on_result(object_ptr result) final { int64 pinned_message_id = 0; if (result->get_id() == td_api::error::ID) { auto error = move_object_as(result); @@ -3220,12 +3219,12 @@ class Client::TdOnGetChatPinnedMessageToUnpinCallback : public TdQueryCallback { PromisedQueryPtr query_; }; -class Client::TdOnGetMyCommandsCallback : public TdQueryCallback { +class Client::TdOnGetMyCommandsCallback final : public TdQueryCallback { public: explicit TdOnGetMyCommandsCallback(PromisedQueryPtr query) : query_(std::move(query)) { } - void on_result(object_ptr result) override { + void on_result(object_ptr result) final { if (result->get_id() == td_api::error::ID) { return fail_query_with_error(std::move(query_), move_object_as(result)); } @@ -3240,13 +3239,13 @@ class Client::TdOnGetMyCommandsCallback : public TdQueryCallback { PromisedQueryPtr query_; }; -class Client::TdOnGetChatFullInfoCallback : public TdQueryCallback { +class Client::TdOnGetChatFullInfoCallback final : public TdQueryCallback { public: TdOnGetChatFullInfoCallback(Client *client, int64 chat_id, PromisedQueryPtr query) : client_(client), chat_id_(chat_id), query_(std::move(query)) { } - void on_result(object_ptr result) override { + void on_result(object_ptr result) final { if (result->get_id() == td_api::error::ID) { return fail_query_with_error(std::move(query_), move_object_as(result)); } @@ -3263,13 +3262,13 @@ class Client::TdOnGetChatFullInfoCallback : public TdQueryCallback { PromisedQueryPtr query_; }; -class Client::TdOnGetGroupMembersCallback : public TdQueryCallback { +class Client::TdOnGetGroupMembersCallback final : public TdQueryCallback { public: TdOnGetGroupMembersCallback(const Client *client, bool administrators_only, PromisedQueryPtr query) : client_(client), administrators_only_(administrators_only), query_(std::move(query)) { } - void on_result(object_ptr result) override { + void on_result(object_ptr result) final { if (result->get_id() == td_api::error::ID) { return fail_query_with_error(std::move(query_), move_object_as(result)); } @@ -3286,13 +3285,13 @@ class Client::TdOnGetGroupMembersCallback : public TdQueryCallback { PromisedQueryPtr query_; }; -class Client::TdOnGetSupergroupMembersCallback : public TdQueryCallback { +class Client::TdOnGetSupergroupMembersCallback final : public TdQueryCallback { public: TdOnGetSupergroupMembersCallback(const Client *client, Client::ChatType chat_type, PromisedQueryPtr query) : client_(client), chat_type_(chat_type), query_(std::move(query)) { } - void on_result(object_ptr result) override { + void on_result(object_ptr result) final { if (result->get_id() == td_api::error::ID) { return fail_query_with_error(std::move(query_), move_object_as(result)); } @@ -3308,12 +3307,12 @@ class Client::TdOnGetSupergroupMembersCallback : public TdQueryCallback { PromisedQueryPtr query_; }; -class Client::TdOnGetSupergroupMembersCountCallback : public TdQueryCallback { +class Client::TdOnGetSupergroupMembersCountCallback final : public TdQueryCallback { public: explicit TdOnGetSupergroupMembersCountCallback(PromisedQueryPtr query) : query_(std::move(query)) { } - void on_result(object_ptr result) override { + void on_result(object_ptr result) final { if (result->get_id() == td_api::error::ID) { return fail_query_with_error(std::move(query_), move_object_as(result)); } @@ -3327,12 +3326,12 @@ class Client::TdOnGetSupergroupMembersCountCallback : public TdQueryCallback { PromisedQueryPtr query_; }; -class Client::TdOnReplacePrimaryChatInviteLinkCallback : public TdQueryCallback { +class Client::TdOnReplacePrimaryChatInviteLinkCallback final : public TdQueryCallback { public: explicit TdOnReplacePrimaryChatInviteLinkCallback(PromisedQueryPtr query) : query_(std::move(query)) { } - void on_result(object_ptr result) override { + void on_result(object_ptr result) final { if (result->get_id() == td_api::error::ID) { return fail_query_with_error(std::move(query_), move_object_as(result)); } @@ -3346,13 +3345,13 @@ class Client::TdOnReplacePrimaryChatInviteLinkCallback : public TdQueryCallback PromisedQueryPtr query_; }; -class Client::TdOnGetChatInviteLinkCallback : public TdQueryCallback { +class Client::TdOnGetChatInviteLinkCallback final : public TdQueryCallback { public: TdOnGetChatInviteLinkCallback(const Client *client, PromisedQueryPtr query) : client_(client), query_(std::move(query)) { } - void on_result(object_ptr result) override { + void on_result(object_ptr result) final { if (result->get_id() == td_api::error::ID) { return fail_query_with_error(std::move(query_), move_object_as(result)); } @@ -3373,13 +3372,13 @@ class Client::TdOnGetChatInviteLinkCallback : public TdQueryCallback { PromisedQueryPtr query_; }; -class Client::TdOnGetGameHighScoresCallback : public TdQueryCallback { +class Client::TdOnGetGameHighScoresCallback final : public TdQueryCallback { public: TdOnGetGameHighScoresCallback(const Client *client, PromisedQueryPtr query) : client_(client), query_(std::move(query)) { } - void on_result(object_ptr result) override { + void on_result(object_ptr result) final { if (result->get_id() == td_api::error::ID) { return fail_query_with_error(std::move(query_), move_object_as(result)); } @@ -3396,12 +3395,12 @@ class Client::TdOnGetGameHighScoresCallback : public TdQueryCallback { PromisedQueryPtr query_; }; -class Client::TdOnReturnFileCallback : public TdQueryCallback { +class Client::TdOnReturnFileCallback final : public TdQueryCallback { public: TdOnReturnFileCallback(const Client *client, PromisedQueryPtr query) : client_(client), query_(std::move(query)) { } - void on_result(object_ptr result) override { + void on_result(object_ptr result) final { if (result->get_id() == td_api::error::ID) { return fail_query_with_error(std::move(query_), move_object_as(result)); } @@ -3416,13 +3415,13 @@ class Client::TdOnReturnFileCallback : public TdQueryCallback { PromisedQueryPtr query_; }; -class Client::TdOnReturnStickerSetCallback : public TdQueryCallback { +class Client::TdOnReturnStickerSetCallback final : public TdQueryCallback { public: TdOnReturnStickerSetCallback(Client *client, bool return_sticker_set, PromisedQueryPtr query) : client_(client), return_sticker_set_(return_sticker_set), query_(std::move(query)) { } - void on_result(object_ptr result) override { + void on_result(object_ptr result) final { if (result->get_id() == td_api::error::ID) { return fail_query_with_error(std::move(query_), move_object_as(result)); } @@ -3443,12 +3442,12 @@ class Client::TdOnReturnStickerSetCallback : public TdQueryCallback { PromisedQueryPtr query_; }; -class Client::TdOnSendCustomRequestCallback : public TdQueryCallback { +class Client::TdOnSendCustomRequestCallback final : public TdQueryCallback { public: explicit TdOnSendCustomRequestCallback(PromisedQueryPtr query) : query_(std::move(query)) { } - void on_result(object_ptr result) override { + void on_result(object_ptr result) final { if (result->get_id() == td_api::error::ID) { return fail_query_with_error(std::move(query_), move_object_as(result)); } @@ -3548,14 +3547,14 @@ void Client::start_up() { } dir_ = parameters_->working_directory_ + suff; - class TdCallback : public td::TdCallback { + class TdCallback final : public td::TdCallback { public: explicit TdCallback(td::ActorId client) : client_(std::move(client)) { } - void on_result(td::uint64 id, object_ptr result) override { + void on_result(td::uint64 id, object_ptr result) final { send_closure_later(client_, &Client::on_result, id, std::move(result)); } - void on_error(td::uint64 id, object_ptr result) override { + void on_error(td::uint64 id, object_ptr result) final { send_closure_later(client_, &Client::on_result, id, std::move(result)); } @@ -4603,7 +4602,7 @@ void Client::on_closed() { if (logging_out_) { parameters_->shared_data_->webhook_db_->erase(bot_token_with_dc_); - class RmWorker : public td::Actor { + class RmWorker final : public td::Actor { public: RmWorker(td::string dir, td::ActorId parent) : dir_(std::move(dir)), parent_(std::move(parent)) { } @@ -4612,13 +4611,13 @@ void Client::on_closed() { td::string dir_; td::ActorId parent_; - void start_up() override { + void start_up() final { CHECK(dir_.size() >= 24); CHECK(dir_.back() == TD_DIR_SLASH); td::rmrf(dir_).ignore(); stop(); } - void tear_down() override { + void tear_down() final { send_closure(parent_, &Client::finish_closing); } }; @@ -8287,7 +8286,7 @@ void Client::fail_query_conflict(Slice message, PromisedQueryPtr &&query) { } } -class Client::JsonUpdates : public Jsonable { +class Client::JsonUpdates final : public Jsonable { public: explicit JsonUpdates(td::Span updates) : updates_(updates) { } @@ -8797,11 +8796,11 @@ bool Client::update_allowed_update_types(const Query *query) { } template -class UpdateJsonable : public td::VirtuallyJsonable { +class UpdateJsonable final : public td::VirtuallyJsonable { public: explicit UpdateJsonable(const T &update) : update(update) { } - void store(JsonValueScope *scope) const override { + void store(JsonValueScope *scope) const final { *scope << update; } @@ -9760,7 +9759,7 @@ td::int64 Client::as_tdlib_message_id(int32 message_id) { } td::int32 Client::as_client_message_id(int64 message_id) { - int32 result = static_cast(message_id >> 20); + auto result = static_cast(message_id >> 20); CHECK(as_tdlib_message_id(result) == message_id); return result; } diff --git a/telegram-bot-api/Client.h b/telegram-bot-api/Client.h index fee9aad..3a9c638 100644 --- a/telegram-bot-api/Client.h +++ b/telegram-bot-api/Client.h @@ -11,6 +11,7 @@ #include "telegram-bot-api/WebhookActor.h" #include "td/telegram/ClientActor.h" +#include "td/telegram/td_api.h" #include "td/actor/actor.h" #include "td/actor/PromiseFuture.h" @@ -35,12 +36,12 @@ struct ClientParameters; namespace td_api = td::td_api; -class Client : public WebhookActor::Callback { +class Client final : public WebhookActor::Callback { public: Client(td::ActorShared<> parent, const td::string &bot_token, bool is_test_dc, td::int64 tqueue_id, std::shared_ptr parameters, td::ActorId stat_actor); - void send(PromisedQueryPtr query) override; + void send(PromisedQueryPtr query) final; void close(); @@ -519,11 +520,11 @@ class Client : public WebhookActor::Callback { Status process_get_webhook_info_query(PromisedQueryPtr &query); Status process_get_file_query(PromisedQueryPtr &query); - void webhook_verified(td::string cached_ip_address) override; - void webhook_success() override; - void webhook_error(Status status) override; - void webhook_closed(Status status) override; - void hangup_shared() override; + void webhook_verified(td::string cached_ip_address) final; + void webhook_success() final; + void webhook_error(Status status) final; + void webhook_closed(Status status) final; + void hangup_shared() final; int32 get_webhook_max_connections(const Query *query) const; static bool get_webhook_fix_ip_address(const Query *query); void do_set_webhook(PromisedQueryPtr query, bool was_deleted); @@ -562,13 +563,13 @@ class Client : public WebhookActor::Callback { void long_poll_wakeup(bool force_flag); - void start_up() override; + void start_up() final; - void raw_event(const td::Event::Raw &event) override; + void raw_event(const td::Event::Raw &event) final; - void loop() override; + void loop() final; - void timeout_expired() override; + void timeout_expired() final; struct UserInfo { enum class Type { Regular, Deleted, Bot, Unknown }; diff --git a/telegram-bot-api/ClientManager.cpp b/telegram-bot-api/ClientManager.cpp index 09a905f..f0f023d 100644 --- a/telegram-bot-api/ClientManager.cpp +++ b/telegram-bot-api/ClientManager.cpp @@ -11,6 +11,7 @@ #include "telegram-bot-api/WebhookActor.h" #include "td/telegram/ClientActor.h" +#include "td/telegram/td_api.h" #include "td/db/binlog/Binlog.h" #include "td/db/binlog/ConcurrentBinlog.h" @@ -104,7 +105,7 @@ void ClientManager::send(PromisedQueryPtr query) { flood_control.add_limit(60, 20); // 20 in a minute flood_control.add_limit(60 * 60, 600); // 600 in an hour } - td::uint32 now = static_cast(td::Time::now()); + auto now = static_cast(td::Time::now()); td::uint32 wakeup_at = flood_control.get_wakeup_at(); if (wakeup_at > now) { LOG(INFO) << "Failed to create Client from IP address " << ip_address; diff --git a/telegram-bot-api/ClientManager.h b/telegram-bot-api/ClientManager.h index e376490..5720d98 100644 --- a/telegram-bot-api/ClientManager.h +++ b/telegram-bot-api/ClientManager.h @@ -73,9 +73,9 @@ class ClientManager final : public td::Actor { static PromisedQueryPtr get_webhook_restore_query(td::Slice token, td::Slice webhook_info, std::shared_ptr shared_data); - void start_up() override; - void raw_event(const td::Event::Raw &event) override; - void hangup_shared() override; + void start_up() final; + void raw_event(const td::Event::Raw &event) final; + void hangup_shared() final; void close_db(); void finish_close(); }; diff --git a/telegram-bot-api/ClientParameters.h b/telegram-bot-api/ClientParameters.h index 79607f7..455e72f 100644 --- a/telegram-bot-api/ClientParameters.h +++ b/telegram-bot-api/ClientParameters.h @@ -6,13 +6,13 @@ // #pragma once -#include "td/actor/actor.h" - #include "td/db/KeyValueSyncInterface.h" #include "td/db/TQueue.h" #include "td/net/GetHostByNameActor.h" +#include "td/actor/actor.h" + #include "td/utils/common.h" #include "td/utils/List.h" #include "td/utils/port/IPAddress.h" diff --git a/telegram-bot-api/HttpConnection.h b/telegram-bot-api/HttpConnection.h index a4b1160..d631244 100644 --- a/telegram-bot-api/HttpConnection.h +++ b/telegram-bot-api/HttpConnection.h @@ -9,12 +9,12 @@ #include "telegram-bot-api/ClientManager.h" #include "telegram-bot-api/Query.h" -#include "td/actor/actor.h" -#include "td/actor/PromiseFuture.h" - #include "td/net/HttpInboundConnection.h" #include "td/net/HttpQuery.h" +#include "td/actor/actor.h" +#include "td/actor/PromiseFuture.h" + #include "td/utils/buffer.h" #include "td/utils/Slice.h" @@ -24,15 +24,15 @@ namespace telegram_bot_api { struct SharedData; -class HttpConnection : public td::HttpInboundConnection::Callback { +class HttpConnection final : public td::HttpInboundConnection::Callback { public: explicit HttpConnection(td::ActorId client_manager, std::shared_ptr shared_data) : client_manager_(client_manager), shared_data_(std::move(shared_data)) { } - void handle(td::unique_ptr http_query, td::ActorOwn connection) override; + void handle(td::unique_ptr http_query, td::ActorOwn connection) final; - void wakeup() override; + void wakeup() final; private: td::FutureActor> result_; @@ -40,7 +40,7 @@ class HttpConnection : public td::HttpInboundConnection::Callback { td::ActorOwn connection_; std::shared_ptr shared_data_; - void hangup() override { + void hangup() final { connection_.release(); stop(); } diff --git a/telegram-bot-api/HttpServer.h b/telegram-bot-api/HttpServer.h index b500bab..f7d0009 100644 --- a/telegram-bot-api/HttpServer.h +++ b/telegram-bot-api/HttpServer.h @@ -6,11 +6,11 @@ // #pragma once -#include "td/actor/actor.h" - #include "td/net/HttpInboundConnection.h" #include "td/net/TcpListener.h" +#include "td/actor/actor.h" + #include "td/utils/BufferedFd.h" #include "td/utils/FloodControlFast.h" #include "td/utils/format.h" @@ -23,7 +23,7 @@ namespace telegram_bot_api { -class HttpServer : public td::TcpListener::Callback { +class HttpServer final : public td::TcpListener::Callback { public: HttpServer(td::string ip_address, int port, std::function()> creator) @@ -39,7 +39,7 @@ class HttpServer : public td::TcpListener::Callback { td::ActorOwn listener_; td::FloodControlFast flood_control_; - void start_up() override { + void start_up() final { auto now = td::Time::now(); auto wakeup_at = flood_control_.get_wakeup_at(); if (wakeup_at > now) { @@ -53,13 +53,13 @@ class HttpServer : public td::TcpListener::Callback { actor_shared(this, 1), ip_address_); } - void hangup_shared() override { + void hangup_shared() final { LOG(ERROR) << "TCP listener was closed"; listener_.release(); yield(); } - void accept(td::SocketFd fd) override { + void accept(td::SocketFd fd) final { auto scheduler_count = td::Scheduler::instance()->sched_count(); auto scheduler_id = scheduler_count - 1; if (scheduler_id > 0) { @@ -70,7 +70,7 @@ class HttpServer : public td::TcpListener::Callback { .release(); } - void loop() override { + void loop() final { if (listener_.empty()) { start_up(); } diff --git a/telegram-bot-api/HttpStatConnection.h b/telegram-bot-api/HttpStatConnection.h index 5ef7db9..614f5ca 100644 --- a/telegram-bot-api/HttpStatConnection.h +++ b/telegram-bot-api/HttpStatConnection.h @@ -8,30 +8,30 @@ #include "telegram-bot-api/ClientManager.h" -#include "td/actor/actor.h" -#include "td/actor/PromiseFuture.h" - #include "td/net/HttpInboundConnection.h" #include "td/net/HttpQuery.h" +#include "td/actor/actor.h" +#include "td/actor/PromiseFuture.h" + #include "td/utils/buffer.h" namespace telegram_bot_api { -class HttpStatConnection : public td::HttpInboundConnection::Callback { +class HttpStatConnection final : public td::HttpInboundConnection::Callback { public: explicit HttpStatConnection(td::ActorId client_manager) : client_manager_(client_manager) { } - void handle(td::unique_ptr http_query, td::ActorOwn connection) override; + void handle(td::unique_ptr http_query, td::ActorOwn connection) final; - void wakeup() override; + void wakeup() final; private: td::FutureActor result_; td::ActorId client_manager_; td::ActorOwn connection_; - void hangup() override { + void hangup() final { connection_.release(); stop(); } diff --git a/telegram-bot-api/Query.h b/telegram-bot-api/Query.h index 92cb9bb..f5d15f8 100644 --- a/telegram-bot-api/Query.h +++ b/telegram-bot-api/Query.h @@ -8,11 +8,11 @@ #include "telegram-bot-api/ClientParameters.h" +#include "td/net/HttpFile.h" + #include "td/actor/actor.h" #include "td/actor/PromiseFuture.h" -#include "td/net/HttpFile.h" - #include "td/utils/buffer.h" #include "td/utils/common.h" #include "td/utils/JsonBuilder.h" @@ -30,7 +30,7 @@ namespace telegram_bot_api { class BotStatActor; -class Query : public td::ListNode { +class Query final : public td::ListNode { public: enum class State : td::int8 { Query, OK, Error }; @@ -166,7 +166,7 @@ td::StringBuilder &operator<<(td::StringBuilder &sb, const Query &query); // https://stackoverflow.com/questions/26947704/implicit-conversion-failure-from-initializer-list extern std::unordered_map> empty_parameters; -class JsonParameters : public td::Jsonable { +class JsonParameters final : public td::Jsonable { public: explicit JsonParameters(const std::unordered_map> ¶meters) : parameters_(parameters) { @@ -184,7 +184,7 @@ class JsonParameters : public td::Jsonable { }; template -class JsonQueryOk : public td::Jsonable { +class JsonQueryOk final : public td::Jsonable { public: JsonQueryOk(const T &result, td::Slice description) : result_(result), description_(description) { } @@ -202,7 +202,7 @@ class JsonQueryOk : public td::Jsonable { td::Slice description_; }; -class JsonQueryError : public td::Jsonable { +class JsonQueryError final : public td::Jsonable { public: JsonQueryError( int error_code, td::Slice description, diff --git a/telegram-bot-api/Stats.h b/telegram-bot-api/Stats.h index 06e6606..3b317fc 100644 --- a/telegram-bot-api/Stats.h +++ b/telegram-bot-api/Stats.h @@ -156,7 +156,7 @@ class BotStatActor final : public td::Actor { BotStatActor(const BotStatActor &) = delete; BotStatActor &operator=(const BotStatActor &other) = delete; BotStatActor(BotStatActor &&) = default; - BotStatActor &operator=(BotStatActor &&other) { + BotStatActor &operator=(BotStatActor &&other) noexcept { if (!empty()) { do_stop(); } @@ -165,7 +165,7 @@ class BotStatActor final : public td::Actor { parent_ = other.parent_; return *this; } - ~BotStatActor() override = default; + ~BotStatActor() final = default; template void add_event(const EventT &event, double now) { diff --git a/telegram-bot-api/WebhookActor.cpp b/telegram-bot-api/WebhookActor.cpp index ce51f88..1d7a559 100644 --- a/telegram-bot-api/WebhookActor.cpp +++ b/telegram-bot-api/WebhookActor.cpp @@ -152,11 +152,11 @@ td::Status WebhookActor::create_connection() { } VLOG(webhook) << "Create connection through proxy " << parameters_->webhook_proxy_ip_address_; - class Callback : public td::TransparentProxy::Callback { + class Callback final : public td::TransparentProxy::Callback { public: Callback(td::ActorId actor, td::int64 id) : actor_(actor), id_(id) { } - void set_result(td::Result> result) override { + void set_result(td::Result> result) final { send_closure(std::move(actor_), &WebhookActor::on_socket_ready_async, std::move(result), id_); CHECK(actor_.empty()); } @@ -169,7 +169,7 @@ td::Status WebhookActor::create_connection() { send_closure(std::move(actor_), &WebhookActor::on_socket_ready_async, td::Status::Error("Canceled"), id_); } } - void on_connected() override { + void on_connected() final { // nothing to do } diff --git a/telegram-bot-api/WebhookActor.h b/telegram-bot-api/WebhookActor.h index fa98ddb..6067d73 100644 --- a/telegram-bot-api/WebhookActor.h +++ b/telegram-bot-api/WebhookActor.h @@ -41,7 +41,7 @@ namespace telegram_bot_api { struct ClientParameters; -class WebhookActor : public td::HttpOutboundConnection::Callback { +class WebhookActor final : public td::HttpOutboundConnection::Callback { public: class Callback : public td::Actor { public: @@ -139,7 +139,7 @@ class WebhookActor : public td::HttpOutboundConnection::Callback { double next_ip_address_resolve_time_ = 0; td::FutureActor future_ip_address_; - class Connection : public td::ListNode { + class Connection final : public td::ListNode { public: Connection() = default; Connection(const Connection &) = delete; @@ -190,26 +190,26 @@ class WebhookActor : public td::HttpOutboundConnection::Callback { td::Status send_update() TD_WARN_UNUSED_RESULT; void send_updates(); - void loop() override; - void handle(td::unique_ptr response) override; + void loop() final; + void handle(td::unique_ptr response) final; - void hangup_shared() override; + void hangup_shared() final; - void hangup() override; + void hangup() final; - void tear_down() override; + void tear_down() final; - void start_up() override; + void start_up() final; bool check_ip_address(const td::IPAddress &addr) const; void on_error(td::Status status); - void on_connection_error(td::Status error) override; + void on_connection_error(td::Status error) final; void on_webhook_error(td::Slice error); void on_webhook_verified(); }; -class JsonUpdate : public td::Jsonable { +class JsonUpdate final : public td::Jsonable { public: JsonUpdate(td::int32 id, td::Slice update) : id_(id), update_(update) { } diff --git a/telegram-bot-api/telegram-bot-api.cpp b/telegram-bot-api/telegram-bot-api.cpp index cf423ee..e42390d 100644 --- a/telegram-bot-api/telegram-bot-api.cpp +++ b/telegram-bot-api/telegram-bot-api.cpp @@ -310,16 +310,16 @@ int main(int argc, char *argv[]) { options.add_checked_option('c', "max-connections", "maximum number of open file descriptors", td::OptionParser::parse_integer(max_connections)); - options.add_checked_option( - '\0', "proxy", PSLICE() << "HTTP proxy server for outgoing webhook requests in the format http://host:port", - [&](td::Slice address) { - if (td::begins_with(address, "http://")) { - address.remove_prefix(7); - } else if (td::begins_with(address, "https://")) { - address.remove_prefix(8); - } - return parameters->webhook_proxy_ip_address_.init_host_port(address.str()); - }); + options.add_checked_option('\0', "proxy", + "HTTP proxy server for outgoing webhook requests in the format http://host:port", + [&](td::Slice address) { + if (td::begins_with(address, "http://")) { + address.remove_prefix(7); + } else if (td::begins_with(address, "https://")) { + address.remove_prefix(8); + } + return parameters->webhook_proxy_ip_address_.init_host_port(address.str()); + }); options.add_check([&] { if (parameters->api_id_ <= 0 || parameters->api_hash_.empty()) { return td::Status::Error("You must provide valid api-id and api-hash obtained at https://my.telegram.org"); From 1851ba7eb5169ff3d35eead6047c35c8d1117231 Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 31 Jan 2022 22:32:10 +0300 Subject: [PATCH 18/19] Update TDLib to 1.8.1. --- td | 2 +- telegram-bot-api/Client.cpp | 66 ++++++++++++++++++++----------- telegram-bot-api/Client.h | 2 +- telegram-bot-api/WebhookActor.cpp | 2 +- 4 files changed, 47 insertions(+), 25 deletions(-) diff --git a/td b/td index 14637ca..92c2a9c 160000 --- a/td +++ b/td @@ -1 +1 @@ -Subproject commit 14637caa64c2c992c1cde7c92cadb43a83d4435e +Subproject commit 92c2a9c4e521df720abeaa9872e1c2b797d5c93f diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp index aec0787..87d11e6 100644 --- a/telegram-bot-api/Client.cpp +++ b/telegram-bot-api/Client.cpp @@ -964,9 +964,14 @@ class Client::JsonSticker final : public Jsonable { if (!set_name.empty()) { object("set_name", set_name); } - object("is_animated", td::JsonBool(sticker_->is_animated_)); - if (sticker_->mask_position_ != nullptr) { - object("mask_position", JsonMaskPosition(sticker_->mask_position_.get())); + auto type = sticker_->type_->get_id(); + object("is_animated", td::JsonBool(type == td_api::stickerTypeAnimated::ID)); + object("is_video", td::JsonBool(type == td_api::stickerTypeVideo::ID)); + if (type == td_api::stickerTypeMask::ID) { + const auto &mask_position = static_cast(sticker_->type_.get())->mask_position_; + if (mask_position != nullptr) { + object("mask_position", JsonMaskPosition(mask_position.get())); + } } client_->json_store_thumbnail(object, sticker_->thumbnail_.get()); client_->json_store_file(object, sticker_->sticker_.get()); @@ -2489,8 +2494,10 @@ class Client::JsonStickerSet final : public Jsonable { if (sticker_set_->thumbnail_ != nullptr) { client_->json_store_thumbnail(object, sticker_set_->thumbnail_.get()); } - object("is_animated", td::JsonBool(sticker_set_->is_animated_)); - object("contains_masks", td::JsonBool(sticker_set_->is_masks_)); + auto type = sticker_set_->sticker_type_->get_id(); + object("is_animated", td::JsonBool(type == td_api::stickerTypeAnimated::ID)); + object("is_video", td::JsonBool(type == td_api::stickerTypeVideo::ID)); + object("contains_masks", td::JsonBool(type == td_api::stickerTypeMask::ID)); object("stickers", JsonStickers(sticker_set_->stickers_, client_)); } @@ -5767,28 +5774,41 @@ td::Result> Client::get_mask_position(c return r_mask_position.move_as_ok(); } -td::Result>> Client::get_input_stickers(const Query *query) const { +td::Result>> Client::get_input_stickers(const Query *query, + bool is_masks) const { auto emojis = query->arg("emojis"); - td::vector> stickers; auto sticker = get_input_file(query, "png_sticker"); + object_ptr sticker_type; if (sticker != nullptr) { - TRY_RESULT(mask_position, get_mask_position(query, "mask_position")); - stickers.push_back( - make_object(std::move(sticker), emojis.str(), std::move(mask_position))); + if (is_masks) { + TRY_RESULT(mask_position, get_mask_position(query, "mask_position")); + sticker_type = make_object(std::move(mask_position)); + } else { + sticker_type = make_object(); + } } else { sticker = get_input_file(query, "tgs_sticker", true); - if (sticker == nullptr) { - if (query->arg("tgs_sticker").empty()) { + if (sticker != nullptr) { + sticker_type = make_object(); + } else { + sticker = get_input_file(query, "webm_sticker", true); + if (sticker != nullptr) { + sticker_type = make_object(); + } else { + if (!query->arg("tgs_sticker").empty()) { + return Status::Error(400, "Bad Request: animated sticker must be uploaded as an InputFile"); + } + if (!query->arg("webm_sticker").empty()) { + return Status::Error(400, "Bad Request: video sticker must be uploaded as an InputFile"); + } return Status::Error(400, "Bad Request: there is no sticker file in the request"); } - return Status::Error(400, "Bad Request: TGS sticker must be uploaded as an InputFile"); } - - stickers.push_back(make_object(std::move(sticker), emojis.str())); } - CHECK(stickers.size() == 1); + td::vector> stickers; + stickers.push_back(make_object(std::move(sticker), emojis.str(), std::move(sticker_type))); return std::move(stickers); } @@ -7783,7 +7803,8 @@ td::Status Client::process_upload_sticker_file_query(PromisedQueryPtr &query) { check_user(user_id, std::move(query), [this, user_id, png_sticker = std::move(png_sticker)](PromisedQueryPtr query) mutable { send_request(make_object( - user_id, make_object(std::move(png_sticker), "", nullptr)), + user_id, make_object(std::move(png_sticker), "", + make_object())), std::make_unique(this, std::move(query))); }); return Status::OK(); @@ -7794,11 +7815,11 @@ td::Status Client::process_create_new_sticker_set_query(PromisedQueryPtr &query) auto name = query->arg("name"); auto title = query->arg("title"); auto is_masks = to_bool(query->arg("contains_masks")); - TRY_RESULT(stickers, get_input_stickers(query.get())); + TRY_RESULT(stickers, get_input_stickers(query.get(), is_masks)); check_user(user_id, std::move(query), - [this, user_id, title, name, is_masks, stickers = std::move(stickers)](PromisedQueryPtr query) mutable { - send_request(make_object(user_id, title.str(), name.str(), is_masks, + [this, user_id, title, name, stickers = std::move(stickers)](PromisedQueryPtr query) mutable { + send_request(make_object(user_id, title.str(), name.str(), std::move(stickers), PSTRING() << "bot" << my_id_), std::make_unique(this, false, std::move(query))); }); @@ -7808,7 +7829,7 @@ td::Status Client::process_create_new_sticker_set_query(PromisedQueryPtr &query) td::Status Client::process_add_sticker_to_set_query(PromisedQueryPtr &query) { TRY_RESULT(user_id, get_user_id(query.get())); auto name = query->arg("name"); - TRY_RESULT(stickers, get_input_stickers(query.get())); + TRY_RESULT(stickers, get_input_stickers(query.get(), true)); CHECK(!stickers.empty()); check_user(user_id, std::move(query), @@ -8324,7 +8345,8 @@ void Client::do_get_updates(int32 offset, int32 limit, int32 timeout, PromisedQu } } - auto updates = mutable_span(parameters_->shared_data_->event_buffer_, SharedData::TQUEUE_EVENT_BUFFER_SIZE); + td::MutableSpan updates(parameters_->shared_data_->event_buffer_, + SharedData::TQUEUE_EVENT_BUFFER_SIZE); updates.truncate(limit); td::TQueue::EventId from; size_t total_size = 0; diff --git a/telegram-bot-api/Client.h b/telegram-bot-api/Client.h index 3a9c638..caefd33 100644 --- a/telegram-bot-api/Client.h +++ b/telegram-bot-api/Client.h @@ -367,7 +367,7 @@ class Client final : public WebhookActor::Callback { static object_ptr mask_index_to_point(int32 index); - td::Result>> get_input_stickers(const Query *query) const; + td::Result>> get_input_stickers(const Query *query, bool is_masks) const; static td::Result get_passport_element_hash(Slice encoded_hash); diff --git a/telegram-bot-api/WebhookActor.cpp b/telegram-bot-api/WebhookActor.cpp index 1d7a559..bfab715 100644 --- a/telegram-bot-api/WebhookActor.cpp +++ b/telegram-bot-api/WebhookActor.cpp @@ -356,7 +356,7 @@ void WebhookActor::load_updates() { auto offset = tqueue_offset_; auto limit = td::min(SharedData::TQUEUE_EVENT_BUFFER_SIZE, max_loaded_updates_ - queue_updates_.size()); - auto updates = mutable_span(parameters_->shared_data_->event_buffer_, limit); + td::MutableSpan updates(parameters_->shared_data_->event_buffer_, limit); auto now = td::Time::now(); auto unix_time_now = parameters_->shared_data_->get_unix_time(now); From c57b04c4c8c4e8d8bb6fdd0bd3bfb5b93b9d8f05 Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 31 Jan 2022 22:49:25 +0300 Subject: [PATCH 19/19] Update version to 5.7. --- CMakeLists.txt | 2 +- telegram-bot-api/telegram-bot-api.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 694a31e..be48be4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,7 @@ if (POLICY CMP0065) cmake_policy(SET CMP0065 NEW) endif() -project(TelegramBotApi VERSION 5.6.1 LANGUAGES CXX) +project(TelegramBotApi VERSION 5.7 LANGUAGES CXX) if (POLICY CMP0069) option(TELEGRAM_BOT_API_ENABLE_LTO "Use \"ON\" to enable Link Time Optimization.") diff --git a/telegram-bot-api/telegram-bot-api.cpp b/telegram-bot-api/telegram-bot-api.cpp index e42390d..5a82db5 100644 --- a/telegram-bot-api/telegram-bot-api.cpp +++ b/telegram-bot-api/telegram-bot-api.cpp @@ -200,7 +200,7 @@ int main(int argc, char *argv[]) { auto start_time = td::Time::now(); auto shared_data = std::make_shared(); auto parameters = std::make_unique(); - parameters->version_ = "5.6.1"; + parameters->version_ = "5.7"; parameters->shared_data_ = shared_data; parameters->start_time_ = start_time; auto net_query_stats = td::create_net_query_stats();