Fix EHentai gallery update notifications for real

This commit is contained in:
NerdNumber9 2019-08-09 09:48:31 -04:00
parent a89a36fd4c
commit 8f36d698cf

View File

@ -181,7 +181,7 @@ class EHentaiUpdateWorker: JobService(), CoroutineScope {
continue continue
} }
val chapters = try { val (new, chapters) = try {
updateEntryAndGetChapters(manga) updateEntryAndGetChapters(manga)
} catch (e: GalleryNotUpdatedException) { } catch (e: GalleryNotUpdatedException) {
if (e.network) { if (e.network) {
@ -212,7 +212,8 @@ class EHentaiUpdateWorker: JobService(), CoroutineScope {
val (acceptedRoot, discardedRoots, hasNew) = val (acceptedRoot, discardedRoots, hasNew) =
updateHelper.findAcceptedRootAndDiscardOthers(manga.source, chapters).await() updateHelper.findAcceptedRootAndDiscardOthers(manga.source, chapters).await()
if(hasNew && updatedManga.none { it.id == acceptedRoot.manga.id }) { if((new.isNotEmpty() && manga.id == acceptedRoot.manga.id)
|| (hasNew && updatedManga.none { it.id == acceptedRoot.manga.id })) {
updatedManga += acceptedRoot.manga updatedManga += acceptedRoot.manga
} }
@ -237,7 +238,8 @@ class EHentaiUpdateWorker: JobService(), CoroutineScope {
} }
} }
suspend fun updateEntryAndGetChapters(manga: Manga): List<Chapter> { // New, current
suspend fun updateEntryAndGetChapters(manga: Manga): Pair<List<Chapter>, List<Chapter>> {
val source = sourceManager.get(manga.source) as? EHentai val source = sourceManager.get(manga.source) as? EHentai
?: throw GalleryNotUpdatedException(false, IllegalStateException("Missing EH-based source (${manga.source})!")) ?: throw GalleryNotUpdatedException(false, IllegalStateException("Missing EH-based source (${manga.source})!"))
@ -247,8 +249,8 @@ class EHentaiUpdateWorker: JobService(), CoroutineScope {
db.insertManga(manga).asRxSingle().await() db.insertManga(manga).asRxSingle().await()
val newChapters = source.fetchChapterList(manga).toSingle().await(Schedulers.io()) val newChapters = source.fetchChapterList(manga).toSingle().await(Schedulers.io())
syncChaptersWithSource(db, newChapters, manga, source) // Not suspending, but does block, maybe fix this? val (new, _) = syncChaptersWithSource(db, newChapters, manga, source) // Not suspending, but does block, maybe fix this?
return db.getChapters(manga).await() return new to db.getChapters(manga).await()
} catch(t: Throwable) { } catch(t: Throwable) {
if(t is EHentai.GalleryNotFoundException) { if(t is EHentai.GalleryNotFoundException) {
val meta = db.getFlatMetadataForManga(manga.id!!).await()?.raise<EHentaiSearchMetadata>() val meta = db.getFlatMetadataForManga(manga.id!!).await()?.raise<EHentaiSearchMetadata>()