-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use abstract export writer for different formats.
- Loading branch information
1 parent
c587c01
commit 0a1a5ed
Showing
17 changed files
with
927 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
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/data/export_data_types.h" | ||
|
||
namespace App { // Hackish.. | ||
QString formatPhone(QString phone); | ||
} // namespace App | ||
|
||
namespace Export { | ||
namespace Data { | ||
|
||
Utf8String ParseString(const MTPstring &data) { | ||
return data.v; | ||
} | ||
|
||
PersonalInfo ParsePersonalInfo(const MTPUserFull &data) { | ||
Expects(data.type() == mtpc_userFull); | ||
|
||
const auto &fields = data.c_userFull(); | ||
const auto &small = fields.vuser.c_user(); | ||
auto result = PersonalInfo(); | ||
if (small.has_first_name()) { | ||
result.firstName = ParseString(small.vfirst_name); | ||
} | ||
if (small.has_last_name()) { | ||
result.lastName = ParseString(small.vlast_name); | ||
} | ||
if (small.has_phone()) { | ||
result.phoneNumber = ParseString(small.vphone); | ||
} | ||
if (small.has_username()) { | ||
result.username = ParseString(small.vusername); | ||
} | ||
if (fields.has_about()) { | ||
result.bio = ParseString(fields.vabout); | ||
} | ||
return result; | ||
} | ||
|
||
UserpicsSlice ParseUserpicsSlice(const MTPVector<MTPPhoto> &data) { | ||
const auto &list = data.v; | ||
auto result = UserpicsSlice(); | ||
result.list.reserve(list.size()); | ||
for (const auto &photo : list) { | ||
switch (photo.type()) { | ||
case mtpc_photo: { | ||
const auto &fields = photo.c_photo(); | ||
auto userpic = Userpic(); | ||
userpic.id = fields.vid.v; | ||
userpic.date = QDateTime::fromTime_t(fields.vdate.v); | ||
userpic.image = File{ "(not saved)" }; | ||
result.list.push_back(std::move(userpic)); | ||
} break; | ||
|
||
case mtpc_photoEmpty: { | ||
const auto &fields = photo.c_photoEmpty(); | ||
auto userpic = Userpic(); | ||
userpic.id = fields.vid.v; | ||
result.list.push_back(std::move(userpic)); | ||
} break; | ||
|
||
default: Unexpected("Photo type in ParseUserpicsSlice."); | ||
} | ||
} | ||
return result; | ||
} | ||
|
||
Utf8String FormatPhoneNumber(const Utf8String &phoneNumber) { | ||
return phoneNumber.isEmpty() | ||
? Utf8String() | ||
: App::formatPhone(QString::fromUtf8(phoneNumber)).toUtf8(); | ||
} | ||
|
||
} // namespace Data | ||
} // namespace Export |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/* | ||
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" | ||
|
||
#include <QtCore/QDateTime> | ||
#include <QtCore/QString> | ||
#include <QtCore/QByteArray> | ||
#include <vector> | ||
|
||
namespace Export { | ||
namespace Data { | ||
|
||
using Utf8String = QByteArray; | ||
|
||
Utf8String ParseString(const MTPstring &data); | ||
|
||
template <typename Type> | ||
inline auto NumberToString(Type value) | ||
-> std::enable_if_t<std::is_arithmetic_v<Type>, Utf8String> { | ||
const auto result = std::to_string(value); | ||
return QByteArray(result.data(), int(result.size())); | ||
} | ||
|
||
struct PersonalInfo { | ||
Utf8String firstName; | ||
Utf8String lastName; | ||
Utf8String phoneNumber; | ||
Utf8String username; | ||
Utf8String bio; | ||
}; | ||
|
||
PersonalInfo ParsePersonalInfo(const MTPUserFull &data); | ||
|
||
struct UserpicsInfo { | ||
int count = 0; | ||
}; | ||
|
||
struct File { | ||
QString relativePath; | ||
}; | ||
|
||
struct Userpic { | ||
uint64 id = 0; | ||
QDateTime date; | ||
File image; | ||
}; | ||
|
||
struct UserpicsSlice { | ||
std::vector<Userpic> list; | ||
}; | ||
|
||
UserpicsSlice ParseUserpicsSlice(const MTPVector<MTPPhoto> &data); | ||
|
||
struct Contact { | ||
Utf8String firstName; | ||
Utf8String lastName; | ||
Utf8String phoneNumber; | ||
}; | ||
|
||
struct ContactsList { | ||
std::vector<Contact> list; | ||
}; | ||
|
||
struct Session { | ||
Utf8String platform; | ||
Utf8String deviceModel; | ||
Utf8String systemVersion; | ||
Utf8String applicationName; | ||
Utf8String applicationVersion; | ||
QDateTime created; | ||
QDateTime lastActive; | ||
Utf8String ip; | ||
Utf8String country; | ||
Utf8String region; | ||
}; | ||
|
||
struct SessionsList { | ||
std::vector<Session> list; | ||
}; | ||
|
||
struct ChatsInfo { | ||
int count = 0; | ||
}; | ||
|
||
struct ChatInfo { | ||
enum class Type { | ||
Personal, | ||
Group, | ||
Channel, | ||
}; | ||
Type type = Type::Personal; | ||
QString name; | ||
}; | ||
|
||
struct Message { | ||
int id = 0; | ||
}; | ||
|
||
struct MessagesSlice { | ||
std::vector<Message> list; | ||
}; | ||
|
||
Utf8String FormatPhoneNumber(const Utf8String &phoneNumber); | ||
|
||
} // namespace Data | ||
} // namespace Export |
Oops, something went wrong.