2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-30 22:25:12 +00:00

Fix mixed order of messages sent with unquoted forwarding

This commit is contained in:
RadRussianRus
2021-03-30 16:32:09 +03:00
parent 0038f20d16
commit 252a0d6581
3 changed files with 40 additions and 33 deletions

View File

@@ -231,7 +231,7 @@ void SendExistingPhoto(
bool SendDice( bool SendDice(
Api::MessageToSend &message, Api::MessageToSend &message,
Fn<void()> doneCallback, Fn<void(const MTPUpdates &, mtpRequestId)> doneCallback,
bool forwarding) { bool forwarding) {
const auto full = message.textWithTags.text.midRef(0).trimmed(); const auto full = message.textWithTags.text.midRef(0).trimmed();
auto length = 0; auto length = 0;
@@ -340,10 +340,10 @@ bool SendDice(
MTPReplyMarkup(), MTPReplyMarkup(),
MTP_vector<MTPMessageEntity>(), MTP_vector<MTPMessageEntity>(),
MTP_int(message.action.options.scheduled) MTP_int(message.action.options.scheduled)
)).done([=](const MTPUpdates &result) { )).done([=](const MTPUpdates &result, mtpRequestId requestId) {
api->applyUpdates(result, randomId); api->applyUpdates(result, randomId);
if (doneCallback) { if (doneCallback) {
doneCallback(); doneCallback(result, requestId);
} }
finish(); finish();
}).fail([=](const MTP::Error &error) { }).fail([=](const MTP::Error &error) {

View File

@@ -39,7 +39,7 @@ void SendExistingPhoto(
bool SendDice( bool SendDice(
Api::MessageToSend &message, Api::MessageToSend &message,
Fn<void()> doneCallback = nullptr, Fn<void(const MTPUpdates &, mtpRequestId)> doneCallback = nullptr,
bool forwarding = false); bool forwarding = false);
void FillMessagePostFlags( void FillMessagePostFlags(

View File

@@ -4074,7 +4074,7 @@ void ApiWrap::forwardMessagesUnquoted(
message.action.options = action.options; message.action.options = action.options;
message.action.clearDraft = false; message.action.clearDraft = false;
Api::SendDice(message, [=] { Api::SendDice(message, [=] (const MTPUpdates &result, mtpRequestId requestId) {
if (shared && !--shared->requestsLeft) { if (shared && !--shared->requestsLeft) {
shared->callback(); shared->callback();
} }
@@ -4432,7 +4432,12 @@ void ApiWrap::sendMessage(
action.generateLocal = true; action.generateLocal = true;
sendAction(action); 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; return;
} }
local().saveRecentSentHashtags(textWithTags.text); local().saveRecentSentHashtags(textWithTags.text);
@@ -4517,32 +4522,34 @@ void ApiWrap::sendMessage(
} }
const auto views = 1; const auto views = 1;
const auto forwards = 0; const auto forwards = 0;
lastMessage = history->addNewMessage( if (!forwarding) {
MTP_message( lastMessage = history->addNewMessage(
MTP_flags(flags), MTP_message(
MTP_int(newId.msg), MTP_flags(flags),
peerToMTP(messageFromId), MTP_int(newId.msg),
peerToMTP(peer->id), peerToMTP(messageFromId),
MTPMessageFwdHeader(), peerToMTP(peer->id),
MTPint(), // via_bot_id MTPMessageFwdHeader(),
replyHeader, MTPint(), // via_bot_id
MTP_int( replyHeader,
HistoryItem::NewMessageDate(action.options.scheduled)), MTP_int(
msgText, HistoryItem::NewMessageDate(action.options.scheduled)),
media, msgText,
MTPReplyMarkup(), media,
localEntities, MTPReplyMarkup(),
MTP_int(views), localEntities,
MTP_int(forwards), MTP_int(views),
MTPMessageReplies(), MTP_int(forwards),
MTPint(), // edit_date MTPMessageReplies(),
MTP_string(messagePostAuthor), MTPint(), // edit_date
MTPlong(), MTP_string(messagePostAuthor),
//MTPMessageReactions(), MTPlong(),
MTPVector<MTPRestrictionReason>(), //MTPMessageReactions(),
MTPint()), // ttl_period MTPVector<MTPRestrictionReason>(),
clientFlags, MTPint()), // ttl_period
NewMessageType::Unread); clientFlags,
NewMessageType::Unread);
}
histories.sendRequest(history, requestType, [=](Fn<void()> finish) { histories.sendRequest(history, requestType, [=](Fn<void()> finish) {
history->sendRequestId = request(MTPmessages_SendMessage( history->sendRequestId = request(MTPmessages_SendMessage(
MTP_flags(sendFlags), MTP_flags(sendFlags),
@@ -4568,7 +4575,7 @@ void ApiWrap::sendMessage(
}).fail([=]( }).fail([=](
const MTP::Error &error, const MTP::Error &error,
const MTP::Response &response) { const MTP::Response &response) {
if (error.type() == qstr("MESSAGE_EMPTY")) { if (error.type() == qstr("MESSAGE_EMPTY") && !forwarding) {
lastMessage->destroy(); lastMessage->destroy();
} else { } else {
sendMessageFail(error, peer, randomId, newId); sendMessageFail(error, peer, randomId, newId);