mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-15 21:57:10 +02:00
Hide MTPInputFile in Api::RemoteFileInfo.
This commit is contained in:
parent
5d0445dd25
commit
3b2f6b893d
12 changed files with 93 additions and 117 deletions
|
@ -45,4 +45,10 @@ struct MessageToSend {
|
|||
WebPageId webPageId = 0;
|
||||
};
|
||||
|
||||
struct RemoteFileInfo {
|
||||
MTPInputFile file;
|
||||
std::optional<MTPInputFile> thumb;
|
||||
std::vector<MTPInputDocument> attachedStickers;
|
||||
};
|
||||
|
||||
} // namespace Api
|
||||
|
|
|
@ -172,33 +172,28 @@ void RescheduleMessage(
|
|||
|
||||
void EditMessageWithUploadedDocument(
|
||||
HistoryItem *item,
|
||||
const MTPInputFile &file,
|
||||
const std::optional<MTPInputFile> &thumb,
|
||||
SendOptions options,
|
||||
std::vector<MTPInputDocument> 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<MTPInputDocument> 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(
|
||||
|
|
|
@ -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<MTPInputFile> &thumb,
|
||||
SendOptions options,
|
||||
std::vector<MTPInputDocument> attachedStickers);
|
||||
RemoteFileInfo info,
|
||||
SendOptions options);
|
||||
|
||||
void EditMessageWithUploadedPhoto(
|
||||
HistoryItem *item,
|
||||
const MTPInputFile &file,
|
||||
SendOptions options,
|
||||
std::vector<MTPInputDocument> attachedStickers);
|
||||
RemoteFileInfo info,
|
||||
SendOptions options);
|
||||
|
||||
mtpRequestId EditCaption(
|
||||
not_null<HistoryItem*> item,
|
||||
|
|
|
@ -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<MTPDocumentAttribute> ComposeSendingDocumentAttributes(
|
|||
|
||||
} // namespace
|
||||
|
||||
MTPInputMedia PrepareUploadedPhoto(
|
||||
const MTPInputFile &file,
|
||||
std::vector<MTPInputDocument> 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<MTPInputDocument>(ranges::to<QVector>(attachedStickers)),
|
||||
info.file,
|
||||
MTP_vector<MTPInputDocument>(
|
||||
ranges::to<QVector>(info.attachedStickers)),
|
||||
MTP_int(0));
|
||||
}
|
||||
|
||||
MTPInputMedia PrepareUploadedDocument(
|
||||
not_null<HistoryItem*> item,
|
||||
const MTPInputFile &file,
|
||||
const std::optional<MTPInputFile> &thumb,
|
||||
std::vector<MTPInputDocument> 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<MTPInputDocument>(ranges::to<QVector>(attachedStickers)),
|
||||
MTP_vector<MTPInputDocument>(
|
||||
ranges::to<QVector>(info.attachedStickers)),
|
||||
MTP_int(0));
|
||||
}
|
||||
|
||||
|
|
|
@ -11,15 +11,13 @@ class HistoryItem;
|
|||
|
||||
namespace Api {
|
||||
|
||||
MTPInputMedia PrepareUploadedPhoto(
|
||||
const MTPInputFile &file,
|
||||
std::vector<MTPInputDocument> attachedStickers);
|
||||
struct RemoteFileInfo;
|
||||
|
||||
MTPInputMedia PrepareUploadedPhoto(RemoteFileInfo info);
|
||||
|
||||
MTPInputMedia PrepareUploadedDocument(
|
||||
not_null<HistoryItem*> item,
|
||||
const MTPInputFile &file,
|
||||
const std::optional<MTPInputFile> &thumb,
|
||||
std::vector<MTPInputDocument> attachedStickers);
|
||||
RemoteFileInfo info);
|
||||
|
||||
bool HasAttachedStickers(MTPInputMedia media);
|
||||
|
||||
|
|
|
@ -104,8 +104,8 @@ PeerPhoto::PeerPhoto(not_null<ApiWrap*> 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());
|
||||
});
|
||||
}
|
||||
|
|
|
@ -3963,13 +3963,10 @@ void ApiWrap::sendFile(
|
|||
|
||||
void ApiWrap::sendUploadedPhoto(
|
||||
FullMsgId localId,
|
||||
const MTPInputFile &file,
|
||||
Api::SendOptions options,
|
||||
std::vector<MTPInputDocument> 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<MTPInputFile> &thumb,
|
||||
Api::SendOptions options,
|
||||
std::vector<MTPInputDocument> 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);
|
||||
|
|
|
@ -357,15 +357,12 @@ public:
|
|||
|
||||
void sendUploadedPhoto(
|
||||
FullMsgId localId,
|
||||
const MTPInputFile &file,
|
||||
Api::SendOptions options,
|
||||
std::vector<MTPInputDocument> attachedStickers);
|
||||
Api::RemoteFileInfo info,
|
||||
Api::SendOptions options);
|
||||
void sendUploadedDocument(
|
||||
FullMsgId localId,
|
||||
const MTPInputFile &file,
|
||||
const std::optional<MTPInputFile> &thumb,
|
||||
Api::SendOptions options,
|
||||
std::vector<MTPInputDocument> attachedStickers);
|
||||
Api::RemoteFileInfo file,
|
||||
Api::SendOptions options);
|
||||
|
||||
void cancelLocalItem(not_null<HistoryItem*> item);
|
||||
|
||||
|
|
|
@ -158,40 +158,34 @@ Uploader::Uploader(not_null<ApiWrap*> 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,
|
||||
|
|
|
@ -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<MTPInputDocument> attachedStickers;
|
||||
};
|
||||
|
||||
struct UploadedDocument {
|
||||
FullMsgId fullId;
|
||||
Api::SendOptions options;
|
||||
MTPInputFile file;
|
||||
std::optional<MTPInputFile> thumb;
|
||||
bool edit = false;
|
||||
std::vector<MTPInputDocument> attachedStickers;
|
||||
};
|
||||
|
||||
struct UploadSecureProgress {
|
||||
|
@ -75,10 +65,10 @@ public:
|
|||
|
||||
void clear();
|
||||
|
||||
rpl::producer<UploadedPhoto> photoReady() const {
|
||||
rpl::producer<UploadedMedia> photoReady() const {
|
||||
return _photoReady.events();
|
||||
}
|
||||
rpl::producer<UploadedDocument> documentReady() const {
|
||||
rpl::producer<UploadedMedia> documentReady() const {
|
||||
return _documentReady.events();
|
||||
}
|
||||
rpl::producer<UploadSecureDone> secureReady() const {
|
||||
|
@ -138,8 +128,8 @@ private:
|
|||
std::map<FullMsgId, File> uploaded;
|
||||
base::Timer _nextTimer, _stopSessionsTimer;
|
||||
|
||||
rpl::event_stream<UploadedPhoto> _photoReady;
|
||||
rpl::event_stream<UploadedDocument> _documentReady;
|
||||
rpl::event_stream<UploadedMedia> _photoReady;
|
||||
rpl::event_stream<UploadedMedia> _documentReady;
|
||||
rpl::event_stream<UploadSecureDone> _secureReady;
|
||||
rpl::event_stream<FullMsgId> _photoProgress;
|
||||
rpl::event_stream<FullMsgId> _documentProgress;
|
||||
|
|
|
@ -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()
|
||||
)
|
||||
|
|
|
@ -465,7 +465,7 @@ Fn<void()> SavePreparedTheme(
|
|||
Fn<void(SaveErrorType,QString)> fail) {
|
||||
Expects(window->account().sessionExists());
|
||||
|
||||
using Storage::UploadedDocument;
|
||||
using Storage::UploadedMedia;
|
||||
struct State {
|
||||
FullMsgId id;
|
||||
bool generating = false;
|
||||
|
@ -548,11 +548,11 @@ Fn<void()> 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<void()> 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);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue