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/CMakeLists.txt b/CMakeLists.txt index 8c5a221..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.5.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/README.md b/README.md index b8db9a4..3f5c7ba 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ The maximum number of messages to be deleted in a single batch is determined by ###### Returns `true` ##### Command `ping` -Send an MTProto ping message to the telegram servers. +Send an MTProto ping message to the telegram servers. Useful to detect the delay of the bot api server. ###### Parameters @@ -149,7 +149,7 @@ The bot will now receive Updates for all received media, even if a destruction t ### User Mode -You can allow user accounts to access the bot api with the command-line option `--allow-users` or set the env variable +You can allow user accounts to access the bot api with the command-line option `--allow-users` or set the env variable `TELEGRAM_ALLOW_USERS` to `1` when using docker. User Mode is disabled by default, so only bots can access the api. You can now log into the bot api with user accounts to create userbots running on your account. @@ -161,37 +161,37 @@ Note: Never send your 2fa password over a plain http connection. Make sure https Parameters: - `phone_number`: `string`. The phone number of your Telegram Account. - + Returns your `user_token` as `string`. You can use this just like a normal bot token on the `/user` endpoint - + 2. Send the received code to `{api_url}/user{user_token}/authcode` Parameters: - `code`: `int`. The code send to you by Telegram In-App or by SMS - - Will send `{"ok": true, "result": true}` on success. - + + Will send `{"ok": true, "result": true}` on success. + 3. Optional: Send your 2fa password to `{api_url}/user{user_token}/2fapassword` - + Parameters: - `password`: `string`. Password for 2fa authentication - - Will send `{"ok": true, "result": true}` on success. - -4. Optional: Register the user by calling `{api_url}/user{user_token}/registerUser`. - + + Will send `{"ok": true, "result": true}` on success. + +4. Optional: Register the user by calling `{api_url}/user{user_token}/registerUser`. + User registration is disabled by default. You can enable it with the `--allow-users-registration` command line option or the env variable `TELEGRAM_ALLOW_USERS_REGISTRATION` set to `1` when using docker. - + Parameters: - `first_name`: `string`. First name for the new account. - `last_name`: `string`, optional. Last name for the new account. - - Will send `{"ok": true, "result": true}` on success. - -You are now logged in and can use all methods like in the bot api, just replace the -`/bot{bot_token}/` in your urls with `/user{token}/`. - + + Will send `{"ok": true, "result": true}` on success. + +You are now logged in and can use all methods like in the bot api, just replace the +`/bot{bot_token}/` in your urls with `/user{token}/`. + You only need to authenticate once, the account will stay logged in. You can use the `logOut` method to log out or simply close the session in your account settings. @@ -226,7 +226,7 @@ It is possible to have multiple user-tokens to multiple client instances on the The simplest way to use it is with this docker command: ```bash -docker run -p 8081:8081 --env TELEGRAM_API_ID=API_ID --env TELEGRAM_API_HASH=API_HASH tdlight/tdlightbotapi +docker run -p 8081:8081 --env TELEGRAM_API_ID=API_ID --env TELEGRAM_API_HASH=API_HASH tdlight/tdlightbotapi ``` The simplest way to build `Telegram Bot API server` is to use our [Telegram Bot API server build instructions generator](https://tdlight-team.github.io/tdlight-telegram-bot-api/build.html). diff --git a/build.html b/build.html index ad2503b..d24505d 100644 --- a/build.html +++ b/build.html @@ -3,17 +3,184 @@ Telegram Bot API server build instructions - +
-
+

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

@@ -45,7 +212,7 @@ select.large { font-size: large; }

-
+
@@ -77,6 +244,13 @@ select.large { font-size: large; }

+
+ Choose host architecture:
+ + +

+
+
Choose for which bitness you want to build the Telegram Bot API server:
@@ -91,13 +265,16 @@ select.large { font-size: large; }

-
+

Hidden text

-
+

Hidden text

Empty commands +
@@ -193,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; @@ -205,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; @@ -312,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) { @@ -435,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) { @@ -485,6 +676,26 @@ function onOptionsChanged() { } commands.push((use_powershell ? 'dir ' : 'ls -l ') + install_dir + '/bin/tdlight-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); + }) } diff --git a/td b/td index 5a76413..1e1ab5d 160000 --- a/td +++ b/td @@ -1 +1 @@ -Subproject commit 5a76413990ff96653bfda32d37f38ee825be65d8 +Subproject commit 1e1ab5d1b0e4811e6d9e1584a82da08448d0cada diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp index 17edc7c..c504510 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" @@ -204,9 +203,6 @@ Client::Client(td::ActorShared<> parent, const td::string &bot_token, bool is_us , 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); } @@ -333,7 +329,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) { } @@ -347,7 +343,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) { } @@ -362,7 +358,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) { @@ -379,7 +375,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) { @@ -425,7 +421,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) { } @@ -441,7 +437,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) { } @@ -486,6 +482,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; @@ -520,7 +519,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) { @@ -541,7 +540,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) @@ -577,7 +576,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) { } @@ -590,7 +589,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) { } @@ -606,7 +605,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) { } @@ -620,7 +619,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) { @@ -632,8 +631,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_); @@ -651,7 +650,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) { @@ -676,7 +675,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, int32 distance = -1) : chat_id_(chat_id) @@ -844,7 +843,7 @@ class Client::JsonChat : public Jsonable { int32 distance_; }; -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) { @@ -872,7 +871,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) { } @@ -887,7 +886,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) { @@ -915,7 +914,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) { } @@ -943,7 +942,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) { } @@ -964,7 +963,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) { } @@ -980,7 +979,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) { } @@ -996,7 +995,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) { } @@ -1014,7 +1013,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) { } @@ -1032,7 +1031,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) { } @@ -1048,7 +1047,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) { } @@ -1063,9 +1062,14 @@ class Client::JsonSticker : 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()); @@ -1076,7 +1080,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) { @@ -1093,7 +1097,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) { } @@ -1117,7 +1121,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) { } @@ -1134,7 +1138,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) { } @@ -1152,7 +1156,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) { } @@ -1183,7 +1187,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) { } @@ -1206,7 +1210,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) { } @@ -1221,7 +1225,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) { } @@ -1247,7 +1251,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) { } @@ -1268,7 +1272,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) { } @@ -1283,7 +1287,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) { } @@ -1330,7 +1334,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) { @@ -1347,7 +1351,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) { } @@ -1365,7 +1369,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) { } @@ -1389,7 +1393,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) { @@ -1419,7 +1423,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) { @@ -1486,7 +1490,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) { } @@ -1501,7 +1505,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) { @@ -1519,7 +1523,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) @@ -1537,7 +1541,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) { @@ -1551,14 +1555,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) { @@ -1572,7 +1576,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) @@ -1588,7 +1592,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) { } @@ -1601,14 +1605,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) { } @@ -1666,7 +1670,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) { @@ -1682,7 +1686,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) { } @@ -2053,7 +2057,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) { @@ -2071,7 +2075,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) { } @@ -2084,7 +2088,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, @@ -2150,7 +2154,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) @@ -2184,7 +2188,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, @@ -2223,7 +2227,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) @@ -2253,7 +2257,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) { @@ -2277,7 +2281,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) { @@ -2308,7 +2312,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) { } @@ -2321,7 +2325,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) { } @@ -2335,7 +2339,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) { } @@ -2351,7 +2355,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) { @@ -2445,7 +2449,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) @@ -2491,7 +2495,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) { @@ -2514,7 +2518,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) { @@ -2537,7 +2541,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) { } @@ -2554,7 +2558,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) { } @@ -2574,7 +2578,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) { } @@ -2612,7 +2616,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) { @@ -2628,8 +2632,10 @@ class Client::JsonStickerSet : 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_)); } @@ -2824,9 +2830,9 @@ class Client::JsonProxiesArray : public Jsonable { //end custom Json objects impl -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) { @@ -2836,12 +2842,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); @@ -2908,12 +2914,12 @@ class Client::TdOnAuthorizationQueryCallback : public TdQueryCallback { bool send_token_; }; -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(); @@ -2924,13 +2930,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)); } @@ -2945,12 +2951,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)); } @@ -2965,12 +2971,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)); } @@ -2988,7 +2994,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) @@ -2997,10 +3003,10 @@ 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) { + 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_; @@ -3022,12 +3028,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)); } @@ -3050,12 +3056,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)); } @@ -3068,13 +3074,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)); } @@ -3099,13 +3105,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)); } @@ -3119,13 +3125,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"); } @@ -3145,13 +3151,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_)); } @@ -3161,7 +3167,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) @@ -3172,7 +3178,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"); } @@ -3232,13 +3238,13 @@ class Client::TdOnOptimizeMemoryCallback : 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_)); } @@ -3249,13 +3255,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"); } @@ -3270,13 +3276,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); } @@ -3303,23 +3309,24 @@ class Client::TdOnResolveBotUsernameCallback : public TdQueryCallback { }; template -class Client::TdOnCheckMessageCallback : public TdQueryCallback { +class Client::TdOnCheckMessageCallback final : 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)) , 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) { - 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_)); @@ -3330,12 +3337,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_; @@ -3343,13 +3352,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"); } @@ -3364,13 +3373,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"); } @@ -3384,12 +3393,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_)); @@ -3406,9 +3415,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; @@ -3417,12 +3426,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); } @@ -3436,12 +3445,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) { @@ -3458,13 +3467,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) { @@ -3483,7 +3492,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) @@ -3492,7 +3501,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) { @@ -3515,13 +3524,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); @@ -3543,13 +3552,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); @@ -3589,13 +3598,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); @@ -3622,12 +3631,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)); } @@ -3642,13 +3651,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)); } @@ -3665,13 +3674,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)); } @@ -3688,13 +3697,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)); } @@ -3710,12 +3719,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)); } @@ -3729,12 +3738,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)); } @@ -3748,13 +3757,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)); } @@ -3775,13 +3784,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)); } @@ -3798,12 +3807,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)); } @@ -3818,13 +3827,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)); } @@ -3845,12 +3854,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)); } @@ -4121,7 +4130,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_; @@ -4163,14 +4171,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)); } @@ -4545,9 +4553,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))); }); } @@ -4835,6 +4844,7 @@ void Client::on_update_authorization_state() { waiting_for_auth_input_ = false; 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)); } @@ -4890,7 +4900,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; } @@ -5009,7 +5019,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; } @@ -5034,11 +5044,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: { @@ -5262,7 +5272,7 @@ void Client::on_closed() { parameters_->shared_data_->webhook_db_->erase(bot_token_with_dc_); parameters_->shared_data_->user_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)) { } @@ -5271,13 +5281,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); } }; @@ -5916,8 +5926,10 @@ td::Result> Client::get_input_me return nullptr; } -td_api::object_ptr Client::get_message_send_options(bool disable_notification, td_api::object_ptr &&scheduling_state) { - return make_object(disable_notification, false, std::move(scheduling_state)); +td_api::object_ptr Client::get_message_send_options(bool disable_notification, + bool protect_content, + td_api::object_ptr &&scheduling_state) { + return make_object(disable_notification, false, protect_content, std::move(scheduling_state)); } td::Result>> Client::get_inline_query_results( @@ -6426,28 +6438,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); } @@ -6600,6 +6625,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(); } @@ -7656,6 +7684,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")); @@ -7664,19 +7693,22 @@ 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), - send_at = std::move(send_at)](object_ptr reply_markup, PromisedQueryPtr query) mutable { - auto on_success = [this, disable_notification, input_message_contents = std::move(input_message_contents), - reply_markup = std::move(reply_markup), send_at = std::move(send_at)]( - int64 chat_id, int64 reply_to_message_id, PromisedQueryPtr query) mutable { + protect_content, input_message_contents = std::move(input_message_contents), send_at = std::move(send_at)]( + 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), send_at = std::move(send_at)](int64 chat_id, int64 reply_to_message_id, + PromisedQueryPtr query) mutable { auto it = yet_unsent_message_count_.find(chat_id); if (it != yet_unsent_message_count_.end() && it->second > MAX_CONCURRENTLY_SENT_CHAT_MESSAGES) { 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(send_at)), - 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(send_at)), + 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)); @@ -8621,7 +8653,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(); @@ -8633,11 +8666,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))); }); @@ -8648,7 +8681,7 @@ td::Status Client::process_add_sticker_to_set_query(PromisedQueryPtr &query) { CHECK_IS_BOT(); 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), @@ -9519,6 +9552,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()); @@ -9537,17 +9571,18 @@ 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), - send_at = std::move(send_at)](object_ptr reply_markup, PromisedQueryPtr query) mutable { - auto on_success = [this, disable_notification, input_message_content = std::move(input_message_content), - reply_markup = std::move(reply_markup), send_at = std::move(send_at)]( - int64 chat_id, int64 reply_to_message_id, PromisedQueryPtr query) mutable { + protect_content, input_message_content = std::move(input_message_content), send_at = std::move(send_at)]( + 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), send_at = std::move(send_at)](int64 chat_id, int64 reply_to_message_id, + PromisedQueryPtr query) mutable { auto it = yet_unsent_message_count_.find(chat_id); if (it != yet_unsent_message_count_.end() && it->second > MAX_CONCURRENTLY_SENT_CHAT_MESSAGES) { 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(send_at)), + get_message_send_options(disable_notification, protect_content, std::move(send_at)), std::move(reply_markup), std::move(input_message_content)), std::make_unique(this, std::move(query))); }; @@ -9613,7 +9648,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) { } @@ -9651,7 +9686,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; @@ -10133,11 +10169,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; } @@ -10812,58 +10848,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); @@ -10880,8 +10870,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_; @@ -11034,9 +11022,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) { @@ -11047,9 +11033,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) { @@ -11164,7 +11148,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) >> 2 == message_id >> 2); return result; } diff --git a/telegram-bot-api/Client.h b/telegram-bot-api/Client.h index 5fb1745..6d4e7f2 100644 --- a/telegram-bot-api/Client.h +++ b/telegram-bot-api/Client.h @@ -11,11 +11,11 @@ #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" #include "td/actor/SignalSlot.h" -#include "td/actor/Timeout.h" #include "td/utils/common.h" #include "td/utils/Container.h" @@ -36,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_user, 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(); @@ -65,8 +65,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; @@ -413,7 +411,7 @@ class Client : 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); @@ -459,7 +457,9 @@ 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, object_ptr &&scheduling_state); + static object_ptr get_message_send_options(bool disable_notification, + bool protect_content, + object_ptr &&scheduling_state); static td::Result> get_poll_options(const Query *query); @@ -622,11 +622,11 @@ class Client : public WebhookActor::Callback { void process_register_user_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); @@ -665,13 +665,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 }; @@ -768,10 +768,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; @@ -842,9 +838,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); @@ -995,7 +988,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 @@ -1007,8 +999,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_; diff --git a/telegram-bot-api/ClientManager.cpp b/telegram-bot-api/ClientManager.cpp index c117046..34f21a9 100644 --- a/telegram-bot-api/ClientManager.cpp +++ b/telegram-bot-api/ClientManager.cpp @@ -12,6 +12,7 @@ #include "telegram-bot-api/StatsJson.h" #include "td/telegram/ClientActor.h" +#include "td/telegram/td_api.h" #include "td/db/binlog/Binlog.h" #include "td/db/binlog/ConcurrentBinlog.h" diff --git a/telegram-bot-api/ClientManager.h b/telegram-bot-api/ClientManager.h index 35b6757..93e58f3 100644 --- a/telegram-bot-api/ClientManager.h +++ b/telegram-bot-api/ClientManager.h @@ -76,9 +76,9 @@ class ClientManager final : public td::Actor { static PromisedQueryPtr get_webhook_restore_query(td::Slice token, bool is_user, 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 5718fad..97650c8 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" @@ -23,7 +23,7 @@ namespace td { class NetQueryStats; -} +} // namespace td namespace telegram_bot_api { 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 ea4f499..f5cb5c1 100644 --- a/telegram-bot-api/HttpStatConnection.h +++ b/telegram-bot-api/HttpStatConnection.h @@ -8,23 +8,23 @@ #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: bool as_json_; @@ -32,7 +32,7 @@ class HttpStatConnection : public td::HttpInboundConnection::Callback { 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 d51c45d..3461c09 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 }; @@ -170,7 +170,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) { @@ -188,7 +188,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) { } @@ -206,7 +206,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 2ff2482..a9cc232 100644 --- a/telegram-bot-api/Stats.h +++ b/telegram-bot-api/Stats.h @@ -157,7 +157,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(); } @@ -166,7 +166,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 1f991b6..72c7a96 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 } @@ -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); 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 4570046..dc127d9 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.7"; parameters->shared_data_ = shared_data; parameters->start_time_ = start_time; auto net_query_stats = td::create_net_query_stats(); @@ -320,22 +320,23 @@ 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', "max-batch-operations", PSLICE() << "maximum number of batch operations (default: " << parameters->max_batch_operations << ")", - td::OptionParser::parse_integer(parameters->max_batch_operations)); + td::OptionParser::parse_integer(parameters->max_batch_operations)); options.add_checked_option('\0', "file-expiration-time", PSLICE() << "downloaded files expire after this amount of seconds of not being used (defaults to " << parameters->file_expiration_timeout_seconds_ << ")", td::OptionParser::parse_integer(parameters->file_expiration_timeout_seconds_)); - - 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");