From 252a0d6581a79583b6bf06036b47e214e8ab09e5 Mon Sep 17 00:00:00 2001 From: RadRussianRus Date: Tue, 30 Mar 2021 16:32:09 +0300 Subject: [PATCH] Fix mixed order of messages sent with unquoted forwarding --- Telegram/SourceFiles/api/api_sending.cpp | 6 +-- Telegram/SourceFiles/api/api_sending.h | 2 +- Telegram/SourceFiles/apiwrap.cpp | 65 +++++++++++++----------- 3 files changed, 40 insertions(+), 33 deletions(-) diff --git a/Telegram/SourceFiles/api/api_sending.cpp b/Telegram/SourceFiles/api/api_sending.cpp index 0755e7c7f..ebd0be1c7 100644 --- a/Telegram/SourceFiles/api/api_sending.cpp +++ b/Telegram/SourceFiles/api/api_sending.cpp @@ -231,7 +231,7 @@ void SendExistingPhoto( bool SendDice( Api::MessageToSend &message, - Fn doneCallback, + Fn doneCallback, bool forwarding) { const auto full = message.textWithTags.text.midRef(0).trimmed(); auto length = 0; @@ -340,10 +340,10 @@ bool SendDice( MTPReplyMarkup(), MTP_vector(), MTP_int(message.action.options.scheduled) - )).done([=](const MTPUpdates &result) { + )).done([=](const MTPUpdates &result, mtpRequestId requestId) { api->applyUpdates(result, randomId); if (doneCallback) { - doneCallback(); + doneCallback(result, requestId); } finish(); }).fail([=](const MTP::Error &error) { diff --git a/Telegram/SourceFiles/api/api_sending.h b/Telegram/SourceFiles/api/api_sending.h index 415a3ea87..459b3063a 100644 --- a/Telegram/SourceFiles/api/api_sending.h +++ b/Telegram/SourceFiles/api/api_sending.h @@ -39,7 +39,7 @@ void SendExistingPhoto( bool SendDice( Api::MessageToSend &message, - Fn doneCallback = nullptr, + Fn doneCallback = nullptr, bool forwarding = false); void FillMessagePostFlags( diff --git a/Telegram/SourceFiles/apiwrap.cpp b/Telegram/SourceFiles/apiwrap.cpp index fa6aea410..534398433 100644 --- a/Telegram/SourceFiles/apiwrap.cpp +++ b/Telegram/SourceFiles/apiwrap.cpp @@ -4074,7 +4074,7 @@ void ApiWrap::forwardMessagesUnquoted( message.action.options = action.options; message.action.clearDraft = false; - Api::SendDice(message, [=] { + Api::SendDice(message, [=] (const MTPUpdates &result, mtpRequestId requestId) { if (shared && !--shared->requestsLeft) { shared->callback(); } @@ -4432,7 +4432,12 @@ void ApiWrap::sendMessage( action.generateLocal = true; sendAction(action); - if (!peer->canWrite() || Api::SendDice(message)) { + if (!peer->canWrite() + || Api::SendDice(message, [=] (const MTPUpdates &result, mtpRequestId requestId) { + if (doneCallback) { + doneCallback(result, requestId); + } + }, forwarding)) { return; } local().saveRecentSentHashtags(textWithTags.text); @@ -4517,32 +4522,34 @@ void ApiWrap::sendMessage( } const auto views = 1; const auto forwards = 0; - lastMessage = history->addNewMessage( - MTP_message( - MTP_flags(flags), - MTP_int(newId.msg), - peerToMTP(messageFromId), - peerToMTP(peer->id), - MTPMessageFwdHeader(), - MTPint(), // via_bot_id - replyHeader, - MTP_int( - HistoryItem::NewMessageDate(action.options.scheduled)), - msgText, - media, - MTPReplyMarkup(), - localEntities, - MTP_int(views), - MTP_int(forwards), - MTPMessageReplies(), - MTPint(), // edit_date - MTP_string(messagePostAuthor), - MTPlong(), - //MTPMessageReactions(), - MTPVector(), - MTPint()), // ttl_period - clientFlags, - NewMessageType::Unread); + if (!forwarding) { + lastMessage = history->addNewMessage( + MTP_message( + MTP_flags(flags), + MTP_int(newId.msg), + peerToMTP(messageFromId), + peerToMTP(peer->id), + MTPMessageFwdHeader(), + MTPint(), // via_bot_id + replyHeader, + MTP_int( + HistoryItem::NewMessageDate(action.options.scheduled)), + msgText, + media, + MTPReplyMarkup(), + localEntities, + MTP_int(views), + MTP_int(forwards), + MTPMessageReplies(), + MTPint(), // edit_date + MTP_string(messagePostAuthor), + MTPlong(), + //MTPMessageReactions(), + MTPVector(), + MTPint()), // ttl_period + clientFlags, + NewMessageType::Unread); + } histories.sendRequest(history, requestType, [=](Fn finish) { history->sendRequestId = request(MTPmessages_SendMessage( MTP_flags(sendFlags), @@ -4568,7 +4575,7 @@ void ApiWrap::sendMessage( }).fail([=]( const MTP::Error &error, const MTP::Response &response) { - if (error.type() == qstr("MESSAGE_EMPTY")) { + if (error.type() == qstr("MESSAGE_EMPTY") && !forwarding) { lastMessage->destroy(); } else { sendMessageFail(error, peer, randomId, newId);