From 5f3144416de60f56254bd24e6ecbd6678d382eb4 Mon Sep 17 00:00:00 2001 From: Jesse Chan Date: Mon, 17 May 2021 21:24:11 +0800 Subject: [PATCH] server: use "dateFinished" for more accurate download completion notification --- server/services/notificationService.ts | 4 ++-- server/services/torrentService.ts | 16 ++++++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/server/services/notificationService.ts b/server/services/notificationService.ts index 14ac59ce..a4997c88 100644 --- a/server/services/notificationService.ts +++ b/server/services/notificationService.ts @@ -58,14 +58,14 @@ class NotificationService extends BaseService { * @param {Array} notifications - Notifications to add * @return {Promise} - Rejects with error. */ - async addNotification(notifications: Array>): Promise { + async addNotification(notifications: Array>, ts = Date.now()): Promise { this.count.total += notifications.length; this.count.unread += notifications.length; await this.db .insert( notifications.map((notification) => ({ - ts: Date.now(), + ts, data: notification.data, id: notification.id, read: false, diff --git a/server/services/torrentService.ts b/server/services/torrentService.ts index ac662c59..d5bbcff0 100644 --- a/server/services/torrentService.ts +++ b/server/services/torrentService.ts @@ -117,12 +117,16 @@ class TorrentService extends BaseService { const prevTorrentProperties = this.torrentListSummary.torrents[nextTorrentProperties.hash]; if (hasTorrentFinished(prevTorrentProperties, nextTorrentProperties)) { - this.services?.notificationService.addNotification([ - { - id: 'notification.torrent.finished', - data: {name: nextTorrentProperties.name}, - }, - ]); + const {dateFinished} = nextTorrentProperties; + this.services?.notificationService.addNotification( + [ + { + id: 'notification.torrent.finished', + data: {name: nextTorrentProperties.name}, + }, + ], + dateFinished > 0 ? dateFinished * 1000 : undefined, + ); } }; }