2014-05-30 08:53:19 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2014-05-30 08:53:19 +00:00
|
|
|
*/
|
2017-03-04 10:23:56 +00:00
|
|
|
#include "storage/file_upload.h"
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2020-05-28 13:42:50 +00:00
|
|
|
#include "api/api_editing.h"
|
2020-07-06 09:58:18 +00:00
|
|
|
#include "api/api_send_progress.h"
|
2017-12-19 16:57:42 +00:00
|
|
|
#include "storage/localimageloader.h"
|
2018-09-04 19:33:57 +00:00
|
|
|
#include "storage/file_download.h"
|
2017-09-26 11:49:16 +00:00
|
|
|
#include "data/data_document.h"
|
2020-03-27 11:40:50 +00:00
|
|
|
#include "data/data_document_media.h"
|
2017-09-26 11:49:16 +00:00
|
|
|
#include "data/data_photo.h"
|
2018-01-17 16:21:01 +00:00
|
|
|
#include "data/data_session.h"
|
2020-04-16 12:37:26 +00:00
|
|
|
#include "ui/image/image_location_factory.h"
|
2020-07-06 09:58:18 +00:00
|
|
|
#include "history/history_item.h"
|
2020-09-29 08:36:30 +00:00
|
|
|
#include "history/history.h"
|
2020-10-13 16:43:18 +00:00
|
|
|
#include "core/file_location.h"
|
2020-04-16 12:37:26 +00:00
|
|
|
#include "core/mime_type.h"
|
2019-07-24 11:45:24 +00:00
|
|
|
#include "main/main_session.h"
|
2020-06-08 15:17:33 +00:00
|
|
|
#include "apiwrap.h"
|
2017-09-26 11:49:16 +00:00
|
|
|
|
2017-08-04 14:54:32 +00:00
|
|
|
namespace Storage {
|
2017-03-23 16:11:35 +00:00
|
|
|
namespace {
|
|
|
|
|
2019-01-18 11:26:43 +00:00
|
|
|
// max 512kb uploaded at the same time in each session
|
|
|
|
constexpr auto kMaxUploadFileParallelSize = MTP::kUploadSessionsCount * 512 * 1024;
|
|
|
|
|
2022-06-17 20:00:56 +00:00
|
|
|
constexpr auto kDocumentMaxPartsCountDefault = 4000;
|
2019-01-18 11:26:43 +00:00
|
|
|
|
|
|
|
// 32kb for tiny document ( < 1mb )
|
|
|
|
constexpr auto kDocumentUploadPartSize0 = 32 * 1024;
|
|
|
|
|
|
|
|
// 64kb for little document ( <= 32mb )
|
|
|
|
constexpr auto kDocumentUploadPartSize1 = 64 * 1024;
|
|
|
|
|
|
|
|
// 128kb for small document ( <= 375mb )
|
|
|
|
constexpr auto kDocumentUploadPartSize2 = 128 * 1024;
|
|
|
|
|
|
|
|
// 256kb for medium document ( <= 750mb )
|
|
|
|
constexpr auto kDocumentUploadPartSize3 = 256 * 1024;
|
|
|
|
|
|
|
|
// 512kb for large document ( <= 1500mb )
|
|
|
|
constexpr auto kDocumentUploadPartSize4 = 512 * 1024;
|
|
|
|
|
|
|
|
// One part each half second, if not uploaded faster.
|
2019-02-19 06:57:53 +00:00
|
|
|
constexpr auto kUploadRequestInterval = crl::time(500);
|
2017-03-23 16:11:35 +00:00
|
|
|
|
2019-01-21 13:42:21 +00:00
|
|
|
// How much time without upload causes additional session kill.
|
2019-12-02 13:10:19 +00:00
|
|
|
constexpr auto kKillSessionTimeout = 15 * crl::time(000);
|
2019-01-21 13:42:21 +00:00
|
|
|
|
2020-04-16 12:37:26 +00:00
|
|
|
[[nodiscard]] const char *ThumbnailFormat(const QString &mime) {
|
|
|
|
return Core::IsMimeSticker(mime) ? "WEBP" : "JPG";
|
|
|
|
}
|
|
|
|
|
2017-03-23 16:11:35 +00:00
|
|
|
} // namespace
|
|
|
|
|
2017-12-19 16:57:42 +00:00
|
|
|
struct Uploader::File {
|
|
|
|
File(const SendMediaReady &media);
|
|
|
|
File(const std::shared_ptr<FileLoadResult> &file);
|
|
|
|
|
2022-05-10 14:22:28 +00:00
|
|
|
void setDocSize(int64 size);
|
2017-12-19 16:57:42 +00:00
|
|
|
bool setPartSize(uint32 partSize);
|
|
|
|
|
|
|
|
std::shared_ptr<FileLoadResult> file;
|
|
|
|
SendMediaReady media;
|
2018-03-28 20:40:42 +00:00
|
|
|
int32 partsCount = 0;
|
2022-05-10 14:22:28 +00:00
|
|
|
mutable int64 fileSentSize = 0;
|
2017-12-19 16:57:42 +00:00
|
|
|
|
|
|
|
uint64 id() const;
|
|
|
|
SendMediaType type() const;
|
|
|
|
uint64 thumbId() const;
|
|
|
|
const QString &filename() const;
|
|
|
|
|
|
|
|
HashMd5 md5Hash;
|
|
|
|
|
|
|
|
std::unique_ptr<QFile> docFile;
|
2022-05-10 14:22:28 +00:00
|
|
|
int64 docSize = 0;
|
|
|
|
int64 docPartSize = 0;
|
|
|
|
int docSentParts = 0;
|
|
|
|
int docPartsCount = 0;
|
2017-12-19 16:57:42 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
Uploader::File::File(const SendMediaReady &media) : media(media) {
|
|
|
|
partsCount = media.parts.size();
|
2019-02-08 16:20:08 +00:00
|
|
|
if (type() == SendMediaType::File
|
2019-09-03 08:25:19 +00:00
|
|
|
|| type() == SendMediaType::ThemeFile
|
2019-02-08 16:20:08 +00:00
|
|
|
|| type() == SendMediaType::Audio) {
|
2017-12-19 16:57:42 +00:00
|
|
|
setDocSize(media.file.isEmpty()
|
|
|
|
? media.data.size()
|
|
|
|
: media.filesize);
|
|
|
|
} else {
|
|
|
|
docSize = docPartSize = docPartsCount = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Uploader::File::File(const std::shared_ptr<FileLoadResult> &file)
|
|
|
|
: file(file) {
|
2018-03-25 11:37:57 +00:00
|
|
|
partsCount = (type() == SendMediaType::Photo
|
|
|
|
|| type() == SendMediaType::Secure)
|
2017-12-19 16:57:42 +00:00
|
|
|
? file->fileparts.size()
|
|
|
|
: file->thumbparts.size();
|
2019-02-08 16:20:08 +00:00
|
|
|
if (type() == SendMediaType::File
|
2019-09-03 08:25:19 +00:00
|
|
|
|| type() == SendMediaType::ThemeFile
|
2019-02-08 16:20:08 +00:00
|
|
|
|| type() == SendMediaType::Audio) {
|
2017-12-19 16:57:42 +00:00
|
|
|
setDocSize(file->filesize);
|
|
|
|
} else {
|
|
|
|
docSize = docPartSize = docPartsCount = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-10 14:22:28 +00:00
|
|
|
void Uploader::File::setDocSize(int64 size) {
|
2017-12-19 16:57:42 +00:00
|
|
|
docSize = size;
|
|
|
|
constexpr auto limit0 = 1024 * 1024;
|
|
|
|
constexpr auto limit1 = 32 * limit0;
|
2019-01-18 11:26:43 +00:00
|
|
|
if (docSize >= limit0 || !setPartSize(kDocumentUploadPartSize0)) {
|
|
|
|
if (docSize > limit1 || !setPartSize(kDocumentUploadPartSize1)) {
|
|
|
|
if (!setPartSize(kDocumentUploadPartSize2)) {
|
|
|
|
if (!setPartSize(kDocumentUploadPartSize3)) {
|
2022-06-17 20:00:56 +00:00
|
|
|
setPartSize(kDocumentUploadPartSize4);
|
2017-12-19 16:57:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Uploader::File::setPartSize(uint32 partSize) {
|
|
|
|
docPartSize = partSize;
|
|
|
|
docPartsCount = (docSize / docPartSize)
|
|
|
|
+ ((docSize % docPartSize) ? 1 : 0);
|
2022-06-17 20:00:56 +00:00
|
|
|
return (docPartsCount <= kDocumentMaxPartsCountDefault);
|
2017-12-19 16:57:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint64 Uploader::File::id() const {
|
|
|
|
return file ? file->id : media.id;
|
|
|
|
}
|
|
|
|
|
|
|
|
SendMediaType Uploader::File::type() const {
|
|
|
|
return file ? file->type : media.type;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64 Uploader::File::thumbId() const {
|
|
|
|
return file ? file->thumbId : media.thumbId;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QString &Uploader::File::filename() const {
|
|
|
|
return file ? file->filename : media.filename;
|
|
|
|
}
|
|
|
|
|
2019-04-12 10:50:41 +00:00
|
|
|
Uploader::Uploader(not_null<ApiWrap*> api)
|
2021-03-09 09:33:33 +00:00
|
|
|
: _api(api)
|
|
|
|
, _nextTimer([=] { sendNext(); })
|
|
|
|
, _stopSessionsTimer([=] { stopSessions(); }) {
|
2020-05-28 13:42:50 +00:00
|
|
|
const auto session = &_api->session();
|
2020-07-06 09:58:18 +00:00
|
|
|
photoReady(
|
2021-11-16 12:38:31 +00:00
|
|
|
) | rpl::start_with_next([=](UploadedMedia &&data) {
|
2020-07-06 09:58:18 +00:00
|
|
|
if (data.edit) {
|
2020-05-28 13:42:50 +00:00
|
|
|
const auto item = session->data().message(data.fullId);
|
2021-03-14 09:46:17 +00:00
|
|
|
Api::EditMessageWithUploadedPhoto(
|
|
|
|
item,
|
2021-11-16 12:38:31 +00:00
|
|
|
std::move(data.info),
|
|
|
|
data.options);
|
2020-07-06 09:58:18 +00:00
|
|
|
} else {
|
|
|
|
_api->sendUploadedPhoto(
|
|
|
|
data.fullId,
|
2021-11-16 12:38:31 +00:00
|
|
|
std::move(data.info),
|
|
|
|
data.options);
|
2020-07-06 09:58:18 +00:00
|
|
|
}
|
|
|
|
}, _lifetime);
|
|
|
|
|
|
|
|
documentReady(
|
2021-11-16 12:38:31 +00:00
|
|
|
) | rpl::start_with_next([=](UploadedMedia &&data) {
|
2020-07-06 09:58:18 +00:00
|
|
|
if (data.edit) {
|
2020-05-28 13:42:50 +00:00
|
|
|
const auto item = session->data().message(data.fullId);
|
|
|
|
Api::EditMessageWithUploadedDocument(
|
|
|
|
item,
|
2021-11-16 12:38:31 +00:00
|
|
|
std::move(data.info),
|
|
|
|
data.options);
|
2020-07-06 09:58:18 +00:00
|
|
|
} else {
|
|
|
|
_api->sendUploadedDocument(
|
|
|
|
data.fullId,
|
2021-11-16 12:38:31 +00:00
|
|
|
std::move(data.info),
|
|
|
|
data.options);
|
2020-07-06 09:58:18 +00:00
|
|
|
}
|
|
|
|
}, _lifetime);
|
|
|
|
|
|
|
|
photoProgress(
|
|
|
|
) | rpl::start_with_next([=](const FullMsgId &fullId) {
|
|
|
|
processPhotoProgress(fullId);
|
|
|
|
}, _lifetime);
|
|
|
|
|
|
|
|
photoFailed(
|
|
|
|
) | rpl::start_with_next([=](const FullMsgId &fullId) {
|
|
|
|
processPhotoFailed(fullId);
|
|
|
|
}, _lifetime);
|
|
|
|
|
|
|
|
documentProgress(
|
|
|
|
) | rpl::start_with_next([=](const FullMsgId &fullId) {
|
|
|
|
processDocumentProgress(fullId);
|
|
|
|
}, _lifetime);
|
|
|
|
|
|
|
|
documentFailed(
|
|
|
|
) | rpl::start_with_next([=](const FullMsgId &fullId) {
|
|
|
|
processDocumentFailed(fullId);
|
|
|
|
}, _lifetime);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Uploader::processPhotoProgress(const FullMsgId &newId) {
|
|
|
|
const auto session = &_api->session();
|
|
|
|
if (const auto item = session->data().message(newId)) {
|
2020-09-29 08:36:30 +00:00
|
|
|
sendProgressUpdate(item, Api::SendProgressType::UploadPhoto);
|
2020-07-06 09:58:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Uploader::processDocumentProgress(const FullMsgId &newId) {
|
|
|
|
const auto session = &_api->session();
|
|
|
|
if (const auto item = session->data().message(newId)) {
|
|
|
|
const auto media = item->media();
|
|
|
|
const auto document = media ? media->document() : nullptr;
|
|
|
|
const auto sendAction = (document && document->isVoiceMessage())
|
|
|
|
? Api::SendProgressType::UploadVoice
|
|
|
|
: Api::SendProgressType::UploadFile;
|
|
|
|
const auto progress = (document && document->uploading())
|
2022-05-10 14:22:28 +00:00
|
|
|
? ((document->uploadingData->offset * 100)
|
|
|
|
/ document->uploadingData->size)
|
2020-07-06 09:58:18 +00:00
|
|
|
: 0;
|
2020-09-29 08:36:30 +00:00
|
|
|
sendProgressUpdate(item, sendAction, progress);
|
2020-07-06 09:58:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Uploader::processPhotoFailed(const FullMsgId &newId) {
|
|
|
|
const auto session = &_api->session();
|
|
|
|
if (const auto item = session->data().message(newId)) {
|
2020-09-29 08:36:30 +00:00
|
|
|
sendProgressUpdate(item, Api::SendProgressType::UploadPhoto, -1);
|
2020-07-06 09:58:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Uploader::processDocumentFailed(const FullMsgId &newId) {
|
|
|
|
const auto session = &_api->session();
|
|
|
|
if (const auto item = session->data().message(newId)) {
|
|
|
|
const auto media = item->media();
|
|
|
|
const auto document = media ? media->document() : nullptr;
|
|
|
|
const auto sendAction = (document && document->isVoiceMessage())
|
|
|
|
? Api::SendProgressType::UploadVoice
|
|
|
|
: Api::SendProgressType::UploadFile;
|
2020-09-29 08:36:30 +00:00
|
|
|
sendProgressUpdate(item, sendAction, -1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Uploader::sendProgressUpdate(
|
|
|
|
not_null<HistoryItem*> item,
|
|
|
|
Api::SendProgressType type,
|
|
|
|
int progress) {
|
|
|
|
const auto history = item->history();
|
|
|
|
auto &manager = _api->session().sendProgressManager();
|
|
|
|
manager.update(history, type, progress);
|
|
|
|
if (const auto replyTo = item->replyToTop()) {
|
|
|
|
if (history->peer->isMegagroup()) {
|
|
|
|
manager.update(history, replyTo, type, progress);
|
|
|
|
}
|
2020-07-06 09:58:18 +00:00
|
|
|
}
|
2020-09-29 08:36:30 +00:00
|
|
|
_api->session().data().requestItemRepaint(item);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2020-06-08 15:17:33 +00:00
|
|
|
Uploader::~Uploader() {
|
|
|
|
clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
Main::Session &Uploader::session() const {
|
|
|
|
return _api->session();
|
|
|
|
}
|
|
|
|
|
2019-01-18 12:27:37 +00:00
|
|
|
void Uploader::uploadMedia(
|
|
|
|
const FullMsgId &msgId,
|
|
|
|
const SendMediaReady &media) {
|
2016-11-28 15:45:07 +00:00
|
|
|
if (media.type == SendMediaType::Photo) {
|
2020-06-08 15:17:33 +00:00
|
|
|
session().data().processPhoto(media.photo, media.photoThumbs);
|
2019-01-18 12:27:37 +00:00
|
|
|
} else if (media.type == SendMediaType::File
|
2019-09-03 08:25:19 +00:00
|
|
|
|| media.type == SendMediaType::ThemeFile
|
2019-01-18 12:27:37 +00:00
|
|
|
|| media.type == SendMediaType::Audio) {
|
2019-01-25 14:37:28 +00:00
|
|
|
const auto document = media.photoThumbs.empty()
|
2020-06-08 15:17:33 +00:00
|
|
|
? session().data().processDocument(media.document)
|
|
|
|
: session().data().processDocument(
|
2018-10-12 16:41:51 +00:00
|
|
|
media.document,
|
2020-04-16 12:37:26 +00:00
|
|
|
Images::FromImageInMemory(
|
2020-08-26 13:28:56 +00:00
|
|
|
media.photoThumbs.front().second.image,
|
|
|
|
"JPG",
|
|
|
|
media.photoThumbs.front().second.bytes));
|
2016-02-12 16:35:06 +00:00
|
|
|
if (!media.data.isEmpty()) {
|
2019-09-06 11:33:51 +00:00
|
|
|
document->setDataAndCache(media.data);
|
2019-09-03 08:25:19 +00:00
|
|
|
if (media.type == SendMediaType::ThemeFile) {
|
2019-02-08 16:20:08 +00:00
|
|
|
document->checkWallPaperProperties();
|
|
|
|
}
|
2016-02-12 16:35:06 +00:00
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
if (!media.file.isEmpty()) {
|
2020-10-13 16:43:18 +00:00
|
|
|
document->setLocation(Core::FileLocation(media.file));
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
2017-12-18 10:38:14 +00:00
|
|
|
queue.emplace(msgId, File(media));
|
2014-05-30 08:53:19 +00:00
|
|
|
sendNext();
|
|
|
|
}
|
|
|
|
|
2017-12-19 16:57:42 +00:00
|
|
|
void Uploader::upload(
|
|
|
|
const FullMsgId &msgId,
|
|
|
|
const std::shared_ptr<FileLoadResult> &file) {
|
2016-11-28 15:45:07 +00:00
|
|
|
if (file->type == SendMediaType::Photo) {
|
2020-06-08 15:17:33 +00:00
|
|
|
const auto photo = session().data().processPhoto(
|
2019-01-18 12:27:37 +00:00
|
|
|
file->photo,
|
|
|
|
file->photoThumbs);
|
|
|
|
photo->uploadingData = std::make_unique<Data::UploadState>(
|
|
|
|
file->partssize);
|
|
|
|
} else if (file->type == SendMediaType::File
|
2019-09-03 08:25:19 +00:00
|
|
|
|| file->type == SendMediaType::ThemeFile
|
2019-01-18 12:27:37 +00:00
|
|
|
|| file->type == SendMediaType::Audio) {
|
|
|
|
const auto document = file->thumb.isNull()
|
2020-06-08 15:17:33 +00:00
|
|
|
? session().data().processDocument(file->document)
|
|
|
|
: session().data().processDocument(
|
2018-10-12 16:41:51 +00:00
|
|
|
file->document,
|
2020-04-16 12:37:26 +00:00
|
|
|
Images::FromImageInMemory(
|
|
|
|
file->thumb,
|
2020-08-26 13:28:56 +00:00
|
|
|
ThumbnailFormat(file->filemime),
|
|
|
|
file->thumbbytes));
|
2019-01-18 12:27:37 +00:00
|
|
|
document->uploadingData = std::make_unique<Data::UploadState>(
|
|
|
|
document->size);
|
2020-04-16 12:37:26 +00:00
|
|
|
if (const auto active = document->activeMediaView()) {
|
|
|
|
if (!file->goodThumbnail.isNull()) {
|
2020-03-27 11:40:50 +00:00
|
|
|
active->setGoodThumbnail(std::move(file->goodThumbnail));
|
|
|
|
}
|
2020-04-16 12:37:26 +00:00
|
|
|
if (!file->thumb.isNull()) {
|
|
|
|
active->setThumbnail(file->thumb);
|
|
|
|
}
|
2020-03-27 11:40:50 +00:00
|
|
|
}
|
|
|
|
if (!file->goodThumbnailBytes.isEmpty()) {
|
|
|
|
document->owner().cache().putIfEmpty(
|
|
|
|
document->goodThumbnailCacheKey(),
|
|
|
|
Storage::Cache::Database::TaggedValue(
|
|
|
|
std::move(file->goodThumbnailBytes),
|
|
|
|
Data::kImageCacheTag));
|
|
|
|
}
|
2016-02-12 16:35:06 +00:00
|
|
|
if (!file->content.isEmpty()) {
|
2019-09-06 11:33:51 +00:00
|
|
|
document->setDataAndCache(file->content);
|
2016-02-12 16:35:06 +00:00
|
|
|
}
|
2015-10-27 02:39:02 +00:00
|
|
|
if (!file->filepath.isEmpty()) {
|
2020-10-13 16:43:18 +00:00
|
|
|
document->setLocation(Core::FileLocation(file->filepath));
|
2015-10-27 02:39:02 +00:00
|
|
|
}
|
2020-04-16 12:37:26 +00:00
|
|
|
if (file->type == SendMediaType::ThemeFile) {
|
|
|
|
document->checkWallPaperProperties();
|
|
|
|
}
|
2015-10-27 02:39:02 +00:00
|
|
|
}
|
2017-12-18 10:38:14 +00:00
|
|
|
queue.emplace(msgId, File(file));
|
2015-10-27 02:39:02 +00:00
|
|
|
sendNext();
|
|
|
|
}
|
|
|
|
|
2017-08-04 14:54:32 +00:00
|
|
|
void Uploader::currentFailed() {
|
2017-12-18 10:38:14 +00:00
|
|
|
auto j = queue.find(uploadingId);
|
2014-05-30 08:53:19 +00:00
|
|
|
if (j != queue.end()) {
|
2022-01-26 09:41:27 +00:00
|
|
|
const auto [msgId, file] = std::move(*j);
|
2014-05-30 08:53:19 +00:00
|
|
|
queue.erase(j);
|
2022-01-26 09:41:27 +00:00
|
|
|
notifyFailed(msgId, file);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2022-01-26 09:41:27 +00:00
|
|
|
cancelRequests();
|
2014-10-30 16:23:44 +00:00
|
|
|
dcMap.clear();
|
2017-12-18 10:38:14 +00:00
|
|
|
uploadingId = FullMsgId();
|
2014-05-30 08:53:19 +00:00
|
|
|
sentSize = 0;
|
2017-03-23 16:11:35 +00:00
|
|
|
for (int i = 0; i < MTP::kUploadSessionsCount; ++i) {
|
2014-10-30 16:23:44 +00:00
|
|
|
sentSizes[i] = 0;
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
sendNext();
|
|
|
|
}
|
|
|
|
|
2022-01-26 09:41:27 +00:00
|
|
|
void Uploader::notifyFailed(FullMsgId id, const File &file) {
|
|
|
|
const auto type = file.type();
|
|
|
|
if (type == SendMediaType::Photo) {
|
|
|
|
_photoFailed.fire_copy(id);
|
|
|
|
} else if (type == SendMediaType::File
|
|
|
|
|| type == SendMediaType::ThemeFile
|
|
|
|
|| type == SendMediaType::Audio) {
|
|
|
|
const auto document = session().data().document(file.id());
|
|
|
|
if (document->uploading()) {
|
|
|
|
document->status = FileUploadFailed;
|
|
|
|
}
|
|
|
|
_documentFailed.fire_copy(id);
|
|
|
|
} else if (type == SendMediaType::Secure) {
|
|
|
|
_secureFailed.fire_copy(id);
|
|
|
|
} else {
|
|
|
|
Unexpected("Type in Uploader::currentFailed.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-17 19:58:00 +00:00
|
|
|
void Uploader::stopSessions() {
|
2017-03-23 16:11:35 +00:00
|
|
|
for (int i = 0; i < MTP::kUploadSessionsCount; ++i) {
|
2020-06-17 09:36:25 +00:00
|
|
|
_api->instance().stopSession(MTP::uploadDcId(i));
|
2014-10-30 16:23:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-04 14:54:32 +00:00
|
|
|
void Uploader::sendNext() {
|
2020-07-06 09:58:18 +00:00
|
|
|
if (sentSize >= kMaxUploadFileParallelSize || _pausedId.msg) {
|
|
|
|
return;
|
|
|
|
}
|
2014-10-30 16:23:44 +00:00
|
|
|
|
2021-03-09 09:33:33 +00:00
|
|
|
const auto stopping = _stopSessionsTimer.isActive();
|
2017-12-18 10:38:14 +00:00
|
|
|
if (queue.empty()) {
|
2018-05-17 19:58:00 +00:00
|
|
|
if (!stopping) {
|
2021-03-09 09:33:33 +00:00
|
|
|
_stopSessionsTimer.callOnce(kKillSessionTimeout);
|
2014-10-30 16:23:44 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2018-05-17 19:58:00 +00:00
|
|
|
if (stopping) {
|
2021-03-09 09:33:33 +00:00
|
|
|
_stopSessionsTimer.cancel();
|
2014-10-30 16:23:44 +00:00
|
|
|
}
|
2017-12-18 10:38:14 +00:00
|
|
|
auto i = uploadingId.msg ? queue.find(uploadingId) : queue.begin();
|
|
|
|
if (!uploadingId.msg) {
|
|
|
|
uploadingId = i->first;
|
2014-05-30 08:53:19 +00:00
|
|
|
} else if (i == queue.end()) {
|
2016-02-12 16:35:06 +00:00
|
|
|
i = queue.begin();
|
2017-12-18 10:38:14 +00:00
|
|
|
uploadingId = i->first;
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2017-12-18 10:38:14 +00:00
|
|
|
auto &uploadingData = i->second;
|
|
|
|
|
|
|
|
auto todc = 0;
|
|
|
|
for (auto dc = 1; dc != MTP::kUploadSessionsCount; ++dc) {
|
2014-10-30 16:23:44 +00:00
|
|
|
if (sentSizes[dc] < sentSizes[todc]) {
|
|
|
|
todc = dc;
|
|
|
|
}
|
|
|
|
}
|
2015-10-27 02:39:02 +00:00
|
|
|
|
2017-12-18 10:38:14 +00:00
|
|
|
auto &parts = uploadingData.file
|
2018-03-25 11:37:57 +00:00
|
|
|
? ((uploadingData.type() == SendMediaType::Photo
|
|
|
|
|| uploadingData.type() == SendMediaType::Secure)
|
2017-12-18 10:38:14 +00:00
|
|
|
? uploadingData.file->fileparts
|
|
|
|
: uploadingData.file->thumbparts)
|
|
|
|
: uploadingData.media.parts;
|
|
|
|
const auto partsOfId = uploadingData.file
|
2018-03-25 11:37:57 +00:00
|
|
|
? ((uploadingData.type() == SendMediaType::Photo
|
|
|
|
|| uploadingData.type() == SendMediaType::Secure)
|
2017-12-18 10:38:14 +00:00
|
|
|
? uploadingData.file->id
|
|
|
|
: uploadingData.file->thumbId)
|
|
|
|
: uploadingData.media.thumbId;
|
2015-10-27 02:39:02 +00:00
|
|
|
if (parts.isEmpty()) {
|
2017-12-18 10:38:14 +00:00
|
|
|
if (uploadingData.docSentParts >= uploadingData.docPartsCount) {
|
|
|
|
if (requestsSent.empty() && docRequestsSent.empty()) {
|
2019-08-12 12:11:34 +00:00
|
|
|
const auto options = uploadingData.file
|
|
|
|
? uploadingData.file->to.options
|
|
|
|
: Api::SendOptions();
|
2019-03-29 10:51:19 +00:00
|
|
|
const auto edit = uploadingData.file &&
|
2021-03-09 09:11:40 +00:00
|
|
|
uploadingData.file->to.replaceMediaOf;
|
2021-03-14 09:46:17 +00:00
|
|
|
const auto attachedStickers = uploadingData.file
|
|
|
|
? uploadingData.file->attachedStickers
|
|
|
|
: std::vector<MTPInputDocument>();
|
2017-12-18 10:38:14 +00:00
|
|
|
if (uploadingData.type() == SendMediaType::Photo) {
|
|
|
|
auto photoFilename = uploadingData.filename();
|
2017-03-10 15:45:22 +00:00
|
|
|
if (!photoFilename.endsWith(qstr(".jpg"), Qt::CaseInsensitive)) {
|
|
|
|
// Server has some extensions checking for inputMediaUploadedPhoto,
|
|
|
|
// so force the extension to be .jpg anyway. It doesn't matter,
|
|
|
|
// because the filename from inputFile is not used anywhere.
|
|
|
|
photoFilename += qstr(".jpg");
|
|
|
|
}
|
2017-12-18 10:38:14 +00:00
|
|
|
const auto md5 = uploadingData.file
|
|
|
|
? uploadingData.file->filemd5
|
|
|
|
: uploadingData.media.jpeg_md5;
|
|
|
|
const auto file = MTP_inputFile(
|
|
|
|
MTP_long(uploadingData.id()),
|
|
|
|
MTP_int(uploadingData.partsCount),
|
|
|
|
MTP_string(photoFilename),
|
|
|
|
MTP_bytes(md5));
|
2021-03-14 09:46:17 +00:00
|
|
|
_photoReady.fire({
|
2021-11-16 12:38:31 +00:00
|
|
|
.fullId = uploadingId,
|
|
|
|
.info = {
|
|
|
|
.file = file,
|
|
|
|
.attachedStickers = attachedStickers,
|
|
|
|
},
|
|
|
|
.options = options,
|
|
|
|
.edit = edit,
|
|
|
|
});
|
2017-12-18 10:38:14 +00:00
|
|
|
} else if (uploadingData.type() == SendMediaType::File
|
2019-09-03 08:25:19 +00:00
|
|
|
|| uploadingData.type() == SendMediaType::ThemeFile
|
2017-12-18 10:38:14 +00:00
|
|
|
|| uploadingData.type() == SendMediaType::Audio) {
|
2014-05-30 08:53:19 +00:00
|
|
|
QByteArray docMd5(32, Qt::Uninitialized);
|
2017-12-18 10:38:14 +00:00
|
|
|
hashMd5Hex(uploadingData.md5Hash.result(), docMd5.data());
|
|
|
|
|
2019-01-18 11:26:43 +00:00
|
|
|
const auto file = (uploadingData.docSize > kUseBigFilesFrom)
|
2017-12-18 10:38:14 +00:00
|
|
|
? MTP_inputFileBig(
|
|
|
|
MTP_long(uploadingData.id()),
|
|
|
|
MTP_int(uploadingData.docPartsCount),
|
|
|
|
MTP_string(uploadingData.filename()))
|
|
|
|
: MTP_inputFile(
|
|
|
|
MTP_long(uploadingData.id()),
|
|
|
|
MTP_int(uploadingData.docPartsCount),
|
|
|
|
MTP_string(uploadingData.filename()),
|
|
|
|
MTP_bytes(docMd5));
|
2021-03-09 10:00:49 +00:00
|
|
|
const auto thumb = [&]() -> std::optional<MTPInputFile> {
|
|
|
|
if (!uploadingData.partsCount) {
|
|
|
|
return std::nullopt;
|
|
|
|
}
|
2017-12-18 10:38:14 +00:00
|
|
|
const auto thumbFilename = uploadingData.file
|
|
|
|
? uploadingData.file->thumbname
|
|
|
|
: (qsl("thumb.") + uploadingData.media.thumbExt);
|
|
|
|
const auto thumbMd5 = uploadingData.file
|
|
|
|
? uploadingData.file->thumbmd5
|
|
|
|
: uploadingData.media.jpeg_md5;
|
2021-03-09 10:00:49 +00:00
|
|
|
return MTP_inputFile(
|
2017-12-18 10:38:14 +00:00
|
|
|
MTP_long(uploadingData.thumbId()),
|
|
|
|
MTP_int(uploadingData.partsCount),
|
|
|
|
MTP_string(thumbFilename),
|
|
|
|
MTP_bytes(thumbMd5));
|
2021-03-09 10:00:49 +00:00
|
|
|
}();
|
|
|
|
_documentReady.fire({
|
2021-11-16 12:38:31 +00:00
|
|
|
.fullId = uploadingId,
|
|
|
|
.info = {
|
|
|
|
.file = file,
|
|
|
|
.thumb = thumb,
|
|
|
|
.attachedStickers = attachedStickers,
|
|
|
|
},
|
|
|
|
.options = options,
|
|
|
|
.edit = edit,
|
|
|
|
});
|
2018-03-25 11:37:57 +00:00
|
|
|
} else if (uploadingData.type() == SendMediaType::Secure) {
|
|
|
|
_secureReady.fire({
|
|
|
|
uploadingId,
|
|
|
|
uploadingData.id(),
|
|
|
|
uploadingData.partsCount });
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2017-12-18 10:38:14 +00:00
|
|
|
queue.erase(uploadingId);
|
|
|
|
uploadingId = FullMsgId();
|
2014-05-30 08:53:19 +00:00
|
|
|
sendNext();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-12-18 10:38:14 +00:00
|
|
|
auto &content = uploadingData.file
|
|
|
|
? uploadingData.file->content
|
|
|
|
: uploadingData.media.data;
|
2014-05-30 08:53:19 +00:00
|
|
|
QByteArray toSend;
|
2015-10-27 02:39:02 +00:00
|
|
|
if (content.isEmpty()) {
|
2017-12-18 10:38:14 +00:00
|
|
|
if (!uploadingData.docFile) {
|
|
|
|
const auto filepath = uploadingData.file
|
|
|
|
? uploadingData.file->filepath
|
|
|
|
: uploadingData.media.file;
|
|
|
|
uploadingData.docFile = std::make_unique<QFile>(filepath);
|
|
|
|
if (!uploadingData.docFile->open(QIODevice::ReadOnly)) {
|
2014-05-30 08:53:19 +00:00
|
|
|
currentFailed();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2017-12-18 10:38:14 +00:00
|
|
|
toSend = uploadingData.docFile->read(uploadingData.docPartSize);
|
2019-01-18 11:26:43 +00:00
|
|
|
if (uploadingData.docSize <= kUseBigFilesFrom) {
|
2017-12-18 10:38:14 +00:00
|
|
|
uploadingData.md5Hash.feed(toSend.constData(), toSend.size());
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
} else {
|
2017-12-18 10:38:14 +00:00
|
|
|
const auto offset = uploadingData.docSentParts
|
|
|
|
* uploadingData.docPartSize;
|
|
|
|
toSend = content.mid(offset, uploadingData.docPartSize);
|
|
|
|
if ((uploadingData.type() == SendMediaType::File
|
2019-09-03 08:25:19 +00:00
|
|
|
|| uploadingData.type() == SendMediaType::ThemeFile
|
2017-12-18 10:38:14 +00:00
|
|
|
|| uploadingData.type() == SendMediaType::Audio)
|
2019-01-18 11:26:43 +00:00
|
|
|
&& uploadingData.docSentParts <= kUseBigFilesFrom) {
|
2017-12-18 10:38:14 +00:00
|
|
|
uploadingData.md5Hash.feed(toSend.constData(), toSend.size());
|
2014-07-04 11:12:54 +00:00
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2017-12-18 10:38:14 +00:00
|
|
|
if ((toSend.size() > uploadingData.docPartSize)
|
|
|
|
|| ((toSend.size() < uploadingData.docPartSize
|
|
|
|
&& uploadingData.docSentParts + 1 != uploadingData.docPartsCount))) {
|
2014-05-30 08:53:19 +00:00
|
|
|
currentFailed();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mtpRequestId requestId;
|
2019-01-18 11:26:43 +00:00
|
|
|
if (uploadingData.docSize > kUseBigFilesFrom) {
|
2020-06-11 13:07:14 +00:00
|
|
|
requestId = _api->request(MTPupload_SaveBigFilePart(
|
|
|
|
MTP_long(uploadingData.id()),
|
|
|
|
MTP_int(uploadingData.docSentParts),
|
|
|
|
MTP_int(uploadingData.docPartsCount),
|
|
|
|
MTP_bytes(toSend)
|
|
|
|
)).done([=](const MTPBool &result, mtpRequestId requestId) {
|
|
|
|
partLoaded(result, requestId);
|
2021-03-12 12:48:00 +00:00
|
|
|
}).fail([=](const MTP::Error &error, mtpRequestId requestId) {
|
2020-06-11 13:07:14 +00:00
|
|
|
partFailed(error, requestId);
|
|
|
|
}).toDC(MTP::uploadDcId(todc)).send();
|
2014-05-30 08:53:19 +00:00
|
|
|
} else {
|
2020-06-11 13:07:14 +00:00
|
|
|
requestId = _api->request(MTPupload_SaveFilePart(
|
|
|
|
MTP_long(uploadingData.id()),
|
|
|
|
MTP_int(uploadingData.docSentParts),
|
|
|
|
MTP_bytes(toSend)
|
|
|
|
)).done([=](const MTPBool &result, mtpRequestId requestId) {
|
|
|
|
partLoaded(result, requestId);
|
2021-03-12 12:48:00 +00:00
|
|
|
}).fail([=](const MTP::Error &error, mtpRequestId requestId) {
|
2020-06-11 13:07:14 +00:00
|
|
|
partFailed(error, requestId);
|
|
|
|
}).toDC(MTP::uploadDcId(todc)).send();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2017-12-18 10:38:14 +00:00
|
|
|
docRequestsSent.emplace(requestId, uploadingData.docSentParts);
|
|
|
|
dcMap.emplace(requestId, todc);
|
|
|
|
sentSize += uploadingData.docPartSize;
|
|
|
|
sentSizes[todc] += uploadingData.docPartSize;
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2017-12-18 10:38:14 +00:00
|
|
|
uploadingData.docSentParts++;
|
2014-05-30 08:53:19 +00:00
|
|
|
} else {
|
2017-12-18 10:38:14 +00:00
|
|
|
auto part = parts.begin();
|
|
|
|
|
2020-06-11 13:07:14 +00:00
|
|
|
const auto requestId = _api->request(MTPupload_SaveFilePart(
|
|
|
|
MTP_long(partsOfId),
|
|
|
|
MTP_int(part.key()),
|
|
|
|
MTP_bytes(part.value())
|
|
|
|
)).done([=](const MTPBool &result, mtpRequestId requestId) {
|
|
|
|
partLoaded(result, requestId);
|
2021-03-12 12:48:00 +00:00
|
|
|
}).fail([=](const MTP::Error &error, mtpRequestId requestId) {
|
2020-06-11 13:07:14 +00:00
|
|
|
partFailed(error, requestId);
|
|
|
|
}).toDC(MTP::uploadDcId(todc)).send();
|
2017-12-18 10:38:14 +00:00
|
|
|
requestsSent.emplace(requestId, part.value());
|
|
|
|
dcMap.emplace(requestId, todc);
|
2014-05-30 08:53:19 +00:00
|
|
|
sentSize += part.value().size();
|
2014-10-30 16:23:44 +00:00
|
|
|
sentSizes[todc] += part.value().size();
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2015-10-27 02:39:02 +00:00
|
|
|
parts.erase(part);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2021-03-09 09:33:33 +00:00
|
|
|
_nextTimer.callOnce(kUploadRequestInterval);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2017-08-04 14:54:32 +00:00
|
|
|
void Uploader::cancel(const FullMsgId &msgId) {
|
2017-12-18 10:38:14 +00:00
|
|
|
if (uploadingId == msgId) {
|
2014-05-30 08:53:19 +00:00
|
|
|
currentFailed();
|
|
|
|
} else {
|
2017-12-18 10:38:14 +00:00
|
|
|
queue.erase(msgId);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-26 09:41:27 +00:00
|
|
|
void Uploader::cancelAll() {
|
|
|
|
const auto single = queue.empty() ? uploadingId : queue.begin()->first;
|
|
|
|
if (!single) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_pausedId = single;
|
|
|
|
if (uploadingId) {
|
|
|
|
currentFailed();
|
|
|
|
}
|
|
|
|
while (!queue.empty()) {
|
|
|
|
const auto [msgId, file] = std::move(*queue.begin());
|
|
|
|
queue.erase(queue.begin());
|
|
|
|
notifyFailed(msgId, file);
|
|
|
|
}
|
|
|
|
clear();
|
|
|
|
unpause();
|
|
|
|
}
|
|
|
|
|
2017-08-04 14:54:32 +00:00
|
|
|
void Uploader::pause(const FullMsgId &msgId) {
|
2017-12-18 10:38:14 +00:00
|
|
|
_pausedId = msgId;
|
2015-12-24 19:26:28 +00:00
|
|
|
}
|
|
|
|
|
2017-08-04 14:54:32 +00:00
|
|
|
void Uploader::unpause() {
|
2017-12-18 10:38:14 +00:00
|
|
|
_pausedId = FullMsgId();
|
2015-12-24 19:26:28 +00:00
|
|
|
sendNext();
|
|
|
|
}
|
|
|
|
|
2017-08-04 14:54:32 +00:00
|
|
|
void Uploader::confirm(const FullMsgId &msgId) {
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2022-01-26 09:41:27 +00:00
|
|
|
void Uploader::cancelRequests() {
|
2017-12-18 15:52:58 +00:00
|
|
|
for (const auto &requestData : requestsSent) {
|
2020-06-11 13:07:14 +00:00
|
|
|
_api->request(requestData.first).cancel();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
requestsSent.clear();
|
2017-12-18 15:52:58 +00:00
|
|
|
for (const auto &requestData : docRequestsSent) {
|
2020-06-11 13:07:14 +00:00
|
|
|
_api->request(requestData.first).cancel();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
docRequestsSent.clear();
|
2022-01-26 09:41:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Uploader::clear() {
|
|
|
|
queue.clear();
|
|
|
|
cancelRequests();
|
2014-10-30 16:23:44 +00:00
|
|
|
dcMap.clear();
|
2014-05-30 08:53:19 +00:00
|
|
|
sentSize = 0;
|
2017-03-23 16:11:35 +00:00
|
|
|
for (int i = 0; i < MTP::kUploadSessionsCount; ++i) {
|
2020-06-17 09:36:25 +00:00
|
|
|
_api->instance().stopSession(MTP::uploadDcId(i));
|
2014-10-30 16:23:44 +00:00
|
|
|
sentSizes[i] = 0;
|
|
|
|
}
|
2021-03-09 09:33:33 +00:00
|
|
|
_stopSessionsTimer.cancel();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2017-08-04 14:54:32 +00:00
|
|
|
void Uploader::partLoaded(const MTPBool &result, mtpRequestId requestId) {
|
2017-12-18 10:38:14 +00:00
|
|
|
auto j = docRequestsSent.end();
|
|
|
|
auto i = requestsSent.find(requestId);
|
2014-05-30 08:53:19 +00:00
|
|
|
if (i == requestsSent.cend()) {
|
|
|
|
j = docRequestsSent.find(requestId);
|
|
|
|
}
|
|
|
|
if (i != requestsSent.cend() || j != docRequestsSent.cend()) {
|
2015-10-29 00:16:52 +00:00
|
|
|
if (mtpIsFalse(result)) { // failed to upload current file
|
2014-05-30 08:53:19 +00:00
|
|
|
currentFailed();
|
|
|
|
return;
|
|
|
|
} else {
|
2017-12-18 10:38:14 +00:00
|
|
|
auto dcIt = dcMap.find(requestId);
|
2014-10-30 16:23:44 +00:00
|
|
|
if (dcIt == dcMap.cend()) { // must not happen
|
|
|
|
currentFailed();
|
|
|
|
return;
|
|
|
|
}
|
2017-12-18 10:38:14 +00:00
|
|
|
auto dc = dcIt->second;
|
2014-10-30 16:23:44 +00:00
|
|
|
dcMap.erase(dcIt);
|
|
|
|
|
2022-05-10 14:22:28 +00:00
|
|
|
int64 sentPartSize = 0;
|
2017-12-18 10:38:14 +00:00
|
|
|
auto k = queue.find(uploadingId);
|
|
|
|
Assert(k != queue.cend());
|
|
|
|
auto &[fullId, file] = *k;
|
2014-05-30 08:53:19 +00:00
|
|
|
if (i != requestsSent.cend()) {
|
2017-12-18 10:38:14 +00:00
|
|
|
sentPartSize = i->second.size();
|
2014-05-30 08:53:19 +00:00
|
|
|
requestsSent.erase(i);
|
|
|
|
} else {
|
2017-12-18 10:38:14 +00:00
|
|
|
sentPartSize = file.docPartSize;
|
2014-05-30 08:53:19 +00:00
|
|
|
docRequestsSent.erase(j);
|
|
|
|
}
|
2015-12-24 19:26:28 +00:00
|
|
|
sentSize -= sentPartSize;
|
|
|
|
sentSizes[dc] -= sentPartSize;
|
2017-12-18 10:38:14 +00:00
|
|
|
if (file.type() == SendMediaType::Photo) {
|
|
|
|
file.fileSentSize += sentPartSize;
|
2020-06-08 15:17:33 +00:00
|
|
|
const auto photo = session().data().photo(file.id());
|
2017-12-18 10:38:14 +00:00
|
|
|
if (photo->uploading() && file.file) {
|
|
|
|
photo->uploadingData->size = file.file->partssize;
|
|
|
|
photo->uploadingData->offset = file.fileSentSize;
|
2015-12-24 19:26:28 +00:00
|
|
|
}
|
2018-03-25 11:37:57 +00:00
|
|
|
_photoProgress.fire_copy(fullId);
|
2017-12-18 10:38:14 +00:00
|
|
|
} else if (file.type() == SendMediaType::File
|
2019-09-03 08:25:19 +00:00
|
|
|
|| file.type() == SendMediaType::ThemeFile
|
2017-12-18 10:38:14 +00:00
|
|
|
|| file.type() == SendMediaType::Audio) {
|
2020-06-08 15:17:33 +00:00
|
|
|
const auto document = session().data().document(file.id());
|
2017-12-18 10:38:14 +00:00
|
|
|
if (document->uploading()) {
|
|
|
|
const auto doneParts = file.docSentParts
|
|
|
|
- int(docRequestsSent.size());
|
2017-12-27 18:57:07 +00:00
|
|
|
document->uploadingData->offset = std::min(
|
2017-12-25 14:17:00 +00:00
|
|
|
document->uploadingData->size,
|
|
|
|
doneParts * file.docPartSize);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2018-03-25 11:37:57 +00:00
|
|
|
_documentProgress.fire_copy(fullId);
|
|
|
|
} else if (file.type() == SendMediaType::Secure) {
|
2018-03-28 20:40:42 +00:00
|
|
|
file.fileSentSize += sentPartSize;
|
|
|
|
_secureProgress.fire_copy({
|
|
|
|
fullId,
|
|
|
|
file.fileSentSize,
|
|
|
|
file.file->partssize });
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sendNext();
|
|
|
|
}
|
|
|
|
|
2021-03-12 12:48:00 +00:00
|
|
|
void Uploader::partFailed(const MTP::Error &error, mtpRequestId requestId) {
|
2017-12-18 10:38:14 +00:00
|
|
|
// failed to upload current file
|
|
|
|
if ((requestsSent.find(requestId) != requestsSent.cend())
|
|
|
|
|| (docRequestsSent.find(requestId) != docRequestsSent.cend())) {
|
2014-05-30 08:53:19 +00:00
|
|
|
currentFailed();
|
|
|
|
}
|
|
|
|
sendNext();
|
|
|
|
}
|
2017-08-04 14:54:32 +00:00
|
|
|
|
|
|
|
} // namespace Storage
|