Skip to content

Commit

Permalink
Better steps division in export.
Browse files Browse the repository at this point in the history
  • Loading branch information
john-preston committed Jun 18, 2018
1 parent c7aa5ed commit 7d4e234
Show file tree
Hide file tree
Showing 13 changed files with 806 additions and 384 deletions.
2 changes: 1 addition & 1 deletion Telegram/Resources/scheme.tl
Original file line number Diff line number Diff line change
Expand Up @@ -1266,7 +1266,7 @@ channels.setStickers#ea8ca4f9 channel:InputChannel stickerset:InputStickerSet =
channels.readMessageContents#eab5dc38 channel:InputChannel id:Vector<int> = Bool;
channels.deleteHistory#af369d42 channel:InputChannel max_id:int = Bool;
channels.togglePreHistoryHidden#eabbb94c channel:InputChannel enabled:Bool = Updates;
channels.getLeftChannels#90920196 = messages.Chats;
channels.getLeftChannels#8341ecc0 offset:int = messages.Chats;

bots.sendCustomRequest#aa2769ed custom_method:string params:DataJSON = DataJSON;
bots.answerWebhookJSONQuery#e6213f4d query_id:long data:DataJSON = Bool;
Expand Down
52 changes: 28 additions & 24 deletions Telegram/SourceFiles/export/data/export_data_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -944,30 +944,23 @@ DialogsInfo ParseDialogsInfo(const MTPmessages_Dialogs &data) {
return result;
}

void InsertLeftDialog(
DialogsInfo &info,
const Chat &chat,
Message &&message) {
const auto projection = [](const DialogInfo &dialog) {
return std::make_tuple(
dialog.topMessageDate,
dialog.topMessageId,
BarePeerId(dialog.peerId));
};
const auto i = ranges::lower_bound(
info.list,
std::make_tuple(message.date, message.id, chat.id),
ranges::ordered_less{},
projection);

auto insert = DialogInfo();
insert.input = chat.input;
insert.name = chat.title;
insert.peerId = ChatPeerId(chat.id);
insert.topMessageDate = message.date;
insert.topMessageId = message.id;
insert.type = DialogTypeFromChat(chat);
info.list.insert(i, std::move(insert));
DialogsInfo ParseLeftChannelsInfo(const MTPmessages_Chats &data) {
auto result = DialogsInfo();
data.match([&](const auto &data) { //MTPDmessages_chats &data) {
result.list.reserve(data.vchats.v.size());
for (const auto &single : data.vchats.v) {
const auto chat = ParseChat(single);
auto info = DialogInfo();
info.input = chat.input;
info.name = chat.title;
info.peerId = ChatPeerId(chat.id);
info.topMessageDate = 0;
info.topMessageId = 0;
info.type = DialogTypeFromChat(chat);
result.list.push_back(std::move(info));
}
});
return result;
}

void FinalizeDialogsInfo(DialogsInfo &info, const Settings &settings) {
Expand Down Expand Up @@ -995,6 +988,17 @@ void FinalizeDialogsInfo(DialogsInfo &info, const Settings &settings) {
}
}

void FinalizeLeftChannelsInfo(DialogsInfo &info, const Settings &settings) {
auto &list = info.list;
const auto digits = Data::NumberToString(list.size() - 1).size();
auto index = 0;
for (auto &dialog : list) {
const auto number = Data::NumberToString(++index, digits, '0');
dialog.relativePath = "Chats/left_" + number + '/';
dialog.onlyMyMessages = true;
}
}

MessagesSlice ParseMessagesSlice(
const MTPVector<MTPMessage> &data,
const MTPVector<MTPUser> &users,
Expand Down
8 changes: 4 additions & 4 deletions Telegram/SourceFiles/export/data/export_data_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -433,12 +433,12 @@ struct DialogsInfo {
std::vector<DialogInfo> list;
};

DialogInfo::Type DialogTypeFromChat(const Chat &chat);

DialogsInfo ParseDialogsInfo(const MTPmessages_Dialogs &data);
void InsertLeftDialog(
DialogsInfo &info,
const Chat &chat,
Message &&message);
DialogsInfo ParseLeftChannelsInfo(const MTPmessages_Chats &data);
void FinalizeDialogsInfo(DialogsInfo &info, const Settings &settings);
void FinalizeLeftChannelsInfo(DialogsInfo &info, const Settings &settings);

struct MessagesSlice {
std::vector<Message> list;
Expand Down
Loading

0 comments on commit 7d4e234

Please sign in to comment.