Hide MTPInputFile in Api::RemoteFileInfo.

This commit is contained in:
John Preston 2021-11-16 16:38:31 +04:00
parent 5d0445dd25
commit 3b2f6b893d
12 changed files with 93 additions and 117 deletions

View file

@ -45,4 +45,10 @@ struct MessageToSend {
WebPageId webPageId = 0; WebPageId webPageId = 0;
}; };
struct RemoteFileInfo {
MTPInputFile file;
std::optional<MTPInputFile> thumb;
std::vector<MTPInputDocument> attachedStickers;
};
} // namespace Api } // namespace Api

View file

@ -172,33 +172,28 @@ void RescheduleMessage(
void EditMessageWithUploadedDocument( void EditMessageWithUploadedDocument(
HistoryItem *item, HistoryItem *item,
const MTPInputFile &file, RemoteFileInfo info,
const std::optional<MTPInputFile> &thumb, SendOptions options) {
SendOptions options,
std::vector<MTPInputDocument> attachedStickers) {
if (!item || !item->media() || !item->media()->document()) { if (!item || !item->media() || !item->media()->document()) {
return; return;
} }
const auto media = PrepareUploadedDocument( EditMessageWithUploadedMedia(
item, item,
file, options,
thumb, PrepareUploadedDocument(item, std::move(info)));
std::move(attachedStickers));
EditMessageWithUploadedMedia(item, options, media);
} }
void EditMessageWithUploadedPhoto( void EditMessageWithUploadedPhoto(
HistoryItem *item, HistoryItem *item,
const MTPInputFile &file, RemoteFileInfo info,
SendOptions options, SendOptions options) {
std::vector<MTPInputDocument> attachedStickers) {
if (!item || !item->media() || !item->media()->photo()) { if (!item || !item->media() || !item->media()->photo()) {
return; return;
} }
const auto media = PrepareUploadedPhoto( EditMessageWithUploadedMedia(
file, item,
std::move(attachedStickers)); options,
EditMessageWithUploadedMedia(item, options, media); PrepareUploadedPhoto(std::move(info)));
} }
mtpRequestId EditCaption( mtpRequestId EditCaption(

View file

@ -16,6 +16,7 @@ class Error;
namespace Api { namespace Api {
struct SendOptions; struct SendOptions;
struct RemoteFileInfo;
const auto kDefaultEditMessagesErrors = { const auto kDefaultEditMessagesErrors = {
u"MESSAGE_ID_INVALID"_q, u"MESSAGE_ID_INVALID"_q,
@ -29,16 +30,13 @@ void RescheduleMessage(
void EditMessageWithUploadedDocument( void EditMessageWithUploadedDocument(
HistoryItem *item, HistoryItem *item,
const MTPInputFile &file, RemoteFileInfo info,
const std::optional<MTPInputFile> &thumb, SendOptions options);
SendOptions options,
std::vector<MTPInputDocument> attachedStickers);
void EditMessageWithUploadedPhoto( void EditMessageWithUploadedPhoto(
HistoryItem *item, HistoryItem *item,
const MTPInputFile &file, RemoteFileInfo info,
SendOptions options, SendOptions options);
std::vector<MTPInputDocument> attachedStickers);
mtpRequestId EditCaption( mtpRequestId EditCaption(
not_null<HistoryItem*> item, not_null<HistoryItem*> item,

View file

@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/ */
#include "api/api_media.h" #include "api/api_media.h"
#include "api/api_common.h"
#include "data/data_document.h" #include "data/data_document.h"
#include "data/stickers/data_stickers_set.h" #include "data/stickers/data_stickers_set.h"
#include "history/history_item.h" #include "history/history_item.h"
@ -74,41 +75,39 @@ MTPVector<MTPDocumentAttribute> ComposeSendingDocumentAttributes(
} // namespace } // namespace
MTPInputMedia PrepareUploadedPhoto( MTPInputMedia PrepareUploadedPhoto(RemoteFileInfo info) {
const MTPInputFile &file, const auto flags = info.attachedStickers.empty()
std::vector<MTPInputDocument> attachedStickers) {
const auto flags = attachedStickers.empty()
? MTPDinputMediaUploadedPhoto::Flags(0) ? MTPDinputMediaUploadedPhoto::Flags(0)
: MTPDinputMediaUploadedPhoto::Flag::f_stickers; : MTPDinputMediaUploadedPhoto::Flag::f_stickers;
return MTP_inputMediaUploadedPhoto( return MTP_inputMediaUploadedPhoto(
MTP_flags(flags), MTP_flags(flags),
file, info.file,
MTP_vector<MTPInputDocument>(ranges::to<QVector>(attachedStickers)), MTP_vector<MTPInputDocument>(
ranges::to<QVector>(info.attachedStickers)),
MTP_int(0)); MTP_int(0));
} }
MTPInputMedia PrepareUploadedDocument( MTPInputMedia PrepareUploadedDocument(
not_null<HistoryItem*> item, not_null<HistoryItem*> item,
const MTPInputFile &file, RemoteFileInfo info) {
const std::optional<MTPInputFile> &thumb,
std::vector<MTPInputDocument> attachedStickers) {
if (!item || !item->media() || !item->media()->document()) { if (!item || !item->media() || !item->media()->document()) {
return MTP_inputMediaEmpty(); return MTP_inputMediaEmpty();
} }
const auto emptyFlag = MTPDinputMediaUploadedDocument::Flags(0); const auto emptyFlag = MTPDinputMediaUploadedDocument::Flags(0);
using DocFlags = MTPDinputMediaUploadedDocument::Flag; using DocFlags = MTPDinputMediaUploadedDocument::Flag;
const auto flags = emptyFlag const auto flags = emptyFlag
| (thumb ? DocFlags::f_thumb : emptyFlag) | (info.thumb ? DocFlags::f_thumb : emptyFlag)
| (item->groupId() ? DocFlags::f_nosound_video : emptyFlag) | (item->groupId() ? DocFlags::f_nosound_video : emptyFlag)
| (attachedStickers.empty() ? DocFlags::f_stickers : emptyFlag); | (info.attachedStickers.empty() ? DocFlags::f_stickers : emptyFlag);
const auto document = item->media()->document(); const auto document = item->media()->document();
return MTP_inputMediaUploadedDocument( return MTP_inputMediaUploadedDocument(
MTP_flags(flags), MTP_flags(flags),
file, info.file,
thumb.value_or(MTPInputFile()), info.thumb.value_or(MTPInputFile()),
MTP_string(document->mimeString()), MTP_string(document->mimeString()),
ComposeSendingDocumentAttributes(document), ComposeSendingDocumentAttributes(document),
MTP_vector<MTPInputDocument>(ranges::to<QVector>(attachedStickers)), MTP_vector<MTPInputDocument>(
ranges::to<QVector>(info.attachedStickers)),
MTP_int(0)); MTP_int(0));
} }

View file

@ -11,15 +11,13 @@ class HistoryItem;
namespace Api { namespace Api {
MTPInputMedia PrepareUploadedPhoto( struct RemoteFileInfo;
const MTPInputFile &file,
std::vector<MTPInputDocument> attachedStickers); MTPInputMedia PrepareUploadedPhoto(RemoteFileInfo info);
MTPInputMedia PrepareUploadedDocument( MTPInputMedia PrepareUploadedDocument(
not_null<HistoryItem*> item, not_null<HistoryItem*> item,
const MTPInputFile &file, RemoteFileInfo info);
const std::optional<MTPInputFile> &thumb,
std::vector<MTPInputDocument> attachedStickers);
bool HasAttachedStickers(MTPInputMedia media); bool HasAttachedStickers(MTPInputMedia media);

View file

@ -104,8 +104,8 @@ PeerPhoto::PeerPhoto(not_null<ApiWrap*> api)
// You can't use _session->lifetime() in the constructor, // You can't use _session->lifetime() in the constructor,
// only queued, because it is not constructed yet. // only queued, because it is not constructed yet.
_session->uploader().photoReady( _session->uploader().photoReady(
) | rpl::start_with_next([=](const Storage::UploadedPhoto &data) { ) | rpl::start_with_next([=](const Storage::UploadedMedia &data) {
ready(data.fullId, data.file); ready(data.fullId, data.info.file);
}, _session->lifetime()); }, _session->lifetime());
}); });
} }

View file

@ -3963,13 +3963,10 @@ void ApiWrap::sendFile(
void ApiWrap::sendUploadedPhoto( void ApiWrap::sendUploadedPhoto(
FullMsgId localId, FullMsgId localId,
const MTPInputFile &file, Api::RemoteFileInfo info,
Api::SendOptions options, Api::SendOptions options) {
std::vector<MTPInputDocument> attachedStickers) {
if (const auto item = _session->data().message(localId)) { if (const auto item = _session->data().message(localId)) {
const auto media = Api::PrepareUploadedPhoto( const auto media = Api::PrepareUploadedPhoto(std::move(info));
file,
std::move(attachedStickers));
if (const auto groupId = item->groupId()) { if (const auto groupId = item->groupId()) {
uploadAlbumMedia(item, groupId, media); uploadAlbumMedia(item, groupId, media);
} else { } else {
@ -3980,19 +3977,15 @@ void ApiWrap::sendUploadedPhoto(
void ApiWrap::sendUploadedDocument( void ApiWrap::sendUploadedDocument(
FullMsgId localId, FullMsgId localId,
const MTPInputFile &file, Api::RemoteFileInfo info,
const std::optional<MTPInputFile> &thumb, Api::SendOptions options) {
Api::SendOptions options,
std::vector<MTPInputDocument> attachedStickers) {
if (const auto item = _session->data().message(localId)) { if (const auto item = _session->data().message(localId)) {
if (!item->media() || !item->media()->document()) { if (!item->media() || !item->media()->document()) {
return; return;
} }
const auto media = Api::PrepareUploadedDocument( const auto media = Api::PrepareUploadedDocument(
item, item,
file, std::move(info));
thumb,
std::move(attachedStickers));
const auto groupId = item->groupId(); const auto groupId = item->groupId();
if (groupId) { if (groupId) {
uploadAlbumMedia(item, groupId, media); uploadAlbumMedia(item, groupId, media);

View file

@ -357,15 +357,12 @@ public:
void sendUploadedPhoto( void sendUploadedPhoto(
FullMsgId localId, FullMsgId localId,
const MTPInputFile &file, Api::RemoteFileInfo info,
Api::SendOptions options, Api::SendOptions options);
std::vector<MTPInputDocument> attachedStickers);
void sendUploadedDocument( void sendUploadedDocument(
FullMsgId localId, FullMsgId localId,
const MTPInputFile &file, Api::RemoteFileInfo file,
const std::optional<MTPInputFile> &thumb, Api::SendOptions options);
Api::SendOptions options,
std::vector<MTPInputDocument> attachedStickers);
void cancelLocalItem(not_null<HistoryItem*> item); void cancelLocalItem(not_null<HistoryItem*> item);

View file

@ -158,40 +158,34 @@ Uploader::Uploader(not_null<ApiWrap*> api)
, _stopSessionsTimer([=] { stopSessions(); }) { , _stopSessionsTimer([=] { stopSessions(); }) {
const auto session = &_api->session(); const auto session = &_api->session();
photoReady( photoReady(
) | rpl::start_with_next([=](const UploadedPhoto &data) { ) | rpl::start_with_next([=](UploadedMedia &&data) {
if (data.edit) { if (data.edit) {
const auto item = session->data().message(data.fullId); const auto item = session->data().message(data.fullId);
Api::EditMessageWithUploadedPhoto( Api::EditMessageWithUploadedPhoto(
item, item,
data.file, std::move(data.info),
data.options, data.options);
data.attachedStickers);
} else { } else {
_api->sendUploadedPhoto( _api->sendUploadedPhoto(
data.fullId, data.fullId,
data.file, std::move(data.info),
data.options, data.options);
data.attachedStickers);
} }
}, _lifetime); }, _lifetime);
documentReady( documentReady(
) | rpl::start_with_next([=](const UploadedDocument &data) { ) | rpl::start_with_next([=](UploadedMedia &&data) {
if (data.edit) { if (data.edit) {
const auto item = session->data().message(data.fullId); const auto item = session->data().message(data.fullId);
Api::EditMessageWithUploadedDocument( Api::EditMessageWithUploadedDocument(
item, item,
data.file, std::move(data.info),
data.thumb, data.options);
data.options,
data.attachedStickers);
} else { } else {
_api->sendUploadedDocument( _api->sendUploadedDocument(
data.fullId, data.fullId,
data.file, std::move(data.info),
data.thumb, data.options);
data.options,
data.attachedStickers);
} }
}, _lifetime); }, _lifetime);
@ -472,11 +466,14 @@ void Uploader::sendNext() {
MTP_string(photoFilename), MTP_string(photoFilename),
MTP_bytes(md5)); MTP_bytes(md5));
_photoReady.fire({ _photoReady.fire({
uploadingId, .fullId = uploadingId,
options, .info = {
file, .file = file,
edit, .attachedStickers = attachedStickers,
attachedStickers }); },
.options = options,
.edit = edit,
});
} else if (uploadingData.type() == SendMediaType::File } else if (uploadingData.type() == SendMediaType::File
|| uploadingData.type() == SendMediaType::ThemeFile || uploadingData.type() == SendMediaType::ThemeFile
|| uploadingData.type() == SendMediaType::Audio) { || uploadingData.type() == SendMediaType::Audio) {
@ -510,12 +507,15 @@ void Uploader::sendNext() {
MTP_bytes(thumbMd5)); MTP_bytes(thumbMd5));
}(); }();
_documentReady.fire({ _documentReady.fire({
uploadingId, .fullId = uploadingId,
options, .info = {
file, .file = file,
thumb, .thumb = thumb,
edit, .attachedStickers = attachedStickers,
attachedStickers }); },
.options = options,
.edit = edit,
});
} else if (uploadingData.type() == SendMediaType::Secure) { } else if (uploadingData.type() == SendMediaType::Secure) {
_secureReady.fire({ _secureReady.fire({
uploadingId, uploadingId,

View file

@ -28,21 +28,11 @@ namespace Storage {
// MTP big files methods used for files greater than 10mb. // MTP big files methods used for files greater than 10mb.
constexpr auto kUseBigFilesFrom = 10 * 1024 * 1024; constexpr auto kUseBigFilesFrom = 10 * 1024 * 1024;
struct UploadedPhoto { struct UploadedMedia {
FullMsgId fullId; FullMsgId fullId;
Api::RemoteFileInfo info;
Api::SendOptions options; Api::SendOptions options;
MTPInputFile file;
bool edit = false; bool edit = false;
std::vector<MTPInputDocument> attachedStickers;
};
struct UploadedDocument {
FullMsgId fullId;
Api::SendOptions options;
MTPInputFile file;
std::optional<MTPInputFile> thumb;
bool edit = false;
std::vector<MTPInputDocument> attachedStickers;
}; };
struct UploadSecureProgress { struct UploadSecureProgress {
@ -75,10 +65,10 @@ public:
void clear(); void clear();
rpl::producer<UploadedPhoto> photoReady() const { rpl::producer<UploadedMedia> photoReady() const {
return _photoReady.events(); return _photoReady.events();
} }
rpl::producer<UploadedDocument> documentReady() const { rpl::producer<UploadedMedia> documentReady() const {
return _documentReady.events(); return _documentReady.events();
} }
rpl::producer<UploadSecureDone> secureReady() const { rpl::producer<UploadSecureDone> secureReady() const {
@ -138,8 +128,8 @@ private:
std::map<FullMsgId, File> uploaded; std::map<FullMsgId, File> uploaded;
base::Timer _nextTimer, _stopSessionsTimer; base::Timer _nextTimer, _stopSessionsTimer;
rpl::event_stream<UploadedPhoto> _photoReady; rpl::event_stream<UploadedMedia> _photoReady;
rpl::event_stream<UploadedDocument> _documentReady; rpl::event_stream<UploadedMedia> _documentReady;
rpl::event_stream<UploadSecureDone> _secureReady; rpl::event_stream<UploadSecureDone> _secureReady;
rpl::event_stream<FullMsgId> _photoProgress; rpl::event_stream<FullMsgId> _photoProgress;
rpl::event_stream<FullMsgId> _documentProgress; rpl::event_stream<FullMsgId> _documentProgress;

View file

@ -608,14 +608,14 @@ void ChatBackground::checkUploadWallPaper() {
return; return;
} }
_wallPaperUploadLifetime = _session->uploader().documentReady( _wallPaperUploadLifetime = _session->uploader().documentReady(
) | rpl::start_with_next([=](const Storage::UploadedDocument &data) { ) | rpl::start_with_next([=](const Storage::UploadedMedia &data) {
if (data.fullId != _wallPaperUploadId) { if (data.fullId != _wallPaperUploadId) {
return; return;
} }
_wallPaperUploadId = FullMsgId(); _wallPaperUploadId = FullMsgId();
_wallPaperRequestId = _session->api().request( _wallPaperRequestId = _session->api().request(
MTPaccount_UploadWallPaper( MTPaccount_UploadWallPaper(
data.file, data.info.file,
MTP_string("image/jpeg"), MTP_string("image/jpeg"),
_paper.mtpSettings() _paper.mtpSettings()
) )

View file

@ -465,7 +465,7 @@ Fn<void()> SavePreparedTheme(
Fn<void(SaveErrorType,QString)> fail) { Fn<void(SaveErrorType,QString)> fail) {
Expects(window->account().sessionExists()); Expects(window->account().sessionExists());
using Storage::UploadedDocument; using Storage::UploadedMedia;
struct State { struct State {
FullMsgId id; FullMsgId id;
bool generating = false; bool generating = false;
@ -548,11 +548,11 @@ Fn<void()> SavePreparedTheme(
}).send(); }).send();
}; };
const auto uploadTheme = [=](const UploadedDocument &data) { const auto uploadTheme = [=](const UploadedMedia &data) {
state->requestId = api->request(MTPaccount_UploadTheme( state->requestId = api->request(MTPaccount_UploadTheme(
MTP_flags(MTPaccount_UploadTheme::Flag::f_thumb), MTP_flags(MTPaccount_UploadTheme::Flag::f_thumb),
data.file, data.info.file,
*data.thumb, *data.info.thumb,
MTP_string(state->filename), MTP_string(state->filename),
MTP_string("application/x-tgtheme-tdesktop") MTP_string("application/x-tgtheme-tdesktop")
)).done([=](const MTPDocument &result) { )).done([=](const MTPDocument &result) {
@ -575,9 +575,9 @@ Fn<void()> SavePreparedTheme(
state->themeContent = theme; state->themeContent = theme;
session->uploader().documentReady( session->uploader().documentReady(
) | rpl::filter([=](const UploadedDocument &data) { ) | rpl::filter([=](const UploadedMedia &data) {
return (data.fullId == state->id) && data.thumb.has_value(); return (data.fullId == state->id) && data.info.thumb.has_value();
}) | rpl::start_with_next([=](const UploadedDocument &data) { }) | rpl::start_with_next([=](const UploadedMedia &data) {
uploadTheme(data); uploadTheme(data);
}, state->lifetime); }, state->lifetime);