Fixes #97 missing jobs.

Implemented Equals(obj) functions for Chapter, DownloadChapter and DownloadNewChapters to check if jobs already exist.
This commit is contained in:
Glax 2024-01-11 20:19:04 +01:00
parent 0c135aa89e
commit b5be4e0dd8
5 changed files with 33 additions and 9 deletions

View File

@ -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)

View File

@ -43,4 +43,12 @@ public class DownloadChapter : Job
downloadTask.Start();
return Array.Empty<Job>();
}
public override bool Equals(object? obj)
{
if (obj is not DownloadChapter otherJob)
return false;
return otherJob.mangaConnector == this.mangaConnector &&
otherJob.chapter.Equals(this.chapter);
}
}

View File

@ -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);
}
}

View File

@ -43,15 +43,7 @@ public class JobBoss : GlobalBase
/// </summary>
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)

View File

@ -48,4 +48,13 @@ public class UpdateMetadata : Job
this.progressToken.Cancel();
return Array.Empty<Job>();
}
public override bool Equals(object? obj)
{
if (obj is not UpdateMetadata otherJob)
return false;
return otherJob.mangaConnector == this.mangaConnector &&
otherJob.manga.Equals(this.manga);
}
}