diff --git a/Telegram/SourceFiles/export/output/export_output_html.cpp b/Telegram/SourceFiles/export/output/export_output_html.cpp
index 26528fa28..9a795f42f 100644
--- a/Telegram/SourceFiles/export/output/export_output_html.cpp
+++ b/Telegram/SourceFiles/export/output/export_output_html.cpp
@@ -17,6 +17,8 @@ namespace Export {
namespace Output {
namespace {
+constexpr auto kMessagesInFile = 1000;
+
const auto kLineBreak = QByteArrayLiteral("
");
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 number = Data::NumberToString(++_dialogIndex, digits, '0');
- _chat = fileWithRelativePath(data.relativePath + "messages.html");
+ _chat = fileWithRelativePath(data.relativePath + messagesFile(0));
_messagesCount = 0;
_dialog = data;
return Result::Success();
@@ -1174,7 +1176,15 @@ Result HtmlWriter::writeChatSlice(const Data::MessagesSlice &data) {
Expects(_chat != nullptr);
Expects(!data.list.empty());
+ const auto wasIndex = (_messagesCount / kMessagesInFile);
_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();
list.reserve(data.list.size());
for (const auto &message : data.list) {
@@ -1263,6 +1273,20 @@ Result HtmlWriter::writeChatsEnd() {
return Result::Success();
}
+Result HtmlWriter::switchToNextChatFile(int index) {
+ Expects(_chat != nullptr);
+
+ const auto nextPath = messagesFile(index);
+ const auto link = kLineBreak + "Next messages part";
+ if (const auto result = _chat->writeBlock(link); !result) {
+ return result;
+ }
+ _chat = fileWithRelativePath(_dialog.relativePath + nextPath);
+ return Result::Success();
+}
+
Result HtmlWriter::finish() {
Expects(_summary != nullptr);
@@ -1290,6 +1314,12 @@ QString HtmlWriter::pathWithRelativePath(const QString &path) const {
return _settings.path + path;
}
+QString HtmlWriter::messagesFile(int index) const {
+ return "messages"
+ + (index > 0 ? QString::number(index + 1) : QString())
+ + ".html";
+}
+
std::unique_ptr HtmlWriter::fileWithRelativePath(
const QString &path) const {
return std::make_unique(
diff --git a/Telegram/SourceFiles/export/output/export_output_html.h b/Telegram/SourceFiles/export/output/export_output_html.h
index 28d1b0fe4..644957605 100644
--- a/Telegram/SourceFiles/export/output/export_output_html.h
+++ b/Telegram/SourceFiles/export/output/export_output_html.h
@@ -68,6 +68,7 @@ private:
QString mainFileRelativePath() const;
QString pathWithRelativePath(const QString &path) const;
std::unique_ptr fileWithRelativePath(const QString &path) const;
+ QString messagesFile(int index) const;
Result writeSavedContacts(const Data::ContactsList &data);
Result writeFrequentContacts(const Data::ContactsList &data);
@@ -84,6 +85,7 @@ private:
Result writeChatSlice(const Data::MessagesSlice &data);
Result writeChatEnd();
Result writeChatsEnd();
+ Result switchToNextChatFile(int index);
Settings _settings;
Environment _environment;