2018-06-09 11:51:22 +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
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "scheme.h"
|
2018-06-11 18:35:27 +00:00
|
|
|
#include "base/optional.h"
|
2018-06-12 18:09:21 +00:00
|
|
|
#include "base/variant.h"
|
2018-06-09 11:51:22 +00:00
|
|
|
|
|
|
|
#include <QtCore/QString>
|
|
|
|
#include <QtCore/QByteArray>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace Export {
|
|
|
|
namespace Data {
|
|
|
|
|
2018-06-12 18:09:21 +00:00
|
|
|
using TimeId = int32;
|
2018-06-09 11:51:22 +00:00
|
|
|
using Utf8String = QByteArray;
|
2018-06-12 18:09:21 +00:00
|
|
|
using PeerId = uint64;
|
|
|
|
|
|
|
|
PeerId UserPeerId(int32 userId);
|
|
|
|
PeerId ChatPeerId(int32 chatId);
|
|
|
|
int32 BarePeerId(PeerId peerId);
|
2018-06-09 11:51:22 +00:00
|
|
|
|
|
|
|
Utf8String ParseString(const MTPstring &data);
|
|
|
|
|
2018-06-13 13:12:36 +00:00
|
|
|
Utf8String FillLeft(const Utf8String &data, int length, char filler);
|
|
|
|
|
2018-06-09 11:51:22 +00:00
|
|
|
template <typename Type>
|
2018-06-13 13:12:36 +00:00
|
|
|
inline auto NumberToString(Type value, int length = 0, char filler = '0')
|
2018-06-09 11:51:22 +00:00
|
|
|
-> std::enable_if_t<std::is_arithmetic_v<Type>, Utf8String> {
|
|
|
|
const auto result = std::to_string(value);
|
2018-06-13 13:12:36 +00:00
|
|
|
return FillLeft(
|
|
|
|
Utf8String(result.data(), int(result.size())),
|
|
|
|
length,
|
|
|
|
filler);
|
2018-06-09 11:51:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct UserpicsInfo {
|
|
|
|
int count = 0;
|
|
|
|
};
|
|
|
|
|
2018-06-11 18:35:27 +00:00
|
|
|
struct FileLocation {
|
|
|
|
int dcId = 0;
|
|
|
|
MTPInputFileLocation data;
|
|
|
|
};
|
|
|
|
|
2018-06-09 11:51:22 +00:00
|
|
|
struct File {
|
2018-06-11 18:35:27 +00:00
|
|
|
FileLocation location;
|
|
|
|
int size = 0;
|
|
|
|
QByteArray content;
|
|
|
|
|
|
|
|
QString suggestedPath;
|
|
|
|
|
2018-06-09 11:51:22 +00:00
|
|
|
QString relativePath;
|
|
|
|
};
|
|
|
|
|
2018-06-13 17:10:12 +00:00
|
|
|
struct Image {
|
|
|
|
int width = 0;
|
|
|
|
int height = 0;
|
|
|
|
File file;
|
|
|
|
};
|
|
|
|
|
2018-06-11 18:35:27 +00:00
|
|
|
struct Photo {
|
2018-06-09 11:51:22 +00:00
|
|
|
uint64 id = 0;
|
2018-06-12 18:09:21 +00:00
|
|
|
TimeId date = 0;
|
2018-06-11 18:35:27 +00:00
|
|
|
|
2018-06-13 17:10:12 +00:00
|
|
|
Image image;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Document {
|
|
|
|
uint64 id = 0;
|
|
|
|
TimeId date = 0;
|
|
|
|
|
|
|
|
File file;
|
|
|
|
|
|
|
|
Utf8String name;
|
|
|
|
Utf8String mime;
|
2018-06-11 18:35:27 +00:00
|
|
|
int width = 0;
|
|
|
|
int height = 0;
|
2018-06-13 17:10:12 +00:00
|
|
|
|
|
|
|
Utf8String stickerEmoji;
|
|
|
|
Utf8String songPerformer;
|
|
|
|
Utf8String songTitle;
|
|
|
|
int duration = 0;
|
|
|
|
|
|
|
|
bool isAnimated = false;
|
|
|
|
bool isVideoMessage = false;
|
|
|
|
bool isVoiceMessage = false;
|
|
|
|
bool isVideoFile = false;
|
|
|
|
bool isAudioFile = false;
|
2018-06-09 11:51:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct UserpicsSlice {
|
2018-06-11 18:35:27 +00:00
|
|
|
std::vector<Photo> list;
|
2018-06-09 11:51:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
UserpicsSlice ParseUserpicsSlice(const MTPVector<MTPPhoto> &data);
|
|
|
|
|
2018-06-11 18:35:27 +00:00
|
|
|
struct User {
|
2018-06-12 18:09:21 +00:00
|
|
|
int32 id = 0;
|
2018-06-09 11:51:22 +00:00
|
|
|
Utf8String firstName;
|
|
|
|
Utf8String lastName;
|
|
|
|
Utf8String phoneNumber;
|
2018-06-11 18:35:27 +00:00
|
|
|
Utf8String username;
|
2018-06-12 18:09:21 +00:00
|
|
|
|
|
|
|
MTPInputUser input;
|
|
|
|
};
|
|
|
|
|
|
|
|
User ParseUser(const MTPUser &data);
|
|
|
|
std::map<int32, User> ParseUsersList(const MTPVector<MTPUser> &data);
|
|
|
|
|
|
|
|
struct Chat {
|
|
|
|
int32 id = 0;
|
|
|
|
Utf8String title;
|
|
|
|
Utf8String username;
|
|
|
|
bool broadcast = false;
|
|
|
|
|
|
|
|
MTPInputPeer input;
|
|
|
|
};
|
|
|
|
|
|
|
|
Chat ParseChat(const MTPChat &data);
|
|
|
|
std::map<int32, Chat> ParseChatsList(const MTPVector<MTPChat> &data);
|
|
|
|
|
|
|
|
struct Peer {
|
|
|
|
PeerId id() const;
|
|
|
|
Utf8String name() const;
|
|
|
|
MTPInputPeer input() const;
|
|
|
|
|
|
|
|
const User *user() const;
|
|
|
|
const Chat *chat() const;
|
|
|
|
|
|
|
|
base::variant<User, Chat> data;
|
|
|
|
|
2018-06-11 18:35:27 +00:00
|
|
|
};
|
|
|
|
|
2018-06-12 18:09:21 +00:00
|
|
|
std::map<PeerId, Peer> ParsePeersLists(
|
|
|
|
const MTPVector<MTPUser> &users,
|
|
|
|
const MTPVector<MTPChat> &chats);
|
2018-06-11 18:35:27 +00:00
|
|
|
|
|
|
|
struct PersonalInfo {
|
|
|
|
User user;
|
|
|
|
Utf8String bio;
|
2018-06-09 11:51:22 +00:00
|
|
|
};
|
|
|
|
|
2018-06-11 18:35:27 +00:00
|
|
|
PersonalInfo ParsePersonalInfo(const MTPUserFull &data);
|
|
|
|
|
2018-06-09 11:51:22 +00:00
|
|
|
struct ContactsList {
|
2018-06-11 18:35:27 +00:00
|
|
|
std::vector<User> list;
|
2018-06-09 11:51:22 +00:00
|
|
|
};
|
|
|
|
|
2018-06-11 18:35:27 +00:00
|
|
|
ContactsList ParseContactsList(const MTPcontacts_Contacts &data);
|
2018-06-11 18:57:56 +00:00
|
|
|
std::vector<int> SortedContactsIndices(const ContactsList &data);
|
2018-06-11 18:35:27 +00:00
|
|
|
|
2018-06-09 11:51:22 +00:00
|
|
|
struct Session {
|
|
|
|
Utf8String platform;
|
|
|
|
Utf8String deviceModel;
|
|
|
|
Utf8String systemVersion;
|
|
|
|
Utf8String applicationName;
|
|
|
|
Utf8String applicationVersion;
|
2018-06-12 18:09:21 +00:00
|
|
|
TimeId created = 0;
|
|
|
|
TimeId lastActive = 0;
|
2018-06-09 11:51:22 +00:00
|
|
|
Utf8String ip;
|
|
|
|
Utf8String country;
|
|
|
|
Utf8String region;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct SessionsList {
|
|
|
|
std::vector<Session> list;
|
|
|
|
};
|
|
|
|
|
2018-06-11 18:57:56 +00:00
|
|
|
SessionsList ParseSessionsList(const MTPaccount_Authorizations &data);
|
|
|
|
|
2018-06-13 17:10:12 +00:00
|
|
|
struct Media {
|
|
|
|
base::optional_variant<Photo, Document> content;
|
|
|
|
TimeId ttl = 0;
|
|
|
|
|
|
|
|
File &file();
|
|
|
|
const File &file() const;
|
|
|
|
};
|
|
|
|
|
|
|
|
Media ParseMedia(
|
|
|
|
const MTPMessageMedia &data,
|
|
|
|
const QString &folder,
|
|
|
|
TimeId date);
|
|
|
|
|
|
|
|
struct ServiceAction {
|
|
|
|
base::optional_variant<> data;
|
|
|
|
};
|
|
|
|
|
|
|
|
ServiceAction ParseServiceAction(
|
|
|
|
const MTPMessageAction &data,
|
|
|
|
const QString &mediaFolder,
|
|
|
|
TimeId date);
|
|
|
|
|
2018-06-12 18:09:21 +00:00
|
|
|
struct Message {
|
|
|
|
int32 id = 0;
|
|
|
|
TimeId date = 0;
|
2018-06-13 17:10:12 +00:00
|
|
|
TimeId edited = 0;
|
|
|
|
int32 fromId = 0;
|
|
|
|
int32 viaBotId = 0;
|
|
|
|
int32 replyToMsgId = 0;
|
2018-06-13 13:12:36 +00:00
|
|
|
Utf8String text;
|
2018-06-13 17:10:12 +00:00
|
|
|
Media media;
|
|
|
|
ServiceAction action;
|
2018-06-13 13:12:36 +00:00
|
|
|
|
2018-06-09 11:51:22 +00:00
|
|
|
};
|
|
|
|
|
2018-06-13 17:10:12 +00:00
|
|
|
Message ParseMessage(const MTPMessage &data, const QString &mediaFolder);
|
2018-06-12 18:09:21 +00:00
|
|
|
std::map<int32, Message> ParseMessagesList(
|
2018-06-13 17:10:12 +00:00
|
|
|
const MTPVector<MTPMessage> &data,
|
|
|
|
const QString &mediaFolder);
|
2018-06-12 18:09:21 +00:00
|
|
|
|
|
|
|
struct DialogInfo {
|
2018-06-09 11:51:22 +00:00
|
|
|
enum class Type {
|
2018-06-12 18:09:21 +00:00
|
|
|
Unknown,
|
2018-06-09 11:51:22 +00:00
|
|
|
Personal,
|
2018-06-12 18:09:21 +00:00
|
|
|
PrivateGroup,
|
|
|
|
PublicGroup,
|
2018-06-09 11:51:22 +00:00
|
|
|
Channel,
|
|
|
|
};
|
2018-06-12 18:09:21 +00:00
|
|
|
Type type = Type::Unknown;
|
|
|
|
Utf8String name;
|
|
|
|
|
|
|
|
MTPInputPeer input;
|
|
|
|
int32 topMessageId = 0;
|
|
|
|
TimeId topMessageDate = 0;
|
2018-06-13 17:10:12 +00:00
|
|
|
|
|
|
|
QString relativePath;
|
|
|
|
|
2018-06-09 11:51:22 +00:00
|
|
|
};
|
|
|
|
|
2018-06-12 18:09:21 +00:00
|
|
|
struct DialogsInfo {
|
|
|
|
std::vector<DialogInfo> list;
|
2018-06-09 11:51:22 +00:00
|
|
|
};
|
|
|
|
|
2018-06-13 13:12:36 +00:00
|
|
|
DialogsInfo ParseDialogsInfo(const MTPmessages_Dialogs &data);
|
2018-06-12 18:09:21 +00:00
|
|
|
|
2018-06-09 11:51:22 +00:00
|
|
|
struct MessagesSlice {
|
|
|
|
std::vector<Message> list;
|
2018-06-13 13:12:36 +00:00
|
|
|
std::map<PeerId, Peer> peers;
|
2018-06-09 11:51:22 +00:00
|
|
|
};
|
|
|
|
|
2018-06-13 13:12:36 +00:00
|
|
|
MessagesSlice ParseMessagesSlice(
|
|
|
|
const MTPVector<MTPMessage> &data,
|
|
|
|
const MTPVector<MTPUser> &users,
|
2018-06-13 17:10:12 +00:00
|
|
|
const MTPVector<MTPChat> &chats,
|
|
|
|
const QString &mediaFolder);
|
2018-06-13 13:12:36 +00:00
|
|
|
|
2018-06-09 11:51:22 +00:00
|
|
|
Utf8String FormatPhoneNumber(const Utf8String &phoneNumber);
|
2018-06-11 18:57:56 +00:00
|
|
|
|
2018-06-11 18:35:27 +00:00
|
|
|
Utf8String FormatDateTime(
|
2018-06-12 18:09:21 +00:00
|
|
|
TimeId date,
|
2018-06-11 18:35:27 +00:00
|
|
|
QChar dateSeparator = QChar('.'),
|
|
|
|
QChar timeSeparator = QChar(':'),
|
|
|
|
QChar separator = QChar(' '));
|
2018-06-09 11:51:22 +00:00
|
|
|
|
|
|
|
} // namespace Data
|
|
|
|
} // namespace Export
|