Add support for recent poll voters.
GitOrigin-RevId: f4260d87ae4a22d56b2024c07713ceeb37203895
This commit is contained in:
parent
a7501e1582
commit
f2211527db
@ -268,8 +268,8 @@ game id:int64 short_name:string title:string text:formattedText description:stri
|
||||
|
||||
//@description Describes a poll @id Unique poll identifier @question Poll question, 1-255 characters @options List of poll answer options
|
||||
//@total_voter_count Total number of voters, participating in the poll @is_closed True, if the poll is closed
|
||||
//@is_anonymous True, if the poll is anonymous @type Type of the poll
|
||||
poll id:int64 question:string options:vector<pollOption> total_voter_count:int32 is_closed:Bool is_anonymous:Bool type:PollType = Poll;
|
||||
//@is_anonymous True, if the poll is anonymous @recent_voter_user_ids User identifiers of recent voters, if the poll is non-anonymous @type Type of the poll
|
||||
poll id:int64 question:string options:vector<pollOption> total_voter_count:int32 is_closed:Bool is_anonymous:Bool recent_voter_user_ids:vector<int32> type:PollType = Poll;
|
||||
|
||||
|
||||
//@description Describes a user profile photo @id Photo identifier; 0 for an empty photo. Can be used to find a photo in a list of userProfilePhotos
|
||||
|
Binary file not shown.
@ -12721,8 +12721,8 @@ tl_object_ptr<td_api::user> ContactsManager::get_user_object(UserId user_id, con
|
||||
u->is_received, std::move(type), u->language_code);
|
||||
}
|
||||
|
||||
vector<int32> ContactsManager::get_user_ids_object(const vector<UserId> &user_ids) const {
|
||||
return transform(user_ids, [this](UserId user_id) { return get_user_id_object(user_id, "get_user_ids_object"); });
|
||||
vector<int32> ContactsManager::get_user_ids_object(const vector<UserId> &user_ids, const char *source) const {
|
||||
return transform(user_ids, [this, source](UserId user_id) { return get_user_id_object(user_id, source); });
|
||||
}
|
||||
|
||||
tl_object_ptr<td_api::users> ContactsManager::get_users_object(int32 total_count,
|
||||
@ -12730,7 +12730,7 @@ tl_object_ptr<td_api::users> ContactsManager::get_users_object(int32 total_count
|
||||
if (total_count == -1) {
|
||||
total_count = narrow_cast<int32>(user_ids.size());
|
||||
}
|
||||
return td_api::make_object<td_api::users>(total_count, get_user_ids_object(user_ids));
|
||||
return td_api::make_object<td_api::users>(total_count, get_user_ids_object(user_ids, "get_users_object"));
|
||||
}
|
||||
|
||||
tl_object_ptr<td_api::userFullInfo> ContactsManager::get_user_full_info_object(UserId user_id) const {
|
||||
@ -12961,7 +12961,7 @@ tl_object_ptr<td_api::chatInviteLinkInfo> ContactsManager::get_chat_invite_link_
|
||||
invite_link_photo = as_dialog_photo(invite_link_info->photo);
|
||||
photo = &invite_link_photo;
|
||||
participant_count = invite_link_info->participant_count;
|
||||
member_user_ids = get_user_ids_object(invite_link_info->participant_user_ids);
|
||||
member_user_ids = get_user_ids_object(invite_link_info->participant_user_ids, "get_chat_invite_link_info_object");
|
||||
is_public = invite_link_info->is_public;
|
||||
|
||||
if (invite_link_info->is_chat) {
|
||||
|
@ -485,7 +485,7 @@ class ContactsManager : public Actor {
|
||||
|
||||
tl_object_ptr<td_api::user> get_user_object(UserId user_id) const;
|
||||
|
||||
vector<int32> get_user_ids_object(const vector<UserId> &user_ids) const;
|
||||
vector<int32> get_user_ids_object(const vector<UserId> &user_ids, const char *source) const;
|
||||
|
||||
tl_object_ptr<td_api::users> get_users_object(int32 total_count, const vector<UserId> &user_ids) const;
|
||||
|
||||
|
@ -4501,7 +4501,7 @@ tl_object_ptr<td_api::MessageContent> get_message_content_object(const MessageCo
|
||||
case MessageContentType::ChatCreate: {
|
||||
const MessageChatCreate *m = static_cast<const MessageChatCreate *>(content);
|
||||
return make_tl_object<td_api::messageBasicGroupChatCreate>(
|
||||
m->title, td->contacts_manager_->get_user_ids_object(m->participant_user_ids));
|
||||
m->title, td->contacts_manager_->get_user_ids_object(m->participant_user_ids, "MessageChatCreate"));
|
||||
}
|
||||
case MessageContentType::ChatChangeTitle: {
|
||||
const MessageChatChangeTitle *m = static_cast<const MessageChatChangeTitle *>(content);
|
||||
@ -4517,7 +4517,8 @@ tl_object_ptr<td_api::MessageContent> get_message_content_object(const MessageCo
|
||||
return make_tl_object<td_api::messageUnsupported>();
|
||||
case MessageContentType::ChatAddUsers: {
|
||||
const MessageChatAddUsers *m = static_cast<const MessageChatAddUsers *>(content);
|
||||
return make_tl_object<td_api::messageChatAddMembers>(td->contacts_manager_->get_user_ids_object(m->user_ids));
|
||||
return make_tl_object<td_api::messageChatAddMembers>(
|
||||
td->contacts_manager_->get_user_ids_object(m->user_ids, "MessageChatAddUsers"));
|
||||
}
|
||||
case MessageContentType::ChatJoinedByLink:
|
||||
return make_tl_object<td_api::messageChatJoinByLink>();
|
||||
|
@ -8,6 +8,7 @@
|
||||
|
||||
#include "td/telegram/AccessRights.h"
|
||||
#include "td/telegram/AuthManager.h"
|
||||
#include "td/telegram/ContactsManager.h"
|
||||
#include "td/telegram/Dependencies.h"
|
||||
#include "td/telegram/DialogId.h"
|
||||
#include "td/telegram/Global.h"
|
||||
@ -287,6 +288,9 @@ void PollManager::on_load_poll_from_database(PollId poll_id, string value) {
|
||||
if (status.is_error()) {
|
||||
LOG(FATAL) << status << ": " << format::as_hex_dump<4>(Slice(value));
|
||||
}
|
||||
for (auto &user_id : result->recent_voter_user_ids) {
|
||||
td_->contacts_manager_->have_user_force(user_id);
|
||||
}
|
||||
polls_[poll_id] = std::move(result);
|
||||
}
|
||||
}
|
||||
@ -480,8 +484,10 @@ td_api::object_ptr<td_api::poll> PollManager::get_poll_object(PollId poll_id, co
|
||||
poll_type = td_api::make_object<td_api::pollTypeRegular>(poll->allow_multiple_answers);
|
||||
}
|
||||
|
||||
return td_api::make_object<td_api::poll>(poll_id.get(), poll->question, std::move(poll_options), total_voter_count,
|
||||
poll->is_closed, poll->is_anonymous, std::move(poll_type));
|
||||
return td_api::make_object<td_api::poll>(
|
||||
poll_id.get(), poll->question, std::move(poll_options), total_voter_count, poll->is_closed, poll->is_anonymous,
|
||||
td_->contacts_manager_->get_user_ids_object(poll->recent_voter_user_ids, "get_poll_object"),
|
||||
std::move(poll_type));
|
||||
}
|
||||
|
||||
telegram_api::object_ptr<telegram_api::pollAnswer> PollManager::get_input_poll_option(const PollOption &poll_option) {
|
||||
@ -1069,6 +1075,23 @@ PollId PollManager::on_get_poll(PollId poll_id, tl_object_ptr<telegram_api::poll
|
||||
} else if (correct_option_id != -1) {
|
||||
LOG(ERROR) << "Receive correct option " << correct_option_id << " in quiz " << poll_id;
|
||||
}
|
||||
vector<UserId> recent_voter_user_ids;
|
||||
for (auto &user_id_int : poll_results->recent_voters_) {
|
||||
UserId user_id(user_id_int);
|
||||
if (user_id.is_valid()) {
|
||||
recent_voter_user_ids.push_back(user_id);
|
||||
} else {
|
||||
LOG(ERROR) << "Receive " << user_id << " as recent voter in " << poll_id;
|
||||
}
|
||||
}
|
||||
if (poll->is_anonymous && !recent_voter_user_ids.empty()) {
|
||||
LOG(ERROR) << "Receive anonymous " << poll_id << " with recent voters " << recent_voter_user_ids;
|
||||
recent_voter_user_ids.clear();
|
||||
}
|
||||
if (recent_voter_user_ids != poll->recent_voter_user_ids) {
|
||||
poll->recent_voter_user_ids = std::move(recent_voter_user_ids);
|
||||
is_changed = true;
|
||||
}
|
||||
|
||||
if (!td_->auth_manager_->is_bot() && !poll->is_closed) {
|
||||
auto timeout = get_polling_timeout();
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "td/telegram/ReplyMarkup.h"
|
||||
#include "td/telegram/td_api.h"
|
||||
#include "td/telegram/telegram_api.h"
|
||||
#include "td/telegram/UserId.h"
|
||||
|
||||
#include "td/actor/actor.h"
|
||||
#include "td/actor/PromiseFuture.h"
|
||||
@ -95,6 +96,7 @@ class PollManager : public Actor {
|
||||
struct Poll {
|
||||
string question;
|
||||
vector<PollOption> options;
|
||||
vector<UserId> recent_voter_user_ids;
|
||||
int32 total_voter_count = 0;
|
||||
int32 correct_option_id = -1;
|
||||
bool is_anonymous = true;
|
||||
|
@ -43,11 +43,13 @@ 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();
|
||||
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);
|
||||
END_STORE_FLAGS();
|
||||
|
||||
store(question, storer);
|
||||
@ -56,17 +58,22 @@ void PollManager::Poll::store(StorerT &storer) const {
|
||||
if (is_quiz) {
|
||||
store(correct_option_id, storer);
|
||||
}
|
||||
if (has_recent_voters) {
|
||||
store(recent_voter_user_ids, storer);
|
||||
}
|
||||
}
|
||||
|
||||
template <class ParserT>
|
||||
void PollManager::Poll::parse(ParserT &parser) {
|
||||
using ::td::parse;
|
||||
bool is_public;
|
||||
bool has_recent_voters;
|
||||
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);
|
||||
END_PARSE_FLAGS();
|
||||
is_anonymous = !is_public;
|
||||
|
||||
@ -79,6 +86,9 @@ void PollManager::Poll::parse(ParserT &parser) {
|
||||
parser.set_error("Wrong correct_option_id");
|
||||
}
|
||||
}
|
||||
if (has_recent_voters) {
|
||||
parse(recent_voter_user_ids, parser);
|
||||
}
|
||||
}
|
||||
|
||||
template <class StorerT>
|
||||
|
Reference in New Issue
Block a user