Add reply_markup to stopPoll.

GitOrigin-RevId: 08cf68d42ecc6c25cd8ec7146fb7e3b1856a7207
This commit is contained in:
levlam 2019-04-12 02:10:33 +03:00
parent 542c4d374d
commit af39698707
11 changed files with 47 additions and 24 deletions

View File

@ -3030,8 +3030,8 @@ getJsonString json_value:JsonValue = Text;
setPollAnswer chat_id:int53 message_id:int53 option_ids:vector<int32> = Ok;
//@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
stopPoll chat_id:int53 message_id:int53 = Ok;
//@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
stopPoll chat_id:int53 message_id:int53 reply_markup:ReplyMarkup = Ok;
//@description Sends an inline query to a bot and returns its results. Returns an error with code 502 if the bot fails to answer the query before the query timeout expires @bot_user_id The identifier of the target bot

Binary file not shown.

View File

@ -2693,9 +2693,10 @@ void set_message_content_poll_answer(Td *td, MessageContent *content, FullMessag
}
void stop_message_content_poll(Td *td, MessageContent *content, FullMessageId full_message_id,
Promise<Unit> &&promise) {
unique_ptr<ReplyMarkup> &&reply_markup, Promise<Unit> &&promise) {
CHECK(content->get_type() == MessageContentType::Poll);
td->poll_manager_->stop_poll(static_cast<MessagePoll *>(content)->poll_id, full_message_id, std::move(promise));
td->poll_manager_->stop_poll(static_cast<MessagePoll *>(content)->poll_id, full_message_id, std::move(reply_markup),
std::move(promise));
}
static void merge_location_access_hash(const Location &first, const Location &second) {

View File

@ -186,7 +186,8 @@ void set_message_content_web_page_id(MessageContent *content, WebPageId web_page
void set_message_content_poll_answer(Td *td, MessageContent *content, FullMessageId full_message_id,
vector<int32> &&option_ids, Promise<Unit> &&promise);
void stop_message_content_poll(Td *td, MessageContent *content, FullMessageId full_message_id, Promise<Unit> &&promise);
void stop_message_content_poll(Td *td, MessageContent *content, FullMessageId full_message_id,
unique_ptr<ReplyMarkup> &&reply_markup, Promise<Unit> &&promise);
void merge_message_contents(Td *td, const MessageContent *old_content, MessageContent *new_content,
bool need_message_changed_warning, DialogId dialog_id, bool need_merge_files,

View File

@ -25870,7 +25870,8 @@ 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));
}
void MessagesManager::stop_poll(FullMessageId full_message_id, Promise<Unit> &&promise) {
void MessagesManager::stop_poll(FullMessageId full_message_id, td_api::object_ptr<td_api::ReplyMarkup> &&reply_markup,
Promise<Unit> &&promise) {
auto m = get_message_force(full_message_id, "stop_poll");
if (m == nullptr) {
return promise.set_error(Status::Error(5, "Message not found"));
@ -25891,7 +25892,14 @@ void MessagesManager::stop_poll(FullMessageId full_message_id, Promise<Unit> &&p
return promise.set_error(Status::Error(5, "Poll can't be stopped"));
}
stop_message_content_poll(td_, m->content.get(), full_message_id, std::move(promise));
auto r_new_reply_markup = get_reply_markup(std::move(reply_markup), td_->auth_manager_->is_bot(), true, false,
!is_broadcast_channel(full_message_id.get_dialog_id()));
if (r_new_reply_markup.is_error()) {
return promise.set_error(r_new_reply_markup.move_as_error());
}
stop_message_content_poll(td_, m->content.get(), full_message_id, r_new_reply_markup.move_as_ok(),
std::move(promise));
}
Result<ServerMessageId> MessagesManager::get_invoice_message_id(FullMessageId full_message_id) {

View File

@ -734,7 +734,8 @@ class MessagesManager : public Actor {
void set_poll_answer(FullMessageId full_message_id, vector<int32> &&option_ids, Promise<Unit> &&promise);
void stop_poll(FullMessageId full_message_id, Promise<Unit> &&promise);
void stop_poll(FullMessageId full_message_id, td_api::object_ptr<td_api::ReplyMarkup> &&reply_markup,
Promise<Unit> &&promise);
void get_payment_form(FullMessageId full_message_id, Promise<tl_object_ptr<td_api::paymentForm>> &&promise);

View File

@ -134,7 +134,7 @@ class StopPollActor : public NetActorOnce {
explicit StopPollActor(Promise<Unit> &&promise) : promise_(std::move(promise)) {
}
void send(FullMessageId full_message_id) {
void send(FullMessageId full_message_id, unique_ptr<ReplyMarkup> &&reply_markup) {
dialog_id_ = full_message_id.get_dialog_id();
auto input_peer = td->messages_manager_->get_input_peer(dialog_id_, AccessRights::Edit);
if (input_peer == nullptr) {
@ -142,13 +142,19 @@ class StopPollActor : public NetActorOnce {
return on_error(0, Status::Error(400, "Can't access the chat"));
}
int32 flags = telegram_api::messages_editMessage::MEDIA_MASK;
auto input_reply_markup = get_input_reply_markup(reply_markup);
if (input_reply_markup != nullptr) {
flags |= telegram_api::messages_editMessage::REPLY_MARKUP_MASK;
}
auto message_id = full_message_id.get_message_id().get_server_message_id().get();
auto poll = telegram_api::make_object<telegram_api::poll>();
poll->flags_ |= telegram_api::poll::CLOSED_MASK;
auto input_media = telegram_api::make_object<telegram_api::inputMediaPoll>(std::move(poll));
auto query = G()->net_query_creator().create(create_storer(telegram_api::messages_editMessage(
telegram_api::messages_editMessage::MEDIA_MASK, false /*ignored*/, std::move(input_peer), message_id, string(),
std::move(input_media), nullptr, vector<tl_object_ptr<telegram_api::MessageEntity>>())));
flags, false /*ignored*/, std::move(input_peer), message_id, string(), std::move(input_media),
std::move(input_reply_markup), vector<tl_object_ptr<telegram_api::MessageEntity>>())));
auto sequence_id = -1;
send_closure(td->messages_manager_->sequence_dispatcher_, &MultiSequenceDispatcher::send_with_callback,
std::move(query), actor_shared(this), sequence_id);
@ -682,7 +688,8 @@ void PollManager::on_set_poll_answer(PollId poll_id, uint64 generation,
}
}
void PollManager::stop_poll(PollId poll_id, FullMessageId full_message_id, Promise<Unit> &&promise) {
void PollManager::stop_poll(PollId poll_id, FullMessageId full_message_id, unique_ptr<ReplyMarkup> &&reply_markup,
Promise<Unit> &&promise) {
if (is_local_poll_id(poll_id)) {
LOG(ERROR) << "Receive local " << poll_id << " from " << full_message_id << " in stop_poll";
stop_local_poll(poll_id);
@ -702,7 +709,7 @@ void PollManager::stop_poll(PollId poll_id, FullMessageId full_message_id, Promi
notify_on_poll_update(poll_id);
save_poll(poll, poll_id);
do_stop_poll(poll_id, full_message_id, 0, std::move(promise));
do_stop_poll(poll_id, full_message_id, std::move(reply_markup), 0, std::move(promise));
}
class PollManager::StopPollLogEvent {
@ -723,10 +730,10 @@ class PollManager::StopPollLogEvent {
}
};
void PollManager::do_stop_poll(PollId poll_id, FullMessageId full_message_id, uint64 logevent_id,
Promise<Unit> &&promise) {
void PollManager::do_stop_poll(PollId poll_id, FullMessageId full_message_id, unique_ptr<ReplyMarkup> &&reply_markup,
uint64 logevent_id, Promise<Unit> &&promise) {
LOG(INFO) << "Stop " << poll_id << " from " << full_message_id;
if (logevent_id == 0 && G()->parameters().use_message_db) {
if (logevent_id == 0 && G()->parameters().use_message_db && reply_markup == nullptr) {
StopPollLogEvent logevent{poll_id, full_message_id};
auto storer = LogEventStorerImpl<StopPollLogEvent>(logevent);
logevent_id = binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::StopPoll, storer);
@ -736,7 +743,8 @@ void PollManager::do_stop_poll(PollId poll_id, FullMessageId full_message_id, ui
CHECK(is_inserted);
auto new_promise = get_erase_logevent_promise(logevent_id, std::move(promise));
send_closure(td_->create_net_actor<StopPollActor>(std::move(new_promise)), &StopPollActor::send, full_message_id);
send_closure(td_->create_net_actor<StopPollActor>(std::move(new_promise)), &StopPollActor::send, full_message_id,
std::move(reply_markup));
}
void PollManager::stop_local_poll(PollId poll_id) {
@ -1010,7 +1018,7 @@ void PollManager::on_binlog_events(vector<BinlogEvent> &&events) {
td_->messages_manager_->add_dialog_dependencies(dependencies, dialog_id);
td_->messages_manager_->resolve_dependencies_force(dependencies);
do_stop_poll(log_event.poll_id_, log_event.full_message_id_, event.id_, Auto());
do_stop_poll(log_event.poll_id_, log_event.full_message_id_, nullptr, event.id_, Auto());
break;
}
default:

View File

@ -9,6 +9,7 @@
#include "td/telegram/MessageId.h"
#include "td/telegram/net/NetQuery.h"
#include "td/telegram/PollId.h"
#include "td/telegram/ReplyMarkup.h"
#include "td/telegram/td_api.h"
#include "td/telegram/telegram_api.h"
@ -53,7 +54,8 @@ class PollManager : public Actor {
void set_poll_answer(PollId poll_id, FullMessageId full_message_id, vector<int32> &&option_ids,
Promise<Unit> &&promise);
void stop_poll(PollId poll_id, FullMessageId full_message_id, Promise<Unit> &&promise);
void stop_poll(PollId poll_id, FullMessageId full_message_id, unique_ptr<ReplyMarkup> &&reply_markup,
Promise<Unit> &&promise);
void stop_local_poll(PollId poll_id);
@ -146,7 +148,8 @@ class PollManager : public Actor {
void on_set_poll_answer(PollId poll_id, uint64 generation, Result<tl_object_ptr<telegram_api::Updates>> &&result);
void do_stop_poll(PollId poll_id, FullMessageId full_message_id, uint64 logevent_id, Promise<Unit> &&promise);
void do_stop_poll(PollId poll_id, FullMessageId full_message_id, unique_ptr<ReplyMarkup> &&reply_markup,
uint64 logevent_id, Promise<Unit> &&promise);
MultiTimeout update_poll_timeout_{"UpdatePollTimeout"};

View File

@ -6638,9 +6638,10 @@ void Td::on_request(uint64 id, td_api::setPollAnswer &request) {
std::move(request.option_ids_), std::move(promise));
}
void Td::on_request(uint64 id, const td_api::stopPoll &request) {
void Td::on_request(uint64 id, td_api::stopPoll &request) {
CREATE_OK_REQUEST_PROMISE();
messages_manager_->stop_poll({DialogId(request.chat_id_), MessageId(request.message_id_)}, std::move(promise));
messages_manager_->stop_poll({DialogId(request.chat_id_), MessageId(request.message_id_)},
std::move(request.reply_markup_), std::move(promise));
}
void Td::on_request(uint64 id, td_api::getInlineQueryResults &request) {

View File

@ -851,7 +851,7 @@ class Td final : public NetQueryCallback {
void on_request(uint64 id, td_api::setPollAnswer &request);
void on_request(uint64 id, const td_api::stopPoll &request);
void on_request(uint64 id, td_api::stopPoll &request);
void on_request(uint64 id, td_api::getInlineQueryResults &request);

View File

@ -3253,7 +3253,7 @@ class CliClient final : public Actor {
string message_id;
std::tie(chat_id, message_id) = split(args);
send_request(td_api::make_object<td_api::stopPoll>(as_chat_id(chat_id), as_message_id(message_id)));
send_request(td_api::make_object<td_api::stopPoll>(as_chat_id(chat_id), as_message_id(message_id), nullptr));
} else {
op_not_found_count++;
}