diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index d39a17f5..aa5efa4d 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -2981,6 +2981,9 @@ updateNewCustomQuery id:int64 data:string timeout:int32 = Update; //@description Information about a poll was updated; for bots only @poll New data about the poll updatePoll poll:poll = Update; +//@description Informs bot about a user changed their answer to a poll @poll_id Unique poll identifier @user_id The user changed their answer to a poll @option_ids 0-based identifiers of answer options, chosen by the user +updatePollAnswer poll_id:int64 user_id:int32 option_ids:vector = Update; + //@description Contains a list of updates @updates List of updates updates updates:vector = Updates; diff --git a/td/generate/scheme/td_api.tlo b/td/generate/scheme/td_api.tlo index 338eddc9..a50b6e8c 100644 Binary files a/td/generate/scheme/td_api.tlo and b/td/generate/scheme/td_api.tlo differ diff --git a/td/generate/scheme/telegram_api.tl b/td/generate/scheme/telegram_api.tl index 206ac41b..99f3e31c 100644 --- a/td/generate/scheme/telegram_api.tl +++ b/td/generate/scheme/telegram_api.tl @@ -338,6 +338,7 @@ updateDeleteScheduledMessages#90866cee peer:Peer messages:Vector = Update; updateTheme#8216fba3 theme:Theme = Update; updateGeoLiveViewed#871fb939 peer:Peer msg_id:int = Update; updateLoginToken#564fe691 = Update; +updateMessagePollVote#42f88f2c poll_id:long user_id:int options:Vector = Update; updates.state#a56c2a3e pts:int qts:int date:int seq:int unread_count:int = updates.State; @@ -1093,7 +1094,7 @@ themeSettings#9c14984a flags:# base_theme:BaseTheme accent_color:int message_top webPageAttributeTheme#54b56617 flags:# documents:flags.0?Vector settings:flags.1?ThemeSettings = WebPageAttribute; -messageUserVote#f212f56d user_id:int option:bytes = MessageUserVote; +messageUserVote#a28e5559 user_id:int option:bytes date:int = MessageUserVote; messages.votesList#823f649 flags:# count:int votes:Vector users:Vector next_offset:flags.0?string = messages.VotesList; diff --git a/td/generate/scheme/telegram_api.tlo b/td/generate/scheme/telegram_api.tlo index 1cc0fca3..81d00fc2 100644 Binary files a/td/generate/scheme/telegram_api.tlo and b/td/generate/scheme/telegram_api.tlo differ diff --git a/td/telegram/PollManager.cpp b/td/telegram/PollManager.cpp index d3465c92..ff792681 100644 --- a/td/telegram/PollManager.cpp +++ b/td/telegram/PollManager.cpp @@ -1310,7 +1310,7 @@ PollId PollManager::on_get_poll(PollId poll_id, tl_object_ptrauth_manager_->is_bot() && !poll->is_closed) { + if (!is_bot && !poll->is_closed) { auto timeout = get_polling_timeout(); LOG(INFO) << "Schedule updating of " << poll_id << " in " << timeout; update_poll_timeout_.set_timeout_in(poll_id.get(), timeout); @@ -1325,6 +1325,35 @@ PollId PollManager::on_get_poll(PollId poll_id, tl_object_ptr &&options) { + if (!poll_id.is_valid()) { + LOG(ERROR) << "Receive updateMessagePollVote about invalid " << poll_id; + return; + } + if (!user_id.is_valid()) { + LOG(ERROR) << "Receive updateMessagePollVote from invalid " << user_id; + return; + } + if (!td_->auth_manager_->is_bot()) { + return; + } + + vector option_ids; + for (auto &option : options) { + auto slice = option.as_slice(); + if (slice.size() != 1 || slice[0] < '0' || slice[0] > '9') { + LOG(ERROR) << "Receive updateMessagePollVote with unexpected option \"" << format::escaped(slice) << '"'; + return; + } + option_ids.push_back(static_cast(slice[0] - '0')); + } + + send_closure(G()->td(), &Td::send_update, + td_api::make_object( + poll_id.get(), td_->contacts_manager_->get_user_id_object(user_id, "on_get_poll_vote"), + std::move(option_ids))); +} + void PollManager::on_binlog_events(vector &&events) { for (auto &event : events) { switch (event.type_) { diff --git a/td/telegram/PollManager.h b/td/telegram/PollManager.h index eec0f5d7..bd313223 100644 --- a/td/telegram/PollManager.h +++ b/td/telegram/PollManager.h @@ -71,6 +71,8 @@ class PollManager : public Actor { PollId on_get_poll(PollId poll_id, tl_object_ptr &&poll_server, tl_object_ptr &&poll_results); + void on_get_poll_vote(PollId poll_id, UserId user_id, vector &&options); + td_api::object_ptr get_poll_object(PollId poll_id) const; void on_binlog_events(vector &&events); diff --git a/td/telegram/UpdatesManager.cpp b/td/telegram/UpdatesManager.cpp index 6b66c564..1742556c 100644 --- a/td/telegram/UpdatesManager.cpp +++ b/td/telegram/UpdatesManager.cpp @@ -1980,6 +1980,10 @@ void UpdatesManager::on_update(tl_object_ptr up td_->poll_manager_->on_get_poll(PollId(update->poll_id_), std::move(update->poll_), std::move(update->results_)); } +void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { + td_->poll_manager_->on_get_poll_vote(PollId(update->poll_id_), UserId(update->user_id_), std::move(update->options_)); +} + void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { td_->messages_manager_->on_get_message(std::move(update->message_), true, false, true, true, true, "updateNewScheduledMessage"); diff --git a/td/telegram/UpdatesManager.h b/td/telegram/UpdatesManager.h index 770c60a1..e2c95c8b 100644 --- a/td/telegram/UpdatesManager.h +++ b/td/telegram/UpdatesManager.h @@ -281,6 +281,7 @@ class UpdatesManager : public Actor { void on_update(tl_object_ptr update, bool /*force_apply*/); void on_update(tl_object_ptr update, bool /*force_apply*/); + void on_update(tl_object_ptr update, bool /*force_apply*/); void on_update(tl_object_ptr update, bool /*force_apply*/); void on_update(tl_object_ptr update, bool /*force_apply*/);