Add updatePollAnswer.

GitOrigin-RevId: 472f91830667f52317f03636f3ab2c37bca32d43
This commit is contained in:
levlam 2020-01-13 22:56:59 +03:00
parent 656fda701f
commit 6d15cc7bf0
8 changed files with 42 additions and 2 deletions

View File

@ -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<int32> = Update;
//@description Contains a list of updates @updates List of updates
updates updates:vector<Update> = Updates;

Binary file not shown.

View File

@ -338,6 +338,7 @@ updateDeleteScheduledMessages#90866cee peer:Peer messages:Vector<int> = 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<bytes> = 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<Document> 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<MessageUserVote> users:Vector<User> next_offset:flags.0?string = messages.VotesList;

Binary file not shown.

View File

@ -1310,7 +1310,7 @@ PollId PollManager::on_get_poll(PollId poll_id, tl_object_ptr<telegram_api::poll
is_changed = true;
}
if (!td_->auth_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<telegram_api::poll
return poll_id;
}
void PollManager::on_get_poll_vote(PollId poll_id, UserId user_id, vector<BufferSlice> &&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<int32> 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<int32>(slice[0] - '0'));
}
send_closure(G()->td(), &Td::send_update,
td_api::make_object<td_api::updatePollAnswer>(
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<BinlogEvent> &&events) {
for (auto &event : events) {
switch (event.type_) {

View File

@ -71,6 +71,8 @@ class PollManager : public Actor {
PollId on_get_poll(PollId poll_id, tl_object_ptr<telegram_api::poll> &&poll_server,
tl_object_ptr<telegram_api::pollResults> &&poll_results);
void on_get_poll_vote(PollId poll_id, UserId user_id, vector<BufferSlice> &&options);
td_api::object_ptr<td_api::poll> get_poll_object(PollId poll_id) const;
void on_binlog_events(vector<BinlogEvent> &&events);

View File

@ -1980,6 +1980,10 @@ void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateMessagePoll> 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<telegram_api::updateMessagePollVote> 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<telegram_api::updateNewScheduledMessage> update, bool /*force_apply*/) {
td_->messages_manager_->on_get_message(std::move(update->message_), true, false, true, true, true,
"updateNewScheduledMessage");

View File

@ -281,6 +281,7 @@ class UpdatesManager : public Actor {
void on_update(tl_object_ptr<telegram_api::updateGeoLiveViewed> update, bool /*force_apply*/);
void on_update(tl_object_ptr<telegram_api::updateMessagePoll> update, bool /*force_apply*/);
void on_update(tl_object_ptr<telegram_api::updateMessagePollVote> update, bool /*force_apply*/);
void on_update(tl_object_ptr<telegram_api::updateNewScheduledMessage> update, bool /*force_apply*/);
void on_update(tl_object_ptr<telegram_api::updateDeleteScheduledMessages> update, bool /*force_apply*/);