From 4f35dbd41889a6f67606ec6fef849d1618e70fc9 Mon Sep 17 00:00:00 2001 From: levlam Date: Sat, 1 Jun 2024 23:32:25 +0300 Subject: [PATCH] Make functions static in InlineMessageManager.cpp. --- td/telegram/InlineMessageManager.cpp | 77 ++++++++++++++-------------- td/telegram/InlineMessageManager.h | 7 --- 2 files changed, 39 insertions(+), 45 deletions(-) diff --git a/td/telegram/InlineMessageManager.cpp b/td/telegram/InlineMessageManager.cpp index a0b32de8c..a16022c08 100644 --- a/td/telegram/InlineMessageManager.cpp +++ b/td/telegram/InlineMessageManager.cpp @@ -21,6 +21,7 @@ #include "td/telegram/OptionManager.h" #include "td/telegram/ReplyMarkup.h" #include "td/telegram/Td.h" +#include "td/telegram/telegram_api.h" #include "td/telegram/UserManager.h" #include "td/utils/base64.h" @@ -31,6 +32,41 @@ namespace td { +static int32 get_inline_message_dc_id( + const telegram_api::object_ptr &inline_message_id) { + CHECK(inline_message_id != nullptr); + switch (inline_message_id->get_id()) { + case telegram_api::inputBotInlineMessageID::ID: + return static_cast(inline_message_id.get())->dc_id_; + case telegram_api::inputBotInlineMessageID64::ID: + return static_cast(inline_message_id.get())->dc_id_; + default: + UNREACHABLE(); + return 0; + } +} + +static telegram_api::object_ptr get_input_bot_inline_message_id( + const string &inline_message_id) { + auto r_binary = base64url_decode(inline_message_id); + if (r_binary.is_error()) { + return nullptr; + } + BufferSlice buffer_slice(r_binary.ok()); + TlBufferParser parser(&buffer_slice); + auto result = buffer_slice.size() == 20 ? telegram_api::inputBotInlineMessageID::fetch(parser) + : telegram_api::inputBotInlineMessageID64::fetch(parser); + parser.fetch_end(); + if (parser.get_error()) { + return nullptr; + } + if (!DcId::is_valid(get_inline_message_dc_id(result))) { + return nullptr; + } + LOG(INFO) << "Have inline message identifier: " << to_string(result); + return result; +} + class EditInlineMessageQuery final : public Td::ResultHandler { Promise promise_; @@ -69,7 +105,7 @@ class EditInlineMessageQuery final : public Td::ResultHandler { flags |= telegram_api::messages_editInlineBotMessage::INVERT_MEDIA_MASK; } - auto dc_id = DcId::internal(InlineMessageManager::get_inline_message_dc_id(input_bot_inline_message_id)); + auto dc_id = DcId::internal(get_inline_message_dc_id(input_bot_inline_message_id)); send_query(G()->net_query_creator().create( telegram_api::messages_editInlineBotMessage( flags, false /*ignored*/, false /*ignored*/, std::move(input_bot_inline_message_id), text, @@ -114,7 +150,7 @@ class SetInlineGameScoreQuery final : public Td::ResultHandler { flags |= telegram_api::messages_setInlineGameScore::FORCE_MASK; } - auto dc_id = DcId::internal(InlineMessageManager::get_inline_message_dc_id(input_bot_inline_message_id)); + auto dc_id = DcId::internal(get_inline_message_dc_id(input_bot_inline_message_id)); send_query(G()->net_query_creator().create( telegram_api::messages_setInlineGameScore(flags, false /*ignored*/, false /*ignored*/, std::move(input_bot_inline_message_id), std::move(input_user), score), @@ -151,7 +187,7 @@ class GetInlineGameHighScoresQuery final : public Td::ResultHandler { CHECK(input_bot_inline_message_id != nullptr); CHECK(input_user != nullptr); - auto dc_id = DcId::internal(InlineMessageManager::get_inline_message_dc_id(input_bot_inline_message_id)); + auto dc_id = DcId::internal(get_inline_message_dc_id(input_bot_inline_message_id)); send_query(G()->net_query_creator().create( telegram_api::messages_getInlineGameHighScores(std::move(input_bot_inline_message_id), std::move(input_user)), {}, dc_id)); @@ -366,39 +402,4 @@ void InlineMessageManager::get_inline_game_high_scores(const string &inline_mess ->send(std::move(input_bot_inline_message_id), std::move(input_user)); } -int32 InlineMessageManager::get_inline_message_dc_id( - const telegram_api::object_ptr &inline_message_id) { - CHECK(inline_message_id != nullptr); - switch (inline_message_id->get_id()) { - case telegram_api::inputBotInlineMessageID::ID: - return static_cast(inline_message_id.get())->dc_id_; - case telegram_api::inputBotInlineMessageID64::ID: - return static_cast(inline_message_id.get())->dc_id_; - default: - UNREACHABLE(); - return 0; - } -} - -telegram_api::object_ptr InlineMessageManager::get_input_bot_inline_message_id( - const string &inline_message_id) { - auto r_binary = base64url_decode(inline_message_id); - if (r_binary.is_error()) { - return nullptr; - } - BufferSlice buffer_slice(r_binary.ok()); - TlBufferParser parser(&buffer_slice); - auto result = buffer_slice.size() == 20 ? telegram_api::inputBotInlineMessageID::fetch(parser) - : telegram_api::inputBotInlineMessageID64::fetch(parser); - parser.fetch_end(); - if (parser.get_error()) { - return nullptr; - } - if (!DcId::is_valid(get_inline_message_dc_id(result))) { - return nullptr; - } - LOG(INFO) << "Have inline message identifier: " << to_string(result); - return result; -} - } // namespace td diff --git a/td/telegram/InlineMessageManager.h b/td/telegram/InlineMessageManager.h index 85f2b5c06..7a6b7e3e5 100644 --- a/td/telegram/InlineMessageManager.h +++ b/td/telegram/InlineMessageManager.h @@ -7,7 +7,6 @@ #pragma once #include "td/telegram/td_api.h" -#include "td/telegram/telegram_api.h" #include "td/telegram/UserId.h" #include "td/actor/actor.h" @@ -52,15 +51,9 @@ class InlineMessageManager final : public Actor { void get_inline_game_high_scores(const string &inline_message_id, UserId user_id, Promise> &&promise); - static int32 get_inline_message_dc_id( - const telegram_api::object_ptr &inline_message_id); - private: void tear_down() final; - static telegram_api::object_ptr get_input_bot_inline_message_id( - const string &inline_message_id); - Td *td_; ActorShared<> parent_; };