diff --git a/src/chatlog/chatlog.cpp b/src/chatlog/chatlog.cpp index dbc7b6fbc..5d4d7f4d4 100644 --- a/src/chatlog/chatlog.cpp +++ b/src/chatlog/chatlog.cpp @@ -677,7 +677,7 @@ void ChatLog::forceRelayout() startResizeWorker(); } -void ChatLog::checkVisibility() +void ChatLog::checkVisibility(bool causedByScroll) { if (lines.empty()) return; @@ -717,12 +717,16 @@ void ChatLog::checkVisibility() if (!visibleLines.isEmpty()) { emit firstVisibleLineChanged(visibleLines.at(0)); } + + if (causedByScroll && lowerBound != lines.cend() && lowerBound->get()->row == 0) { + emit loadHistoryLower(); + } } void ChatLog::scrollContentsBy(int dx, int dy) { QGraphicsView::scrollContentsBy(dx, dy); - checkVisibility(); + checkVisibility(true); } void ChatLog::resizeEvent(QResizeEvent* ev) diff --git a/src/chatlog/chatlog.h b/src/chatlog/chatlog.h index 6975ceb9a..d7f5ed79c 100644 --- a/src/chatlog/chatlog.h +++ b/src/chatlog/chatlog.h @@ -72,6 +72,7 @@ signals: void selectionChanged(); void workerTimeoutFinished(); void firstVisibleLineChanged(const ChatLine::Ptr&); + void loadHistoryLower(); public slots: void forceRelayout(); @@ -94,7 +95,7 @@ protected: void reposition(int start, int end, qreal deltaY); void updateSceneRect(); - void checkVisibility(); + void checkVisibility(bool causedByScroll = false); void scrollToBottom(); void startResizeWorker(); diff --git a/src/widget/form/genericchatform.cpp b/src/widget/form/genericchatform.cpp index ffb4a4b7a..2967ec7d8 100644 --- a/src/widget/form/genericchatform.cpp +++ b/src/widget/form/genericchatform.cpp @@ -355,6 +355,7 @@ GenericChatForm::GenericChatForm(const Contact* contact, IChatLog& chatLog, connect(chatWidget, &ChatLog::customContextMenuRequested, this, &GenericChatForm::onChatContextMenuRequested); connect(chatWidget, &ChatLog::firstVisibleLineChanged, this, &GenericChatForm::updateShowDateInfo); + connect(chatWidget, &ChatLog::loadHistoryLower, this, &GenericChatForm::loadHistoryLower); connect(searchForm, &SearchForm::searchInBegin, this, &GenericChatForm::searchInBegin); 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) { const auto date = getTime(line); diff --git a/src/widget/form/genericchatform.h b/src/widget/form/genericchatform.h index af640e4dd..53de6b556 100644 --- a/src/widget/form/genericchatform.h +++ b/src/widget/form/genericchatform.h @@ -126,6 +126,8 @@ protected slots: void renderMessages(ChatLogIdx begin, ChatLogIdx end, std::function onCompletion = std::function()); + void loadHistoryLower(); + private: void retranslateUi(); void addSystemDateMessage(const QDate& date);