From d0f4c336baaf8922215994d4adb7191cb45d7695 Mon Sep 17 00:00:00 2001 From: Mick Sayson Date: Sat, 30 Jan 2021 17:02:40 -0800 Subject: [PATCH] refactor(chatform): Use IChatLog to get date in GenericChatForm * Allows for deletion of APIs returning ChatLine::Ptr from ChatLog * Bonus removal of unused "getFirstTime" function from GenericChatForm --- src/chatlog/chatlog.cpp | 21 --------------------- src/chatlog/chatlog.h | 3 --- src/widget/form/genericchatform.cpp | 8 +++----- src/widget/form/genericchatform.h | 1 - 4 files changed, 3 insertions(+), 30 deletions(-) diff --git a/src/chatlog/chatlog.cpp b/src/chatlog/chatlog.cpp index e0c5e7637..0c067488b 100644 --- a/src/chatlog/chatlog.cpp +++ b/src/chatlog/chatlog.cpp @@ -595,27 +595,6 @@ ChatLine::Ptr ChatLog::getTypingNotification() const return typingNotification; } -QVector ChatLog::getLines() -{ - return lines; -} - -ChatLine::Ptr ChatLog::getLatestLine() const -{ - if (!lines.empty()) { - return lines.last(); - } - return nullptr; -} - -ChatLine::Ptr ChatLog::getFirstLine() const -{ - if (!lines.empty()) { - return lines.first(); - } - return nullptr; -} - /** * @brief Finds the chat line object at a position on screen * @param pos Position on screen in global coordinates diff --git a/src/chatlog/chatlog.h b/src/chatlog/chatlog.h index 6d5b3bf49..9839f2c99 100644 --- a/src/chatlog/chatlog.h +++ b/src/chatlog/chatlog.h @@ -67,9 +67,6 @@ public: bool hasTextToBeCopied() const; ChatLine::Ptr getTypingNotification() const; - QVector getLines(); - ChatLine::Ptr getLatestLine() const; - ChatLine::Ptr getFirstLine() const; ChatLineContent* getContentFromGlobalPos(QPoint pos) const; const uint repNameAfter = 5 * 60; diff --git a/src/widget/form/genericchatform.cpp b/src/widget/form/genericchatform.cpp index 10d974c1d..7d52c4798 100644 --- a/src/widget/form/genericchatform.cpp +++ b/src/widget/form/genericchatform.cpp @@ -402,12 +402,10 @@ void GenericChatForm::hideFileMenu() QDateTime GenericChatForm::getLatestTime() const { - return getTime(chatWidget->getLatestLine()); -} + if (chatLog.getFirstIdx() == chatLog.getNextIdx()) + return QDateTime(); -QDateTime GenericChatForm::getFirstTime() const -{ - return getTime(chatWidget->getFirstLine()); + return chatLog.at(chatLog.getNextIdx() - 1).getTimestamp(); } void GenericChatForm::reloadTheme() diff --git a/src/widget/form/genericchatform.h b/src/widget/form/genericchatform.h index 01a2c1f8f..3919ac670 100644 --- a/src/widget/form/genericchatform.h +++ b/src/widget/form/genericchatform.h @@ -80,7 +80,6 @@ public: const QDateTime& datetime); static QString resolveToxPk(const ToxPk& pk); QDateTime getLatestTime() const; - QDateTime getFirstTime() const; signals: void messageInserted();