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

revert(chatlog): "optimize load messages during the search"

This reverts commit 6de307e6b9.
This commit is contained in:
Anthony Bilinski 2020-04-04 22:45:46 -07:00
parent 306bbb424e
commit 83d5863bbe
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C

View File

@ -680,8 +680,8 @@ void GenericChatForm::loadHistoryTo(const QDateTime &time)
}
if (begin != end) {
if (searchResult.found == true && searchResult.pos.logIdx == end) {
renderMessages(begin, end, [this]{enableSearchText();});
if (searchResult.found == true) {
renderMessages(begin, searchResult.pos.logIdx, [this]{enableSearchText();});
} else {
renderMessages(begin, end);
}
@ -961,6 +961,12 @@ void GenericChatForm::searchInBegin(const QString& phrase, const ParameterSearch
goToCurrentDate();
}
if (!parameter.time.isNull()) {
LoadHistoryDialog::LoadType type = (parameter.period == PeriodSearch::BeforeDate)
? LoadHistoryDialog::to : LoadHistoryDialog::from;
loadHistory(parameter.time, type);
}
bool bForwardSearch = false;
switch (parameter.period) {
case PeriodSearch::WithTheFirst: {
@ -1006,6 +1012,12 @@ void GenericChatForm::onSearchUp(const QString& phrase, const ParameterSearch& p
void GenericChatForm::onSearchDown(const QString& phrase, const ParameterSearch& parameter)
{
auto result = chatLog.searchForward(searchResult.pos, phrase, parameter);
if (result.found && result.pos.logIdx.get() > messages.end()->first.get()) {
const auto dt = chatLog.at(result.pos.logIdx).getTimestamp();
loadHistory(dt, LoadHistoryDialog::from);
}
handleSearchResult(result, SearchDirection::Down);
}
@ -1020,56 +1032,9 @@ void GenericChatForm::handleSearchResult(SearchResult result, SearchDirection di
searchResult = result;
auto searchIdx = result.pos.logIdx;
auto const firstRenderedIdx = (messages.empty()) ? chatLog.getNextIdx() : messages.begin()->first;
auto firstRenderedIdx = messages.begin()->first;
auto endRenderedIdx = messages.rbegin()->first;
if (direction == SearchDirection::Up) {
if (searchIdx.get() < firstRenderedIdx.get()) {
if (searchIdx.get() > DEF_NUM_MSG_TO_LOAD / 2) {
firstRenderedIdx = ChatLogIdx(searchIdx.get() - DEF_NUM_MSG_TO_LOAD / 2);
} else {
firstRenderedIdx = ChatLogIdx(0);
}
}
if (endRenderedIdx.get() - firstRenderedIdx.get() > DEF_NUM_MSG_TO_LOAD) {
endRenderedIdx = ChatLogIdx(firstRenderedIdx.get() + DEF_NUM_MSG_TO_LOAD);
}
} else {
if (searchIdx.get() < firstRenderedIdx.get()) {
firstRenderedIdx = searchIdx;
}
if (firstRenderedIdx == searchIdx || searchIdx.get() > endRenderedIdx.get()) {
if (searchIdx.get() + DEF_NUM_MSG_TO_LOAD > chatLog.getNextIdx().get()) {
endRenderedIdx = chatLog.getNextIdx();
} else {
endRenderedIdx = ChatLogIdx(searchIdx.get() + DEF_NUM_MSG_TO_LOAD);
}
}
if (endRenderedIdx.get() - firstRenderedIdx.get() > DEF_NUM_MSG_TO_LOAD) {
if (endRenderedIdx.get() > DEF_NUM_MSG_TO_LOAD) {
firstRenderedIdx = ChatLogIdx(endRenderedIdx.get() - DEF_NUM_MSG_TO_LOAD);
} else {
firstRenderedIdx = ChatLogIdx(0);
}
}
}
if (!messages.empty() && (firstRenderedIdx.get() < messages.begin()->first.get()
|| endRenderedIdx.get() > messages.rbegin()->first.get())) {
chatWidget->clear();
messages.clear();
auto mediator = endRenderedIdx;
endRenderedIdx = firstRenderedIdx;
firstRenderedIdx = mediator;
}
renderMessages(endRenderedIdx, firstRenderedIdx, [this]{enableSearchText();});
renderMessages(searchResult.pos.logIdx, firstRenderedIdx, [this]{enableSearchText();});
}
void GenericChatForm::renderMessage(ChatLogIdx idx)