From 4ec628fc78421493ad1ba397f64c33cb21dd6a15 Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 16 Jan 2020 05:18:06 +0300 Subject: [PATCH] Add Game::has_input_media. GitOrigin-RevId: 13be31df3a93d495628f64d7cedc767a6e030a68 --- td/telegram/Game.cpp | 4 ++++ td/telegram/Game.h | 2 ++ td/telegram/MessageContent.cpp | 15 +++++++++------ td/telegram/MessagesManager.cpp | 2 +- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/td/telegram/Game.cpp b/td/telegram/Game.cpp index 1498db19..36e37dfa 100644 --- a/td/telegram/Game.cpp +++ b/td/telegram/Game.cpp @@ -97,6 +97,10 @@ tl_object_ptr Game::get_game_object(Td *td) const { td->animations_manager_->get_animation_object(animation_file_id_, "get_game_object")); } +bool Game::has_input_media() const { + return bot_user_id_.is_valid(); +} + tl_object_ptr Game::get_input_media_game(const Td *td) const { auto input_user = td->contacts_manager_->get_input_user(bot_user_id_); CHECK(input_user != nullptr); diff --git a/td/telegram/Game.h b/td/telegram/Game.h index d6e011b0..43c3b9d4 100644 --- a/td/telegram/Game.h +++ b/td/telegram/Game.h @@ -65,6 +65,8 @@ class Game { tl_object_ptr get_game_object(Td *td) const; + bool has_input_media() const; + tl_object_ptr get_input_media_game(const Td *td) const; template diff --git a/td/telegram/MessageContent.cpp b/td/telegram/MessageContent.cpp index a90ed3f6..61673126 100644 --- a/td/telegram/MessageContent.cpp +++ b/td/telegram/MessageContent.cpp @@ -2150,7 +2150,7 @@ static tl_object_ptr get_input_media_impl( } case MessageContentType::Game: { auto m = static_cast(content); - if (!m->game.get_bot_user_id().is_valid()) { + if (!m->game.has_input_media()) { return nullptr; } return m->game.get_input_media_game(td); @@ -2173,6 +2173,13 @@ static tl_object_ptr get_input_media_impl( auto m = static_cast(content); return photo_get_input_media(td->file_manager_.get(), m->photo, std::move(input_file), ttl); } + case MessageContentType::Poll: { + auto m = static_cast(content); + if (!td->poll_manager_->has_input_media(m->poll_id)) { + return nullptr; + } + return td->poll_manager_->get_input_media(m->poll_id); + } case MessageContentType::Sticker: { auto m = static_cast(content); return td->stickers_manager_->get_input_media(m->file_id, std::move(input_file), std::move(input_thumbnail)); @@ -2193,10 +2200,6 @@ static tl_object_ptr get_input_media_impl( auto m = static_cast(content); return td->voice_notes_manager_->get_input_media(m->file_id, std::move(input_file)); } - case MessageContentType::Poll: { - auto m = static_cast(content); - return td->poll_manager_->get_input_media(m->poll_id); - } case MessageContentType::Text: case MessageContentType::Unsupported: case MessageContentType::ChatCreate: @@ -4094,7 +4097,7 @@ unique_ptr dup_message_content(Td *td, DialogId dialog_id, const case MessageContentType::Game: { auto result = make_unique(*static_cast(content)); if (type != MessageContentDupType::Forward && type != MessageContentDupType::SendViaBot && - !result->game.get_bot_user_id().is_valid()) { + !result->game.has_input_media()) { LOG(INFO) << "Can't send/copy game without bot_user_id"; return nullptr; } diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 0b1775cd..a7f91220 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -18522,7 +18522,7 @@ void MessagesManager::do_send_message(DialogId dialog_id, const Message *m, vect } else { auto input_media = get_input_media(content, td_, m->ttl, false); if (input_media == nullptr) { - if (content_type == MessageContentType::Game) { + if (content_type == MessageContentType::Game || content_type == MessageContentType::Poll) { return; } if (content_type == MessageContentType::Photo) {