diff --git a/Telegram/SourceFiles/apiwrap.cpp b/Telegram/SourceFiles/apiwrap.cpp index 67e95940565b2..476fd9aee5e1f 100644 --- a/Telegram/SourceFiles/apiwrap.cpp +++ b/Telegram/SourceFiles/apiwrap.cpp @@ -2064,7 +2064,8 @@ void ApiWrap::saveDraftsToCloud() { ConvertTextTagsToEntities(textWithTags.tags), TextUtilities::ConvertOption::SkipLocal); - history->setSentDraftText(textWithTags.text); + const auto draftText = textWithTags.text; + history->setSentDraftText(draftText); cloudDraft->saveRequestId = request(MTPmessages_SaveDraft( MTP_flags(flags), MTP_int(cloudDraft->msgId), @@ -2072,7 +2073,7 @@ void ApiWrap::saveDraftsToCloud() { MTP_string(textWithTags.text), entities )).done([=](const MTPBool &result, mtpRequestId requestId) { - history->clearSentDraftText(); + history->clearSentDraftText(draftText); if (const auto cloudDraft = history->cloudDraft()) { if (cloudDraft->saveRequestId == requestId) { @@ -2086,7 +2087,7 @@ void ApiWrap::saveDraftsToCloud() { checkQuitPreventFinished(); } }).fail([=](const RPCError &error, mtpRequestId requestId) { - history->clearSentDraftText(); + history->clearSentDraftText(draftText); if (const auto cloudDraft = history->cloudDraft()) { if (cloudDraft->saveRequestId == requestId) { @@ -4042,6 +4043,7 @@ void ApiWrap::sendMessage(MessageToSend &&message) { if (message.clearDraft) { sendFlags |= MTPmessages_SendMessage::Flag::f_clear_draft; history->clearCloudDraft(); + history->setSentDraftText(QString()); } auto messageFromId = channelPost ? 0 : _session->userId(); auto messagePostAuthor = channelPost @@ -4076,7 +4078,10 @@ void ApiWrap::sendMessage(MessageToSend &&message) { sentEntities )).done([=](const MTPUpdates &result) { applyUpdates(result, randomId); - }).fail([=](const RPCError &error) { sendMessageFail(error); + history->clearSentDraftText(QString()); + }).fail([=](const RPCError &error) { + sendMessageFail(error); + history->clearSentDraftText(QString()); }).afterRequest(history->sendRequestId ).send(); } @@ -4141,6 +4146,9 @@ void ApiWrap::sendInlineResult( options.replyTo, messagePostAuthor); + history->clearCloudDraft(); + history->setSentDraftText(QString()); + history->sendRequestId = request(MTPmessages_SendInlineBotResult( MTP_flags(sendFlags), peer->input, @@ -4150,7 +4158,10 @@ void ApiWrap::sendInlineResult( MTP_string(data->getId()) )).done([=](const MTPUpdates &result) { applyUpdates(result, randomId); - }).fail([=](const RPCError &error) { sendMessageFail(error); + history->clearSentDraftText(QString()); + }).fail([=](const RPCError &error) { + sendMessageFail(error); + history->clearSentDraftText(QString()); }).afterRequest(history->sendRequestId ).send(); diff --git a/Telegram/SourceFiles/history/history.cpp b/Telegram/SourceFiles/history/history.cpp index e41800226dccb..00fae37530164 100644 --- a/Telegram/SourceFiles/history/history.cpp +++ b/Telegram/SourceFiles/history/history.cpp @@ -409,9 +409,9 @@ Data::Draft *History::createCloudDraft(Data::Draft *fromDraft) { } bool History::skipCloudDraft(const QString &text, TimeId date) const { - if (_lastSentDraftText && *_lastSentDraftText == text) { + if (date > 0 && date <= _lastSentDraftTime + kSkipCloudDraftsFor) { return true; - } else if (date <= _lastSentDraftTime + kSkipCloudDraftsFor) { + } else if (_lastSentDraftText && *_lastSentDraftText == text) { return true; } return false; @@ -421,8 +421,10 @@ void History::setSentDraftText(const QString &text) { _lastSentDraftText = text; } -void History::clearSentDraftText() { - _lastSentDraftText = base::none; +void History::clearSentDraftText(const QString &text) { + if (_lastSentDraftText && *_lastSentDraftText == text) { + _lastSentDraftText = base::none; + } accumulate_max(_lastSentDraftTime, unixtime()); } diff --git a/Telegram/SourceFiles/history/history.h b/Telegram/SourceFiles/history/history.h index 13eb35ac37e10..460fd9bcc1e4e 100644 --- a/Telegram/SourceFiles/history/history.h +++ b/Telegram/SourceFiles/history/history.h @@ -306,7 +306,7 @@ class History : public Dialogs::Entry { Data::Draft *createCloudDraft(Data::Draft *fromDraft); bool skipCloudDraft(const QString &text, TimeId date) const; void setSentDraftText(const QString &text); - void clearSentDraftText(); + void clearSentDraftText(const QString &text); void setEditDraft(std::unique_ptr &&draft); void clearLocalDraft(); void clearCloudDraft();