Prevent duplicated downloads in download queue

The mutation to add chapters to the download queue returns the current download queue.

Thus, the local queue already includes the new downloads and adding them blindly in the download subscription will cause them to be in the local queue twice.
This commit is contained in:
schroda
2024-12-07 23:19:01 +01:00
parent b9ab13c7d2
commit 12e8939267

View File

@@ -2981,7 +2981,16 @@ export class RequestManager {
return data;
}
const queueWithAddedDownloads = [...data.downloadStatus.queue, ...downloadsToAdd];
const downloadsToAddWithoutAlreadyKnown = downloadsToAdd.filter((download) =>
data.downloadStatus.queue.every(
(queueDownload) => queueDownload.chapter.id !== download.chapter.id,
),
);
const queueWithAddedDownloads = [
...data.downloadStatus.queue,
...downloadsToAddWithoutAlreadyKnown,
];
const queueWithoutRemovedDownloads = !downloadsToRemove.length
? queueWithAddedDownloads
: queueWithAddedDownloads.filter(