Skip draft updates while sending with clear_draft.

I hope fixes #4845, fixes #4852, fixes #4861.
This commit is contained in:
John Preston 2018-06-26 16:59:05 +01:00
parent 33095966af
commit 372cf275e0
3 changed files with 23 additions and 10 deletions

View File

@ -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();

View File

@ -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());
}

View File

@ -306,7 +306,7 @@ public:
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<Data::Draft> &&draft);
void clearLocalDraft();
void clearCloudDraft();