Add limit to getPollVoters.
GitOrigin-RevId: 7f782124e111680b3b726685d6633e79f3d3b60f
This commit is contained in:
parent
8ea7e4eccf
commit
8350443093
@ -3440,8 +3440,10 @@ setPollAnswer chat_id:int53 message_id:int53 option_ids:vector<int32> = Ok;
|
|||||||
|
|
||||||
//@description Returns users voted for the specified option in a non-anonymous polls. For the optimal performance the number of returned users is chosen by the library
|
//@description Returns users voted for the specified option in a non-anonymous polls. For the optimal performance the number of returned users is chosen by the library
|
||||||
//@chat_id Identifier of the chat to which the poll belongs @message_id Identifier of the message containing the poll
|
//@chat_id Identifier of the chat to which the poll belongs @message_id Identifier of the message containing the poll
|
||||||
//@option_id 0-based identifier of the answer option @offset Number of users to skip in the result; must be non-negative
|
//@option_id 0-based identifier of the answer option
|
||||||
getPollVoters chat_id:int53 message_id:int53 option_id:int32 offset:int32 = Users;
|
//@offset Number of users to skip in the result; must be non-negative
|
||||||
|
//@limit The maximum number of users to be returned; must be positive and can't be greater than 50. Fewer users may be returned than specified by the limit, even if the end of the voter list has not been reached
|
||||||
|
getPollVoters chat_id:int53 message_id:int53 option_id:int32 offset:int32 limit:int32 = Users;
|
||||||
|
|
||||||
//@description Stops a poll. A poll in a message can be stopped when the message has can_be_edited flag set
|
//@description Stops a poll. A poll in a message can be stopped when the message has can_be_edited flag set
|
||||||
//@chat_id Identifier of the chat to which the poll belongs @message_id Identifier of the message containing the poll @reply_markup The new message reply markup; for bots only
|
//@chat_id Identifier of the chat to which the poll belongs @message_id Identifier of the message containing the poll @reply_markup The new message reply markup; for bots only
|
||||||
|
Binary file not shown.
@ -2826,11 +2826,11 @@ void set_message_content_poll_answer(Td *td, const MessageContent *content, Full
|
|||||||
}
|
}
|
||||||
|
|
||||||
void get_message_content_poll_voters(Td *td, const MessageContent *content, FullMessageId full_message_id,
|
void get_message_content_poll_voters(Td *td, const MessageContent *content, FullMessageId full_message_id,
|
||||||
int32 option_id, int32 offset,
|
int32 option_id, int32 offset, int32 limit,
|
||||||
Promise<std::pair<int32, vector<UserId>>> &&promise) {
|
Promise<std::pair<int32, vector<UserId>>> &&promise) {
|
||||||
CHECK(content->get_type() == MessageContentType::Poll);
|
CHECK(content->get_type() == MessageContentType::Poll);
|
||||||
td->poll_manager_->get_poll_voters(static_cast<const MessagePoll *>(content)->poll_id, full_message_id, option_id,
|
td->poll_manager_->get_poll_voters(static_cast<const MessagePoll *>(content)->poll_id, full_message_id, option_id,
|
||||||
offset, std::move(promise));
|
offset, limit, std::move(promise));
|
||||||
}
|
}
|
||||||
|
|
||||||
void stop_message_content_poll(Td *td, const MessageContent *content, FullMessageId full_message_id,
|
void stop_message_content_poll(Td *td, const MessageContent *content, FullMessageId full_message_id,
|
||||||
|
@ -194,7 +194,7 @@ void set_message_content_poll_answer(Td *td, const MessageContent *content, Full
|
|||||||
vector<int32> &&option_ids, Promise<Unit> &&promise);
|
vector<int32> &&option_ids, Promise<Unit> &&promise);
|
||||||
|
|
||||||
void get_message_content_poll_voters(Td *td, const MessageContent *content, FullMessageId full_message_id,
|
void get_message_content_poll_voters(Td *td, const MessageContent *content, FullMessageId full_message_id,
|
||||||
int32 option_id, int32 offset,
|
int32 option_id, int32 offset, int32 limit,
|
||||||
Promise<std::pair<int32, vector<UserId>>> &&promise);
|
Promise<std::pair<int32, vector<UserId>>> &&promise);
|
||||||
|
|
||||||
void stop_message_content_poll(Td *td, const MessageContent *content, FullMessageId full_message_id,
|
void stop_message_content_poll(Td *td, const MessageContent *content, FullMessageId full_message_id,
|
||||||
|
@ -30122,7 +30122,7 @@ void MessagesManager::set_poll_answer(FullMessageId full_message_id, vector<int3
|
|||||||
set_message_content_poll_answer(td_, m->content.get(), full_message_id, std::move(option_ids), std::move(promise));
|
set_message_content_poll_answer(td_, m->content.get(), full_message_id, std::move(option_ids), std::move(promise));
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessagesManager::get_poll_voters(FullMessageId full_message_id, int32 option_id, int32 offset,
|
void MessagesManager::get_poll_voters(FullMessageId full_message_id, int32 option_id, int32 offset, int32 limit,
|
||||||
Promise<std::pair<int32, vector<UserId>>> &&promise) {
|
Promise<std::pair<int32, vector<UserId>>> &&promise) {
|
||||||
auto m = get_message_force(full_message_id, "get_poll_voters");
|
auto m = get_message_force(full_message_id, "get_poll_voters");
|
||||||
if (m == nullptr) {
|
if (m == nullptr) {
|
||||||
@ -30141,7 +30141,7 @@ void MessagesManager::get_poll_voters(FullMessageId full_message_id, int32 optio
|
|||||||
return promise.set_error(Status::Error(5, "Poll results can't be received"));
|
return promise.set_error(Status::Error(5, "Poll results can't be received"));
|
||||||
}
|
}
|
||||||
|
|
||||||
get_message_content_poll_voters(td_, m->content.get(), full_message_id, option_id, offset, std::move(promise));
|
get_message_content_poll_voters(td_, m->content.get(), full_message_id, option_id, offset, limit, std::move(promise));
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessagesManager::stop_poll(FullMessageId full_message_id, td_api::object_ptr<td_api::ReplyMarkup> &&reply_markup,
|
void MessagesManager::stop_poll(FullMessageId full_message_id, td_api::object_ptr<td_api::ReplyMarkup> &&reply_markup,
|
||||||
|
@ -803,7 +803,7 @@ class MessagesManager : public Actor {
|
|||||||
|
|
||||||
void set_poll_answer(FullMessageId full_message_id, vector<int32> &&option_ids, Promise<Unit> &&promise);
|
void set_poll_answer(FullMessageId full_message_id, vector<int32> &&option_ids, Promise<Unit> &&promise);
|
||||||
|
|
||||||
void get_poll_voters(FullMessageId full_message_id, int32 option_id, int32 offset,
|
void get_poll_voters(FullMessageId full_message_id, int32 option_id, int32 offset, int32 limit,
|
||||||
Promise<std::pair<int32, vector<UserId>>> &&promise);
|
Promise<std::pair<int32, vector<UserId>>> &&promise);
|
||||||
|
|
||||||
void stop_poll(FullMessageId full_message_id, td_api::object_ptr<td_api::ReplyMarkup> &&reply_markup,
|
void stop_poll(FullMessageId full_message_id, td_api::object_ptr<td_api::ReplyMarkup> &&reply_markup,
|
||||||
|
@ -839,13 +839,19 @@ PollManager::PollOptionVoters &PollManager::get_poll_option_voters(const Poll *p
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PollManager::get_poll_voters(PollId poll_id, FullMessageId full_message_id, int32 option_id, int32 offset,
|
void PollManager::get_poll_voters(PollId poll_id, FullMessageId full_message_id, int32 option_id, int32 offset,
|
||||||
Promise<std::pair<int32, vector<UserId>>> &&promise) {
|
int32 limit, Promise<std::pair<int32, vector<UserId>>> &&promise) {
|
||||||
if (is_local_poll_id(poll_id)) {
|
if (is_local_poll_id(poll_id)) {
|
||||||
return promise.set_error(Status::Error(400, "Poll results can't be received"));
|
return promise.set_error(Status::Error(400, "Poll results can't be received"));
|
||||||
}
|
}
|
||||||
if (offset < 0) {
|
if (offset < 0) {
|
||||||
return promise.set_error(Status::Error(400, "Invalid offset specified"));
|
return promise.set_error(Status::Error(400, "Invalid offset specified"));
|
||||||
}
|
}
|
||||||
|
if (limit <= 0) {
|
||||||
|
return promise.set_error(Status::Error(400, "Parameter limit must be positive"));
|
||||||
|
}
|
||||||
|
if (limit > MAX_GET_POLL_VOTERS) {
|
||||||
|
limit = MAX_GET_POLL_VOTERS;
|
||||||
|
}
|
||||||
|
|
||||||
auto poll = get_poll(poll_id);
|
auto poll = get_poll(poll_id);
|
||||||
CHECK(poll != nullptr);
|
CHECK(poll != nullptr);
|
||||||
@ -870,7 +876,7 @@ void PollManager::get_poll_voters(PollId poll_id, FullMessageId full_message_id,
|
|||||||
}
|
}
|
||||||
if (offset < cur_offset) {
|
if (offset < cur_offset) {
|
||||||
vector<UserId> result;
|
vector<UserId> result;
|
||||||
for (int32 i = offset; i != cur_offset && i - offset < MAX_GET_POLL_VOTERS; i++) {
|
for (int32 i = offset; i != cur_offset && i - offset < limit; i++) {
|
||||||
result.push_back(voters.voter_user_ids[i]);
|
result.push_back(voters.voter_user_ids[i]);
|
||||||
}
|
}
|
||||||
return promise.set_value({poll->options[option_id].voter_count, std::move(result)});
|
return promise.set_value({poll->options[option_id].voter_count, std::move(result)});
|
||||||
@ -885,16 +891,15 @@ void PollManager::get_poll_voters(PollId poll_id, FullMessageId full_message_id,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto query_promise = PromiseCreator::lambda([actor_id = actor_id(this), poll_id, option_id](
|
auto query_promise = PromiseCreator::lambda([actor_id = actor_id(this), poll_id, option_id, limit](
|
||||||
Result<tl_object_ptr<telegram_api::messages_votesList>> &&result) {
|
Result<tl_object_ptr<telegram_api::messages_votesList>> &&result) {
|
||||||
send_closure(actor_id, &PollManager::on_get_poll_voters, poll_id, option_id, std::move(result));
|
send_closure(actor_id, &PollManager::on_get_poll_voters, poll_id, option_id, limit, std::move(result));
|
||||||
});
|
});
|
||||||
td_->create_handler<GetPollVotersQuery>(std::move(query_promise))
|
td_->create_handler<GetPollVotersQuery>(std::move(query_promise))
|
||||||
->send(poll_id, full_message_id, BufferSlice(poll->options[option_id].data), voters.next_offset,
|
->send(poll_id, full_message_id, BufferSlice(poll->options[option_id].data), voters.next_offset, max(limit, 15));
|
||||||
MAX_GET_POLL_VOTERS);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PollManager::on_get_poll_voters(PollId poll_id, int32 option_id,
|
void PollManager::on_get_poll_voters(PollId poll_id, int32 option_id, int32 limit,
|
||||||
Result<tl_object_ptr<telegram_api::messages_votesList>> &&result) {
|
Result<tl_object_ptr<telegram_api::messages_votesList>> &&result) {
|
||||||
auto poll = get_poll(poll_id);
|
auto poll = get_poll(poll_id);
|
||||||
CHECK(poll != nullptr);
|
CHECK(poll != nullptr);
|
||||||
@ -961,6 +966,9 @@ void PollManager::on_get_poll_voters(PollId poll_id, int32 option_id,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
voters.voter_user_ids.insert(voters.voter_user_ids.end(), user_ids.begin(), user_ids.end());
|
voters.voter_user_ids.insert(voters.voter_user_ids.end(), user_ids.begin(), user_ids.end());
|
||||||
|
if (static_cast<int32>(user_ids.size()) > limit) {
|
||||||
|
user_ids.resize(limit);
|
||||||
|
}
|
||||||
|
|
||||||
for (auto &promise : promises) {
|
for (auto &promise : promises) {
|
||||||
promise.set_value({vote_list->count_, vector<UserId>(user_ids)});
|
promise.set_value({vote_list->count_, vector<UserId>(user_ids)});
|
||||||
|
@ -58,7 +58,7 @@ class PollManager : public Actor {
|
|||||||
void set_poll_answer(PollId poll_id, FullMessageId full_message_id, vector<int32> &&option_ids,
|
void set_poll_answer(PollId poll_id, FullMessageId full_message_id, vector<int32> &&option_ids,
|
||||||
Promise<Unit> &&promise);
|
Promise<Unit> &&promise);
|
||||||
|
|
||||||
void get_poll_voters(PollId poll_id, FullMessageId full_message_id, int32 option_id, int32 offset,
|
void get_poll_voters(PollId poll_id, FullMessageId full_message_id, int32 option_id, int32 offset, int32 limit,
|
||||||
Promise<std::pair<int32, vector<UserId>>> &&promise);
|
Promise<std::pair<int32, vector<UserId>>> &&promise);
|
||||||
|
|
||||||
void stop_poll(PollId poll_id, FullMessageId full_message_id, unique_ptr<ReplyMarkup> &&reply_markup,
|
void stop_poll(PollId poll_id, FullMessageId full_message_id, unique_ptr<ReplyMarkup> &&reply_markup,
|
||||||
@ -124,7 +124,7 @@ class PollManager : public Actor {
|
|||||||
bool was_invalidated = false; // the list needs to be invalidated when voters are changed
|
bool was_invalidated = false; // the list needs to be invalidated when voters are changed
|
||||||
};
|
};
|
||||||
|
|
||||||
static constexpr int32 MAX_GET_POLL_VOTERS = 20; // server side limit
|
static constexpr int32 MAX_GET_POLL_VOTERS = 50; // server side limit
|
||||||
|
|
||||||
class SetPollAnswerLogEvent;
|
class SetPollAnswerLogEvent;
|
||||||
class StopPollLogEvent;
|
class StopPollLogEvent;
|
||||||
@ -179,7 +179,7 @@ class PollManager : public Actor {
|
|||||||
|
|
||||||
PollOptionVoters &get_poll_option_voters(const Poll *poll, PollId poll_id, int32 option_id);
|
PollOptionVoters &get_poll_option_voters(const Poll *poll, PollId poll_id, int32 option_id);
|
||||||
|
|
||||||
void on_get_poll_voters(PollId poll_id, int32 option_id,
|
void on_get_poll_voters(PollId poll_id, int32 option_id, int32 limit,
|
||||||
Result<tl_object_ptr<telegram_api::messages_votesList>> &&result);
|
Result<tl_object_ptr<telegram_api::messages_votesList>> &&result);
|
||||||
|
|
||||||
void do_stop_poll(PollId poll_id, FullMessageId full_message_id, unique_ptr<ReplyMarkup> &&reply_markup,
|
void do_stop_poll(PollId poll_id, FullMessageId full_message_id, unique_ptr<ReplyMarkup> &&reply_markup,
|
||||||
|
@ -7265,7 +7265,7 @@ void Td::on_request(uint64 id, td_api::getPollVoters &request) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
messages_manager_->get_poll_voters({DialogId(request.chat_id_), MessageId(request.message_id_)}, request.option_id_,
|
messages_manager_->get_poll_voters({DialogId(request.chat_id_), MessageId(request.message_id_)}, request.option_id_,
|
||||||
request.offset_, std::move(query_promise));
|
request.offset_, request.limit_, std::move(query_promise));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Td::on_request(uint64 id, td_api::stopPoll &request) {
|
void Td::on_request(uint64 id, td_api::stopPoll &request) {
|
||||||
|
@ -3494,12 +3494,15 @@ class CliClient final : public Actor {
|
|||||||
string message_id;
|
string message_id;
|
||||||
string option_id;
|
string option_id;
|
||||||
string offset;
|
string offset;
|
||||||
|
string limit;
|
||||||
|
|
||||||
std::tie(chat_id, args) = split(args);
|
std::tie(chat_id, args) = split(args);
|
||||||
std::tie(message_id, args) = split(args);
|
std::tie(message_id, args) = split(args);
|
||||||
std::tie(option_id, offset) = split(args);
|
std::tie(option_id, args) = split(args);
|
||||||
|
std::tie(offset, limit) = split(args);
|
||||||
send_request(td_api::make_object<td_api::getPollVoters>(as_chat_id(chat_id), as_message_id(message_id),
|
send_request(td_api::make_object<td_api::getPollVoters>(as_chat_id(chat_id), as_message_id(message_id),
|
||||||
to_integer<int32>(option_id), to_integer<int32>(offset)));
|
to_integer<int32>(option_id), to_integer<int32>(offset),
|
||||||
|
to_integer<int32>(limit)));
|
||||||
} else if (op == "stoppoll") {
|
} else if (op == "stoppoll") {
|
||||||
string chat_id;
|
string chat_id;
|
||||||
string message_id;
|
string message_id;
|
||||||
|
Reference in New Issue
Block a user