mirror of
https://github.com/mihonapp/mihon.git
synced 2026-10-19 23:22:26 -07:00
Merge manga favorite related fields into favorite_at
Migration 16 replaces favorite, date_added and favorite_modified_at with one nullable favorite_at. A favorite whose date_added is 0 falls back to favorite_modified_at. Manga.favorite and dateAdded become getters derived from it, and restore merges it by taking the earliest non-zero time.
This commit is contained in:
@@ -48,15 +48,10 @@ class UpdateManga(
|
||||
}
|
||||
|
||||
suspend fun awaitUpdateFavorite(mangaId: Long, favorite: Boolean): Boolean {
|
||||
val dateAdded = when (favorite) {
|
||||
true -> Clock.System.now().toEpochMilliseconds()
|
||||
false -> 0
|
||||
val update = when (favorite) {
|
||||
true -> MangaUpdate(mangaId) { favoriteAt = Clock.System.now().toEpochMilliseconds() }
|
||||
false -> MangaUpdate(mangaId) { favoriteAt = null }
|
||||
}
|
||||
return mangaRepository.update(
|
||||
MangaUpdate(mangaId) {
|
||||
this.favorite = favorite
|
||||
this.dateAdded = dateAdded
|
||||
},
|
||||
)
|
||||
return mangaRepository.update(update)
|
||||
}
|
||||
}
|
||||
|
||||
+1
-2
@@ -88,12 +88,11 @@ private fun Manga.toBackupManga() =
|
||||
thumbnailUrl = this.thumbnailUrl,
|
||||
favorite = this.favorite,
|
||||
source = this.source,
|
||||
dateAdded = this.dateAdded,
|
||||
dateAdded = this.favoriteAt ?: 0L,
|
||||
viewer = (this.viewerFlags.toInt() and ReadingMode.MASK),
|
||||
viewer_flags = this.viewerFlags.toInt(),
|
||||
chapterFlags = this.chapterFlags.toInt(),
|
||||
updateStrategy = this.updateStrategy,
|
||||
favoriteModifiedAt = this.favoriteModifiedAt,
|
||||
notes = this.notes,
|
||||
initialized = this.initialized,
|
||||
memo = this.memo.toByteArray(),
|
||||
|
||||
@@ -57,13 +57,19 @@ class BackupManga(
|
||||
genre = this@BackupManga.genre,
|
||||
status = this@BackupManga.status.toLong(),
|
||||
thumbnailUrl = this@BackupManga.thumbnailUrl,
|
||||
favorite = this@BackupManga.favorite,
|
||||
source = this@BackupManga.source,
|
||||
dateAdded = this@BackupManga.dateAdded,
|
||||
// For libraries older than dateAdded, the favorite timestamp is the only record of when
|
||||
// an entry was added. It was written by a trigger in seconds, unlike dateAdded.
|
||||
favoriteAt = if (this@BackupManga.favorite) {
|
||||
this@BackupManga.dateAdded.takeIf { it != 0L }
|
||||
?: this@BackupManga.favoriteModifiedAt?.times(1000)
|
||||
?: 0L
|
||||
} else {
|
||||
null
|
||||
},
|
||||
viewerFlags = (this@BackupManga.viewer_flags ?: this@BackupManga.viewer).toLong(),
|
||||
chapterFlags = this@BackupManga.chapterFlags.toLong(),
|
||||
updateStrategy = this@BackupManga.updateStrategy,
|
||||
favoriteModifiedAt = this@BackupManga.favoriteModifiedAt,
|
||||
notes = this@BackupManga.notes,
|
||||
initialized = this@BackupManga.initialized,
|
||||
memo = this@BackupManga.memo.toJsonObject(),
|
||||
|
||||
+2
-6
@@ -236,17 +236,13 @@ class BrowseSourceViewModel(
|
||||
val update = if (manga.favorite) {
|
||||
val coverLastModified = manga.removeCovers(coverCache).coverLastModified
|
||||
MangaUpdate(manga.id) {
|
||||
favorite = false
|
||||
dateAdded = 0
|
||||
favoriteAt = null
|
||||
if (coverLastModified != manga.coverLastModified) this.coverLastModified = coverLastModified
|
||||
}
|
||||
} else {
|
||||
setMangaDefaultChapterFlags.await(manga)
|
||||
addTracks.bindEnhancedTrackers(manga, sourceManager.getOrStub(manga.source))
|
||||
MangaUpdate(manga.id) {
|
||||
favorite = true
|
||||
dateAdded = Clock.System.now().toEpochMilliseconds()
|
||||
}
|
||||
MangaUpdate(manga.id) { favoriteAt = Clock.System.now().toEpochMilliseconds() }
|
||||
}
|
||||
|
||||
updateManga.await(update)
|
||||
|
||||
@@ -338,7 +338,7 @@ class LibraryViewModel(
|
||||
manga1.libraryManga.chapterFetchedAt.compareTo(manga2.libraryManga.chapterFetchedAt)
|
||||
}
|
||||
LibrarySort.Type.DateAdded -> {
|
||||
manga1.libraryManga.manga.dateAdded.compareTo(manga2.libraryManga.manga.dateAdded)
|
||||
compareValues(manga1.libraryManga.manga.favoriteAt, manga2.libraryManga.manga.favoriteAt)
|
||||
}
|
||||
LibrarySort.Type.TrackerMean -> {
|
||||
val item1Score = trackerScores[manga1.id] ?: defaultTrackerScoreSortValue
|
||||
@@ -572,7 +572,7 @@ class LibraryViewModel(
|
||||
val toDelete = mangas.map {
|
||||
it.removeCovers(coverCache)
|
||||
MangaUpdate(it.id) {
|
||||
favorite = false
|
||||
favoriteAt = null
|
||||
}
|
||||
}
|
||||
updateManga.awaitAll(toDelete)
|
||||
|
||||
Reference in New Issue
Block a user