From 4e59beab1620f2a13f434b850c3382b4f36ca2a1 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Thu, 4 Jan 2024 18:53:34 +0000 Subject: [PATCH] Extra check for edition tag --- outbox.py | 16 +++++++++------- reading.py | 27 +++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/outbox.py b/outbox.py index c22e109a2..81ff078ee 100644 --- a/outbox.py +++ b/outbox.py @@ -63,6 +63,7 @@ from shares import outbox_undo_share_upload from webapp_post import individual_post_as_html from speaker import update_speaker from reading import store_book_events +from reading import has_edition_tag def _person_receive_update_outbox(base_dir: str, http_prefix: str, @@ -502,13 +503,14 @@ def post_message_to_outbox(session, translate: {}, theme, system_language, outbox_name) - store_book_events(base_dir, - message_json, - system_language, [], - translate, debug, - max_recent_books, - books_cache, - max_cached_readers) + if has_edition_tag(message_json): + store_book_events(base_dir, + message_json, + system_language, [], + translate, debug, + max_recent_books, + books_cache, + max_cached_readers) # save all instance blogs to the news actor if post_to_nickname != 'news' and outbox_name == 'tlblogs': diff --git a/reading.py b/reading.py index 94b158ba1..7cfc9d5f0 100644 --- a/reading.py +++ b/reading.py @@ -89,6 +89,30 @@ def _get_book_image_from_post(post_json_object: {}) -> str: return '' +def has_edition_tag(post_json_object: {}) -> bool: + """Checks whether the given post has an Edition tag + indicating that it contains a book event + """ + post_obj = post_json_object + if has_object_dict(post_json_object): + post_obj = post_json_object['object'] + + if not post_obj.get('tag'): + return False + if not isinstance(post_obj['tag'], list): + return False + for tag in post_obj['tag']: + if not isinstance(tag, dict): + continue + if not tag.get('type'): + continue + if not isinstance(tag['type'], str): + continue + if tag['type'] == 'Edition': + return True + return False + + def get_reading_status(post_json_object: {}, system_language: str, languages_understood: [], @@ -169,6 +193,9 @@ def get_reading_status(post_json_object: {}, book_dict['image_url'] = book_image_url return book_dict + if not has_edition_tag(post_json_object): + return {} + # get the book details from a post tag book_dict = get_book_from_post(post_json_object, debug) if not book_dict: