From 6d15cc7bf0546135468ffd5e42ec2f1f65b0b75e Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 13 Jan 2020 22:56:59 +0300 Subject: [PATCH] Add updatePollAnswer. GitOrigin-RevId: 472f91830667f52317f03636f3ab2c37bca32d43 --- td/generate/scheme/td_api.tl | 3 +++ td/generate/scheme/td_api.tlo | Bin 166788 -> 166968 bytes td/generate/scheme/telegram_api.tl | 3 ++- td/generate/scheme/telegram_api.tlo | Bin 199724 -> 199936 bytes td/telegram/PollManager.cpp | 31 +++++++++++++++++++++++++++- td/telegram/PollManager.h | 2 ++ td/telegram/UpdatesManager.cpp | 4 ++++ td/telegram/UpdatesManager.h | 1 + 8 files changed, 42 insertions(+), 2 deletions(-) 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 338eddc9df4d7225e16fc63524b2d2ec46302133..a50b6e8c8324c8a2e4470e4c3ea210f8c637ef91 100644 GIT binary patch delta 1972 zcmZWqQAk^76!u(Gn~DP&LWPDQOz17%v6Kq)A%&FLO-5ETXlWmWWl+03q+4h$m2D3l zmXSdpVs4fbHMUW+8f#M1CNXJ^nPoC$FUw$~7A*5&j1DrE2VooduzTEt`- z`_4K4`OklEVrx0xnj4W{dYV47*>Wy;@q>}!CQtrz`9w1u94q#eiaoG2Y}38y9|sp% z>2c^Lt2Pc!vTPAy#r}e`1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5v~(GT{QQR-z!3kd6lo8u%oiU>i!MJ0v*)F04e;tVg9yc?*aYSO>UZF=Y4wgYYYFI X8Ao{Wvl`WT;>TYMET0_{H=VBmb+MmD 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 1cc0fca30bace4f0e66263ea4583cf6b127a6a38..81d00fc2fed67eaae582d930352eb0d4bbadfaa0 100644 GIT binary patch delta 2254 zcmaJ@UrbwN6z};cqzaR6R@VnyI@d`JH?e3Fm)I>;m#iveeGn59vfU+XB+9a8)MXDm zR7VUCi*~t7Pk{m*LxfSF{4Ikr3L{E{C1mQdC79@o&IC=f@UTTR-h03AT$l;mhvwY# zedqW4o$ov6+@|6sk=BxQ-e&%==F6_pb(^zz*ZQ5-j-r~-=~LmLsan|&dq=&F^*tbs zR=!sH(5~$(JritbIQ3DmrXhIlgR|kF=2P5Z2~+dTf|m}04dq=>h}G?IKnKpG4njO+ z){tXEzzxjCz@fYFmly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hpS)Pc2;L)nMZwq&QXKFealk1W~@wHv}?|vO^H! zkv&D2at<0f7EhVAFqxt~{z-X;?%*&4d2atO$d>LZygdTvP#mF(-6JNu{+1eeLqcVp zxTR5&-aJZdiBa%aYy$o?0$$Ah3l23Hbeek8)W7_u8(Y%gH+7_GAAvfd35V^%DRf_j zyL@%;D%G-&K^w>7V&e-@`;9DwM_TesJYG&F{ndP|$ zOfQcTi%fnY3qH&vHMn?#R_#+HRhc3zGX?$p-QYB}BR&m2j!jMW9tGx zrs&F0^TO{iXZ*7QXZ3kLug?B<0{_lH59d^FQ^hi;n;F1Z)tD7rz!PKh#Ag&L-51>D zNtNb_CA`Ia)4V{Bu?3KiZbN1PyhpE=7LIG7ck#IPcPx@xW(RY)-X&5MUV=%!s{_JR z=1n#9u@kdP;6gq~8NMk$_bH}|A%25xL99<|6a->CEgKo}}SR*XEW?i}KCT3iv{%Uv@zpfXa zDVu20x+4qgbg9SlR4^?FG8XdC!Yg<;tYL0IAIEmfnC`-ZcERb|d7*($}c4X%0b^-ZDQ5zB?qqaCYkr@ac+Q)DJ#qt*H3*L{00pM^ArQ`>F8>Ziz-Z zBXltUZiIz;6t}=>3g4o-j4;fxafTgv4z&L7AyZXl6vXyncp0T1LB!sB=H)i91N|7? zHeJ5713m8>-*JWqw7aq(I(QM~5qyr)D}tzX_=T`(E(XR?+=eRcrPqYo|ACcS=5-;w F^B=11jfVgL 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*/);