From bbecf87292e5ff15ec612cc210bc2543fb6ee439 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Wed, 21 Aug 2019 17:37:46 +0800 Subject: [PATCH 1/2] Handle invalid time activity properly When there is no activity before m_nativeStatus.last_upload will be 0 and this commit will map it to -1 which retain the expected behavior as before (libtorrent < 1.2 era). --- src/base/bittorrent/torrenthandle.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/base/bittorrent/torrenthandle.cpp b/src/base/bittorrent/torrenthandle.cpp index bb75083b6..97b355c32 100644 --- a/src/base/bittorrent/torrenthandle.cpp +++ b/src/base/bittorrent/torrenthandle.cpp @@ -1136,6 +1136,8 @@ qlonglong TorrentHandle::timeSinceUpload() const #if (LIBTORRENT_VERSION_NUM < 10200) return m_nativeStatus.time_since_upload; #else + if (m_nativeStatus.last_upload.time_since_epoch().count() == 0) + return -1; return lt::total_seconds(lt::clock_type::now() - m_nativeStatus.last_upload); #endif } @@ -1145,6 +1147,8 @@ qlonglong TorrentHandle::timeSinceDownload() const #if (LIBTORRENT_VERSION_NUM < 10200) return m_nativeStatus.time_since_download; #else + if (m_nativeStatus.last_download.time_since_epoch().count() == 0) + return -1; return lt::total_seconds(lt::clock_type::now() - m_nativeStatus.last_download); #endif } From fba72f5fb77bfc45762a44f23508118a283383ac Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Wed, 21 Aug 2019 17:43:55 +0800 Subject: [PATCH 2/2] Simplify code --- src/webui/api/serialize/serialize_torrent.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/webui/api/serialize/serialize_torrent.cpp b/src/webui/api/serialize/serialize_torrent.cpp index 4f3423fff..14c7935bc 100644 --- a/src/webui/api/serialize/serialize_torrent.cpp +++ b/src/webui/api/serialize/serialize_torrent.cpp @@ -136,9 +136,9 @@ QVariantMap serialize(const BitTorrent::TorrentHandle &torrent) ret[KEY_TORRENT_LAST_ACTIVITY_TIME] = 0; } else { - QDateTime dt = QDateTime::currentDateTime(); - dt = dt.addSecs(-torrent.timeSinceActivity()); - ret[KEY_TORRENT_LAST_ACTIVITY_TIME] = dt.toSecsSinceEpoch(); + const qint64 dt = (QDateTime::currentDateTime().toSecsSinceEpoch() + - torrent.timeSinceActivity()); + ret[KEY_TORRENT_LAST_ACTIVITY_TIME] = dt; } return ret;