Fixed sending polls as reply to other messages.

Fixes #5550.
This commit is contained in:
23rd 2019-02-17 14:43:46 +03:00 committed by John Preston
parent bdfb9b4143
commit 193e454fd4
4 changed files with 25 additions and 1 deletions

View file

@ -5437,6 +5437,11 @@ void ApiWrap::createPoll(
if (options.replyTo) {
sendFlags |= MTPmessages_SendMedia::Flag::f_reply_to_msg_id;
}
if (options.clearDraft) {
sendFlags |= MTPmessages_SendMedia::Flag::f_clear_draft;
history->clearLocalDraft();
history->clearCloudDraft();
}
const auto channelPost = peer->isChannel() && !peer->isMegagroup();
const auto silentPost = channelPost
&& _session->data().notifySilentPosts(peer);

View file

@ -1118,6 +1118,15 @@ bool MainWidget::historyInSelectionMode() const {
return _history->inSelectionMode();
}
MsgId MainWidget::currentReplyToIdFor(not_null<History*> history) const {
if (_history->history() == history) {
return _history->replyToId();
} else if (const auto localDraft = history->localDraft()) {
return localDraft->msgId;
}
return 0;
}
void MainWidget::sendBotCommand(PeerData *peer, UserData *bot, const QString &cmd, MsgId replyTo) {
_history->sendBotCommand(peer, bot, cmd, replyTo);
}

View file

@ -217,6 +217,8 @@ public:
TimeMs highlightStartTime(not_null<const HistoryItem*> item) const;
bool historyInSelectionMode() const;
MsgId currentReplyToIdFor(not_null<History*> history) const;
void sendBotCommand(PeerData *peer, UserData *bot, const QString &cmd, MsgId replyTo);
void hideSingleUseKeyboard(PeerData *peer, MsgId replyTo);
bool insertBotCommand(const QString &cmd);

View file

@ -35,6 +35,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_poll.h"
#include "data/data_channel.h"
#include "data/data_chat.h"
#include "data/data_drafts.h"
#include "data/data_user.h"
#include "dialogs/dialogs_key.h"
@ -636,7 +637,14 @@ void PeerMenuCreatePoll(not_null<PeerData*> peer) {
if (std::exchange(*lock, true)) {
return;
}
const auto options = ApiWrap::SendOptions(peer->owner().history(peer));
auto options = ApiWrap::SendOptions(peer->owner().history(peer));
if (const auto id = App::main()->currentReplyToIdFor(options.history)) {
options.replyTo = id;
}
if (const auto localDraft = options.history->localDraft()) {
options.clearDraft = localDraft->textWithTags.text.isEmpty();
}
Auth().api().createPoll(result, options, crl::guard(box, [=] {
box->closeBox();
}), crl::guard(box, [=](const RPCError &error) {