Skip to content

Commit

Permalink
Request only my messages by settings bits.
Browse files Browse the repository at this point in the history
  • Loading branch information
john-preston committed Jun 17, 2018
1 parent 8d52ca6 commit 07ff7c6
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 11 deletions.
61 changes: 50 additions & 11 deletions Telegram/SourceFiles/export/export_api_wrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,16 +458,7 @@ void ApiWrap::requestMessagesSlice() {
Expects(_dialogsProcess->single != nullptr);

const auto process = _dialogsProcess->single.get();
mainRequest(MTPmessages_GetHistory(
process->info.input,
MTP_int(process->offsetId),
MTP_int(0), // offset_date
MTP_int(-kMessagesSliceLimit),
MTP_int(kMessagesSliceLimit),
MTP_int(0), // max_id
MTP_int(0), // min_id
MTP_int(0) // hash
)).done([=](const MTPmessages_Messages &result) mutable {
auto handleResult = [=](const MTPmessages_Messages &result) mutable {
Expects(_dialogsProcess != nullptr);
Expects(_dialogsProcess->single != nullptr);

Expand All @@ -484,7 +475,55 @@ void ApiWrap::requestMessagesSlice() {
data.vchats,
process->info.relativePath));
});
}).send();
};
if (onlyMyMessages()) {
mainRequest(MTPmessages_Search(
MTP_flags(MTPmessages_Search::Flag::f_from_id),
process->info.input,
MTP_string(""), // query
_user,
MTP_inputMessagesFilterEmpty(),
MTP_int(0), // min_date
MTP_int(0), // max_date
MTP_int(process->offsetId),
MTP_int(-kMessagesSliceLimit),
MTP_int(kMessagesSliceLimit),
MTP_int(0), // max_id
MTP_int(0), // min_id
MTP_int(0) // hash
)).done(std::move(handleResult)).send();
} else {
mainRequest(MTPmessages_GetHistory(
process->info.input,
MTP_int(process->offsetId),
MTP_int(0), // offset_date
MTP_int(-kMessagesSliceLimit),
MTP_int(kMessagesSliceLimit),
MTP_int(0), // max_id
MTP_int(0), // min_id
MTP_int(0) // hash
)).done(std::move(handleResult)).send();
}
}

bool ApiWrap::onlyMyMessages() const {
Expects(_dialogsProcess != nullptr);
Expects(_dialogsProcess->single != nullptr);

const auto process = _dialogsProcess->single.get();
using Type = Data::DialogInfo::Type;
const auto setting = [&] {
switch (process->info.type) {
case Type::Personal: return Settings::Type::PersonalChats;
case Type::Bot: return Settings::Type::BotChats;
case Type::PrivateGroup: return Settings::Type::PrivateGroups;
case Type::PrivateChannel: return Settings::Type::PrivateChannels;
case Type::PublicGroup: return Settings::Type::PublicGroups;
case Type::PublicChannel: return Settings::Type::PublicChannels;
}
Unexpected("Type in ApiWrap::onlyMyMessages.");
}();
return (_settings->fullChats & setting) != setting;
}

void ApiWrap::loadMessagesFiles(Data::MessagesSlice &&slice) {
Expand Down
1 change: 1 addition & 0 deletions Telegram/SourceFiles/export/export_api_wrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class ApiWrap {

void requestNextDialog();
void requestMessagesSlice();
bool onlyMyMessages() const;
void loadMessagesFiles(Data::MessagesSlice &&slice);
void loadNextMessageFile();

Expand Down

0 comments on commit 07ff7c6

Please sign in to comment.