fix(hardcover-sync): Don't send repeated read status to Hardcover.app (#2609)
* fix(hardcover-sync): Don't send repeated read status to Hardcover.app * fix(hardcover-sync): Use progress percentage instead of read status * fix(hardcover-sync): Add test cases * fix(hardcover-sync): Also check read status for changes
This commit is contained in:
@@ -186,6 +186,9 @@ public class KoboReadingStateService {
|
||||
return newProgress;
|
||||
});
|
||||
|
||||
Float prevousKoboProgressPercent = progress.getKoboProgressPercent();
|
||||
ReadStatus previousReadStatus = progress.getReadStatus();
|
||||
|
||||
KoboReadingState.CurrentBookmark bookmark = readingState.getCurrentBookmark();
|
||||
if (bookmark != null) {
|
||||
if (bookmark.getProgressPercent() != null) {
|
||||
@@ -219,7 +222,12 @@ public class KoboReadingStateService {
|
||||
log.debug("Synced Kobo progress: bookId={}, progress={}%", bookId, progress.getKoboProgressPercent());
|
||||
|
||||
// Sync progress to Hardcover asynchronously (if enabled for this user)
|
||||
hardcoverSyncService.syncProgressToHardcover(book.getId(), progress.getKoboProgressPercent(), userId);
|
||||
// But only if the progress percentage has changed from last time, or the read status has changed
|
||||
if (progress.getKoboProgressPercent() != null
|
||||
&& (!progress.getKoboProgressPercent().equals(prevousKoboProgressPercent)
|
||||
|| progress.getReadStatus() != previousReadStatus)) {
|
||||
hardcoverSyncService.syncProgressToHardcover(book.getId(), progress.getKoboProgressPercent(), userId);
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
log.warn("Invalid entitlement ID format: {}", readingState.getEntitlementId());
|
||||
}
|
||||
|
||||
@@ -74,6 +74,8 @@ public class KoreaderService {
|
||||
BookLoreUserEntity user = findBookLoreUser(authDetails.getBookLoreUserId());
|
||||
|
||||
UserBookProgressEntity userProgress = getOrCreateUserProgress(user, book);
|
||||
Float previousProgressPercent = userProgress.getKoreaderProgressPercent();
|
||||
ReadStatus previousReadStatus = userProgress.getReadStatus();
|
||||
updateProgressData(userProgress, koProgress, authDetails.isSyncWithBookloreReader(), book);
|
||||
|
||||
progressRepository.save(userProgress);
|
||||
@@ -83,8 +85,13 @@ public class KoreaderService {
|
||||
|
||||
log.info("saveProgress: saved progress='{}' percentage={} for userId={} bookHash={}", koProgress.getProgress(), koProgress.getPercentage(), authDetails.getBookLoreUserId(), bookHash);
|
||||
|
||||
Float progressPercent = normalizeProgressPercent(koProgress.getPercentage());
|
||||
hardcoverSyncService.syncProgressToHardcover(book.getId(), progressPercent, authDetails.getBookLoreUserId());
|
||||
// Sync progress to Hardcover asynchronously (if enabled for this user)
|
||||
// But only if the progress percentage has changed from last time, or the read status has changed
|
||||
if (koProgress.getPercentage() != null && (!koProgress.getPercentage().equals(previousProgressPercent)
|
||||
|| userProgress.getReadStatus() != previousReadStatus)) {
|
||||
Float progressPercent = normalizeProgressPercent(koProgress.getPercentage());
|
||||
hardcoverSyncService.syncProgressToHardcover(book.getId(), progressPercent, authDetails.getBookLoreUserId());
|
||||
}
|
||||
}
|
||||
|
||||
private void saveToFileProgress(BookLoreUserEntity user, BookEntity book, UserBookProgressEntity progress) {
|
||||
|
||||
Reference in New Issue
Block a user