Skip to content

Kavita is a fast, feature rich, cross platform reading server. Built with the goal of being a full solution for all your reading needs. Setup your own server and share your reading collection with your friends and family.

Fixed loose chapters marked as read for Tachiyomi (#1158)

ThePromidius5220d2b30093
diff --git a/API.Tests/Services/ReaderServiceTests.cs b/API.Tests/Services/ReaderServiceTests.cs
index a66863487..402f136c3 100644
--- a/API.Tests/Services/ReaderServiceTests.cs
+++ b/API.Tests/Services/ReaderServiceTests.cs
@@ -1780,6 +1780,78 @@ public class ReaderServiceTests
Assert.True(await _unitOfWork.AppUserProgressRepository.UserHasProgress(LibraryType.Manga, 1));
}
+ [Fact]
+ public async Task MarkChaptersUntilAsRead_ShouldMarkAsReadAnythingUntil()
+ {
+ await ResetDB();
+ _context.Series.Add(new Series()
+ {
+ Name = "Test",
+ Library = new Library()
+ {
+ Name = "Test LIb",
+ Type = LibraryType.Manga,
+ },
+ Volumes = new List<Volume>()
+ {
+ EntityFactory.CreateVolume("0", new List<Chapter>()
+ {
+ EntityFactory.CreateChapter("45", false, new List<MangaFile>(), 5),
+
+ EntityFactory.CreateChapter("46", false, new List<MangaFile>(), 46),
+ EntityFactory.CreateChapter("47", false, new List<MangaFile>(), 47),
+ EntityFactory.CreateChapter("48", false, new List<MangaFile>(), 48),
+ EntityFactory.CreateChapter("49", false, new List<MangaFile>(), 49),
+ EntityFactory.CreateChapter("50", false, new List<MangaFile>(), 50),
+ EntityFactory.CreateChapter("Some Special Title", true, new List<MangaFile>(), 10),
+ }),
+ EntityFactory.CreateVolume("1", new List<Chapter>()
+ {
+ EntityFactory.CreateChapter("0", false, new List<MangaFile>(), 6),
+ }),
+ EntityFactory.CreateVolume("2", new List<Chapter>()
+ {
+ EntityFactory.CreateChapter("0", false, new List<MangaFile>(), 7),
+ }),
+ EntityFactory.CreateVolume("3", new List<Chapter>()
+ {
+ EntityFactory.CreateChapter("12", false, new List<MangaFile>(), 5),
+ EntityFactory.CreateChapter("13", false, new List<MangaFile>(), 5),
+ EntityFactory.CreateChapter("14", false, new List<MangaFile>(), 5),
+ }),
+ }
+ });
+
+ _context.AppUser.Add(new AppUser()
+ {
+ UserName = "majora2007"
+ });
+
+ await _context.SaveChangesAsync();
+
+ var readerService = new ReaderService(_unitOfWork, Substitute.For<ILogger<ReaderService>>());
+
+ var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync("majora2007", AppUserIncludes.Progress);
+ const int markReadUntilNumber = 47;
+
+ await readerService.MarkChaptersUntilAsRead(user, 1, markReadUntilNumber);
+ await _context.SaveChangesAsync();
+
+ var volumes = await _unitOfWork.VolumeRepository.GetVolumesDtoAsync(1, 1);
+ Assert.True(volumes.SelectMany(v => v.Chapters).All(c =>
+ {
+ // Specials are ignored.
+ var notReadChapterRanges = new[] {"Some Special Title", "48", "49", "50"};
+ if (notReadChapterRanges.Contains(c.Range))
+ {
+ return c.PagesRead == 0;
+ }
+ // Pages read and total pages must match -> chapter fully read
+ return c.Pages == c.PagesRead;
+
+ }));
+ }
+
#endregion
diff --git a/API/Controllers/ReaderController.cs b/API/Controllers/ReaderController.cs
index a8a34bdfd..9bcce9591 100644
--- a/API/Controllers/ReaderController.cs
+++ b/API/Controllers/ReaderController.cs
@@ -394,6 +394,10 @@ namespace API.Controllers
var user = await _unitOfWork.UserRepository.GetUserByUsernameAsync(User.GetUsername(), AppUserIncludes.Progress);
user.Progresses ??= new List<AppUserProgress>();
+ // Tachiyomi sends chapter 0.0f when there's no chapters read.
+ // Due to the encoding for volumes this marks all chapters in volume 0 (loose chapters) as read so we ignore it
+ if (chapterNumber == 0.0f) return true;
+
if (chapterNumber < 1.0f)
{
// This is a hack to track volume number. We need to map it back by x100
diff --git a/API/Services/ReaderService.cs b/API/Services/ReaderService.cs
index ee8647187..f5437e7bc 100644
--- a/API/Services/ReaderService.cs
+++ b/API/Services/ReaderService.cs
@@ -443,7 +443,7 @@ public class ReaderService : IReaderService
public async Task MarkVolumesUntilAsRead(AppUser user, int seriesId, int volumeNumber)
{
var volumes = await _unitOfWork.VolumeRepository.GetVolumesForSeriesAsync(new List<int>() { seriesId }, true);
- foreach (var volume in volumes.OrderBy(v => v.Number).Where(v => v.Number <= volumeNumber))
+ foreach (var volume in volumes.OrderBy(v => v.Number).Where(v => v.Number <= volumeNumber && v.Number > 0))
{
MarkChaptersAsRead(user, volume.SeriesId, volume.Chapters);
}