Add Game::has_input_media.

GitOrigin-RevId: 13be31df3a93d495628f64d7cedc767a6e030a68
This commit is contained in:
levlam 2020-01-16 05:18:06 +03:00
parent b9d1b80f6a
commit 4ec628fc78
4 changed files with 16 additions and 7 deletions

View File

@ -97,6 +97,10 @@ tl_object_ptr<td_api::game> Game::get_game_object(Td *td) const {
td->animations_manager_->get_animation_object(animation_file_id_, "get_game_object")); 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<telegram_api::inputMediaGame> Game::get_input_media_game(const Td *td) const { tl_object_ptr<telegram_api::inputMediaGame> Game::get_input_media_game(const Td *td) const {
auto input_user = td->contacts_manager_->get_input_user(bot_user_id_); auto input_user = td->contacts_manager_->get_input_user(bot_user_id_);
CHECK(input_user != nullptr); CHECK(input_user != nullptr);

View File

@ -65,6 +65,8 @@ class Game {
tl_object_ptr<td_api::game> get_game_object(Td *td) const; tl_object_ptr<td_api::game> get_game_object(Td *td) const;
bool has_input_media() const;
tl_object_ptr<telegram_api::inputMediaGame> get_input_media_game(const Td *td) const; tl_object_ptr<telegram_api::inputMediaGame> get_input_media_game(const Td *td) const;
template <class StorerT> template <class StorerT>

View File

@ -2150,7 +2150,7 @@ static tl_object_ptr<telegram_api::InputMedia> get_input_media_impl(
} }
case MessageContentType::Game: { case MessageContentType::Game: {
auto m = static_cast<const MessageGame *>(content); auto m = static_cast<const MessageGame *>(content);
if (!m->game.get_bot_user_id().is_valid()) { if (!m->game.has_input_media()) {
return nullptr; return nullptr;
} }
return m->game.get_input_media_game(td); return m->game.get_input_media_game(td);
@ -2173,6 +2173,13 @@ static tl_object_ptr<telegram_api::InputMedia> get_input_media_impl(
auto m = static_cast<const MessagePhoto *>(content); auto m = static_cast<const MessagePhoto *>(content);
return photo_get_input_media(td->file_manager_.get(), m->photo, std::move(input_file), ttl); return photo_get_input_media(td->file_manager_.get(), m->photo, std::move(input_file), ttl);
} }
case MessageContentType::Poll: {
auto m = static_cast<const MessagePoll *>(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: { case MessageContentType::Sticker: {
auto m = static_cast<const MessageSticker *>(content); auto m = static_cast<const MessageSticker *>(content);
return td->stickers_manager_->get_input_media(m->file_id, std::move(input_file), std::move(input_thumbnail)); 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<telegram_api::InputMedia> get_input_media_impl(
auto m = static_cast<const MessageVoiceNote *>(content); auto m = static_cast<const MessageVoiceNote *>(content);
return td->voice_notes_manager_->get_input_media(m->file_id, std::move(input_file)); return td->voice_notes_manager_->get_input_media(m->file_id, std::move(input_file));
} }
case MessageContentType::Poll: {
auto m = static_cast<const MessagePoll *>(content);
return td->poll_manager_->get_input_media(m->poll_id);
}
case MessageContentType::Text: case MessageContentType::Text:
case MessageContentType::Unsupported: case MessageContentType::Unsupported:
case MessageContentType::ChatCreate: case MessageContentType::ChatCreate:
@ -4094,7 +4097,7 @@ unique_ptr<MessageContent> dup_message_content(Td *td, DialogId dialog_id, const
case MessageContentType::Game: { case MessageContentType::Game: {
auto result = make_unique<MessageGame>(*static_cast<const MessageGame *>(content)); auto result = make_unique<MessageGame>(*static_cast<const MessageGame *>(content));
if (type != MessageContentDupType::Forward && type != MessageContentDupType::SendViaBot && 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"; LOG(INFO) << "Can't send/copy game without bot_user_id";
return nullptr; return nullptr;
} }

View File

@ -18522,7 +18522,7 @@ void MessagesManager::do_send_message(DialogId dialog_id, const Message *m, vect
} else { } else {
auto input_media = get_input_media(content, td_, m->ttl, false); auto input_media = get_input_media(content, td_, m->ttl, false);
if (input_media == nullptr) { if (input_media == nullptr) {
if (content_type == MessageContentType::Game) { if (content_type == MessageContentType::Game || content_type == MessageContentType::Poll) {
return; return;
} }
if (content_type == MessageContentType::Photo) { if (content_type == MessageContentType::Photo) {