diff --git a/Tranga/Chapter.cs b/Tranga/Chapter.cs index 8e63306..dc1c216 100644 --- a/Tranga/Chapter.cs +++ b/Tranga/Chapter.cs @@ -41,6 +41,13 @@ public readonly struct Chapter : IComparable return $"Chapter {parentManga.sortName} {parentManga.internalId} {chapterNumber} {name}"; } + public override bool Equals(object? obj) + { + if (obj is not Chapter) + return false; + return CompareTo(obj) == 0; + } + public int CompareTo(object? obj) { if (obj is Chapter otherChapter) diff --git a/Tranga/Jobs/DownloadChapter.cs b/Tranga/Jobs/DownloadChapter.cs index dc50e30..434736e 100644 --- a/Tranga/Jobs/DownloadChapter.cs +++ b/Tranga/Jobs/DownloadChapter.cs @@ -43,4 +43,12 @@ public class DownloadChapter : Job downloadTask.Start(); return Array.Empty(); } + + public override bool Equals(object? obj) + { + if (obj is not DownloadChapter otherJob) + return false; + return otherJob.mangaConnector == this.mangaConnector && + otherJob.chapter.Equals(this.chapter); + } } \ No newline at end of file diff --git a/Tranga/Jobs/DownloadNewChapters.cs b/Tranga/Jobs/DownloadNewChapters.cs index 7967289..ebcbde7 100644 --- a/Tranga/Jobs/DownloadNewChapters.cs +++ b/Tranga/Jobs/DownloadNewChapters.cs @@ -48,4 +48,12 @@ public class DownloadNewChapters : Job progressToken.Complete(); return jobs; } + + public override bool Equals(object? obj) + { + if (obj is not DownloadNewChapters otherJob) + return false; + return otherJob.mangaConnector == this.mangaConnector && + otherJob.manga.Equals(this.manga); + } } \ No newline at end of file diff --git a/Tranga/Jobs/JobBoss.cs b/Tranga/Jobs/JobBoss.cs index c3f193d..f603313 100644 --- a/Tranga/Jobs/JobBoss.cs +++ b/Tranga/Jobs/JobBoss.cs @@ -43,15 +43,7 @@ public class JobBoss : GlobalBase /// public bool ContainsJobLike(Job job) { - if (job is DownloadChapter dcJob) - { - return this.GetJobsLike(dcJob.mangaConnector, chapter: dcJob.chapter).Any(); - }else if (job is DownloadNewChapters ncJob) - { - return this.GetJobsLike(ncJob.mangaConnector, ncJob.manga).Any(); - } - - return false; + return this.jobs.Any(existingJob => existingJob.Equals(job)); } public void RemoveJob(Job job) diff --git a/Tranga/Jobs/UpdateMetadata.cs b/Tranga/Jobs/UpdateMetadata.cs index 725c60f..c400c8f 100644 --- a/Tranga/Jobs/UpdateMetadata.cs +++ b/Tranga/Jobs/UpdateMetadata.cs @@ -48,4 +48,13 @@ public class UpdateMetadata : Job this.progressToken.Cancel(); return Array.Empty(); } + + public override bool Equals(object? obj) + { + + if (obj is not UpdateMetadata otherJob) + return false; + return otherJob.mangaConnector == this.mangaConnector && + otherJob.manga.Equals(this.manga); + } } \ No newline at end of file