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
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2017-12-19 16:57:42 +00:00
|
|
|
struct FileLoadResult;
|
|
|
|
struct SendMediaReady;
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2017-08-04 14:54:32 +00:00
|
|
|
namespace Storage {
|
|
|
|
|
2019-01-18 11:26:43 +00:00
|
|
|
// MTP big files methods used for files greater than 10mb.
|
|
|
|
constexpr auto kUseBigFilesFrom = 10 * 1024 * 1024;
|
|
|
|
|
2018-03-25 11:37:57 +00:00
|
|
|
struct UploadedPhoto {
|
|
|
|
FullMsgId fullId;
|
|
|
|
bool silent = false;
|
|
|
|
MTPInputFile file;
|
2019-03-26 12:26:34 +00:00
|
|
|
bool edit = false;
|
2018-03-25 11:37:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct UploadedDocument {
|
|
|
|
FullMsgId fullId;
|
|
|
|
bool silent = false;
|
|
|
|
MTPInputFile file;
|
2019-03-26 12:26:34 +00:00
|
|
|
bool edit = false;
|
2018-03-25 11:37:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct UploadedThumbDocument {
|
|
|
|
FullMsgId fullId;
|
|
|
|
bool silent = false;
|
|
|
|
MTPInputFile file;
|
|
|
|
MTPInputFile thumb;
|
2019-03-26 12:26:34 +00:00
|
|
|
bool edit = false;
|
2018-03-25 11:37:57 +00:00
|
|
|
};
|
|
|
|
|
2018-03-28 20:40:42 +00:00
|
|
|
struct UploadSecureProgress {
|
|
|
|
FullMsgId fullId;
|
|
|
|
int offset = 0;
|
|
|
|
int size = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct UploadSecureDone {
|
2018-03-25 11:37:57 +00:00
|
|
|
FullMsgId fullId;
|
|
|
|
uint64 fileId = 0;
|
|
|
|
int partsCount = 0;
|
|
|
|
};
|
|
|
|
|
2017-08-04 14:54:32 +00:00
|
|
|
class Uploader : public QObject, public RPCSender {
|
2014-05-30 08:53:19 +00:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2017-08-04 14:54:32 +00:00
|
|
|
Uploader();
|
2016-11-28 15:45:07 +00:00
|
|
|
void uploadMedia(const FullMsgId &msgId, const SendMediaReady &image);
|
2017-12-19 16:57:42 +00:00
|
|
|
void upload(
|
|
|
|
const FullMsgId &msgId,
|
|
|
|
const std::shared_ptr<FileLoadResult> &file);
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2015-09-03 10:48:40 +00:00
|
|
|
int32 currentOffset(const FullMsgId &msgId) const; // -1 means file not found
|
|
|
|
int32 fullSize(const FullMsgId &msgId) const;
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2015-09-03 10:48:40 +00:00
|
|
|
void cancel(const FullMsgId &msgId);
|
2015-12-24 19:26:28 +00:00
|
|
|
void pause(const FullMsgId &msgId);
|
2015-09-03 10:48:40 +00:00
|
|
|
void confirm(const FullMsgId &msgId);
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
void clear();
|
|
|
|
|
2018-03-25 11:37:57 +00:00
|
|
|
rpl::producer<UploadedPhoto> photoReady() const {
|
|
|
|
return _photoReady.events();
|
|
|
|
}
|
|
|
|
rpl::producer<UploadedDocument> documentReady() const {
|
|
|
|
return _documentReady.events();
|
|
|
|
}
|
|
|
|
rpl::producer<UploadedThumbDocument> thumbDocumentReady() const {
|
|
|
|
return _thumbDocumentReady.events();
|
|
|
|
}
|
2018-03-28 20:40:42 +00:00
|
|
|
rpl::producer<UploadSecureDone> secureReady() const {
|
2018-03-25 11:37:57 +00:00
|
|
|
return _secureReady.events();
|
|
|
|
}
|
|
|
|
rpl::producer<FullMsgId> photoProgress() const {
|
|
|
|
return _photoProgress.events();
|
|
|
|
}
|
|
|
|
rpl::producer<FullMsgId> documentProgress() const {
|
|
|
|
return _documentProgress.events();
|
|
|
|
}
|
2018-03-28 20:40:42 +00:00
|
|
|
rpl::producer<UploadSecureProgress> secureProgress() const {
|
2018-03-25 11:37:57 +00:00
|
|
|
return _secureProgress.events();
|
|
|
|
}
|
|
|
|
rpl::producer<FullMsgId> photoFailed() const {
|
|
|
|
return _photoFailed.events();
|
|
|
|
}
|
|
|
|
rpl::producer<FullMsgId> documentFailed() const {
|
|
|
|
return _documentFailed.events();
|
|
|
|
}
|
|
|
|
rpl::producer<FullMsgId> secureFailed() const {
|
|
|
|
return _secureFailed.events();
|
|
|
|
}
|
|
|
|
|
2017-08-04 14:54:32 +00:00
|
|
|
~Uploader();
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
public slots:
|
2015-12-24 19:26:28 +00:00
|
|
|
void unpause();
|
2014-05-30 08:53:19 +00:00
|
|
|
void sendNext();
|
2018-05-17 19:58:00 +00:00
|
|
|
void stopSessions();
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
private:
|
2017-12-19 16:57:42 +00:00
|
|
|
struct File;
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
void partLoaded(const MTPBool &result, mtpRequestId requestId);
|
|
|
|
bool partFailed(const RPCError &err, mtpRequestId requestId);
|
|
|
|
|
|
|
|
void currentFailed();
|
|
|
|
|
2017-12-18 10:38:14 +00:00
|
|
|
base::flat_map<mtpRequestId, QByteArray> requestsSent;
|
|
|
|
base::flat_map<mtpRequestId, int32> docRequestsSent;
|
|
|
|
base::flat_map<mtpRequestId, int32> dcMap;
|
2017-08-04 14:54:32 +00:00
|
|
|
uint32 sentSize = 0;
|
|
|
|
uint32 sentSizes[MTP::kUploadSessionsCount] = { 0 };
|
2016-02-12 16:35:06 +00:00
|
|
|
|
2017-12-18 10:38:14 +00:00
|
|
|
FullMsgId uploadingId;
|
|
|
|
FullMsgId _pausedId;
|
|
|
|
std::map<FullMsgId, File> queue;
|
|
|
|
std::map<FullMsgId, File> uploaded;
|
2018-05-17 19:58:00 +00:00
|
|
|
QTimer nextTimer, stopSessionsTimer;
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2018-03-25 11:37:57 +00:00
|
|
|
rpl::event_stream<UploadedPhoto> _photoReady;
|
|
|
|
rpl::event_stream<UploadedDocument> _documentReady;
|
|
|
|
rpl::event_stream<UploadedThumbDocument> _thumbDocumentReady;
|
2018-03-28 20:40:42 +00:00
|
|
|
rpl::event_stream<UploadSecureDone> _secureReady;
|
2018-03-25 11:37:57 +00:00
|
|
|
rpl::event_stream<FullMsgId> _photoProgress;
|
|
|
|
rpl::event_stream<FullMsgId> _documentProgress;
|
2018-03-28 20:40:42 +00:00
|
|
|
rpl::event_stream<UploadSecureProgress> _secureProgress;
|
2018-03-25 11:37:57 +00:00
|
|
|
rpl::event_stream<FullMsgId> _photoFailed;
|
|
|
|
rpl::event_stream<FullMsgId> _documentFailed;
|
|
|
|
rpl::event_stream<FullMsgId> _secureFailed;
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
};
|
2017-08-04 14:54:32 +00:00
|
|
|
|
|
|
|
} // namespace Storage
|