From 5da1e4b9a88db60048147fbf63af09607326cffd Mon Sep 17 00:00:00 2001 From: Anthony Bilinski Date: Sat, 4 Apr 2020 22:32:52 -0700 Subject: [PATCH 01/20] revert(chatlog): "enable dynamic view range in chatlog with history disabled" This reverts commit a7f349595696b3292897ac72b5cffb05b7300eda. --- src/chatlog/chatlog.cpp | 8 ++++---- src/chatlog/chatlog.h | 3 ++- src/widget/form/genericchatform.cpp | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/chatlog/chatlog.cpp b/src/chatlog/chatlog.cpp index 067c34dca..e73699f1a 100644 --- a/src/chatlog/chatlog.cpp +++ b/src/chatlog/chatlog.cpp @@ -52,8 +52,8 @@ T clamp(T x, T min, T max) return x; } -ChatLog::ChatLog(QWidget* parent) - : QGraphicsView(parent) +ChatLog::ChatLog(const bool canRemove, QWidget* parent) + : QGraphicsView(parent), canRemove(canRemove) { // Create the scene busyScene = new QGraphicsScene(this); @@ -394,7 +394,7 @@ void ChatLog::insertChatlineAtBottom(const QList& newLines) if (newLines.isEmpty()) return; - if (lines.size() + DEF_NUM_MSG_TO_LOAD >= maxMessages) { + if (canRemove && lines.size() + DEF_NUM_MSG_TO_LOAD >= maxMessages) { removeFirsts(DEF_NUM_MSG_TO_LOAD); } @@ -444,7 +444,7 @@ void ChatLog::insertChatlinesOnTop(const QList& newLines) combLines.push_back(l); } - if (lines.size() + DEF_NUM_MSG_TO_LOAD >= maxMessages) { + if (canRemove && lines.size() + DEF_NUM_MSG_TO_LOAD >= maxMessages) { removeLasts(DEF_NUM_MSG_TO_LOAD); } diff --git a/src/chatlog/chatlog.h b/src/chatlog/chatlog.h index 58df1ed51..ffc82d977 100644 --- a/src/chatlog/chatlog.h +++ b/src/chatlog/chatlog.h @@ -41,7 +41,7 @@ class ChatLog : public QGraphicsView { Q_OBJECT public: - explicit ChatLog(QWidget* parent = nullptr); + explicit ChatLog(const bool canRemove, QWidget* parent = nullptr); virtual ~ChatLog(); void insertChatlineAtBottom(ChatLine::Ptr l); @@ -188,6 +188,7 @@ private: int numRemove{0}; const int maxMessages{300}; + bool canRemove; }; #endif // CHATLOG_H diff --git a/src/widget/form/genericchatform.cpp b/src/widget/form/genericchatform.cpp index 1f99a5ae2..601221f74 100644 --- a/src/widget/form/genericchatform.cpp +++ b/src/widget/form/genericchatform.cpp @@ -259,7 +259,7 @@ GenericChatForm::GenericChatForm(const Contact* contact, IChatLog& chatLog, headWidget = new ChatFormHeader(); searchForm = new SearchForm(); dateInfo = new QLabel(this); - chatWidget = new ChatLog(this); + chatWidget = new ChatLog(contact->useHistory(), this); chatWidget->setBusyNotification(ChatMessage::createBusyNotification()); searchForm->hide(); dateInfo->setAlignment(Qt::AlignHCenter); From b04639c6d0eb4583ead66fff21f7416996867b14 Mon Sep 17 00:00:00 2001 From: Anthony Bilinski Date: Sat, 4 Apr 2020 22:33:00 -0700 Subject: [PATCH 02/20] revert(chatlog): "fix stick to bottom behavior" This reverts commit f2fa601073373ae2ef9fba7952aed415af3ccee0. --- src/chatlog/chatlog.cpp | 28 ++++++++++++++-------------- src/chatlog/chatlog.h | 2 +- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/chatlog/chatlog.cpp b/src/chatlog/chatlog.cpp index e73699f1a..a5cac0d94 100644 --- a/src/chatlog/chatlog.cpp +++ b/src/chatlog/chatlog.cpp @@ -407,9 +407,10 @@ void ChatLog::insertChatlineAtBottom(const QList& newLines) layout(lines.last()->getRow(), lines.size(), useableWidth()); - // redo layout only when scrolled down - if(stickToBottom()) { - startResizeWorker(true); + if (visibleLines.size() > 1) { + startResizeWorker(visibleLines[1]); + } else { + startResizeWorker(); } } @@ -462,9 +463,9 @@ void ChatLog::insertChatlinesOnTop(const QList& newLines) // redo layout if (visibleLines.size() > 1) { - startResizeWorker(stickToBottom(), visibleLines[1]); + startResizeWorker(visibleLines[1]); } else { - startResizeWorker(stickToBottom()); + startResizeWorker(); } } @@ -480,7 +481,7 @@ void ChatLog::scrollToBottom() verticalScrollBar()->setValue(verticalScrollBar()->maximum()); } -void ChatLog::startResizeWorker(bool stick, ChatLine::Ptr anchorLine) +void ChatLog::startResizeWorker(ChatLine::Ptr anchorLine) { if (lines.empty()) { isScroll = true; @@ -490,11 +491,11 @@ void ChatLog::startResizeWorker(bool stick, ChatLine::Ptr anchorLine) // (re)start the worker if (!workerTimer->isActive()) { // these values must not be reevaluated while the worker is running - workerStb = stick; - if (stick) { - workerAnchorLine = ChatLine::Ptr(); - } else { + if (anchorLine) { workerAnchorLine = anchorLine; + workerStb = false; + } else { + workerStb = stickToBottom(); } } @@ -764,7 +765,7 @@ int ChatLog::getNumRemove() const void ChatLog::forceRelayout() { - startResizeWorker(stickToBottom()); + startResizeWorker(); } void ChatLog::checkVisibility(bool causedWheelEvent) @@ -833,7 +834,7 @@ void ChatLog::resizeEvent(QResizeEvent* ev) bool stb = stickToBottom(); if (ev->size().width() != ev->oldSize().width()) { - startResizeWorker(stb); + startResizeWorker(); stb = false; // let the resize worker handle it } @@ -900,9 +901,8 @@ QRectF ChatLog::calculateSceneRect() const { qreal bottom = (lines.empty() ? 0.0 : lines.last()->sceneBoundingRect().bottom()); - if (typingNotification.get() != nullptr) { + if (typingNotification.get() != nullptr) bottom += typingNotification->sceneBoundingRect().height() + lineSpacing; - } return QRectF(-margins.left(), -margins.top(), useableWidth(), bottom + margins.bottom() + margins.top()); diff --git a/src/chatlog/chatlog.h b/src/chatlog/chatlog.h index ffc82d977..f48ef0c33 100644 --- a/src/chatlog/chatlog.h +++ b/src/chatlog/chatlog.h @@ -105,7 +105,7 @@ protected: void updateSceneRect(); void checkVisibility(bool causedWheelEvent = false); void scrollToBottom(); - void startResizeWorker(bool stick, ChatLine::Ptr anchorLine = nullptr); + void startResizeWorker(ChatLine::Ptr anchorLine = nullptr); virtual void mouseDoubleClickEvent(QMouseEvent* ev) final override; virtual void mousePressEvent(QMouseEvent* ev) final override; From 5d44cd773f8bb35799c9e66863cc4c18315da2da Mon Sep 17 00:00:00 2001 From: Anthony Bilinski Date: Sat, 4 Apr 2020 22:39:02 -0700 Subject: [PATCH 03/20] revert(chatlog): partially revert "prevent invalid history access" This partially reverts commit e3e6e1d9c4e22d6f090f153628677ad427cf4900. --- src/widget/form/genericchatform.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/widget/form/genericchatform.cpp b/src/widget/form/genericchatform.cpp index 601221f74..56548210f 100644 --- a/src/widget/form/genericchatform.cpp +++ b/src/widget/form/genericchatform.cpp @@ -980,10 +980,6 @@ void GenericChatForm::searchInBegin(const QString& phrase, const ParameterSearch return; } - if (messages.size() == 0) { - return; - } - if (chatLog.getNextIdx().get() == messages.rbegin()->first.get() + 1) { disableSearchText(); } else { From efff8d53c9b06f592493a9729cc6b226c2ad10d3 Mon Sep 17 00:00:00 2001 From: Anthony Bilinski Date: Sat, 4 Apr 2020 22:45:30 -0700 Subject: [PATCH 04/20] revert(chatlog): "add comments for functions that load history" This reverts commit 5fc1afbab51d06133e2fc1a05d6ef0e8f175ff86. --- src/widget/form/genericchatform.cpp | 25 ++----------------------- 1 file changed, 2 insertions(+), 23 deletions(-) diff --git a/src/widget/form/genericchatform.cpp b/src/widget/form/genericchatform.cpp index 56548210f..88cc8b877 100644 --- a/src/widget/form/genericchatform.cpp +++ b/src/widget/form/genericchatform.cpp @@ -649,11 +649,6 @@ QDateTime GenericChatForm::getTime(const ChatLine::Ptr &chatLine) const return QDateTime(); } -/** - * @brief GenericChatForm::loadHistory load history - * @param time start date - * @param type indicates the direction of loading history - */ void GenericChatForm::loadHistory(const QDateTime &time, const LoadHistoryDialog::LoadType type) { chatWidget->clear(); @@ -669,10 +664,6 @@ void GenericChatForm::loadHistory(const QDateTime &time, const LoadHistoryDialog } } -/** - * @brief GenericChatForm::loadHistoryTo load history before to date "time" or before the first "messages" item - * @param time start date - */ void GenericChatForm::loadHistoryTo(const QDateTime &time) { chatWidget->setScroll(false); @@ -699,11 +690,6 @@ void GenericChatForm::loadHistoryTo(const QDateTime &time) } } -/** - * @brief GenericChatForm::loadHistoryFrom load history starting from date "time" or from the last "messages" item - * @param time start date - * @return true if function loaded history else false - */ bool GenericChatForm::loadHistoryFrom(const QDateTime &time) { chatWidget->setScroll(false); @@ -716,12 +702,11 @@ bool GenericChatForm::loadHistoryFrom(const QDateTime &time) int add = DEF_NUM_MSG_TO_LOAD; if (begin.get() + DEF_NUM_MSG_TO_LOAD > chatLog.getNextIdx().get()) { + auto t = chatLog.getNextIdx(); add = chatLog.getNextIdx().get() - begin.get(); } - // The chatLog.getNextIdx() is usually 1 more than the idx on last "messages" item - // so if we have nothing to load, "add" is equal 1 - if (add <= 1) { + if (add <= 1) { chatWidget->setScroll(true); return false; } @@ -1166,17 +1151,11 @@ void GenericChatForm::goToCurrentDate() renderMessages(begin, end); } -/** - * @brief GenericChatForm::loadHistoryLower load history after scrolling chatlog before first "messages" item - */ void GenericChatForm::loadHistoryLower() { loadHistoryTo(QDateTime()); } -/** - * @brief GenericChatForm::loadHistoryUpper load history after scrolling chatlog after last "messages" item - */ void GenericChatForm::loadHistoryUpper() { if (messages.empty()) { From 4cd443ae7ba364b5d2c803b3019c12048956363d Mon Sep 17 00:00:00 2001 From: Anthony Bilinski Date: Sat, 4 Apr 2020 22:45:36 -0700 Subject: [PATCH 05/20] revert(chatlog): "scroll bar stuck to bottom (fix #5755)" This reverts commit 38df897e024393ba15c80017930dac19a92e13b7. --- src/widget/form/genericchatform.cpp | 17 +++-------------- src/widget/form/genericchatform.h | 2 +- 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/src/widget/form/genericchatform.cpp b/src/widget/form/genericchatform.cpp index 88cc8b877..3fbce045c 100644 --- a/src/widget/form/genericchatform.cpp +++ b/src/widget/form/genericchatform.cpp @@ -690,7 +690,7 @@ void GenericChatForm::loadHistoryTo(const QDateTime &time) } } -bool GenericChatForm::loadHistoryFrom(const QDateTime &time) +void GenericChatForm::loadHistoryFrom(const QDateTime &time) { chatWidget->setScroll(false); auto begin = ChatLogIdx(0); @@ -702,20 +702,10 @@ bool GenericChatForm::loadHistoryFrom(const QDateTime &time) int add = DEF_NUM_MSG_TO_LOAD; if (begin.get() + DEF_NUM_MSG_TO_LOAD > chatLog.getNextIdx().get()) { - auto t = chatLog.getNextIdx(); add = chatLog.getNextIdx().get() - begin.get(); } - - if (add <= 1) { - chatWidget->setScroll(true); - return false; - } - auto end = ChatLogIdx(begin.get() + add); - renderMessages(begin, end); - - return true; } void GenericChatForm::removeFirstsMessages(const int num) @@ -1163,9 +1153,8 @@ void GenericChatForm::loadHistoryUpper() } auto msg = messages.crbegin()->second; - if (loadHistoryFrom(QDateTime())) { - chatWidget->scrollToLine(msg); - } + loadHistoryFrom(QDateTime()); + chatWidget->scrollToLine(msg); } void GenericChatForm::updateShowDateInfo(const ChatLine::Ptr& prevLine, const ChatLine::Ptr& topLine) diff --git a/src/widget/form/genericchatform.h b/src/widget/form/genericchatform.h index ba4d813c3..51df5cefb 100644 --- a/src/widget/form/genericchatform.h +++ b/src/widget/form/genericchatform.h @@ -137,7 +137,7 @@ private: QDateTime getTime(const ChatLine::Ptr& chatLine) const; void loadHistory(const QDateTime& time, const LoadHistoryDialog::LoadType type); void loadHistoryTo(const QDateTime& time); - bool loadHistoryFrom(const QDateTime& time); + void loadHistoryFrom(const QDateTime& time); void removeFirstsMessages(const int num); void removeLastsMessages(const int num); From 306bbb424e7ed5879df0518056b9aaf5e0176523 Mon Sep 17 00:00:00 2001 From: Anthony Bilinski Date: Sat, 4 Apr 2020 22:45:41 -0700 Subject: [PATCH 06/20] revert(chatlog): "update workerStb" This reverts commit 177bf12f1150a842e5263eb573fe110fb717ea5a. --- src/chatlog/chatlog.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/chatlog/chatlog.cpp b/src/chatlog/chatlog.cpp index a5cac0d94..33b0cc25d 100644 --- a/src/chatlog/chatlog.cpp +++ b/src/chatlog/chatlog.cpp @@ -947,12 +947,10 @@ void ChatLog::onWorkerTimeout() updateMultiSelectionRect(); // scroll - if (workerStb) { + if (workerStb) scrollToBottom(); - workerStb = false; - } else { + else scrollToLine(workerAnchorLine); - } // don't keep a Ptr to the anchor line workerAnchorLine = ChatLine::Ptr(); From 83d5863bbe84572bfd00c3fbef9ced4765e20099 Mon Sep 17 00:00:00 2001 From: Anthony Bilinski Date: Sat, 4 Apr 2020 22:45:46 -0700 Subject: [PATCH 07/20] revert(chatlog): "optimize load messages during the search" This reverts commit 6de307e6b98eb8aa9b583c55e4fa19c5c06534c9. --- src/widget/form/genericchatform.cpp | 67 +++++++---------------------- 1 file changed, 16 insertions(+), 51 deletions(-) diff --git a/src/widget/form/genericchatform.cpp b/src/widget/form/genericchatform.cpp index 3fbce045c..a33bb91ea 100644 --- a/src/widget/form/genericchatform.cpp +++ b/src/widget/form/genericchatform.cpp @@ -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) From c1d0624b5d755580278cbc27ed252377377b8952 Mon Sep 17 00:00:00 2001 From: Anthony Bilinski Date: Sat, 4 Apr 2020 22:45:51 -0700 Subject: [PATCH 08/20] revert(chatlog): "feat: save selected search text after scrolling up" This reverts commit dbf880078e8b3207bf5c4f057bc6071b4c74b9ce. --- src/chatlog/chatlog.cpp | 2 +- src/model/ichatlog.h | 2 +- src/widget/form/genericchatform.cpp | 50 ++++++++++++----------------- src/widget/form/genericchatform.h | 3 +- 4 files changed, 24 insertions(+), 33 deletions(-) diff --git a/src/chatlog/chatlog.cpp b/src/chatlog/chatlog.cpp index 33b0cc25d..925479847 100644 --- a/src/chatlog/chatlog.cpp +++ b/src/chatlog/chatlog.cpp @@ -688,7 +688,7 @@ void ChatLog::scrollToLine(ChatLine::Ptr line) workerStb = false; } else { updateSceneRect(); - verticalScrollBar()->setValue(line->sceneBoundingRect().top()); + verticalScrollBar()->setValue(line->sceneBoundingRect().top()); // NOTE: start here } } diff --git a/src/model/ichatlog.h b/src/model/ichatlog.h index a4928e9f2..2144c2d0d 100644 --- a/src/model/ichatlog.h +++ b/src/model/ichatlog.h @@ -70,7 +70,7 @@ struct SearchPos struct SearchResult { - bool found{false}; + bool found; SearchPos pos; size_t start; size_t len; diff --git a/src/widget/form/genericchatform.cpp b/src/widget/form/genericchatform.cpp index a33bb91ea..ae552d7e2 100644 --- a/src/widget/form/genericchatform.cpp +++ b/src/widget/form/genericchatform.cpp @@ -680,11 +680,7 @@ void GenericChatForm::loadHistoryTo(const QDateTime &time) } if (begin != end) { - if (searchResult.found == true) { - renderMessages(begin, searchResult.pos.logIdx, [this]{enableSearchText();}); - } else { - renderMessages(begin, end); - } + renderMessages(begin, end); } else { chatWidget->setScroll(true); } @@ -729,23 +725,13 @@ void GenericChatForm::removeLastsMessages(const int num) void GenericChatForm::disableSearchText() { - auto msgIt = messages.find(searchResult.pos.logIdx); + auto msgIt = messages.find(searchPos.logIdx); if (msgIt != messages.end()) { auto text = qobject_cast(msgIt->second->getContent(1)); text->deselectText(); } } -void GenericChatForm::enableSearchText() -{ - auto msg = messages.at(searchResult.pos.logIdx); - chatWidget->scrollToLine(msg); - - auto text = qobject_cast(msg->getContent(1)); - text->visibilityChanged(true); - text->selectText(searchResult.exp, std::make_pair(searchResult.start, searchResult.len)); -} - void GenericChatForm::clearChatArea() { clearChatArea(/* confirm = */ true, /* inform = */ true); @@ -941,7 +927,6 @@ void GenericChatForm::onExportChat() void GenericChatForm::onSearchTriggered() { if (searchForm->isHidden()) { - searchResult.found = false; searchForm->removeSearchPhrase(); } disableSearchText(); @@ -971,27 +956,27 @@ void GenericChatForm::searchInBegin(const QString& phrase, const ParameterSearch switch (parameter.period) { case PeriodSearch::WithTheFirst: { bForwardSearch = true; - searchResult.pos.logIdx = chatLog.getFirstIdx(); - searchResult.pos.numMatches = 0; + searchPos.logIdx = chatLog.getFirstIdx(); + searchPos.numMatches = 0; break; } case PeriodSearch::WithTheEnd: case PeriodSearch::None: { bForwardSearch = false; - searchResult.pos.logIdx = chatLog.getNextIdx(); - searchResult.pos.numMatches = 0; + searchPos.logIdx = chatLog.getNextIdx(); + searchPos.numMatches = 0; break; } case PeriodSearch::AfterDate: { bForwardSearch = true; - searchResult.pos.logIdx = firstItemAfterDate(parameter.time.date(), chatLog); - searchResult.pos.numMatches = 0; + searchPos.logIdx = firstItemAfterDate(parameter.time.date(), chatLog); + searchPos.numMatches = 0; break; } case PeriodSearch::BeforeDate: { bForwardSearch = false; - searchResult.pos.logIdx = firstItemAfterDate(parameter.time.date(), chatLog); - searchResult.pos.numMatches = 0; + searchPos.logIdx = firstItemAfterDate(parameter.time.date(), chatLog); + searchPos.numMatches = 0; break; } } @@ -1005,13 +990,13 @@ void GenericChatForm::searchInBegin(const QString& phrase, const ParameterSearch void GenericChatForm::onSearchUp(const QString& phrase, const ParameterSearch& parameter) { - auto result = chatLog.searchBackward(searchResult.pos, phrase, parameter); + auto result = chatLog.searchBackward(searchPos, phrase, parameter); handleSearchResult(result, SearchDirection::Up); } void GenericChatForm::onSearchDown(const QString& phrase, const ParameterSearch& parameter) { - auto result = chatLog.searchForward(searchResult.pos, phrase, parameter); + auto result = chatLog.searchForward(searchPos, phrase, parameter); if (result.found && result.pos.logIdx.get() > messages.end()->first.get()) { const auto dt = chatLog.at(result.pos.logIdx).getTimestamp(); @@ -1030,11 +1015,18 @@ void GenericChatForm::handleSearchResult(SearchResult result, SearchDirection di disableSearchText(); - searchResult = result; + searchPos = result.pos; auto const firstRenderedIdx = (messages.empty()) ? chatLog.getNextIdx() : messages.begin()->first; - renderMessages(searchResult.pos.logIdx, firstRenderedIdx, [this]{enableSearchText();}); + renderMessages(searchPos.logIdx, firstRenderedIdx, [this, result] { + auto msg = messages.at(searchPos.logIdx); + chatWidget->scrollToLine(msg); + + auto text = qobject_cast(msg->getContent(1)); + text->visibilityChanged(true); + text->selectText(result.exp, std::make_pair(result.start, result.len)); + }); } void GenericChatForm::renderMessage(ChatLogIdx idx) diff --git a/src/widget/form/genericchatform.h b/src/widget/form/genericchatform.h index 51df5cefb..7fe3867d8 100644 --- a/src/widget/form/genericchatform.h +++ b/src/widget/form/genericchatform.h @@ -156,7 +156,6 @@ protected: virtual void resizeEvent(QResizeEvent* event) final override; virtual bool eventFilter(QObject* object, QEvent* event) final override; void disableSearchText(); - void enableSearchText(); bool searchInText(const QString& phrase, const ParameterSearch& parameter, SearchDirection direction); std::pair indexForSearchInLine(const QString& txt, const QString& phrase, const ParameterSearch& parameter, SearchDirection direction); @@ -197,7 +196,7 @@ protected: IChatLog& chatLog; IMessageDispatcher& messageDispatcher; - SearchResult searchResult; + SearchPos searchPos; std::map messages; bool colorizeNames = false; }; From 6395ce3aaef2b6fd28d7940212b384ec5dd69141 Mon Sep 17 00:00:00 2001 From: Anthony Bilinski Date: Sat, 4 Apr 2020 22:45:58 -0700 Subject: [PATCH 09/20] revert(chatlog): "feat: check chat status before start a search" This reverts commit ce570927b145676ff3a63f36a3fe082fa52b228a. --- src/widget/form/genericchatform.cpp | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/src/widget/form/genericchatform.cpp b/src/widget/form/genericchatform.cpp index ae552d7e2..1b2ccaeb6 100644 --- a/src/widget/form/genericchatform.cpp +++ b/src/widget/form/genericchatform.cpp @@ -934,17 +934,7 @@ void GenericChatForm::onSearchTriggered() void GenericChatForm::searchInBegin(const QString& phrase, const ParameterSearch& parameter) { - if (phrase.isEmpty()) { - disableSearchText(); - - return; - } - - if (chatLog.getNextIdx().get() == messages.rbegin()->first.get() + 1) { - disableSearchText(); - } else { - goToCurrentDate(); - } + disableSearchText(); if (!parameter.time.isNull()) { LoadHistoryDialog::LoadType type = (parameter.period == PeriodSearch::BeforeDate) @@ -996,7 +986,7 @@ void GenericChatForm::onSearchUp(const QString& phrase, const ParameterSearch& p void GenericChatForm::onSearchDown(const QString& phrase, const ParameterSearch& parameter) { - auto result = chatLog.searchForward(searchPos, phrase, parameter); + auto result = chatLog.searchForward(searchPos, phrase, parameter); if (result.found && result.pos.logIdx.get() > messages.end()->first.get()) { const auto dt = chatLog.at(result.pos.logIdx).getTimestamp(); From 35c5e77a8a7e6854a74c75013c40d1e478599ea9 Mon Sep 17 00:00:00 2001 From: Anthony Bilinski Date: Sat, 4 Apr 2020 22:46:03 -0700 Subject: [PATCH 10/20] revert(chatlog): "fix: data validation during the search" This reverts commit acb91ed731bece1fbdac90064446c61ab68b721f. --- src/model/chathistory.cpp | 18 ++++++------------ src/widget/form/genericchatform.cpp | 9 +-------- 2 files changed, 7 insertions(+), 20 deletions(-) diff --git a/src/model/chathistory.cpp b/src/model/chathistory.cpp index 76f476d1e..0b4585763 100644 --- a/src/model/chathistory.cpp +++ b/src/model/chathistory.cpp @@ -158,19 +158,13 @@ SearchResult ChatHistory::searchBackward(SearchPos startIdx, const QString& phra history->getDateWhereFindPhrase(f.getPublicKey().toString(), earliestMessageDate, phrase, parameter); - if (dateWherePhraseFound.isValid()) { - auto loadIdx = history->getNumMessagesForFriendBeforeDate(f.getPublicKey(), dateWherePhraseFound); - loadHistoryIntoSessionChatLog(ChatLogIdx(loadIdx)); + auto loadIdx = history->getNumMessagesForFriendBeforeDate(f.getPublicKey(), dateWherePhraseFound); + loadHistoryIntoSessionChatLog(ChatLogIdx(loadIdx)); - // Reset search pos to the message we just loaded to avoid a double search - startIdx.logIdx = ChatLogIdx(loadIdx); - startIdx.numMatches = 0; - return sessionChatLog.searchBackward(startIdx, phrase, parameter); - } - - SearchResult ret; - ret.found = false; - return ret; + // Reset search pos to the message we just loaded to avoid a double search + startIdx.logIdx = ChatLogIdx(loadIdx); + startIdx.numMatches = 0; + return sessionChatLog.searchBackward(startIdx, phrase, parameter); } ChatLogIdx ChatHistory::getFirstIdx() const diff --git a/src/widget/form/genericchatform.cpp b/src/widget/form/genericchatform.cpp index 1b2ccaeb6..dd224a961 100644 --- a/src/widget/form/genericchatform.cpp +++ b/src/widget/form/genericchatform.cpp @@ -986,13 +986,7 @@ void GenericChatForm::onSearchUp(const QString& phrase, const ParameterSearch& p void GenericChatForm::onSearchDown(const QString& phrase, const ParameterSearch& parameter) { - auto result = chatLog.searchForward(searchPos, 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); - } - + auto result = chatLog.searchForward(searchPos, phrase, parameter); handleSearchResult(result, SearchDirection::Down); } @@ -1014,7 +1008,6 @@ void GenericChatForm::handleSearchResult(SearchResult result, SearchDirection di chatWidget->scrollToLine(msg); auto text = qobject_cast(msg->getContent(1)); - text->visibilityChanged(true); text->selectText(result.exp, std::make_pair(result.start, result.len)); }); } From 3ac6b578df681275aedb1d182a7034fa495ccb27 Mon Sep 17 00:00:00 2001 From: Anthony Bilinski Date: Sat, 4 Apr 2020 22:53:45 -0700 Subject: [PATCH 11/20] revert(chatlog): "fix a crash when there are no messages to load" This reverts commit 040c6b95aed26dfc7950770ed4dca379e8be2bc5. --- src/widget/form/genericchatform.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/widget/form/genericchatform.cpp b/src/widget/form/genericchatform.cpp index dd224a961..dce6dd516 100644 --- a/src/widget/form/genericchatform.cpp +++ b/src/widget/form/genericchatform.cpp @@ -1088,10 +1088,6 @@ void GenericChatForm::loadHistoryLower() void GenericChatForm::loadHistoryUpper() { - if (messages.empty()) { - return; - } - auto msg = messages.crbegin()->second; loadHistoryFrom(QDateTime()); chatWidget->scrollToLine(msg); From bd0ef5de8261bf727e06a9484877feccb6696f03 Mon Sep 17 00:00:00 2001 From: Anthony Bilinski Date: Sat, 4 Apr 2020 22:54:17 -0700 Subject: [PATCH 12/20] revert(chatlog): "prohibition to remove messages in group chat" This reverts commit 5aeac56b761ad24b6a2829fca499b8eff480a306. --- src/chatlog/chatlog.cpp | 9 +++++---- src/chatlog/chatlog.h | 3 +-- src/model/contact.h | 2 -- src/model/friend.cpp | 5 ----- src/model/friend.h | 1 - src/model/group.cpp | 5 ----- src/model/group.h | 2 -- src/widget/form/genericchatform.cpp | 3 ++- 8 files changed, 8 insertions(+), 22 deletions(-) diff --git a/src/chatlog/chatlog.cpp b/src/chatlog/chatlog.cpp index 925479847..45f40fff2 100644 --- a/src/chatlog/chatlog.cpp +++ b/src/chatlog/chatlog.cpp @@ -52,8 +52,8 @@ T clamp(T x, T min, T max) return x; } -ChatLog::ChatLog(const bool canRemove, QWidget* parent) - : QGraphicsView(parent), canRemove(canRemove) +ChatLog::ChatLog(QWidget* parent) + : QGraphicsView(parent) { // Create the scene busyScene = new QGraphicsScene(this); @@ -394,7 +394,7 @@ void ChatLog::insertChatlineAtBottom(const QList& newLines) if (newLines.isEmpty()) return; - if (canRemove && lines.size() + DEF_NUM_MSG_TO_LOAD >= maxMessages) { + if (lines.size() + DEF_NUM_MSG_TO_LOAD >= maxMessages) { removeFirsts(DEF_NUM_MSG_TO_LOAD); } @@ -445,7 +445,7 @@ void ChatLog::insertChatlinesOnTop(const QList& newLines) combLines.push_back(l); } - if (canRemove && lines.size() + DEF_NUM_MSG_TO_LOAD >= maxMessages) { + if (lines.size() + DEF_NUM_MSG_TO_LOAD >= maxMessages) { removeLasts(DEF_NUM_MSG_TO_LOAD); } @@ -815,6 +815,7 @@ void ChatLog::checkVisibility(bool causedWheelEvent) } if (causedWheelEvent) { + qDebug() << "causedWheelEvent"; if (lowerBound != lines.cend() && lowerBound->get()->row == 0) { emit loadHistoryLower(); } else if (upperBound == lines.cend()) { diff --git a/src/chatlog/chatlog.h b/src/chatlog/chatlog.h index f48ef0c33..4b6ae1721 100644 --- a/src/chatlog/chatlog.h +++ b/src/chatlog/chatlog.h @@ -41,7 +41,7 @@ class ChatLog : public QGraphicsView { Q_OBJECT public: - explicit ChatLog(const bool canRemove, QWidget* parent = nullptr); + explicit ChatLog(QWidget* parent = nullptr); virtual ~ChatLog(); void insertChatlineAtBottom(ChatLine::Ptr l); @@ -188,7 +188,6 @@ private: int numRemove{0}; const int maxMessages{300}; - bool canRemove; }; #endif // CHATLOG_H diff --git a/src/model/contact.h b/src/model/contact.h index 182d1ce90..e2faa5799 100644 --- a/src/model/contact.h +++ b/src/model/contact.h @@ -37,8 +37,6 @@ public: virtual void setEventFlag(bool flag) = 0; virtual bool getEventFlag() const = 0; - virtual bool useHistory() const = 0; // TODO: remove after added history in group chat - signals: void displayedNameChanged(const QString& newName); }; diff --git a/src/model/friend.cpp b/src/model/friend.cpp index c34058e18..f63bf23b6 100644 --- a/src/model/friend.cpp +++ b/src/model/friend.cpp @@ -168,8 +168,3 @@ Status::Status Friend::getStatus() const { return friendStatus; } - -bool Friend::useHistory() const -{ - return true; -} diff --git a/src/model/friend.h b/src/model/friend.h index b711c31d9..3d80e957a 100644 --- a/src/model/friend.h +++ b/src/model/friend.h @@ -53,7 +53,6 @@ public: void setStatus(Status::Status s); Status::Status getStatus() const; - bool useHistory() const override final; signals: void nameChanged(const ToxPk& friendId, const QString& name); diff --git a/src/model/group.cpp b/src/model/group.cpp index f08d4397d..39f7e58ab 100644 --- a/src/model/group.cpp +++ b/src/model/group.cpp @@ -205,11 +205,6 @@ QString Group::getSelfName() const return selfName; } -bool Group::useHistory() const -{ - return false; -} - void Group::stopAudioOfDepartedPeers(const ToxPk& peerPk) { if (avGroupchat) { diff --git a/src/model/group.h b/src/model/group.h index fd19461ca..4e70a407e 100644 --- a/src/model/group.h +++ b/src/model/group.h @@ -61,8 +61,6 @@ public: void setSelfName(const QString& name); QString getSelfName() const; - bool useHistory() const override final; - signals: void titleChangedByUser(const QString& title); void titleChanged(const QString& author, const QString& title); diff --git a/src/widget/form/genericchatform.cpp b/src/widget/form/genericchatform.cpp index dce6dd516..106f8e48b 100644 --- a/src/widget/form/genericchatform.cpp +++ b/src/widget/form/genericchatform.cpp @@ -259,7 +259,7 @@ GenericChatForm::GenericChatForm(const Contact* contact, IChatLog& chatLog, headWidget = new ChatFormHeader(); searchForm = new SearchForm(); dateInfo = new QLabel(this); - chatWidget = new ChatLog(contact->useHistory(), this); + chatWidget = new ChatLog(this); chatWidget->setBusyNotification(ChatMessage::createBusyNotification()); searchForm->hide(); dateInfo->setAlignment(Qt::AlignHCenter); @@ -698,6 +698,7 @@ void GenericChatForm::loadHistoryFrom(const QDateTime &time) int add = DEF_NUM_MSG_TO_LOAD; if (begin.get() + DEF_NUM_MSG_TO_LOAD > chatLog.getNextIdx().get()) { + auto aTest = chatLog.getNextIdx().get(); add = chatLog.getNextIdx().get() - begin.get(); } auto end = ChatLogIdx(begin.get() + add); From 8f167f45a3d7f2fbf1b41d1bf7aa94b9036e18e8 Mon Sep 17 00:00:00 2001 From: Anthony Bilinski Date: Sat, 4 Apr 2020 22:54:45 -0700 Subject: [PATCH 13/20] revert(chatlog): "edit load history when scrolling" This reverts commit 0a9e72020e3ec0bcfdca98891466e79cca8c23ec. --- src/chatlog/chatlog.cpp | 66 ++++------------------------- src/chatlog/chatlog.h | 10 +---- src/model/chathistory.cpp | 5 +-- src/model/ichatlog.h | 2 + src/widget/form/genericchatform.cpp | 49 +++++++++++---------- src/widget/form/genericchatform.h | 4 ++ 6 files changed, 42 insertions(+), 94 deletions(-) diff --git a/src/chatlog/chatlog.cpp b/src/chatlog/chatlog.cpp index 45f40fff2..e7fe8237c 100644 --- a/src/chatlog/chatlog.cpp +++ b/src/chatlog/chatlog.cpp @@ -366,7 +366,6 @@ void ChatLog::reposition(int start, int end, qreal deltaY) void ChatLog::insertChatlineAtBottom(ChatLine::Ptr l) { - numRemove = 0; if (!l.get()) return; @@ -390,14 +389,9 @@ void ChatLog::insertChatlineAtBottom(ChatLine::Ptr l) void ChatLog::insertChatlineAtBottom(const QList& newLines) { - numRemove = 0; if (newLines.isEmpty()) return; - if (lines.size() + DEF_NUM_MSG_TO_LOAD >= maxMessages) { - removeFirsts(DEF_NUM_MSG_TO_LOAD); - } - for (ChatLine::Ptr l : newLines) { l->setRow(lines.size()); l->addToScene(scene); @@ -406,17 +400,11 @@ void ChatLog::insertChatlineAtBottom(const QList& newLines) } layout(lines.last()->getRow(), lines.size(), useableWidth()); - - if (visibleLines.size() > 1) { - startResizeWorker(visibleLines[1]); - } else { - startResizeWorker(); - } + startResizeWorker(); } void ChatLog::insertChatlineOnTop(ChatLine::Ptr l) { - numRemove = 0; if (!l.get()) return; @@ -425,7 +413,6 @@ void ChatLog::insertChatlineOnTop(ChatLine::Ptr l) void ChatLog::insertChatlinesOnTop(const QList& newLines) { - numRemove = 0; if (newLines.isEmpty()) return; @@ -445,10 +432,6 @@ void ChatLog::insertChatlinesOnTop(const QList& newLines) combLines.push_back(l); } - if (lines.size() + DEF_NUM_MSG_TO_LOAD >= maxMessages) { - removeLasts(DEF_NUM_MSG_TO_LOAD); - } - // add the old lines for (ChatLine::Ptr l : lines) { l->setRow(i++); @@ -462,12 +445,7 @@ void ChatLog::insertChatlinesOnTop(const QList& newLines) scene->setItemIndexMethod(oldIndexMeth); // redo layout - if (visibleLines.size() > 1) { - startResizeWorker(visibleLines[1]); - } else { - startResizeWorker(); - } - + startResizeWorker(); } bool ChatLog::stickToBottom() const @@ -481,22 +459,19 @@ void ChatLog::scrollToBottom() verticalScrollBar()->setValue(verticalScrollBar()->maximum()); } -void ChatLog::startResizeWorker(ChatLine::Ptr anchorLine) +void ChatLog::startResizeWorker() { if (lines.empty()) { - isScroll = true; return; } // (re)start the worker if (!workerTimer->isActive()) { // these values must not be reevaluated while the worker is running - if (anchorLine) { - workerAnchorLine = anchorLine; - workerStb = false; - } else { - workerStb = stickToBottom(); - } + workerStb = stickToBottom(); + + if (!visibleLines.empty()) + workerAnchorLine = visibleLines.first(); } // switch to busy scene displaying the busy notification if there is a lot @@ -683,13 +658,8 @@ void ChatLog::scrollToLine(ChatLine::Ptr line) if (!line.get()) return; - if (workerTimer->isActive()) { - workerAnchorLine = line; - workerStb = false; - } else { - updateSceneRect(); - verticalScrollBar()->setValue(line->sceneBoundingRect().top()); // NOTE: start here - } + updateSceneRect(); + verticalScrollBar()->setValue(line->sceneBoundingRect().top()); } void ChatLog::selectAll() @@ -731,7 +701,6 @@ void ChatLog::removeFirsts(const int num) { if (lines.size() > num) { lines.erase(lines.begin(), lines.begin()+num); - numRemove = num; } else { lines.clear(); } @@ -747,22 +716,11 @@ void ChatLog::removeLasts(const int num) { if (lines.size() > num) { lines.erase(lines.end()-num, lines.end()); - numRemove = num; } else { lines.clear(); } } -void ChatLog::setScroll(const bool scroll) -{ - isScroll = scroll; -} - -int ChatLog::getNumRemove() const -{ - return numRemove; -} - void ChatLog::forceRelayout() { startResizeWorker(); @@ -815,7 +773,6 @@ void ChatLog::checkVisibility(bool causedWheelEvent) } if (causedWheelEvent) { - qDebug() << "causedWheelEvent"; if (lowerBound != lines.cend() && lowerBound->get()->row == 0) { emit loadHistoryLower(); } else if (upperBound == lines.cend()) { @@ -959,7 +916,6 @@ void ChatLog::onWorkerTimeout() // hidden during busy screen verticalScrollBar()->show(); - isScroll = true; emit workerTimeoutFinished(); } } @@ -1027,10 +983,6 @@ void ChatLog::focusOutEvent(QFocusEvent* ev) void ChatLog::wheelEvent(QWheelEvent *event) { - if (!isScroll) { - return; - } - QGraphicsView::wheelEvent(event); checkVisibility(true); } diff --git a/src/chatlog/chatlog.h b/src/chatlog/chatlog.h index 4b6ae1721..31ae1048a 100644 --- a/src/chatlog/chatlog.h +++ b/src/chatlog/chatlog.h @@ -35,8 +35,6 @@ class QTimer; class ChatLineContent; struct ToxFile; -static const auto DEF_NUM_MSG_TO_LOAD = 100; - class ChatLog : public QGraphicsView { Q_OBJECT @@ -60,8 +58,6 @@ public: void reloadTheme(); void removeFirsts(const int num); void removeLasts(const int num); - void setScroll(const bool scroll); - int getNumRemove() const; QString getSelectedText() const; @@ -105,7 +101,7 @@ protected: void updateSceneRect(); void checkVisibility(bool causedWheelEvent = false); void scrollToBottom(); - void startResizeWorker(ChatLine::Ptr anchorLine = nullptr); + void startResizeWorker(); virtual void mouseDoubleClickEvent(QMouseEvent* ev) final override; virtual void mousePressEvent(QMouseEvent* ev) final override; @@ -175,7 +171,6 @@ private: int clickCount = 0; QPoint lastClickPos; Qt::MouseButton lastClickButton; - bool isScroll{true}; // worker vars int workerLastIndex = 0; @@ -185,9 +180,6 @@ private: // layout QMargins margins = QMargins(10, 10, 10, 10); qreal lineSpacing = 5.0f; - - int numRemove{0}; - const int maxMessages{300}; }; #endif // CHATLOG_H diff --git a/src/model/chathistory.cpp b/src/model/chathistory.cpp index 0b4585763..9aa75e98e 100644 --- a/src/model/chathistory.cpp +++ b/src/model/chathistory.cpp @@ -94,10 +94,9 @@ ChatHistory::ChatHistory(Friend& f_, History* history_, const ICoreIdHandler& co // NOTE: this has to be done _after_ sending all sent messages since initial // state of the message has to be marked according to our dispatch state - constexpr auto defaultNumMessagesToLoad = 100; - auto firstChatLogIdx = sessionChatLog.getFirstIdx().get() < defaultNumMessagesToLoad + auto firstChatLogIdx = sessionChatLog.getFirstIdx().get() < DEF_NUM_MSG_TO_LOAD ? ChatLogIdx(0) - : sessionChatLog.getFirstIdx() - defaultNumMessagesToLoad; + : sessionChatLog.getFirstIdx() - DEF_NUM_MSG_TO_LOAD; if (canUseHistory()) { loadHistoryIntoSessionChatLog(firstChatLogIdx); diff --git a/src/model/ichatlog.h b/src/model/ichatlog.h index 2144c2d0d..1438610d6 100644 --- a/src/model/ichatlog.h +++ b/src/model/ichatlog.h @@ -35,6 +35,8 @@ #include +static const auto DEF_NUM_MSG_TO_LOAD = 100; + using ChatLogIdx = NamedType; Q_DECLARE_METATYPE(ChatLogIdx); diff --git a/src/widget/form/genericchatform.cpp b/src/widget/form/genericchatform.cpp index 106f8e48b..315f4c8bf 100644 --- a/src/widget/form/genericchatform.cpp +++ b/src/widget/form/genericchatform.cpp @@ -53,8 +53,6 @@ #include #include -#include - #ifdef SPELL_CHECKING #include #endif @@ -657,7 +655,6 @@ void GenericChatForm::loadHistory(const QDateTime &time, const LoadHistoryDialog if (type == LoadHistoryDialog::from) { loadHistoryFrom(time); auto msg = messages.cbegin()->second; - chatWidget->setScroll(true); chatWidget->scrollToLine(msg); } else { loadHistoryTo(time); @@ -666,10 +663,15 @@ void GenericChatForm::loadHistory(const QDateTime &time, const LoadHistoryDialog void GenericChatForm::loadHistoryTo(const QDateTime &time) { - chatWidget->setScroll(false); auto end = ChatLogIdx(0); if (time.isNull()) { - end = messages.begin()->first; + if (messages.size() + DEF_NUM_MSG_TO_LOAD >= maxMessages) { + end = ChatLogIdx(messages.rbegin()->first.get() - DEF_NUM_MSG_TO_LOAD); + chatWidget->removeLasts(DEF_NUM_MSG_TO_LOAD); + removeLastsMessages(DEF_NUM_MSG_TO_LOAD); + } else { + end = messages.begin()->first; + } } else { end = firstItemAfterDate(time.date(), chatLog); } @@ -679,27 +681,28 @@ void GenericChatForm::loadHistoryTo(const QDateTime &time) begin = ChatLogIdx(end.get() - DEF_NUM_MSG_TO_LOAD); } - if (begin != end) { - renderMessages(begin, end); - } else { - chatWidget->setScroll(true); - } + renderMessages(begin, end); } void GenericChatForm::loadHistoryFrom(const QDateTime &time) { - chatWidget->setScroll(false); auto begin = ChatLogIdx(0); if (time.isNull()) { - begin = messages.rbegin()->first; + if (messages.size() + DEF_NUM_MSG_TO_LOAD >= maxMessages) { + begin = ChatLogIdx(messages.rbegin()->first.get() + DEF_NUM_MSG_TO_LOAD); + chatWidget->removeFirsts(DEF_NUM_MSG_TO_LOAD); + removeFirstsMessages(DEF_NUM_MSG_TO_LOAD); + } else { + begin = messages.rbegin()->first; + } + } else { begin = firstItemAfterDate(time.date(), chatLog); } int add = DEF_NUM_MSG_TO_LOAD; if (begin.get() + DEF_NUM_MSG_TO_LOAD > chatLog.getNextIdx().get()) { - auto aTest = chatLog.getNextIdx().get(); - add = chatLog.getNextIdx().get() - begin.get(); + add = chatLog.getNextIdx().get() - (begin.get() + DEF_NUM_MSG_TO_LOAD); } auto end = ChatLogIdx(begin.get() + add); renderMessages(begin, end); @@ -1015,6 +1018,10 @@ void GenericChatForm::handleSearchResult(SearchResult result, SearchDirection di void GenericChatForm::renderMessage(ChatLogIdx idx) { + if (chatWidget->getLines().size() >= maxMessages) { + chatWidget->removeFirsts(optimalRemove); + removeFirstsMessages(optimalRemove); + } renderMessages(idx, idx + 1); } @@ -1041,13 +1048,8 @@ void GenericChatForm::renderMessages(ChatLogIdx begin, ChatLogIdx end, } } - if (beforeLines.isEmpty() && afterLines.isEmpty()) { - chatWidget->setScroll(true); - } - - chatWidget->insertChatlineAtBottom(afterLines); - if (chatWidget->getNumRemove()) { - removeFirstsMessages(chatWidget->getNumRemove()); + for (auto const& line : afterLines) { + chatWidget->insertChatlineAtBottom(line); } if (!beforeLines.empty()) { @@ -1064,9 +1066,6 @@ void GenericChatForm::renderMessages(ChatLogIdx begin, ChatLogIdx end, } chatWidget->insertChatlinesOnTop(beforeLines); - if (chatWidget->getNumRemove()) { - removeLastsMessages(chatWidget->getNumRemove()); - } } else if (onCompletion) { onCompletion(); } @@ -1076,7 +1075,7 @@ void GenericChatForm::goToCurrentDate() { chatWidget->clear(); messages.clear(); - auto end = ChatLogIdx(chatLog.size()); + auto end = ChatLogIdx(chatLog.size() - 1); auto begin = end.get() > DEF_NUM_MSG_TO_LOAD ? ChatLogIdx(end.get() - DEF_NUM_MSG_TO_LOAD) : ChatLogIdx(0); renderMessages(begin, end); diff --git a/src/widget/form/genericchatform.h b/src/widget/form/genericchatform.h index 7fe3867d8..34623abca 100644 --- a/src/widget/form/genericchatform.h +++ b/src/widget/form/genericchatform.h @@ -199,6 +199,10 @@ protected: SearchPos searchPos; std::map messages; bool colorizeNames = false; + +private: + const int maxMessages{300}; + const int optimalRemove{50}; }; #endif // GENERICCHATFORM_H From 3f36b31f8b480cea63ee65b51cba07d9ac05f341 Mon Sep 17 00:00:00 2001 From: Anthony Bilinski Date: Sat, 4 Apr 2020 22:54:53 -0700 Subject: [PATCH 14/20] revert(chatlog): "simple edit code" This reverts commit b807998fe9c055bd97b9bd3ff746955124b0f89b. --- src/chatlog/chatlog.cpp | 18 +++++--------- src/model/chathistory.cpp | 5 ++-- src/model/ichatlog.h | 2 -- src/widget/form/genericchatform.cpp | 34 +++++++++++++------------- src/widget/form/loadhistorydialog.cpp | 8 ++---- src/widget/form/loadhistorydialog.h | 10 ++------ src/widget/form/searchsettingsform.cpp | 3 ++- 7 files changed, 32 insertions(+), 48 deletions(-) diff --git a/src/chatlog/chatlog.cpp b/src/chatlog/chatlog.cpp index e7fe8237c..3f5729bef 100644 --- a/src/chatlog/chatlog.cpp +++ b/src/chatlog/chatlog.cpp @@ -171,9 +171,8 @@ void ChatLog::updateSceneRect() void ChatLog::layout(int start, int end, qreal width) { - if (lines.empty()) { + if (lines.empty()) return; - } qreal h = 0.0; @@ -316,9 +315,8 @@ void ChatLog::mouseMoveEvent(QMouseEvent* ev) // Much faster than QGraphicsScene::itemAt()! ChatLineContent* ChatLog::getContentFromPos(QPointF scenePos) const { - if (lines.empty()) { + if (lines.empty()) return nullptr; - } auto itr = std::lower_bound(lines.cbegin(), lines.cend(), scenePos.y(), ChatLine::lessThanBSRectBottom); @@ -461,9 +459,8 @@ void ChatLog::scrollToBottom() void ChatLog::startResizeWorker() { - if (lines.empty()) { + if (lines.empty()) return; - } // (re)start the worker if (!workerTimer->isActive()) { @@ -664,9 +661,8 @@ void ChatLog::scrollToLine(ChatLine::Ptr line) void ChatLog::selectAll() { - if (lines.empty()) { + if (lines.empty()) return; - } clearSelection(); @@ -728,9 +724,8 @@ void ChatLog::forceRelayout() void ChatLog::checkVisibility(bool causedWheelEvent) { - if (lines.empty()) { + if (lines.empty()) return; - } // find first visible line auto lowerBound = std::lower_bound(lines.cbegin(), lines.cend(), getVisibleRect().top(), @@ -829,9 +824,8 @@ void ChatLog::updateTypingNotification() qreal posY = 0.0; - if (!lines.empty()) { + if (!lines.empty()) posY = lines.last()->sceneBoundingRect().bottom() + lineSpacing; - } notification->layout(useableWidth(), QPointF(0.0, posY)); } diff --git a/src/model/chathistory.cpp b/src/model/chathistory.cpp index 9aa75e98e..0b4585763 100644 --- a/src/model/chathistory.cpp +++ b/src/model/chathistory.cpp @@ -94,9 +94,10 @@ ChatHistory::ChatHistory(Friend& f_, History* history_, const ICoreIdHandler& co // NOTE: this has to be done _after_ sending all sent messages since initial // state of the message has to be marked according to our dispatch state - auto firstChatLogIdx = sessionChatLog.getFirstIdx().get() < DEF_NUM_MSG_TO_LOAD + constexpr auto defaultNumMessagesToLoad = 100; + auto firstChatLogIdx = sessionChatLog.getFirstIdx().get() < defaultNumMessagesToLoad ? ChatLogIdx(0) - : sessionChatLog.getFirstIdx() - DEF_NUM_MSG_TO_LOAD; + : sessionChatLog.getFirstIdx() - defaultNumMessagesToLoad; if (canUseHistory()) { loadHistoryIntoSessionChatLog(firstChatLogIdx); diff --git a/src/model/ichatlog.h b/src/model/ichatlog.h index 1438610d6..2144c2d0d 100644 --- a/src/model/ichatlog.h +++ b/src/model/ichatlog.h @@ -35,8 +35,6 @@ #include -static const auto DEF_NUM_MSG_TO_LOAD = 100; - using ChatLogIdx = NamedType; Q_DECLARE_METATYPE(ChatLogIdx); diff --git a/src/widget/form/genericchatform.cpp b/src/widget/form/genericchatform.cpp index 315f4c8bf..9ffdb2ee8 100644 --- a/src/widget/form/genericchatform.cpp +++ b/src/widget/form/genericchatform.cpp @@ -386,7 +386,7 @@ GenericChatForm::GenericChatForm(const Contact* contact, IChatLog& chatLog, connect(contact, &Contact::displayedNameChanged, this, &GenericChatForm::setName); auto chatLogIdxRange = chatLog.getNextIdx() - chatLog.getFirstIdx(); - auto firstChatLogIdx = (chatLogIdxRange < DEF_NUM_MSG_TO_LOAD) ? chatLog.getFirstIdx() : chatLog.getNextIdx() - DEF_NUM_MSG_TO_LOAD; + auto firstChatLogIdx = (chatLogIdxRange < 100) ? chatLog.getFirstIdx() : chatLog.getNextIdx() - 100; renderMessages(firstChatLogIdx, chatLog.getNextIdx()); @@ -665,10 +665,10 @@ void GenericChatForm::loadHistoryTo(const QDateTime &time) { auto end = ChatLogIdx(0); if (time.isNull()) { - if (messages.size() + DEF_NUM_MSG_TO_LOAD >= maxMessages) { - end = ChatLogIdx(messages.rbegin()->first.get() - DEF_NUM_MSG_TO_LOAD); - chatWidget->removeLasts(DEF_NUM_MSG_TO_LOAD); - removeLastsMessages(DEF_NUM_MSG_TO_LOAD); + if (messages.size() + 100 >= maxMessages) { + end = ChatLogIdx(messages.rbegin()->first.get() - 100); + chatWidget->removeLasts(100); + removeLastsMessages(100); } else { end = messages.begin()->first; } @@ -677,8 +677,8 @@ void GenericChatForm::loadHistoryTo(const QDateTime &time) } auto begin = ChatLogIdx(0); - if (end.get() > DEF_NUM_MSG_TO_LOAD) { - begin = ChatLogIdx(end.get() - DEF_NUM_MSG_TO_LOAD); + if (end.get() > 100) { + begin = ChatLogIdx(end.get() - 100); } renderMessages(begin, end); @@ -688,10 +688,10 @@ void GenericChatForm::loadHistoryFrom(const QDateTime &time) { auto begin = ChatLogIdx(0); if (time.isNull()) { - if (messages.size() + DEF_NUM_MSG_TO_LOAD >= maxMessages) { - begin = ChatLogIdx(messages.rbegin()->first.get() + DEF_NUM_MSG_TO_LOAD); - chatWidget->removeFirsts(DEF_NUM_MSG_TO_LOAD); - removeFirstsMessages(DEF_NUM_MSG_TO_LOAD); + if (messages.size() + 100 >= maxMessages) { + begin = ChatLogIdx(messages.rbegin()->first.get() + 100); + chatWidget->removeFirsts(100); + removeFirstsMessages(100); } else { begin = messages.rbegin()->first; } @@ -700,9 +700,9 @@ void GenericChatForm::loadHistoryFrom(const QDateTime &time) begin = firstItemAfterDate(time.date(), chatLog); } - int add = DEF_NUM_MSG_TO_LOAD; - if (begin.get() + DEF_NUM_MSG_TO_LOAD > chatLog.getNextIdx().get()) { - add = chatLog.getNextIdx().get() - (begin.get() + DEF_NUM_MSG_TO_LOAD); + 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); @@ -719,8 +719,8 @@ void GenericChatForm::removeFirstsMessages(const int num) void GenericChatForm::removeLastsMessages(const int num) { - if (messages.size() > num) { - messages.erase(std::next(messages.end(), -num), messages.end()); + if (messages.size() > 100) { + messages.erase(std::next(messages.end(), -100), messages.end()); } else { messages.clear(); } @@ -1076,7 +1076,7 @@ void GenericChatForm::goToCurrentDate() chatWidget->clear(); messages.clear(); auto end = ChatLogIdx(chatLog.size() - 1); - auto begin = end.get() > DEF_NUM_MSG_TO_LOAD ? ChatLogIdx(end.get() - DEF_NUM_MSG_TO_LOAD) : ChatLogIdx(0); + auto begin = end.get() > 100 ? ChatLogIdx(end.get() - 100) : ChatLogIdx(0); renderMessages(begin, end); } diff --git a/src/widget/form/loadhistorydialog.cpp b/src/widget/form/loadhistorydialog.cpp index c3246bb8f..12e9d8197 100644 --- a/src/widget/form/loadhistorydialog.cpp +++ b/src/widget/form/loadhistorydialog.cpp @@ -38,15 +38,11 @@ LoadHistoryDialog::LoadHistoryDialog(const IChatLog* chatLog, QWidget* parent) &LoadHistoryDialog::highlightDates); } -LoadHistoryDialog::LoadHistoryDialog(Mode mode, QWidget* parent) +LoadHistoryDialog::LoadHistoryDialog(QWidget* parent) : QDialog(parent) , ui(new Ui::LoadHistoryDialog) { ui->setupUi(this); - - if (mode == Mode::search) { - enableSearchMode(); - } } LoadHistoryDialog::~LoadHistoryDialog() @@ -75,7 +71,7 @@ LoadHistoryDialog::LoadType LoadHistoryDialog::getLoadType() return LoadType::to; } -void LoadHistoryDialog::enableSearchMode() +void LoadHistoryDialog::turnSearchMode() { setWindowTitle(tr("Select Date Dialog")); ui->fromLabel->setText(tr("Select a date")); diff --git a/src/widget/form/loadhistorydialog.h b/src/widget/form/loadhistorydialog.h index 7fdd178b6..59c769573 100644 --- a/src/widget/form/loadhistorydialog.h +++ b/src/widget/form/loadhistorydialog.h @@ -39,24 +39,18 @@ public: to }; - enum Mode { - common, - search - }; - explicit LoadHistoryDialog(const IChatLog* chatLog, QWidget* parent = nullptr); - explicit LoadHistoryDialog(Mode mode, QWidget* parent = nullptr); + explicit LoadHistoryDialog(QWidget* parent = nullptr); ~LoadHistoryDialog(); QDateTime getFromDate(); LoadType getLoadType(); + void turnSearchMode(); public slots: void highlightDates(int year, int month); private: - void enableSearchMode(); - Ui::LoadHistoryDialog* ui; const IChatLog* chatLog; }; diff --git a/src/widget/form/searchsettingsform.cpp b/src/widget/form/searchsettingsform.cpp index c55735099..733c1a4e2 100644 --- a/src/widget/form/searchsettingsform.cpp +++ b/src/widget/form/searchsettingsform.cpp @@ -161,7 +161,8 @@ void SearchSettingsForm::onRegularClicked(const bool checked) void SearchSettingsForm::onChoiceDate() { - LoadHistoryDialog dlg(LoadHistoryDialog::search); + LoadHistoryDialog dlg; + dlg.turnSearchMode(); if (dlg.exec()) { startTime = dlg.getFromDate(); updateStartDateLabel(); From ccc7107f920abaa197b4d216f668241597468ab1 Mon Sep 17 00:00:00 2001 From: Anthony Bilinski Date: Sat, 4 Apr 2020 22:57:29 -0700 Subject: [PATCH 15/20] revert(chatlog): "remove part messages from chat" This reverts commit 4c7ecb60247a0e0d84442e506ae5122204ffb328. --- src/chatlog/chatlog.cpp | 24 ------------------ src/chatlog/chatlog.h | 2 -- src/widget/form/genericchatform.cpp | 39 ++--------------------------- src/widget/form/genericchatform.h | 6 ----- 4 files changed, 2 insertions(+), 69 deletions(-) diff --git a/src/chatlog/chatlog.cpp b/src/chatlog/chatlog.cpp index 3f5729bef..c9a28f8cc 100644 --- a/src/chatlog/chatlog.cpp +++ b/src/chatlog/chatlog.cpp @@ -693,30 +693,6 @@ void ChatLog::reloadTheme() } } -void ChatLog::removeFirsts(const int num) -{ - if (lines.size() > num) { - lines.erase(lines.begin(), lines.begin()+num); - } else { - lines.clear(); - } - - for (int i = 0; i < lines.size(); ++i) { - lines[i]->setRow(i); - } - - moveSelectionRectUpIfSelected(num); -} - -void ChatLog::removeLasts(const int num) -{ - if (lines.size() > num) { - lines.erase(lines.end()-num, lines.end()); - } else { - lines.clear(); - } -} - void ChatLog::forceRelayout() { startResizeWorker(); diff --git a/src/chatlog/chatlog.h b/src/chatlog/chatlog.h index 31ae1048a..31bb64a56 100644 --- a/src/chatlog/chatlog.h +++ b/src/chatlog/chatlog.h @@ -56,8 +56,6 @@ public: void selectAll(); void fontChanged(const QFont& font); void reloadTheme(); - void removeFirsts(const int num); - void removeLasts(const int num); QString getSelectedText() const; diff --git a/src/widget/form/genericchatform.cpp b/src/widget/form/genericchatform.cpp index 9ffdb2ee8..ee06e5c1d 100644 --- a/src/widget/form/genericchatform.cpp +++ b/src/widget/form/genericchatform.cpp @@ -665,13 +665,7 @@ void GenericChatForm::loadHistoryTo(const QDateTime &time) { auto end = ChatLogIdx(0); if (time.isNull()) { - if (messages.size() + 100 >= maxMessages) { - end = ChatLogIdx(messages.rbegin()->first.get() - 100); - chatWidget->removeLasts(100); - removeLastsMessages(100); - } else { - end = messages.begin()->first; - } + end = messages.begin()->first; } else { end = firstItemAfterDate(time.date(), chatLog); } @@ -688,14 +682,7 @@ void GenericChatForm::loadHistoryFrom(const QDateTime &time) { auto begin = ChatLogIdx(0); if (time.isNull()) { - if (messages.size() + 100 >= maxMessages) { - begin = ChatLogIdx(messages.rbegin()->first.get() + 100); - chatWidget->removeFirsts(100); - removeFirstsMessages(100); - } else { - begin = messages.rbegin()->first; - } - + begin = messages.rbegin()->first; } else { begin = firstItemAfterDate(time.date(), chatLog); } @@ -708,24 +695,6 @@ void GenericChatForm::loadHistoryFrom(const QDateTime &time) renderMessages(begin, end); } -void GenericChatForm::removeFirstsMessages(const int num) -{ - if (messages.size() > num) { - messages.erase(messages.begin(), std::next(messages.begin(), num)); - } else { - messages.clear(); - } -} - -void GenericChatForm::removeLastsMessages(const int num) -{ - if (messages.size() > 100) { - messages.erase(std::next(messages.end(), -100), messages.end()); - } else { - messages.clear(); - } -} - void GenericChatForm::disableSearchText() { @@ -1018,10 +987,6 @@ void GenericChatForm::handleSearchResult(SearchResult result, SearchDirection di void GenericChatForm::renderMessage(ChatLogIdx idx) { - if (chatWidget->getLines().size() >= maxMessages) { - chatWidget->removeFirsts(optimalRemove); - removeFirstsMessages(optimalRemove); - } renderMessages(idx, idx + 1); } diff --git a/src/widget/form/genericchatform.h b/src/widget/form/genericchatform.h index 34623abca..adc744e20 100644 --- a/src/widget/form/genericchatform.h +++ b/src/widget/form/genericchatform.h @@ -138,8 +138,6 @@ private: void loadHistory(const QDateTime& time, const LoadHistoryDialog::LoadType type); void loadHistoryTo(const QDateTime& time); void loadHistoryFrom(const QDateTime& time); - void removeFirstsMessages(const int num); - void removeLastsMessages(const int num); protected: ChatMessage::Ptr createMessage(const ToxPk& author, const QString& message, @@ -199,10 +197,6 @@ protected: SearchPos searchPos; std::map messages; bool colorizeNames = false; - -private: - const int maxMessages{300}; - const int optimalRemove{50}; }; #endif // GENERICCHATFORM_H From 8c3f3199ef5e689cba7b42e8ed0d8c8e4ea46c9c Mon Sep 17 00:00:00 2001 From: Anthony Bilinski Date: Sat, 4 Apr 2020 22:57:46 -0700 Subject: [PATCH 16/20] revert(chatlog): "edit position chat after load history" This reverts commit c2d5b422b3ff09af329840dd829d9d2163b79e52. --- src/chatlog/chatlog.cpp | 14 ++----- src/chatlog/chatlog.h | 3 +- src/widget/form/genericchatform.cpp | 64 ++++++++++------------------- src/widget/form/genericchatform.h | 2 - 4 files changed, 27 insertions(+), 56 deletions(-) diff --git a/src/chatlog/chatlog.cpp b/src/chatlog/chatlog.cpp index c9a28f8cc..c8d37720b 100644 --- a/src/chatlog/chatlog.cpp +++ b/src/chatlog/chatlog.cpp @@ -698,7 +698,7 @@ void ChatLog::forceRelayout() startResizeWorker(); } -void ChatLog::checkVisibility(bool causedWheelEvent) +void ChatLog::checkVisibility(bool causedByScroll) { if (lines.empty()) return; @@ -743,10 +743,10 @@ void ChatLog::checkVisibility(bool causedWheelEvent) emit firstVisibleLineChanged(lastLineBeforeVisible, visibleLines.at(0)); } - if (causedWheelEvent) { + if (causedByScroll) { if (lowerBound != lines.cend() && lowerBound->get()->row == 0) { emit loadHistoryLower(); - } else if (upperBound == lines.cend()) { + } else if (upperBound != lines.cend() && upperBound->get()->row >= lines.size() - 10) { emit loadHistoryUpper(); } } @@ -755,7 +755,7 @@ void ChatLog::checkVisibility(bool causedWheelEvent) void ChatLog::scrollContentsBy(int dx, int dy) { QGraphicsView::scrollContentsBy(dx, dy); - checkVisibility(); + checkVisibility(true); } void ChatLog::resizeEvent(QResizeEvent* ev) @@ -951,12 +951,6 @@ void ChatLog::focusOutEvent(QFocusEvent* ev) } } -void ChatLog::wheelEvent(QWheelEvent *event) -{ - QGraphicsView::wheelEvent(event); - checkVisibility(true); -} - void ChatLog::retranslateUi() { copyAction->setText(tr("Copy")); diff --git a/src/chatlog/chatlog.h b/src/chatlog/chatlog.h index 31bb64a56..21da81958 100644 --- a/src/chatlog/chatlog.h +++ b/src/chatlog/chatlog.h @@ -97,7 +97,7 @@ protected: void reposition(int start, int end, qreal deltaY); void updateSceneRect(); - void checkVisibility(bool causedWheelEvent = false); + void checkVisibility(bool causedByScroll = false); void scrollToBottom(); void startResizeWorker(); @@ -110,7 +110,6 @@ protected: virtual void showEvent(QShowEvent*) final override; virtual void focusInEvent(QFocusEvent* ev) final override; virtual void focusOutEvent(QFocusEvent* ev) final override; - virtual void wheelEvent(QWheelEvent *event) final override; void updateMultiSelectionRect(); void updateTypingNotification(); diff --git a/src/widget/form/genericchatform.cpp b/src/widget/form/genericchatform.cpp index ee06e5c1d..d40af7158 100644 --- a/src/widget/form/genericchatform.cpp +++ b/src/widget/form/genericchatform.cpp @@ -652,49 +652,18 @@ void GenericChatForm::loadHistory(const QDateTime &time, const LoadHistoryDialog chatWidget->clear(); messages.clear(); + auto begin = firstItemAfterDate(time.date(), chatLog); + auto end = ChatLogIdx(begin.get() + 1); + + renderMessages(begin, end); + if (type == LoadHistoryDialog::from) { - loadHistoryFrom(time); - auto msg = messages.cbegin()->second; - chatWidget->scrollToLine(msg); + loadHistoryUpper(); } else { - loadHistoryTo(time); + loadHistoryLower(); } } -void GenericChatForm::loadHistoryTo(const QDateTime &time) -{ - auto end = ChatLogIdx(0); - if (time.isNull()) { - end = messages.begin()->first; - } else { - end = firstItemAfterDate(time.date(), chatLog); - } - - auto begin = ChatLogIdx(0); - if (end.get() > 100) { - begin = ChatLogIdx(end.get() - 100); - } - - renderMessages(begin, end); -} - -void GenericChatForm::loadHistoryFrom(const QDateTime &time) -{ - auto begin = ChatLogIdx(0); - if (time.isNull()) { - begin = messages.rbegin()->first; - } else { - begin = firstItemAfterDate(time.date(), chatLog); - } - - 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::disableSearchText() { @@ -1048,14 +1017,25 @@ void GenericChatForm::goToCurrentDate() void GenericChatForm::loadHistoryLower() { - loadHistoryTo(QDateTime()); + auto end = messages.begin()->first; + auto begin = ChatLogIdx(0); + if (end.get() > 100) { + begin = ChatLogIdx(end.get() - 100); + } + + renderMessages(begin, end); } void GenericChatForm::loadHistoryUpper() { - auto msg = messages.crbegin()->second; - loadHistoryFrom(QDateTime()); - chatWidget->scrollToLine(msg); + auto begin = messages.rbegin()->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& prevLine, const ChatLine::Ptr& topLine) diff --git a/src/widget/form/genericchatform.h b/src/widget/form/genericchatform.h index adc744e20..38b405639 100644 --- a/src/widget/form/genericchatform.h +++ b/src/widget/form/genericchatform.h @@ -136,8 +136,6 @@ private: void addSystemDateMessage(const QDate& date); QDateTime getTime(const ChatLine::Ptr& chatLine) const; void loadHistory(const QDateTime& time, const LoadHistoryDialog::LoadType type); - void loadHistoryTo(const QDateTime& time); - void loadHistoryFrom(const QDateTime& time); protected: ChatMessage::Ptr createMessage(const ToxPk& author, const QString& message, From 5efb0ba020716a4b28b533f85b7001c450f92bf0 Mon Sep 17 00:00:00 2001 From: Anthony Bilinski Date: Sat, 4 Apr 2020 22:59:09 -0700 Subject: [PATCH 17/20] revert(chatlog): "add action "Go to current date"" This reverts commit 2a9648d12c2f71efa8f9722f1c0fa6e39e701c47. --- src/model/chathistory.cpp | 9 --------- src/model/chathistory.h | 1 - src/model/ichatlog.h | 2 -- src/model/sessionchatlog.cpp | 5 ----- src/model/sessionchatlog.h | 1 - src/widget/form/genericchatform.cpp | 18 ------------------ src/widget/form/genericchatform.h | 2 -- 7 files changed, 38 deletions(-) diff --git a/src/model/chathistory.cpp b/src/model/chathistory.cpp index 0b4585763..b0badb9bb 100644 --- a/src/model/chathistory.cpp +++ b/src/model/chathistory.cpp @@ -204,15 +204,6 @@ std::vector ChatHistory::getDateIdxs(const QDate& } } -std::size_t ChatHistory::size() const -{ - if (canUseHistory()) { - return history->getNumMessagesForFriend(f.getPublicKey()); - } - - return sessionChatLog.size(); -} - void ChatHistory::onFileUpdated(const ToxPk& sender, const ToxFile& file) { if (canUseHistory()) { diff --git a/src/model/chathistory.h b/src/model/chathistory.h index d9b25032d..a1625e8ce 100644 --- a/src/model/chathistory.h +++ b/src/model/chathistory.h @@ -42,7 +42,6 @@ public: ChatLogIdx getFirstIdx() const override; ChatLogIdx getNextIdx() const override; std::vector getDateIdxs(const QDate& startDate, size_t maxDates) const override; - std::size_t size() const override; public slots: void onFileUpdated(const ToxPk& sender, const ToxFile& file); diff --git a/src/model/ichatlog.h b/src/model/ichatlog.h index 2144c2d0d..bc3b4ad72 100644 --- a/src/model/ichatlog.h +++ b/src/model/ichatlog.h @@ -138,8 +138,6 @@ public: virtual std::vector getDateIdxs(const QDate& startDate, size_t maxDates) const = 0; - virtual std::size_t size() const = 0; - signals: void itemUpdated(ChatLogIdx idx); }; diff --git a/src/model/sessionchatlog.cpp b/src/model/sessionchatlog.cpp index b52c20d35..f4a224f0b 100644 --- a/src/model/sessionchatlog.cpp +++ b/src/model/sessionchatlog.cpp @@ -289,11 +289,6 @@ std::vector SessionChatLog::getDateIdxs(const QDat return ret; } -std::size_t SessionChatLog::size() const -{ - return items.size(); -} - void SessionChatLog::insertCompleteMessageAtIdx(ChatLogIdx idx, const ToxPk& sender, const QString& senderName, const ChatLogMessage& message) { diff --git a/src/model/sessionchatlog.h b/src/model/sessionchatlog.h index b23a0cb18..51234b847 100644 --- a/src/model/sessionchatlog.h +++ b/src/model/sessionchatlog.h @@ -45,7 +45,6 @@ public: ChatLogIdx getFirstIdx() const override; ChatLogIdx getNextIdx() const override; std::vector getDateIdxs(const QDate& startDate, size_t maxDates) const override; - std::size_t size() const override; void insertCompleteMessageAtIdx(ChatLogIdx idx, const ToxPk& sender, const QString& senderName, const ChatLogMessage& message); diff --git a/src/widget/form/genericchatform.cpp b/src/widget/form/genericchatform.cpp index d40af7158..7a61f4179 100644 --- a/src/widget/form/genericchatform.cpp +++ b/src/widget/form/genericchatform.cpp @@ -326,13 +326,6 @@ GenericChatForm::GenericChatForm(const Contact* contact, IChatLog& chatLog, quoteAction = menu.addAction(QIcon(), QString(), this, SLOT(quoteSelectedText()), QKeySequence(Qt::ALT + Qt::Key_Q)); addAction(quoteAction); - - menu.addSeparator(); - - goCurrentDateAction = menu.addAction(QIcon(), QString(), this, SLOT(goToCurrentDate()), - QKeySequence(Qt::CTRL + Qt::Key_G)); - addAction(goCurrentDateAction); - menu.addSeparator(); searchAction = menu.addAction(QIcon(), QString(), this, SLOT(searchFormShow()), @@ -1005,16 +998,6 @@ void GenericChatForm::renderMessages(ChatLogIdx begin, ChatLogIdx end, } } -void GenericChatForm::goToCurrentDate() -{ - chatWidget->clear(); - messages.clear(); - auto end = ChatLogIdx(chatLog.size() - 1); - auto begin = end.get() > 100 ? ChatLogIdx(end.get() - 100) : ChatLogIdx(0); - - renderMessages(begin, end); -} - void GenericChatForm::loadHistoryLower() { auto end = messages.begin()->first; @@ -1066,7 +1049,6 @@ void GenericChatForm::retranslateUi() quoteAction->setText(tr("Quote selected text")); copyLinkAction->setText(tr("Copy link address")); searchAction->setText(tr("Search in text")); - goCurrentDateAction->setText(tr("Go to current date")); loadHistoryAction->setText(tr("Load chat history...")); exportChatAction->setText(tr("Export to file")); } diff --git a/src/widget/form/genericchatform.h b/src/widget/form/genericchatform.h index 38b405639..f3621f14a 100644 --- a/src/widget/form/genericchatform.h +++ b/src/widget/form/genericchatform.h @@ -126,7 +126,6 @@ protected slots: void renderMessage(ChatLogIdx idx); void renderMessages(ChatLogIdx begin, ChatLogIdx end, std::function onCompletion = std::function()); - void goToCurrentDate(); void loadHistoryLower(); void loadHistoryUpper(); @@ -166,7 +165,6 @@ protected: QAction* searchAction; QAction* loadHistoryAction; QAction* exportChatAction; - QAction* goCurrentDateAction; QMenu menu; From 8e03aa4b179d5aa05533121f458a43246a3cc6aa Mon Sep 17 00:00:00 2001 From: Anthony Bilinski Date: Sun, 5 Apr 2020 01:19:05 -0700 Subject: [PATCH 18/20] revert(chatlog): "edit load history in search" This reverts commit 8c4b1e00a128b739904ed60543132b34817f0ba5. --- src/chatlog/content/text.cpp | 23 ++++---------- src/chatlog/content/text.h | 4 --- src/persistence/history.cpp | 14 ++++---- src/widget/form/genericchatform.cpp | 44 ++++++++++---------------- src/widget/form/genericchatform.h | 2 -- src/widget/form/loadhistorydialog.cpp | 12 ++++--- src/widget/form/loadhistorydialog.h | 3 +- src/widget/form/loadhistorydialog.ui | 2 +- src/widget/form/searchsettingsform.cpp | 13 ++++---- src/widget/form/searchsettingsform.h | 2 +- src/widget/searchtypes.h | 4 +-- 11 files changed, 51 insertions(+), 72 deletions(-) diff --git a/src/chatlog/content/text.cpp b/src/chatlog/content/text.cpp index e1877ad23..d32adc4e8 100644 --- a/src/chatlog/content/text.cpp +++ b/src/chatlog/content/text.cpp @@ -66,11 +66,9 @@ void Text::selectText(const QString& txt, const std::pair& point) return; } - selectCursor = doc->find(txt, point.first); - selectPoint = point; + auto cursor = doc->find(txt, point.first); - regenerate(); - update(); + selectText(cursor, point); } void Text::selectText(const QRegularExpression &exp, const std::pair& point) @@ -81,20 +79,14 @@ void Text::selectText(const QRegularExpression &exp, const std::pair& return; } - selectCursor = doc->find(exp, point.first); - selectPoint = point; + auto cursor = doc->find(exp, point.first); - regenerate(); - update(); + selectText(cursor, point); } void Text::deselectText() { dirty = true; - - selectCursor = QTextCursor(); - selectPoint = {0, 0}; - regenerate(); update(); } @@ -363,10 +355,6 @@ void Text::regenerate() dirty = false; } - if (!selectCursor.isNull()) { - selectText(selectCursor, selectPoint); - } - // if we are not visible -> free mem if (!keepInMemory) freeResources(); @@ -474,6 +462,9 @@ void Text::selectText(QTextCursor& cursor, const std::pair& point) QTextCharFormat format; format.setBackground(QBrush(Style::getColor(Style::SearchHighlighted))); cursor.mergeCharFormat(format); + + regenerate(); + update(); } } diff --git a/src/chatlog/content/text.h b/src/chatlog/content/text.h index 0f58bdb4a..e1f69112b 100644 --- a/src/chatlog/content/text.h +++ b/src/chatlog/content/text.h @@ -24,7 +24,6 @@ #include "src/widget/style.h" #include -#include class QTextDocument; @@ -111,9 +110,6 @@ private: TextType textType; QColor color; QColor customColor; - - QTextCursor selectCursor; - std::pair selectPoint{0, 0}; }; #endif // TEXT_H diff --git a/src/persistence/history.cpp b/src/persistence/history.cpp index d641e8cbd..6e9f29f6f 100644 --- a/src/persistence/history.cpp +++ b/src/persistence/history.cpp @@ -865,14 +865,14 @@ QDateTime History::getDateWhereFindPhrase(const QString& friendPk, const QDateTi break; } - QDateTime time = from; + QDateTime date = from; - if (!time.isValid()) { - time = QDateTime::currentDateTime(); + if (!date.isValid()) { + date = QDateTime::currentDateTime(); } if (parameter.period == PeriodSearch::AfterDate || parameter.period == PeriodSearch::BeforeDate) { - time = parameter.time; + date = QDateTime(parameter.date); } QString period; @@ -882,15 +882,15 @@ QDateTime History::getDateWhereFindPhrase(const QString& friendPk, const QDateTi break; case PeriodSearch::AfterDate: period = QStringLiteral("AND timestamp > '%1' ORDER BY timestamp ASC LIMIT 1;") - .arg(time.toMSecsSinceEpoch()); + .arg(date.toMSecsSinceEpoch()); break; case PeriodSearch::BeforeDate: period = QStringLiteral("AND timestamp < '%1' ORDER BY timestamp DESC LIMIT 1;") - .arg(time.toMSecsSinceEpoch()); + .arg(date.toMSecsSinceEpoch()); break; default: period = QStringLiteral("AND timestamp < '%1' ORDER BY timestamp DESC LIMIT 1;") - .arg(time.toMSecsSinceEpoch()); + .arg(date.toMSecsSinceEpoch()); break; } diff --git a/src/widget/form/genericchatform.cpp b/src/widget/form/genericchatform.cpp index 7a61f4179..13d7bb1bb 100644 --- a/src/widget/form/genericchatform.cpp +++ b/src/widget/form/genericchatform.cpp @@ -37,6 +37,7 @@ #include "src/widget/contentlayout.h" #include "src/widget/emoticonswidget.h" #include "src/widget/form/chatform.h" +#include "src/widget/form/loadhistorydialog.h" #include "src/widget/maskablepixmapwidget.h" #include "src/widget/searchform.h" #include "src/widget/style.h" @@ -640,23 +641,6 @@ QDateTime GenericChatForm::getTime(const ChatLine::Ptr &chatLine) const return QDateTime(); } -void GenericChatForm::loadHistory(const QDateTime &time, const LoadHistoryDialog::LoadType type) -{ - chatWidget->clear(); - messages.clear(); - - auto begin = firstItemAfterDate(time.date(), chatLog); - auto end = ChatLogIdx(begin.get() + 1); - - renderMessages(begin, end); - - if (type == LoadHistoryDialog::from) { - loadHistoryUpper(); - } else { - loadHistoryLower(); - } -} - void GenericChatForm::disableSearchText() { @@ -821,10 +805,22 @@ void GenericChatForm::onLoadHistory() { LoadHistoryDialog dlg(&chatLog); if (dlg.exec()) { + chatWidget->clear(); + messages.clear(); + QDateTime time = dlg.getFromDate(); auto type = dlg.getLoadType(); - loadHistory(time, type); + auto begin = firstItemAfterDate(dlg.getFromDate().date(), chatLog); + auto end = ChatLogIdx(begin.get() + 1); + + renderMessages(begin, end); + + if (type == LoadHistoryDialog::from) { + loadHistoryUpper(); + } else { + loadHistoryLower(); + } } } @@ -871,12 +867,6 @@ void GenericChatForm::searchInBegin(const QString& phrase, const ParameterSearch { disableSearchText(); - 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: { @@ -894,13 +884,13 @@ void GenericChatForm::searchInBegin(const QString& phrase, const ParameterSearch } case PeriodSearch::AfterDate: { bForwardSearch = true; - searchPos.logIdx = firstItemAfterDate(parameter.time.date(), chatLog); + searchPos.logIdx = firstItemAfterDate(parameter.date, chatLog); searchPos.numMatches = 0; break; } case PeriodSearch::BeforeDate: { bForwardSearch = false; - searchPos.logIdx = firstItemAfterDate(parameter.time.date(), chatLog); + searchPos.logIdx = firstItemAfterDate(parameter.date, chatLog); searchPos.numMatches = 0; break; } @@ -1011,7 +1001,7 @@ void GenericChatForm::loadHistoryLower() void GenericChatForm::loadHistoryUpper() { - auto begin = messages.rbegin()->first; + auto begin = messages.end()->first; int add = 100; if (begin.get() + 100 > chatLog.getNextIdx().get()) { diff --git a/src/widget/form/genericchatform.h b/src/widget/form/genericchatform.h index f3621f14a..83f2b1d90 100644 --- a/src/widget/form/genericchatform.h +++ b/src/widget/form/genericchatform.h @@ -23,7 +23,6 @@ #include "src/chatlog/chatmessage.h" #include "src/core/toxpk.h" #include "src/model/ichatlog.h" -#include "src/widget/form/loadhistorydialog.h" #include "src/widget/searchtypes.h" #include @@ -134,7 +133,6 @@ private: void retranslateUi(); void addSystemDateMessage(const QDate& date); QDateTime getTime(const ChatLine::Ptr& chatLine) const; - void loadHistory(const QDateTime& time, const LoadHistoryDialog::LoadType type); protected: ChatMessage::Ptr createMessage(const ToxPk& author, const QString& message, diff --git a/src/widget/form/loadhistorydialog.cpp b/src/widget/form/loadhistorydialog.cpp index 12e9d8197..2ff15eeb4 100644 --- a/src/widget/form/loadhistorydialog.cpp +++ b/src/widget/form/loadhistorydialog.cpp @@ -71,12 +71,14 @@ LoadHistoryDialog::LoadType LoadHistoryDialog::getLoadType() return LoadType::to; } -void LoadHistoryDialog::turnSearchMode() +void LoadHistoryDialog::setTitle(const QString& title) { - setWindowTitle(tr("Select Date Dialog")); - ui->fromLabel->setText(tr("Select a date")); - ui->loadTypeComboBox->setVisible(false); - ui->infoLabel->setVisible(false); + setWindowTitle(title); +} + +void LoadHistoryDialog::setInfoLabel(const QString& info) +{ + ui->fromLabel->setText(info); } void LoadHistoryDialog::highlightDates(int year, int month) diff --git a/src/widget/form/loadhistorydialog.h b/src/widget/form/loadhistorydialog.h index 59c769573..dfb046867 100644 --- a/src/widget/form/loadhistorydialog.h +++ b/src/widget/form/loadhistorydialog.h @@ -45,7 +45,8 @@ public: QDateTime getFromDate(); LoadType getLoadType(); - void turnSearchMode(); + void setTitle(const QString& title); + void setInfoLabel(const QString& info); public slots: void highlightDates(int year, int month); diff --git a/src/widget/form/loadhistorydialog.ui b/src/widget/form/loadhistorydialog.ui index b382c706d..5bf3fc553 100644 --- a/src/widget/form/loadhistorydialog.ui +++ b/src/widget/form/loadhistorydialog.ui @@ -41,7 +41,7 @@ - + (about 100 messages are loaded) diff --git a/src/widget/form/searchsettingsform.cpp b/src/widget/form/searchsettingsform.cpp index 733c1a4e2..abdf6b40c 100644 --- a/src/widget/form/searchsettingsform.cpp +++ b/src/widget/form/searchsettingsform.cpp @@ -86,7 +86,7 @@ ParameterSearch SearchSettingsForm::getParameterSearch() break; } - ps.time = startTime; + ps.date = startDate; ps.isUpdate = isUpdate; isUpdate = false; @@ -101,7 +101,7 @@ void SearchSettingsForm::reloadTheme() void SearchSettingsForm::updateStartDateLabel() { - ui->startDateLabel->setText(startTime.toString(Settings::getInstance().getDateFormat())); + ui->startDateLabel->setText(startDate.toString(Settings::getInstance().getDateFormat())); } void SearchSettingsForm::setUpdate(const bool isUpdate) @@ -119,8 +119,8 @@ void SearchSettingsForm::onStartSearchSelected(const int index) ui->choiceDateButton->setProperty("state", QStringLiteral("green")); ui->choiceDateButton->setStyleSheet(Style::getStylesheet(QStringLiteral("chatForm/buttons.css"))); - if (startTime.isNull()) { - startTime = QDateTime::currentDateTime(); + if (startDate.isNull()) { + startDate = QDate::currentDate(); updateStartDateLabel(); } @@ -162,9 +162,10 @@ void SearchSettingsForm::onRegularClicked(const bool checked) void SearchSettingsForm::onChoiceDate() { LoadHistoryDialog dlg; - dlg.turnSearchMode(); + dlg.setTitle(tr("Select Date Dialog")); + dlg.setInfoLabel(tr("Select a date")); if (dlg.exec()) { - startTime = dlg.getFromDate(); + startDate = dlg.getFromDate().date(); updateStartDateLabel(); } diff --git a/src/widget/form/searchsettingsform.h b/src/widget/form/searchsettingsform.h index 1814c4e75..91d665be5 100644 --- a/src/widget/form/searchsettingsform.h +++ b/src/widget/form/searchsettingsform.h @@ -40,7 +40,7 @@ public: private: Ui::SearchSettingsForm *ui; - QDateTime startTime; + QDate startDate; bool isUpdate{false}; void updateStartDateLabel(); diff --git a/src/widget/searchtypes.h b/src/widget/searchtypes.h index 7130887b6..cbfce5738 100644 --- a/src/widget/searchtypes.h +++ b/src/widget/searchtypes.h @@ -48,13 +48,13 @@ enum class SearchDirection { struct ParameterSearch { FilterSearch filter{FilterSearch::None}; PeriodSearch period{PeriodSearch::None}; - QDateTime time; + QDate date; bool isUpdate{false}; bool operator ==(const ParameterSearch& other) { return filter == other.filter && period == other.period && - time == other.time; + date == other.date; } bool operator !=(const ParameterSearch& other) { From c75d8c8d3ea862e4d59c9a42a1d36446d3d615cb Mon Sep 17 00:00:00 2001 From: Anthony Bilinski Date: Sun, 5 Apr 2020 01:30:27 -0700 Subject: [PATCH 19/20] revert(chatlog): "edit function "Load chat history"" This reverts commit 6de1173c172a14aec3dba289dd63d5857fe69d19. --- src/widget/form/genericchatform.cpp | 30 +++++--------- src/widget/form/loadhistorydialog.cpp | 9 ---- src/widget/form/loadhistorydialog.h | 6 --- src/widget/form/loadhistorydialog.ui | 60 +++++---------------------- 4 files changed, 22 insertions(+), 83 deletions(-) diff --git a/src/widget/form/genericchatform.cpp b/src/widget/form/genericchatform.cpp index 13d7bb1bb..e0a68fc29 100644 --- a/src/widget/form/genericchatform.cpp +++ b/src/widget/form/genericchatform.cpp @@ -805,22 +805,12 @@ void GenericChatForm::onLoadHistory() { LoadHistoryDialog dlg(&chatLog); if (dlg.exec()) { + QDateTime time = dlg.getFromDate(); + auto idx = firstItemAfterDate(dlg.getFromDate().date(), chatLog); + auto end = ChatLogIdx(idx.get() + 100); chatWidget->clear(); messages.clear(); - - QDateTime time = dlg.getFromDate(); - auto type = dlg.getLoadType(); - - auto begin = firstItemAfterDate(dlg.getFromDate().date(), chatLog); - auto end = ChatLogIdx(begin.get() + 1); - - renderMessages(begin, end); - - if (type == LoadHistoryDialog::from) { - loadHistoryUpper(); - } else { - loadHistoryLower(); - } + renderMessages(idx, end); } } @@ -990,13 +980,15 @@ void GenericChatForm::renderMessages(ChatLogIdx begin, ChatLogIdx end, void GenericChatForm::loadHistoryLower() { - auto end = messages.begin()->first; - auto begin = ChatLogIdx(0); - if (end.get() > 100) { - begin = ChatLogIdx(end.get() - 100); + auto begin = messages.begin()->first; + + if (begin.get() > 100) { + begin = ChatLogIdx(begin.get() - 100); + } else { + begin = ChatLogIdx(0); } - renderMessages(begin, end); + renderMessages(begin, chatLog.getNextIdx()); } void GenericChatForm::loadHistoryUpper() diff --git a/src/widget/form/loadhistorydialog.cpp b/src/widget/form/loadhistorydialog.cpp index 2ff15eeb4..0e1925245 100644 --- a/src/widget/form/loadhistorydialog.cpp +++ b/src/widget/form/loadhistorydialog.cpp @@ -62,15 +62,6 @@ QDateTime LoadHistoryDialog::getFromDate() return res; } -LoadHistoryDialog::LoadType LoadHistoryDialog::getLoadType() -{ - if (ui->loadTypeComboBox->currentIndex() == 0) { - return LoadType::from; - } - - return LoadType::to; -} - void LoadHistoryDialog::setTitle(const QString& title) { setWindowTitle(title); diff --git a/src/widget/form/loadhistorydialog.h b/src/widget/form/loadhistorydialog.h index dfb046867..092bd8b15 100644 --- a/src/widget/form/loadhistorydialog.h +++ b/src/widget/form/loadhistorydialog.h @@ -34,17 +34,11 @@ class LoadHistoryDialog : public QDialog Q_OBJECT public: - enum LoadType { - from, - to - }; - explicit LoadHistoryDialog(const IChatLog* chatLog, QWidget* parent = nullptr); explicit LoadHistoryDialog(QWidget* parent = nullptr); ~LoadHistoryDialog(); QDateTime getFromDate(); - LoadType getLoadType(); void setTitle(const QString& title); void setInfoLabel(const QString& info); diff --git a/src/widget/form/loadhistorydialog.ui b/src/widget/form/loadhistorydialog.ui index 5bf3fc553..fc4ab5029 100644 --- a/src/widget/form/loadhistorydialog.ui +++ b/src/widget/form/loadhistorydialog.ui @@ -6,8 +6,8 @@ 0 0 - 410 - 332 + 347 + 264 @@ -16,60 +16,22 @@ true - - - - - - - Load history - - - - - - - - from - - - - - to - - - - - - - - (about 100 messages are loaded) - - - - - - - Qt::Horizontal - - - - 17 - 20 - - - - - + + + + + Load history from: + + - + false - + Qt::Horizontal From 7b7950e7f7c8263fcd34ae10dcd312b7cf51ffe7 Mon Sep 17 00:00:00 2001 From: Anthony Bilinski Date: Sun, 5 Apr 2020 01:35:15 -0700 Subject: [PATCH 20/20] revert(chatlog): "load messages from the database after date" This reverts commit b705ac806059717d98cfd60b1b2f1abdaa84e6a9. --- src/chatlog/chatlog.cpp | 24 ++---------------------- src/chatlog/chatlog.h | 2 -- src/widget/form/genericchatform.cpp | 18 +----------------- src/widget/form/genericchatform.h | 1 - 4 files changed, 3 insertions(+), 42 deletions(-) diff --git a/src/chatlog/chatlog.cpp b/src/chatlog/chatlog.cpp index c8d37720b..1313924d5 100644 --- a/src/chatlog/chatlog.cpp +++ b/src/chatlog/chatlog.cpp @@ -385,22 +385,6 @@ void ChatLog::insertChatlineAtBottom(ChatLine::Ptr l) updateTypingNotification(); } -void ChatLog::insertChatlineAtBottom(const QList& 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()) @@ -743,12 +727,8 @@ void ChatLog::checkVisibility(bool causedByScroll) emit firstVisibleLineChanged(lastLineBeforeVisible, visibleLines.at(0)); } - 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(); - } + if (causedByScroll && lowerBound != lines.cend() && lowerBound->get()->row == 0) { + emit loadHistoryLower(); } } diff --git a/src/chatlog/chatlog.h b/src/chatlog/chatlog.h index 21da81958..8c6d2b512 100644 --- a/src/chatlog/chatlog.h +++ b/src/chatlog/chatlog.h @@ -43,7 +43,6 @@ public: virtual ~ChatLog(); void insertChatlineAtBottom(ChatLine::Ptr l); - void insertChatlineAtBottom(const QList& newLines); void insertChatlineOnTop(ChatLine::Ptr l); void insertChatlinesOnTop(const QList& newLines); void clearSelection(); @@ -74,7 +73,6 @@ signals: void workerTimeoutFinished(); void firstVisibleLineChanged(const ChatLine::Ptr& prevLine, const ChatLine::Ptr& firstLine); void loadHistoryLower(); - void loadHistoryUpper(); public slots: void forceRelayout(); diff --git a/src/widget/form/genericchatform.cpp b/src/widget/form/genericchatform.cpp index e0a68fc29..65ffafa53 100644 --- a/src/widget/form/genericchatform.cpp +++ b/src/widget/form/genericchatform.cpp @@ -354,7 +354,6 @@ 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); @@ -807,10 +806,7 @@ void GenericChatForm::onLoadHistory() if (dlg.exec()) { QDateTime time = dlg.getFromDate(); auto idx = firstItemAfterDate(dlg.getFromDate().date(), chatLog); - auto end = ChatLogIdx(idx.get() + 100); - chatWidget->clear(); - messages.clear(); - renderMessages(idx, end); + renderMessages(idx, chatLog.getNextIdx()); } } @@ -991,18 +987,6 @@ 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& prevLine, const ChatLine::Ptr& topLine) { // If the dateInfo is visible we need to pretend the top line is the one diff --git a/src/widget/form/genericchatform.h b/src/widget/form/genericchatform.h index 83f2b1d90..5a8c21fd9 100644 --- a/src/widget/form/genericchatform.h +++ b/src/widget/form/genericchatform.h @@ -127,7 +127,6 @@ protected slots: std::function onCompletion = std::function()); void loadHistoryLower(); - void loadHistoryUpper(); private: void retranslateUi();