tdesktop/Telegram/SourceFiles/export/export_api_wrap.h

219 lines
5.7 KiB
C
Raw Normal View History

/*
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
#include "mtproto/concurrent_sender.h"
namespace Export {
namespace Data {
struct File;
2018-06-17 20:15:40 +00:00
struct Chat;
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;
struct Message;
} // namespace Data
namespace Output {
struct Result;
class Stats;
} // namespace Output
2018-06-13 13:12:36 +00:00
struct Settings;
class ApiWrap {
public:
explicit ApiWrap(Fn<void(FnMut<void()>)> runner);
rpl::producer<RPCError> errors() const;
rpl::producer<Output::Result> ioErrors() const;
2018-06-18 21:52:13 +00:00
struct StartInfo {
int userpicsCount = 0;
int dialogsCount = 0;
};
void startExport(
const Settings &settings,
Output::Stats *stats,
2018-06-18 21:52:13 +00:00
FnMut<void(StartInfo)> done);
void requestDialogsList(
Fn<bool(int count)> progress,
FnMut<void(Data::DialogsInfo&&)> done);
2018-06-13 13:12:36 +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);
struct DownloadProgress {
2018-06-19 18:31:30 +00:00
QString path;
int itemIndex = 0;
int ready = 0;
int total = 0;
};
void requestUserpics(
FnMut<bool(Data::UserpicsInfo&&)> start,
Fn<bool(DownloadProgress)> progress,
Fn<bool(Data::UserpicsSlice&&)> slice,
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,
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);
void cancelExportFast();
~ApiWrap();
private:
2018-06-18 21:52:13 +00:00
class LoadedFileCache;
struct StartProcess;
2018-06-19 20:40:16 +00:00
struct ContactsProcess;
struct UserpicsProcess;
2018-06-24 00:33:47 +00:00
struct OtherDataProcess;
struct FileProcess;
struct FileProgress;
struct ChatsProcess;
2018-06-18 21:52:13 +00:00
struct LeftChannelsProcess;
struct DialogsProcess;
2018-06-18 21:52:13 +00:00
struct ChatProcess;
void startMainSession(FnMut<void()> done);
2018-06-18 21:52:13 +00:00
void sendNextStartRequest();
void requestUserpicsCount();
void requestSplitRanges();
2018-06-18 21:52:13 +00:00
void requestDialogsCount();
void requestLeftChannelsCount();
void finishStartProcess();
2018-06-19 20:40:16 +00:00
void requestTopPeersSlice();
void handleUserpicsSlice(const MTPphotos_Photos &result);
void loadUserpicsFiles(Data::UserpicsSlice &&slice);
void loadNextUserpic();
bool loadUserpicProgress(FileProgress value);
void loadUserpicDone(const QString &relativePath);
void finishUserpicsSlice();
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-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();
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);
void appendChatsSlice(
2018-07-11 21:06:35 +00:00
ChatsProcess &process,
std::vector<Data::DialogInfo> &to,
std::vector<Data::DialogInfo> &&from,
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);
void requestMessagesSlice();
void requestChatMessages(
int splitIndex,
int offsetId,
int addOffset,
int limit,
FnMut<void(MTPmessages_Messages&&)> done);
2018-06-13 13:12:36 +00:00
void loadMessagesFiles(Data::MessagesSlice &&slice);
void loadNextMessageFile();
bool loadMessageFileProgress(FileProgress value);
2018-06-13 13:12:36 +00:00
void loadMessageFileDone(const QString &relativePath);
bool loadMessageThumbProgress(FileProgress value);
void loadMessageThumbDone(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
bool processFileLoad(
Data::File &file,
Fn<bool(FileProgress)> progress,
FnMut<void(QString)> done,
Data::Message *message = nullptr);
std::unique_ptr<FileProcess> prepareFileProcess(
const Data::File &file) const;
bool writePreloadedFile(Data::File &file);
2018-06-18 21:52:13 +00:00
void loadFile(
const Data::File &file,
Fn<bool(FileProgress)> progress,
2018-06-18 21:52:13 +00:00
FnMut<void(QString)> done);
void loadFilePart();
void filePartDone(int offset, const MTPupload_File &result);
2018-06-24 12:30:09 +00:00
void filePartUnavailable();
template <typename Request>
class RequestBuilder;
template <typename Request>
[[nodiscard]] auto mainRequest(Request &&request);
template <typename Request>
[[nodiscard]] auto splitRequest(int index, Request &&request);
[[nodiscard]] auto fileRequest(
const Data::FileLocation &location,
int offset);
void error(RPCError &&error);
void error(const QString &text);
void ioError(const Output::Result &result);
MTP::ConcurrentSender _mtp;
2018-09-21 16:28:46 +00:00
std::optional<uint64> _takeoutId;
Output::Stats *_stats = nullptr;
2018-06-13 13:12:36 +00:00
std::unique_ptr<Settings> _settings;
MTPInputUser _user = MTP_inputUserSelf();
2018-06-18 21:52:13 +00:00
std::unique_ptr<StartProcess> _startProcess;
std::unique_ptr<LoadedFileCache> _fileCache;
2018-06-19 20:40:16 +00:00
std::unique_ptr<ContactsProcess> _contactsProcess;
std::unique_ptr<UserpicsProcess> _userpicsProcess;
2018-06-24 00:33:47 +00:00
std::unique_ptr<OtherDataProcess> _otherDataProcess;
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;
QVector<MTPMessageRange> _splits;
2018-06-12 18:09:21 +00:00
rpl::event_stream<RPCError> _errors;
rpl::event_stream<Output::Result> _ioErrors;
};
} // namespace Export