mirror of
https://github.com/mihonapp/mihon.git
synced 2025-10-20 01:59:43 +02:00
refactor: refactor merging logic tidy up.
As we fixed the issue with removing favorites we don't the extra stuff. Signed-off-by: KaiserBh <kaiserbh@proton.me>
This commit is contained in:
@@ -106,39 +106,22 @@ abstract class SyncService(
|
|||||||
localMangaMap.forEach { (key, localManga) ->
|
localMangaMap.forEach { (key, localManga) ->
|
||||||
val remoteManga = remoteMangaMap[key]
|
val remoteManga = remoteMangaMap[key]
|
||||||
if (remoteManga != null) {
|
if (remoteManga != null) {
|
||||||
val localInstant = localManga.lastModifiedAt.let { Instant.ofEpochMilli(it) }
|
val localMangaLastModifiedAtInstant = Instant.ofEpochMilli(localManga.lastModifiedAt)
|
||||||
val remoteInstant = remoteManga.lastModifiedAt.let { Instant.ofEpochMilli(it) }
|
val remoteMangaLastModifiedAtInstant = Instant.ofEpochMilli(remoteManga.lastModifiedAt)
|
||||||
|
val mergedChapters = mergeChapters(localManga.chapters, remoteManga.chapters)
|
||||||
val mergedManga = if ((localInstant ?: Instant.MIN) >= (
|
// Keep the more recent manga
|
||||||
remoteInstant
|
if (localMangaLastModifiedAtInstant.isAfter(remoteMangaLastModifiedAtInstant)) {
|
||||||
?: Instant.MIN
|
mergedMangaMap[key] = localManga.copy(chapters = mergedChapters)
|
||||||
)
|
|
||||||
) {
|
|
||||||
localManga
|
|
||||||
} else {
|
} else {
|
||||||
remoteManga
|
mergedMangaMap[key] = remoteManga.copy(chapters = mergedChapters)
|
||||||
}
|
}
|
||||||
|
|
||||||
val localChapters = localManga.chapters
|
|
||||||
val remoteChapters = remoteManga.chapters
|
|
||||||
val mergedChapters = mergeChapters(localChapters, remoteChapters)
|
|
||||||
|
|
||||||
val isFavorite = if ((localInstant ?: Instant.MIN) >= (
|
|
||||||
remoteInstant
|
|
||||||
?: Instant.MIN
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
localManga.favorite
|
|
||||||
} else {
|
|
||||||
remoteManga.favorite
|
|
||||||
}
|
|
||||||
|
|
||||||
mergedMangaMap[key] = mergedManga.copy(chapters = mergedChapters, favorite = isFavorite)
|
|
||||||
} else {
|
} else {
|
||||||
|
// If there is no corresponding remote manga, keep the local one
|
||||||
mergedMangaMap[key] = localManga
|
mergedMangaMap[key] = localManga
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add any remote manga that doesn't exist locally
|
||||||
remoteMangaMap.forEach { (key, remoteManga) ->
|
remoteMangaMap.forEach { (key, remoteManga) ->
|
||||||
if (!mergedMangaMap.containsKey(key)) {
|
if (!mergedMangaMap.containsKey(key)) {
|
||||||
mergedMangaMap[key] = remoteManga
|
mergedMangaMap[key] = remoteManga
|
||||||
@@ -168,7 +151,7 @@ abstract class SyncService(
|
|||||||
val remoteInstant = remoteChapter.lastModifiedAt.let { Instant.ofEpochMilli(it) }
|
val remoteInstant = remoteChapter.lastModifiedAt.let { Instant.ofEpochMilli(it) }
|
||||||
|
|
||||||
val mergedChapter =
|
val mergedChapter =
|
||||||
if ((localInstant ?: Instant.MIN) >= (remoteInstant ?: Instant.MIN)) {
|
if (localInstant > remoteInstant) {
|
||||||
localChapter
|
localChapter
|
||||||
} else {
|
} else {
|
||||||
remoteChapter
|
remoteChapter
|
||||||
@@ -207,7 +190,7 @@ abstract class SyncService(
|
|||||||
val remoteCategory = remoteCategoriesMap[name]
|
val remoteCategory = remoteCategoriesMap[name]
|
||||||
if (remoteCategory != null) {
|
if (remoteCategory != null) {
|
||||||
// Compare and merge local and remote categories
|
// Compare and merge local and remote categories
|
||||||
val mergedCategory = if (localCategory.order >= remoteCategory.order) {
|
val mergedCategory = if (localCategory.order > remoteCategory.order) {
|
||||||
localCategory
|
localCategory
|
||||||
} else {
|
} else {
|
||||||
remoteCategory
|
remoteCategory
|
||||||
|
Reference in New Issue
Block a user