/* 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/mtproto_concurrent_sender.h" namespace Export { namespace Data { struct File; struct Chat; struct FileLocation; struct PersonalInfo; struct UserpicsInfo; struct UserpicsSlice; struct ContactsList; struct SessionsList; struct DialogsInfo; struct DialogInfo; struct MessagesSlice; struct Message; struct FileOrigin; } // namespace Data namespace Output { struct Result; class Stats; } // namespace Output struct Settings; class ApiWrap { public: ApiWrap(QPointer weak, Fn)> runner); rpl::producer errors() const; rpl::producer ioErrors() const; struct StartInfo { int userpicsCount = 0; int dialogsCount = 0; }; void startExport( const Settings &settings, Output::Stats *stats, FnMut done); void requestDialogsList( Fn progress, FnMut done); void requestPersonalInfo(FnMut done); void requestOtherData( const QString &suggestedPath, FnMut done); struct DownloadProgress { uint64 randomId = 0; QString path; int itemIndex = 0; int ready = 0; int total = 0; }; void requestUserpics( FnMut start, Fn progress, Fn slice, FnMut finish); void requestContacts(FnMut done); void requestSessions(FnMut done); void requestMessages( const Data::DialogInfo &info, FnMut start, Fn progress, Fn slice, FnMut done); void finishExport(FnMut done); void skipFile(uint64 randomId); void cancelExportFast(); ~ApiWrap(); private: class LoadedFileCache; struct StartProcess; struct ContactsProcess; struct UserpicsProcess; struct OtherDataProcess; struct FileProcess; struct FileProgress; struct ChatsProcess; struct LeftChannelsProcess; struct DialogsProcess; struct ChatProcess; void startMainSession(FnMut done); void sendNextStartRequest(); void requestUserpicsCount(); void requestSplitRanges(); void requestDialogsCount(); void requestLeftChannelsCount(); void finishStartProcess(); 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(); void otherDataDone(const QString &relativePath); bool useOnlyLastSplit() const; void requestDialogsSlice(); void appendDialogsSlice(Data::DialogsInfo &&info); void finishDialogsList(); void requestSinglePeerDialog(); mtpRequestId requestSinglePeerMigrated(const Data::DialogInfo &info); void appendSinglePeerDialogs(Data::DialogsInfo &&info); void requestLeftChannelsIfNeeded(); void requestLeftChannelsList( Fn progress, FnMut done); void requestLeftChannelsSliceGeneric(FnMut done); void requestLeftChannelsSlice(); void appendLeftChannelsSlice(Data::DialogsInfo &&info); void appendChatsSlice( ChatsProcess &process, std::vector &to, std::vector &&from, int splitIndex); void requestMessagesCount(int localSplitIndex); 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 done); void loadMessagesFiles(Data::MessagesSlice &&slice); void loadNextMessageFile(); bool loadMessageFileProgress(FileProgress value); void loadMessageFileDone(const QString &relativePath); bool loadMessageThumbProgress(FileProgress value); void loadMessageThumbDone(const QString &relativePath); void finishMessagesSlice(); void finishMessages(); [[nodiscard]] Data::Message *currentFileMessage() const; [[nodiscard]] Data::FileOrigin currentFileMessageOrigin() const; bool processFileLoad( Data::File &file, const Data::FileOrigin &origin, Fn progress, FnMut done, Data::Message *message = nullptr); std::unique_ptr prepareFileProcess( const Data::File &file, const Data::FileOrigin &origin) const; bool writePreloadedFile( Data::File &file, const Data::FileOrigin &origin); void loadFile( const Data::File &file, const Data::FileOrigin &origin, Fn progress, FnMut done); void loadFilePart(); void filePartDone(int offset, const MTPupload_File &result); void filePartUnavailable(); void filePartRefreshReference(int offset); void filePartExtractReference( int offset, const MTPmessages_Messages &result); template class RequestBuilder; template [[nodiscard]] auto mainRequest(Request &&request); template [[nodiscard]] auto splitRequest(int index, Request &&request); [[nodiscard]] auto fileRequest( const Data::FileLocation &location, int offset); void error(const MTP::Error &error); void error(const QString &text); void ioError(const Output::Result &result); MTP::ConcurrentSender _mtp; std::optional _takeoutId; std::optional _selfId; Output::Stats *_stats = nullptr; std::unique_ptr _settings; MTPInputUser _user = MTP_inputUserSelf(); std::unique_ptr _startProcess; std::unique_ptr _fileCache; std::unique_ptr _contactsProcess; std::unique_ptr _userpicsProcess; std::unique_ptr _otherDataProcess; std::unique_ptr _fileProcess; std::unique_ptr _leftChannelsProcess; std::unique_ptr _dialogsProcess; std::unique_ptr _chatProcess; QVector _splits; rpl::event_stream _errors; rpl::event_stream _ioErrors; }; } // namespace Export