diff --git a/td/telegram/MessageContent.cpp b/td/telegram/MessageContent.cpp index 51b704ef0..4bbabbf65 100644 --- a/td/telegram/MessageContent.cpp +++ b/td/telegram/MessageContent.cpp @@ -4362,7 +4362,12 @@ unique_ptr dup_message_content(Td *td, DialogId dialog_id, const return std::move(result); } case MessageContentType::Poll: - return make_unique(*static_cast(content)); + if (type == MessageContentDupType::Copy) { + return make_unique( + td->poll_manager_->dup_poll(static_cast(content)->poll_id)); + } else { + return make_unique(*static_cast(content)); + } case MessageContentType::Sticker: { auto result = make_unique(*static_cast(content)); if (td->stickers_manager_->has_input_media(result->file_id, to_secret)) { diff --git a/td/telegram/PollManager.cpp b/td/telegram/PollManager.cpp index c7e62846c..048f250e1 100644 --- a/td/telegram/PollManager.cpp +++ b/td/telegram/PollManager.cpp @@ -576,6 +576,10 @@ td_api::object_ptr PollManager::get_poll_object(PollId poll_id, co open_period = close_date - now; } } + if (poll->is_closed) { + open_period = 0; + close_date = 0; + } return td_api::make_object( poll_id.get(), poll->question, std::move(poll_options), total_voter_count, td_->contacts_manager_->get_user_ids_object(poll->recent_voter_user_ids, "get_poll_object"), poll->is_anonymous, @@ -1246,6 +1250,18 @@ void PollManager::on_online() { } } +PollId PollManager::dup_poll(PollId poll_id) { + auto poll = get_poll(poll_id); + CHECK(poll != nullptr); + + auto question = poll->question; + auto options = transform(poll->options, [](auto &option) { return option.text; }); + auto explanation = poll->explanation; + return create_poll(std::move(question), std::move(options), poll->is_anonymous, poll->allow_multiple_answers, + poll->is_quiz, poll->correct_option_id, std::move(explanation), poll->open_period, + poll->open_period == 0 ? 0 : G()->unix_time(), false); +} + bool PollManager::has_input_media(PollId poll_id) const { auto poll = get_poll(poll_id); CHECK(poll != nullptr); @@ -1346,6 +1362,7 @@ PollId PollManager::on_get_poll(PollId poll_id, tl_object_ptropen_period) { poll->open_period = open_period; - is_changed = true; + if (!poll->is_closed) { + is_changed = true; + } else { + need_save_to_database = true; + } } if (close_date != poll->close_date) { poll->close_date = close_date; - is_changed = true; - if (!poll->is_closed) { + is_changed = true; if (close_date != 0) { if (close_date <= G()->server_time()) { poll->is_closed = true; @@ -1444,6 +1464,8 @@ PollId PollManager::on_get_poll(PollId poll_id, tl_object_ptrflags_ & telegram_api::poll::PUBLIC_VOTERS_MASK) == 0; @@ -1608,6 +1630,8 @@ PollId PollManager::on_get_poll(PollId poll_id, tl_object_ptris_closed && being_closed_polls_.erase(poll_id) != 0))) { diff --git a/td/telegram/PollManager.h b/td/telegram/PollManager.h index c26ab5a59..1b415a939 100644 --- a/td/telegram/PollManager.h +++ b/td/telegram/PollManager.h @@ -70,6 +70,8 @@ class PollManager final : public Actor { void stop_local_poll(PollId poll_id); + PollId dup_poll(PollId poll_id); + bool has_input_media(PollId poll_id) const; tl_object_ptr get_input_media(PollId poll_id) const;