From fb215a028751dc6ff4b0211b41def8882425dd8d Mon Sep 17 00:00:00 2001 From: levlam Date: Wed, 15 Jan 2020 05:42:10 +0300 Subject: [PATCH] Fix quiz copying. GitOrigin-RevId: f92b11f5327b7f6f67cb7e67ea7ee282a5f5cb23 --- td/telegram/MessageContent.cpp | 10 ++++++++-- td/telegram/PollManager.cpp | 8 ++++++++ td/telegram/PollManager.h | 2 ++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/td/telegram/MessageContent.cpp b/td/telegram/MessageContent.cpp index 0e5af193..a90ed3f6 100644 --- a/td/telegram/MessageContent.cpp +++ b/td/telegram/MessageContent.cpp @@ -4170,6 +4170,14 @@ unique_ptr dup_message_content(Td *td, DialogId dialog_id, const } return std::move(result); } + case MessageContentType::Poll: { + auto result = make_unique(*static_cast(content)); + if (type != MessageContentDupType::Forward && type != MessageContentDupType::SendViaBot && + !td->poll_manager_->has_input_media(result->poll_id)) { + return nullptr; + } + return std::move(result); + } case MessageContentType::Sticker: { auto result = make_unique(*static_cast(content)); if (td->stickers_manager_->has_input_media(result->file_id, to_secret)) { @@ -4218,8 +4226,6 @@ unique_ptr dup_message_content(Td *td, DialogId dialog_id, const CHECK(result->file_id.is_valid()); return std::move(result); } - case MessageContentType::Poll: - return make_unique(*static_cast(content)); case MessageContentType::Unsupported: case MessageContentType::ChatCreate: case MessageContentType::ChatChangeTitle: diff --git a/td/telegram/PollManager.cpp b/td/telegram/PollManager.cpp index d2f428b7..3e788188 100644 --- a/td/telegram/PollManager.cpp +++ b/td/telegram/PollManager.cpp @@ -1111,6 +1111,12 @@ void PollManager::on_online() { } } +bool PollManager::has_input_media(PollId poll_id) const { + auto poll = get_poll(poll_id); + CHECK(poll != nullptr); + return !poll->is_quiz || poll->correct_option_id >= 0; +} + tl_object_ptr PollManager::get_input_media(PollId poll_id) const { auto poll = get_poll(poll_id); CHECK(poll != nullptr); @@ -1130,6 +1136,8 @@ tl_object_ptr PollManager::get_input_media(PollId poll vector correct_answers; if (poll->is_quiz) { flags |= telegram_api::inputMediaPoll::CORRECT_ANSWERS_MASK; + CHECK(poll->correct_option_id >= 0); + CHECK(static_cast(poll->correct_option_id) < poll->options.size()); correct_answers.push_back(BufferSlice(poll->options[poll->correct_option_id].data)); } return telegram_api::make_object( diff --git a/td/telegram/PollManager.h b/td/telegram/PollManager.h index bd313223..41c4557f 100644 --- a/td/telegram/PollManager.h +++ b/td/telegram/PollManager.h @@ -66,6 +66,8 @@ class PollManager : public Actor { void stop_local_poll(PollId poll_id); + bool has_input_media(PollId poll_id) const; + tl_object_ptr get_input_media(PollId poll_id) const; PollId on_get_poll(PollId poll_id, tl_object_ptr &&poll_server,