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

fix: check time for get num messages for friend (fix #5714)

This commit is contained in:
TriKriSta 2019-06-23 13:20:48 +03:00
parent 033f28e67e
commit b0f32379d0

View File

@ -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<int64_t>::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<QVariant>& row) {
@ -798,4 +799,4 @@ void History::markAsSent(RowId messageId)
}
db->execLater(QString("DELETE FROM faux_offline_pending WHERE id=%1;").arg(messageId.get()));
}
}