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
|
|
|
|
|
2019-08-12 12:11:34 +00:00
|
|
|
#include "api/api_common.h"
|
2021-03-09 09:33:33 +00:00
|
|
|
#include "base/timer.h"
|
2019-11-13 08:31:12 +00:00
|
|
|
#include "mtproto/facade.h"
|
2019-08-12 12:11:34 +00:00
|
|
|
|
|
|
|
class ApiWrap;
|
2017-12-19 16:57:42 +00:00
|
|
|
struct FileLoadResult;
|
|
|
|
struct SendMediaReady;
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2020-09-29 08:36:30 +00:00
|
|
|
namespace Api {
|
|
|
|
enum class SendProgressType;
|
|
|
|
} // namespace Api
|
|
|
|
|
2020-06-08 15:17:33 +00:00
|
|
|
namespace Main {
|
|
|
|
class Session;
|
|
|
|
} // namespace Main
|
|
|
|
|
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;
|
|
|
|
|
2021-11-16 12:38:31 +00:00
|
|
|
struct UploadedMedia {
|
2018-03-25 11:37:57 +00:00
|
|
|
FullMsgId fullId;
|
2021-11-16 12:38:31 +00:00
|
|
|
Api::RemoteFileInfo info;
|
2019-08-12 12:11:34 +00:00
|
|
|
Api::SendOptions options;
|
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;
|
|
|
|
};
|
|
|
|
|
2020-06-11 16:09:46 +00:00
|
|
|
class Uploader final : public QObject {
|
2014-05-30 08:53:19 +00:00
|
|
|
public:
|
2019-04-12 10:50:41 +00:00
|
|
|
explicit Uploader(not_null<ApiWrap*> api);
|
|
|
|
~Uploader();
|
|
|
|
|
2020-06-08 15:17:33 +00:00
|
|
|
[[nodiscard]] Main::Session &session() const;
|
|
|
|
|
2022-01-26 09:41:27 +00:00
|
|
|
[[nodiscard]] FullMsgId currentUploadId() const {
|
|
|
|
return uploadingId;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
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
|
|
|
|
2022-01-26 09:41:27 +00:00
|
|
|
void cancelAll();
|
2014-05-30 08:53:19 +00:00
|
|
|
void clear();
|
|
|
|
|
2021-11-16 12:38:31 +00:00
|
|
|
rpl::producer<UploadedMedia> photoReady() const {
|
2018-03-25 11:37:57 +00:00
|
|
|
return _photoReady.events();
|
|
|
|
}
|
2021-11-16 12:38:31 +00:00
|
|
|
rpl::producer<UploadedMedia> documentReady() const {
|
2018-03-25 11:37:57 +00:00
|
|
|
return _documentReady.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();
|
|
|
|
}
|
|
|
|
|
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);
|
2021-03-12 12:48:00 +00:00
|
|
|
void partFailed(const MTP::Error &error, mtpRequestId requestId);
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2020-07-06 09:58:18 +00:00
|
|
|
void processPhotoProgress(const FullMsgId &msgId);
|
|
|
|
void processPhotoFailed(const FullMsgId &msgId);
|
|
|
|
void processDocumentProgress(const FullMsgId &msgId);
|
|
|
|
void processDocumentFailed(const FullMsgId &msgId);
|
|
|
|
|
2022-01-26 09:41:27 +00:00
|
|
|
void notifyFailed(FullMsgId id, const File &file);
|
2014-05-30 08:53:19 +00:00
|
|
|
void currentFailed();
|
2022-01-26 09:41:27 +00:00
|
|
|
void cancelRequests();
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2020-09-29 08:36:30 +00:00
|
|
|
void sendProgressUpdate(
|
|
|
|
not_null<HistoryItem*> item,
|
|
|
|
Api::SendProgressType type,
|
|
|
|
int progress = 0);
|
|
|
|
|
|
|
|
const not_null<ApiWrap*> _api;
|
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;
|
2021-03-09 09:33:33 +00:00
|
|
|
base::Timer _nextTimer, _stopSessionsTimer;
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2021-11-16 12:38:31 +00:00
|
|
|
rpl::event_stream<UploadedMedia> _photoReady;
|
|
|
|
rpl::event_stream<UploadedMedia> _documentReady;
|
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;
|
|
|
|
|
2020-07-06 09:58:18 +00:00
|
|
|
rpl::lifetime _lifetime;
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
};
|
2017-08-04 14:54:32 +00:00
|
|
|
|
|
|
|
} // namespace Storage
|