mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
refactor: optimize load messages during the search
This commit is contained in:
parent
a6a0481ddc
commit
e2efe443fe
|
@ -685,8 +685,8 @@ void GenericChatForm::loadHistoryTo(const QDateTime &time)
|
|||
}
|
||||
|
||||
if (begin != end) {
|
||||
if (searchResult.found == true) {
|
||||
renderMessages(begin, searchResult.pos.logIdx, [this]{enableSearchText();});
|
||||
if (searchResult.found == true && searchResult.pos.logIdx == end) {
|
||||
renderMessages(begin, end, [this]{enableSearchText();});
|
||||
} else {
|
||||
renderMessages(begin, end);
|
||||
}
|
||||
|
@ -967,12 +967,6 @@ 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: {
|
||||
|
@ -1018,12 +1012,6 @@ 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);
|
||||
}
|
||||
|
||||
|
@ -1038,9 +1026,56 @@ void GenericChatForm::handleSearchResult(SearchResult result, SearchDirection di
|
|||
|
||||
searchResult = result;
|
||||
|
||||
auto const firstRenderedIdx = (messages.empty()) ? chatLog.getNextIdx() : messages.begin()->first;
|
||||
auto searchIdx = result.pos.logIdx;
|
||||
|
||||
renderMessages(searchResult.pos.logIdx, firstRenderedIdx, [this]{enableSearchText();});
|
||||
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();});
|
||||
}
|
||||
|
||||
void GenericChatForm::renderMessage(ChatLogIdx idx)
|
||||
|
|
Loading…
Reference in New Issue
Block a user