mirror of
https://github.com/zoriya/flood.git
synced 2026-05-29 18:04:10 +00:00
server: use "dateFinished" for more accurate download completion notification
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user