server: use "dateFinished" for more accurate download completion notification

This commit is contained in:
Jesse Chan
2021-05-17 21:24:11 +08:00
parent 4e6d4136cb
commit 5f3144416d
2 changed files with 12 additions and 8 deletions
+2 -2
View File
@@ -58,14 +58,14 @@ class NotificationService extends BaseService<NotificationServiceEvents> {
* @param {Array<Notification>} notifications - Notifications to add
* @return {Promise<void>} - Rejects with error.
*/
async addNotification(notifications: Array<Pick<Notification, 'id' | 'data'>>): Promise<void> {
async addNotification(notifications: Array<Pick<Notification, 'id' | 'data'>>, ts = Date.now()): Promise<void> {
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,
+10 -6
View File
@@ -117,12 +117,16 @@ class TorrentService extends BaseService<TorrentServiceEvents> {
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,
);
}
};
}