2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-31 06:35:14 +00:00

[Option][GUI] Unquoted forward and forward options

This commit is contained in:
RadRussianRus
2022-09-11 05:50:27 +03:00
committed by Eric Kotato
parent fc8feea983
commit 8c65b8cedd
28 changed files with 1695 additions and 94 deletions

View File

@@ -12,6 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "base/unixtime.h"
#include "data/data_document.h"
#include "data/data_photo.h"
#include "data/data_location.h"
#include "data/data_channel.h" // ChannelData::addsSignature.
#include "data/data_user.h" // UserData::name
#include "data/data_session.h"
@@ -68,7 +69,9 @@ void SendExistingMedia(
not_null<MediaData*> media,
Fn<MTPInputMedia()> inputMedia,
Data::FileOrigin origin,
std::optional<MsgId> localMessageId) {
std::optional<MsgId> localMessageId,
Fn<void()> doneCallback = nullptr,
bool forwarding = false) {
const auto history = message.action.history;
const auto peer = history->peer;
const auto session = &history->session();
@@ -146,7 +149,6 @@ void SendExistingMedia(
const auto performRequest = [=](const auto &repeatRequest) -> void {
auto &histories = history->owner().histories();
const auto usedFileReference = media->fileReference();
histories.sendPreparedMessage(
history,
message.action.replyTo,
@@ -166,6 +168,7 @@ void SendExistingMedia(
}, [=](const MTP::Error &error, const MTP::Response &response) {
if (error.code() == 400
&& error.type().startsWith(u"FILE_REFERENCE_"_q)) {
const auto usedFileReference = media->fileReference();
api->refreshFileReference(origin, [=](const auto &result) {
if (media->fileReference() != usedFileReference) {
repeatRequest(repeatRequest);
@@ -180,15 +183,41 @@ void SendExistingMedia(
};
performRequest(performRequest);
api->finishForwarding(message.action);
if (!forwarding) {
api->finishForwarding(message.action);
}
}
} // namespace
void SendWebDocument(
Api::MessageToSend &&message,
not_null<DocumentData*> document,
std::optional<MsgId> localMessageId,
Fn<void()> doneCallback,
bool forwarding) {
const auto inputMedia = [=] {
return MTP_inputMediaDocumentExternal(
MTP_flags(0),
MTP_string(document->url()),
MTPint()); // ttl_seconds
};
SendExistingMedia(
std::move(message),
document,
inputMedia,
document->stickerOrGifOrigin(),
std::move(localMessageId),
(doneCallback ? std::move(doneCallback) : nullptr),
forwarding);
}
void SendExistingDocument(
MessageToSend &&message,
not_null<DocumentData*> document,
std::optional<MsgId> localMessageId) {
std::optional<MsgId> localMessageId,
Fn<void()> doneCallback,
bool forwarding) {
const auto inputMedia = [=] {
return MTP_inputMediaDocument(
MTP_flags(0),
@@ -201,7 +230,9 @@ void SendExistingDocument(
document,
inputMedia,
document->stickerOrGifOrigin(),
std::move(localMessageId));
std::move(localMessageId),
(doneCallback ? std::move(doneCallback) : nullptr),
forwarding);
if (document->sticker()) {
document->owner().stickers().incrementSticker(document);
@@ -211,7 +242,9 @@ void SendExistingDocument(
void SendExistingPhoto(
MessageToSend &&message,
not_null<PhotoData*> photo,
std::optional<MsgId> localMessageId) {
std::optional<MsgId> localMessageId,
Fn<void()> doneCallback,
bool forwarding) {
const auto inputMedia = [=] {
return MTP_inputMediaPhoto(
MTP_flags(0),
@@ -223,10 +256,15 @@ void SendExistingPhoto(
photo,
inputMedia,
Data::FileOrigin(),
std::move(localMessageId));
std::move(localMessageId),
(doneCallback ? std::move(doneCallback) : nullptr),
forwarding);
}
bool SendDice(MessageToSend &message) {
bool SendDice(
MessageToSend &message,
Fn<void(const MTPUpdates &, mtpRequestId)> doneCallback,
bool forwarding) {
const auto full = QStringView(message.textWithTags.text).trimmed();
auto length = 0;
if (!Ui::Emoji::Find(full.data(), full.data() + full.size(), &length)
@@ -330,7 +368,9 @@ bool SendDice(MessageToSend &message) {
}, [=](const MTP::Error &error, const MTP::Response &response) {
api->sendMessageFail(error, peer, randomId, newId);
});
api->finishForwarding(message.action);
if (!forwarding) {
api->finishForwarding(message.action);
}
return true;
}
@@ -515,4 +555,73 @@ void SendConfirmedFile(
}
}
void SendLocationPoint(
const Data::LocationPoint &data,
const SendAction &action,
Fn<void()> done,
Fn<void(const MTP::Error &error)> fail) {
const auto history = action.history;
const auto session = &history->session();
const auto api = &session->api();
const auto peer = history->peer;
api->sendAction(action);
auto sendFlags = MTPmessages_SendMedia::Flags(0);
if (action.replyTo) {
sendFlags |= MTPmessages_SendMedia::Flag::f_reply_to;
}
const auto topicRootId = action.replyTo.messageId
? action.replyTo.topicRootId
: 0;
if (action.clearDraft) {
sendFlags |= MTPmessages_SendMedia::Flag::f_clear_draft;
history->clearLocalDraft(topicRootId);
history->clearCloudDraft(topicRootId);
}
const auto sendAs = action.options.sendAs;
if (sendAs) {
sendFlags |= MTPmessages_SendMedia::Flag::f_send_as;
}
const auto silentPost = ShouldSendSilent(peer, action.options);
if (silentPost) {
sendFlags |= MTPmessages_SendMedia::Flag::f_silent;
}
if (action.options.scheduled) {
sendFlags |= MTPmessages_SendMedia::Flag::f_schedule_date;
}
auto &histories = history->owner().histories();
const auto requestType = Data::Histories::RequestType::Send;
histories.sendRequest(history, requestType, [=](Fn<void()> finish) {
history->sendRequestId = api->request(MTPmessages_SendMedia(
MTP_flags(sendFlags),
peer->input,
action.mtpReplyTo(),
MTP_inputMediaGeoPoint(
MTP_inputGeoPoint(
MTP_flags(0),
MTP_double(data.lat()),
MTP_double(data.lon()),
MTP_int(0))),
MTP_string(),
MTP_long(base::RandomValue<uint64>()),
MTPReplyMarkup(),
MTPVector<MTPMessageEntity>(),
MTP_int(action.options.scheduled),
(sendAs ? sendAs->input : MTP_inputPeerEmpty())
)).done([=](const MTPUpdates &result) mutable {
api->applyUpdates(result);
done();
finish();
}).fail([=](const MTP::Error &error) mutable {
if (fail) {
fail(error);
}
finish();
}).afterRequest(history->sendRequestId
).send();
return history->sendRequestId;
});
}
} // namespace Api