diff options
author | George Hazan <george.hazan@gmail.com> | 2024-09-29 19:03:55 +0300 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2024-09-29 19:04:03 +0300 |
commit | cebfc5c8facbf6ae335499f7f4b3dc57a60af999 (patch) | |
tree | 4c39e613c87f6164df1fe80601e611987aaaec84 /protocols/Telegram/tdlib/td/td/telegram/PollManager.hpp | |
parent | 189164bebda4bca9bb3d672500d844bfe7f26517 (diff) |
TDLIB update up to the current state
Diffstat (limited to 'protocols/Telegram/tdlib/td/td/telegram/PollManager.hpp')
-rw-r--r-- | protocols/Telegram/tdlib/td/td/telegram/PollManager.hpp | 118 |
1 files changed, 95 insertions, 23 deletions
diff --git a/protocols/Telegram/tdlib/td/td/telegram/PollManager.hpp b/protocols/Telegram/tdlib/td/td/telegram/PollManager.hpp index 85cb4ae3ca..681a6a1d81 100644 --- a/protocols/Telegram/tdlib/td/td/telegram/PollManager.hpp +++ b/protocols/Telegram/tdlib/td/td/telegram/PollManager.hpp @@ -1,12 +1,15 @@ // -// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023 +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2024 // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #pragma once +#include "td/telegram/MessageEntity.hpp" +#include "td/telegram/MinChannel.hpp" #include "td/telegram/PollManager.h" +#include "td/telegram/UserId.h" #include "td/telegram/Version.h" #include "td/utils/algorithm.h" @@ -18,56 +21,68 @@ namespace td { template <class StorerT> void PollManager::PollOption::store(StorerT &storer) const { using ::td::store; + bool has_entities = !text_.entities.empty(); BEGIN_STORE_FLAGS(); STORE_FLAG(is_chosen_); + STORE_FLAG(has_entities); END_STORE_FLAGS(); - store(text_, storer); + store(text_.text, storer); store(data_, storer); store(voter_count_, storer); + if (has_entities) { + store(text_.entities, storer); + } } template <class ParserT> void PollManager::PollOption::parse(ParserT &parser) { using ::td::parse; + bool has_entities; BEGIN_PARSE_FLAGS(); PARSE_FLAG(is_chosen_); + PARSE_FLAG(has_entities); END_PARSE_FLAGS(); - parse(text_, parser); + parse(text_.text, parser); parse(data_, parser); parse(voter_count_, parser); + if (has_entities) { + parse(text_.entities, parser); + } } template <class StorerT> void PollManager::Poll::store(StorerT &storer) const { using ::td::store; bool is_public = !is_anonymous_; - bool has_recent_voters = !recent_voter_user_ids_.empty(); bool has_open_period = open_period_ != 0; bool has_close_date = close_date_ != 0; bool has_explanation = !explanation_.text.empty(); + bool has_recent_voter_dialog_ids = !recent_voter_dialog_ids_.empty(); + bool has_recent_voter_min_channels = !recent_voter_min_channels_.empty(); + bool has_question_entities = !question_.entities.empty(); BEGIN_STORE_FLAGS(); STORE_FLAG(is_closed_); STORE_FLAG(is_public); STORE_FLAG(allow_multiple_answers_); STORE_FLAG(is_quiz_); - STORE_FLAG(has_recent_voters); + STORE_FLAG(false); STORE_FLAG(has_open_period); STORE_FLAG(has_close_date); STORE_FLAG(has_explanation); STORE_FLAG(is_updated_after_close_); + STORE_FLAG(has_recent_voter_dialog_ids); + STORE_FLAG(has_recent_voter_min_channels); + STORE_FLAG(has_question_entities); END_STORE_FLAGS(); - store(question_, storer); + store(question_.text, storer); store(options_, storer); store(total_voter_count_, storer); if (is_quiz_) { store(correct_option_id_, storer); } - if (has_recent_voters) { - store(recent_voter_user_ids_, storer); - } if (has_open_period) { store(open_period_, storer); } @@ -77,40 +92,57 @@ void PollManager::Poll::store(StorerT &storer) const { if (has_explanation) { store(explanation_, storer); } + if (has_recent_voter_dialog_ids) { + store(recent_voter_dialog_ids_, storer); + } + if (has_recent_voter_min_channels) { + store(recent_voter_min_channels_, storer); + } + if (has_question_entities) { + store(question_.entities, storer); + } } template <class ParserT> void PollManager::Poll::parse(ParserT &parser) { using ::td::parse; bool is_public; - bool has_recent_voters; + bool has_recent_voter_user_ids; bool has_open_period; bool has_close_date; bool has_explanation; + bool has_recent_voter_dialog_ids; + bool has_recent_voter_min_channels; + bool has_question_entities; BEGIN_PARSE_FLAGS(); PARSE_FLAG(is_closed_); PARSE_FLAG(is_public); PARSE_FLAG(allow_multiple_answers_); PARSE_FLAG(is_quiz_); - PARSE_FLAG(has_recent_voters); + PARSE_FLAG(has_recent_voter_user_ids); PARSE_FLAG(has_open_period); PARSE_FLAG(has_close_date); PARSE_FLAG(has_explanation); PARSE_FLAG(is_updated_after_close_); + PARSE_FLAG(has_recent_voter_dialog_ids); + PARSE_FLAG(has_recent_voter_min_channels); + PARSE_FLAG(has_question_entities); END_PARSE_FLAGS(); is_anonymous_ = !is_public; - parse(question_, parser); + parse(question_.text, parser); parse(options_, parser); parse(total_voter_count_, parser); if (is_quiz_) { parse(correct_option_id_, parser); if (correct_option_id_ < -1 || correct_option_id_ >= static_cast<int32>(options_.size())) { - parser.set_error("Wrong correct_option_id"); + parser.set_error("Wrong quiz correct_option_id"); } } - if (has_recent_voters) { - parse(recent_voter_user_ids_, parser); + if (has_recent_voter_user_ids) { + vector<UserId> recent_voter_user_ids; + parse(recent_voter_user_ids, parser); + recent_voter_dialog_ids_ = transform(recent_voter_user_ids, [](UserId user_id) { return DialogId(user_id); }); } if (has_open_period) { parse(open_period_, parser); @@ -121,6 +153,15 @@ void PollManager::Poll::parse(ParserT &parser) { if (has_explanation) { parse(explanation_, parser); } + if (has_recent_voter_dialog_ids) { + parse(recent_voter_dialog_ids_, parser); + } + if (has_recent_voter_min_channels) { + parse(recent_voter_min_channels_, parser); + } + if (has_question_entities) { + parse(question_.entities, parser); + } } template <class StorerT> @@ -132,6 +173,9 @@ void PollManager::store_poll(PollId poll_id, StorerT &storer) const { bool has_open_period = poll->open_period_ != 0; bool has_close_date = poll->close_date_ != 0; bool has_explanation = !poll->explanation_.text.empty(); + bool has_question_entities = !poll->question_.entities.empty(); + bool has_option_entities = + any_of(poll->options_, [](const auto &option) { return !option.text_.entities.empty(); }); BEGIN_STORE_FLAGS(); STORE_FLAG(poll->is_closed_); STORE_FLAG(poll->is_anonymous_); @@ -140,9 +184,11 @@ void PollManager::store_poll(PollId poll_id, StorerT &storer) const { STORE_FLAG(has_open_period); STORE_FLAG(has_close_date); STORE_FLAG(has_explanation); + STORE_FLAG(has_question_entities); + STORE_FLAG(has_option_entities); END_STORE_FLAGS(); - store(poll->question_, storer); - vector<string> options = transform(poll->options_, [](const PollOption &option) { return option.text_; }); + store(poll->question_.text, storer); + vector<string> options = transform(poll->options_, [](const PollOption &option) { return option.text_.text; }); store(options, storer); if (poll->is_quiz_) { store(poll->correct_option_id_, storer); @@ -156,6 +202,13 @@ void PollManager::store_poll(PollId poll_id, StorerT &storer) const { if (has_explanation) { store(poll->explanation_, storer); } + if (has_question_entities) { + store(poll->question_.entities, storer); + } + if (has_option_entities) { + auto option_entities = transform(poll->options_, [](const PollOption &option) { return option.text_.entities; }); + store(option_entities, storer); + } } } @@ -165,8 +218,7 @@ PollId PollManager::parse_poll(ParserT &parser) { td::parse(poll_id_int, parser); PollId poll_id(poll_id_int); if (is_local_poll_id(poll_id)) { - string question; - vector<string> options; + FormattedText question; FormattedText explanation; int32 open_period = 0; int32 close_date = 0; @@ -177,6 +229,8 @@ PollId PollManager::parse_poll(ParserT &parser) { bool has_open_period = false; bool has_close_date = false; bool has_explanation = false; + bool has_question_entities = false; + bool has_option_entities = false; int32 correct_option_id = -1; if (parser.version() >= static_cast<int32>(Version::SupportPolls2_0)) { @@ -188,14 +242,17 @@ PollId PollManager::parse_poll(ParserT &parser) { PARSE_FLAG(has_open_period); PARSE_FLAG(has_close_date); PARSE_FLAG(has_explanation); + PARSE_FLAG(has_question_entities); + PARSE_FLAG(has_option_entities); END_PARSE_FLAGS(); } - parse(question, parser); - parse(options, parser); + parse(question.text, parser); + vector<string> option_texts; + parse(option_texts, parser); if (is_quiz) { parse(correct_option_id, parser); - if (correct_option_id < -1 || correct_option_id >= static_cast<int32>(options.size())) { - parser.set_error("Wrong correct_option_id"); + if (correct_option_id < -1 || correct_option_id >= static_cast<int32>(option_texts.size())) { + parser.set_error("Wrong local quiz correct_option_id"); } } if (has_open_period) { @@ -207,6 +264,21 @@ PollId PollManager::parse_poll(ParserT &parser) { if (has_explanation) { parse(explanation, parser); } + if (has_question_entities) { + parse(question.entities, parser); + } + vector<vector<MessageEntity>> option_entities; + if (has_option_entities) { + parse(option_entities, parser); + CHECK(option_entities.size() == option_texts.size()); + } else { + option_entities.resize(option_texts.size()); + } + vector<FormattedText> options; + for (size_t i = 0; i < option_texts.size(); i++) { + options.push_back({std::move(option_texts[i]), std::move(option_entities[i])}); + } + if (parser.get_error() != nullptr) { return PollId(); } |