/* This file is part of Telegram Desktop, the official desktop application for the Telegram messaging service. For license and copyright information please follow this link: https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once struct FileLoadResult; struct SendMediaReady; namespace Storage { // MTP big files methods used for files greater than 10mb. constexpr auto kUseBigFilesFrom = 10 * 1024 * 1024; struct UploadedPhoto { FullMsgId fullId; bool silent = false; MTPInputFile file; bool edit = false; }; struct UploadedDocument { FullMsgId fullId; bool silent = false; MTPInputFile file; bool edit = false; }; struct UploadedThumbDocument { FullMsgId fullId; bool silent = false; MTPInputFile file; MTPInputFile thumb; bool edit = false; }; struct UploadSecureProgress { FullMsgId fullId; int offset = 0; int size = 0; }; struct UploadSecureDone { FullMsgId fullId; uint64 fileId = 0; int partsCount = 0; }; class Uploader : public QObject, public RPCSender { Q_OBJECT public: Uploader(); void uploadMedia(const FullMsgId &msgId, const SendMediaReady &image); void upload( const FullMsgId &msgId, const std::shared_ptr &file); int32 currentOffset(const FullMsgId &msgId) const; // -1 means file not found int32 fullSize(const FullMsgId &msgId) const; void cancel(const FullMsgId &msgId); void pause(const FullMsgId &msgId); void confirm(const FullMsgId &msgId); void clear(); rpl::producer photoReady() const { return _photoReady.events(); } rpl::producer documentReady() const { return _documentReady.events(); } rpl::producer thumbDocumentReady() const { return _thumbDocumentReady.events(); } rpl::producer secureReady() const { return _secureReady.events(); } rpl::producer photoProgress() const { return _photoProgress.events(); } rpl::producer documentProgress() const { return _documentProgress.events(); } rpl::producer secureProgress() const { return _secureProgress.events(); } rpl::producer photoFailed() const { return _photoFailed.events(); } rpl::producer documentFailed() const { return _documentFailed.events(); } rpl::producer secureFailed() const { return _secureFailed.events(); } ~Uploader(); public slots: void unpause(); void sendNext(); void stopSessions(); private: struct File; void partLoaded(const MTPBool &result, mtpRequestId requestId); bool partFailed(const RPCError &err, mtpRequestId requestId); void currentFailed(); base::flat_map requestsSent; base::flat_map docRequestsSent; base::flat_map dcMap; uint32 sentSize = 0; uint32 sentSizes[MTP::kUploadSessionsCount] = { 0 }; FullMsgId uploadingId; FullMsgId _pausedId; std::map queue; std::map uploaded; QTimer nextTimer, stopSessionsTimer; rpl::event_stream _photoReady; rpl::event_stream _documentReady; rpl::event_stream _thumbDocumentReady; rpl::event_stream _secureReady; rpl::event_stream _photoProgress; rpl::event_stream _documentProgress; rpl::event_stream _secureProgress; rpl::event_stream _photoFailed; rpl::event_stream _documentFailed; rpl::event_stream _secureFailed; }; } // namespace Storage