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 after date

This commit is contained in:
TriKriSta 2019-05-19 23:52:36 +03:00
parent fb2957c5ee
commit b705ac8060
4 changed files with 42 additions and 3 deletions

View File

@ -382,6 +382,22 @@ void ChatLog::insertChatlineAtBottom(ChatLine::Ptr l)
updateTypingNotification();
}
void ChatLog::insertChatlineAtBottom(const QList<ChatLine::Ptr>& newLines)
{
if (newLines.isEmpty())
return;
for (ChatLine::Ptr l : newLines) {
l->setRow(lines.size());
l->addToScene(scene);
l->visibilityChanged(false);
lines.append(l);
}
layout(lines.last()->getRow(), lines.size(), useableWidth());
startResizeWorker();
}
void ChatLog::insertChatlineOnTop(ChatLine::Ptr l)
{
if (!l.get())
@ -718,8 +734,12 @@ void ChatLog::checkVisibility(bool causedByScroll)
emit firstVisibleLineChanged(visibleLines.at(0));
}
if (causedByScroll && lowerBound != lines.cend() && lowerBound->get()->row == 0) {
emit loadHistoryLower();
if (causedByScroll) {
if (lowerBound != lines.cend() && lowerBound->get()->row == 0) {
emit loadHistoryLower();
} else if (upperBound != lines.cend() && upperBound->get()->row >= lines.size() - 10) {
emit loadHistoryUpper();
}
}
}

View File

@ -43,6 +43,7 @@ public:
virtual ~ChatLog();
void insertChatlineAtBottom(ChatLine::Ptr l);
void insertChatlineAtBottom(const QList<ChatLine::Ptr>& newLines);
void insertChatlineOnTop(ChatLine::Ptr l);
void insertChatlinesOnTop(const QList<ChatLine::Ptr>& newLines);
void clearSelection();
@ -73,6 +74,7 @@ signals:
void workerTimeoutFinished();
void firstVisibleLineChanged(const ChatLine::Ptr&);
void loadHistoryLower();
void loadHistoryUpper();
public slots:
void forceRelayout();

View File

@ -356,6 +356,7 @@ GenericChatForm::GenericChatForm(const Contact* contact, IChatLog& chatLog,
&GenericChatForm::onChatContextMenuRequested);
connect(chatWidget, &ChatLog::firstVisibleLineChanged, this, &GenericChatForm::updateShowDateInfo);
connect(chatWidget, &ChatLog::loadHistoryLower, this, &GenericChatForm::loadHistoryLower);
connect(chatWidget, &ChatLog::loadHistoryUpper, this, &GenericChatForm::loadHistoryUpper);
connect(searchForm, &SearchForm::searchInBegin, this, &GenericChatForm::searchInBegin);
connect(searchForm, &SearchForm::searchUp, this, &GenericChatForm::onSearchUp);
@ -812,7 +813,10 @@ void GenericChatForm::onLoadHistory()
if (dlg.exec()) {
QDateTime time = dlg.getFromDate();
auto idx = firstItemAfterDate(dlg.getFromDate().date(), chatLog);
renderMessages(idx, chatLog.getNextIdx());
auto end = ChatLogIdx(idx.get() + 100);
chatWidget->clear();
messages.clear();
renderMessages(idx, end);
}
}
@ -993,6 +997,18 @@ void GenericChatForm::loadHistoryLower()
renderMessages(begin, chatLog.getNextIdx());
}
void GenericChatForm::loadHistoryUpper()
{
auto begin = messages.end()->first;
int add = 100;
if (begin.get() + 100 > chatLog.getNextIdx().get()) {
add = chatLog.getNextIdx().get() - (begin.get() + 100);
}
auto end = ChatLogIdx(begin.get() + add);
renderMessages(begin, end);
}
void GenericChatForm::updateShowDateInfo(const ChatLine::Ptr& line)
{
const auto date = getTime(line);

View File

@ -127,6 +127,7 @@ protected slots:
std::function<void(void)> onCompletion = std::function<void(void)>());
void loadHistoryLower();
void loadHistoryUpper();
private:
void retranslateUi();