mirror of
https://github.com/vale981/tdesktop
synced 2025-03-07 02:31:41 -05:00
Split messages.html by 1000 messages.
This commit is contained in:
parent
97d27fe869
commit
1ae3af0e80
2 changed files with 33 additions and 1 deletions
|
@ -17,6 +17,8 @@ namespace Export {
|
||||||
namespace Output {
|
namespace Output {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
constexpr auto kMessagesInFile = 1000;
|
||||||
|
|
||||||
const auto kLineBreak = QByteArrayLiteral("<br>");
|
const auto kLineBreak = QByteArrayLiteral("<br>");
|
||||||
|
|
||||||
QByteArray SerializeString(const QByteArray &value) {
|
QByteArray SerializeString(const QByteArray &value) {
|
||||||
|
@ -1164,7 +1166,7 @@ Result HtmlWriter::writeChatStart(const Data::DialogInfo &data) {
|
||||||
|
|
||||||
const auto digits = Data::NumberToString(_dialogsCount - 1).size();
|
const auto digits = Data::NumberToString(_dialogsCount - 1).size();
|
||||||
const auto number = Data::NumberToString(++_dialogIndex, digits, '0');
|
const auto number = Data::NumberToString(++_dialogIndex, digits, '0');
|
||||||
_chat = fileWithRelativePath(data.relativePath + "messages.html");
|
_chat = fileWithRelativePath(data.relativePath + messagesFile(0));
|
||||||
_messagesCount = 0;
|
_messagesCount = 0;
|
||||||
_dialog = data;
|
_dialog = data;
|
||||||
return Result::Success();
|
return Result::Success();
|
||||||
|
@ -1174,7 +1176,15 @@ Result HtmlWriter::writeChatSlice(const Data::MessagesSlice &data) {
|
||||||
Expects(_chat != nullptr);
|
Expects(_chat != nullptr);
|
||||||
Expects(!data.list.empty());
|
Expects(!data.list.empty());
|
||||||
|
|
||||||
|
const auto wasIndex = (_messagesCount / kMessagesInFile);
|
||||||
_messagesCount += data.list.size();
|
_messagesCount += data.list.size();
|
||||||
|
const auto nowIndex = (_messagesCount / kMessagesInFile);
|
||||||
|
if (nowIndex != wasIndex) {
|
||||||
|
if (const auto result = switchToNextChatFile(nowIndex); !result) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
auto list = std::vector<QByteArray>();
|
auto list = std::vector<QByteArray>();
|
||||||
list.reserve(data.list.size());
|
list.reserve(data.list.size());
|
||||||
for (const auto &message : data.list) {
|
for (const auto &message : data.list) {
|
||||||
|
@ -1263,6 +1273,20 @@ Result HtmlWriter::writeChatsEnd() {
|
||||||
return Result::Success();
|
return Result::Success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Result HtmlWriter::switchToNextChatFile(int index) {
|
||||||
|
Expects(_chat != nullptr);
|
||||||
|
|
||||||
|
const auto nextPath = messagesFile(index);
|
||||||
|
const auto link = kLineBreak + "<a href=\""
|
||||||
|
+ nextPath.toUtf8()
|
||||||
|
+ "\">Next messages part</a>";
|
||||||
|
if (const auto result = _chat->writeBlock(link); !result) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
_chat = fileWithRelativePath(_dialog.relativePath + nextPath);
|
||||||
|
return Result::Success();
|
||||||
|
}
|
||||||
|
|
||||||
Result HtmlWriter::finish() {
|
Result HtmlWriter::finish() {
|
||||||
Expects(_summary != nullptr);
|
Expects(_summary != nullptr);
|
||||||
|
|
||||||
|
@ -1290,6 +1314,12 @@ QString HtmlWriter::pathWithRelativePath(const QString &path) const {
|
||||||
return _settings.path + path;
|
return _settings.path + path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString HtmlWriter::messagesFile(int index) const {
|
||||||
|
return "messages"
|
||||||
|
+ (index > 0 ? QString::number(index + 1) : QString())
|
||||||
|
+ ".html";
|
||||||
|
}
|
||||||
|
|
||||||
std::unique_ptr<HtmlWriter::Wrap> HtmlWriter::fileWithRelativePath(
|
std::unique_ptr<HtmlWriter::Wrap> HtmlWriter::fileWithRelativePath(
|
||||||
const QString &path) const {
|
const QString &path) const {
|
||||||
return std::make_unique<Wrap>(
|
return std::make_unique<Wrap>(
|
||||||
|
|
|
@ -68,6 +68,7 @@ private:
|
||||||
QString mainFileRelativePath() const;
|
QString mainFileRelativePath() const;
|
||||||
QString pathWithRelativePath(const QString &path) const;
|
QString pathWithRelativePath(const QString &path) const;
|
||||||
std::unique_ptr<Wrap> fileWithRelativePath(const QString &path) const;
|
std::unique_ptr<Wrap> fileWithRelativePath(const QString &path) const;
|
||||||
|
QString messagesFile(int index) const;
|
||||||
|
|
||||||
Result writeSavedContacts(const Data::ContactsList &data);
|
Result writeSavedContacts(const Data::ContactsList &data);
|
||||||
Result writeFrequentContacts(const Data::ContactsList &data);
|
Result writeFrequentContacts(const Data::ContactsList &data);
|
||||||
|
@ -84,6 +85,7 @@ private:
|
||||||
Result writeChatSlice(const Data::MessagesSlice &data);
|
Result writeChatSlice(const Data::MessagesSlice &data);
|
||||||
Result writeChatEnd();
|
Result writeChatEnd();
|
||||||
Result writeChatsEnd();
|
Result writeChatsEnd();
|
||||||
|
Result switchToNextChatFile(int index);
|
||||||
|
|
||||||
Settings _settings;
|
Settings _settings;
|
||||||
Environment _environment;
|
Environment _environment;
|
||||||
|
|
Loading…
Add table
Reference in a new issue