2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-23 18:57:12 +00:00
tdesktop/Telegram/SourceFiles/api/api_sending.cpp

628 lines
18 KiB
C++
Raw Normal View History

2019-07-17 16:34:39 +02:00
/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "api/api_sending.h"
2019-09-16 14:14:06 +03:00
#include "api/api_text_entities.h"
#include "base/random.h"
2019-07-17 16:34:39 +02:00
#include "base/unixtime.h"
2024-02-23 21:23:15 +04:00
#include "data/business/data_shortcut_messages.h"
2019-07-17 16:34:39 +02:00
#include "data/data_document.h"
#include "data/data_photo.h"
#include "data/data_channel.h" // ChannelData::addsSignature.
#include "data/data_user.h" // UserData::name
2019-07-17 16:34:39 +02:00
#include "data/data_session.h"
#include "data/data_file_origin.h"
#include "data/data_histories.h"
2020-06-12 18:09:04 +04:00
#include "data/data_changes.h"
#include "data/stickers/data_stickers.h"
2019-07-17 16:34:39 +02:00
#include "history/history.h"
2022-12-14 16:15:46 +04:00
#include "history/history_item.h"
#include "history/history_item_helpers.h" // NewMessageFlags.
#include "chat_helpers/message_field.h" // ConvertTextTagsToEntities.
2020-10-14 16:01:07 +03:00
#include "chat_helpers/stickers_dice_pack.h" // DicePacks::kDiceString.
2019-07-17 16:34:39 +02:00
#include "ui/text/text_entity.h" // TextWithEntities.
2020-10-10 12:15:37 +03:00
#include "ui/item_text_options.h" // Ui::ItemTextOptions.
2019-07-24 13:45:24 +02:00
#include "main/main_session.h"
2020-04-20 13:45:59 +04:00
#include "main/main_app_config.h"
2020-06-12 18:09:04 +04:00
#include "storage/localimageloader.h"
#include "storage/file_upload.h"
2019-07-17 16:34:39 +02:00
#include "mainwidget.h"
#include "apiwrap.h"
namespace Api {
namespace {
void InnerFillMessagePostFlags(
2021-11-18 11:03:03 +04:00
const SendOptions &options,
not_null<PeerData*> peer,
2021-07-28 14:55:02 +03:00
MessageFlags &flags) {
if (ShouldSendSilent(peer, options)) {
flags |= MessageFlag::Silent;
}
2024-08-30 11:44:25 +04:00
if (!peer->amAnonymous()
|| (!peer->isBroadcast()
&& options.sendAs
&& options.sendAs != peer)) {
2021-07-28 14:55:02 +03:00
flags |= MessageFlag::HasFromId;
2024-08-13 13:51:11 +02:00
}
const auto channel = peer->asBroadcast();
if (!channel) {
2020-09-10 14:19:48 +03:00
return;
}
2021-07-28 14:55:02 +03:00
flags |= MessageFlag::Post;
// Don't display views and author of a new post when it's scheduled.
if (options.scheduled) {
return;
}
2021-07-28 14:55:02 +03:00
flags |= MessageFlag::HasViews;
2024-08-13 13:51:11 +02:00
if (channel->addsSignature()) {
2021-07-28 14:55:02 +03:00
flags |= MessageFlag::HasPostAuthor;
}
}
2024-07-04 12:18:30 +04:00
void SendSimpleMedia(SendAction action, MTPInputMedia inputMedia) {
const auto history = action.history;
const auto peer = history->peer;
const auto session = &history->session();
const auto api = &session->api();
action.clearDraft = false;
action.generateLocal = false;
api->sendAction(action);
const auto randomId = base::RandomValue<uint64>();
auto flags = NewMessageFlags(peer);
auto sendFlags = MTPmessages_SendMedia::Flags(0);
if (action.replyTo) {
flags |= MessageFlag::HasReplyInfo;
sendFlags |= MTPmessages_SendMedia::Flag::f_reply_to;
}
const auto silentPost = ShouldSendSilent(peer, action.options);
InnerFillMessagePostFlags(action.options, peer, flags);
if (silentPost) {
sendFlags |= MTPmessages_SendMedia::Flag::f_silent;
}
const auto sendAs = action.options.sendAs;
if (sendAs) {
sendFlags |= MTPmessages_SendMedia::Flag::f_send_as;
}
const auto messagePostAuthor = peer->isBroadcast()
? session->user()->name()
: QString();
if (action.options.scheduled) {
flags |= MessageFlag::IsOrWasScheduled;
sendFlags |= MTPmessages_SendMedia::Flag::f_schedule_date;
}
if (action.options.shortcutId) {
flags |= MessageFlag::ShortcutMessage;
sendFlags |= MTPmessages_SendMedia::Flag::f_quick_reply_shortcut;
}
if (action.options.effectId) {
sendFlags |= MTPmessages_SendMedia::Flag::f_effect;
}
if (action.options.invertCaption) {
flags |= MessageFlag::InvertMedia;
sendFlags |= MTPmessages_SendMedia::Flag::f_invert_media;
}
auto &histories = history->owner().histories();
histories.sendPreparedMessage(
history,
action.replyTo,
randomId,
Data::Histories::PrepareMessage<MTPmessages_SendMedia>(
MTP_flags(sendFlags),
peer->input,
Data::Histories::ReplyToPlaceholder(),
std::move(inputMedia),
MTPstring(),
MTP_long(randomId),
MTPReplyMarkup(),
MTPvector<MTPMessageEntity>(),
MTP_int(action.options.scheduled),
(sendAs ? sendAs->input : MTP_inputPeerEmpty()),
Data::ShortcutIdToMTP(session, action.options.shortcutId),
MTP_long(action.options.effectId)
), [=](const MTPUpdates &result, const MTP::Response &response) {
}, [=](const MTP::Error &error, const MTP::Response &response) {
api->sendMessageFail(error, peer, randomId);
});
api->finishForwarding(action);
}
2019-07-17 16:34:39 +02:00
template <typename MediaData>
void SendExistingMedia(
2021-11-18 11:03:03 +04:00
MessageToSend &&message,
2019-07-17 16:34:39 +02:00
not_null<MediaData*> media,
Fn<MTPInputMedia()> inputMedia,
Data::FileOrigin origin,
std::optional<MsgId> localMessageId) {
const auto history = message.action.history;
2019-07-17 16:34:39 +02:00
const auto peer = history->peer;
const auto session = &history->session();
const auto api = &session->api();
message.action.clearDraft = false;
message.action.generateLocal = true;
api->sendAction(message.action);
2019-07-17 16:34:39 +02:00
2019-08-12 17:33:36 +01:00
const auto newId = FullMsgId(
peer->id,
localMessageId
? (*localMessageId)
: session->data().nextLocalMessageId());
const auto randomId = base::RandomValue<uint64>();
const auto &action = message.action;
2019-07-17 16:34:39 +02:00
2021-07-28 14:55:02 +03:00
auto flags = NewMessageFlags(peer);
2019-07-17 16:34:39 +02:00
auto sendFlags = MTPmessages_SendMedia::Flags(0);
if (action.replyTo) {
2021-07-28 14:55:02 +03:00
flags |= MessageFlag::HasReplyInfo;
sendFlags |= MTPmessages_SendMedia::Flag::f_reply_to;
2019-07-17 16:34:39 +02:00
}
const auto silentPost = ShouldSendSilent(peer, action.options);
InnerFillMessagePostFlags(action.options, peer, flags);
2019-07-17 16:34:39 +02:00
if (silentPost) {
sendFlags |= MTPmessages_SendMedia::Flag::f_silent;
}
const auto sendAs = action.options.sendAs;
2021-11-09 19:24:13 +04:00
if (sendAs) {
sendFlags |= MTPmessages_SendMedia::Flag::f_send_as;
}
auto caption = TextWithEntities{
message.textWithTags.text,
2019-09-16 14:14:06 +03:00
TextUtilities::ConvertTextTagsToEntities(message.textWithTags.tags)
};
2019-07-17 16:34:39 +02:00
TextUtilities::Trim(caption);
2019-09-16 14:14:06 +03:00
auto sentEntities = EntitiesToMTP(
2020-06-08 12:03:45 +04:00
session,
2019-07-17 16:34:39 +02:00
caption.entities,
2019-09-16 14:14:06 +03:00
ConvertOption::SkipLocal);
2019-07-17 16:34:39 +02:00
if (!sentEntities.v.isEmpty()) {
sendFlags |= MTPmessages_SendMedia::Flag::f_entities;
}
const auto captionText = caption.text;
if (action.options.scheduled) {
2021-07-28 14:55:02 +03:00
flags |= MessageFlag::IsOrWasScheduled;
2019-08-12 17:33:36 +01:00
sendFlags |= MTPmessages_SendMedia::Flag::f_schedule_date;
}
if (action.options.shortcutId) {
flags |= MessageFlag::ShortcutMessage;
2024-02-23 21:23:15 +04:00
sendFlags |= MTPmessages_SendMedia::Flag::f_quick_reply_shortcut;
}
2024-05-10 15:00:30 +04:00
if (action.options.effectId) {
sendFlags |= MTPmessages_SendMedia::Flag::f_effect;
}
if (action.options.invertCaption) {
flags |= MessageFlag::InvertMedia;
sendFlags |= MTPmessages_SendMedia::Flag::f_invert_media;
}
2019-08-12 17:33:36 +01:00
2019-07-17 16:34:39 +02:00
session->data().registerMessageRandomId(randomId, newId);
history->addNewLocalMessage({
.id = newId.msg,
.flags = flags,
.from = NewMessageFromId(action),
.replyTo = action.replyTo,
.date = NewMessageDate(action.options),
.shortcutId = action.options.shortcutId,
.postAuthor = NewMessagePostAuthor(action),
2024-05-10 15:00:30 +04:00
.effectId = action.options.effectId,
}, media, caption);
2019-07-17 16:34:39 +02:00
const auto performRequest = [=](const auto &repeatRequest) -> void {
auto &histories = history->owner().histories();
2024-02-23 21:23:15 +04:00
const auto session = &history->session();
const auto usedFileReference = media->fileReference();
histories.sendPreparedMessage(
history,
2024-02-23 21:23:15 +04:00
action.replyTo,
randomId,
2022-10-04 19:34:45 +04:00
Data::Histories::PrepareMessage<MTPmessages_SendMedia>(
MTP_flags(sendFlags),
peer->input,
2022-10-04 19:34:45 +04:00
Data::Histories::ReplyToPlaceholder(),
inputMedia(),
MTP_string(captionText),
MTP_long(randomId),
MTPReplyMarkup(),
sentEntities,
2024-02-23 21:23:15 +04:00
MTP_int(action.options.scheduled),
2024-02-21 17:54:01 +04:00
(sendAs ? sendAs->input : MTP_inputPeerEmpty()),
2024-05-06 17:49:49 +04:00
Data::ShortcutIdToMTP(session, action.options.shortcutId),
MTP_long(action.options.effectId)
), [=](const MTPUpdates &result, const MTP::Response &response) {
}, [=](const MTP::Error &error, const MTP::Response &response) {
if (error.code() == 400
2022-11-27 00:20:17 +03:00
&& error.type().startsWith(u"FILE_REFERENCE_"_q)) {
api->refreshFileReference(origin, [=](const auto &result) {
if (media->fileReference() != usedFileReference) {
repeatRequest(repeatRequest);
} else {
api->sendMessageFail(error, peer, randomId, newId);
}
});
} else {
api->sendMessageFail(error, peer, randomId, newId);
}
});
2019-07-17 16:34:39 +02:00
};
performRequest(performRequest);
2019-07-17 16:34:39 +02:00
api->finishForwarding(action);
2019-07-17 16:34:39 +02:00
}
} // namespace
void SendExistingDocument(
2021-11-18 11:03:03 +04:00
MessageToSend &&message,
not_null<DocumentData*> document,
std::optional<MsgId> localMessageId) {
const auto inputMedia = [=] {
return MTP_inputMediaDocument(
MTP_flags(0),
document->mtpInput(),
2025-01-09 11:24:54 +04:00
MTPInputPhoto(), // video_cover
2020-12-22 17:48:50 +04:00
MTPint(), // ttl_seconds
MTPstring()); // query
};
2019-07-17 16:34:39 +02:00
SendExistingMedia(
std::move(message),
2019-07-17 16:34:39 +02:00
document,
inputMedia,
document->stickerOrGifOrigin(),
std::move(localMessageId));
2019-07-17 16:34:39 +02:00
if (document->sticker()) {
document->owner().stickers().incrementSticker(document);
2019-07-17 16:34:39 +02:00
}
}
void SendExistingPhoto(
2021-11-18 11:03:03 +04:00
MessageToSend &&message,
not_null<PhotoData*> photo,
std::optional<MsgId> localMessageId) {
const auto inputMedia = [=] {
return MTP_inputMediaPhoto(
MTP_flags(0),
photo->mtpInput(),
MTPint());
};
2019-07-17 16:34:39 +02:00
SendExistingMedia(
std::move(message),
2019-07-17 16:34:39 +02:00
photo,
inputMedia,
Data::FileOrigin(),
std::move(localMessageId));
2019-07-17 16:34:39 +02:00
}
2021-11-18 11:03:03 +04:00
bool SendDice(MessageToSend &message) {
const auto full = QStringView(message.textWithTags.text).trimmed();
2020-04-20 13:45:59 +04:00
auto length = 0;
if (!Ui::Emoji::Find(full.data(), full.data() + full.size(), &length)
|| length != full.size()
|| !message.textWithTags.tags.isEmpty()) {
2020-03-06 16:12:03 +04:00
return false;
}
2024-03-29 15:30:50 +04:00
auto &config = message.action.history->session().appConfig();
2020-04-20 13:45:59 +04:00
static const auto hardcoded = std::vector<QString>{
2020-10-14 16:01:07 +03:00
Stickers::DicePacks::kDiceString,
Stickers::DicePacks::kDartString,
Stickers::DicePacks::kSlotString,
Stickers::DicePacks::kFballString,
Stickers::DicePacks::kFballString + QChar(0xFE0F),
Stickers::DicePacks::kBballString,
2020-04-20 13:45:59 +04:00
};
const auto list = config.get<std::vector<QString>>(
"emojies_send_dice",
hardcoded);
const auto emoji = full.toString();
2020-04-20 13:45:59 +04:00
if (!ranges::contains(list, emoji)) {
return false;
}
2020-03-06 16:12:03 +04:00
const auto history = message.action.history;
const auto peer = history->peer;
const auto session = &history->session();
const auto api = &session->api();
message.textWithTags = TextWithTags();
message.action.clearDraft = false;
message.action.generateLocal = true;
2024-02-23 21:23:15 +04:00
const auto &action = message.action;
api->sendAction(action);
2020-03-06 16:12:03 +04:00
const auto newId = FullMsgId(
peer->id,
2020-03-06 16:12:03 +04:00
session->data().nextLocalMessageId());
const auto randomId = base::RandomValue<uint64>();
2020-03-06 16:12:03 +04:00
auto &histories = history->owner().histories();
2021-07-28 14:55:02 +03:00
auto flags = NewMessageFlags(peer);
2020-03-06 16:12:03 +04:00
auto sendFlags = MTPmessages_SendMedia::Flags(0);
2024-02-23 21:23:15 +04:00
if (action.replyTo) {
2021-07-28 14:55:02 +03:00
flags |= MessageFlag::HasReplyInfo;
sendFlags |= MTPmessages_SendMedia::Flag::f_reply_to;
2020-03-06 16:12:03 +04:00
}
2024-02-23 21:23:15 +04:00
const auto silentPost = ShouldSendSilent(peer, action.options);
InnerFillMessagePostFlags(action.options, peer, flags);
2020-03-06 16:12:03 +04:00
if (silentPost) {
sendFlags |= MTPmessages_SendMedia::Flag::f_silent;
}
2024-02-23 21:23:15 +04:00
const auto sendAs = action.options.sendAs;
2021-11-09 19:24:13 +04:00
if (sendAs) {
sendFlags |= MTPmessages_SendMedia::Flag::f_send_as;
}
2024-02-23 21:23:15 +04:00
if (action.options.scheduled) {
2021-07-28 14:55:02 +03:00
flags |= MessageFlag::IsOrWasScheduled;
2020-03-06 16:12:03 +04:00
sendFlags |= MTPmessages_SendMedia::Flag::f_schedule_date;
}
2024-02-23 21:23:15 +04:00
if (action.options.shortcutId) {
flags |= MessageFlag::ShortcutMessage;
2024-02-23 21:23:15 +04:00
sendFlags |= MTPmessages_SendMedia::Flag::f_quick_reply_shortcut;
}
2024-05-10 15:00:30 +04:00
if (action.options.effectId) {
sendFlags |= MTPmessages_SendMedia::Flag::f_effect;
}
if (action.options.invertCaption) {
flags |= MessageFlag::InvertMedia;
sendFlags |= MTPmessages_SendMedia::Flag::f_invert_media;
}
2020-03-06 16:12:03 +04:00
session->data().registerMessageRandomId(randomId, newId);
history->addNewLocalMessage({
.id = newId.msg,
.flags = flags,
.from = NewMessageFromId(action),
.replyTo = action.replyTo,
.date = NewMessageDate(action.options),
.shortcutId = action.options.shortcutId,
.postAuthor = NewMessagePostAuthor(action),
2024-05-10 15:00:30 +04:00
.effectId = action.options.effectId,
}, TextWithEntities(), MTP_messageMediaDice(
MTP_int(0),
MTP_string(emoji)));
histories.sendPreparedMessage(
history,
2024-02-23 21:23:15 +04:00
action.replyTo,
randomId,
2022-10-04 19:34:45 +04:00
Data::Histories::PrepareMessage<MTPmessages_SendMedia>(
2020-03-06 16:12:03 +04:00
MTP_flags(sendFlags),
peer->input,
2022-10-04 19:34:45 +04:00
Data::Histories::ReplyToPlaceholder(),
MTP_inputMediaDice(MTP_string(emoji)),
2020-03-06 16:12:03 +04:00
MTP_string(),
MTP_long(randomId),
MTPReplyMarkup(),
MTP_vector<MTPMessageEntity>(),
2024-02-23 21:23:15 +04:00
MTP_int(action.options.scheduled),
2024-02-21 17:54:01 +04:00
(sendAs ? sendAs->input : MTP_inputPeerEmpty()),
2024-05-06 17:49:49 +04:00
Data::ShortcutIdToMTP(session, action.options.shortcutId),
MTP_long(action.options.effectId)
), [=](const MTPUpdates &result, const MTP::Response &response) {
}, [=](const MTP::Error &error, const MTP::Response &response) {
api->sendMessageFail(error, peer, randomId, newId);
2020-03-06 16:12:03 +04:00
});
2024-02-23 21:23:15 +04:00
api->finishForwarding(action);
2020-03-06 16:12:03 +04:00
return true;
}
2024-07-04 12:18:30 +04:00
void SendLocation(SendAction action, float64 lat, float64 lon) {
SendSimpleMedia(
action,
MTP_inputMediaGeoPoint(
MTP_inputGeoPoint(
MTP_flags(0),
MTP_double(lat),
MTP_double(lon),
MTPint()))); // accuracy_radius
}
void SendVenue(SendAction action, Data::InputVenue venue) {
SendSimpleMedia(
action,
MTP_inputMediaVenue(
MTP_inputGeoPoint(
MTP_flags(0),
MTP_double(venue.lat),
MTP_double(venue.lon),
MTPint()), // accuracy_radius
MTP_string(venue.title),
MTP_string(venue.address),
MTP_string(venue.provider),
MTP_string(venue.id),
MTP_string(venue.venueType)));
}
void FillMessagePostFlags(
2021-11-18 11:03:03 +04:00
const SendAction &action,
not_null<PeerData*> peer,
2021-07-28 14:55:02 +03:00
MessageFlags &flags) {
InnerFillMessagePostFlags(action.options, peer, flags);
}
2020-06-12 18:09:04 +04:00
void SendConfirmedFile(
not_null<Main::Session*> session,
const std::shared_ptr<FilePrepareResult> &file) {
2021-07-28 14:55:02 +03:00
const auto isEditing = (file->type != SendMediaType::Audio)
2024-10-19 11:12:54 +04:00
&& (file->type != SendMediaType::Round)
2021-07-28 14:55:02 +03:00
&& (file->to.replaceMediaOf != 0);
const auto newId = FullMsgId(
file->to.peer,
2022-10-04 19:34:45 +04:00
(isEditing
? file->to.replaceMediaOf
2022-10-04 19:34:45 +04:00
: session->data().nextLocalMessageId()));
const auto groupId = file->album ? file->album->groupId : uint64(0);
2020-06-12 18:09:04 +04:00
if (file->album) {
const auto proj = [](const SendingAlbum::Item &item) {
return item.taskId;
};
const auto it = ranges::find(file->album->items, file->taskId, proj);
Assert(it != file->album->items.end());
it->msgId = newId;
}
const auto itemToEdit = isEditing
? session->data().message(newId)
: nullptr;
const auto history = session->data().history(file->to.peer);
const auto peer = history->peer;
2022-10-04 19:34:45 +04:00
if (!isEditing) {
const auto histories = &session->data().histories();
2023-10-10 10:49:22 +04:00
file->to.replyTo.messageId = histories->convertTopicReplyToId(
2022-10-04 19:34:45 +04:00
history,
2023-10-10 10:49:22 +04:00
file->to.replyTo.messageId);
file->to.replyTo.topicRootId = histories->convertTopicReplyToId(
history,
file->to.replyTo.topicRootId);
2022-10-04 19:34:45 +04:00
}
session->uploader().upload(newId, file);
2021-11-09 19:24:13 +04:00
auto action = SendAction(history, file->to.options);
2020-06-12 18:09:04 +04:00
action.clearDraft = false;
action.replyTo = file->to.replyTo;
action.generateLocal = true;
action.replaceMediaOf = file->to.replaceMediaOf;
2020-06-12 18:09:04 +04:00
session->api().sendAction(action);
auto caption = TextWithEntities{
file->caption.text,
TextUtilities::ConvertTextTagsToEntities(file->caption.tags)
};
const auto prepareFlags = Ui::ItemTextOptions(
history,
session->user()).flags;
TextUtilities::PrepareForSending(caption, prepareFlags);
TextUtilities::Trim(caption);
2021-07-28 14:55:02 +03:00
auto flags = isEditing ? MessageFlags() : NewMessageFlags(peer);
2020-06-12 18:09:04 +04:00
if (file->to.replyTo) {
2021-07-28 14:55:02 +03:00
flags |= MessageFlag::HasReplyInfo;
2020-06-12 18:09:04 +04:00
}
2021-07-28 14:55:02 +03:00
FillMessagePostFlags(action, peer, flags);
2020-06-12 18:09:04 +04:00
if (file->to.options.scheduled) {
2021-07-28 14:55:02 +03:00
flags |= MessageFlag::IsOrWasScheduled;
// Scheduled messages have no 'edited' badge.
flags |= MessageFlag::HideEdited;
}
if (file->to.options.shortcutId) {
flags |= MessageFlag::ShortcutMessage;
// Shortcut messages have no 'edited' badge.
2021-07-28 14:55:02 +03:00
flags |= MessageFlag::HideEdited;
2020-06-12 18:09:04 +04:00
}
2024-10-19 11:12:54 +04:00
if (file->type == SendMediaType::Audio
|| file->type == SendMediaType::Round) {
if (!peer->isChannel() || peer->isMegagroup()) {
flags |= MessageFlag::MediaIsUnread;
}
}
if (file->to.options.invertCaption) {
flags |= MessageFlag::InvertMedia;
}
const auto media = MTPMessageMedia([&] {
2021-07-28 14:55:02 +03:00
if (file->type == SendMediaType::Photo) {
2022-12-13 16:11:52 +04:00
using Flag = MTPDmessageMediaPhoto::Flag;
2021-07-28 14:55:02 +03:00
return MTP_messageMediaPhoto(
2022-12-13 16:11:52 +04:00
MTP_flags(Flag::f_photo
| (file->spoiler ? Flag::f_spoiler : Flag())),
2021-07-28 14:55:02 +03:00
file->photo,
MTPint());
} else if (file->type == SendMediaType::File) {
2022-12-13 16:11:52 +04:00
using Flag = MTPDmessageMediaDocument::Flag;
2021-07-28 14:55:02 +03:00
return MTP_messageMediaDocument(
2022-12-13 16:11:52 +04:00
MTP_flags(Flag::f_document
| (file->spoiler ? Flag::f_spoiler : Flag())),
2021-07-28 14:55:02 +03:00
file->document,
2024-09-13 20:44:36 +04:00
MTPVector<MTPDocument>(), // alt_documents
2025-01-09 11:24:54 +04:00
MTPPhoto(), // video_cover
2021-07-28 14:55:02 +03:00
MTPint());
} else if (file->type == SendMediaType::Audio) {
const auto ttlSeconds = file->to.options.ttlSeconds;
using Flag = MTPDmessageMediaDocument::Flag;
2021-07-28 14:55:02 +03:00
return MTP_messageMediaDocument(
MTP_flags(Flag::f_document
2024-10-19 11:12:54 +04:00
| Flag::f_voice
| (ttlSeconds ? Flag::f_ttl_seconds : Flag())),
2021-07-28 14:55:02 +03:00
file->document,
2024-09-13 20:44:36 +04:00
MTPVector<MTPDocument>(), // alt_documents
2025-01-09 11:24:54 +04:00
MTPPhoto(), // video_cover
MTP_int(ttlSeconds));
2024-10-19 11:12:54 +04:00
} else if (file->type == SendMediaType::Round) {
using Flag = MTPDmessageMediaDocument::Flag;
const auto ttlSeconds = file->to.options.ttlSeconds;
return MTP_messageMediaDocument(
MTP_flags(Flag::f_document
| Flag::f_round
| (ttlSeconds ? Flag::f_ttl_seconds : Flag())
| (file->spoiler ? Flag::f_spoiler : Flag())),
file->document,
MTPVector<MTPDocument>(), // alt_documents
2025-01-09 11:24:54 +04:00
MTPPhoto(), // video_cover
2024-10-19 11:12:54 +04:00
MTP_int(ttlSeconds));
2020-06-12 18:09:04 +04:00
} else {
2021-07-28 14:55:02 +03:00
Unexpected("Type in sendFilesConfirmed.");
2020-06-12 18:09:04 +04:00
}
}());
2020-06-12 18:09:04 +04:00
2021-07-28 14:55:02 +03:00
if (itemToEdit) {
auto edition = HistoryMessageEdition();
edition.isEditHide = (flags & MessageFlag::HideEdited);
edition.editDate = 0;
edition.ttl = 0;
edition.mtpMedia = &media;
edition.textWithEntities = caption;
edition.invertMedia = file->to.options.invertCaption;
edition.useSameViews = true;
edition.useSameForwards = true;
edition.useSameMarkup = true;
edition.useSameReplies = true;
edition.useSameReactions = true;
edition.savePreviousMedia = true;
itemToEdit->applyEdition(std::move(edition));
2020-06-12 18:09:04 +04:00
} else {
history->addNewLocalMessage({
.id = newId.msg,
.flags = flags,
.from = NewMessageFromId(action),
.replyTo = file->to.replyTo,
.date = NewMessageDate(file->to.options),
.shortcutId = file->to.options.shortcutId,
.postAuthor = NewMessagePostAuthor(action),
.groupedId = groupId,
2024-05-10 15:00:30 +04:00
.effectId = file->to.options.effectId,
}, caption, media);
2020-06-12 18:09:04 +04:00
}
if (isEditing) {
return;
}
session->data().sendHistoryChangeNotifications();
if (!itemToEdit) {
session->changes().historyUpdated(
history,
(action.options.scheduled
? Data::HistoryUpdate::Flag::ScheduledSent
: Data::HistoryUpdate::Flag::MessageSent));
}
2020-06-12 18:09:04 +04:00
}
2019-07-17 16:34:39 +02:00
} // namespace Api