diff --git a/Telegram/SourceFiles/api/api_common.h b/Telegram/SourceFiles/api/api_common.h index 63ee24691..112727cc5 100644 --- a/Telegram/SourceFiles/api/api_common.h +++ b/Telegram/SourceFiles/api/api_common.h @@ -45,4 +45,10 @@ struct MessageToSend { WebPageId webPageId = 0; }; +struct RemoteFileInfo { + MTPInputFile file; + std::optional thumb; + std::vector attachedStickers; +}; + } // namespace Api diff --git a/Telegram/SourceFiles/api/api_editing.cpp b/Telegram/SourceFiles/api/api_editing.cpp index 2f083f389..46a120c54 100644 --- a/Telegram/SourceFiles/api/api_editing.cpp +++ b/Telegram/SourceFiles/api/api_editing.cpp @@ -172,33 +172,28 @@ void RescheduleMessage( void EditMessageWithUploadedDocument( HistoryItem *item, - const MTPInputFile &file, - const std::optional &thumb, - SendOptions options, - std::vector attachedStickers) { + RemoteFileInfo info, + SendOptions options) { if (!item || !item->media() || !item->media()->document()) { return; } - const auto media = PrepareUploadedDocument( + EditMessageWithUploadedMedia( item, - file, - thumb, - std::move(attachedStickers)); - EditMessageWithUploadedMedia(item, options, media); + options, + PrepareUploadedDocument(item, std::move(info))); } void EditMessageWithUploadedPhoto( HistoryItem *item, - const MTPInputFile &file, - SendOptions options, - std::vector attachedStickers) { + RemoteFileInfo info, + SendOptions options) { if (!item || !item->media() || !item->media()->photo()) { return; } - const auto media = PrepareUploadedPhoto( - file, - std::move(attachedStickers)); - EditMessageWithUploadedMedia(item, options, media); + EditMessageWithUploadedMedia( + item, + options, + PrepareUploadedPhoto(std::move(info))); } mtpRequestId EditCaption( diff --git a/Telegram/SourceFiles/api/api_editing.h b/Telegram/SourceFiles/api/api_editing.h index 87200cde2..4a80e9dae 100644 --- a/Telegram/SourceFiles/api/api_editing.h +++ b/Telegram/SourceFiles/api/api_editing.h @@ -16,6 +16,7 @@ class Error; namespace Api { struct SendOptions; +struct RemoteFileInfo; const auto kDefaultEditMessagesErrors = { u"MESSAGE_ID_INVALID"_q, @@ -29,16 +30,13 @@ void RescheduleMessage( void EditMessageWithUploadedDocument( HistoryItem *item, - const MTPInputFile &file, - const std::optional &thumb, - SendOptions options, - std::vector attachedStickers); + RemoteFileInfo info, + SendOptions options); void EditMessageWithUploadedPhoto( HistoryItem *item, - const MTPInputFile &file, - SendOptions options, - std::vector attachedStickers); + RemoteFileInfo info, + SendOptions options); mtpRequestId EditCaption( not_null item, diff --git a/Telegram/SourceFiles/api/api_media.cpp b/Telegram/SourceFiles/api/api_media.cpp index 517389d13..6038060f7 100644 --- a/Telegram/SourceFiles/api/api_media.cpp +++ b/Telegram/SourceFiles/api/api_media.cpp @@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "api/api_media.h" +#include "api/api_common.h" #include "data/data_document.h" #include "data/stickers/data_stickers_set.h" #include "history/history_item.h" @@ -74,41 +75,39 @@ MTPVector ComposeSendingDocumentAttributes( } // namespace -MTPInputMedia PrepareUploadedPhoto( - const MTPInputFile &file, - std::vector attachedStickers) { - const auto flags = attachedStickers.empty() +MTPInputMedia PrepareUploadedPhoto(RemoteFileInfo info) { + const auto flags = info.attachedStickers.empty() ? MTPDinputMediaUploadedPhoto::Flags(0) : MTPDinputMediaUploadedPhoto::Flag::f_stickers; return MTP_inputMediaUploadedPhoto( MTP_flags(flags), - file, - MTP_vector(ranges::to(attachedStickers)), + info.file, + MTP_vector( + ranges::to(info.attachedStickers)), MTP_int(0)); } MTPInputMedia PrepareUploadedDocument( not_null item, - const MTPInputFile &file, - const std::optional &thumb, - std::vector attachedStickers) { + RemoteFileInfo info) { if (!item || !item->media() || !item->media()->document()) { return MTP_inputMediaEmpty(); } const auto emptyFlag = MTPDinputMediaUploadedDocument::Flags(0); using DocFlags = MTPDinputMediaUploadedDocument::Flag; const auto flags = emptyFlag - | (thumb ? DocFlags::f_thumb : emptyFlag) + | (info.thumb ? DocFlags::f_thumb : 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(); return MTP_inputMediaUploadedDocument( MTP_flags(flags), - file, - thumb.value_or(MTPInputFile()), + info.file, + info.thumb.value_or(MTPInputFile()), MTP_string(document->mimeString()), ComposeSendingDocumentAttributes(document), - MTP_vector(ranges::to(attachedStickers)), + MTP_vector( + ranges::to(info.attachedStickers)), MTP_int(0)); } diff --git a/Telegram/SourceFiles/api/api_media.h b/Telegram/SourceFiles/api/api_media.h index d9dbaefb2..b9f744856 100644 --- a/Telegram/SourceFiles/api/api_media.h +++ b/Telegram/SourceFiles/api/api_media.h @@ -11,15 +11,13 @@ class HistoryItem; namespace Api { -MTPInputMedia PrepareUploadedPhoto( - const MTPInputFile &file, - std::vector attachedStickers); +struct RemoteFileInfo; + +MTPInputMedia PrepareUploadedPhoto(RemoteFileInfo info); MTPInputMedia PrepareUploadedDocument( not_null item, - const MTPInputFile &file, - const std::optional &thumb, - std::vector attachedStickers); + RemoteFileInfo info); bool HasAttachedStickers(MTPInputMedia media); diff --git a/Telegram/SourceFiles/api/api_peer_photo.cpp b/Telegram/SourceFiles/api/api_peer_photo.cpp index 1d75b38dc..28f47583f 100644 --- a/Telegram/SourceFiles/api/api_peer_photo.cpp +++ b/Telegram/SourceFiles/api/api_peer_photo.cpp @@ -104,8 +104,8 @@ PeerPhoto::PeerPhoto(not_null api) // You can't use _session->lifetime() in the constructor, // only queued, because it is not constructed yet. _session->uploader().photoReady( - ) | rpl::start_with_next([=](const Storage::UploadedPhoto &data) { - ready(data.fullId, data.file); + ) | rpl::start_with_next([=](const Storage::UploadedMedia &data) { + ready(data.fullId, data.info.file); }, _session->lifetime()); }); } diff --git a/Telegram/SourceFiles/apiwrap.cpp b/Telegram/SourceFiles/apiwrap.cpp index 011ae8a65..49d5eb682 100644 --- a/Telegram/SourceFiles/apiwrap.cpp +++ b/Telegram/SourceFiles/apiwrap.cpp @@ -3963,13 +3963,10 @@ void ApiWrap::sendFile( void ApiWrap::sendUploadedPhoto( FullMsgId localId, - const MTPInputFile &file, - Api::SendOptions options, - std::vector attachedStickers) { + Api::RemoteFileInfo info, + Api::SendOptions options) { if (const auto item = _session->data().message(localId)) { - const auto media = Api::PrepareUploadedPhoto( - file, - std::move(attachedStickers)); + const auto media = Api::PrepareUploadedPhoto(std::move(info)); if (const auto groupId = item->groupId()) { uploadAlbumMedia(item, groupId, media); } else { @@ -3980,19 +3977,15 @@ void ApiWrap::sendUploadedPhoto( void ApiWrap::sendUploadedDocument( FullMsgId localId, - const MTPInputFile &file, - const std::optional &thumb, - Api::SendOptions options, - std::vector attachedStickers) { + Api::RemoteFileInfo info, + Api::SendOptions options) { if (const auto item = _session->data().message(localId)) { if (!item->media() || !item->media()->document()) { return; } const auto media = Api::PrepareUploadedDocument( item, - file, - thumb, - std::move(attachedStickers)); + std::move(info)); const auto groupId = item->groupId(); if (groupId) { uploadAlbumMedia(item, groupId, media); diff --git a/Telegram/SourceFiles/apiwrap.h b/Telegram/SourceFiles/apiwrap.h index 461d1327b..6fced4cc2 100644 --- a/Telegram/SourceFiles/apiwrap.h +++ b/Telegram/SourceFiles/apiwrap.h @@ -357,15 +357,12 @@ public: void sendUploadedPhoto( FullMsgId localId, - const MTPInputFile &file, - Api::SendOptions options, - std::vector attachedStickers); + Api::RemoteFileInfo info, + Api::SendOptions options); void sendUploadedDocument( FullMsgId localId, - const MTPInputFile &file, - const std::optional &thumb, - Api::SendOptions options, - std::vector attachedStickers); + Api::RemoteFileInfo file, + Api::SendOptions options); void cancelLocalItem(not_null item); diff --git a/Telegram/SourceFiles/storage/file_upload.cpp b/Telegram/SourceFiles/storage/file_upload.cpp index c06146225..664c8e0cb 100644 --- a/Telegram/SourceFiles/storage/file_upload.cpp +++ b/Telegram/SourceFiles/storage/file_upload.cpp @@ -158,40 +158,34 @@ Uploader::Uploader(not_null api) , _stopSessionsTimer([=] { stopSessions(); }) { const auto session = &_api->session(); photoReady( - ) | rpl::start_with_next([=](const UploadedPhoto &data) { + ) | rpl::start_with_next([=](UploadedMedia &&data) { if (data.edit) { const auto item = session->data().message(data.fullId); Api::EditMessageWithUploadedPhoto( item, - data.file, - data.options, - data.attachedStickers); + std::move(data.info), + data.options); } else { _api->sendUploadedPhoto( data.fullId, - data.file, - data.options, - data.attachedStickers); + std::move(data.info), + data.options); } }, _lifetime); documentReady( - ) | rpl::start_with_next([=](const UploadedDocument &data) { + ) | rpl::start_with_next([=](UploadedMedia &&data) { if (data.edit) { const auto item = session->data().message(data.fullId); Api::EditMessageWithUploadedDocument( item, - data.file, - data.thumb, - data.options, - data.attachedStickers); + std::move(data.info), + data.options); } else { _api->sendUploadedDocument( data.fullId, - data.file, - data.thumb, - data.options, - data.attachedStickers); + std::move(data.info), + data.options); } }, _lifetime); @@ -472,11 +466,14 @@ void Uploader::sendNext() { MTP_string(photoFilename), MTP_bytes(md5)); _photoReady.fire({ - uploadingId, - options, - file, - edit, - attachedStickers }); + .fullId = uploadingId, + .info = { + .file = file, + .attachedStickers = attachedStickers, + }, + .options = options, + .edit = edit, + }); } else if (uploadingData.type() == SendMediaType::File || uploadingData.type() == SendMediaType::ThemeFile || uploadingData.type() == SendMediaType::Audio) { @@ -510,12 +507,15 @@ void Uploader::sendNext() { MTP_bytes(thumbMd5)); }(); _documentReady.fire({ - uploadingId, - options, - file, - thumb, - edit, - attachedStickers }); + .fullId = uploadingId, + .info = { + .file = file, + .thumb = thumb, + .attachedStickers = attachedStickers, + }, + .options = options, + .edit = edit, + }); } else if (uploadingData.type() == SendMediaType::Secure) { _secureReady.fire({ uploadingId, diff --git a/Telegram/SourceFiles/storage/file_upload.h b/Telegram/SourceFiles/storage/file_upload.h index 521adc05b..5bb893f92 100644 --- a/Telegram/SourceFiles/storage/file_upload.h +++ b/Telegram/SourceFiles/storage/file_upload.h @@ -28,21 +28,11 @@ namespace Storage { // MTP big files methods used for files greater than 10mb. constexpr auto kUseBigFilesFrom = 10 * 1024 * 1024; -struct UploadedPhoto { +struct UploadedMedia { FullMsgId fullId; + Api::RemoteFileInfo info; Api::SendOptions options; - MTPInputFile file; bool edit = false; - std::vector attachedStickers; -}; - -struct UploadedDocument { - FullMsgId fullId; - Api::SendOptions options; - MTPInputFile file; - std::optional thumb; - bool edit = false; - std::vector attachedStickers; }; struct UploadSecureProgress { @@ -75,10 +65,10 @@ public: void clear(); - rpl::producer photoReady() const { + rpl::producer photoReady() const { return _photoReady.events(); } - rpl::producer documentReady() const { + rpl::producer documentReady() const { return _documentReady.events(); } rpl::producer secureReady() const { @@ -138,8 +128,8 @@ private: std::map uploaded; base::Timer _nextTimer, _stopSessionsTimer; - rpl::event_stream _photoReady; - rpl::event_stream _documentReady; + rpl::event_stream _photoReady; + rpl::event_stream _documentReady; rpl::event_stream _secureReady; rpl::event_stream _photoProgress; rpl::event_stream _documentProgress; diff --git a/Telegram/SourceFiles/window/themes/window_theme.cpp b/Telegram/SourceFiles/window/themes/window_theme.cpp index 3813ac809..24f9aca68 100644 --- a/Telegram/SourceFiles/window/themes/window_theme.cpp +++ b/Telegram/SourceFiles/window/themes/window_theme.cpp @@ -608,14 +608,14 @@ void ChatBackground::checkUploadWallPaper() { return; } _wallPaperUploadLifetime = _session->uploader().documentReady( - ) | rpl::start_with_next([=](const Storage::UploadedDocument &data) { + ) | rpl::start_with_next([=](const Storage::UploadedMedia &data) { if (data.fullId != _wallPaperUploadId) { return; } _wallPaperUploadId = FullMsgId(); _wallPaperRequestId = _session->api().request( MTPaccount_UploadWallPaper( - data.file, + data.info.file, MTP_string("image/jpeg"), _paper.mtpSettings() ) diff --git a/Telegram/SourceFiles/window/themes/window_theme_editor_box.cpp b/Telegram/SourceFiles/window/themes/window_theme_editor_box.cpp index b92defa50..3f736ba09 100644 --- a/Telegram/SourceFiles/window/themes/window_theme_editor_box.cpp +++ b/Telegram/SourceFiles/window/themes/window_theme_editor_box.cpp @@ -465,7 +465,7 @@ Fn SavePreparedTheme( Fn fail) { Expects(window->account().sessionExists()); - using Storage::UploadedDocument; + using Storage::UploadedMedia; struct State { FullMsgId id; bool generating = false; @@ -548,11 +548,11 @@ Fn SavePreparedTheme( }).send(); }; - const auto uploadTheme = [=](const UploadedDocument &data) { + const auto uploadTheme = [=](const UploadedMedia &data) { state->requestId = api->request(MTPaccount_UploadTheme( MTP_flags(MTPaccount_UploadTheme::Flag::f_thumb), - data.file, - *data.thumb, + data.info.file, + *data.info.thumb, MTP_string(state->filename), MTP_string("application/x-tgtheme-tdesktop") )).done([=](const MTPDocument &result) { @@ -575,9 +575,9 @@ Fn SavePreparedTheme( state->themeContent = theme; session->uploader().documentReady( - ) | rpl::filter([=](const UploadedDocument &data) { - return (data.fullId == state->id) && data.thumb.has_value(); - }) | rpl::start_with_next([=](const UploadedDocument &data) { + ) | rpl::filter([=](const UploadedMedia &data) { + return (data.fullId == state->id) && data.info.thumb.has_value(); + }) | rpl::start_with_next([=](const UploadedMedia &data) { uploadTheme(data); }, state->lifetime);