Fix simple language generation for favorites

This commit is contained in:
FooIbar authored and renovate[bot] committed 2024-03-02 19:40:30 +08:00
1 parent c578b16e27
commit 4142f28822
3 files changed
+8 -12

No files matched your search

@@ -20,6 +20,7 @@ import arrow.core.left
import arrow.core.right import arrow.core.right
import arrow.fx.coroutines.parMap import arrow.fx.coroutines.parMap
import arrow.fx.coroutines.parZip import arrow.fx.coroutines.parZip
import com.hippo.ehviewer.EhDB
import com.hippo.ehviewer.R import com.hippo.ehviewer.R
import com.hippo.ehviewer.Settings import com.hippo.ehviewer.Settings
import com.hippo.ehviewer.client.data.BaseGalleryInfo import com.hippo.ehviewer.client.data.BaseGalleryInfo
@@ -436,6 +437,12 @@ object EhEngine {
val needApi = filter && needTags() && !hasTags || Settings.showGalleryPages.value && !hasPages || hasRated val needApi = filter && needTags() && !hasTags || Settings.showGalleryPages.value && !hasPages || hasRated
if (needApi) fillGalleryListByApi(this@fillInfo, url) if (needApi) fillGalleryListByApi(this@fillInfo, url)
if (filter) removeAllSuspend { filterUploader(it) || filterTag(it) || filterTagNamespace(it) } if (filter) removeAllSuspend { filterUploader(it) || filterTag(it) || filterTagNamespace(it) }
forEach {
if (it.favoriteSlot == GalleryInfo.NOT_FAVORITED && EhDB.containLocalFavorites(it.gid)) {
it.favoriteSlot = GalleryInfo.LOCAL_FAVORITED
}
it.generateSLang()
}
} }
suspend fun addFavorites(galleryList: List<Pair<Long, String>>, dstCat: Int) { suspend fun addFavorites(galleryList: List<Pair<Long, String>>, dstCat: Int) {
@@ -38,7 +38,6 @@ object GalleryApiParser {
rating = item.rating rating = item.rating
simpleTags = item.tags simpleTags = item.tags
pages = item.pages pages = item.pages
generateSLang()
} }
} }
} }
@@ -1,26 +1,16 @@
package com.hippo.ehviewer.client.parser package com.hippo.ehviewer.client.parser
import com.hippo.ehviewer.EhDB
import com.hippo.ehviewer.client.data.BaseGalleryInfo import com.hippo.ehviewer.client.data.BaseGalleryInfo
import com.hippo.ehviewer.client.data.GalleryInfo.Companion.LOCAL_FAVORITED
import com.hippo.ehviewer.client.data.GalleryInfo.Companion.NOT_FAVORITED
import com.hippo.ehviewer.client.exception.ParseException import com.hippo.ehviewer.client.exception.ParseException
import java.nio.ByteBuffer import java.nio.ByteBuffer
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
import moe.tarsin.coroutines.runSuspendCatching import moe.tarsin.coroutines.runSuspendCatching
object GalleryListParser { object GalleryListParser {
suspend fun parse(body: ByteBuffer) = runSuspendCatching { fun parse(body: ByteBuffer) = runSuspendCatching {
unmarshalParsingAs<GalleryListResult>(body, ::parseGalleryInfoList) unmarshalParsingAs<GalleryListResult>(body, ::parseGalleryInfoList)
}.getOrElse { }.getOrElse {
throw ParseException("Can't parse gallery list", it) throw ParseException("Can't parse gallery list", it)
}.apply {
galleryInfoList.onEach {
if (it.favoriteSlot == NOT_FAVORITED && EhDB.containLocalFavorites(it.gid)) {
it.favoriteSlot = LOCAL_FAVORITED
}
it.generateSLang()
}
} }
val emptyResult = GalleryListResult(null, null, arrayListOf()) val emptyResult = GalleryListResult(null, null, arrayListOf())