From 8e1982c70001070c6ce47779d82c691c3e3e95b3 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 2 Apr 2023 14:29:50 +0530 Subject: [PATCH] Content server: Fix re-opening book from home page after making progress not opening to correct last read position when a user is logged in. Fixes 2011755 --- src/pyj/book_list/home.pyj | 6 ++++++ src/pyj/read_book/view.pyj | 2 ++ 2 files changed, 8 insertions(+) diff --git a/src/pyj/book_list/home.pyj b/src/pyj/book_list/home.pyj index 41750e0ccd..e91b2447cf 100644 --- a/src/pyj/book_list/home.pyj +++ b/src/pyj/book_list/home.pyj @@ -42,6 +42,12 @@ def update_recently_read_by_user(items): recently_read_by_user.updated = True +def update_book_in_recently_read_by_user_on_home_page(library_id, book_id, book_format, cfi): + for item in recently_read_by_user.items: + if item.library_id is library_id and item.book_id is book_id and item.format is book_format: + item.cfi = cfi + + def show_cover(blob, name, mt, book): img = document.getElementById(this) if not img: diff --git a/src/pyj/read_book/view.pyj b/src/pyj/read_book/view.pyj index d17bc911fc..1aabe9ea6e 100644 --- a/src/pyj/read_book/view.pyj +++ b/src/pyj/read_book/view.pyj @@ -7,6 +7,7 @@ from elementmaker import E import read_book.iframe # noqa from ajax import ajax_send from book_list.globals import get_session_data +from book_list.home import update_book_in_recently_read_by_user_on_home_page from book_list.theme import cached_color_to_rgba, get_color, set_ui_colors from book_list.ui import query_as_href from dom import add_extra_css, build_rule, clear, set_css, svgicon, unique_id @@ -1245,6 +1246,7 @@ class View: if end_type is not 'load': print('Failed to update last read position, AJAX call did not succeed') ) + update_book_in_recently_read_by_user_on_home_page(key[0], key[1], key[2], data.cfi) @property def current_position_data(self):