mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-19 00:59:17 +01:00
Update chapter progress upon registering tracker (closes #7209)
Co-authored-by: Saud-97 <Saud-97@users.noreply.github.com>
This commit is contained in:
parent
8efb20439a
commit
488d8ab8cf
@ -936,20 +936,31 @@ class MangaPresenter(
|
||||
item.manga_id = successState.manga.id
|
||||
launchIO {
|
||||
try {
|
||||
val allChapters = successState.chapters
|
||||
.map { it.chapter.toDbChapter() }
|
||||
val allChapters = successState.chapters.map { it.chapter }
|
||||
val hasReadChapters = allChapters.any { it.read }
|
||||
service.bind(item, hasReadChapters)
|
||||
|
||||
item.toDomainTrack(idRequired = false)?.let { track ->
|
||||
insertTrack.await(track)
|
||||
|
||||
(service as? EnhancedTrackService)?.let { _ ->
|
||||
val chapters = successState.chapters
|
||||
.map { it.chapter }
|
||||
// Update chapter progress if newer chapters marked read locally
|
||||
if (hasReadChapters) {
|
||||
val latestLocalReadChapterNumber = allChapters
|
||||
.sortedBy { it.chapterNumber }
|
||||
.takeWhile { it.read }
|
||||
.lastOrNull()
|
||||
?.chapterNumber?.toDouble() ?: -1.0
|
||||
|
||||
syncChaptersWithTrackServiceTwoWay
|
||||
.await(chapters, track, service)
|
||||
if (latestLocalReadChapterNumber >= track.lastChapterRead) {
|
||||
val updatedTrack = track.copy(
|
||||
lastChapterRead = latestLocalReadChapterNumber,
|
||||
)
|
||||
setTrackerLastChapterRead(TrackItem(updatedTrack.toDbTrack(), service), latestLocalReadChapterNumber.toInt())
|
||||
}
|
||||
}
|
||||
|
||||
if (service is EnhancedTrackService) {
|
||||
syncChaptersWithTrackServiceTwoWay.await(allChapters, track, service)
|
||||
}
|
||||
}
|
||||
} catch (e: Throwable) {
|
||||
|
Loading…
Reference in New Issue
Block a user