mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2026-01-09 09:02:31 -06:00
Improve "last activity" calculation in WebAPI (#15339)
Co-authored-by: 秦风 <mayli.he@gmail.com> Co-authored-by: Chocobo1 <Chocobo1@users.noreply.github.com>
This commit is contained in:
@@ -95,11 +95,12 @@ QVariantMap serialize(const BitTorrent::Torrent &torrent)
|
|||||||
return (ratio > BitTorrent::Torrent::MAX_RATIO) ? -1 : ratio;
|
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())
|
const qlonglong timeSinceActivity = torrent.timeSinceActivity();
|
||||||
? 0
|
return (timeSinceActivity < 0)
|
||||||
: (QDateTime::currentDateTime().toSecsSinceEpoch() - value);
|
? torrent.addedTime().toSecsSinceEpoch()
|
||||||
|
: (QDateTime::currentDateTime().toSecsSinceEpoch() - timeSinceActivity);
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -149,7 +150,7 @@ QVariantMap serialize(const BitTorrent::Torrent &torrent)
|
|||||||
{KEY_TORRENT_AUTO_TORRENT_MANAGEMENT, torrent.isAutoTMMEnabled()},
|
{KEY_TORRENT_AUTO_TORRENT_MANAGEMENT, torrent.isAutoTMMEnabled()},
|
||||||
{KEY_TORRENT_TIME_ACTIVE, torrent.activeTime()},
|
{KEY_TORRENT_TIME_ACTIVE, torrent.activeTime()},
|
||||||
{KEY_TORRENT_SEEDING_TIME, torrent.seedingTime()},
|
{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_AVAILABILITY, torrent.distributedCopies()},
|
||||||
|
|
||||||
{KEY_TORRENT_TOTAL_SIZE, torrent.totalSize()}
|
{KEY_TORRENT_TOTAL_SIZE, torrent.totalSize()}
|
||||||
|
|||||||
Reference in New Issue
Block a user