2018-06-11 18:35:27 +00:00
|
|
|
/*
|
|
|
|
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
|
|
|
|
|
2019-12-02 13:10:19 +00:00
|
|
|
#include "mtproto/mtproto_concurrent_sender.h"
|
2021-04-09 16:47:28 +00:00
|
|
|
#include "data/data_peer_id.h"
|
2018-06-11 18:35:27 +00:00
|
|
|
|
|
|
|
namespace Export {
|
|
|
|
namespace Data {
|
|
|
|
struct File;
|
2018-06-17 20:15:40 +00:00
|
|
|
struct Chat;
|
2022-07-28 14:48:28 +00:00
|
|
|
struct Document;
|
2018-06-11 18:35:27 +00:00
|
|
|
struct FileLocation;
|
|
|
|
struct PersonalInfo;
|
|
|
|
struct UserpicsInfo;
|
|
|
|
struct UserpicsSlice;
|
|
|
|
struct ContactsList;
|
2018-06-11 18:57:56 +00:00
|
|
|
struct SessionsList;
|
2018-06-12 18:09:21 +00:00
|
|
|
struct DialogsInfo;
|
2018-06-13 13:12:36 +00:00
|
|
|
struct DialogInfo;
|
|
|
|
struct MessagesSlice;
|
2018-06-17 08:39:03 +00:00
|
|
|
struct Message;
|
2019-11-29 06:55:22 +00:00
|
|
|
struct FileOrigin;
|
2018-06-11 18:35:27 +00:00
|
|
|
} // namespace Data
|
|
|
|
|
2018-06-19 10:42:21 +00:00
|
|
|
namespace Output {
|
|
|
|
struct Result;
|
2018-06-20 16:10:38 +00:00
|
|
|
class Stats;
|
2018-06-19 10:42:21 +00:00
|
|
|
} // namespace Output
|
|
|
|
|
2018-06-13 13:12:36 +00:00
|
|
|
struct Settings;
|
|
|
|
|
2018-06-11 18:35:27 +00:00
|
|
|
class ApiWrap {
|
|
|
|
public:
|
2020-06-11 16:09:46 +00:00
|
|
|
ApiWrap(QPointer<MTP::Instance> weak, Fn<void(FnMut<void()>)> runner);
|
2018-06-11 18:35:27 +00:00
|
|
|
|
2021-03-12 12:48:00 +00:00
|
|
|
rpl::producer<MTP::Error> errors() const;
|
2018-06-19 10:42:21 +00:00
|
|
|
rpl::producer<Output::Result> ioErrors() const;
|
2018-06-11 18:35:27 +00:00
|
|
|
|
2018-06-18 21:52:13 +00:00
|
|
|
struct StartInfo {
|
|
|
|
int userpicsCount = 0;
|
|
|
|
int dialogsCount = 0;
|
|
|
|
};
|
2018-06-14 21:47:09 +00:00
|
|
|
void startExport(
|
|
|
|
const Settings &settings,
|
2018-06-20 16:10:38 +00:00
|
|
|
Output::Stats *stats,
|
2018-06-18 21:52:13 +00:00
|
|
|
FnMut<void(StartInfo)> done);
|
|
|
|
|
2018-06-19 10:42:21 +00:00
|
|
|
void requestDialogsList(
|
|
|
|
Fn<bool(int count)> progress,
|
|
|
|
FnMut<void(Data::DialogsInfo&&)> done);
|
2018-06-13 13:12:36 +00:00
|
|
|
|
2018-06-11 18:35:27 +00:00
|
|
|
void requestPersonalInfo(FnMut<void(Data::PersonalInfo&&)> done);
|
|
|
|
|
2018-06-24 00:33:47 +00:00
|
|
|
void requestOtherData(
|
|
|
|
const QString &suggestedPath,
|
|
|
|
FnMut<void(Data::File&&)> done);
|
|
|
|
|
2018-06-19 10:42:21 +00:00
|
|
|
struct DownloadProgress {
|
2021-03-22 12:32:40 +00:00
|
|
|
uint64 randomId = 0;
|
2018-06-19 18:31:30 +00:00
|
|
|
QString path;
|
2018-06-19 10:42:21 +00:00
|
|
|
int itemIndex = 0;
|
2022-05-10 14:22:28 +00:00
|
|
|
int64 ready = 0;
|
|
|
|
int64 total = 0;
|
2018-06-19 10:42:21 +00:00
|
|
|
};
|
2018-06-11 18:35:27 +00:00
|
|
|
void requestUserpics(
|
2018-06-19 10:42:21 +00:00
|
|
|
FnMut<bool(Data::UserpicsInfo&&)> start,
|
|
|
|
Fn<bool(DownloadProgress)> progress,
|
|
|
|
Fn<bool(Data::UserpicsSlice&&)> slice,
|
2018-06-11 18:35:27 +00:00
|
|
|
FnMut<void()> finish);
|
|
|
|
|
|
|
|
void requestContacts(FnMut<void(Data::ContactsList&&)> done);
|
|
|
|
|
2018-06-11 18:57:56 +00:00
|
|
|
void requestSessions(FnMut<void(Data::SessionsList&&)> done);
|
|
|
|
|
2018-06-18 21:52:13 +00:00
|
|
|
void requestMessages(
|
|
|
|
const Data::DialogInfo &info,
|
2018-06-19 10:42:21 +00:00
|
|
|
FnMut<bool(const Data::DialogInfo &)> start,
|
|
|
|
Fn<bool(DownloadProgress)> progress,
|
|
|
|
Fn<bool(Data::MessagesSlice&&)> slice,
|
2018-06-18 21:52:13 +00:00
|
|
|
FnMut<void()> done);
|
2018-06-12 18:09:21 +00:00
|
|
|
|
2018-06-21 00:54:59 +00:00
|
|
|
void finishExport(FnMut<void()> done);
|
2021-03-22 12:32:40 +00:00
|
|
|
void skipFile(uint64 randomId);
|
2018-06-21 00:54:59 +00:00
|
|
|
void cancelExportFast();
|
|
|
|
|
2018-06-11 18:35:27 +00:00
|
|
|
~ApiWrap();
|
|
|
|
|
|
|
|
private:
|
2018-06-18 21:52:13 +00:00
|
|
|
class LoadedFileCache;
|
|
|
|
struct StartProcess;
|
2018-06-19 20:40:16 +00:00
|
|
|
struct ContactsProcess;
|
2018-06-17 08:39:03 +00:00
|
|
|
struct UserpicsProcess;
|
2018-06-24 00:33:47 +00:00
|
|
|
struct OtherDataProcess;
|
2018-06-17 08:39:03 +00:00
|
|
|
struct FileProcess;
|
2018-06-19 10:42:21 +00:00
|
|
|
struct FileProgress;
|
2018-06-21 14:01:27 +00:00
|
|
|
struct ChatsProcess;
|
2018-06-18 21:52:13 +00:00
|
|
|
struct LeftChannelsProcess;
|
2018-06-17 08:39:03 +00:00
|
|
|
struct DialogsProcess;
|
2018-06-18 21:52:13 +00:00
|
|
|
struct ChatProcess;
|
2018-06-17 08:39:03 +00:00
|
|
|
|
2018-06-14 21:47:09 +00:00
|
|
|
void startMainSession(FnMut<void()> done);
|
2018-06-18 21:52:13 +00:00
|
|
|
void sendNextStartRequest();
|
|
|
|
void requestUserpicsCount();
|
2018-06-21 14:01:27 +00:00
|
|
|
void requestSplitRanges();
|
2018-06-18 21:52:13 +00:00
|
|
|
void requestDialogsCount();
|
|
|
|
void requestLeftChannelsCount();
|
|
|
|
void finishStartProcess();
|
2018-06-14 21:47:09 +00:00
|
|
|
|
2018-06-19 20:40:16 +00:00
|
|
|
void requestTopPeersSlice();
|
|
|
|
|
2018-06-11 18:35:27 +00:00
|
|
|
void handleUserpicsSlice(const MTPphotos_Photos &result);
|
|
|
|
void loadUserpicsFiles(Data::UserpicsSlice &&slice);
|
|
|
|
void loadNextUserpic();
|
2018-06-19 10:42:21 +00:00
|
|
|
bool loadUserpicProgress(FileProgress value);
|
2018-06-11 18:35:27 +00:00
|
|
|
void loadUserpicDone(const QString &relativePath);
|
2018-06-19 10:42:21 +00:00
|
|
|
void finishUserpicsSlice();
|
2018-06-11 18:35:27 +00:00
|
|
|
void finishUserpics();
|
|
|
|
|
2018-06-24 00:33:47 +00:00
|
|
|
void otherDataDone(const QString &relativePath);
|
|
|
|
|
2018-06-24 01:34:47 +00:00
|
|
|
bool useOnlyLastSplit() const;
|
2018-06-21 14:01:27 +00:00
|
|
|
|
2018-06-12 18:09:21 +00:00
|
|
|
void requestDialogsSlice();
|
2018-06-13 13:12:36 +00:00
|
|
|
void appendDialogsSlice(Data::DialogsInfo &&info);
|
|
|
|
void finishDialogsList();
|
2018-07-23 13:11:56 +00:00
|
|
|
void requestSinglePeerDialog();
|
2019-04-09 14:55:21 +00:00
|
|
|
mtpRequestId requestSinglePeerMigrated(const Data::DialogInfo &info);
|
|
|
|
void appendSinglePeerDialogs(Data::DialogsInfo &&info);
|
2018-06-13 13:12:36 +00:00
|
|
|
|
2018-07-11 21:06:35 +00:00
|
|
|
void requestLeftChannelsIfNeeded();
|
|
|
|
void requestLeftChannelsList(
|
|
|
|
Fn<bool(int count)> progress,
|
|
|
|
FnMut<void(Data::DialogsInfo&&)> done);
|
2018-06-18 21:52:13 +00:00
|
|
|
void requestLeftChannelsSliceGeneric(FnMut<void()> done);
|
|
|
|
void requestLeftChannelsSlice();
|
|
|
|
void appendLeftChannelsSlice(Data::DialogsInfo &&info);
|
|
|
|
|
2018-06-21 14:01:27 +00:00
|
|
|
void appendChatsSlice(
|
2018-07-11 21:06:35 +00:00
|
|
|
ChatsProcess &process,
|
|
|
|
std::vector<Data::DialogInfo> &to,
|
|
|
|
std::vector<Data::DialogInfo> &&from,
|
2018-06-21 14:01:27 +00:00
|
|
|
int splitIndex);
|
|
|
|
|
|
|
|
void requestMessagesCount(int localSplitIndex);
|
2018-10-06 12:17:29 +00:00
|
|
|
void checkFirstMessageDate(int localSplitIndex, int count);
|
|
|
|
void messagesCountLoaded(int localSplitIndex, int count);
|
2018-06-21 14:01:27 +00:00
|
|
|
void requestMessagesSlice();
|
|
|
|
void requestChatMessages(
|
|
|
|
int splitIndex,
|
|
|
|
int offsetId,
|
|
|
|
int addOffset,
|
|
|
|
int limit,
|
|
|
|
FnMut<void(MTPmessages_Messages&&)> done);
|
2022-07-28 14:48:28 +00:00
|
|
|
void collectMessagesCustomEmoji(const Data::MessagesSlice &slice);
|
|
|
|
void resolveCustomEmoji();
|
2018-06-13 13:12:36 +00:00
|
|
|
void loadMessagesFiles(Data::MessagesSlice &&slice);
|
|
|
|
void loadNextMessageFile();
|
2022-07-28 14:48:28 +00:00
|
|
|
bool messageCustomEmojiReady(Data::Message &message);
|
2018-06-19 10:42:21 +00:00
|
|
|
bool loadMessageFileProgress(FileProgress value);
|
2018-06-13 13:12:36 +00:00
|
|
|
void loadMessageFileDone(const QString &relativePath);
|
2018-07-07 20:58:54 +00:00
|
|
|
bool loadMessageThumbProgress(FileProgress value);
|
|
|
|
void loadMessageThumbDone(const QString &relativePath);
|
2022-07-28 14:48:28 +00:00
|
|
|
bool loadMessageEmojiProgress(FileProgress progress);
|
|
|
|
void loadMessageEmojiDone(uint64 id, const QString &relativePath);
|
2018-06-17 20:15:40 +00:00
|
|
|
void finishMessagesSlice();
|
2018-06-13 13:12:36 +00:00
|
|
|
void finishMessages();
|
2018-06-12 18:09:21 +00:00
|
|
|
|
2019-11-29 06:55:22 +00:00
|
|
|
[[nodiscard]] Data::Message *currentFileMessage() const;
|
|
|
|
[[nodiscard]] Data::FileOrigin currentFileMessageOrigin() const;
|
|
|
|
|
2018-06-17 08:39:03 +00:00
|
|
|
bool processFileLoad(
|
|
|
|
Data::File &file,
|
2019-11-29 06:55:22 +00:00
|
|
|
const Data::FileOrigin &origin,
|
2018-06-19 10:42:21 +00:00
|
|
|
Fn<bool(FileProgress)> progress,
|
2018-06-17 08:39:03 +00:00
|
|
|
FnMut<void(QString)> done,
|
|
|
|
Data::Message *message = nullptr);
|
|
|
|
std::unique_ptr<FileProcess> prepareFileProcess(
|
2019-11-29 06:55:22 +00:00
|
|
|
const Data::File &file,
|
|
|
|
const Data::FileOrigin &origin) const;
|
|
|
|
bool writePreloadedFile(
|
|
|
|
Data::File &file,
|
|
|
|
const Data::FileOrigin &origin);
|
2018-06-18 21:52:13 +00:00
|
|
|
void loadFile(
|
|
|
|
const Data::File &file,
|
2019-11-29 06:55:22 +00:00
|
|
|
const Data::FileOrigin &origin,
|
2018-06-19 10:42:21 +00:00
|
|
|
Fn<bool(FileProgress)> progress,
|
2018-06-18 21:52:13 +00:00
|
|
|
FnMut<void(QString)> done);
|
2018-06-11 18:35:27 +00:00
|
|
|
void loadFilePart();
|
2022-05-10 14:22:28 +00:00
|
|
|
void filePartDone(int64 offset, const MTPupload_File &result);
|
2018-06-24 12:30:09 +00:00
|
|
|
void filePartUnavailable();
|
2022-05-10 14:22:28 +00:00
|
|
|
void filePartRefreshReference(int64 offset);
|
2019-11-29 06:55:22 +00:00
|
|
|
void filePartExtractReference(
|
2022-05-10 14:22:28 +00:00
|
|
|
int64 offset,
|
2019-11-29 06:55:22 +00:00
|
|
|
const MTPmessages_Messages &result);
|
2018-06-11 18:35:27 +00:00
|
|
|
|
2018-06-28 16:25:50 +00:00
|
|
|
template <typename Request>
|
|
|
|
class RequestBuilder;
|
|
|
|
|
2018-06-11 18:35:27 +00:00
|
|
|
template <typename Request>
|
|
|
|
[[nodiscard]] auto mainRequest(Request &&request);
|
|
|
|
|
2018-06-21 14:01:27 +00:00
|
|
|
template <typename Request>
|
|
|
|
[[nodiscard]] auto splitRequest(int index, Request &&request);
|
|
|
|
|
2018-06-11 18:35:27 +00:00
|
|
|
[[nodiscard]] auto fileRequest(
|
|
|
|
const Data::FileLocation &location,
|
2022-05-10 14:22:28 +00:00
|
|
|
int64 offset);
|
2018-06-11 18:35:27 +00:00
|
|
|
|
2021-03-12 12:48:00 +00:00
|
|
|
void error(const MTP::Error &error);
|
2018-06-11 18:35:27 +00:00
|
|
|
void error(const QString &text);
|
2018-06-19 10:42:21 +00:00
|
|
|
void ioError(const Output::Result &result);
|
2018-06-11 18:35:27 +00:00
|
|
|
|
|
|
|
MTP::ConcurrentSender _mtp;
|
2018-09-21 16:28:46 +00:00
|
|
|
std::optional<uint64> _takeoutId;
|
2021-04-09 16:47:28 +00:00
|
|
|
std::optional<UserId> _selfId;
|
2018-06-20 16:10:38 +00:00
|
|
|
Output::Stats *_stats = nullptr;
|
2018-06-13 13:12:36 +00:00
|
|
|
|
|
|
|
std::unique_ptr<Settings> _settings;
|
2018-06-11 18:35:27 +00:00
|
|
|
MTPInputUser _user = MTP_inputUserSelf();
|
|
|
|
|
2018-06-18 21:52:13 +00:00
|
|
|
std::unique_ptr<StartProcess> _startProcess;
|
2018-06-17 12:47:47 +00:00
|
|
|
std::unique_ptr<LoadedFileCache> _fileCache;
|
2018-06-19 20:40:16 +00:00
|
|
|
std::unique_ptr<ContactsProcess> _contactsProcess;
|
2018-06-11 18:35:27 +00:00
|
|
|
std::unique_ptr<UserpicsProcess> _userpicsProcess;
|
2018-06-24 00:33:47 +00:00
|
|
|
std::unique_ptr<OtherDataProcess> _otherDataProcess;
|
2018-06-11 18:35:27 +00:00
|
|
|
std::unique_ptr<FileProcess> _fileProcess;
|
2018-06-18 21:52:13 +00:00
|
|
|
std::unique_ptr<LeftChannelsProcess> _leftChannelsProcess;
|
2018-06-12 18:09:21 +00:00
|
|
|
std::unique_ptr<DialogsProcess> _dialogsProcess;
|
2018-06-18 21:52:13 +00:00
|
|
|
std::unique_ptr<ChatProcess> _chatProcess;
|
2022-07-28 14:48:28 +00:00
|
|
|
base::flat_set<uint64> _unresolvedCustomEmoji;
|
|
|
|
base::flat_map<uint64, Data::Document> _resolvedCustomEmoji;
|
2018-06-21 14:01:27 +00:00
|
|
|
QVector<MTPMessageRange> _splits;
|
2018-06-12 18:09:21 +00:00
|
|
|
|
2021-03-12 12:48:00 +00:00
|
|
|
rpl::event_stream<MTP::Error> _errors;
|
2018-06-19 10:42:21 +00:00
|
|
|
rpl::event_stream<Output::Result> _ioErrors;
|
2018-06-11 18:35:27 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Export
|