From 9ec9377815782a9190d15936b58ea6c0c95dfc6a Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 28 Sep 2018 02:16:49 +0300 Subject: [PATCH] Make more functions static. GitOrigin-RevId: 70c3e1fee2af9620ef61e4d337ba8126ca41634c --- td/telegram/Game.cpp | 4 ++-- td/telegram/Game.h | 4 ++-- td/telegram/InlineQueriesManager.cpp | 12 +++++------- td/telegram/MessagesManager.cpp | 26 +++++++++++++------------- td/telegram/MessagesManager.h | 9 +++++---- 5 files changed, 27 insertions(+), 28 deletions(-) diff --git a/td/telegram/Game.cpp b/td/telegram/Game.cpp index f065ca07..6f65e7e2 100644 --- a/td/telegram/Game.cpp +++ b/td/telegram/Game.cpp @@ -83,11 +83,11 @@ UserId Game::get_bot_user_id() const { return bot_user_id_; } -void Game::set_message_text(FormattedText &&text) { +void Game::set_text(FormattedText &&text) { text_ = std::move(text); } -const FormattedText &Game::get_message_text() const { +const FormattedText &Game::get_text() const { return text_; } diff --git a/td/telegram/Game.h b/td/telegram/Game.h index 98eed664..26683e43 100644 --- a/td/telegram/Game.h +++ b/td/telegram/Game.h @@ -55,9 +55,9 @@ class Game { UserId get_bot_user_id() const; - void set_message_text(FormattedText &&text); + void set_text(FormattedText &&text); - const FormattedText &get_message_text() const; + const FormattedText &get_text() const; tl_object_ptr get_game_object(Td *td) const; diff --git a/td/telegram/InlineQueriesManager.cpp b/td/telegram/InlineQueriesManager.cpp index 843657cc..e73591be 100644 --- a/td/telegram/InlineQueriesManager.cpp +++ b/td/telegram/InlineQueriesManager.cpp @@ -384,11 +384,9 @@ InlineMessageContent InlineQueriesManager::create_inline_message_content( } case telegram_api::botInlineMessageMediaAuto::ID: { auto input_message_media_auto = move_tl_object_as(inline_message); - auto caption = td_->messages_manager_->get_message_text(input_message_media_auto->message_, - std::move(input_message_media_auto->entities_), 0, - "register_inline_message_content"); - reply_markup = std::move(input_message_media_auto->reply_markup_); - + auto caption = MessagesManager::get_message_text(td_->contacts_manager_.get(), input_message_media_auto->message_, + std::move(input_message_media_auto->entities_), 0, + "register_inline_message_content"); if (allowed_media_content_id == td_api::inputMessageAnimation::ID) { result.message_content = make_unique(file_id, std::move(caption)); } else if (allowed_media_content_id == td_api::inputMessageAudio::ID) { @@ -408,10 +406,10 @@ InlineMessageContent InlineQueriesManager::create_inline_message_content( } else if (allowed_media_content_id == td_api::inputMessageVoiceNote::ID) { result.message_content = make_unique(file_id, std::move(caption), true); } else { - input_message_media_auto->reply_markup_ = std::move(reply_markup); - input_message_media_auto->message_ = std::move(caption.text); LOG(WARNING) << "Unallowed bot inline message " << to_string(input_message_media_auto); } + + reply_markup = std::move(input_message_media_auto->reply_markup_); break; } default: diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 8f0ff0f8..c362aab2 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -5696,8 +5696,8 @@ void MessagesManager::on_update_service_notification(tl_object_ptrmessage_), std::move(update->entities_), update->inbox_date_, - "on_update_service_notification"), + get_message_text(td_->contacts_manager_.get(), std::move(update->message_), std::move(update->entities_), + update->inbox_date_, "on_update_service_notification"), std::move(update->media_), td_->auth_manager_->is_bot() ? DialogId() : get_service_notifications_dialog()->dialog_id, false, UserId(), &ttl); bool is_content_secret = is_secret_message_content(ttl, content->get_type()); @@ -10665,7 +10665,7 @@ MessagesManager::MessageInfo MessagesManager::parse_telegram_api_message( } message_info.content = get_message_content( td_, - get_message_text(std::move(message->message_), std::move(message->entities_), + get_message_text(td_->contacts_manager_.get(), std::move(message->message_), std::move(message->entities_), message_info.forward_header ? message_info.forward_header->date_ : message_info.date, "parse_telegram_api_message"), std::move(message->media_), message_info.dialog_id, is_content_read, message_info.via_bot_user_id, @@ -11217,8 +11217,8 @@ void MessagesManager::on_update_sent_text_message(int64 random_id, auto new_content = get_message_content( td_, - get_message_text(message_text->text.text, std::move(entities), m->forward_info ? m->forward_info->date : m->date, - "on_update_sent_text_message"), + get_message_text(td_->contacts_manager_.get(), message_text->text.text, std::move(entities), + m->forward_info ? m->forward_info->date : m->date, "on_update_sent_text_message"), std::move(message_media), dialog_id, true /*likely ignored*/, UserId() /*likely ignored*/, nullptr /*ignored*/); if (new_content->get_type() != MessageContentType::Text) { LOG(ERROR) << "Text message content has changed to " << new_content->get_type(); @@ -15730,13 +15730,13 @@ Result MessagesManager::process_input_message_contact( } Result MessagesManager::process_input_message_game( - tl_object_ptr &&input_message_content) const { + const ContactsManager *contacts_manager, tl_object_ptr &&input_message_content) { CHECK(input_message_content != nullptr); CHECK(input_message_content->get_id() == td_api::inputMessageGame::ID); auto input_message_game = move_tl_object_as(input_message_content); UserId bot_user_id(input_message_game->bot_user_id_); - if (!td_->contacts_manager_->have_input_user(bot_user_id)) { + if (!contacts_manager->have_input_user(bot_user_id)) { return Status::Error(400, "Game owner bot is not accessible"); } @@ -16411,7 +16411,7 @@ FormattedText MessagesManager::get_message_content_text(const MessageContent *co case MessageContentType::Text: return static_cast(content)->text; case MessageContentType::Game: - return static_cast(content)->game.get_message_text(); + return static_cast(content)->game.get_text(); default: return get_message_content_caption(content); } @@ -17243,7 +17243,7 @@ Result MessagesManager::process_input_mess break; } case td_api::inputMessageGame::ID: { - TRY_RESULT(game, process_input_message_game(std::move(input_message_content))); + TRY_RESULT(game, process_input_message_game(td_->contacts_manager_.get(), std::move(input_message_content))); via_bot_user_id = game.get_bot_user_id(); if (via_bot_user_id == td_->contacts_manager_->get_my_id("send_message")) { via_bot_user_id = UserId(); @@ -22387,10 +22387,10 @@ FormattedText MessagesManager::get_secret_media_caption(string &&message_text, s return caption; } -FormattedText MessagesManager::get_message_text(string message_text, +FormattedText MessagesManager::get_message_text(const ContactsManager *contacts_manager, string message_text, vector> &&server_entities, - int32 send_date, const char *source) const { - auto entities = get_message_entities(td_->contacts_manager_.get(), std::move(server_entities), source); + int32 send_date, const char *source) { + auto entities = get_message_entities(contacts_manager, std::move(server_entities), source); auto status = fix_formatted_text(message_text, entities, true, true, true, false); if (status.is_error()) { if (send_date == 0 || send_date > 1497000000) { // approximate fix date @@ -22876,7 +22876,7 @@ unique_ptr MessagesManager::get_message_content(Td *td, Formatte } m->game.set_bot_user_id(via_bot_user_id); - m->game.set_message_text(std::move(message)); + m->game.set_text(std::move(message)); return std::move(m); } diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index ead298f5..7f8d343e 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -1080,14 +1080,15 @@ class MessagesManager : public Actor { static Result process_input_message_contact( tl_object_ptr &&input_message_content) TD_WARN_UNUSED_RESULT; - Result process_input_message_game(tl_object_ptr &&input_message_content) const + static Result process_input_message_game(const ContactsManager *contacts_manager, + tl_object_ptr &&input_message_content) TD_WARN_UNUSED_RESULT; bool need_skip_bot_commands(DialogId dialog_id, bool is_bot) const; - FormattedText get_message_text(string message_text, - vector> &&server_entities, int32 send_date, - const char *source) const; + static FormattedText get_message_text(const ContactsManager *contacts_manager, string message_text, + vector> &&server_entities, + int32 send_date, const char *source); Result send_message(DialogId dialog_id, MessageId reply_to_message_id, bool disable_notification, bool from_background, tl_object_ptr &&reply_markup,