From 8d822f2cb4406f3cc363d18b6f6f3293f9cba4ac Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Thu, 19 Aug 2021 11:16:34 +0800 Subject: [PATCH] Improve "last activity" calculation in WebAPI (#15339) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: 秦风 Co-authored-by: Chocobo1 --- src/webui/api/serialize/serialize_torrent.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/webui/api/serialize/serialize_torrent.cpp b/src/webui/api/serialize/serialize_torrent.cpp index 829dee936..9056bd039 100644 --- a/src/webui/api/serialize/serialize_torrent.cpp +++ b/src/webui/api/serialize/serialize_torrent.cpp @@ -97,6 +97,14 @@ QVariantMap serialize(const BitTorrent::Torrent &torrent) return (ratio > BitTorrent::Torrent::MAX_RATIO) ? -1 : ratio; }; + const auto getLastActivityTime = [&torrent]() -> qlonglong + { + const qlonglong timeSinceActivity = torrent.timeSinceActivity(); + return (timeSinceActivity < 0) + ? torrent.addedTime().toSecsSinceEpoch() + : (QDateTime::currentDateTime().toSecsSinceEpoch() - timeSinceActivity); + }; + return { {KEY_TORRENT_ID, torrent.id().toString()}, {KEY_TORRENT_INFOHASHV1, torrent.infoHash().v1().toString()}, @@ -145,7 +153,7 @@ QVariantMap serialize(const BitTorrent::Torrent &torrent) {KEY_TORRENT_AUTO_TORRENT_MANAGEMENT, torrent.isAutoTMMEnabled()}, {KEY_TORRENT_TIME_ACTIVE, torrent.activeTime()}, {KEY_TORRENT_SEEDING_TIME, torrent.seedingTime()}, - {KEY_TORRENT_LAST_ACTIVITY_TIME, (QDateTime::currentDateTime().toSecsSinceEpoch() - torrent.timeSinceActivity())}, + {KEY_TORRENT_LAST_ACTIVITY_TIME, getLastActivityTime()}, {KEY_TORRENT_AVAILABILITY, torrent.distributedCopies()}, {KEY_TORRENT_TOTAL_SIZE, torrent.totalSize()}