1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

feat: load messages from the database before date

This commit is contained in:
TriKriSta 2019-05-19 17:30:44 +03:00
parent 6abf766359
commit fb2957c5ee
4 changed files with 24 additions and 3 deletions

View File

@ -677,7 +677,7 @@ void ChatLog::forceRelayout()
startResizeWorker(); startResizeWorker();
} }
void ChatLog::checkVisibility() void ChatLog::checkVisibility(bool causedByScroll)
{ {
if (lines.empty()) if (lines.empty())
return; return;
@ -717,12 +717,16 @@ void ChatLog::checkVisibility()
if (!visibleLines.isEmpty()) { if (!visibleLines.isEmpty()) {
emit firstVisibleLineChanged(visibleLines.at(0)); emit firstVisibleLineChanged(visibleLines.at(0));
} }
if (causedByScroll && lowerBound != lines.cend() && lowerBound->get()->row == 0) {
emit loadHistoryLower();
}
} }
void ChatLog::scrollContentsBy(int dx, int dy) void ChatLog::scrollContentsBy(int dx, int dy)
{ {
QGraphicsView::scrollContentsBy(dx, dy); QGraphicsView::scrollContentsBy(dx, dy);
checkVisibility(); checkVisibility(true);
} }
void ChatLog::resizeEvent(QResizeEvent* ev) void ChatLog::resizeEvent(QResizeEvent* ev)

View File

@ -72,6 +72,7 @@ signals:
void selectionChanged(); void selectionChanged();
void workerTimeoutFinished(); void workerTimeoutFinished();
void firstVisibleLineChanged(const ChatLine::Ptr&); void firstVisibleLineChanged(const ChatLine::Ptr&);
void loadHistoryLower();
public slots: public slots:
void forceRelayout(); void forceRelayout();
@ -94,7 +95,7 @@ protected:
void reposition(int start, int end, qreal deltaY); void reposition(int start, int end, qreal deltaY);
void updateSceneRect(); void updateSceneRect();
void checkVisibility(); void checkVisibility(bool causedByScroll = false);
void scrollToBottom(); void scrollToBottom();
void startResizeWorker(); void startResizeWorker();

View File

@ -355,6 +355,7 @@ GenericChatForm::GenericChatForm(const Contact* contact, IChatLog& chatLog,
connect(chatWidget, &ChatLog::customContextMenuRequested, this, connect(chatWidget, &ChatLog::customContextMenuRequested, this,
&GenericChatForm::onChatContextMenuRequested); &GenericChatForm::onChatContextMenuRequested);
connect(chatWidget, &ChatLog::firstVisibleLineChanged, this, &GenericChatForm::updateShowDateInfo); connect(chatWidget, &ChatLog::firstVisibleLineChanged, this, &GenericChatForm::updateShowDateInfo);
connect(chatWidget, &ChatLog::loadHistoryLower, this, &GenericChatForm::loadHistoryLower);
connect(searchForm, &SearchForm::searchInBegin, this, &GenericChatForm::searchInBegin); connect(searchForm, &SearchForm::searchInBegin, this, &GenericChatForm::searchInBegin);
connect(searchForm, &SearchForm::searchUp, this, &GenericChatForm::onSearchUp); connect(searchForm, &SearchForm::searchUp, this, &GenericChatForm::onSearchUp);
@ -979,6 +980,19 @@ void GenericChatForm::renderMessages(ChatLogIdx begin, ChatLogIdx end,
} }
} }
void GenericChatForm::loadHistoryLower()
{
auto begin = messages.begin()->first;
if (begin.get() > 100) {
begin = ChatLogIdx(begin.get() - 100);
} else {
begin = ChatLogIdx(0);
}
renderMessages(begin, chatLog.getNextIdx());
}
void GenericChatForm::updateShowDateInfo(const ChatLine::Ptr& line) void GenericChatForm::updateShowDateInfo(const ChatLine::Ptr& line)
{ {
const auto date = getTime(line); const auto date = getTime(line);

View File

@ -126,6 +126,8 @@ protected slots:
void renderMessages(ChatLogIdx begin, ChatLogIdx end, void renderMessages(ChatLogIdx begin, ChatLogIdx end,
std::function<void(void)> onCompletion = std::function<void(void)>()); std::function<void(void)> onCompletion = std::function<void(void)>());
void loadHistoryLower();
private: private:
void retranslateUi(); void retranslateUi();
void addSystemDateMessage(const QDate& date); void addSystemDateMessage(const QDate& date);