diff --git a/main.lua b/main.lua index 85cfe0e..5faf4e1 100644 --- a/main.lua +++ b/main.lua @@ -1980,6 +1980,11 @@ function Bookhoard:getMetaSyncState(book_key) if type(state) ~= "table" then state = {} self.settings.meta_sync_state[book_key] = state + elseif type(state.rating) == "number" and state.rating > 5 then + -- Settings written by the first bridge build remembered ratings + -- in 10-space; normalize once. 10-space memory cannot survive + -- the round-trip (odd values would re-round at every push). + state.rating = rating10to5(state.rating) end return state end @@ -2007,20 +2012,24 @@ function Bookhoard:pullBookMeta(interactive) if self.settings.sync_ratings then local ok, result = api:getRating(ref) if ok and result and not result.error then - local server10 = result.rating - local server5 = rating10to5(server10) + -- Compare in 5-STAR SPACE. The summary cannot represent odd + -- server values (9 = 4.5 stars), so remembering the raw + -- 10-scale would make every pulled odd rating look "changed" + -- at push time (9 remembered → 5★ local → push derives 10) + -- and silently round it up. Remember the star count we + -- actually wrote; conversion to 10 happens only at the POST. + local server5 = rating10to5(result.rating) local local5 = summary.rating or 0 - local local10 = rating5to10(local5) or 0 - local remembered10 = remembered.rating or 0 - if server10 ~= nil and server10 ~= local10 and remembered10 == local10 then + local remembered5 = remembered.rating or 0 + if server5 ~= local5 and remembered5 == local5 then -- Server moved, koreader didn't → apply. summary.rating = server5 self:writeSummary(summary) - remembered.rating = server10 + remembered.rating = server5 table.insert(applied, T(_("rating %1/5"), server5)) - elseif server10 ~= nil and server10 == local10 and remembered10 ~= local10 then + elseif server5 == local5 and remembered5 ~= local5 then -- Values agree but our memory is stale; just re-sync memory. - remembered.rating = server10 + remembered.rating = server5 end end end @@ -2068,12 +2077,15 @@ function Bookhoard:pushBookMeta(interactive) local api = self:getAPI() if self.settings.sync_ratings then - local local10 = rating5to10(summary.rating) or 0 - local remembered10 = remembered.rating or 0 - if local10 ~= remembered10 then - local ok, result = api:setRating(ref, local10) + -- 5-star space comparison (see the pull): the POST only fires + -- when the star count itself changed; conversion happens at the + -- boundary (nil/0 → server clears). + local local5 = summary.rating or 0 + local remembered5 = remembered.rating or 0 + if local5 ~= remembered5 then + local ok, result = api:setRating(ref, rating5to10(local5) or 0) if ok and result and not result.error then - remembered.rating = local10 + remembered.rating = local5 table.insert(pushed, _("rating")) else errors = errors + 1