From 250cac73b6fb2b44394e1f4eff556de17140b757 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 | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/webui/api/serialize/serialize_torrent.cpp b/src/webui/api/serialize/serialize_torrent.cpp index 9b4479429..98d071995 100644 --- a/src/webui/api/serialize/serialize_torrent.cpp +++ b/src/webui/api/serialize/serialize_torrent.cpp @@ -95,11 +95,12 @@ QVariantMap serialize(const BitTorrent::Torrent &torrent) return (ratio > BitTorrent::Torrent::MAX_RATIO) ? -1 : ratio; }; - const auto adjustLastActivity = [&torrent](const qlonglong value) -> qlonglong + const auto getLastActivityTime = [&torrent]() -> qlonglong { - return (torrent.isPaused() || torrent.isChecking()) - ? 0 - : (QDateTime::currentDateTime().toSecsSinceEpoch() - value); + const qlonglong timeSinceActivity = torrent.timeSinceActivity(); + return (timeSinceActivity < 0) + ? torrent.addedTime().toSecsSinceEpoch() + : (QDateTime::currentDateTime().toSecsSinceEpoch() - timeSinceActivity); }; return { @@ -149,7 +150,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, adjustLastActivity(torrent.timeSinceActivity())}, + {KEY_TORRENT_LAST_ACTIVITY_TIME, getLastActivityTime()}, {KEY_TORRENT_AVAILABILITY, torrent.distributedCopies()}, {KEY_TORRENT_TOTAL_SIZE, torrent.totalSize()}