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 {
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
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();
|
2014-10-30 16:23:44 +00:00
|
|
|
void killSessions();
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
signals:
|
2016-02-25 16:19:54 +00:00
|
|
|
void photoReady(const FullMsgId &msgId, bool silent, const MTPInputFile &file);
|
|
|
|
void documentReady(const FullMsgId &msgId, bool silent, const MTPInputFile &file);
|
|
|
|
void thumbDocumentReady(const FullMsgId &msgId, bool silent, const MTPInputFile &file, const MTPInputFile &thumb);
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2015-09-03 10:48:40 +00:00
|
|
|
void photoProgress(const FullMsgId &msgId);
|
|
|
|
void documentProgress(const FullMsgId &msgId);
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2015-09-03 10:48:40 +00:00
|
|
|
void photoFailed(const FullMsgId &msgId);
|
|
|
|
void documentFailed(const FullMsgId &msgId);
|
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;
|
2014-10-30 16:23:44 +00:00
|
|
|
QTimer nextTimer, killSessionsTimer;
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
};
|
2017-08-04 14:54:32 +00:00
|
|
|
|
|
|
|
} // namespace Storage
|