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
|
|
|
|
*/
|
|
|
|
#include "export/export_api_wrap.h"
|
|
|
|
|
2018-06-13 13:12:36 +00:00
|
|
|
#include "export/export_settings.h"
|
2018-06-11 18:35:27 +00:00
|
|
|
#include "export/data/export_data_types.h"
|
2018-06-19 10:42:21 +00:00
|
|
|
#include "export/output/export_output_result.h"
|
2018-06-11 18:35:27 +00:00
|
|
|
#include "export/output/export_output_file.h"
|
2021-03-12 12:48:00 +00:00
|
|
|
#include "mtproto/mtproto_response.h"
|
2018-06-14 21:47:09 +00:00
|
|
|
#include "base/bytes.h"
|
2021-09-15 10:21:45 +00:00
|
|
|
#include "base/random.h"
|
2018-06-21 14:01:27 +00:00
|
|
|
#include <set>
|
2018-06-11 18:35:27 +00:00
|
|
|
#include <deque>
|
|
|
|
|
|
|
|
namespace Export {
|
|
|
|
namespace {
|
|
|
|
|
2018-06-12 18:09:21 +00:00
|
|
|
constexpr auto kUserpicsSliceLimit = 100;
|
2018-06-11 18:35:27 +00:00
|
|
|
constexpr auto kFileChunkSize = 128 * 1024;
|
|
|
|
constexpr auto kFileRequestsCount = 2;
|
2021-07-13 17:51:07 +00:00
|
|
|
//constexpr auto kFileNextRequestDelay = crl::time(20);
|
2018-06-13 13:12:36 +00:00
|
|
|
constexpr auto kChatsSliceLimit = 100;
|
|
|
|
constexpr auto kMessagesSliceLimit = 100;
|
2018-06-19 20:40:16 +00:00
|
|
|
constexpr auto kTopPeerSliceLimit = 100;
|
2022-05-19 15:11:45 +00:00
|
|
|
constexpr auto kFileMaxSize = 4000 * int64(1024 * 1024);
|
2018-06-17 12:47:47 +00:00
|
|
|
constexpr auto kLocationCacheSize = 100'000;
|
2022-07-28 14:48:28 +00:00
|
|
|
constexpr auto kMaxEmojiPerRequest = 100;
|
2023-06-16 17:23:40 +00:00
|
|
|
constexpr auto kStoriesSliceLimit = 100;
|
2018-06-11 18:35:27 +00:00
|
|
|
|
2018-06-17 12:47:47 +00:00
|
|
|
struct LocationKey {
|
|
|
|
uint64 type;
|
|
|
|
uint64 id;
|
|
|
|
|
|
|
|
inline bool operator<(const LocationKey &other) const {
|
|
|
|
return std::tie(type, id) < std::tie(other.type, other.id);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
LocationKey ComputeLocationKey(const Data::FileLocation &value) {
|
|
|
|
auto result = LocationKey();
|
|
|
|
result.type = value.dcId;
|
2021-03-30 08:16:05 +00:00
|
|
|
value.data.match([&](const MTPDinputDocumentFileLocation &data) {
|
2019-07-05 13:38:38 +00:00
|
|
|
const auto letter = data.vthumb_size().v.isEmpty()
|
2019-03-22 13:43:34 +00:00
|
|
|
? char(0)
|
2019-07-05 13:38:38 +00:00
|
|
|
: data.vthumb_size().v[0];
|
2018-06-17 12:47:47 +00:00
|
|
|
result.type |= (2ULL << 24);
|
2019-03-22 13:43:34 +00:00
|
|
|
result.type |= (uint64(uint32(letter)) << 16);
|
2019-07-05 13:38:38 +00:00
|
|
|
result.id = data.vid().v;
|
2019-03-22 13:43:34 +00:00
|
|
|
}, [&](const MTPDinputPhotoFileLocation &data) {
|
2019-07-05 13:38:38 +00:00
|
|
|
const auto letter = data.vthumb_size().v.isEmpty()
|
2019-03-22 13:43:34 +00:00
|
|
|
? char(0)
|
2019-07-05 13:38:38 +00:00
|
|
|
: data.vthumb_size().v[0];
|
2019-03-22 13:43:34 +00:00
|
|
|
result.type |= (6ULL << 24);
|
|
|
|
result.type |= (uint64(uint32(letter)) << 16);
|
2019-07-05 13:38:38 +00:00
|
|
|
result.id = data.vid().v;
|
2021-03-30 08:16:05 +00:00
|
|
|
}, [&](const MTPDinputTakeoutFileLocation &data) {
|
|
|
|
result.type |= (5ULL << 24);
|
|
|
|
}, [](const auto &data) {
|
|
|
|
Unexpected("File location type in Export::ComputeLocationKey.");
|
2018-06-17 12:47:47 +00:00
|
|
|
});
|
|
|
|
return result;
|
2018-06-13 17:10:12 +00:00
|
|
|
}
|
|
|
|
|
2018-06-18 21:52:13 +00:00
|
|
|
Settings::Type SettingsFromDialogsType(Data::DialogInfo::Type type) {
|
|
|
|
using DialogType = Data::DialogInfo::Type;
|
|
|
|
switch (type) {
|
2018-06-23 20:27:41 +00:00
|
|
|
case DialogType::Self:
|
2018-06-18 21:52:13 +00:00
|
|
|
case DialogType::Personal:
|
|
|
|
return Settings::Type::PersonalChats;
|
|
|
|
case DialogType::Bot:
|
|
|
|
return Settings::Type::BotChats;
|
|
|
|
case DialogType::PrivateGroup:
|
2018-06-23 20:27:41 +00:00
|
|
|
case DialogType::PrivateSupergroup:
|
2018-06-18 21:52:13 +00:00
|
|
|
return Settings::Type::PrivateGroups;
|
2018-06-23 20:27:41 +00:00
|
|
|
case DialogType::PublicSupergroup:
|
2018-06-18 21:52:13 +00:00
|
|
|
return Settings::Type::PublicGroups;
|
|
|
|
case DialogType::PrivateChannel:
|
|
|
|
return Settings::Type::PrivateChannels;
|
|
|
|
case DialogType::PublicChannel:
|
|
|
|
return Settings::Type::PublicChannels;
|
|
|
|
}
|
|
|
|
return Settings::Type(0);
|
|
|
|
}
|
|
|
|
|
2018-06-11 18:35:27 +00:00
|
|
|
} // namespace
|
|
|
|
|
2018-06-17 12:47:47 +00:00
|
|
|
class ApiWrap::LoadedFileCache {
|
|
|
|
public:
|
|
|
|
using Location = Data::FileLocation;
|
|
|
|
|
|
|
|
LoadedFileCache(int limit);
|
|
|
|
|
|
|
|
void save(const Location &location, const QString &relativePath);
|
2018-09-21 16:28:46 +00:00
|
|
|
std::optional<QString> find(const Location &location) const;
|
2018-06-17 12:47:47 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
int _limit = 0;
|
|
|
|
std::map<LocationKey, QString> _map;
|
|
|
|
std::deque<LocationKey> _list;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2018-06-18 21:52:13 +00:00
|
|
|
struct ApiWrap::StartProcess {
|
|
|
|
FnMut<void(StartInfo)> done;
|
|
|
|
|
|
|
|
enum class Step {
|
|
|
|
UserpicsCount,
|
2023-06-16 17:23:40 +00:00
|
|
|
StoriesCount,
|
2018-06-21 14:01:27 +00:00
|
|
|
SplitRanges,
|
2018-06-18 21:52:13 +00:00
|
|
|
DialogsCount,
|
|
|
|
LeftChannelsCount,
|
|
|
|
};
|
|
|
|
std::deque<Step> steps;
|
2018-06-21 14:01:27 +00:00
|
|
|
int splitIndex = 0;
|
2018-06-18 21:52:13 +00:00
|
|
|
StartInfo info;
|
2018-06-19 20:40:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ApiWrap::ContactsProcess {
|
|
|
|
FnMut<void(Data::ContactsList&&)> done;
|
|
|
|
|
|
|
|
Data::ContactsList result;
|
2018-06-18 21:52:13 +00:00
|
|
|
|
2018-06-19 20:40:16 +00:00
|
|
|
int topPeersOffset = 0;
|
2018-06-18 21:52:13 +00:00
|
|
|
};
|
|
|
|
|
2018-06-11 18:35:27 +00:00
|
|
|
struct ApiWrap::UserpicsProcess {
|
2018-06-19 10:42:21 +00:00
|
|
|
FnMut<bool(Data::UserpicsInfo&&)> start;
|
|
|
|
Fn<bool(DownloadProgress)> fileProgress;
|
|
|
|
Fn<bool(Data::UserpicsSlice&&)> handleSlice;
|
2018-06-11 18:35:27 +00:00
|
|
|
FnMut<void()> finish;
|
|
|
|
|
2018-06-20 20:32:52 +00:00
|
|
|
int processed = 0;
|
2018-09-21 16:28:46 +00:00
|
|
|
std::optional<Data::UserpicsSlice> slice;
|
2018-06-19 10:42:21 +00:00
|
|
|
uint64 maxId = 0;
|
2018-06-11 18:35:27 +00:00
|
|
|
bool lastSlice = false;
|
2018-07-07 20:58:54 +00:00
|
|
|
int fileIndex = 0;
|
2018-06-11 18:35:27 +00:00
|
|
|
};
|
|
|
|
|
2023-06-16 17:23:40 +00:00
|
|
|
struct ApiWrap::StoriesProcess {
|
|
|
|
FnMut<bool(Data::StoriesInfo&&)> start;
|
|
|
|
Fn<bool(DownloadProgress)> fileProgress;
|
|
|
|
Fn<bool(Data::StoriesSlice&&)> handleSlice;
|
|
|
|
FnMut<void()> finish;
|
|
|
|
|
|
|
|
int processed = 0;
|
|
|
|
std::optional<Data::StoriesSlice> slice;
|
|
|
|
int offsetId = 0;
|
|
|
|
bool lastSlice = false;
|
|
|
|
int fileIndex = 0;
|
|
|
|
};
|
|
|
|
|
2018-06-24 00:33:47 +00:00
|
|
|
struct ApiWrap::OtherDataProcess {
|
|
|
|
Data::File file;
|
|
|
|
FnMut<void(Data::File&&)> done;
|
|
|
|
};
|
|
|
|
|
2018-06-11 18:35:27 +00:00
|
|
|
struct ApiWrap::FileProcess {
|
2018-06-20 16:10:38 +00:00
|
|
|
FileProcess(const QString &path, Output::Stats *stats);
|
2018-06-11 18:35:27 +00:00
|
|
|
|
|
|
|
Output::File file;
|
|
|
|
QString relativePath;
|
|
|
|
|
2018-06-19 10:42:21 +00:00
|
|
|
Fn<bool(FileProgress)> progress;
|
2018-06-11 18:35:27 +00:00
|
|
|
FnMut<void(const QString &relativePath)> done;
|
|
|
|
|
2021-03-22 12:32:40 +00:00
|
|
|
uint64 randomId = 0;
|
2018-06-11 18:35:27 +00:00
|
|
|
Data::FileLocation location;
|
2019-11-29 06:55:22 +00:00
|
|
|
Data::FileOrigin origin;
|
2022-05-10 14:22:28 +00:00
|
|
|
int64 offset = 0;
|
|
|
|
int64 size = 0;
|
2018-06-11 18:35:27 +00:00
|
|
|
|
|
|
|
struct Request {
|
2022-05-10 14:22:28 +00:00
|
|
|
int64 offset = 0;
|
2018-06-11 18:35:27 +00:00
|
|
|
QByteArray bytes;
|
|
|
|
};
|
|
|
|
std::deque<Request> requests;
|
2021-03-22 12:32:40 +00:00
|
|
|
mtpRequestId requestId = 0;
|
2018-06-11 18:35:27 +00:00
|
|
|
};
|
|
|
|
|
2018-06-19 10:42:21 +00:00
|
|
|
struct ApiWrap::FileProgress {
|
2022-05-10 14:22:28 +00:00
|
|
|
int64 ready = 0;
|
|
|
|
int64 total = 0;
|
2018-06-19 10:42:21 +00:00
|
|
|
};
|
|
|
|
|
2018-06-21 14:01:27 +00:00
|
|
|
struct ApiWrap::ChatsProcess {
|
2018-06-19 10:42:21 +00:00
|
|
|
Fn<bool(int count)> progress;
|
2018-06-18 21:52:13 +00:00
|
|
|
FnMut<void(Data::DialogsInfo&&)> done;
|
|
|
|
|
2018-06-12 18:09:21 +00:00
|
|
|
Data::DialogsInfo info;
|
2018-06-21 14:01:27 +00:00
|
|
|
int processedCount = 0;
|
2021-04-09 16:47:28 +00:00
|
|
|
std::map<PeerId, int> indexByPeer;
|
2018-06-21 14:01:27 +00:00
|
|
|
};
|
2018-06-12 18:09:21 +00:00
|
|
|
|
2018-06-21 14:01:27 +00:00
|
|
|
struct ApiWrap::LeftChannelsProcess : ChatsProcess {
|
2018-06-18 21:52:13 +00:00
|
|
|
int fullCount = 0;
|
2018-06-19 10:42:21 +00:00
|
|
|
int offset = 0;
|
2018-06-18 21:52:13 +00:00
|
|
|
bool finished = false;
|
|
|
|
};
|
|
|
|
|
2018-06-21 14:01:27 +00:00
|
|
|
struct ApiWrap::DialogsProcess : ChatsProcess {
|
|
|
|
int splitIndexPlusOne = 0;
|
2018-06-22 23:18:43 +00:00
|
|
|
TimeId offsetDate = 0;
|
2018-06-12 18:09:21 +00:00
|
|
|
int32 offsetId = 0;
|
|
|
|
MTPInputPeer offsetPeer = MTP_inputPeerEmpty();
|
2018-06-13 13:12:36 +00:00
|
|
|
};
|
|
|
|
|
2018-06-18 21:52:13 +00:00
|
|
|
struct ApiWrap::ChatProcess {
|
2018-06-13 17:10:12 +00:00
|
|
|
Data::DialogInfo info;
|
2018-06-18 21:52:13 +00:00
|
|
|
|
2018-06-19 10:42:21 +00:00
|
|
|
FnMut<bool(const Data::DialogInfo &)> start;
|
|
|
|
Fn<bool(DownloadProgress)> fileProgress;
|
|
|
|
Fn<bool(Data::MessagesSlice&&)> handleSlice;
|
2018-06-18 21:52:13 +00:00
|
|
|
FnMut<void()> done;
|
|
|
|
|
2018-06-28 16:25:50 +00:00
|
|
|
FnMut<void(MTPmessages_Messages&&)> requestDone;
|
|
|
|
|
2018-06-21 14:01:27 +00:00
|
|
|
int localSplitIndex = 0;
|
|
|
|
int32 largestIdPlusOne = 1;
|
2018-06-13 13:12:36 +00:00
|
|
|
|
2018-06-20 20:32:52 +00:00
|
|
|
Data::ParseMediaContext context;
|
2018-09-21 16:28:46 +00:00
|
|
|
std::optional<Data::MessagesSlice> slice;
|
2018-06-13 13:12:36 +00:00
|
|
|
bool lastSlice = false;
|
2018-07-07 20:58:54 +00:00
|
|
|
int fileIndex = 0;
|
2018-06-12 18:09:21 +00:00
|
|
|
};
|
|
|
|
|
2018-06-28 16:25:50 +00:00
|
|
|
|
|
|
|
template <typename Request>
|
|
|
|
class ApiWrap::RequestBuilder {
|
|
|
|
public:
|
|
|
|
using Original = MTP::ConcurrentSender::SpecificRequestBuilder<Request>;
|
|
|
|
using Response = typename Request::ResponseType;
|
|
|
|
|
|
|
|
RequestBuilder(
|
|
|
|
Original &&builder,
|
2021-03-12 12:48:00 +00:00
|
|
|
Fn<void(const MTP::Error&)> commonFailHandler);
|
2018-06-28 16:25:50 +00:00
|
|
|
|
|
|
|
[[nodiscard]] RequestBuilder &done(FnMut<void()> &&handler);
|
|
|
|
[[nodiscard]] RequestBuilder &done(
|
|
|
|
FnMut<void(Response &&)> &&handler);
|
|
|
|
[[nodiscard]] RequestBuilder &fail(
|
2021-03-12 12:48:00 +00:00
|
|
|
Fn<bool(const MTP::Error&)> &&handler);
|
2018-06-28 16:25:50 +00:00
|
|
|
|
|
|
|
mtpRequestId send();
|
|
|
|
|
|
|
|
private:
|
|
|
|
Original _builder;
|
2021-03-12 12:48:00 +00:00
|
|
|
Fn<void(const MTP::Error&)> _commonFailHandler;
|
2018-06-28 16:25:50 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename Request>
|
|
|
|
ApiWrap::RequestBuilder<Request>::RequestBuilder(
|
|
|
|
Original &&builder,
|
2021-03-12 12:48:00 +00:00
|
|
|
Fn<void(const MTP::Error&)> commonFailHandler)
|
2018-06-28 16:25:50 +00:00
|
|
|
: _builder(std::move(builder))
|
|
|
|
, _commonFailHandler(std::move(commonFailHandler)) {
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Request>
|
|
|
|
auto ApiWrap::RequestBuilder<Request>::done(
|
|
|
|
FnMut<void()> &&handler
|
|
|
|
) -> RequestBuilder& {
|
|
|
|
if (handler) {
|
2021-07-13 17:51:07 +00:00
|
|
|
[[maybe_unused]] auto &silence_warning = _builder.done(std::move(handler));
|
2018-06-28 16:25:50 +00:00
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Request>
|
|
|
|
auto ApiWrap::RequestBuilder<Request>::done(
|
|
|
|
FnMut<void(Response &&)> &&handler
|
|
|
|
) -> RequestBuilder& {
|
|
|
|
if (handler) {
|
2021-07-13 17:51:07 +00:00
|
|
|
[[maybe_unused]] auto &silence_warning = _builder.done(std::move(handler));
|
2018-06-28 16:25:50 +00:00
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Request>
|
|
|
|
auto ApiWrap::RequestBuilder<Request>::fail(
|
2021-03-12 12:48:00 +00:00
|
|
|
Fn<bool(const MTP::Error &)> &&handler
|
2018-06-28 16:25:50 +00:00
|
|
|
) -> RequestBuilder& {
|
|
|
|
if (handler) {
|
2021-07-13 17:51:07 +00:00
|
|
|
[[maybe_unused]] auto &silence_warning = _builder.fail([
|
2018-06-28 16:25:50 +00:00
|
|
|
common = base::take(_commonFailHandler),
|
|
|
|
specific = std::move(handler)
|
2021-03-12 13:58:58 +00:00
|
|
|
](const MTP::Error &error) {
|
2018-06-28 16:25:50 +00:00
|
|
|
if (!specific(error)) {
|
2021-03-12 10:45:13 +00:00
|
|
|
common(error);
|
2018-06-28 16:25:50 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Request>
|
|
|
|
mtpRequestId ApiWrap::RequestBuilder<Request>::send() {
|
|
|
|
return _commonFailHandler
|
|
|
|
? _builder.fail(base::take(_commonFailHandler)).send()
|
|
|
|
: _builder.send();
|
|
|
|
}
|
|
|
|
|
2018-06-17 12:47:47 +00:00
|
|
|
ApiWrap::LoadedFileCache::LoadedFileCache(int limit) : _limit(limit) {
|
|
|
|
Expects(limit >= 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ApiWrap::LoadedFileCache::save(
|
|
|
|
const Location &location,
|
|
|
|
const QString &relativePath) {
|
2018-06-28 17:03:44 +00:00
|
|
|
if (!location) {
|
|
|
|
return;
|
|
|
|
}
|
2018-06-17 12:47:47 +00:00
|
|
|
const auto key = ComputeLocationKey(location);
|
|
|
|
_map[key] = relativePath;
|
|
|
|
_list.push_back(key);
|
|
|
|
if (_list.size() > _limit) {
|
|
|
|
const auto key = _list.front();
|
|
|
|
_list.pop_front();
|
|
|
|
_map.erase(key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-21 16:28:46 +00:00
|
|
|
std::optional<QString> ApiWrap::LoadedFileCache::find(
|
2018-06-17 12:47:47 +00:00
|
|
|
const Location &location) const {
|
2018-06-28 17:03:44 +00:00
|
|
|
if (!location) {
|
2018-09-21 16:28:46 +00:00
|
|
|
return std::nullopt;
|
2018-06-28 17:03:44 +00:00
|
|
|
}
|
2018-06-17 12:47:47 +00:00
|
|
|
const auto key = ComputeLocationKey(location);
|
|
|
|
if (const auto i = _map.find(key); i != end(_map)) {
|
|
|
|
return i->second;
|
|
|
|
}
|
2018-09-21 16:28:46 +00:00
|
|
|
return std::nullopt;
|
2018-06-17 12:47:47 +00:00
|
|
|
}
|
|
|
|
|
2018-06-20 16:10:38 +00:00
|
|
|
ApiWrap::FileProcess::FileProcess(const QString &path, Output::Stats *stats)
|
|
|
|
: file(path, stats) {
|
2018-06-11 18:35:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Request>
|
|
|
|
auto ApiWrap::mainRequest(Request &&request) {
|
2018-06-14 21:47:09 +00:00
|
|
|
Expects(_takeoutId.has_value());
|
|
|
|
|
2018-06-28 16:25:50 +00:00
|
|
|
auto original = std::move(_mtp.request(MTPInvokeWithTakeout<Request>(
|
2018-06-14 21:47:09 +00:00
|
|
|
MTP_long(*_takeoutId),
|
2018-06-21 14:01:27 +00:00
|
|
|
std::forward<Request>(request)
|
2018-06-28 16:25:50 +00:00
|
|
|
)).toDC(MTP::ShiftDcId(0, MTP::kExportDcShift)));
|
|
|
|
|
|
|
|
return RequestBuilder<MTPInvokeWithTakeout<Request>>(
|
|
|
|
std::move(original),
|
2021-03-12 12:48:00 +00:00
|
|
|
[=](const MTP::Error &result) { error(result); });
|
2018-06-11 18:35:27 +00:00
|
|
|
}
|
|
|
|
|
2018-06-21 14:01:27 +00:00
|
|
|
template <typename Request>
|
|
|
|
auto ApiWrap::splitRequest(int index, Request &&request) {
|
|
|
|
Expects(index < _splits.size());
|
|
|
|
|
|
|
|
//if (index == _splits.size() - 1) {
|
|
|
|
// return mainRequest(std::forward<Request>(request));
|
|
|
|
//}
|
|
|
|
return mainRequest(MTPInvokeWithMessagesRange<Request>(
|
|
|
|
_splits[index],
|
|
|
|
std::forward<Request>(request)));
|
|
|
|
}
|
|
|
|
|
2022-05-10 14:22:28 +00:00
|
|
|
auto ApiWrap::fileRequest(const Data::FileLocation &location, int64 offset) {
|
2018-06-24 00:33:47 +00:00
|
|
|
Expects(location.dcId != 0
|
|
|
|
|| location.data.type() == mtpc_inputTakeoutFileLocation);
|
2018-06-14 21:47:09 +00:00
|
|
|
Expects(_takeoutId.has_value());
|
2021-03-22 12:32:40 +00:00
|
|
|
Expects(_fileProcess->requestId == 0);
|
2018-06-14 21:47:09 +00:00
|
|
|
|
|
|
|
return std::move(_mtp.request(MTPInvokeWithTakeout<MTPupload_GetFile>(
|
|
|
|
MTP_long(*_takeoutId),
|
|
|
|
MTPupload_GetFile(
|
2019-08-01 09:22:49 +00:00
|
|
|
MTP_flags(0),
|
2018-06-14 21:47:09 +00:00
|
|
|
location.data,
|
2022-05-10 14:22:28 +00:00
|
|
|
MTP_long(offset),
|
2018-06-14 21:47:09 +00:00
|
|
|
MTP_int(kFileChunkSize))
|
2021-03-12 12:48:00 +00:00
|
|
|
)).fail([=](const MTP::Error &result) {
|
2021-03-22 12:32:40 +00:00
|
|
|
_fileProcess->requestId = 0;
|
2022-11-26 21:20:17 +00:00
|
|
|
if (result.type() == u"TAKEOUT_FILE_EMPTY"_q
|
2018-06-24 00:33:47 +00:00
|
|
|
&& _otherDataProcess != nullptr) {
|
2019-07-05 13:38:38 +00:00
|
|
|
filePartDone(
|
|
|
|
0,
|
|
|
|
MTP_upload_file(
|
|
|
|
MTP_storage_filePartial(),
|
|
|
|
MTP_int(0),
|
|
|
|
MTP_bytes()));
|
2022-11-26 21:20:17 +00:00
|
|
|
} else if (result.type() == u"LOCATION_INVALID"_q
|
|
|
|
|| result.type() == u"VERSION_INVALID"_q
|
|
|
|
|| result.type() == u"LOCATION_NOT_AVAILABLE"_q) {
|
2018-06-24 12:30:09 +00:00
|
|
|
filePartUnavailable();
|
2019-11-29 06:55:22 +00:00
|
|
|
} else if (result.code() == 400
|
2022-11-26 21:20:17 +00:00
|
|
|
&& result.type().startsWith(u"FILE_REFERENCE_"_q)) {
|
2019-11-29 06:55:22 +00:00
|
|
|
filePartRefreshReference(offset);
|
2018-06-24 00:33:47 +00:00
|
|
|
} else {
|
|
|
|
error(std::move(result));
|
|
|
|
}
|
2018-06-14 21:47:09 +00:00
|
|
|
}).toDC(MTP::ShiftDcId(location.dcId, MTP::kExportMediaDcShift)));
|
2018-06-11 18:35:27 +00:00
|
|
|
}
|
|
|
|
|
2020-06-11 16:09:46 +00:00
|
|
|
ApiWrap::ApiWrap(QPointer<MTP::Instance> weak, Fn<void(FnMut<void()>)> runner)
|
|
|
|
: _mtp(weak, std::move(runner))
|
2018-06-17 12:47:47 +00:00
|
|
|
, _fileCache(std::make_unique<LoadedFileCache>(kLocationCacheSize)) {
|
2018-06-11 18:35:27 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:48:00 +00:00
|
|
|
rpl::producer<MTP::Error> ApiWrap::errors() const {
|
2018-06-11 18:35:27 +00:00
|
|
|
return _errors.events();
|
|
|
|
}
|
|
|
|
|
2018-06-19 10:42:21 +00:00
|
|
|
rpl::producer<Output::Result> ApiWrap::ioErrors() const {
|
|
|
|
return _ioErrors.events();
|
|
|
|
}
|
|
|
|
|
2018-06-14 21:47:09 +00:00
|
|
|
void ApiWrap::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-13 13:12:36 +00:00
|
|
|
Expects(_settings == nullptr);
|
2018-06-18 21:52:13 +00:00
|
|
|
Expects(_startProcess == nullptr);
|
2018-06-13 13:12:36 +00:00
|
|
|
|
|
|
|
_settings = std::make_unique<Settings>(settings);
|
2018-06-20 16:10:38 +00:00
|
|
|
_stats = stats;
|
2018-06-18 21:52:13 +00:00
|
|
|
_startProcess = std::make_unique<StartProcess>();
|
|
|
|
_startProcess->done = std::move(done);
|
|
|
|
|
|
|
|
using Step = StartProcess::Step;
|
|
|
|
if (_settings->types & Settings::Type::Userpics) {
|
|
|
|
_startProcess->steps.push_back(Step::UserpicsCount);
|
2018-06-19 10:42:21 +00:00
|
|
|
}
|
2023-06-16 17:23:40 +00:00
|
|
|
if (_settings->types & Settings::Type::Stories) {
|
|
|
|
_startProcess->steps.push_back(Step::StoriesCount);
|
|
|
|
}
|
2018-06-24 01:34:47 +00:00
|
|
|
if (_settings->types & Settings::Type::AnyChatsMask) {
|
2018-06-21 14:01:27 +00:00
|
|
|
_startProcess->steps.push_back(Step::SplitRanges);
|
|
|
|
}
|
2018-06-19 10:42:21 +00:00
|
|
|
if (_settings->types & Settings::Type::AnyChatsMask) {
|
2018-06-18 21:52:13 +00:00
|
|
|
_startProcess->steps.push_back(Step::DialogsCount);
|
2018-06-19 10:42:21 +00:00
|
|
|
}
|
|
|
|
if (_settings->types & Settings::Type::GroupsChannelsMask) {
|
2018-07-23 13:11:56 +00:00
|
|
|
if (!_settings->onlySinglePeer()) {
|
|
|
|
_startProcess->steps.push_back(Step::LeftChannelsCount);
|
|
|
|
}
|
2018-06-18 21:52:13 +00:00
|
|
|
}
|
|
|
|
startMainSession([=] {
|
|
|
|
sendNextStartRequest();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void ApiWrap::sendNextStartRequest() {
|
|
|
|
Expects(_startProcess != nullptr);
|
|
|
|
|
|
|
|
auto &steps = _startProcess->steps;
|
|
|
|
if (steps.empty()) {
|
|
|
|
finishStartProcess();
|
|
|
|
return;
|
|
|
|
}
|
2018-06-21 14:01:27 +00:00
|
|
|
using Step = StartProcess::Step;
|
2018-06-18 21:52:13 +00:00
|
|
|
const auto step = steps.front();
|
|
|
|
steps.pop_front();
|
|
|
|
switch (step) {
|
2018-06-21 14:01:27 +00:00
|
|
|
case Step::UserpicsCount:
|
2018-06-18 21:52:13 +00:00
|
|
|
return requestUserpicsCount();
|
2023-06-16 17:23:40 +00:00
|
|
|
case Step::StoriesCount:
|
|
|
|
return requestStoriesCount();
|
2018-06-21 14:01:27 +00:00
|
|
|
case Step::SplitRanges:
|
|
|
|
return requestSplitRanges();
|
|
|
|
case Step::DialogsCount:
|
2018-06-18 21:52:13 +00:00
|
|
|
return requestDialogsCount();
|
2018-06-21 14:01:27 +00:00
|
|
|
case Step::LeftChannelsCount:
|
2018-06-18 21:52:13 +00:00
|
|
|
return requestLeftChannelsCount();
|
|
|
|
}
|
|
|
|
Unexpected("Step in ApiWrap::sendNextStartRequest.");
|
|
|
|
}
|
|
|
|
|
|
|
|
void ApiWrap::requestUserpicsCount() {
|
|
|
|
Expects(_startProcess != nullptr);
|
|
|
|
|
|
|
|
mainRequest(MTPphotos_GetUserPhotos(
|
|
|
|
_user,
|
|
|
|
MTP_int(0), // offset
|
|
|
|
MTP_long(0), // max_id
|
|
|
|
MTP_int(0) // limit
|
|
|
|
)).done([=](const MTPphotos_Photos &result) {
|
|
|
|
Expects(_settings != nullptr);
|
|
|
|
Expects(_startProcess != nullptr);
|
|
|
|
|
|
|
|
_startProcess->info.userpicsCount = result.match(
|
|
|
|
[](const MTPDphotos_photos &data) {
|
2019-07-05 13:38:38 +00:00
|
|
|
return int(data.vphotos().v.size());
|
2018-06-18 21:52:13 +00:00
|
|
|
}, [](const MTPDphotos_photosSlice &data) {
|
2019-07-05 13:38:38 +00:00
|
|
|
return data.vcount().v;
|
2018-06-18 21:52:13 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
sendNextStartRequest();
|
|
|
|
}).send();
|
|
|
|
}
|
|
|
|
|
2023-06-16 17:23:40 +00:00
|
|
|
void ApiWrap::requestStoriesCount() {
|
|
|
|
Expects(_startProcess != nullptr);
|
|
|
|
|
|
|
|
mainRequest(MTPstories_GetStoriesArchive(
|
2023-08-31 08:58:34 +00:00
|
|
|
MTP_inputPeerSelf(),
|
2023-06-16 17:23:40 +00:00
|
|
|
MTP_int(0), // offset_id
|
|
|
|
MTP_int(0) // limit
|
|
|
|
)).done([=](const MTPstories_Stories &result) {
|
|
|
|
Expects(_settings != nullptr);
|
|
|
|
Expects(_startProcess != nullptr);
|
|
|
|
|
|
|
|
_startProcess->info.storiesCount = result.data().vcount().v;
|
|
|
|
|
|
|
|
sendNextStartRequest();
|
|
|
|
}).send();
|
|
|
|
}
|
|
|
|
|
2018-06-21 14:01:27 +00:00
|
|
|
void ApiWrap::requestSplitRanges() {
|
|
|
|
Expects(_startProcess != nullptr);
|
|
|
|
|
|
|
|
mainRequest(MTPmessages_GetSplitRanges(
|
|
|
|
)).done([=](const MTPVector<MTPMessageRange> &result) {
|
|
|
|
_splits = result.v;
|
2018-06-24 01:34:47 +00:00
|
|
|
if (_splits.empty()) {
|
|
|
|
_splits.push_back(MTP_messageRange(
|
|
|
|
MTP_int(1),
|
|
|
|
MTP_int(std::numeric_limits<int>::max())));
|
|
|
|
}
|
|
|
|
_startProcess->splitIndex = useOnlyLastSplit()
|
|
|
|
? (_splits.size() - 1)
|
|
|
|
: 0;
|
|
|
|
|
2018-06-21 14:01:27 +00:00
|
|
|
sendNextStartRequest();
|
|
|
|
}).send();
|
|
|
|
}
|
|
|
|
|
2018-06-18 21:52:13 +00:00
|
|
|
void ApiWrap::requestDialogsCount() {
|
|
|
|
Expects(_startProcess != nullptr);
|
|
|
|
|
2018-07-23 13:11:56 +00:00
|
|
|
if (_settings->onlySinglePeer()) {
|
|
|
|
_startProcess->info.dialogsCount =
|
|
|
|
(_settings->singlePeer.type() == mtpc_inputPeerChannel
|
|
|
|
? 1
|
|
|
|
: _splits.size());
|
|
|
|
sendNextStartRequest();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-06-26 13:58:29 +00:00
|
|
|
const auto offsetDate = 0;
|
|
|
|
const auto offsetId = 0;
|
|
|
|
const auto offsetPeer = MTP_inputPeerEmpty();
|
|
|
|
const auto limit = 1;
|
2021-08-25 08:15:05 +00:00
|
|
|
const auto hash = uint64(0);
|
2018-06-21 14:01:27 +00:00
|
|
|
splitRequest(_startProcess->splitIndex, MTPmessages_GetDialogs(
|
2018-06-18 21:52:13 +00:00
|
|
|
MTP_flags(0),
|
2019-04-15 09:20:07 +00:00
|
|
|
MTPint(), // folder_id
|
2018-06-26 13:58:29 +00:00
|
|
|
MTP_int(offsetDate),
|
|
|
|
MTP_int(offsetId),
|
|
|
|
offsetPeer,
|
|
|
|
MTP_int(limit),
|
2021-08-25 08:15:05 +00:00
|
|
|
MTP_long(hash)
|
2018-06-18 21:52:13 +00:00
|
|
|
)).done([=](const MTPmessages_Dialogs &result) {
|
|
|
|
Expects(_settings != nullptr);
|
|
|
|
Expects(_startProcess != nullptr);
|
|
|
|
|
2018-06-26 13:58:29 +00:00
|
|
|
const auto count = result.match(
|
2018-06-18 21:52:13 +00:00
|
|
|
[](const MTPDmessages_dialogs &data) {
|
2019-07-05 13:38:38 +00:00
|
|
|
return int(data.vdialogs().v.size());
|
2018-06-18 21:52:13 +00:00
|
|
|
}, [](const MTPDmessages_dialogsSlice &data) {
|
2019-07-05 13:38:38 +00:00
|
|
|
return data.vcount().v;
|
2018-06-26 13:58:29 +00:00
|
|
|
}, [](const MTPDmessages_dialogsNotModified &data) {
|
|
|
|
return -1;
|
2018-06-18 21:52:13 +00:00
|
|
|
});
|
2018-06-26 13:58:29 +00:00
|
|
|
if (count < 0) {
|
|
|
|
error("Unexpected dialogsNotModified received.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_startProcess->info.dialogsCount += count;
|
2018-06-18 21:52:13 +00:00
|
|
|
|
2018-06-21 14:01:27 +00:00
|
|
|
if (++_startProcess->splitIndex >= _splits.size()) {
|
|
|
|
sendNextStartRequest();
|
|
|
|
} else {
|
|
|
|
requestDialogsCount();
|
|
|
|
}
|
2018-06-18 21:52:13 +00:00
|
|
|
}).send();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ApiWrap::requestLeftChannelsCount() {
|
|
|
|
Expects(_startProcess != nullptr);
|
|
|
|
Expects(_leftChannelsProcess == nullptr);
|
|
|
|
|
|
|
|
_leftChannelsProcess = std::make_unique<LeftChannelsProcess>();
|
|
|
|
requestLeftChannelsSliceGeneric([=] {
|
|
|
|
Expects(_startProcess != nullptr);
|
|
|
|
Expects(_leftChannelsProcess != nullptr);
|
|
|
|
|
2018-07-11 21:06:35 +00:00
|
|
|
_startProcess->info.dialogsCount
|
|
|
|
+= _leftChannelsProcess->fullCount;
|
2018-06-18 21:52:13 +00:00
|
|
|
sendNextStartRequest();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void ApiWrap::finishStartProcess() {
|
|
|
|
Expects(_startProcess != nullptr);
|
|
|
|
|
|
|
|
const auto process = base::take(_startProcess);
|
|
|
|
process->done(process->info);
|
|
|
|
}
|
|
|
|
|
2018-06-24 01:34:47 +00:00
|
|
|
bool ApiWrap::useOnlyLastSplit() const {
|
|
|
|
return !(_settings->types & Settings::Type::NonChannelChatsMask);
|
|
|
|
}
|
|
|
|
|
2018-06-18 21:52:13 +00:00
|
|
|
void ApiWrap::requestLeftChannelsList(
|
2018-06-19 10:42:21 +00:00
|
|
|
Fn<bool(int count)> progress,
|
2018-06-18 21:52:13 +00:00
|
|
|
FnMut<void(Data::DialogsInfo&&)> done) {
|
|
|
|
Expects(_leftChannelsProcess != nullptr);
|
|
|
|
|
2018-06-19 10:42:21 +00:00
|
|
|
_leftChannelsProcess->progress = std::move(progress);
|
2018-06-18 21:52:13 +00:00
|
|
|
_leftChannelsProcess->done = std::move(done);
|
|
|
|
requestLeftChannelsSlice();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ApiWrap::requestLeftChannelsSlice() {
|
|
|
|
requestLeftChannelsSliceGeneric([=] {
|
|
|
|
Expects(_leftChannelsProcess != nullptr);
|
|
|
|
|
|
|
|
if (_leftChannelsProcess->finished) {
|
|
|
|
const auto process = base::take(_leftChannelsProcess);
|
|
|
|
process->done(std::move(process->info));
|
|
|
|
} else {
|
|
|
|
requestLeftChannelsSlice();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-06-19 10:42:21 +00:00
|
|
|
void ApiWrap::requestDialogsList(
|
|
|
|
Fn<bool(int count)> progress,
|
|
|
|
FnMut<void(Data::DialogsInfo&&)> done) {
|
2018-06-18 21:52:13 +00:00
|
|
|
Expects(_dialogsProcess == nullptr);
|
|
|
|
|
|
|
|
_dialogsProcess = std::make_unique<DialogsProcess>();
|
2018-06-21 14:01:27 +00:00
|
|
|
_dialogsProcess->splitIndexPlusOne = _splits.size();
|
2018-06-19 10:42:21 +00:00
|
|
|
_dialogsProcess->progress = std::move(progress);
|
2018-06-18 21:52:13 +00:00
|
|
|
_dialogsProcess->done = std::move(done);
|
|
|
|
|
|
|
|
requestDialogsSlice();
|
|
|
|
}
|
|
|
|
|
2018-06-14 21:47:09 +00:00
|
|
|
void ApiWrap::startMainSession(FnMut<void()> done) {
|
2018-06-24 13:19:49 +00:00
|
|
|
using Type = Settings::Type;
|
2018-06-15 18:56:17 +00:00
|
|
|
const auto sizeLimit = _settings->media.sizeLimit;
|
2018-06-24 13:19:49 +00:00
|
|
|
const auto hasFiles = ((_settings->media.types != 0) && (sizeLimit > 0))
|
2023-06-16 17:23:40 +00:00
|
|
|
|| (_settings->types & Type::Userpics)
|
|
|
|
|| (_settings->types & Type::Stories);
|
2018-06-14 21:47:09 +00:00
|
|
|
|
|
|
|
using Flag = MTPaccount_InitTakeoutSession::Flag;
|
|
|
|
const auto flags = Flag(0)
|
|
|
|
| (_settings->types & Type::Contacts ? Flag::f_contacts : Flag(0))
|
|
|
|
| (hasFiles ? Flag::f_files : Flag(0))
|
2018-06-24 13:19:49 +00:00
|
|
|
| ((hasFiles && sizeLimit < kFileMaxSize)
|
|
|
|
? Flag::f_file_max_size
|
|
|
|
: Flag(0))
|
2018-06-14 21:47:09 +00:00
|
|
|
| (_settings->types & (Type::PersonalChats | Type::BotChats)
|
|
|
|
? Flag::f_message_users
|
|
|
|
: Flag(0))
|
|
|
|
| (_settings->types & Type::PrivateGroups
|
|
|
|
? (Flag::f_message_chats | Flag::f_message_megagroups)
|
|
|
|
: Flag(0))
|
|
|
|
| (_settings->types & Type::PublicGroups
|
|
|
|
? Flag::f_message_megagroups
|
|
|
|
: Flag(0))
|
|
|
|
| (_settings->types & (Type::PrivateChannels | Type::PublicChannels)
|
|
|
|
? Flag::f_message_channels
|
|
|
|
: Flag(0));
|
|
|
|
|
2020-09-01 06:44:18 +00:00
|
|
|
_mtp.request(MTPusers_GetUsers(
|
|
|
|
MTP_vector<MTPInputUser>(1, MTP_inputUserSelf())
|
2018-06-14 21:47:09 +00:00
|
|
|
)).done([=, done = std::move(done)](
|
2020-09-01 06:44:18 +00:00
|
|
|
const MTPVector<MTPUser> &result) mutable {
|
|
|
|
for (const auto &user : result.v) {
|
|
|
|
user.match([&](const MTPDuser &data) {
|
|
|
|
if (data.is_self()) {
|
2021-04-09 16:47:28 +00:00
|
|
|
_selfId.emplace(data.vid());
|
2020-09-01 06:44:18 +00:00
|
|
|
}
|
|
|
|
}, [&](const MTPDuserEmpty&) {
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if (!_selfId) {
|
|
|
|
error("Could not retrieve selfId.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_mtp.request(MTPaccount_InitTakeoutSession(
|
|
|
|
MTP_flags(flags),
|
2022-05-10 14:22:28 +00:00
|
|
|
MTP_long(sizeLimit)
|
2020-09-01 06:44:18 +00:00
|
|
|
)).done([=, done = std::move(done)](
|
|
|
|
const MTPaccount_Takeout &result) mutable {
|
|
|
|
_takeoutId = result.match([](const MTPDaccount_takeout &data) {
|
|
|
|
return data.vid().v;
|
|
|
|
});
|
|
|
|
done();
|
2021-03-12 12:48:00 +00:00
|
|
|
}).fail([=](const MTP::Error &result) {
|
2021-03-12 10:45:13 +00:00
|
|
|
error(result);
|
2020-09-01 06:44:18 +00:00
|
|
|
}).toDC(MTP::ShiftDcId(0, MTP::kExportDcShift)).send();
|
2021-03-12 12:48:00 +00:00
|
|
|
}).fail([=](const MTP::Error &result) {
|
2021-03-12 10:45:13 +00:00
|
|
|
error(result);
|
2020-09-01 06:44:18 +00:00
|
|
|
}).send();
|
2018-06-13 13:12:36 +00:00
|
|
|
}
|
|
|
|
|
2018-06-11 18:35:27 +00:00
|
|
|
void ApiWrap::requestPersonalInfo(FnMut<void(Data::PersonalInfo&&)> done) {
|
|
|
|
mainRequest(MTPusers_GetFullUser(
|
|
|
|
_user
|
2021-11-19 19:04:40 +00:00
|
|
|
)).done([=, done = std::move(done)](const MTPusers_UserFull &result) mutable {
|
|
|
|
result.match([&](const MTPDusers_userFull &data) {
|
|
|
|
if (!data.vusers().v.empty()) {
|
|
|
|
done(Data::ParsePersonalInfo(data));
|
|
|
|
} else {
|
|
|
|
error("Bad user type.");
|
|
|
|
}
|
|
|
|
});
|
2018-06-11 18:35:27 +00:00
|
|
|
}).send();
|
|
|
|
}
|
|
|
|
|
2018-06-24 00:33:47 +00:00
|
|
|
void ApiWrap::requestOtherData(
|
|
|
|
const QString &suggestedPath,
|
|
|
|
FnMut<void(Data::File&&)> done) {
|
|
|
|
Expects(_otherDataProcess == nullptr);
|
|
|
|
|
|
|
|
_otherDataProcess = std::make_unique<OtherDataProcess>();
|
|
|
|
_otherDataProcess->done = std::move(done);
|
|
|
|
_otherDataProcess->file.location.data = MTP_inputTakeoutFileLocation();
|
|
|
|
_otherDataProcess->file.suggestedPath = suggestedPath;
|
|
|
|
loadFile(
|
|
|
|
_otherDataProcess->file,
|
2019-11-29 06:55:22 +00:00
|
|
|
Data::FileOrigin(),
|
2018-06-24 00:33:47 +00:00
|
|
|
[](FileProgress progress) { return true; },
|
|
|
|
[=](const QString &result) { otherDataDone(result); });
|
|
|
|
}
|
|
|
|
|
|
|
|
void ApiWrap::otherDataDone(const QString &relativePath) {
|
|
|
|
Expects(_otherDataProcess != nullptr);
|
|
|
|
|
|
|
|
const auto process = base::take(_otherDataProcess);
|
2018-06-24 12:30:09 +00:00
|
|
|
process->file.relativePath = relativePath;
|
|
|
|
if (relativePath.isEmpty()) {
|
|
|
|
process->file.skipReason = Data::File::SkipReason::Unavailable;
|
|
|
|
}
|
2018-06-24 00:33:47 +00:00
|
|
|
process->done(std::move(process->file));
|
|
|
|
}
|
|
|
|
|
2018-06-11 18:35:27 +00:00
|
|
|
void ApiWrap::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) {
|
2018-06-13 13:12:36 +00:00
|
|
|
Expects(_userpicsProcess == nullptr);
|
|
|
|
|
2018-06-11 18:35:27 +00:00
|
|
|
_userpicsProcess = std::make_unique<UserpicsProcess>();
|
|
|
|
_userpicsProcess->start = std::move(start);
|
2018-06-19 10:42:21 +00:00
|
|
|
_userpicsProcess->fileProgress = std::move(progress);
|
2018-06-11 18:35:27 +00:00
|
|
|
_userpicsProcess->handleSlice = std::move(slice);
|
|
|
|
_userpicsProcess->finish = std::move(finish);
|
|
|
|
|
|
|
|
mainRequest(MTPphotos_GetUserPhotos(
|
|
|
|
_user,
|
2018-06-19 10:42:21 +00:00
|
|
|
MTP_int(0), // offset
|
|
|
|
MTP_long(_userpicsProcess->maxId),
|
2018-06-11 18:35:27 +00:00
|
|
|
MTP_int(kUserpicsSliceLimit)
|
|
|
|
)).done([=](const MTPphotos_Photos &result) mutable {
|
|
|
|
Expects(_userpicsProcess != nullptr);
|
|
|
|
|
2018-06-19 10:42:21 +00:00
|
|
|
auto startInfo = result.match(
|
|
|
|
[](const MTPDphotos_photos &data) {
|
2021-10-19 13:00:21 +00:00
|
|
|
return Data::UserpicsInfo{ int(data.vphotos().v.size()) };
|
2018-06-19 10:42:21 +00:00
|
|
|
}, [](const MTPDphotos_photosSlice &data) {
|
2019-07-05 13:38:38 +00:00
|
|
|
return Data::UserpicsInfo{ data.vcount().v };
|
2018-06-19 10:42:21 +00:00
|
|
|
});
|
|
|
|
if (!_userpicsProcess->start(std::move(startInfo))) {
|
|
|
|
return;
|
|
|
|
}
|
2018-06-11 18:35:27 +00:00
|
|
|
|
|
|
|
handleUserpicsSlice(result);
|
|
|
|
}).send();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ApiWrap::handleUserpicsSlice(const MTPphotos_Photos &result) {
|
|
|
|
Expects(_userpicsProcess != nullptr);
|
|
|
|
|
2018-06-13 17:10:12 +00:00
|
|
|
result.match([&](const auto &data) {
|
2018-06-12 19:30:33 +00:00
|
|
|
if constexpr (MTPDphotos_photos::Is<decltype(data)>()) {
|
|
|
|
_userpicsProcess->lastSlice = true;
|
|
|
|
}
|
2018-06-20 20:32:52 +00:00
|
|
|
loadUserpicsFiles(Data::ParseUserpicsSlice(
|
2019-07-05 13:38:38 +00:00
|
|
|
data.vphotos(),
|
2018-06-20 20:32:52 +00:00
|
|
|
_userpicsProcess->processed));
|
2018-06-12 19:30:33 +00:00
|
|
|
});
|
2018-06-11 18:35:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ApiWrap::loadUserpicsFiles(Data::UserpicsSlice &&slice) {
|
|
|
|
Expects(_userpicsProcess != nullptr);
|
|
|
|
Expects(!_userpicsProcess->slice.has_value());
|
|
|
|
|
|
|
|
if (slice.list.empty()) {
|
|
|
|
_userpicsProcess->lastSlice = true;
|
|
|
|
}
|
|
|
|
_userpicsProcess->slice = std::move(slice);
|
2018-07-07 20:58:54 +00:00
|
|
|
_userpicsProcess->fileIndex = 0;
|
2018-06-11 18:35:27 +00:00
|
|
|
loadNextUserpic();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ApiWrap::loadNextUserpic() {
|
|
|
|
Expects(_userpicsProcess != nullptr);
|
|
|
|
Expects(_userpicsProcess->slice.has_value());
|
|
|
|
|
2018-07-07 20:58:54 +00:00
|
|
|
for (auto &list = _userpicsProcess->slice->list
|
|
|
|
; _userpicsProcess->fileIndex < list.size()
|
|
|
|
; ++_userpicsProcess->fileIndex) {
|
2018-06-17 08:39:03 +00:00
|
|
|
const auto ready = processFileLoad(
|
2018-07-07 20:58:54 +00:00
|
|
|
list[_userpicsProcess->fileIndex].image.file,
|
2019-11-29 06:55:22 +00:00
|
|
|
Data::FileOrigin(),
|
2018-06-19 10:42:21 +00:00
|
|
|
[=](FileProgress value) { return loadUserpicProgress(value); },
|
2018-06-17 08:39:03 +00:00
|
|
|
[=](const QString &path) { loadUserpicDone(path); });
|
|
|
|
if (!ready) {
|
2018-06-13 17:10:12 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-06-11 18:35:27 +00:00
|
|
|
}
|
2018-06-19 10:42:21 +00:00
|
|
|
finishUserpicsSlice();
|
|
|
|
}
|
2018-06-11 18:35:27 +00:00
|
|
|
|
2018-06-19 10:42:21 +00:00
|
|
|
void ApiWrap::finishUserpicsSlice() {
|
|
|
|
Expects(_userpicsProcess != nullptr);
|
|
|
|
Expects(_userpicsProcess->slice.has_value());
|
|
|
|
|
|
|
|
auto slice = *base::take(_userpicsProcess->slice);
|
|
|
|
if (!slice.list.empty()) {
|
2018-06-20 20:32:52 +00:00
|
|
|
_userpicsProcess->processed += slice.list.size();
|
2018-06-19 10:42:21 +00:00
|
|
|
_userpicsProcess->maxId = slice.list.back().id;
|
|
|
|
if (!_userpicsProcess->handleSlice(std::move(slice))) {
|
|
|
|
return;
|
|
|
|
}
|
2018-06-17 20:15:40 +00:00
|
|
|
}
|
2018-06-11 18:35:27 +00:00
|
|
|
if (_userpicsProcess->lastSlice) {
|
|
|
|
finishUserpics();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mainRequest(MTPphotos_GetUserPhotos(
|
|
|
|
_user,
|
2018-06-19 10:42:21 +00:00
|
|
|
MTP_int(0), // offset
|
|
|
|
MTP_long(_userpicsProcess->maxId),
|
2018-06-11 18:35:27 +00:00
|
|
|
MTP_int(kUserpicsSliceLimit)
|
|
|
|
)).done([=](const MTPphotos_Photos &result) {
|
|
|
|
handleUserpicsSlice(result);
|
|
|
|
}).send();
|
|
|
|
}
|
|
|
|
|
2018-06-19 10:42:21 +00:00
|
|
|
bool ApiWrap::loadUserpicProgress(FileProgress progress) {
|
2018-06-19 18:31:30 +00:00
|
|
|
Expects(_fileProcess != nullptr);
|
2018-06-19 10:42:21 +00:00
|
|
|
Expects(_userpicsProcess != nullptr);
|
|
|
|
Expects(_userpicsProcess->slice.has_value());
|
|
|
|
Expects((_userpicsProcess->fileIndex >= 0)
|
|
|
|
&& (_userpicsProcess->fileIndex
|
|
|
|
< _userpicsProcess->slice->list.size()));
|
|
|
|
|
|
|
|
return _userpicsProcess->fileProgress(DownloadProgress{
|
2021-03-22 12:32:40 +00:00
|
|
|
_fileProcess->randomId,
|
2018-06-19 18:31:30 +00:00
|
|
|
_fileProcess->relativePath,
|
2018-06-19 10:42:21 +00:00
|
|
|
_userpicsProcess->fileIndex,
|
|
|
|
progress.ready,
|
|
|
|
progress.total });
|
|
|
|
}
|
|
|
|
|
2018-06-11 18:35:27 +00:00
|
|
|
void ApiWrap::loadUserpicDone(const QString &relativePath) {
|
|
|
|
Expects(_userpicsProcess != nullptr);
|
|
|
|
Expects(_userpicsProcess->slice.has_value());
|
2018-06-13 13:12:36 +00:00
|
|
|
Expects((_userpicsProcess->fileIndex >= 0)
|
|
|
|
&& (_userpicsProcess->fileIndex
|
2018-06-11 18:35:27 +00:00
|
|
|
< _userpicsProcess->slice->list.size()));
|
|
|
|
|
2018-06-13 13:12:36 +00:00
|
|
|
const auto index = _userpicsProcess->fileIndex;
|
2018-06-13 17:10:12 +00:00
|
|
|
auto &file = _userpicsProcess->slice->list[index].image.file;
|
|
|
|
file.relativePath = relativePath;
|
2018-06-24 12:30:09 +00:00
|
|
|
if (relativePath.isEmpty()) {
|
|
|
|
file.skipReason = Data::File::SkipReason::Unavailable;
|
|
|
|
}
|
2018-06-11 18:35:27 +00:00
|
|
|
loadNextUserpic();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ApiWrap::finishUserpics() {
|
|
|
|
Expects(_userpicsProcess != nullptr);
|
|
|
|
|
|
|
|
base::take(_userpicsProcess)->finish();
|
|
|
|
}
|
|
|
|
|
2023-06-16 17:23:40 +00:00
|
|
|
void ApiWrap::requestStories(
|
|
|
|
FnMut<bool(Data::StoriesInfo&&)> start,
|
|
|
|
Fn<bool(DownloadProgress)> progress,
|
|
|
|
Fn<bool(Data::StoriesSlice&&)> slice,
|
|
|
|
FnMut<void()> finish) {
|
|
|
|
Expects(_storiesProcess == nullptr);
|
|
|
|
|
|
|
|
_storiesProcess = std::make_unique<StoriesProcess>();
|
|
|
|
_storiesProcess->start = std::move(start);
|
|
|
|
_storiesProcess->fileProgress = std::move(progress);
|
|
|
|
_storiesProcess->handleSlice = std::move(slice);
|
|
|
|
_storiesProcess->finish = std::move(finish);
|
|
|
|
|
|
|
|
mainRequest(MTPstories_GetStoriesArchive(
|
2023-08-31 08:58:34 +00:00
|
|
|
MTP_inputPeerSelf(),
|
2023-06-16 17:23:40 +00:00
|
|
|
MTP_int(_storiesProcess->offsetId),
|
|
|
|
MTP_int(kStoriesSliceLimit)
|
|
|
|
)).done([=](const MTPstories_Stories &result) mutable {
|
|
|
|
Expects(_storiesProcess != nullptr);
|
|
|
|
|
|
|
|
auto startInfo = Data::StoriesInfo{ result.data().vcount().v };
|
|
|
|
if (!_storiesProcess->start(std::move(startInfo))) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
handleStoriesSlice(result);
|
|
|
|
}).send();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ApiWrap::handleStoriesSlice(const MTPstories_Stories &result) {
|
|
|
|
Expects(_storiesProcess != nullptr);
|
|
|
|
|
|
|
|
loadStoriesFiles(Data::ParseStoriesSlice(
|
|
|
|
result.data().vstories(),
|
|
|
|
_storiesProcess->processed));
|
|
|
|
}
|
|
|
|
|
|
|
|
void ApiWrap::loadStoriesFiles(Data::StoriesSlice &&slice) {
|
|
|
|
Expects(_storiesProcess != nullptr);
|
|
|
|
Expects(!_storiesProcess->slice.has_value());
|
|
|
|
|
|
|
|
if (!slice.lastId) {
|
|
|
|
_storiesProcess->lastSlice = true;
|
|
|
|
}
|
|
|
|
_storiesProcess->slice = std::move(slice);
|
|
|
|
_storiesProcess->fileIndex = 0;
|
|
|
|
loadNextStory();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ApiWrap::loadNextStory() {
|
|
|
|
Expects(_storiesProcess != nullptr);
|
|
|
|
Expects(_storiesProcess->slice.has_value());
|
|
|
|
|
|
|
|
for (auto &list = _storiesProcess->slice->list
|
|
|
|
; _storiesProcess->fileIndex < list.size()
|
|
|
|
; ++_storiesProcess->fileIndex) {
|
|
|
|
auto &story = list[_storiesProcess->fileIndex];
|
|
|
|
const auto origin = Data::FileOrigin{ .storyId = story.id };
|
|
|
|
const auto ready = processFileLoad(
|
|
|
|
story.file(),
|
|
|
|
origin,
|
|
|
|
[=](FileProgress value) { return loadStoryProgress(value); },
|
|
|
|
[=](const QString &path) { loadStoryDone(path); });
|
|
|
|
if (!ready) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto thumbProgress = [=](FileProgress value) {
|
|
|
|
return loadStoryThumbProgress(value);
|
|
|
|
};
|
|
|
|
const auto thumbReady = processFileLoad(
|
|
|
|
story.thumb().file,
|
|
|
|
origin,
|
|
|
|
thumbProgress,
|
|
|
|
[=](const QString &path) { loadStoryThumbDone(path); },
|
|
|
|
nullptr,
|
|
|
|
&story);
|
|
|
|
if (!thumbReady) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
finishStoriesSlice();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ApiWrap::finishStoriesSlice() {
|
|
|
|
Expects(_storiesProcess != nullptr);
|
|
|
|
Expects(_storiesProcess->slice.has_value());
|
|
|
|
|
|
|
|
auto slice = *base::take(_storiesProcess->slice);
|
|
|
|
if (slice.lastId) {
|
|
|
|
_storiesProcess->processed += slice.list.size();
|
|
|
|
_storiesProcess->offsetId = slice.lastId;
|
|
|
|
if (!_storiesProcess->handleSlice(std::move(slice))) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (_storiesProcess->lastSlice) {
|
|
|
|
finishStories();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mainRequest(MTPstories_GetStoriesArchive(
|
2023-08-31 08:58:34 +00:00
|
|
|
MTP_inputPeerSelf(),
|
2023-06-16 17:23:40 +00:00
|
|
|
MTP_int(_storiesProcess->offsetId),
|
|
|
|
MTP_int(kStoriesSliceLimit)
|
|
|
|
)).done([=](const MTPstories_Stories &result) {
|
|
|
|
handleStoriesSlice(result);
|
|
|
|
}).send();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ApiWrap::loadStoryProgress(FileProgress progress) {
|
|
|
|
Expects(_fileProcess != nullptr);
|
|
|
|
Expects(_storiesProcess != nullptr);
|
|
|
|
Expects(_storiesProcess->slice.has_value());
|
|
|
|
Expects((_storiesProcess->fileIndex >= 0)
|
|
|
|
&& (_storiesProcess->fileIndex
|
|
|
|
< _storiesProcess->slice->list.size()));
|
|
|
|
|
|
|
|
return _storiesProcess->fileProgress(DownloadProgress{
|
|
|
|
_fileProcess->randomId,
|
|
|
|
_fileProcess->relativePath,
|
|
|
|
_storiesProcess->fileIndex,
|
|
|
|
progress.ready,
|
|
|
|
progress.total });
|
|
|
|
}
|
|
|
|
|
|
|
|
void ApiWrap::loadStoryDone(const QString &relativePath) {
|
|
|
|
Expects(_storiesProcess != nullptr);
|
|
|
|
Expects(_storiesProcess->slice.has_value());
|
|
|
|
Expects((_storiesProcess->fileIndex >= 0)
|
|
|
|
&& (_storiesProcess->fileIndex
|
|
|
|
< _storiesProcess->slice->list.size()));
|
|
|
|
|
|
|
|
const auto index = _storiesProcess->fileIndex;
|
|
|
|
auto &file = _storiesProcess->slice->list[index].file();
|
|
|
|
file.relativePath = relativePath;
|
|
|
|
if (relativePath.isEmpty()) {
|
|
|
|
file.skipReason = Data::File::SkipReason::Unavailable;
|
|
|
|
}
|
|
|
|
loadNextStory();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ApiWrap::loadStoryThumbProgress(FileProgress progress) {
|
|
|
|
return loadStoryProgress(progress);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ApiWrap::loadStoryThumbDone(const QString &relativePath) {
|
|
|
|
Expects(_storiesProcess != nullptr);
|
|
|
|
Expects(_storiesProcess->slice.has_value());
|
|
|
|
Expects((_storiesProcess->fileIndex >= 0)
|
|
|
|
&& (_storiesProcess->fileIndex
|
|
|
|
< _storiesProcess->slice->list.size()));
|
|
|
|
|
|
|
|
const auto index = _storiesProcess->fileIndex;
|
|
|
|
auto &file = _storiesProcess->slice->list[index].thumb().file;
|
|
|
|
file.relativePath = relativePath;
|
|
|
|
if (relativePath.isEmpty()) {
|
|
|
|
file.skipReason = Data::File::SkipReason::Unavailable;
|
|
|
|
}
|
|
|
|
loadNextStory();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ApiWrap::finishStories() {
|
|
|
|
Expects(_storiesProcess != nullptr);
|
|
|
|
|
|
|
|
base::take(_storiesProcess)->finish();
|
|
|
|
}
|
|
|
|
|
2018-06-11 18:35:27 +00:00
|
|
|
void ApiWrap::requestContacts(FnMut<void(Data::ContactsList&&)> done) {
|
2018-06-19 20:40:16 +00:00
|
|
|
Expects(_contactsProcess == nullptr);
|
|
|
|
|
|
|
|
_contactsProcess = std::make_unique<ContactsProcess>();
|
|
|
|
_contactsProcess->done = std::move(done);
|
2018-06-14 21:47:09 +00:00
|
|
|
mainRequest(MTPcontacts_GetSaved(
|
2018-06-19 20:40:16 +00:00
|
|
|
)).done([=](const MTPVector<MTPSavedContact> &result) {
|
|
|
|
_contactsProcess->result = Data::ParseContactsList(result);
|
|
|
|
requestTopPeersSlice();
|
|
|
|
}).send();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ApiWrap::requestTopPeersSlice() {
|
|
|
|
Expects(_contactsProcess != nullptr);
|
|
|
|
|
|
|
|
using Flag = MTPcontacts_GetTopPeers::Flag;
|
|
|
|
mainRequest(MTPcontacts_GetTopPeers(
|
2018-06-20 20:39:04 +00:00
|
|
|
MTP_flags(Flag::f_correspondents
|
|
|
|
| Flag::f_bots_inline
|
|
|
|
| Flag::f_phone_calls),
|
2018-06-19 20:40:16 +00:00
|
|
|
MTP_int(_contactsProcess->topPeersOffset),
|
|
|
|
MTP_int(kTopPeerSliceLimit),
|
2021-08-25 08:15:05 +00:00
|
|
|
MTP_long(0) // hash
|
2018-06-19 20:40:16 +00:00
|
|
|
)).done([=](const MTPcontacts_TopPeers &result) {
|
|
|
|
Expects(_contactsProcess != nullptr);
|
|
|
|
|
|
|
|
if (!Data::AppendTopPeers(_contactsProcess->result, result)) {
|
|
|
|
error("Unexpected data in ApiWrap::requestTopPeersSlice.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto offset = _contactsProcess->topPeersOffset;
|
|
|
|
const auto loaded = result.match(
|
|
|
|
[](const MTPDcontacts_topPeersNotModified &data) {
|
|
|
|
return true;
|
2018-06-26 13:58:29 +00:00
|
|
|
}, [](const MTPDcontacts_topPeersDisabled &data) {
|
|
|
|
return true;
|
2018-06-19 20:40:16 +00:00
|
|
|
}, [&](const MTPDcontacts_topPeers &data) {
|
2019-07-05 13:38:38 +00:00
|
|
|
for (const auto &category : data.vcategories().v) {
|
2018-06-19 20:40:16 +00:00
|
|
|
const auto loaded = category.match(
|
|
|
|
[&](const MTPDtopPeerCategoryPeers &data) {
|
2019-07-05 13:38:38 +00:00
|
|
|
return offset + data.vpeers().v.size() >= data.vcount().v;
|
2018-06-19 20:40:16 +00:00
|
|
|
});
|
|
|
|
if (!loaded) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (loaded) {
|
|
|
|
auto process = base::take(_contactsProcess);
|
|
|
|
process->done(std::move(process->result));
|
|
|
|
} else {
|
2018-06-20 20:39:04 +00:00
|
|
|
_contactsProcess->topPeersOffset = std::max(std::max(
|
2018-06-19 20:40:16 +00:00
|
|
|
_contactsProcess->result.correspondents.size(),
|
2018-06-20 20:39:04 +00:00
|
|
|
_contactsProcess->result.inlineBots.size()),
|
|
|
|
_contactsProcess->result.phoneCalls.size());
|
2018-06-19 20:40:16 +00:00
|
|
|
requestTopPeersSlice();
|
|
|
|
}
|
2018-06-11 18:35:27 +00:00
|
|
|
}).send();
|
|
|
|
}
|
|
|
|
|
2018-06-11 18:57:56 +00:00
|
|
|
void ApiWrap::requestSessions(FnMut<void(Data::SessionsList&&)> done) {
|
|
|
|
mainRequest(MTPaccount_GetAuthorizations(
|
|
|
|
)).done([=, done = std::move(done)](
|
|
|
|
const MTPaccount_Authorizations &result) mutable {
|
2018-06-21 21:15:27 +00:00
|
|
|
auto list = Data::ParseSessionsList(result);
|
|
|
|
mainRequest(MTPaccount_GetWebAuthorizations(
|
|
|
|
)).done([=, done = std::move(done), list = std::move(list)](
|
|
|
|
const MTPaccount_WebAuthorizations &result) mutable {
|
|
|
|
list.webList = Data::ParseWebSessionsList(result).webList;
|
|
|
|
done(std::move(list));
|
|
|
|
}).send();
|
2018-06-11 18:57:56 +00:00
|
|
|
}).send();
|
|
|
|
}
|
|
|
|
|
2018-06-18 21:52:13 +00:00
|
|
|
void ApiWrap::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) {
|
|
|
|
Expects(_chatProcess == nullptr);
|
2020-09-01 06:44:18 +00:00
|
|
|
Expects(_selfId.has_value());
|
2018-06-12 18:09:21 +00:00
|
|
|
|
2018-06-18 21:52:13 +00:00
|
|
|
_chatProcess = std::make_unique<ChatProcess>();
|
2021-04-09 16:47:28 +00:00
|
|
|
_chatProcess->context.selfPeerId = peerFromUser(*_selfId);
|
2018-06-18 21:52:13 +00:00
|
|
|
_chatProcess->info = info;
|
2018-06-19 10:42:21 +00:00
|
|
|
_chatProcess->start = std::move(start);
|
|
|
|
_chatProcess->fileProgress = std::move(progress);
|
2018-06-18 21:52:13 +00:00
|
|
|
_chatProcess->handleSlice = std::move(slice);
|
|
|
|
_chatProcess->done = std::move(done);
|
2018-06-13 13:12:36 +00:00
|
|
|
|
2018-06-21 14:01:27 +00:00
|
|
|
requestMessagesCount(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ApiWrap::requestMessagesCount(int localSplitIndex) {
|
|
|
|
Expects(_chatProcess != nullptr);
|
|
|
|
Expects(localSplitIndex < _chatProcess->info.splits.size());
|
|
|
|
|
|
|
|
requestChatMessages(
|
|
|
|
_chatProcess->info.splits[localSplitIndex],
|
|
|
|
0, // offset_id
|
|
|
|
0, // add_offset
|
|
|
|
1, // limit
|
|
|
|
[=](const MTPmessages_Messages &result) {
|
2018-06-19 10:42:21 +00:00
|
|
|
Expects(_chatProcess != nullptr);
|
|
|
|
|
2018-06-21 14:01:27 +00:00
|
|
|
const auto count = result.match(
|
2018-10-06 12:17:29 +00:00
|
|
|
[](const MTPDmessages_messages &data) {
|
2021-10-19 13:00:21 +00:00
|
|
|
return int(data.vmessages().v.size());
|
2018-06-21 14:01:27 +00:00
|
|
|
}, [](const MTPDmessages_messagesSlice &data) {
|
2019-07-05 13:38:38 +00:00
|
|
|
return data.vcount().v;
|
2018-06-21 14:01:27 +00:00
|
|
|
}, [](const MTPDmessages_channelMessages &data) {
|
2019-07-05 13:38:38 +00:00
|
|
|
return data.vcount().v;
|
2018-06-21 14:01:27 +00:00
|
|
|
}, [](const MTPDmessages_messagesNotModified &data) {
|
|
|
|
return -1;
|
|
|
|
});
|
|
|
|
if (count < 0) {
|
|
|
|
error("Unexpected messagesNotModified received.");
|
|
|
|
return;
|
|
|
|
}
|
2018-10-06 12:17:29 +00:00
|
|
|
const auto skipSplit = !Data::SingleMessageAfter(
|
|
|
|
result,
|
|
|
|
_settings->singlePeerFrom);
|
|
|
|
if (skipSplit) {
|
|
|
|
// No messages from the requested range, skip this split.
|
|
|
|
messagesCountLoaded(localSplitIndex, 0);
|
|
|
|
return;
|
2018-06-21 14:01:27 +00:00
|
|
|
}
|
2018-10-06 12:17:29 +00:00
|
|
|
checkFirstMessageDate(localSplitIndex, count);
|
2018-06-19 10:42:21 +00:00
|
|
|
});
|
2018-06-12 18:09:21 +00:00
|
|
|
}
|
|
|
|
|
2018-10-06 12:17:29 +00:00
|
|
|
void ApiWrap::checkFirstMessageDate(int localSplitIndex, int count) {
|
|
|
|
Expects(_chatProcess != nullptr);
|
|
|
|
Expects(localSplitIndex < _chatProcess->info.splits.size());
|
|
|
|
|
|
|
|
if (_settings->singlePeerTill <= 0) {
|
|
|
|
messagesCountLoaded(localSplitIndex, count);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Request first message in this split to check if its' date < till.
|
|
|
|
requestChatMessages(
|
|
|
|
_chatProcess->info.splits[localSplitIndex],
|
|
|
|
1, // offset_id
|
|
|
|
-1, // add_offset
|
|
|
|
1, // limit
|
|
|
|
[=](const MTPmessages_Messages &result) {
|
|
|
|
Expects(_chatProcess != nullptr);
|
|
|
|
|
|
|
|
const auto skipSplit = !Data::SingleMessageBefore(
|
|
|
|
result,
|
|
|
|
_settings->singlePeerTill);
|
|
|
|
messagesCountLoaded(localSplitIndex, skipSplit ? 0 : count);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void ApiWrap::messagesCountLoaded(int localSplitIndex, int count) {
|
|
|
|
Expects(_chatProcess != nullptr);
|
|
|
|
Expects(localSplitIndex < _chatProcess->info.splits.size());
|
|
|
|
|
|
|
|
_chatProcess->info.messagesCountPerSplit[localSplitIndex] = count;
|
|
|
|
if (localSplitIndex + 1 < _chatProcess->info.splits.size()) {
|
|
|
|
requestMessagesCount(localSplitIndex + 1);
|
|
|
|
} else if (_chatProcess->start(_chatProcess->info)) {
|
|
|
|
requestMessagesSlice();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-21 00:54:59 +00:00
|
|
|
void ApiWrap::finishExport(FnMut<void()> done) {
|
2018-09-21 16:28:46 +00:00
|
|
|
const auto guard = gsl::finally([&] { _takeoutId = std::nullopt; });
|
2018-06-21 00:54:59 +00:00
|
|
|
|
|
|
|
mainRequest(MTPaccount_FinishTakeoutSession(
|
|
|
|
MTP_flags(MTPaccount_FinishTakeoutSession::Flag::f_success)
|
|
|
|
)).done(std::move(done)).send();
|
|
|
|
}
|
|
|
|
|
2021-03-22 12:32:40 +00:00
|
|
|
void ApiWrap::skipFile(uint64 randomId) {
|
|
|
|
if (!_fileProcess || _fileProcess->randomId != randomId) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
LOG(("Export Info: File skipped."));
|
|
|
|
Assert(!_fileProcess->requests.empty());
|
|
|
|
Assert(_fileProcess->requestId != 0);
|
|
|
|
_mtp.request(base::take(_fileProcess->requestId)).cancel();
|
|
|
|
base::take(_fileProcess)->done(QString());
|
|
|
|
}
|
|
|
|
|
2018-06-21 00:54:59 +00:00
|
|
|
void ApiWrap::cancelExportFast() {
|
|
|
|
if (_takeoutId.has_value()) {
|
|
|
|
const auto requestId = mainRequest(MTPaccount_FinishTakeoutSession(
|
|
|
|
MTP_flags(0)
|
|
|
|
)).send();
|
|
|
|
_mtp.request(requestId).detach();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-23 13:11:56 +00:00
|
|
|
void ApiWrap::requestSinglePeerDialog() {
|
|
|
|
auto doneSinglePeer = [=](const auto &result) {
|
2019-04-09 14:55:21 +00:00
|
|
|
appendSinglePeerDialogs(
|
|
|
|
Data::ParseDialogsInfo(_settings->singlePeer, result));
|
2018-07-23 13:11:56 +00:00
|
|
|
};
|
|
|
|
const auto requestUser = [&](const MTPInputUser &data) {
|
|
|
|
mainRequest(MTPusers_GetUsers(
|
|
|
|
MTP_vector<MTPInputUser>(1, data)
|
|
|
|
)).done(std::move(doneSinglePeer)).send();
|
|
|
|
};
|
|
|
|
_settings->singlePeer.match([&](const MTPDinputPeerUser &data) {
|
2019-07-05 13:38:38 +00:00
|
|
|
requestUser(MTP_inputUser(data.vuser_id(), data.vaccess_hash()));
|
2018-07-23 13:11:56 +00:00
|
|
|
}, [&](const MTPDinputPeerChat &data) {
|
|
|
|
mainRequest(MTPmessages_GetChats(
|
2021-08-25 08:15:05 +00:00
|
|
|
MTP_vector<MTPlong>(1, data.vchat_id())
|
2018-07-23 13:11:56 +00:00
|
|
|
)).done(std::move(doneSinglePeer)).send();
|
|
|
|
}, [&](const MTPDinputPeerChannel &data) {
|
|
|
|
mainRequest(MTPchannels_GetChannels(
|
|
|
|
MTP_vector<MTPInputChannel>(
|
|
|
|
1,
|
2019-07-05 13:38:38 +00:00
|
|
|
MTP_inputChannel(data.vchannel_id(), data.vaccess_hash()))
|
2018-07-23 13:11:56 +00:00
|
|
|
)).done(std::move(doneSinglePeer)).send();
|
|
|
|
}, [&](const MTPDinputPeerSelf &data) {
|
|
|
|
requestUser(MTP_inputUserSelf());
|
2019-05-20 14:57:25 +00:00
|
|
|
}, [&](const MTPDinputPeerUserFromMessage &data) {
|
|
|
|
Unexpected("From message peer in ApiWrap::requestSinglePeerDialog.");
|
|
|
|
}, [&](const MTPDinputPeerChannelFromMessage &data) {
|
|
|
|
Unexpected("From message peer in ApiWrap::requestSinglePeerDialog.");
|
2018-07-23 13:11:56 +00:00
|
|
|
}, [](const MTPDinputPeerEmpty &data) {
|
|
|
|
Unexpected("Empty peer in ApiWrap::requestSinglePeerDialog.");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-04-09 14:55:21 +00:00
|
|
|
mtpRequestId ApiWrap::requestSinglePeerMigrated(
|
|
|
|
const Data::DialogInfo &info) {
|
|
|
|
const auto input = info.input.match([&](
|
|
|
|
const MTPDinputPeerChannel & data) {
|
|
|
|
return MTP_inputChannel(
|
|
|
|
data.vchannel_id(),
|
|
|
|
data.vaccess_hash());
|
|
|
|
}, [](auto&&) -> MTPinputChannel {
|
|
|
|
Unexpected("Peer type in a supergroup.");
|
|
|
|
});
|
|
|
|
return mainRequest(MTPchannels_GetFullChannel(
|
|
|
|
input
|
|
|
|
)).done([=](const MTPmessages_ChatFull &result) {
|
|
|
|
auto info = result.match([&](
|
|
|
|
const MTPDmessages_chatFull &data) {
|
|
|
|
const auto migratedChatId = data.vfull_chat().match([&](
|
|
|
|
const MTPDchannelFull &data) {
|
|
|
|
return data.vmigrated_from_chat_id().value_or_empty();
|
2021-08-25 08:15:05 +00:00
|
|
|
}, [](auto &&other) -> BareId {
|
2019-04-09 14:55:21 +00:00
|
|
|
return 0;
|
|
|
|
});
|
|
|
|
return migratedChatId
|
|
|
|
? Data::ParseDialogsInfo(
|
2021-08-25 08:15:05 +00:00
|
|
|
MTP_inputPeerChat(MTP_long(migratedChatId)),
|
2019-04-09 14:55:21 +00:00
|
|
|
MTP_messages_chats(data.vchats()))
|
|
|
|
: Data::DialogsInfo();
|
|
|
|
});
|
|
|
|
appendSinglePeerDialogs(std::move(info));
|
|
|
|
}).send();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ApiWrap::appendSinglePeerDialogs(Data::DialogsInfo &&info) {
|
|
|
|
const auto isSupergroupType = [](Data::DialogInfo::Type type) {
|
|
|
|
using Type = Data::DialogInfo::Type;
|
|
|
|
return (type == Type::PrivateSupergroup)
|
|
|
|
|| (type == Type::PublicSupergroup);
|
|
|
|
};
|
|
|
|
const auto isChannelType = [](Data::DialogInfo::Type type) {
|
|
|
|
using Type = Data::DialogInfo::Type;
|
|
|
|
return (type == Type::PrivateChannel)
|
|
|
|
|| (type == Type::PublicChannel);
|
|
|
|
};
|
|
|
|
|
|
|
|
auto migratedRequestId = mtpRequestId(0);
|
|
|
|
const auto last = _dialogsProcess->splitIndexPlusOne - 1;
|
|
|
|
for (auto &info : info.chats) {
|
|
|
|
if (isSupergroupType(info.type) && !migratedRequestId) {
|
|
|
|
migratedRequestId = requestSinglePeerMigrated(info);
|
|
|
|
continue;
|
|
|
|
} else if (isChannelType(info.type)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
for (auto i = last; i != 0; --i) {
|
|
|
|
info.splits.push_back(i - 1);
|
|
|
|
info.messagesCountPerSplit.push_back(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!migratedRequestId) {
|
|
|
|
_dialogsProcess->processedCount += info.chats.size();
|
|
|
|
}
|
|
|
|
appendDialogsSlice(std::move(info));
|
|
|
|
|
|
|
|
if (migratedRequestId
|
|
|
|
|| !_dialogsProcess->progress(_dialogsProcess->processedCount)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
finishDialogsList();
|
|
|
|
}
|
|
|
|
|
2018-06-12 18:09:21 +00:00
|
|
|
void ApiWrap::requestDialogsSlice() {
|
|
|
|
Expects(_dialogsProcess != nullptr);
|
|
|
|
|
2018-07-23 13:11:56 +00:00
|
|
|
if (_settings->onlySinglePeer()) {
|
|
|
|
requestSinglePeerDialog();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-06-21 14:01:27 +00:00
|
|
|
const auto splitIndex = _dialogsProcess->splitIndexPlusOne - 1;
|
2021-08-25 08:15:05 +00:00
|
|
|
const auto hash = uint64(0);
|
2018-06-21 14:01:27 +00:00
|
|
|
splitRequest(splitIndex, MTPmessages_GetDialogs(
|
2018-06-12 18:09:21 +00:00
|
|
|
MTP_flags(0),
|
2019-04-15 09:20:07 +00:00
|
|
|
MTPint(), // folder_id
|
2018-06-12 18:09:21 +00:00
|
|
|
MTP_int(_dialogsProcess->offsetDate),
|
|
|
|
MTP_int(_dialogsProcess->offsetId),
|
|
|
|
_dialogsProcess->offsetPeer,
|
2018-06-26 13:58:29 +00:00
|
|
|
MTP_int(kChatsSliceLimit),
|
2021-08-25 08:15:05 +00:00
|
|
|
MTP_long(hash)
|
2018-06-18 21:52:13 +00:00
|
|
|
)).done([=](const MTPmessages_Dialogs &result) {
|
2018-06-26 13:58:29 +00:00
|
|
|
if (result.type() == mtpc_messages_dialogsNotModified) {
|
|
|
|
error("Unexpected dialogsNotModified received.");
|
|
|
|
return;
|
|
|
|
}
|
2018-06-21 14:01:27 +00:00
|
|
|
auto finished = result.match(
|
2018-06-17 20:15:40 +00:00
|
|
|
[](const MTPDmessages_dialogs &data) {
|
|
|
|
return true;
|
|
|
|
}, [](const MTPDmessages_dialogsSlice &data) {
|
2019-07-05 13:38:38 +00:00
|
|
|
return data.vdialogs().v.isEmpty();
|
2018-06-26 13:58:29 +00:00
|
|
|
}, [](const MTPDmessages_dialogsNotModified &data) {
|
|
|
|
return true;
|
2018-06-17 20:15:40 +00:00
|
|
|
});
|
|
|
|
|
2018-06-13 13:12:36 +00:00
|
|
|
auto info = Data::ParseDialogsInfo(result);
|
2018-07-11 21:06:35 +00:00
|
|
|
_dialogsProcess->processedCount += info.chats.size();
|
|
|
|
const auto last = info.chats.empty()
|
2018-06-21 14:01:27 +00:00
|
|
|
? Data::DialogInfo()
|
2018-07-11 21:06:35 +00:00
|
|
|
: info.chats.back();
|
2018-06-21 14:01:27 +00:00
|
|
|
appendDialogsSlice(std::move(info));
|
|
|
|
|
|
|
|
if (!_dialogsProcess->progress(_dialogsProcess->processedCount)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!finished && last.topMessageDate > 0) {
|
2018-06-12 18:09:21 +00:00
|
|
|
_dialogsProcess->offsetId = last.topMessageId;
|
|
|
|
_dialogsProcess->offsetDate = last.topMessageDate;
|
|
|
|
_dialogsProcess->offsetPeer = last.input;
|
2018-06-24 01:34:47 +00:00
|
|
|
} else if (!useOnlyLastSplit()
|
|
|
|
&& --_dialogsProcess->splitIndexPlusOne > 0) {
|
2018-06-21 14:01:27 +00:00
|
|
|
_dialogsProcess->offsetId = 0;
|
|
|
|
_dialogsProcess->offsetDate = 0;
|
|
|
|
_dialogsProcess->offsetPeer = MTP_inputPeerEmpty();
|
|
|
|
} else {
|
2018-07-11 21:06:35 +00:00
|
|
|
requestLeftChannelsIfNeeded();
|
2018-06-21 14:01:27 +00:00
|
|
|
return;
|
2018-06-12 18:09:21 +00:00
|
|
|
}
|
2018-06-21 14:01:27 +00:00
|
|
|
requestDialogsSlice();
|
2018-06-12 18:09:21 +00:00
|
|
|
}).send();
|
|
|
|
}
|
|
|
|
|
2018-06-13 13:12:36 +00:00
|
|
|
void ApiWrap::appendDialogsSlice(Data::DialogsInfo &&info) {
|
|
|
|
Expects(_dialogsProcess != nullptr);
|
2018-06-21 14:01:27 +00:00
|
|
|
Expects(_dialogsProcess->splitIndexPlusOne <= _splits.size());
|
2018-06-13 13:12:36 +00:00
|
|
|
|
2018-06-21 14:01:27 +00:00
|
|
|
appendChatsSlice(
|
|
|
|
*_dialogsProcess,
|
2018-07-11 21:06:35 +00:00
|
|
|
_dialogsProcess->info.chats,
|
|
|
|
std::move(info.chats),
|
2018-06-21 14:01:27 +00:00
|
|
|
_dialogsProcess->splitIndexPlusOne - 1);
|
2018-06-13 13:12:36 +00:00
|
|
|
}
|
|
|
|
|
2018-07-11 21:06:35 +00:00
|
|
|
void ApiWrap::requestLeftChannelsIfNeeded() {
|
|
|
|
if (_settings->types & Settings::Type::GroupsChannelsMask) {
|
|
|
|
requestLeftChannelsList([=](int count) {
|
|
|
|
Expects(_dialogsProcess != nullptr);
|
|
|
|
|
|
|
|
return _dialogsProcess->progress(
|
|
|
|
_dialogsProcess->processedCount + count);
|
|
|
|
}, [=](Data::DialogsInfo &&result) {
|
|
|
|
Expects(_dialogsProcess != nullptr);
|
|
|
|
|
|
|
|
_dialogsProcess->info.left = std::move(result.left);
|
|
|
|
finishDialogsList();
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
finishDialogsList();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-18 21:52:13 +00:00
|
|
|
void ApiWrap::finishDialogsList() {
|
2018-06-13 13:12:36 +00:00
|
|
|
Expects(_dialogsProcess != nullptr);
|
|
|
|
|
2018-06-18 21:52:13 +00:00
|
|
|
const auto process = base::take(_dialogsProcess);
|
|
|
|
Data::FinalizeDialogsInfo(process->info, *_settings);
|
|
|
|
process->done(std::move(process->info));
|
|
|
|
}
|
|
|
|
|
|
|
|
void ApiWrap::requestLeftChannelsSliceGeneric(FnMut<void()> done) {
|
|
|
|
Expects(_leftChannelsProcess != nullptr);
|
|
|
|
|
2018-06-17 20:15:40 +00:00
|
|
|
mainRequest(MTPchannels_GetLeftChannels(
|
2018-06-19 10:42:21 +00:00
|
|
|
MTP_int(_leftChannelsProcess->offset)
|
2018-06-18 21:52:13 +00:00
|
|
|
)).done([=, done = std::move(done)](
|
|
|
|
const MTPmessages_Chats &result) mutable {
|
|
|
|
Expects(_leftChannelsProcess != nullptr);
|
2018-06-13 17:10:12 +00:00
|
|
|
|
2018-06-18 21:52:13 +00:00
|
|
|
appendLeftChannelsSlice(Data::ParseLeftChannelsInfo(result));
|
|
|
|
|
|
|
|
const auto process = _leftChannelsProcess.get();
|
2018-06-19 10:42:21 +00:00
|
|
|
process->offset += result.match(
|
|
|
|
[](const auto &data) {
|
2019-07-05 13:38:38 +00:00
|
|
|
return int(data.vchats().v.size());
|
2018-06-19 10:42:21 +00:00
|
|
|
});
|
|
|
|
|
2018-06-18 21:52:13 +00:00
|
|
|
process->fullCount = result.match(
|
|
|
|
[](const MTPDmessages_chats &data) {
|
2019-07-05 13:38:38 +00:00
|
|
|
return int(data.vchats().v.size());
|
2018-06-18 21:52:13 +00:00
|
|
|
}, [](const MTPDmessages_chatsSlice &data) {
|
2019-07-05 13:38:38 +00:00
|
|
|
return data.vcount().v;
|
2018-06-18 21:52:13 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
process->finished = result.match(
|
2018-06-17 20:15:40 +00:00
|
|
|
[](const MTPDmessages_chats &data) {
|
|
|
|
return true;
|
|
|
|
}, [](const MTPDmessages_chatsSlice &data) {
|
2019-07-05 13:38:38 +00:00
|
|
|
return data.vchats().v.isEmpty();
|
2018-06-17 20:15:40 +00:00
|
|
|
});
|
|
|
|
|
2018-06-19 10:42:21 +00:00
|
|
|
if (process->progress) {
|
2018-07-11 21:06:35 +00:00
|
|
|
if (!process->progress(process->info.left.size())) {
|
2018-06-19 10:42:21 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2018-06-13 17:10:12 +00:00
|
|
|
|
2018-06-18 21:52:13 +00:00
|
|
|
done();
|
2018-06-17 20:15:40 +00:00
|
|
|
}).send();
|
|
|
|
}
|
|
|
|
|
2018-06-18 21:52:13 +00:00
|
|
|
void ApiWrap::appendLeftChannelsSlice(Data::DialogsInfo &&info) {
|
|
|
|
Expects(_leftChannelsProcess != nullptr);
|
2018-06-21 14:01:27 +00:00
|
|
|
Expects(!_splits.empty());
|
2018-06-17 20:15:40 +00:00
|
|
|
|
2018-06-21 14:01:27 +00:00
|
|
|
appendChatsSlice(
|
|
|
|
*_leftChannelsProcess,
|
2018-07-11 21:06:35 +00:00
|
|
|
_leftChannelsProcess->info.left,
|
|
|
|
std::move(info.left),
|
2018-06-21 14:01:27 +00:00
|
|
|
_splits.size() - 1);
|
2018-06-13 17:10:12 +00:00
|
|
|
}
|
|
|
|
|
2018-06-18 21:52:13 +00:00
|
|
|
void ApiWrap::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) {
|
2018-06-18 21:52:13 +00:00
|
|
|
Expects(_settings != nullptr);
|
2018-06-13 13:12:36 +00:00
|
|
|
|
2018-06-18 21:52:13 +00:00
|
|
|
const auto types = _settings->types;
|
2019-04-09 14:55:21 +00:00
|
|
|
const auto goodByTypes = [&](const Data::DialogInfo &info) {
|
|
|
|
return ((types & SettingsFromDialogsType(info.type)) != 0);
|
|
|
|
};
|
2021-03-13 12:12:08 +00:00
|
|
|
auto filtered = ranges::views::all(
|
2018-07-11 21:06:35 +00:00
|
|
|
from
|
2021-03-13 12:12:08 +00:00
|
|
|
) | ranges::views::filter([&](const Data::DialogInfo &info) {
|
2019-04-09 14:55:21 +00:00
|
|
|
if (goodByTypes(info)) {
|
|
|
|
return true;
|
|
|
|
} else if (info.migratedToChannelId
|
|
|
|
&& (((types & Settings::Type::PublicGroups) != 0)
|
|
|
|
|| ((types & Settings::Type::PrivateGroups) != 0))) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2018-06-18 21:52:13 +00:00
|
|
|
});
|
2018-07-11 21:06:35 +00:00
|
|
|
to.reserve(to.size() + from.size());
|
2018-06-21 14:01:27 +00:00
|
|
|
for (auto &info : filtered) {
|
2018-07-11 21:06:35 +00:00
|
|
|
const auto nextIndex = to.size();
|
2019-04-09 14:55:21 +00:00
|
|
|
if (info.migratedToChannelId) {
|
2021-04-09 16:47:28 +00:00
|
|
|
const auto toPeerId = PeerId(info.migratedToChannelId);
|
2019-04-09 14:55:21 +00:00
|
|
|
const auto i = process.indexByPeer.find(toPeerId);
|
|
|
|
if (i != process.indexByPeer.end()
|
|
|
|
&& Data::AddMigrateFromSlice(
|
|
|
|
to[i->second],
|
|
|
|
info,
|
|
|
|
splitIndex,
|
|
|
|
int(_splits.size()))) {
|
|
|
|
continue;
|
|
|
|
} else if (!goodByTypes(info)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const auto [i, ok] = process.indexByPeer.emplace(
|
|
|
|
info.peerId,
|
|
|
|
nextIndex);
|
2018-06-21 14:01:27 +00:00
|
|
|
if (ok) {
|
2018-07-11 21:06:35 +00:00
|
|
|
to.push_back(std::move(info));
|
2018-06-18 21:52:13 +00:00
|
|
|
}
|
2018-07-11 21:06:35 +00:00
|
|
|
to[i->second].splits.push_back(splitIndex);
|
|
|
|
to[i->second].messagesCountPerSplit.push_back(0);
|
2018-06-13 13:12:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-21 14:01:27 +00:00
|
|
|
void ApiWrap::requestMessagesSlice() {
|
2018-06-18 21:52:13 +00:00
|
|
|
Expects(_chatProcess != nullptr);
|
2018-06-17 20:15:40 +00:00
|
|
|
|
2018-10-06 12:17:29 +00:00
|
|
|
const auto count = _chatProcess->info.messagesCountPerSplit[
|
|
|
|
_chatProcess->localSplitIndex];
|
|
|
|
if (!count) {
|
|
|
|
loadMessagesFiles({});
|
|
|
|
return;
|
|
|
|
}
|
2018-06-21 14:01:27 +00:00
|
|
|
requestChatMessages(
|
|
|
|
_chatProcess->info.splits[_chatProcess->localSplitIndex],
|
|
|
|
_chatProcess->largestIdPlusOne,
|
|
|
|
-kMessagesSliceLimit,
|
|
|
|
kMessagesSliceLimit,
|
|
|
|
[=](const MTPmessages_Messages &result) {
|
2018-06-18 21:52:13 +00:00
|
|
|
Expects(_chatProcess != nullptr);
|
2018-06-13 13:12:36 +00:00
|
|
|
|
2018-06-13 17:10:12 +00:00
|
|
|
result.match([&](const MTPDmessages_messagesNotModified &data) {
|
2018-06-13 13:12:36 +00:00
|
|
|
error("Unexpected messagesNotModified received.");
|
|
|
|
}, [&](const auto &data) {
|
|
|
|
if constexpr (MTPDmessages_messages::Is<decltype(data)>()) {
|
2018-06-18 21:52:13 +00:00
|
|
|
_chatProcess->lastSlice = true;
|
2018-06-13 13:12:36 +00:00
|
|
|
}
|
|
|
|
loadMessagesFiles(Data::ParseMessagesSlice(
|
2018-06-20 20:32:52 +00:00
|
|
|
_chatProcess->context,
|
2019-07-05 13:38:38 +00:00
|
|
|
data.vmessages(),
|
|
|
|
data.vusers(),
|
|
|
|
data.vchats(),
|
2018-06-18 21:52:13 +00:00
|
|
|
_chatProcess->info.relativePath));
|
2018-06-13 13:12:36 +00:00
|
|
|
});
|
2018-06-21 14:01:27 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void ApiWrap::requestChatMessages(
|
|
|
|
int splitIndex,
|
|
|
|
int offsetId,
|
|
|
|
int addOffset,
|
|
|
|
int limit,
|
|
|
|
FnMut<void(MTPmessages_Messages&&)> done) {
|
2018-06-28 16:25:50 +00:00
|
|
|
Expects(_chatProcess != nullptr);
|
|
|
|
|
|
|
|
_chatProcess->requestDone = std::move(done);
|
|
|
|
const auto doneHandler = [=](MTPmessages_Messages &&result) {
|
|
|
|
Expects(_chatProcess != nullptr);
|
|
|
|
|
|
|
|
base::take(_chatProcess->requestDone)(std::move(result));
|
|
|
|
};
|
2019-04-09 14:55:21 +00:00
|
|
|
const auto splitsCount = int(_splits.size());
|
|
|
|
const auto realPeerInput = (splitIndex >= 0)
|
|
|
|
? _chatProcess->info.input
|
|
|
|
: _chatProcess->info.migratedFromInput;
|
|
|
|
const auto realSplitIndex = (splitIndex >= 0)
|
|
|
|
? splitIndex
|
|
|
|
: (splitsCount + splitIndex);
|
2018-06-18 21:52:13 +00:00
|
|
|
if (_chatProcess->info.onlyMyMessages) {
|
2019-04-09 14:55:21 +00:00
|
|
|
splitRequest(realSplitIndex, MTPmessages_Search(
|
2018-06-17 12:47:07 +00:00
|
|
|
MTP_flags(MTPmessages_Search::Flag::f_from_id),
|
2019-04-09 14:55:21 +00:00
|
|
|
realPeerInput,
|
2019-07-05 13:38:38 +00:00
|
|
|
MTP_string(), // query
|
2020-10-06 12:58:16 +00:00
|
|
|
MTP_inputPeerSelf(),
|
2020-09-01 06:44:18 +00:00
|
|
|
MTPint(), // top_msg_id
|
2018-06-17 12:47:07 +00:00
|
|
|
MTP_inputMessagesFilterEmpty(),
|
|
|
|
MTP_int(0), // min_date
|
|
|
|
MTP_int(0), // max_date
|
2018-06-21 14:01:27 +00:00
|
|
|
MTP_int(offsetId),
|
|
|
|
MTP_int(addOffset),
|
|
|
|
MTP_int(limit),
|
2018-06-17 12:47:07 +00:00
|
|
|
MTP_int(0), // max_id
|
|
|
|
MTP_int(0), // min_id
|
2021-08-25 08:15:05 +00:00
|
|
|
MTP_long(0) // hash
|
2018-06-28 16:25:50 +00:00
|
|
|
)).done(doneHandler).send();
|
2018-06-17 12:47:07 +00:00
|
|
|
} else {
|
2019-04-09 14:55:21 +00:00
|
|
|
splitRequest(realSplitIndex, MTPmessages_GetHistory(
|
|
|
|
realPeerInput,
|
2018-06-21 14:01:27 +00:00
|
|
|
MTP_int(offsetId),
|
2018-06-17 12:47:07 +00:00
|
|
|
MTP_int(0), // offset_date
|
2018-06-21 14:01:27 +00:00
|
|
|
MTP_int(addOffset),
|
|
|
|
MTP_int(limit),
|
2018-06-17 12:47:07 +00:00
|
|
|
MTP_int(0), // max_id
|
|
|
|
MTP_int(0), // min_id
|
2021-08-25 08:15:05 +00:00
|
|
|
MTP_long(0) // hash
|
2021-03-12 12:48:00 +00:00
|
|
|
)).fail([=](const MTP::Error &error) {
|
2018-06-28 16:25:50 +00:00
|
|
|
Expects(_chatProcess != nullptr);
|
|
|
|
|
2022-11-26 21:20:17 +00:00
|
|
|
if (error.type() == u"CHANNEL_PRIVATE"_q) {
|
2019-04-09 14:55:21 +00:00
|
|
|
if (realPeerInput.type() == mtpc_inputPeerChannel
|
2018-06-28 16:25:50 +00:00
|
|
|
&& !_chatProcess->info.onlyMyMessages) {
|
|
|
|
|
|
|
|
// Perhaps we just left / were kicked from channel.
|
|
|
|
// Just switch to only my messages.
|
|
|
|
_chatProcess->info.onlyMyMessages = true;
|
|
|
|
requestChatMessages(
|
|
|
|
splitIndex,
|
|
|
|
offsetId,
|
|
|
|
addOffset,
|
|
|
|
limit,
|
|
|
|
base::take(_chatProcess->requestDone));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}).done(doneHandler).send();
|
2018-06-17 12:47:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-13 13:12:36 +00:00
|
|
|
void ApiWrap::loadMessagesFiles(Data::MessagesSlice &&slice) {
|
2018-06-18 21:52:13 +00:00
|
|
|
Expects(_chatProcess != nullptr);
|
|
|
|
Expects(!_chatProcess->slice.has_value());
|
2018-06-13 13:12:36 +00:00
|
|
|
|
2022-07-28 14:48:28 +00:00
|
|
|
collectMessagesCustomEmoji(slice);
|
|
|
|
|
2018-06-13 13:12:36 +00:00
|
|
|
if (slice.list.empty()) {
|
2018-06-18 21:52:13 +00:00
|
|
|
_chatProcess->lastSlice = true;
|
2018-06-13 13:12:36 +00:00
|
|
|
}
|
2018-06-18 21:52:13 +00:00
|
|
|
_chatProcess->slice = std::move(slice);
|
2018-07-07 20:58:54 +00:00
|
|
|
_chatProcess->fileIndex = 0;
|
2018-06-13 13:12:36 +00:00
|
|
|
|
2022-07-28 14:48:28 +00:00
|
|
|
resolveCustomEmoji();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ApiWrap::collectMessagesCustomEmoji(const Data::MessagesSlice &slice) {
|
|
|
|
for (const auto &message : slice.list) {
|
|
|
|
for (const auto &part : message.text) {
|
|
|
|
if (part.type == Data::TextPart::Type::CustomEmoji) {
|
|
|
|
if (const auto id = part.additional.toULongLong()) {
|
|
|
|
if (!_resolvedCustomEmoji.contains(id)) {
|
|
|
|
_unresolvedCustomEmoji.emplace(id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ApiWrap::resolveCustomEmoji() {
|
|
|
|
if (_unresolvedCustomEmoji.empty()) {
|
|
|
|
loadNextMessageFile();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto count = std::min(
|
|
|
|
int(_unresolvedCustomEmoji.size()),
|
|
|
|
kMaxEmojiPerRequest);
|
|
|
|
auto v = QVector<MTPlong>();
|
|
|
|
v.reserve(count);
|
|
|
|
const auto till = end(_unresolvedCustomEmoji);
|
|
|
|
const auto from = end(_unresolvedCustomEmoji) - count;
|
|
|
|
for (auto i = from; i != till; ++i) {
|
|
|
|
v.push_back(MTP_long(*i));
|
|
|
|
}
|
|
|
|
_unresolvedCustomEmoji.erase(from, till);
|
|
|
|
const auto finalize = [=] {
|
|
|
|
for (const auto &id : v) {
|
|
|
|
if (_resolvedCustomEmoji.contains(id.v)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
_resolvedCustomEmoji.emplace(
|
|
|
|
id.v,
|
|
|
|
Data::Document{
|
|
|
|
.file = {
|
|
|
|
.skipReason = Data::File::SkipReason::Unavailable,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
resolveCustomEmoji();
|
|
|
|
};
|
|
|
|
mainRequest(MTPmessages_GetCustomEmojiDocuments(
|
|
|
|
MTP_vector<MTPlong>(v)
|
|
|
|
)).fail([=](const MTP::Error &error) {
|
|
|
|
LOG(("Export Error: Failed to get documents for emoji."));
|
|
|
|
finalize();
|
|
|
|
return true;
|
|
|
|
}).done([=](const MTPVector<MTPDocument> &result) {
|
|
|
|
for (const auto &entry : result.v) {
|
|
|
|
auto document = Data::ParseDocument(
|
|
|
|
_chatProcess->context,
|
|
|
|
entry,
|
|
|
|
_chatProcess->info.relativePath,
|
|
|
|
TimeId());
|
|
|
|
_resolvedCustomEmoji.emplace(document.id, std::move(document));
|
|
|
|
}
|
|
|
|
finalize();
|
|
|
|
}).send();
|
2018-06-13 13:12:36 +00:00
|
|
|
}
|
|
|
|
|
2019-11-29 06:55:22 +00:00
|
|
|
Data::Message *ApiWrap::currentFileMessage() const {
|
|
|
|
Expects(_chatProcess != nullptr);
|
|
|
|
Expects(_chatProcess->slice.has_value());
|
|
|
|
|
|
|
|
return &_chatProcess->slice->list[_chatProcess->fileIndex];
|
|
|
|
}
|
|
|
|
|
|
|
|
Data::FileOrigin ApiWrap::currentFileMessageOrigin() const {
|
|
|
|
Expects(_chatProcess != nullptr);
|
|
|
|
Expects(_chatProcess->slice.has_value());
|
|
|
|
|
2019-04-09 14:55:21 +00:00
|
|
|
const auto splitIndex = _chatProcess->info.splits[
|
|
|
|
_chatProcess->localSplitIndex];
|
2019-11-29 06:55:22 +00:00
|
|
|
auto result = Data::FileOrigin();
|
|
|
|
result.messageId = currentFileMessage()->id;
|
2019-04-09 14:55:21 +00:00
|
|
|
result.split = (splitIndex >= 0)
|
|
|
|
? splitIndex
|
|
|
|
: (int(_splits.size()) + splitIndex);
|
|
|
|
result.peer = (splitIndex >= 0)
|
|
|
|
? _chatProcess->info.input
|
|
|
|
: _chatProcess->info.migratedFromInput;
|
2019-11-29 06:55:22 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2022-07-28 14:48:28 +00:00
|
|
|
bool ApiWrap::messageCustomEmojiReady(Data::Message &message) {
|
|
|
|
for (auto &part : message.text) {
|
|
|
|
if (part.type == Data::TextPart::Type::CustomEmoji) {
|
|
|
|
if (const auto id = part.additional.toULongLong()) {
|
|
|
|
const auto i = _resolvedCustomEmoji.find(id);
|
|
|
|
if (i == end(_resolvedCustomEmoji)) {
|
|
|
|
part.additional = Data::TextPart::UnavailableEmoji();
|
|
|
|
} else {
|
|
|
|
auto &file = i->second.file;
|
|
|
|
const auto fileProgress = [=](FileProgress value) {
|
|
|
|
return loadMessageEmojiProgress(value);
|
|
|
|
};
|
|
|
|
const auto ready = processFileLoad(
|
|
|
|
file,
|
|
|
|
{ .customEmojiId = id },
|
|
|
|
fileProgress,
|
|
|
|
[=](const QString &path) {
|
|
|
|
loadMessageEmojiDone(id, path);
|
|
|
|
});
|
|
|
|
if (!ready) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
using SkipReason = Data::File::SkipReason;
|
|
|
|
if (file.skipReason == SkipReason::Unavailable) {
|
|
|
|
part.additional = Data::TextPart::UnavailableEmoji();
|
|
|
|
} else if (file.skipReason == SkipReason::FileType
|
|
|
|
|| file.skipReason == SkipReason::FileSize) {
|
|
|
|
part.additional = QByteArray();
|
|
|
|
} else {
|
|
|
|
part.additional = file.relativePath.toUtf8();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-06-13 13:12:36 +00:00
|
|
|
void ApiWrap::loadNextMessageFile() {
|
2018-06-18 21:52:13 +00:00
|
|
|
Expects(_chatProcess != nullptr);
|
|
|
|
Expects(_chatProcess->slice.has_value());
|
2018-06-13 13:12:36 +00:00
|
|
|
|
2018-07-07 20:58:54 +00:00
|
|
|
for (auto &list = _chatProcess->slice->list
|
|
|
|
; _chatProcess->fileIndex < list.size()
|
|
|
|
; ++_chatProcess->fileIndex) {
|
2022-07-28 14:48:28 +00:00
|
|
|
auto &message = list[_chatProcess->fileIndex];
|
2018-10-06 12:17:29 +00:00
|
|
|
if (Data::SkipMessageByDate(message, *_settings)) {
|
|
|
|
continue;
|
|
|
|
}
|
2022-07-28 14:48:28 +00:00
|
|
|
if (!messageCustomEmojiReady(message)) {
|
|
|
|
return;
|
|
|
|
}
|
2018-06-19 10:42:21 +00:00
|
|
|
const auto fileProgress = [=](FileProgress value) {
|
|
|
|
return loadMessageFileProgress(value);
|
|
|
|
};
|
2018-06-17 08:39:03 +00:00
|
|
|
const auto ready = processFileLoad(
|
2018-07-07 20:58:54 +00:00
|
|
|
list[_chatProcess->fileIndex].file(),
|
2019-11-29 06:55:22 +00:00
|
|
|
currentFileMessageOrigin(),
|
2018-06-19 10:42:21 +00:00
|
|
|
fileProgress,
|
2018-06-17 17:18:34 +00:00
|
|
|
[=](const QString &path) { loadMessageFileDone(path); },
|
2019-11-29 06:55:22 +00:00
|
|
|
currentFileMessage());
|
2018-06-17 08:39:03 +00:00
|
|
|
if (!ready) {
|
2018-06-13 17:10:12 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-07-07 20:58:54 +00:00
|
|
|
const auto thumbProgress = [=](FileProgress value) {
|
|
|
|
return loadMessageThumbProgress(value);
|
|
|
|
};
|
|
|
|
const auto thumbReady = processFileLoad(
|
|
|
|
list[_chatProcess->fileIndex].thumb().file,
|
2019-11-29 06:55:22 +00:00
|
|
|
currentFileMessageOrigin(),
|
2018-07-07 20:58:54 +00:00
|
|
|
thumbProgress,
|
|
|
|
[=](const QString &path) { loadMessageThumbDone(path); },
|
2019-11-29 06:55:22 +00:00
|
|
|
currentFileMessage());
|
2018-07-07 20:58:54 +00:00
|
|
|
if (!thumbReady) {
|
|
|
|
return;
|
|
|
|
}
|
2018-06-13 13:12:36 +00:00
|
|
|
}
|
2018-06-17 20:15:40 +00:00
|
|
|
finishMessagesSlice();
|
|
|
|
}
|
2018-06-13 13:12:36 +00:00
|
|
|
|
2018-06-17 20:15:40 +00:00
|
|
|
void ApiWrap::finishMessagesSlice() {
|
2018-06-18 21:52:13 +00:00
|
|
|
Expects(_chatProcess != nullptr);
|
|
|
|
Expects(_chatProcess->slice.has_value());
|
2018-06-13 13:12:36 +00:00
|
|
|
|
2018-06-18 21:52:13 +00:00
|
|
|
auto slice = *base::take(_chatProcess->slice);
|
2018-06-17 20:15:40 +00:00
|
|
|
if (!slice.list.empty()) {
|
2018-06-21 14:01:27 +00:00
|
|
|
_chatProcess->largestIdPlusOne = slice.list.back().id + 1;
|
2019-04-09 14:55:21 +00:00
|
|
|
const auto splitIndex = _chatProcess->info.splits[
|
|
|
|
_chatProcess->localSplitIndex];
|
|
|
|
if (splitIndex < 0) {
|
|
|
|
slice = AdjustMigrateMessageIds(std::move(slice));
|
|
|
|
}
|
2018-06-19 10:42:21 +00:00
|
|
|
if (!_chatProcess->handleSlice(std::move(slice))) {
|
|
|
|
return;
|
|
|
|
}
|
2018-06-17 20:15:40 +00:00
|
|
|
}
|
2018-06-21 14:01:27 +00:00
|
|
|
if (_chatProcess->lastSlice
|
|
|
|
&& (++_chatProcess->localSplitIndex
|
|
|
|
< _chatProcess->info.splits.size())) {
|
|
|
|
_chatProcess->lastSlice = false;
|
|
|
|
_chatProcess->largestIdPlusOne = 1;
|
|
|
|
}
|
|
|
|
if (!_chatProcess->lastSlice) {
|
2018-06-14 18:34:53 +00:00
|
|
|
requestMessagesSlice();
|
2018-06-21 14:01:27 +00:00
|
|
|
} else {
|
|
|
|
finishMessages();
|
2018-06-13 13:12:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-19 10:42:21 +00:00
|
|
|
bool ApiWrap::loadMessageFileProgress(FileProgress progress) {
|
2018-06-19 18:31:30 +00:00
|
|
|
Expects(_fileProcess != nullptr);
|
2018-06-19 10:42:21 +00:00
|
|
|
Expects(_chatProcess != nullptr);
|
|
|
|
Expects(_chatProcess->slice.has_value());
|
|
|
|
Expects((_chatProcess->fileIndex >= 0)
|
|
|
|
&& (_chatProcess->fileIndex < _chatProcess->slice->list.size()));
|
|
|
|
|
|
|
|
return _chatProcess->fileProgress(DownloadProgress{
|
2021-03-22 12:32:40 +00:00
|
|
|
.randomId = _fileProcess->randomId,
|
|
|
|
.path = _fileProcess->relativePath,
|
|
|
|
.itemIndex = _chatProcess->fileIndex,
|
|
|
|
.ready = progress.ready,
|
|
|
|
.total = progress.total });
|
2018-06-19 10:42:21 +00:00
|
|
|
}
|
|
|
|
|
2018-06-13 13:12:36 +00:00
|
|
|
void ApiWrap::loadMessageFileDone(const QString &relativePath) {
|
2018-06-18 21:52:13 +00:00
|
|
|
Expects(_chatProcess != nullptr);
|
|
|
|
Expects(_chatProcess->slice.has_value());
|
|
|
|
Expects((_chatProcess->fileIndex >= 0)
|
|
|
|
&& (_chatProcess->fileIndex < _chatProcess->slice->list.size()));
|
|
|
|
|
|
|
|
const auto index = _chatProcess->fileIndex;
|
2018-06-24 12:30:09 +00:00
|
|
|
auto &file = _chatProcess->slice->list[index].file();
|
|
|
|
file.relativePath = relativePath;
|
|
|
|
if (relativePath.isEmpty()) {
|
|
|
|
file.skipReason = Data::File::SkipReason::Unavailable;
|
|
|
|
}
|
2018-06-13 13:12:36 +00:00
|
|
|
loadNextMessageFile();
|
|
|
|
}
|
|
|
|
|
2018-07-07 20:58:54 +00:00
|
|
|
bool ApiWrap::loadMessageThumbProgress(FileProgress progress) {
|
|
|
|
return loadMessageFileProgress(progress);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ApiWrap::loadMessageThumbDone(const QString &relativePath) {
|
|
|
|
Expects(_chatProcess != nullptr);
|
|
|
|
Expects(_chatProcess->slice.has_value());
|
|
|
|
Expects((_chatProcess->fileIndex >= 0)
|
|
|
|
&& (_chatProcess->fileIndex < _chatProcess->slice->list.size()));
|
|
|
|
|
|
|
|
const auto index = _chatProcess->fileIndex;
|
|
|
|
auto &file = _chatProcess->slice->list[index].thumb().file;
|
|
|
|
file.relativePath = relativePath;
|
|
|
|
if (relativePath.isEmpty()) {
|
|
|
|
file.skipReason = Data::File::SkipReason::Unavailable;
|
|
|
|
}
|
|
|
|
loadNextMessageFile();
|
|
|
|
}
|
|
|
|
|
2022-07-28 14:48:28 +00:00
|
|
|
bool ApiWrap::loadMessageEmojiProgress(FileProgress progress) {
|
|
|
|
return loadMessageFileProgress(progress);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ApiWrap::loadMessageEmojiDone(uint64 id, const QString &relativePath) {
|
|
|
|
const auto i = _resolvedCustomEmoji.find(id);
|
|
|
|
if (i != end(_resolvedCustomEmoji)) {
|
|
|
|
i->second.file.relativePath = relativePath;
|
|
|
|
if (relativePath.isEmpty()) {
|
|
|
|
i->second.file.skipReason = Data::File::SkipReason::Unavailable;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
loadNextMessageFile();
|
|
|
|
}
|
|
|
|
|
2018-06-13 13:12:36 +00:00
|
|
|
void ApiWrap::finishMessages() {
|
2018-06-18 21:52:13 +00:00
|
|
|
Expects(_chatProcess != nullptr);
|
|
|
|
Expects(!_chatProcess->slice.has_value());
|
2018-06-13 13:12:36 +00:00
|
|
|
|
2018-06-18 21:52:13 +00:00
|
|
|
const auto process = base::take(_chatProcess);
|
|
|
|
process->done();
|
2018-06-13 13:12:36 +00:00
|
|
|
}
|
|
|
|
|
2018-06-17 08:39:03 +00:00
|
|
|
bool ApiWrap::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,
|
2023-06-16 17:23:40 +00:00
|
|
|
Data::Message *message,
|
|
|
|
Data::Story *story) {
|
2018-06-17 08:39:03 +00:00
|
|
|
using SkipReason = Data::File::SkipReason;
|
|
|
|
|
2018-07-07 20:58:54 +00:00
|
|
|
if (!file.relativePath.isEmpty()
|
|
|
|
|| file.skipReason != SkipReason::None) {
|
2018-06-17 08:39:03 +00:00
|
|
|
return true;
|
2018-06-28 17:03:44 +00:00
|
|
|
} else if (!file.location && file.content.isEmpty()) {
|
2018-06-17 08:39:03 +00:00
|
|
|
file.skipReason = SkipReason::Unavailable;
|
|
|
|
return true;
|
2019-11-29 06:55:22 +00:00
|
|
|
} else if (writePreloadedFile(file, origin)) {
|
2018-06-19 10:42:21 +00:00
|
|
|
return !file.relativePath.isEmpty();
|
2018-06-17 08:39:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
using Type = MediaSettings::Type;
|
2023-06-16 17:23:40 +00:00
|
|
|
const auto media = message
|
|
|
|
? &message->media
|
|
|
|
: story
|
|
|
|
? &story->media
|
|
|
|
: nullptr;
|
|
|
|
const auto type = media ? v::match(media->content, [&](
|
2020-08-31 09:04:17 +00:00
|
|
|
const Data::Document &data) {
|
2018-06-17 08:39:03 +00:00
|
|
|
if (data.isSticker) {
|
|
|
|
return Type::Sticker;
|
|
|
|
} else if (data.isVideoMessage) {
|
|
|
|
return Type::VideoMessage;
|
|
|
|
} else if (data.isVoiceMessage) {
|
|
|
|
return Type::VoiceMessage;
|
|
|
|
} else if (data.isAnimated) {
|
|
|
|
return Type::GIF;
|
|
|
|
} else if (data.isVideoFile) {
|
|
|
|
return Type::Video;
|
|
|
|
} else {
|
|
|
|
return Type::File;
|
|
|
|
}
|
|
|
|
}, [](const auto &data) {
|
|
|
|
return Type::Photo;
|
2018-06-24 01:34:47 +00:00
|
|
|
}) : Type(0);
|
2018-06-17 08:39:03 +00:00
|
|
|
|
2023-06-16 17:23:40 +00:00
|
|
|
const auto fullSize = message
|
|
|
|
? message->file().size
|
|
|
|
: story
|
|
|
|
? story->file().size
|
|
|
|
: file.size;
|
2018-10-06 12:17:29 +00:00
|
|
|
if (message && Data::SkipMessageByDate(*message, *_settings)) {
|
|
|
|
file.skipReason = SkipReason::DateLimits;
|
|
|
|
return true;
|
2023-06-16 17:23:40 +00:00
|
|
|
} else if (!story && (_settings->media.types & type) != type) {
|
2018-06-17 08:39:03 +00:00
|
|
|
file.skipReason = SkipReason::FileType;
|
|
|
|
return true;
|
2023-06-16 17:23:40 +00:00
|
|
|
} else if (!story && fullSize >= _settings->media.sizeLimit) {
|
2018-07-08 20:19:31 +00:00
|
|
|
// Don't load thumbs for large files that we skip.
|
2018-06-17 08:39:03 +00:00
|
|
|
file.skipReason = SkipReason::FileSize;
|
|
|
|
return true;
|
|
|
|
}
|
2019-11-29 06:55:22 +00:00
|
|
|
loadFile(file, origin, std::move(progress), std::move(done));
|
2018-06-17 08:39:03 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-11-29 06:55:22 +00:00
|
|
|
bool ApiWrap::writePreloadedFile(
|
|
|
|
Data::File &file,
|
|
|
|
const Data::FileOrigin &origin) {
|
2018-06-13 13:12:36 +00:00
|
|
|
Expects(_settings != nullptr);
|
|
|
|
|
2018-06-11 18:35:27 +00:00
|
|
|
using namespace Output;
|
|
|
|
|
2018-06-17 12:47:47 +00:00
|
|
|
if (const auto path = _fileCache->find(file.location)) {
|
|
|
|
file.relativePath = *path;
|
|
|
|
return true;
|
|
|
|
} else if (!file.content.isEmpty()) {
|
2019-11-29 06:55:22 +00:00
|
|
|
const auto process = prepareFileProcess(file, origin);
|
2018-06-28 17:03:44 +00:00
|
|
|
if (const auto result = process->file.writeBlock(file.content)) {
|
2018-06-17 08:39:03 +00:00
|
|
|
file.relativePath = process->relativePath;
|
2018-06-17 12:47:47 +00:00
|
|
|
_fileCache->save(file.location, file.relativePath);
|
2018-06-19 10:42:21 +00:00
|
|
|
} else {
|
|
|
|
ioError(result);
|
2018-06-11 18:35:27 +00:00
|
|
|
}
|
2018-06-19 10:42:21 +00:00
|
|
|
return true;
|
2018-06-11 18:35:27 +00:00
|
|
|
}
|
2018-06-17 08:39:03 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-06-18 21:52:13 +00:00
|
|
|
void ApiWrap::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-17 08:39:03 +00:00
|
|
|
Expects(_fileProcess == nullptr);
|
2018-06-24 00:33:47 +00:00
|
|
|
Expects(file.location.dcId != 0
|
|
|
|
|| file.location.data.type() == mtpc_inputTakeoutFileLocation);
|
2018-06-17 08:39:03 +00:00
|
|
|
|
2019-11-29 06:55:22 +00:00
|
|
|
_fileProcess = prepareFileProcess(file, origin);
|
2018-06-19 10:42:21 +00:00
|
|
|
_fileProcess->progress = std::move(progress);
|
2018-06-17 08:39:03 +00:00
|
|
|
_fileProcess->done = std::move(done);
|
|
|
|
|
2018-06-19 10:42:21 +00:00
|
|
|
if (_fileProcess->progress) {
|
|
|
|
const auto progress = FileProgress{
|
|
|
|
_fileProcess->file.size(),
|
|
|
|
_fileProcess->size
|
|
|
|
};
|
|
|
|
if (!_fileProcess->progress(progress)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-17 08:39:03 +00:00
|
|
|
loadFilePart();
|
2021-03-22 12:32:40 +00:00
|
|
|
|
|
|
|
Ensures(_fileProcess->requestId != 0);
|
2018-06-17 08:39:03 +00:00
|
|
|
}
|
|
|
|
|
2019-11-29 06:55:22 +00:00
|
|
|
auto ApiWrap::prepareFileProcess(
|
|
|
|
const Data::File &file,
|
|
|
|
const Data::FileOrigin &origin) const
|
2018-06-17 08:39:03 +00:00
|
|
|
-> std::unique_ptr<FileProcess> {
|
|
|
|
Expects(_settings != nullptr);
|
|
|
|
|
|
|
|
const auto relativePath = Output::File::PrepareRelativePath(
|
|
|
|
_settings->path,
|
|
|
|
file.suggestedPath);
|
|
|
|
auto result = std::make_unique<FileProcess>(
|
2018-06-20 16:10:38 +00:00
|
|
|
_settings->path + relativePath,
|
|
|
|
_stats);
|
2018-06-17 08:39:03 +00:00
|
|
|
result->relativePath = relativePath;
|
|
|
|
result->location = file.location;
|
|
|
|
result->size = file.size;
|
2019-11-29 06:55:22 +00:00
|
|
|
result->origin = origin;
|
2021-09-15 10:21:45 +00:00
|
|
|
result->randomId = base::RandomValue<uint64>();
|
2018-06-17 08:39:03 +00:00
|
|
|
return result;
|
2018-06-11 18:35:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ApiWrap::loadFilePart() {
|
|
|
|
if (!_fileProcess
|
2021-03-22 12:32:40 +00:00
|
|
|
|| _fileProcess->requestId
|
2018-06-11 18:35:27 +00:00
|
|
|
|| _fileProcess->requests.size() >= kFileRequestsCount
|
|
|
|
|| (_fileProcess->size > 0
|
|
|
|
&& _fileProcess->offset >= _fileProcess->size)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto offset = _fileProcess->offset;
|
|
|
|
_fileProcess->requests.push_back({ offset });
|
2021-03-22 12:32:40 +00:00
|
|
|
_fileProcess->requestId = fileRequest(
|
2018-06-11 18:35:27 +00:00
|
|
|
_fileProcess->location,
|
|
|
|
_fileProcess->offset
|
|
|
|
).done([=](const MTPupload_File &result) {
|
2021-03-22 12:32:40 +00:00
|
|
|
_fileProcess->requestId = 0;
|
2018-06-11 18:35:27 +00:00
|
|
|
filePartDone(offset, result);
|
|
|
|
}).send();
|
|
|
|
_fileProcess->offset += kFileChunkSize;
|
|
|
|
|
|
|
|
if (_fileProcess->size > 0
|
|
|
|
&& _fileProcess->requests.size() < kFileRequestsCount) {
|
2021-03-22 12:32:40 +00:00
|
|
|
// Only one request at a time supported right now.
|
2018-06-11 18:35:27 +00:00
|
|
|
//const auto runner = _runner;
|
|
|
|
//crl::on_main([=] {
|
|
|
|
// QTimer::singleShot(kFileNextRequestDelay, [=] {
|
|
|
|
// runner([=] {
|
|
|
|
// loadFilePart();
|
|
|
|
// });
|
|
|
|
// });
|
|
|
|
//});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-10 14:22:28 +00:00
|
|
|
void ApiWrap::filePartDone(int64 offset, const MTPupload_File &result) {
|
2018-06-11 18:35:27 +00:00
|
|
|
Expects(_fileProcess != nullptr);
|
|
|
|
Expects(!_fileProcess->requests.empty());
|
|
|
|
|
|
|
|
if (result.type() == mtpc_upload_fileCdnRedirect) {
|
|
|
|
error("Cdn redirect is not supported.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto &data = result.c_upload_file();
|
2019-07-05 13:38:38 +00:00
|
|
|
if (data.vbytes().v.isEmpty()) {
|
2018-06-11 18:35:27 +00:00
|
|
|
if (_fileProcess->size > 0) {
|
|
|
|
error("Empty bytes received in file part.");
|
|
|
|
return;
|
|
|
|
}
|
2018-06-24 00:33:47 +00:00
|
|
|
const auto result = _fileProcess->file.writeBlock({});
|
|
|
|
if (!result) {
|
|
|
|
ioError(result);
|
|
|
|
return;
|
|
|
|
}
|
2018-06-11 18:35:27 +00:00
|
|
|
} else {
|
|
|
|
using Request = FileProcess::Request;
|
|
|
|
auto &requests = _fileProcess->requests;
|
|
|
|
const auto i = ranges::find(
|
|
|
|
requests,
|
|
|
|
offset,
|
|
|
|
[](const Request &request) { return request.offset; });
|
|
|
|
Assert(i != end(requests));
|
|
|
|
|
2019-07-05 13:38:38 +00:00
|
|
|
i->bytes = data.vbytes().v;
|
2018-06-11 18:35:27 +00:00
|
|
|
|
|
|
|
auto &file = _fileProcess->file;
|
|
|
|
while (!requests.empty() && !requests.front().bytes.isEmpty()) {
|
|
|
|
const auto &bytes = requests.front().bytes;
|
2018-06-19 10:42:21 +00:00
|
|
|
if (const auto result = file.writeBlock(bytes); !result) {
|
|
|
|
ioError(result);
|
2018-06-11 18:35:27 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
requests.pop_front();
|
|
|
|
}
|
|
|
|
|
2018-06-19 10:42:21 +00:00
|
|
|
if (_fileProcess->progress) {
|
|
|
|
_fileProcess->progress(FileProgress{
|
|
|
|
file.size(),
|
|
|
|
_fileProcess->size });
|
|
|
|
}
|
|
|
|
|
2018-06-11 18:35:27 +00:00
|
|
|
if (!requests.empty()
|
|
|
|
|| !_fileProcess->size
|
|
|
|
|| _fileProcess->size > _fileProcess->offset) {
|
|
|
|
loadFilePart();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2018-06-17 12:47:47 +00:00
|
|
|
|
2018-06-11 18:35:27 +00:00
|
|
|
auto process = base::take(_fileProcess);
|
2018-06-17 12:47:47 +00:00
|
|
|
const auto relativePath = process->relativePath;
|
|
|
|
_fileCache->save(process->location, relativePath);
|
2018-06-11 18:35:27 +00:00
|
|
|
process->done(process->relativePath);
|
|
|
|
}
|
|
|
|
|
2022-05-10 14:22:28 +00:00
|
|
|
void ApiWrap::filePartRefreshReference(int64 offset) {
|
2019-11-29 06:55:22 +00:00
|
|
|
Expects(_fileProcess != nullptr);
|
2021-03-22 12:32:40 +00:00
|
|
|
Expects(_fileProcess->requestId == 0);
|
2019-11-29 06:55:22 +00:00
|
|
|
|
|
|
|
const auto &origin = _fileProcess->origin;
|
2023-06-16 17:23:40 +00:00
|
|
|
if (origin.storyId) {
|
|
|
|
_fileProcess->requestId = mainRequest(MTPstories_GetStoriesByID(
|
2023-08-31 08:58:34 +00:00
|
|
|
MTP_inputPeerSelf(),
|
2023-06-16 17:23:40 +00:00
|
|
|
MTP_vector<MTPint>(1, MTP_int(origin.storyId))
|
|
|
|
)).fail([=](const MTP::Error &error) {
|
|
|
|
_fileProcess->requestId = 0;
|
|
|
|
filePartUnavailable();
|
|
|
|
return true;
|
|
|
|
}).done([=](const MTPstories_Stories &result) {
|
|
|
|
_fileProcess->requestId = 0;
|
|
|
|
filePartExtractReference(offset, result);
|
|
|
|
}).send();
|
|
|
|
return;
|
|
|
|
} else if (!origin.messageId) {
|
2019-11-29 06:55:22 +00:00
|
|
|
error("FILE_REFERENCE error for non-message file.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (origin.peer.type() == mtpc_inputPeerChannel
|
|
|
|
|| origin.peer.type() == mtpc_inputPeerChannelFromMessage) {
|
|
|
|
const auto channel = (origin.peer.type() == mtpc_inputPeerChannel)
|
|
|
|
? MTP_inputChannel(
|
|
|
|
origin.peer.c_inputPeerChannel().vchannel_id(),
|
|
|
|
origin.peer.c_inputPeerChannel().vaccess_hash())
|
|
|
|
: MTP_inputChannelFromMessage(
|
|
|
|
origin.peer.c_inputPeerChannelFromMessage().vpeer(),
|
|
|
|
origin.peer.c_inputPeerChannelFromMessage().vmsg_id(),
|
|
|
|
origin.peer.c_inputPeerChannelFromMessage().vchannel_id());
|
2021-03-22 12:32:40 +00:00
|
|
|
_fileProcess->requestId = mainRequest(MTPchannels_GetMessages(
|
2019-11-29 06:55:22 +00:00
|
|
|
channel,
|
|
|
|
MTP_vector<MTPInputMessage>(
|
|
|
|
1,
|
|
|
|
MTP_inputMessageID(MTP_int(origin.messageId)))
|
2021-03-12 12:48:00 +00:00
|
|
|
)).fail([=](const MTP::Error &error) {
|
2021-03-22 12:32:40 +00:00
|
|
|
_fileProcess->requestId = 0;
|
2019-11-29 06:55:22 +00:00
|
|
|
filePartUnavailable();
|
|
|
|
return true;
|
|
|
|
}).done([=](const MTPmessages_Messages &result) {
|
2021-03-22 12:32:40 +00:00
|
|
|
_fileProcess->requestId = 0;
|
2019-11-29 06:55:22 +00:00
|
|
|
filePartExtractReference(offset, result);
|
|
|
|
}).send();
|
|
|
|
} else {
|
2021-03-22 12:32:40 +00:00
|
|
|
_fileProcess->requestId = splitRequest(
|
|
|
|
origin.split,
|
|
|
|
MTPmessages_GetMessages(
|
|
|
|
MTP_vector<MTPInputMessage>(
|
|
|
|
1,
|
|
|
|
MTP_inputMessageID(MTP_int(origin.messageId)))
|
|
|
|
)
|
|
|
|
).fail([=](const MTP::Error &error) {
|
|
|
|
_fileProcess->requestId = 0;
|
2019-11-29 06:55:22 +00:00
|
|
|
filePartUnavailable();
|
|
|
|
return true;
|
|
|
|
}).done([=](const MTPmessages_Messages &result) {
|
2021-03-22 12:32:40 +00:00
|
|
|
_fileProcess->requestId = 0;
|
2019-11-29 06:55:22 +00:00
|
|
|
filePartExtractReference(offset, result);
|
|
|
|
}).send();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ApiWrap::filePartExtractReference(
|
2022-05-10 14:22:28 +00:00
|
|
|
int64 offset,
|
2019-11-29 06:55:22 +00:00
|
|
|
const MTPmessages_Messages &result) {
|
|
|
|
Expects(_fileProcess != nullptr);
|
2021-03-22 12:32:40 +00:00
|
|
|
Expects(_fileProcess->requestId == 0);
|
2019-11-29 06:55:22 +00:00
|
|
|
|
|
|
|
result.match([&](const MTPDmessages_messagesNotModified &data) {
|
|
|
|
error("Unexpected messagesNotModified received.");
|
|
|
|
}, [&](const auto &data) {
|
2020-09-01 06:44:18 +00:00
|
|
|
Expects(_selfId.has_value());
|
|
|
|
|
2019-11-29 06:55:22 +00:00
|
|
|
auto context = Data::ParseMediaContext();
|
2021-04-09 16:47:28 +00:00
|
|
|
context.selfPeerId = peerFromUser(*_selfId);
|
2019-11-29 06:55:22 +00:00
|
|
|
const auto messages = Data::ParseMessagesSlice(
|
|
|
|
context,
|
|
|
|
data.vmessages(),
|
|
|
|
data.vusers(),
|
|
|
|
data.vchats(),
|
|
|
|
_chatProcess->info.relativePath);
|
|
|
|
for (const auto &message : messages.list) {
|
|
|
|
if (message.id == _fileProcess->origin.messageId) {
|
|
|
|
const auto refresh1 = Data::RefreshFileReference(
|
|
|
|
_fileProcess->location,
|
|
|
|
message.file().location);
|
|
|
|
const auto refresh2 = Data::RefreshFileReference(
|
|
|
|
_fileProcess->location,
|
|
|
|
message.thumb().file.location);
|
|
|
|
if (refresh1 || refresh2) {
|
2021-03-22 12:32:40 +00:00
|
|
|
_fileProcess->requestId = fileRequest(
|
2019-11-29 06:55:22 +00:00
|
|
|
_fileProcess->location,
|
|
|
|
offset
|
|
|
|
).done([=](const MTPupload_File &result) {
|
2021-03-22 12:32:40 +00:00
|
|
|
_fileProcess->requestId = 0;
|
2019-11-29 06:55:22 +00:00
|
|
|
filePartDone(offset, result);
|
|
|
|
}).send();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
filePartUnavailable();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-06-16 17:23:40 +00:00
|
|
|
void ApiWrap::filePartExtractReference(
|
|
|
|
int64 offset,
|
|
|
|
const MTPstories_Stories &result) {
|
|
|
|
Expects(_fileProcess != nullptr);
|
|
|
|
Expects(_fileProcess->requestId == 0);
|
|
|
|
|
|
|
|
const auto stories = Data::ParseStoriesSlice(
|
|
|
|
result.data().vstories(),
|
|
|
|
0);
|
|
|
|
for (const auto &story : stories.list) {
|
|
|
|
if (story.id == _fileProcess->origin.storyId) {
|
|
|
|
const auto refresh1 = Data::RefreshFileReference(
|
|
|
|
_fileProcess->location,
|
|
|
|
story.file().location);
|
|
|
|
const auto refresh2 = Data::RefreshFileReference(
|
|
|
|
_fileProcess->location,
|
|
|
|
story.thumb().file.location);
|
|
|
|
if (refresh1 || refresh2) {
|
|
|
|
_fileProcess->requestId = fileRequest(
|
|
|
|
_fileProcess->location,
|
|
|
|
offset
|
|
|
|
).done([=](const MTPupload_File &result) {
|
|
|
|
_fileProcess->requestId = 0;
|
|
|
|
filePartDone(offset, result);
|
|
|
|
}).send();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
filePartUnavailable();
|
|
|
|
}
|
|
|
|
|
2018-06-24 12:30:09 +00:00
|
|
|
void ApiWrap::filePartUnavailable() {
|
|
|
|
Expects(_fileProcess != nullptr);
|
|
|
|
Expects(!_fileProcess->requests.empty());
|
|
|
|
|
|
|
|
LOG(("Export Error: File unavailable."));
|
|
|
|
|
|
|
|
base::take(_fileProcess)->done(QString());
|
|
|
|
}
|
|
|
|
|
2021-03-12 12:48:00 +00:00
|
|
|
void ApiWrap::error(const MTP::Error &error) {
|
2021-03-12 10:45:13 +00:00
|
|
|
_errors.fire_copy(error);
|
2018-06-11 18:35:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ApiWrap::error(const QString &text) {
|
2021-03-12 12:48:00 +00:00
|
|
|
error(MTP::Error(
|
2021-03-12 10:45:13 +00:00
|
|
|
MTP_rpc_error(MTP_int(0), MTP_string("API_ERROR: " + text))));
|
2018-06-11 18:35:27 +00:00
|
|
|
}
|
|
|
|
|
2018-06-19 10:42:21 +00:00
|
|
|
void ApiWrap::ioError(const Output::Result &result) {
|
|
|
|
_ioErrors.fire_copy(result);
|
|
|
|
}
|
|
|
|
|
2018-06-11 18:35:27 +00:00
|
|
|
ApiWrap::~ApiWrap() = default;
|
|
|
|
|
|
|
|
} // namespace Export
|