2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-30 06:07:45 +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(
Api::MessageToSend &message,
Fn<void()> doneCallback,
Fn<void(const MTPUpdates &, mtpRequestId)> doneCallback,
bool forwarding) {
const auto full = message.textWithTags.text.midRef(0).trimmed();
auto length = 0;
@ -340,10 +340,10 @@ bool SendDice(
MTPReplyMarkup(),
MTP_vector<MTPMessageEntity>(),
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) {

View File

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

View File

@ -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<MTPRestrictionReason>(),
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<MTPRestrictionReason>(),
MTPint()), // ttl_period
clientFlags,
NewMessageType::Unread);
}
histories.sendRequest(history, requestType, [=](Fn<void()> 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);