Make functions static in InlineMessageManager.cpp.

This commit is contained in:
levlam 2024-06-01 23:32:25 +03:00
parent 02ad1269d6
commit 4f35dbd418
2 changed files with 39 additions and 45 deletions

View File

@ -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<telegram_api::InputBotInlineMessageID> &inline_message_id) {
CHECK(inline_message_id != nullptr);
switch (inline_message_id->get_id()) {
case telegram_api::inputBotInlineMessageID::ID:
return static_cast<const telegram_api::inputBotInlineMessageID *>(inline_message_id.get())->dc_id_;
case telegram_api::inputBotInlineMessageID64::ID:
return static_cast<const telegram_api::inputBotInlineMessageID64 *>(inline_message_id.get())->dc_id_;
default:
UNREACHABLE();
return 0;
}
}
static telegram_api::object_ptr<telegram_api::InputBotInlineMessageID> 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<Unit> 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<telegram_api::InputBotInlineMessageID> &inline_message_id) {
CHECK(inline_message_id != nullptr);
switch (inline_message_id->get_id()) {
case telegram_api::inputBotInlineMessageID::ID:
return static_cast<const telegram_api::inputBotInlineMessageID *>(inline_message_id.get())->dc_id_;
case telegram_api::inputBotInlineMessageID64::ID:
return static_cast<const telegram_api::inputBotInlineMessageID64 *>(inline_message_id.get())->dc_id_;
default:
UNREACHABLE();
return 0;
}
}
telegram_api::object_ptr<telegram_api::InputBotInlineMessageID> 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

View File

@ -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<td_api::object_ptr<td_api::gameHighScores>> &&promise);
static int32 get_inline_message_dc_id(
const telegram_api::object_ptr<telegram_api::InputBotInlineMessageID> &inline_message_id);
private:
void tear_down() final;
static telegram_api::object_ptr<telegram_api::InputBotInlineMessageID> get_input_bot_inline_message_id(
const string &inline_message_id);
Td *td_;
ActorShared<> parent_;
};