2020-05-28 09:30:40 +00: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_media.h"
|
|
|
|
|
2021-11-16 12:38:31 +00:00
|
|
|
#include "api/api_common.h"
|
2020-05-28 09:30:40 +00:00
|
|
|
#include "data/data_document.h"
|
2021-07-08 16:42:57 +00:00
|
|
|
#include "data/stickers/data_stickers_set.h"
|
2020-05-28 09:30:40 +00:00
|
|
|
#include "history/history_item.h"
|
|
|
|
|
|
|
|
namespace Api {
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
MTPVector<MTPDocumentAttribute> ComposeSendingDocumentAttributes(
|
|
|
|
not_null<DocumentData*> document) {
|
|
|
|
const auto filenameAttribute = MTP_documentAttributeFilename(
|
|
|
|
MTP_string(document->filename()));
|
|
|
|
const auto dimensions = document->dimensions;
|
|
|
|
auto attributes = QVector<MTPDocumentAttribute>(1, filenameAttribute);
|
|
|
|
if (dimensions.width() > 0 && dimensions.height() > 0) {
|
|
|
|
const auto duration = document->getDuration();
|
|
|
|
if (duration >= 0 && !document->hasMimeType(qstr("image/gif"))) {
|
|
|
|
auto flags = MTPDdocumentAttributeVideo::Flags(0);
|
|
|
|
using VideoFlag = MTPDdocumentAttributeVideo::Flag;
|
|
|
|
if (document->isVideoMessage()) {
|
|
|
|
flags |= VideoFlag::f_round_message;
|
|
|
|
}
|
|
|
|
if (document->supportsStreaming()) {
|
|
|
|
flags |= VideoFlag::f_supports_streaming;
|
|
|
|
}
|
|
|
|
attributes.push_back(MTP_documentAttributeVideo(
|
|
|
|
MTP_flags(flags),
|
|
|
|
MTP_int(duration),
|
|
|
|
MTP_int(dimensions.width()),
|
|
|
|
MTP_int(dimensions.height())));
|
|
|
|
} else {
|
|
|
|
attributes.push_back(MTP_documentAttributeImageSize(
|
|
|
|
MTP_int(dimensions.width()),
|
|
|
|
MTP_int(dimensions.height())));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (document->type == AnimatedDocument) {
|
|
|
|
attributes.push_back(MTP_documentAttributeAnimated());
|
|
|
|
} else if (document->type == StickerDocument && document->sticker()) {
|
|
|
|
attributes.push_back(MTP_documentAttributeSticker(
|
|
|
|
MTP_flags(0),
|
|
|
|
MTP_string(document->sticker()->alt),
|
2021-07-08 16:42:57 +00:00
|
|
|
Data::InputStickerSet(document->sticker()->set),
|
2020-05-28 09:30:40 +00:00
|
|
|
MTPMaskCoords()));
|
|
|
|
} else if (const auto song = document->song()) {
|
|
|
|
const auto flags = MTPDdocumentAttributeAudio::Flag::f_title
|
|
|
|
| MTPDdocumentAttributeAudio::Flag::f_performer;
|
|
|
|
attributes.push_back(MTP_documentAttributeAudio(
|
|
|
|
MTP_flags(flags),
|
|
|
|
MTP_int(song->duration),
|
|
|
|
MTP_string(song->title),
|
|
|
|
MTP_string(song->performer),
|
|
|
|
MTPstring()));
|
|
|
|
} else if (const auto voice = document->voice()) {
|
|
|
|
const auto flags = MTPDdocumentAttributeAudio::Flag::f_voice
|
|
|
|
| MTPDdocumentAttributeAudio::Flag::f_waveform;
|
|
|
|
attributes.push_back(MTP_documentAttributeAudio(
|
|
|
|
MTP_flags(flags),
|
|
|
|
MTP_int(voice->duration),
|
|
|
|
MTPstring(),
|
|
|
|
MTPstring(),
|
|
|
|
MTP_bytes(documentWaveformEncode5bit(voice->waveform))));
|
|
|
|
}
|
|
|
|
return MTP_vector<MTPDocumentAttribute>(attributes);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2021-11-16 12:38:31 +00:00
|
|
|
MTPInputMedia PrepareUploadedPhoto(RemoteFileInfo info) {
|
|
|
|
const auto flags = info.attachedStickers.empty()
|
2021-03-14 09:46:17 +00:00
|
|
|
? MTPDinputMediaUploadedPhoto::Flags(0)
|
|
|
|
: MTPDinputMediaUploadedPhoto::Flag::f_stickers;
|
2020-05-28 09:30:40 +00:00
|
|
|
return MTP_inputMediaUploadedPhoto(
|
2021-03-14 09:46:17 +00:00
|
|
|
MTP_flags(flags),
|
2021-11-16 12:38:31 +00:00
|
|
|
info.file,
|
|
|
|
MTP_vector<MTPInputDocument>(
|
2022-04-26 05:45:34 +00:00
|
|
|
ranges::to<QVector<MTPInputDocument>>(info.attachedStickers)),
|
2020-05-28 09:30:40 +00:00
|
|
|
MTP_int(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
MTPInputMedia PrepareUploadedDocument(
|
|
|
|
not_null<HistoryItem*> item,
|
2021-11-16 12:38:31 +00:00
|
|
|
RemoteFileInfo info) {
|
2020-05-28 09:30:40 +00:00
|
|
|
if (!item || !item->media() || !item->media()->document()) {
|
|
|
|
return MTP_inputMediaEmpty();
|
|
|
|
}
|
|
|
|
const auto emptyFlag = MTPDinputMediaUploadedDocument::Flags(0);
|
|
|
|
using DocFlags = MTPDinputMediaUploadedDocument::Flag;
|
|
|
|
const auto flags = emptyFlag
|
2021-11-16 12:38:31 +00:00
|
|
|
| (info.thumb ? DocFlags::f_thumb : emptyFlag)
|
2021-03-14 09:46:17 +00:00
|
|
|
| (item->groupId() ? DocFlags::f_nosound_video : emptyFlag)
|
2021-11-16 12:38:31 +00:00
|
|
|
| (info.attachedStickers.empty() ? DocFlags::f_stickers : emptyFlag);
|
2020-05-28 09:30:40 +00:00
|
|
|
const auto document = item->media()->document();
|
|
|
|
return MTP_inputMediaUploadedDocument(
|
|
|
|
MTP_flags(flags),
|
2021-11-16 12:38:31 +00:00
|
|
|
info.file,
|
|
|
|
info.thumb.value_or(MTPInputFile()),
|
2020-05-28 09:30:40 +00:00
|
|
|
MTP_string(document->mimeString()),
|
|
|
|
ComposeSendingDocumentAttributes(document),
|
2021-11-16 12:38:31 +00:00
|
|
|
MTP_vector<MTPInputDocument>(
|
2022-04-26 05:45:34 +00:00
|
|
|
ranges::to<QVector<MTPInputDocument>>(info.attachedStickers)),
|
2020-05-28 09:30:40 +00:00
|
|
|
MTP_int(0));
|
|
|
|
}
|
|
|
|
|
2021-03-30 21:00:48 +00:00
|
|
|
bool HasAttachedStickers(MTPInputMedia media) {
|
|
|
|
return media.match([&](const MTPDinputMediaUploadedPhoto &photo) -> bool {
|
|
|
|
return (photo.vflags().v
|
|
|
|
& MTPDinputMediaUploadedPhoto::Flag::f_stickers);
|
|
|
|
}, [&](const MTPDinputMediaUploadedDocument &document) -> bool {
|
|
|
|
return (document.vflags().v
|
|
|
|
& MTPDinputMediaUploadedDocument::Flag::f_stickers);
|
|
|
|
}, [](const auto &d) {
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-05-28 09:30:40 +00:00
|
|
|
} // namespace Api
|