2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-09-02 07:25:46 +00:00

Add chats list export.

This commit is contained in:
John Preston
2018-06-12 21:09:21 +03:00
parent affe9defb5
commit 6776d88688
9 changed files with 473 additions and 77 deletions

View File

@@ -16,10 +16,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace Export {
namespace {
constexpr auto kUserpicsSliceLimit = 2;
constexpr auto kUserpicsSliceLimit = 100;
constexpr auto kFileChunkSize = 128 * 1024;
constexpr auto kFileRequestsCount = 2;
constexpr auto kFileNextRequestDelay = TimeMs(20);
constexpr auto kChatsSliceLimit = 200;
} // namespace
@@ -54,6 +55,17 @@ struct ApiWrap::FileProcess {
};
struct ApiWrap::DialogsProcess {
Data::DialogsInfo info;
FnMut<void(Data::DialogsInfo&&)> done;
int32 offsetDate = 0;
int32 offsetId = 0;
MTPInputPeer offsetPeer = MTP_inputPeerEmpty();
};
ApiWrap::FileProcess::FileProcess(const QString &path) : file(path) {
}
@@ -251,6 +263,49 @@ void ApiWrap::requestSessions(FnMut<void(Data::SessionsList&&)> done) {
}).send();
}
void ApiWrap::requestDialogs(FnMut<void(Data::DialogsInfo&&)> done) {
Expects(_dialogsProcess == nullptr);
_dialogsProcess = std::make_unique<DialogsProcess>();
_dialogsProcess->done = std::move(done);
requestDialogsSlice();
}
void ApiWrap::requestDialogsSlice() {
Expects(_dialogsProcess != nullptr);
mainRequest(MTPmessages_GetDialogs(
MTP_flags(0),
MTP_int(_dialogsProcess->offsetDate),
MTP_int(_dialogsProcess->offsetId),
_dialogsProcess->offsetPeer,
MTP_int(kChatsSliceLimit)
)).done([=](const MTPmessages_Dialogs &result) mutable {
const auto finished = [&] {
switch (result.type()) {
case mtpc_messages_dialogs: return true;
case mtpc_messages_dialogsSlice: {
const auto &data = result.c_messages_dialogsSlice();
return data.vdialogs.v.isEmpty();
} break;
default: Unexpected("Type in ApiWrap::requestChatsSlice.");
}
}();
Data::AppendParsedDialogs(_dialogsProcess->info, result);
if (finished || _dialogsProcess->info.list.empty()) {
auto process = base::take(_dialogsProcess);
ranges::reverse(process->info.list);
process->done(std::move(process->info));
} else {
const auto &last = _dialogsProcess->info.list.back();
_dialogsProcess->offsetId = last.topMessageId;
_dialogsProcess->offsetDate = last.topMessageDate;
_dialogsProcess->offsetPeer = last.input;
requestDialogsSlice();
}
}).send();
}
void ApiWrap::loadFile(const Data::File &file, FnMut<void(QString)> done) {
Expects(_fileProcess == nullptr);