summaryrefslogtreecommitdiffstats
path: root/Telegram
diff options
context:
space:
mode:
authorJohn Preston <johnprestonmail@gmail.com>2018-07-08 19:26:39 +0300
committerJohn Preston <johnprestonmail@gmail.com>2018-07-10 12:18:41 +0300
commit0ef7503917ebee37085a4aab5bbbd8a14b97b223 (patch)
treeb66150930f3e5fc3398261f0b78c43df34cddedd /Telegram
parentcef50e5f525de9f701f9985c2b5c2719d1a65e10 (diff)
Improve export history pagination.
Diffstat (limited to 'Telegram')
-rw-r--r--Telegram/Resources/export_html/css/style.css5
-rw-r--r--Telegram/SourceFiles/export/output/export_output_html.cpp106
-rw-r--r--Telegram/SourceFiles/export/output/export_output_html.h2
3 files changed, 70 insertions, 43 deletions
diff --git a/Telegram/Resources/export_html/css/style.css b/Telegram/Resources/export_html/css/style.css
index 1e4bcfaced..05ae10c125 100644
--- a/Telegram/Resources/export_html/css/style.css
+++ b/Telegram/Resources/export_html/css/style.css
@@ -313,6 +313,11 @@ a.block_link:hover {
padding-top: 4px;
font-size: 13px;
}
+.pagination {
+ text-align: center;
+ padding: 20px;
+ font-size: 16px;
+}
.section.calls {
background-image: url(../images/section_calls.png);
diff --git a/Telegram/SourceFiles/export/output/export_output_html.cpp b/Telegram/SourceFiles/export/output/export_output_html.cpp
index b0b1dfad65..3836e46aae 100644
--- a/Telegram/SourceFiles/export/output/export_output_html.cpp
+++ b/Telegram/SourceFiles/export/output/export_output_html.cpp
@@ -18,7 +18,10 @@ namespace Export {
namespace Output {
namespace {
-constexpr auto kMessagesInFile = 1000;
+#ifndef _DEBUG
+#error test
+#endif
+constexpr auto kMessagesInFile = 50;
constexpr auto kPersonalUserpicSize = 90;
constexpr auto kEntryUserpicSize = 48;
constexpr auto kServiceMessagePhotoSize = 60;
@@ -1973,6 +1976,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 + messagesFile(0));
+ _chatFileEmpty = true;
_messagesCount = 0;
_dateMessageId = 0;
_lastMessageInfo = nullptr;
@@ -1980,38 +1984,43 @@ Result HtmlWriter::writeChatStart(const Data::DialogInfo &data) {
return Result::Success();
}
+Result HtmlWriter::writeChatOpening(int index) {
+ const auto name = (_dialog.name.isEmpty()
+ && _dialog.lastName.isEmpty())
+ ? QByteArray("Deleted Account")
+ : (_dialog.name + ' ' + _dialog.lastName);
+ auto block = _chat->pushHeader(
+ name,
+ _dialogsRelativePath);
+ block.append(_chat->pushDiv("page_body chat_page"));
+ block.append(_chat->pushDiv("history"));
+ if (index > 0) {
+ const auto previousPath = messagesFile(index - 1);
+ block.append(_chat->pushTag("a", {
+ { "class", "pagination block_link" },
+ { "href", previousPath.toUtf8() }
+ }));
+ block.append("Previous messages part");
+ block.append(_chat->popTag());
+ }
+ return _chat->writeBlock(block);
+}
+
Result HtmlWriter::writeChatSlice(const Data::MessagesSlice &data) {
Expects(_chat != nullptr);
Expects(!data.list.empty());
- if (_chat->empty()) {
- const auto name = (_dialog.name.isEmpty()
- && _dialog.lastName.isEmpty())
- ? QByteArray("Deleted Account")
- : (_dialog.name + ' ' + _dialog.lastName);
- auto block = _chat->pushHeader(
- name,
- _dialogsRelativePath);
- block.append(_chat->pushDiv("page_body chat_page"));
- block.append(_chat->pushDiv("history"));
- if (const auto result = _chat->writeBlock(block); !result) {
- return result;
- }
- }
-
- 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 oldIndex = (_messagesCount / kMessagesInFile);
auto previous = _lastMessageInfo.get();
- auto saved = MessageInfo();
+ auto saved = base::optional<MessageInfo>();
auto block = QByteArray();
for (const auto &message : data.list) {
+ if (_chatFileEmpty) {
+ if (const auto result = writeChatOpening(oldIndex); !result) {
+ return result;
+ }
+ _chatFileEmpty = false;
+ }
const auto date = message.date;
if (DisplayDate(date, previous ? previous->date : 0)) {
block.append(_chat->pushServiceMessage(
@@ -2028,10 +2037,29 @@ Result HtmlWriter::writeChatSlice(const Data::MessagesSlice &data) {
data.peers,
_environment.internalLinksDomain);
block.append(content);
- saved = info;
- previous = &saved;
+
+ ++_messagesCount;
+ const auto newIndex = (_messagesCount / kMessagesInFile);
+ if (oldIndex != newIndex) {
+ if (const auto result = _chat->writeBlock(block); !result) {
+ return result;
+ } else if (const auto next = switchToNextChatFile(newIndex)) {
+ block = QByteArray();
+ _lastMessageInfo = nullptr;
+ previous = nullptr;
+ saved = base::none;
+ oldIndex = newIndex;
+ } else {
+ return next;
+ }
+ } else {
+ saved = info;
+ previous = &*saved;
+ }
+ }
+ if (saved) {
+ _lastMessageInfo = std::make_unique<MessageInfo>(*saved);
}
- _lastMessageInfo = std::make_unique<MessageInfo>(saved);
return _chat->writeBlock(block);
}
@@ -2138,7 +2166,7 @@ void HtmlWriter::pushSection(
Result HtmlWriter::writeSections() {
Expects(_summary != nullptr);
- if (!_haveSections && _summaryNeedDivider) {
+ if (!_haveSections) {
auto block = _summary->pushDiv(
_summaryNeedDivider ? "sections with_divider" : "sections");
if (const auto result = _summary->writeBlock(block); !result) {
@@ -2167,27 +2195,19 @@ Result HtmlWriter::switchToNextChatFile(int index) {
const auto nextPath = messagesFile(index);
auto next = _chat->pushTag("a", {
- { "class", "pagination" },
+ { "class", "pagination block_link" },
{ "href", nextPath.toUtf8() }
});
next.append("Next messages part");
next.append(_chat->popTag());
if (const auto result = _chat->writeBlock(next); !result) {
return result;
+ } else if (const auto end = _chat->close(); !end) {
+ return end;
}
_chat = fileWithRelativePath(_dialog.relativePath + nextPath);
- auto block = _chat->pushHeader(
- _dialog.name + ' ' + _dialog.lastName,
- _dialogsRelativePath);
- block.append(_chat->pushDiv("page_body chat_page"));
- block.append(_chat->pushDiv("history"));
- block.append(_chat->pushTag("a", {
- { "class", "pagination" },
- { "href", nextPath.toUtf8() }
- }));
- block.append("Previous messages part");
- block.append(_chat->popTag());
- return _chat->writeBlock(block);
+ _chatFileEmpty = true;
+ return Result::Success();
}
Result HtmlWriter::finish() {
diff --git a/Telegram/SourceFiles/export/output/export_output_html.h b/Telegram/SourceFiles/export/output/export_output_html.h
index 4614ae53e2..75e75ccade 100644
--- a/Telegram/SourceFiles/export/output/export_output_html.h
+++ b/Telegram/SourceFiles/export/output/export_output_html.h
@@ -112,6 +112,7 @@ private:
const QByteArray &about,
const QString &fileName);
[[nodiscard]] Result writeChatStart(const Data::DialogInfo &data);
+ [[nodiscard]] Result writeChatOpening(int index);
[[nodiscard]] Result writeChatSlice(const Data::MessagesSlice &data);
[[nodiscard]] Result writeChatEnd();
[[nodiscard]] Result writeChatsEnd();
@@ -162,6 +163,7 @@ private:
int _dateMessageId = 0;
std::unique_ptr<Wrap> _chats;
std::unique_ptr<Wrap> _chat;
+ bool _chatFileEmpty = false;
};