From b0f32379d098cf525bcbe003d7add071c708bd69 Mon Sep 17 00:00:00 2001 From: TriKriSta Date: Sun, 23 Jun 2019 13:20:48 +0300 Subject: [PATCH] fix: check time for get num messages for friend (fix #5714) --- src/persistence/history.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/persistence/history.cpp b/src/persistence/history.cpp index 604961416..fc74ca66a 100644 --- a/src/persistence/history.cpp +++ b/src/persistence/history.cpp @@ -523,10 +523,7 @@ void History::setFileFinished(const QString& fileId, bool success, const QString size_t History::getNumMessagesForFriend(const ToxPk& friendPk) { - return getNumMessagesForFriendBeforeDate(friendPk, - // Maximum possible time - QDateTime::fromMSecsSinceEpoch( - std::numeric_limits::max())); + return getNumMessagesForFriendBeforeDate(friendPk, QDateTime()); } size_t History::getNumMessagesForFriendBeforeDate(const ToxPk& friendPk, const QDateTime& date) @@ -534,10 +531,14 @@ size_t History::getNumMessagesForFriendBeforeDate(const ToxPk& friendPk, const Q QString queryText = QString("SELECT COUNT(history.id) " "FROM history " "JOIN peers chat ON chat_id = chat.id " - "WHERE chat.public_key='%1'" - "AND timestamp < %2;") - .arg(friendPk.toString()) - .arg(date.toMSecsSinceEpoch()); + "WHERE chat.public_key='%1'") + .arg(friendPk.toString()); + + if (date.isNull()) { + queryText += ";"; + } else { + queryText += QString(" AND timestamp < %1;").arg(date.toMSecsSinceEpoch()); + } size_t numMessages = 0; auto rowCallback = [&numMessages](const QVector& row) { @@ -798,4 +799,4 @@ void History::markAsSent(RowId messageId) } db->execLater(QString("DELETE FROM faux_offline_pending WHERE id=%1;").arg(messageId.get())); -} \ No newline at end of file +}